Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@highlight-ui/radio-button
Advanced tools
A control that allows the user to toggle between checked and unchecked states. Used to pick one option from a set of multiple available options. If you require a multi-selection input, please use the Checkbox.
Using npm:
npm install @highlight-ui/radio-button
Using yarn:
yarn add @highlight-ui/radio-button
Using pnpm:
pnpm install @highlight-ui/radio-button
In your (S)CSS file:
@import url('@highlight-ui/radio-button');
Once the package is installed, you can import the library:
import { RadioButton, RadioButtonGroup } from '@highlight-ui/radio-button';
import React, { useState } from 'react';
import { RadioButton } from '@highlight-ui/radio-button';
export default function RadioButtonExample() {
const [checkedStatus, setCheckedStatus] = useState(false);
return (
<RadioButton
id="radio-button"
label="Click me to toggle me"
subLabel="I am only a radio button input"
checked={checkedStatus}
onClick={() => setCheckedStatus(!checkedStatus)}
/>
);
}
import React, { useState } from 'react';
import { RadioButtonGroup } from '@highlight-ui/radio-button';
export default function RadioButtonGroupExample() {
const [checked, setChecked] = useState<string | number | undefined>(
undefined,
);
const options = [
{ value: 'option-a', label: 'Option A', subLabel: 'Most important' },
{ value: 'option-b', label: 'Option B', subLabel: 'Average' },
{ value: 'option-c', label: 'Option C', subLabel: 'Lowest priority' },
];
return (
<RadioButtonGroup
name="RadioButton-group"
orientation="horizontal"
options={options}
value={checked}
onChange={(option) => setChecked(option.value)}
/>
);
}
All
HTMLInputElement
and [PropsWithMetadata(https://gitlab.personio-internal.de/personio/platform/highlight-ui/-/blob/master/packages/utils/commons/src/types.ts#L24)] props are accepted with this component. In addition to these, this component has the following props
Prop | Type | Required | Default | Description |
---|---|---|---|---|
label | string | No | null | Text displayed next to the radio button input |
subLabel | string | No | null | Text displayed below the main label |
tooltipContent | React.ReactNode | No | null | The content of the tooltip pop-out. When supplied, a tooltip will be placed next to the label. This maps to the TooltipProps['content'] prop types. |
tooltipMouseOutDelay | 'none' , 'medium' , 'long' , or number | No | null | Specifies how to to keep the tooltip opened after the mouse has left the tooltip icon. This maps to the TooltipProps['mouseOutDelay'] prop types. |
tone | default or error | No | default | Sets the tone of the radio button |
Note that the RadioButtonGroupOption
type matches the RadioButton
listed properties above.
Prop | Type | Required | Default | Description |
---|---|---|---|---|
value | RadioButtonGroupOption['value'] | Yes | Currently checked value | |
onChange | function(option: RadioButtonGroupOption): void | Yes | Function called when the checked status of an option changes | |
orientation | vertical or horizontal | No | vertical | Display of the radio button group |
options | RadioButtonGroupOption[] | Yes | Options to render as a group |
Following base accesibility guidelines, the radio-button input currently:
for
prop referring to the id
Potential future improvements to make it more accessible:
aria
tags to indicate checked and disabled statesThere are a number of unit tests covering the RadioButton
and RadioButtonGroup
components, the snippets below can serve as a base to expand future testing if new behaviours are added.
The relevant render methods provide the option to add or override prop values.
import React from 'react';
import { render } from '@testing-library/react';
import { RadioButton, RadioButtonProps } from '@highlight-ui/radio-button';
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
type RadioButtonWrapperProps = Optional<
RadioButtonProps,
'checked' | 'onClick'
>;
function RadioButtonWrapper(props: RadioButtonWrapperProps) {
const [checked, setChecked] = useState(false);
return (
<RadioButton
checked={checked}
onClick={() => setChecked(!checked)}
{...props}
/>
);
}
describe('RadioButtonTest', () => {
const renderRadioButtonWrapper = (props: RadioButtonWrapperProps) => {
return render(<RadioButtonWrapper {...props} />);
};
it('test description', () => {
renderRadioButtonWrapper({});
// write your expect here
});
});
import React from 'react';
import { render } from '@testing-library/react';
import { RadioButtonGroup, RadioButtonGroupProps, RadioButtonGroupOption } from '@highlight-ui/radio-button';
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
type RadioButtonGroupWrapperProps = Optional<
RadioButtonGroupProps,
'value' | 'onChange' | 'options'
>;
function RadioButtonGroupWrapper(props: RadioButtonGroupWrapperProps) {
const [checked, setChecked] = useState<string | number | undefined>(
undefined,
);
const options = [
{ value: 'option-a', label: 'Option A', subLabel: 'Most important' },
{ value: 'option-b', label: 'Option B', subLabel: 'Average' },
{ value: 'option-c', label: 'Option C', subLabel: 'Lowest priority' },
];
return (
<RadioButtonGroup
name="RadioButton-group"
options={options}
value={checked}
onChange={(option) => setChecked(option.value)}
{...props}
/>
);
}
describe('RadioButtonGroupTest', () => {
const renderRadioButtonGroupWrapper = (props: RadioButtonGroupWrapperProps) => {
return render(<RadioButtonWrapper {...props} />);
};
it('test description', () => {
renderRadioButtonGroupWrapper({});
// write your expect here
});
};
The radio button and radio button group are components currently unused in other components and packages.
Please visit personio.design for usage guidelines and visual examples.
If you're interested in contributing, please visit our contribution page.
FAQs
This is the Radio Button package used in Personio
The npm package @highlight-ui/radio-button receives a total of 39 weekly downloads. As such, @highlight-ui/radio-button popularity was classified as not popular.
We found that @highlight-ui/radio-button demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.