@toptal/picasso-forms 6.0.4 → 6.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/CHANGELOG.md +657 -0
  2. package/{Autocomplete → dist-package/Autocomplete}/Autocomplete.d.ts +0 -0
  3. package/{Autocomplete → dist-package/Autocomplete}/Autocomplete.js +0 -0
  4. package/{Autocomplete → dist-package/Autocomplete}/Autocomplete.js.map +0 -0
  5. package/{Autocomplete → dist-package/Autocomplete}/index.d.ts +0 -0
  6. package/{Autocomplete → dist-package/Autocomplete}/index.js +0 -0
  7. package/{Autocomplete → dist-package/Autocomplete}/index.js.map +0 -0
  8. package/{ButtonCheckbox → dist-package/ButtonCheckbox}/ButtonCheckbox.d.ts +0 -0
  9. package/{ButtonCheckbox → dist-package/ButtonCheckbox}/ButtonCheckbox.js +0 -0
  10. package/{ButtonCheckbox → dist-package/ButtonCheckbox}/ButtonCheckbox.js.map +0 -0
  11. package/{ButtonCheckbox → dist-package/ButtonCheckbox}/index.d.ts +0 -0
  12. package/{ButtonCheckbox → dist-package/ButtonCheckbox}/index.js +0 -0
  13. package/{ButtonCheckbox → dist-package/ButtonCheckbox}/index.js.map +0 -0
  14. package/{ButtonRadio → dist-package/ButtonRadio}/ButtonRadio.d.ts +0 -0
  15. package/{ButtonRadio → dist-package/ButtonRadio}/ButtonRadio.js +0 -0
  16. package/{ButtonRadio → dist-package/ButtonRadio}/ButtonRadio.js.map +0 -0
  17. package/{ButtonRadio → dist-package/ButtonRadio}/index.d.ts +0 -0
  18. package/{ButtonRadio → dist-package/ButtonRadio}/index.js +0 -0
  19. package/{ButtonRadio → dist-package/ButtonRadio}/index.js.map +0 -0
  20. package/{Checkbox → dist-package/Checkbox}/Checkbox.d.ts +0 -0
  21. package/{Checkbox → dist-package/Checkbox}/Checkbox.js +0 -0
  22. package/{Checkbox → dist-package/Checkbox}/Checkbox.js.map +0 -0
  23. package/{Checkbox → dist-package/Checkbox}/index.d.ts +0 -0
  24. package/{Checkbox → dist-package/Checkbox}/index.js +0 -0
  25. package/{Checkbox → dist-package/Checkbox}/index.js.map +0 -0
  26. package/{CheckboxGroup → dist-package/CheckboxGroup}/CheckboxGroup.d.ts +0 -0
  27. package/{CheckboxGroup → dist-package/CheckboxGroup}/CheckboxGroup.js +0 -0
  28. package/{CheckboxGroup → dist-package/CheckboxGroup}/CheckboxGroup.js.map +0 -0
  29. package/{CheckboxGroup → dist-package/CheckboxGroup}/CheckboxGroupContext.d.ts +0 -0
  30. package/{CheckboxGroup → dist-package/CheckboxGroup}/CheckboxGroupContext.js +0 -0
  31. package/{CheckboxGroup → dist-package/CheckboxGroup}/CheckboxGroupContext.js.map +0 -0
  32. package/{CheckboxGroup → dist-package/CheckboxGroup}/index.d.ts +0 -0
  33. package/{CheckboxGroup → dist-package/CheckboxGroup}/index.js +0 -0
  34. package/{CheckboxGroup → dist-package/CheckboxGroup}/index.js.map +0 -0
  35. package/{DatePicker → dist-package/DatePicker}/DatePicker.d.ts +0 -0
  36. package/{DatePicker → dist-package/DatePicker}/DatePicker.js +0 -0
  37. package/{DatePicker → dist-package/DatePicker}/DatePicker.js.map +0 -0
  38. package/{DatePicker → dist-package/DatePicker}/index.d.ts +0 -0
  39. package/{DatePicker → dist-package/DatePicker}/index.js +0 -0
  40. package/{DatePicker → dist-package/DatePicker}/index.js.map +0 -0
  41. package/{FieldWrapper → dist-package/FieldWrapper}/FieldWrapper.d.ts +0 -0
  42. package/{FieldWrapper → dist-package/FieldWrapper}/FieldWrapper.js +0 -0
  43. package/{FieldWrapper → dist-package/FieldWrapper}/FieldWrapper.js.map +0 -0
  44. package/{FieldWrapper → dist-package/FieldWrapper}/index.d.ts +0 -0
  45. package/{FieldWrapper → dist-package/FieldWrapper}/index.js +0 -0
  46. package/{FieldWrapper → dist-package/FieldWrapper}/index.js.map +0 -0
  47. package/{FileInput → dist-package/FileInput}/FileInput.d.ts +0 -0
  48. package/{FileInput → dist-package/FileInput}/FileInput.js +0 -0
  49. package/{FileInput → dist-package/FileInput}/FileInput.js.map +0 -0
  50. package/{FileInput → dist-package/FileInput}/index.d.ts +0 -0
  51. package/{FileInput → dist-package/FileInput}/index.js +0 -0
  52. package/{FileInput → dist-package/FileInput}/index.js.map +0 -0
  53. package/{Form → dist-package/Form}/Form.d.ts +0 -0
  54. package/{Form → dist-package/Form}/Form.js +0 -0
  55. package/{Form → dist-package/Form}/Form.js.map +0 -0
  56. package/{Form → dist-package/Form}/FormContext.d.ts +0 -0
  57. package/{Form → dist-package/Form}/FormContext.js +0 -0
  58. package/{Form → dist-package/Form}/FormContext.js.map +0 -0
  59. package/{Form → dist-package/Form}/index.d.ts +0 -0
  60. package/{Form → dist-package/Form}/index.js +0 -0
  61. package/{Form → dist-package/Form}/index.js.map +0 -0
  62. package/{FormConfig → dist-package/FormConfig}/FormConfig.d.ts +0 -0
  63. package/{FormConfig → dist-package/FormConfig}/FormConfig.js +0 -0
  64. package/{FormConfig → dist-package/FormConfig}/FormConfig.js.map +0 -0
  65. package/{FormConfig → dist-package/FormConfig}/index.d.ts +0 -0
  66. package/{FormConfig → dist-package/FormConfig}/index.js +0 -0
  67. package/{FormConfig → dist-package/FormConfig}/index.js.map +0 -0
  68. package/{Input → dist-package/Input}/Input.d.ts +0 -0
  69. package/{Input → dist-package/Input}/Input.js +0 -0
  70. package/{Input → dist-package/Input}/Input.js.map +0 -0
  71. package/{Input → dist-package/Input}/index.d.ts +0 -0
  72. package/{Input → dist-package/Input}/index.js +0 -0
  73. package/{Input → dist-package/Input}/index.js.map +0 -0
  74. package/{Input → dist-package/Input}/utils/get-input-name.d.ts +0 -0
  75. package/{Input → dist-package/Input}/utils/get-input-name.js +0 -0
  76. package/{Input → dist-package/Input}/utils/get-input-name.js.map +0 -0
  77. package/{Input → dist-package/Input}/utils/get-input-name.test.d.ts +0 -0
  78. package/{Input → dist-package/Input}/utils/get-input-name.test.js +0 -0
  79. package/{Input → dist-package/Input}/utils/get-input-name.test.js.map +0 -0
  80. package/{NumberInput → dist-package/NumberInput}/NumberInput.d.ts +0 -0
  81. package/{NumberInput → dist-package/NumberInput}/NumberInput.js +0 -0
  82. package/{NumberInput → dist-package/NumberInput}/NumberInput.js.map +0 -0
  83. package/{NumberInput → dist-package/NumberInput}/index.d.ts +0 -0
  84. package/{NumberInput → dist-package/NumberInput}/index.js +0 -0
  85. package/{NumberInput → dist-package/NumberInput}/index.js.map +0 -0
  86. package/dist-package/README.md +29 -0
  87. package/{Radio → dist-package/Radio}/Radio.d.ts +0 -0
  88. package/{Radio → dist-package/Radio}/Radio.js +0 -0
  89. package/{Radio → dist-package/Radio}/Radio.js.map +0 -0
  90. package/{Radio → dist-package/Radio}/index.d.ts +0 -0
  91. package/{Radio → dist-package/Radio}/index.js +0 -0
  92. package/{Radio → dist-package/Radio}/index.js.map +0 -0
  93. package/{RadioGroup → dist-package/RadioGroup}/RadioGroup.d.ts +0 -0
  94. package/{RadioGroup → dist-package/RadioGroup}/RadioGroup.js +0 -0
  95. package/{RadioGroup → dist-package/RadioGroup}/RadioGroup.js.map +0 -0
  96. package/{RadioGroup → dist-package/RadioGroup}/RadioGroupContext.d.ts +0 -0
  97. package/{RadioGroup → dist-package/RadioGroup}/RadioGroupContext.js +0 -0
  98. package/{RadioGroup → dist-package/RadioGroup}/RadioGroupContext.js.map +0 -0
  99. package/{RadioGroup → dist-package/RadioGroup}/index.d.ts +0 -0
  100. package/{RadioGroup → dist-package/RadioGroup}/index.js +0 -0
  101. package/{RadioGroup → dist-package/RadioGroup}/index.js.map +0 -0
  102. package/{Rating → dist-package/Rating}/Rating.d.ts +0 -0
  103. package/{Rating → dist-package/Rating}/Rating.js +0 -0
  104. package/{Rating → dist-package/Rating}/Rating.js.map +0 -0
  105. package/{Rating → dist-package/Rating}/index.d.ts +0 -0
  106. package/{Rating → dist-package/Rating}/index.js +0 -0
  107. package/{Rating → dist-package/Rating}/index.js.map +0 -0
  108. package/{Select → dist-package/Select}/Select.d.ts +0 -0
  109. package/{Select → dist-package/Select}/Select.js +0 -0
  110. package/{Select → dist-package/Select}/Select.js.map +0 -0
  111. package/{Select → dist-package/Select}/index.d.ts +0 -0
  112. package/{Select → dist-package/Select}/index.js +0 -0
  113. package/{Select → dist-package/Select}/index.js.map +0 -0
  114. package/{SubmitButton → dist-package/SubmitButton}/SubmitButton.d.ts +0 -0
  115. package/{SubmitButton → dist-package/SubmitButton}/SubmitButton.js +0 -0
  116. package/{SubmitButton → dist-package/SubmitButton}/SubmitButton.js.map +0 -0
  117. package/{SubmitButton → dist-package/SubmitButton}/index.d.ts +0 -0
  118. package/{SubmitButton → dist-package/SubmitButton}/index.js +0 -0
  119. package/{SubmitButton → dist-package/SubmitButton}/index.js.map +0 -0
  120. package/{Switch → dist-package/Switch}/Switch.d.ts +0 -0
  121. package/{Switch → dist-package/Switch}/Switch.js +0 -0
  122. package/{Switch → dist-package/Switch}/Switch.js.map +0 -0
  123. package/{Switch → dist-package/Switch}/index.d.ts +0 -0
  124. package/{Switch → dist-package/Switch}/index.js +0 -0
  125. package/{Switch → dist-package/Switch}/index.js.map +0 -0
  126. package/{TagSelector → dist-package/TagSelector}/TagSelector.d.ts +0 -0
  127. package/{TagSelector → dist-package/TagSelector}/TagSelector.js +0 -0
  128. package/{TagSelector → dist-package/TagSelector}/TagSelector.js.map +0 -0
  129. package/{TagSelector → dist-package/TagSelector}/index.d.ts +0 -0
  130. package/{TagSelector → dist-package/TagSelector}/index.js +0 -0
  131. package/{TagSelector → dist-package/TagSelector}/index.js.map +0 -0
  132. package/{TimePicker → dist-package/TimePicker}/TimePicker.d.ts +0 -0
  133. package/{TimePicker → dist-package/TimePicker}/TimePicker.js +0 -0
  134. package/{TimePicker → dist-package/TimePicker}/TimePicker.js.map +0 -0
  135. package/{TimePicker → dist-package/TimePicker}/index.d.ts +0 -0
  136. package/{TimePicker → dist-package/TimePicker}/index.js +0 -0
  137. package/{TimePicker → dist-package/TimePicker}/index.js.map +0 -0
  138. package/{index.d.ts → dist-package/index.d.ts} +2 -1
  139. package/{index.js → dist-package/index.js} +0 -1
  140. package/dist-package/index.js.map +1 -0
  141. package/dist-package/package.json +44 -0
  142. package/{utils → dist-package/utils}/flat-map.d.ts +0 -0
  143. package/{utils → dist-package/utils}/flat-map.js +0 -0
  144. package/{utils → dist-package/utils}/flat-map.js.map +0 -0
  145. package/{utils → dist-package/utils}/index.d.ts +0 -0
  146. package/{utils → dist-package/utils}/index.js +0 -0
  147. package/{utils → dist-package/utils}/index.js.map +0 -0
  148. package/{utils → dist-package/utils}/scroll-to-error-decorator.d.ts +0 -0
  149. package/{utils → dist-package/utils}/scroll-to-error-decorator.js +0 -0
  150. package/{utils → dist-package/utils}/scroll-to-error-decorator.js.map +0 -0
  151. package/{utils → dist-package/utils}/validators.d.ts +0 -0
  152. package/{utils → dist-package/utils}/validators.js +0 -0
  153. package/{utils → dist-package/utils}/validators.js.map +0 -0
  154. package/package.json +4 -5
  155. package/src/Autocomplete/Autocomplete.tsx +21 -0
  156. package/src/Autocomplete/index.ts +1 -0
  157. package/src/ButtonCheckbox/ButtonCheckbox.tsx +57 -0
  158. package/src/ButtonCheckbox/index.ts +1 -0
  159. package/src/ButtonRadio/ButtonRadio.tsx +24 -0
  160. package/src/ButtonRadio/index.ts +1 -0
  161. package/src/Checkbox/Checkbox.tsx +73 -0
  162. package/src/Checkbox/__snapshots__/test.tsx.snap +254 -0
  163. package/src/Checkbox/index.ts +1 -0
  164. package/src/Checkbox/test.tsx +91 -0
  165. package/src/CheckboxGroup/CheckboxGroup.tsx +30 -0
  166. package/src/CheckboxGroup/CheckboxGroupContext.ts +3 -0
  167. package/src/CheckboxGroup/index.ts +3 -0
  168. package/src/CheckboxGroup/test.tsx +35 -0
  169. package/src/DatePicker/DatePicker.tsx +26 -0
  170. package/src/DatePicker/index.ts +1 -0
  171. package/src/FieldWrapper/FieldWrapper.tsx +287 -0
  172. package/src/FieldWrapper/index.ts +2 -0
  173. package/src/FieldWrapper/story/index.jsx +137 -0
  174. package/src/FileInput/FileInput.tsx +66 -0
  175. package/src/FileInput/index.ts +1 -0
  176. package/src/Form/Form.tsx +181 -0
  177. package/src/Form/FormContext.ts +38 -0
  178. package/src/Form/__image_snapshots__/form-default-snap.png +0 -0
  179. package/src/Form/__image_snapshots__/form-form-level-configurations-snap.png +0 -0
  180. package/src/Form/__snapshots__/test.tsx.snap +61 -0
  181. package/src/Form/index.ts +1 -0
  182. package/src/Form/story/BackendCommunication.example.tsx +139 -0
  183. package/src/Form/story/CustomFormLevelConfiguration.example.tsx +26 -0
  184. package/src/Form/story/CustomValidator.example.tsx +45 -0
  185. package/src/Form/story/Default.example.tsx +177 -0
  186. package/src/Form/story/FileInput.example.tsx +42 -0
  187. package/src/Form/story/ParseInput.example.tsx +28 -0
  188. package/src/Form/story/TitleCase.example.tsx +167 -0
  189. package/src/Form/story/ValidateOnSubmit.example.tsx +85 -0
  190. package/src/Form/story/index.jsx +203 -0
  191. package/src/Form/test.tsx +27 -0
  192. package/src/FormConfig/FormConfig.ts +12 -0
  193. package/src/FormConfig/index.ts +1 -0
  194. package/src/FormConfig/test.tsx +44 -0
  195. package/src/Input/Input.tsx +27 -0
  196. package/src/Input/index.ts +1 -0
  197. package/src/Input/test.tsx +34 -0
  198. package/src/Input/utils/get-input-name.test.ts +16 -0
  199. package/src/Input/utils/get-input-name.ts +11 -0
  200. package/src/NumberInput/NumberInput.tsx +45 -0
  201. package/src/NumberInput/index.ts +1 -0
  202. package/src/Radio/Radio.tsx +24 -0
  203. package/src/Radio/__snapshots__/test.tsx.snap +231 -0
  204. package/src/Radio/index.ts +1 -0
  205. package/src/Radio/test.tsx +49 -0
  206. package/src/RadioGroup/RadioGroup.tsx +39 -0
  207. package/src/RadioGroup/RadioGroupContext.ts +3 -0
  208. package/src/RadioGroup/index.ts +3 -0
  209. package/src/RadioGroup/test.tsx +35 -0
  210. package/src/Rating/Rating.tsx +22 -0
  211. package/src/Rating/index.ts +1 -0
  212. package/src/Select/Select.tsx +47 -0
  213. package/src/Select/index.ts +1 -0
  214. package/src/SubmitButton/SubmitButton.tsx +70 -0
  215. package/src/SubmitButton/__image_snapshots__/submitbutton-button-types-snap.png +0 -0
  216. package/src/SubmitButton/__image_snapshots__/submitbutton-default-snap.png +0 -0
  217. package/src/SubmitButton/index.ts +6 -0
  218. package/src/SubmitButton/story/ButtonTypes.example.tsx +46 -0
  219. package/src/SubmitButton/story/Default.example.tsx +15 -0
  220. package/src/SubmitButton/story/index.jsx +32 -0
  221. package/src/Switch/Switch.tsx +23 -0
  222. package/src/Switch/index.ts +1 -0
  223. package/src/TagSelector/TagSelector.tsx +25 -0
  224. package/src/TagSelector/index.ts +1 -0
  225. package/src/TimePicker/TimePicker.tsx +24 -0
  226. package/src/TimePicker/index.ts +1 -0
  227. package/src/index.ts +16 -0
  228. package/src/story/Deserialization.example.tsx +34 -0
  229. package/src/story/FormSpy.example.tsx +42 -0
  230. package/src/story/index.jsx +37 -0
  231. package/src/utils/flat-map.ts +4 -0
  232. package/src/utils/index.ts +3 -0
  233. package/src/utils/scroll-to-error-decorator.ts +78 -0
  234. package/src/utils/validators.ts +18 -0
  235. package/tsconfig.build.json +7 -0
  236. package/index.js.map +0 -1
@@ -0,0 +1 @@
1
+ export { default } from './ButtonRadio'
@@ -0,0 +1,73 @@
1
+ import React, { useContext } from 'react'
2
+ import { Checkbox as PicassoCheckbox, CheckboxProps } from '@toptal/picasso'
3
+ import {
4
+ Field,
5
+ FieldRenderProps as FinalFormFieldProps
6
+ } from 'react-final-form'
7
+
8
+ import FieldWrapper, { FieldProps } from '../FieldWrapper'
9
+ import { CheckboxGroupContext } from '../CheckboxGroup'
10
+ import { useFormConfig } from '../FormConfig'
11
+
12
+ type CheckboxValue = CheckboxProps['value'] | CheckboxProps['checked']
13
+
14
+ type CheckboxFormProps = Omit<CheckboxProps, 'requiredDecoration'> & {
15
+ required?: boolean
16
+ }
17
+ type CheckboxWithoutGroup = CheckboxFormProps & FieldProps<CheckboxValue>
18
+ type CheckboxInGroup = CheckboxFormProps & { name?: string }
19
+
20
+ export type Props = CheckboxWithoutGroup | CheckboxInGroup
21
+
22
+ export const Checkbox = ({
23
+ name,
24
+ value,
25
+ required,
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
+ defaultValue,
28
+ ...restProps
29
+ }: Props) => {
30
+ const formConfig = useFormConfig()
31
+ const groupName = useContext(CheckboxGroupContext)
32
+ const isCheckboxInGroup = Boolean(groupName)
33
+
34
+ if (isCheckboxInGroup) {
35
+ return (
36
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
37
+ <Field type='checkbox' name={name || groupName!} value={value}>
38
+ {({
39
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
+ input: { value: inputValue, type, ...restInput }
41
+ }: FinalFormFieldProps<CheckboxValue>) => {
42
+ return <PicassoCheckbox {...restProps} {...restInput} />
43
+ }}
44
+ </Field>
45
+ )
46
+ }
47
+
48
+ const showAsterisk = required && formConfig.requiredVariant === 'asterisk'
49
+ const requiredDecoration = showAsterisk ? 'asterisk' : undefined
50
+
51
+ return (
52
+ <FieldWrapper
53
+ type='checkbox'
54
+ hideFieldLabel
55
+ required={required}
56
+ {...restProps}
57
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
58
+ name={name!}
59
+ >
60
+ {(input: CheckboxProps) => (
61
+ <PicassoCheckbox
62
+ {...input}
63
+ titleCase={restProps.titleCase}
64
+ requiredDecoration={requiredDecoration}
65
+ />
66
+ )}
67
+ </FieldWrapper>
68
+ )
69
+ }
70
+
71
+ Checkbox.displayName = 'Checkbox'
72
+
73
+ export default Checkbox
@@ -0,0 +1,254 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Form.Checkbox default render for checkboxes in a group 1`] = `
4
+ <div>
5
+ <div
6
+ class="Picasso-root"
7
+ >
8
+ <div
9
+ class=""
10
+ >
11
+ <form>
12
+ <div
13
+ class="PicassoFormField-root"
14
+ data-field-has-error="false"
15
+ >
16
+ <label
17
+ class="PicassoFormLabel-root"
18
+ for="checkbox-group"
19
+ >
20
+ <span
21
+ class="PicassoFormLabel-text"
22
+ >
23
+ checkbox-group-label
24
+ (optional)
25
+ </span>
26
+ </label>
27
+ <div
28
+ class="MuiFormGroup-root PicassoCheckboxGroup-root PicassoCheckboxGroup-root"
29
+ label="checkbox-group-label"
30
+ name="checkbox-group"
31
+ >
32
+ <div
33
+ class="MuiGrid-root PicassoCheckboxGroup-grid MuiGrid-container PicassoGrid-container MuiGrid-direction-xs MuiGrid-align-items-xs-flex"
34
+ >
35
+ <div
36
+ class="MuiGrid-root PicassoCheckboxGroup-gridItem MuiGrid-item"
37
+ >
38
+ <label
39
+ class="PicassoFormControlLabel-root PicassoCheckbox-root picasso-checkbox"
40
+ >
41
+ <span
42
+ class="PicassoContainer-flex PicassoContainer-inline PicassoCheckbox-checkboxWrapper"
43
+ >
44
+ <span
45
+ aria-disabled="false"
46
+ class="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root MuiCheckbox-root PicassoCheckbox-root MuiCheckbox-colorSecondary PicassoCheckbox-withLabel MuiIconButton-colorSecondary"
47
+ >
48
+ <span
49
+ class="MuiIconButton-label"
50
+ >
51
+ <input
52
+ class="PrivateSwitchBase-input"
53
+ data-indeterminate="false"
54
+ name="checkbox-group"
55
+ type="checkbox"
56
+ value=""
57
+ />
58
+ <div
59
+ class="PicassoCheckbox-uncheckedIcon"
60
+ />
61
+ </span>
62
+ </span>
63
+ </span>
64
+ <span
65
+ class="PicassoFormLabel-root PicassoFormLabel-inline PicassoFormControlLabel-label PicassoCheckbox-label"
66
+ >
67
+ <span
68
+ class="PicassoFormLabel-text"
69
+ >
70
+ checkbox-label-0
71
+ </span>
72
+ </span>
73
+ </label>
74
+ </div>
75
+ <div
76
+ class="MuiGrid-root PicassoCheckboxGroup-gridItem MuiGrid-item"
77
+ >
78
+ <label
79
+ class="PicassoFormControlLabel-root PicassoCheckbox-root picasso-checkbox"
80
+ >
81
+ <span
82
+ class="PicassoContainer-flex PicassoContainer-inline PicassoCheckbox-checkboxWrapper"
83
+ >
84
+ <span
85
+ aria-disabled="false"
86
+ class="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root MuiCheckbox-root PicassoCheckbox-root MuiCheckbox-colorSecondary PicassoCheckbox-withLabel MuiIconButton-colorSecondary"
87
+ >
88
+ <span
89
+ class="MuiIconButton-label"
90
+ >
91
+ <input
92
+ class="PrivateSwitchBase-input"
93
+ data-indeterminate="false"
94
+ name="checkbox-group"
95
+ type="checkbox"
96
+ value=""
97
+ />
98
+ <div
99
+ class="PicassoCheckbox-uncheckedIcon"
100
+ />
101
+ </span>
102
+ </span>
103
+ </span>
104
+ <span
105
+ class="PicassoFormLabel-root PicassoFormLabel-inline PicassoFormControlLabel-label PicassoCheckbox-label"
106
+ >
107
+ <span
108
+ class="PicassoFormLabel-text"
109
+ >
110
+ checkbox-label-1
111
+ </span>
112
+ </span>
113
+ </label>
114
+ </div>
115
+ </div>
116
+ </div>
117
+ </div>
118
+ </form>
119
+ </div>
120
+ </div>
121
+ </div>
122
+ `;
123
+
124
+ exports[`Form.Checkbox default render for single checkbox 1`] = `
125
+ <div>
126
+ <div
127
+ class="Picasso-root"
128
+ >
129
+ <div
130
+ class=""
131
+ >
132
+ <form>
133
+ <div
134
+ class="PicassoFormField-root"
135
+ data-field-has-error="false"
136
+ data-testid="single-checkbox"
137
+ >
138
+ <label
139
+ class="PicassoFormControlLabel-root PicassoCheckbox-root picasso-checkbox"
140
+ >
141
+ <span
142
+ class="PicassoContainer-flex PicassoContainer-inline PicassoCheckbox-checkboxWrapper"
143
+ >
144
+ <span
145
+ aria-disabled="false"
146
+ class="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root MuiCheckbox-root PicassoCheckbox-root MuiCheckbox-colorSecondary PicassoCheckbox-withLabel MuiIconButton-colorSecondary"
147
+ >
148
+ <span
149
+ class="MuiIconButton-label"
150
+ >
151
+ <input
152
+ class="PrivateSwitchBase-input"
153
+ data-indeterminate="false"
154
+ id="single-checkbox"
155
+ name="single-checkbox"
156
+ type="checkbox"
157
+ value=""
158
+ />
159
+ <div
160
+ class="PicassoCheckbox-uncheckedIcon"
161
+ />
162
+ </span>
163
+ </span>
164
+ </span>
165
+ <span
166
+ class="PicassoFormLabel-root PicassoFormLabel-inline PicassoFormControlLabel-label PicassoCheckbox-label"
167
+ >
168
+ <span
169
+ class="PicassoFormLabel-text"
170
+ >
171
+ The checkbox label
172
+ </span>
173
+ </span>
174
+ </label>
175
+ </div>
176
+ </form>
177
+ </div>
178
+ </div>
179
+ </div>
180
+ `;
181
+
182
+ exports[`Form.Checkbox required with asterisk single checkbox 1`] = `
183
+ <div>
184
+ <div
185
+ class="Picasso-root"
186
+ >
187
+ <div
188
+ class=""
189
+ >
190
+ <form>
191
+ <div
192
+ class="PicassoFormField-root"
193
+ data-field-has-error="false"
194
+ data-testid="single-checkbox"
195
+ >
196
+ <label
197
+ class="PicassoFormControlLabel-root PicassoCheckbox-root picasso-checkbox"
198
+ >
199
+ <span
200
+ class="PicassoContainer-flex PicassoContainer-inline PicassoCheckbox-checkboxWrapper"
201
+ >
202
+ <span
203
+ aria-disabled="false"
204
+ class="MuiButtonBase-root MuiIconButton-root PrivateSwitchBase-root MuiCheckbox-root PicassoCheckbox-root MuiCheckbox-colorSecondary PicassoCheckbox-withLabel MuiIconButton-colorSecondary"
205
+ >
206
+ <span
207
+ class="MuiIconButton-label"
208
+ >
209
+ <input
210
+ class="PrivateSwitchBase-input"
211
+ data-indeterminate="false"
212
+ id="single-checkbox"
213
+ name="single-checkbox"
214
+ type="checkbox"
215
+ value=""
216
+ />
217
+ <div
218
+ class="PicassoCheckbox-uncheckedIcon"
219
+ />
220
+ </span>
221
+ </span>
222
+ </span>
223
+ <span
224
+ class="PicassoFormLabel-root PicassoFormLabel-inline PicassoFormControlLabel-label PicassoCheckbox-label"
225
+ >
226
+ <span
227
+ class="PicassoFormLabel-asterisk"
228
+ >
229
+ *
230
+ </span>
231
+ <span
232
+ class="PicassoFormLabel-text"
233
+ >
234
+ The checkbox label
235
+ </span>
236
+ </span>
237
+ </label>
238
+ </div>
239
+ </form>
240
+ </div>
241
+ </div>
242
+ </div>
243
+ `;
244
+
245
+ exports[`Form.Checkbox when required prop is passed does not set "required" attribute to input tag, to avoid Chrome tooltip 1`] = `
246
+ <input
247
+ class="PrivateSwitchBase-input"
248
+ data-indeterminate="false"
249
+ id="single-checkbox"
250
+ name="single-checkbox"
251
+ type="checkbox"
252
+ value=""
253
+ />
254
+ `;
@@ -0,0 +1 @@
1
+ export { default } from './Checkbox'
@@ -0,0 +1,91 @@
1
+ import React from 'react'
2
+ import { render } from '@toptal/picasso/test-utils'
3
+
4
+ import { FormConfigProps } from '../FormConfig'
5
+ import Form from '../Form'
6
+ import CheckboxGroup from '../CheckboxGroup'
7
+ import Checkbox, { Props } from './Checkbox'
8
+
9
+ const renderCheckbox = (
10
+ { required, titleCase }: Props,
11
+ formConfig: FormConfigProps = {}
12
+ ) =>
13
+ render(
14
+ <Form.ConfigProvider value={formConfig}>
15
+ <Form onSubmit={() => {}}>
16
+ <Checkbox
17
+ name='single-checkbox'
18
+ label='The checkbox label'
19
+ value='checkbox-value'
20
+ data-testid='single-checkbox'
21
+ required={required}
22
+ titleCase={titleCase}
23
+ />
24
+ </Form>
25
+ </Form.ConfigProvider>
26
+ )
27
+
28
+ const renderCheckboxInGroup = () =>
29
+ render(
30
+ <Form onSubmit={() => {}}>
31
+ <CheckboxGroup name='checkbox-group' label='checkbox-group-label'>
32
+ <Checkbox label='checkbox-label-0' value='checkbox-value-0' />
33
+ <Checkbox label='checkbox-label-1' value='checkbox-value-1' />
34
+ </CheckboxGroup>
35
+ </Form>
36
+ )
37
+
38
+ describe('Form.Checkbox', () => {
39
+ it('default render for single checkbox', () => {
40
+ const { container } = renderCheckbox({})
41
+
42
+ expect(container).toMatchSnapshot()
43
+ })
44
+
45
+ describe('when required prop is passed', () => {
46
+ it('does not set "required" attribute to input tag, to avoid Chrome tooltip', () => {
47
+ const { container } = renderCheckbox({})
48
+
49
+ expect(
50
+ container.querySelector('[name="single-checkbox"]')
51
+ ).toMatchSnapshot()
52
+ })
53
+ })
54
+
55
+ it('default render for checkboxes in a group', () => {
56
+ const { container } = renderCheckboxInGroup()
57
+
58
+ expect(container).toMatchSnapshot()
59
+ })
60
+
61
+ it('required with asterisk single checkbox', () => {
62
+ const { container } = renderCheckbox(
63
+ {
64
+ required: true
65
+ },
66
+ {
67
+ requiredVariant: 'asterisk'
68
+ }
69
+ )
70
+
71
+ expect(container).toMatchSnapshot()
72
+ })
73
+
74
+ it('never shows (optional) postfix for single checkbox', () => {
75
+ const { getByTestId } = renderCheckbox({})
76
+
77
+ expect(getByTestId('single-checkbox')).not.toHaveTextContent('(optional)')
78
+ })
79
+
80
+ it('shows the label in default case', () => {
81
+ const { getByLabelText } = renderCheckbox({})
82
+
83
+ expect(getByLabelText('The checkbox label')).toBeInTheDocument()
84
+ })
85
+
86
+ it('shows the label in title case', () => {
87
+ const { getByLabelText } = renderCheckbox({ titleCase: true })
88
+
89
+ expect(getByLabelText('The Checkbox Label')).toBeInTheDocument()
90
+ })
91
+ })
@@ -0,0 +1,30 @@
1
+ /* eslint-disable react/jsx-props-no-spreading */
2
+ import React from 'react'
3
+ import {
4
+ Checkbox as PicassoCheckbox,
5
+ CheckboxProps,
6
+ CheckboxGroupProps
7
+ } from '@toptal/picasso'
8
+
9
+ import FieldWrapper, { FieldProps } from '../FieldWrapper'
10
+ import CheckboxGroupContext from './CheckboxGroupContext'
11
+
12
+ export type Props = CheckboxGroupProps & FieldProps<CheckboxProps['value']>
13
+
14
+ export const CheckboxGroup = (props: Props) => {
15
+ const { children, titleCase, ...rest } = props
16
+
17
+ return (
18
+ <CheckboxGroupContext.Provider value={props.name}>
19
+ <FieldWrapper titleCase={titleCase} {...rest} type='checkbox'>
20
+ {() => (
21
+ <PicassoCheckbox.Group {...rest}>{children}</PicassoCheckbox.Group>
22
+ )}
23
+ </FieldWrapper>
24
+ </CheckboxGroupContext.Provider>
25
+ )
26
+ }
27
+
28
+ CheckboxGroup.displayName = 'CheckboxGroup'
29
+
30
+ export default CheckboxGroup
@@ -0,0 +1,3 @@
1
+ import { createContext } from 'react'
2
+
3
+ export default createContext<string | undefined>(undefined)
@@ -0,0 +1,3 @@
1
+ export { default } from './CheckboxGroup'
2
+ export { default as CheckboxGroupContext } from './CheckboxGroupContext'
3
+ export type { Props } from './CheckboxGroup'
@@ -0,0 +1,35 @@
1
+ import { render } from '@toptal/picasso/test-utils'
2
+ import React from 'react'
3
+
4
+ import Checkbox from '../Checkbox'
5
+ import Form from '../Form'
6
+ import CheckboxGroup, { Props } from './CheckboxGroup'
7
+
8
+ const arrangeTest = ({ titleCase }: Partial<Props> = {}) =>
9
+ render(
10
+ <Form onSubmit={() => {}}>
11
+ <CheckboxGroup
12
+ required
13
+ name='checkbox-group'
14
+ label='Checkbox group label'
15
+ titleCase={titleCase}
16
+ >
17
+ <Checkbox label='checkbox-label-0' value='checkbox-value-0' />
18
+ <Checkbox label='checkbox-label-1' value='checkbox-value-1' />
19
+ </CheckboxGroup>
20
+ </Form>
21
+ )
22
+
23
+ describe('CheckboxGroup', () => {
24
+ it('shows the label in default case', () => {
25
+ const { getByText } = arrangeTest()
26
+
27
+ expect(getByText('Checkbox group label')).toBeInTheDocument()
28
+ })
29
+
30
+ it('shows the label in title case', () => {
31
+ const { getByText } = arrangeTest({ titleCase: true })
32
+
33
+ expect(getByText('Checkbox Group Label')).toBeInTheDocument()
34
+ })
35
+ })
@@ -0,0 +1,26 @@
1
+ import React from 'react'
2
+ import {
3
+ DatePicker as PicassoDatePicker,
4
+ DatePickerProps
5
+ } from '@toptal/picasso-lab'
6
+
7
+ import FieldWrapper, { FieldProps } from '../FieldWrapper'
8
+
9
+ export type FormDatePickerProps = Omit<DatePickerProps, 'onChange'> & {
10
+ onChange?: DatePickerProps['onChange']
11
+ }
12
+ export type Props = FormDatePickerProps & FieldProps<DatePickerProps['value']>
13
+
14
+ export const DatePicker = (props: Props) => (
15
+ <FieldWrapper<FormDatePickerProps> {...props}>
16
+ {(inputProps: DatePickerProps) => {
17
+ return <PicassoDatePicker {...inputProps} />
18
+ }}
19
+ </FieldWrapper>
20
+ )
21
+
22
+ DatePicker.defaultProps = {}
23
+
24
+ DatePicker.displayName = 'DatePicker'
25
+
26
+ export default DatePicker
@@ -0,0 +1 @@
1
+ export { default } from './DatePicker'