|
| 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 | +}; |
0 commit comments