UNPKG

@storybook/addon-ondevice-controls

Version:

Display storybook controls on your device.

33 lines (32 loc) 1.21 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from 'react'; import RadioSelect from '../components/RadioSelect'; const getOptions = (arg) => { if (arg.options) { return arg.options; } if (arg.control?.options) { return arg.control.options; } return []; }; const RadioType = ({ onChange, arg }) => { const data = React.useMemo(() => { const options = getOptions(arg); if (Array.isArray(options)) { if (arg.control?.labels && Array.isArray(arg.control.labels)) { return options.map((val, i) => ({ key: val, label: arg.control.labels.at(i) ?? val })); } return options.map((val) => ({ key: val, label: val })); } return Object.keys(options).map((key) => ({ label: key, key: options[key], })); }, [arg]); const onChangeOption = React.useCallback((option) => onChange(option.key), [onChange]); return (_jsx(RadioSelect, { isInline: arg.type === 'inline-radio', data: data, value: arg.value, onChange: onChangeOption })); }; RadioType.serialize = (value) => value; RadioType.deserialize = (value) => value; export default RadioType;