/* eslint-disable @eslint-react/dom/no-missing-button-type */ /* eslint-disable react-perf/jsx-no-new-function-as-prop */ import type { Meta, StoryObj } from '@storybook/react'; import type { SimpleElement } from '../../.storybook/decorators/with-simple-data'; import { HTMLNode, RenderItemDecorator } from '../../.storybook/decorators/with-simple-data'; import { useUpdateElement } from './use-update-element'; import { makeRootDocumentation, makeStory } from '@joint/react/src/stories/utils/make-story'; import { getAPILink } from '@joint/react/src/stories/utils/get-api-documentation-link'; import '../stories/examples/index.css'; import { BUTTON_CLASSNAME } from 'storybook-config/theme'; const API_URL = getAPILink('useUpdateElement'); export type Story = StoryObj; const meta: Meta = { title: 'Hooks/useUpdateElement', component: Hook, render: () => , parameters: makeRootDocumentation({ apiURL: API_URL, description: `\`useUpdateElement\` is a hook to set element attributes. It returns a function to set the element attribute. It must be used inside the GraphProvider. `, code: `import { useUpdateElement } from '@joint/react' function Component() { const setPosition = useUpdateElement('element-id', 'position'); return ; }`, }), }; export default meta; function Hook({ label, id }: SimpleElement) { const setLabel = useUpdateElement(id, 'label'); return ( label: {label} ); } export const Default: Story = makeStory({ args: { label: 'default', color: 'red', id: 'default-id', }, apiURL: API_URL, code: `import { useUpdateElement } from '@joint/react' function Hook({ label , id }: SimpleElement) { const setLabel = useUpdateElement(id, 'label'); return ( label: {label} ); }`, description: 'Set new data for the element.', }); function HookSetPosition({ label, id }: SimpleElement) { const set = useUpdateElement(id, 'position'); return ( label: {label} ); } export const SetPosition: Story = makeStory({ component: () => , apiURL: API_URL, code: `import { useUpdateElement } from '@joint/react' function HookSetPosition({ label, id }: SimpleElement) { const set = useUpdateElement(id, 'position'); return ( label: {label} ); } `, description: 'Set the position of the element.', }); function HookSetSize({ label, id }: SimpleElement) { const set = useUpdateElement(id, 'size'); return ( label: {label} ); } export const SetSize: Story = makeStory({ component: () => , apiURL: API_URL, code: `import { useUpdateElement } from '@joint/react' function HookSetSize({ label, id }: SimpleElement) { const set = useUpdateElement(id, 'size'); return ( label: {label} ); }`, description: 'Set the size of the element.', }); function HookSetAngle({ label, id }: SimpleElement) { const set = useUpdateElement(id, 'angle'); return ( label: {label} ); } export const SetAngle: Story = makeStory({ component: () => , apiURL: API_URL, code: `function HookSetAngle({ label, id }: SimpleElement) { const set = useUpdateElement(id, 'angle'); return ( label: {label} ); }`, description: 'Set the angle of the element.', }); function HookSetAny({ label, id }: SimpleElement) { const set = useUpdateElement(id); return ( label: {label} ); } export const SetAnyProperty: Story = makeStory({ apiURL: API_URL, component: () => , code: `import { useUpdateElement } from '@joint/react' function HookSetAny({ label , id }: SimpleElement) { const set = useUpdateElement(id); return ( label: {label} ); }`, description: 'Set the markup of the element.', });