Skip to content

Commit 3f3a75f

Browse files
committed
picker-stories
1 parent f6d2b18 commit 3f3a75f

File tree

8 files changed

+199
-4
lines changed

8 files changed

+199
-4
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"expose-loader": "^3.1.0",
2020
"jquery": "^3.6.0",
2121
"react": "^17.0.1",
22-
"react-declarative": "^1.6.7",
22+
"react-declarative": "^1.6.8",
2323
"react-dom": "^17.0.1"
2424
},
2525
"scripts": {

src/components/PickerWrapper.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
3+
import { ModalProvider } from 'react-declarative';
4+
5+
interface IPickerWrapperProps {
6+
children: React.ReactChild;
7+
}
8+
9+
export const PickerWrapper = ({
10+
children,
11+
}: IPickerWrapperProps) => (
12+
<ModalProvider>
13+
{children}
14+
</ModalProvider>
15+
);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useConfirm } from 'react-declarative';
2+
3+
import { action } from '@storybook/addon-actions';
4+
5+
import { Button } from '@mui/material';
6+
7+
import { PickerWrapper } from '../../../components/PickerWrapper';
8+
9+
const Picker = () => {
10+
const pickConfirm = useConfirm({
11+
title: 'Example Confirm',
12+
msg: 'Some text',
13+
});
14+
const handleClick = () => pickConfirm().then(action('picker'));
15+
return (
16+
<Button onClick={handleClick}>
17+
Click me
18+
</Button>
19+
);
20+
};
21+
22+
const View = () => (
23+
<PickerWrapper>
24+
<Picker />
25+
</PickerWrapper>
26+
);
27+
28+
export const Confirm = View.bind({});
29+
30+
export default {
31+
title: 'One/Pickers',
32+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useDate } from 'react-declarative';
2+
3+
import { action } from '@storybook/addon-actions';
4+
5+
import { Button } from '@mui/material';
6+
7+
import { PickerWrapper } from '../../../components/PickerWrapper';
8+
9+
const Picker = () => {
10+
const pickConfirm = useDate();
11+
const handleClick = () => pickConfirm().then(action('picker'));
12+
return (
13+
<Button onClick={handleClick}>
14+
Click me
15+
</Button>
16+
);
17+
};
18+
19+
const View = () => (
20+
<PickerWrapper>
21+
<Picker />
22+
</PickerWrapper>
23+
);
24+
25+
export const Date = View.bind({});
26+
27+
export default {
28+
title: 'One/Pickers',
29+
};
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { FieldType, IField, useOne } from 'react-declarative';
2+
3+
import { action } from '@storybook/addon-actions';
4+
5+
import { Button } from '@mui/material';
6+
7+
import { PickerWrapper } from '../../../components/PickerWrapper';
8+
9+
import { rnd } from '../../../utils/rnd';
10+
11+
const fields: IField[] = [
12+
{
13+
type: FieldType.Hero,
14+
minWidth: '360px',
15+
minHeight: ({ reason }) => reason === 'moderation-request' ? '250px' : '140px',
16+
child: {
17+
type: FieldType.Group,
18+
fields: [
19+
{
20+
type: FieldType.Text,
21+
name: 'dropperUserId',
22+
fieldBottomMargin: '1',
23+
fieldRightMargin: '0',
24+
title: 'Dropper',
25+
outlined: false,
26+
readonly: true,
27+
disabled: true,
28+
},
29+
{
30+
type: FieldType.Radio,
31+
name: 'reason',
32+
fieldBottomMargin: '0',
33+
fieldRightMargin: '0',
34+
title: 'I lost the competition',
35+
radioValue: 'competition-lose',
36+
defaultValue: 'competition-lose',
37+
},
38+
{
39+
type: FieldType.Radio,
40+
name: 'reason',
41+
fieldBottomMargin: '1',
42+
fieldRightMargin: '0',
43+
title: 'Moderation required',
44+
radioValue: 'moderation-request',
45+
},
46+
{
47+
type: FieldType.Text,
48+
name: 'comment',
49+
title: 'Comment',
50+
placeholder: 'A few words about competition',
51+
autoFocus: true,
52+
fieldBottomMargin: '0',
53+
fieldRightMargin: '0',
54+
isVisible: ({ reason }) => reason === 'moderation-request',
55+
inputRows: 3,
56+
outlined: true,
57+
}
58+
]
59+
}
60+
},
61+
];
62+
63+
const Picker = () => {
64+
const pickConfirm = useOne({
65+
title: 'Finish competition',
66+
handler: {
67+
dropperUserId: rnd(),
68+
},
69+
fields,
70+
});
71+
const handleClick = () => pickConfirm().then(action('picker'));
72+
return (
73+
<Button onClick={handleClick}>
74+
Click me
75+
</Button>
76+
);
77+
};
78+
79+
const View = () => (
80+
<PickerWrapper>
81+
<Picker />
82+
</PickerWrapper>
83+
);
84+
85+
export const One = View.bind({});
86+
87+
export default {
88+
title: 'One/Pickers',
89+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useTime } from 'react-declarative';
2+
3+
import { action } from '@storybook/addon-actions';
4+
5+
import { Button } from '@mui/material';
6+
7+
import { PickerWrapper } from '../../../components/PickerWrapper';
8+
9+
const Picker = () => {
10+
const pickConfirm = useTime();
11+
const handleClick = () => pickConfirm().then(action('picker'));
12+
return (
13+
<Button onClick={handleClick}>
14+
Click me
15+
</Button>
16+
);
17+
};
18+
19+
const View = () => (
20+
<PickerWrapper>
21+
<Picker />
22+
</PickerWrapper>
23+
);
24+
25+
export const Time = View.bind({});
26+
27+
export default {
28+
title: 'One/Pickers',
29+
};

src/utils/rnd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const rnd = () => (Math.random() + 1).toString(36).substring(7);

0 commit comments

Comments
 (0)