UNPKG

@storybook/addon-ondevice-controls

Version:

Display storybook controls on your device.

38 lines (37 loc) 1.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const RadioSelect_1 = __importDefault(require("../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_1.default.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_1.default.useCallback((option) => onChange(option.key), [onChange]); return ((0, jsx_runtime_1.jsx)(RadioSelect_1.default, { isInline: arg.type === 'inline-radio', data: data, value: arg.value, onChange: onChangeOption })); }; RadioType.serialize = (value) => value; RadioType.deserialize = (value) => value; exports.default = RadioType;