FormTools.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import Button from '../components/Button';
  4. import Icon from '../components/Icon';
  5. import ExpansionPanel from '../components/ExpansionPanel';
  6. import TextfieldTool from './TextfieldTool';
  7. import CheckboxTool from './CheckboxTool';
  8. import RadioButtonTool from './RadioButtonTool';
  9. import useStore from '../store';
  10. import useActions from '../actions';
  11. type Props = {
  12. sidebarState: string;
  13. onClickSidebar: (state: string) => void;
  14. };
  15. const FormTools: React.FC<Props> = ({
  16. sidebarState,
  17. onClickSidebar,
  18. }: Props) => {
  19. const { t } = useTranslation('sidebar');
  20. const [{ toolState }, dispatch] = useStore();
  21. const { setTool } = useActions(dispatch);
  22. const isActive = sidebarState === 'create-form';
  23. const onClickTool = (state: string): void => {
  24. if (state === toolState) {
  25. setTool('');
  26. } else {
  27. setTool(state);
  28. }
  29. };
  30. const Label = (
  31. <Button
  32. shouldFitContainer
  33. align="left"
  34. onClick={(): void => {
  35. onClickSidebar('create-form');
  36. }}
  37. >
  38. <Icon glyph="create-form" style={{ marginRight: '10px' }} />
  39. {t('createForm')}
  40. <Icon
  41. glyph="dropdown-arrow"
  42. style={{
  43. transform: isActive ? 'rotate(180deg)' : 'rotate(0deg)',
  44. marginLeft: '10px',
  45. }}
  46. />
  47. </Button>
  48. );
  49. return (
  50. <ExpansionPanel label={Label} isActive={isActive}>
  51. <TextfieldTool
  52. title={t('textField')}
  53. isActive={toolState === 'textfield'}
  54. onClick={(): void => {
  55. onClickTool('textfield');
  56. }}
  57. />
  58. <CheckboxTool
  59. title={t('checkBox')}
  60. isActive={toolState === 'checkbox'}
  61. onClick={(): void => {
  62. onClickTool('checkbox');
  63. }}
  64. />
  65. <RadioButtonTool
  66. title={t('radioButton')}
  67. isActive={toolState === 'radio'}
  68. onClick={(): void => {
  69. onClickTool('radio');
  70. }}
  71. />
  72. </ExpansionPanel>
  73. );
  74. };
  75. export default FormTools;