|  | 
| 1 | 1 | import * as React from 'react'; | 
| 2 | 2 | import get from 'lodash/get'; | 
| 3 | 3 | import { Control, useForm } from 'react-hook-form'; | 
|  | 4 | +import { useStateMachine } from 'little-state-machine'; | 
| 4 | 5 | import { useEffect } from 'react'; | 
| 5 | 6 | import colors from './colors'; | 
| 6 | 7 | import PanelTable from './panelTable'; | 
| 7 | 8 | import FormStateTable from './formStateTable'; | 
| 8 | 9 | import { Button, Input } from './styled'; | 
|  | 10 | +import { setCollapse } from './settingAction'; | 
| 9 | 11 | 
 | 
| 10 | 12 | export default ({ | 
| 11 | 13 |   control: { fieldsRef, getValues, formState, errorsRef, readFormStateRef }, | 
| 12 | 14 | }: { | 
| 13 | 15 |   control: Control; | 
| 14 | 16 | }) => { | 
|  | 17 | +  const { state, action } = useStateMachine(setCollapse); | 
| 15 | 18 |   const [, setData] = React.useState({}); | 
| 16 |  | -  const [collapseAll, setCollapseAll] = React.useState(true); | 
| 17 | 19 |   const [showFormState, setShowFormState] = React.useState(false); | 
| 18 | 20 |   const fieldsValues = getValues(); | 
| 19 | 21 |   const { register, watch } = useForm(); | 
| 20 | 22 |   const searchTerm = watch('search', ''); | 
| 21 | 23 | 
 | 
|  | 24 | +  console.log(state) | 
|  | 25 | + | 
| 22 | 26 |   useEffect(() => { | 
| 23 | 27 |     setData({}); | 
| 24 | 28 |   }, []); | 
| @@ -58,9 +62,12 @@ export default ({ | 
| 58 | 62 |             lineHeight: 1, | 
| 59 | 63 |           }} | 
| 60 | 64 |           title="Toggle entire fields" | 
| 61 |  | -          onClick={() => setCollapseAll(!collapseAll)} | 
|  | 65 | +          onClick={() => { | 
|  | 66 | +            // @ts-ignore | 
|  | 67 | +            action(!state.isCollapse); | 
|  | 68 | +          }} | 
| 62 | 69 |         > | 
| 63 |  | -          {collapseAll ? '[-] COLLAPSE' : '[+] EXPAND'} | 
|  | 70 | +          {state.isCollapse ? '[-] COLLAPSE' : '[+] EXPAND'} | 
| 64 | 71 |         </Button> | 
| 65 | 72 | 
 | 
| 66 | 73 |         <Input | 
| @@ -123,7 +130,7 @@ export default ({ | 
| 123 | 130 |                 <PanelTable | 
| 124 | 131 |                   refObject={ref} | 
| 125 | 132 |                   index={index} | 
| 126 |  | -                  collapseAll={collapseAll} | 
|  | 133 | +                  collapseAll={state.isCollapse} | 
| 127 | 134 |                   name={name} | 
| 128 | 135 |                   isTouched={isTouched} | 
| 129 | 136 |                   type={type} | 
|  | 
0 commit comments