Skip to content

Commit 49a3ecf

Browse files
committed
docs: add boolean widget stories
1 parent a947ff8 commit 49a3ecf

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { StoryObj } from '@storybook/react-webpack5';
2+
import { MantineThemeDecorator } from '../../docs/MantineThemeDecorator';
3+
import { UseEditorOptions, useEditor, Widget, DefaultNodeOptions } from '@sagold/react-json-editor';
4+
5+
type WidgetProps = DefaultNodeOptions & { editorProps: UseEditorOptions };
6+
function WidgetForm({ editorProps, ...props }: WidgetProps) {
7+
const editor = useEditor(editorProps);
8+
return <Widget editor={editor} options={props} />;
9+
}
10+
11+
export default {
12+
title: 'packages/rje-mantine-widgets/widgets/BooleanWidget',
13+
component: WidgetForm,
14+
decorators: [MantineThemeDecorator],
15+
argTypes: {
16+
disabled: { control: 'boolean' },
17+
showHeader: { control: 'boolean' },
18+
title: { control: 'text' },
19+
description: { control: 'text' }
20+
},
21+
args: {
22+
editorProps: {
23+
data: null,
24+
onChange: (v) => console.log(`change:`, v),
25+
schema: {
26+
title: 'A boolean value',
27+
description: 'Toggle input',
28+
type: 'boolean'
29+
}
30+
}
31+
}
32+
};
33+
34+
type Story = StoryObj<WidgetProps>;
35+
36+
export const Options: Story = {
37+
args: {
38+
disabled: false,
39+
showHeader: true
40+
}
41+
};
42+
43+
export const Disabled: Story = {
44+
args: {
45+
disabled: true
46+
}
47+
};
48+
49+
export const SwitchWidget: Story = {
50+
args: {
51+
editorProps: {
52+
data: '',
53+
onChange: (v) => console.log(`change: '${v}'`, typeof v),
54+
schema: {
55+
title: 'A boolean value',
56+
description: 'Toggle input',
57+
type: 'boolean',
58+
format: 'switch'
59+
}
60+
}
61+
}
62+
};

packages/rje-mantine-widgets/src/widgets/BooleanWidget.tsx renamed to packages/rje-mantine-widgets/src/widgets/booleanwidget/BooleanWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Checkbox, Switch } from '@mantine/core';
22
import { BooleanNode, WidgetField, WidgetPlugin, widget } from '@sagold/react-json-editor';
3-
import { widgetInputProps } from '../components/widgetInputProps';
3+
import { widgetInputProps } from '../../components/widgetInputProps';
44

55
export const BooleanWidget = widget<BooleanNode, boolean>(({ node, options, setValue }) => {
66
const Input = node.schema.format === 'switch' ? Switch : Checkbox;

packages/rje-mantine-widgets/src/widgets/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ArrayWidgetPlugin } from './arraywidget/ArrayWidget';
2-
import { BooleanWidgetPlugin } from './BooleanWidget';
2+
import { BooleanWidgetPlugin } from './booleanwidget/BooleanWidget';
33
import { MultiSelectWidgetPlugin } from './multiselectwidget/MultiSelect';
44
import { NullWidgetPlugin } from './nullwidget/NullWidget';
55
import { NumberWidgetPlugin } from './NumberWidget';

0 commit comments

Comments
 (0)