![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@snack-uikit/toggles
Advanced tools
Компоненты, реализующие переключатели.
npm i @snack-uikit/toggles
Хук для элементов внутри группы переключателей.
value: string
Уникальное значение для элемента в группе
function ToggleCard(props: ToggleCardProps) {
const { isChecked, handleClick, multipleSelection } = useToggleGroup(props.id);
return (
<Card {...props} checked={isChecked} onClick={handleClick} multipleSelection={multipleSelection}/>
);
}
const [value, setValue] = useState<string | undefined>(undefined);
function ToggleCard(props: ToggleCardProps) {
const { isChecked, handleClick, multipleSelection } = useToggleGroup(id);
return (
<Card {...props} checked={isChecked} onClick={handleClick} multipleSelection={multipleSelection}/>
);
}
// ITEMS -some array with ToggleCardProps
// ...
return (
<ToggleGroup selectionMode='single' value={value} onChange={setValue}>
{ITEMS.map(props => (
<ToggleCard key={props.id} {...props} />
))}
</ToggleGroup>
);
// ...
return (
<>
{items.map(({ checked, setChecked, data }) =>
<CustomRadioButton
// повторяет нативное поведение радиогруппы: по клику можно выбрать, но нельзя снять выбор
onClick={() => setChecked(true)}
checked={checked}
data={data}
/>
)}
</>
);
name | type | default value | description |
---|---|---|---|
id | string | - | HTML-аттрибут id |
name | string | - | HTML-аттрибут name |
value | string | - | HTML-аттрибут value |
tabIndex | number | - | HTML-аттрибут tab-index |
autofocus | boolean | - | HTML-аттрибут autofocus |
checked | boolean | - | HTML-аттрибут checked |
defaultChecked | boolean | - | HTML-аттрибут checked по-умолчанию |
disabled | boolean | - | HTML-аттрибут disabled |
onChange | (checked: boolean) => void | - | Колбек смены значения |
onClick | MouseEventHandler<HTMLInputElement> | - | Колбек клика |
onBlur | FocusEventHandler<HTMLInputElement> | - | Колбек потери фокуса |
onFocus | FocusEventHandler<HTMLInputElement> | - | Колбек приобретения фокуса |
className | string | - | CSS-класс |
size | enum Size: "s" , "m" | m | Размер |
inputRef | RefObject<HTMLInputElement> | - | |
indeterminate | boolean | - | Состояние частичного выбора |
indeterminateDefault | boolean | - | Состояние частичного выбора по-умолчанию |
name | type | default value | description |
---|---|---|---|
id | string | - | HTML-аттрибут id |
name | string | - | HTML-аттрибут name |
value | string | - | HTML-аттрибут value |
tabIndex | number | - | HTML-аттрибут tab-index |
autofocus | boolean | - | HTML-аттрибут autofocus |
checked | boolean | - | HTML-аттрибут checked |
defaultChecked | boolean | - | HTML-аттрибут checked по-умолчанию |
disabled | boolean | - | HTML-аттрибут disabled |
onChange | (checked: boolean) => void | - | Колбек смены значения |
onClick | MouseEventHandler<HTMLInputElement> | - | Колбек клика |
onBlur | FocusEventHandler<HTMLInputElement> | - | Колбек потери фокуса |
onFocus | FocusEventHandler<HTMLInputElement> | - | Колбек приобретения фокуса |
className | string | - | CSS-класс |
size | enum Size: "s" , "m" | m | Размер |
inputRef | RefObject<HTMLInputElement> | - | |
showIcon | boolean | - | Показывать ли иконку в переключателе |
loading | boolean | - |
name | type | default value | description |
---|---|---|---|
id | string | - | HTML-аттрибут id |
name | string | - | HTML-аттрибут name |
value | string | - | HTML-аттрибут value |
tabIndex | number | - | HTML-аттрибут tab-index |
autofocus | boolean | - | HTML-аттрибут autofocus |
checked | boolean | - | HTML-аттрибут checked |
defaultChecked | boolean | - | HTML-аттрибут checked по-умолчанию |
disabled | boolean | - | HTML-аттрибут disabled |
onChange | (checked: boolean) => void | - | Колбек смены значения |
onClick | MouseEventHandler<HTMLInputElement> | - | Колбек клика |
onBlur | FocusEventHandler<HTMLInputElement> | - | Колбек потери фокуса |
onFocus | FocusEventHandler<HTMLInputElement> | - | Колбек приобретения фокуса |
className | string | - | CSS-класс |
size | enum Size: "s" , "m" | - | Размер |
inputRef | RefObject<HTMLInputElement> | - |
name | type | default value | description |
---|---|---|---|
id | string | - | HTML-аттрибут id |
name | string | - | HTML-аттрибут name |
value | string | - | HTML-аттрибут value |
tabIndex | number | - | HTML-аттрибут tab-index |
autofocus | boolean | - | HTML-аттрибут autofocus |
checked | boolean | - | HTML-аттрибут checked |
defaultChecked | boolean | - | HTML-аттрибут checked по-умолчанию |
onChange | (checked: boolean) => void | - | Колбек смены значения |
onClick | MouseEventHandler<HTMLInputElement> | - | Колбек клика |
onBlur | FocusEventHandler<HTMLInputElement> | - | Колбек потери фокуса |
onFocus | FocusEventHandler<HTMLInputElement> | - | Колбек приобретения фокуса |
className | string | - | CSS-класс |
size | enum Size: "s" , "m" | m | Размер |
inputRef | RefObject<HTMLInputElement> | - | |
icon | enum FavoriteIcon: "star" , "heart" | heart | Иконка |
name | type | default value | description |
---|---|---|---|
children* | ReactNode | - | Вложенный контент |
defaultValue | string | string[] | - | Начальное состояние |
value | string | string[] | - | Controlled состояние |
onChange | ((value: string) => void) | ((value: string[]) => void) | - | Controlled обработчик измения состояния |
selectionMode | "single" | "multiple" | single | Режим выбора |
name | type | default value | description |
---|---|---|---|
value* | string | - |
FAQs
Unknown package
We found that @snack-uikit/toggles demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.