import type { Meta, StoryFn } from '@storybook/react'; import { useCallback, useRef, useState } from 'react'; import { Button } from '../button'; import { ResizePanel } from '../resize-panel/resize-panel'; import type { InlineEditHandle } from './inline-edit'; import { InlineEdit } from './inline-edit'; export default { title: 'UI/Editable/Inline Edit', component: InlineEdit, } satisfies Meta; const Template: StoryFn = args => { const [value, setValue] = useState(args.value || ''); return (
Value: {value}
setValue(v)} {...args} />
); }; export const Basic: StoryFn = Template.bind(undefined); Basic.args = { editable: true, placeholder: 'Untitled', trigger: 'doubleClick', autoSelect: true, }; export const CustomizeText: StoryFn = Template.bind(undefined); CustomizeText.args = { value: 'Customize Text', editable: true, placeholder: 'Untitled', style: { fontSize: 20, fontWeight: 500, padding: '10px 20px', }, }; export const TriggerEdit: StoryFn = args => { const ref = useRef(null); const triggerEdit = useCallback(() => { if (!ref.current) return; ref.current.triggerEdit(); }, []); return ( <>
); }; TriggerEdit.args = { value: 'Trigger edit mode in parent component by `handleRef`', editable: true, autoSelect: true, }; export const UpdateValue: StoryFn = args => { const [value, setValue] = useState(args.value || ''); const appendA = useCallback(() => { setValue(v => v + 'a'); }, []); return ( <>
); }; UpdateValue.args = { value: 'Update value in parent component by `value`', editable: true, autoSelect: true, };