Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
react-likert-scale
Advanced tools
A React component that makes a Likert Scale for collecting data.
A React component that makes a Likert Scale for collecting data or to make a survey. It has the following features:
A live demo is on CodePen.
npm i react-likert-scale
import React from 'react';
import Likert from 'react-likert-scale';
export default () => {
const likertOptions = {
question: "What is your opinion of the President’s performance?",
responses: [
{ value: 1, text: "Abysmal" },
{ value: 2, text: "Poor" },
{ value: 3, text: "Average", checked: true },
{ value: 4, text: "Good" },
{ value: 5, text: "Excellent" }
],
onChange: val => {
console.log(val);
}
};
return (
<Likert {...likertOptions} />
)
}
This component has three props
:
question
— (string) This is the prompt that displays above the options. It is optional.id
- (string) You are highly encouraged to always pass in a unique ID. This is used primarily
for accessibility reasons (to associate the label to the radio button). If you are using the
question
prop and all you questions are unqiue then it is safe to omit the id
prop.responses
— (array of objects) These are your options. The value
key is what is returned to
the calling application in the onChange
callback. text
is what’s shown on-screen. The optional
checked
key will pre-check a radio button when set to true
.onChange
— (callback function) Optionally, you can provide a callback function that returns the
value of the option that was clicked.The top-level DOM element that gets created by this component is <fieldset class="likertScale">
.
You can override any styles by prefixing your rule with fieldset.likertScale
. For example, let’s
say you want the radio button “dots” to have a light gray background with a dark green ring.
fieldset.likertScale .likertIndicator {
border: thin solid darkGreen;
background-color: lightGray;
}
This isn’t very common, but you may want to set focus on a Likert Scale after the page renders. This
is done with React via refs
. Either create your ref with React.createRef()
or the useRef()
hook. You can then pass your ref
to the Likert component.
import React, { useRef } from 'react';
import Likert from 'react-likert-scale';
export default () => {
const likertOptions = {
question: "What is your opinion of the President’s performance?",
responses: [
{ value: 1, text: "Abysmal" },
{ value: 2, text: "Poor" },
{ value: 3, text: "Average" },
{ value: 4, text: "Good" },
{ value: 5, text: "Excellent" }
]
};
const likertRef = useRef();
return (
<Likert {...likertOptions} ref={likertRef} />
)
}
id
, class
, disabled
, data-*
, onClick
, etc.?Sure. They will be applied to the likert component’s top-level DOM element, <fieldset>
.
<Likert {...likertOptions}
id='Q1'
className='myClass'
onClick={() => {
doThis();
andThis();
}}
/>
Let me know. Create an issue on GitHub.
FAQs
A React component that makes a Likert Scale for surveys or data collection.
The npm package react-likert-scale receives a total of 334 weekly downloads. As such, react-likert-scale popularity was classified as not popular.
We found that react-likert-scale demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.