UNPKG

@storybook/addon-ondevice-controls

Version:

Display storybook controls on your device.

30 lines (29 loc) 1.2 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useState } from 'react'; import { useResyncValue } from './useResyncValue'; import { Input } from './common'; function formatArray(value, separator) { if (value === '') { return []; } return value.split(separator); } const ArrayType = ({ arg: { name, value, separator = ',' }, onChange = () => null, isPristine, }) => { const { setCurrentValue, key } = useResyncValue(value, isPristine); const [focused, setFocused] = useState(false); return (_jsx(Input, { testID: name, underlineColorAndroid: "transparent", autoCapitalize: "none", defaultValue: value?.join(separator), onChangeText: (text) => { const formatted = formatArray(text, separator); onChange(formatted); setCurrentValue(formatted); }, onFocus: () => setFocused(true), onBlur: () => setFocused(false), focused: focused }, key)); }; ArrayType.serialize = (value) => value; ArrayType.deserialize = (value) => { if (Array.isArray(value)) { return value; } return Object.keys(value) .sort() .reduce((array, key) => [...array, value[key]], []); }; export default ArrayType;