@7shifts/sous-chef 4.15.0 → 4.16.0

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 (223) hide show
  1. package/dist/actions/Button/Button.d.ts +5 -1
  2. package/dist/actions/Link/Link.d.ts +7 -0
  3. package/dist/actions/PaginationControls/PaginationControls.d.ts +7 -5
  4. package/dist/actions/Toggle/Toggle.d.ts +2 -0
  5. package/dist/controls/DateFilter/DateFilter.d.ts +16 -1
  6. package/dist/controls/SegmentedControl/SegmentedControl.d.ts +6 -0
  7. package/dist/controls/ToolbarSelect/ToolbarSelect.d.ts +9 -1
  8. package/dist/core/SousChefProvider/SousChefProvider.d.ts +7 -0
  9. package/dist/empty_states/EmptyStateContainer/types.d.ts +16 -2
  10. package/dist/feedback/CircularProgress/CircularProgress.d.ts +1 -0
  11. package/dist/feedback/InlineBanner/InlineBanner.d.ts +1 -0
  12. package/dist/feedback/MicroBanner/MicroBanner.d.ts +1 -0
  13. package/dist/feedback/PersistentBanner/PersistentBanner.d.ts +6 -0
  14. package/dist/feedback/ProgressBar/ProgressBar.d.ts +7 -1
  15. package/dist/feedback/Spinner/Spinner.d.ts +6 -0
  16. package/dist/feedback/Toast/Toast.d.ts +13 -0
  17. package/dist/forms/CheckboxField/CheckboxField.d.ts +4 -0
  18. package/dist/forms/CurrencyField/CurrencyField.d.ts +5 -21
  19. package/dist/forms/DateField/DateField.d.ts +13 -1
  20. package/dist/forms/DateRangeField/DateRangeCalendar/DateRangeCalendar.d.ts +6 -3
  21. package/dist/forms/DateRangeField/DateRangeField.d.ts +17 -3
  22. package/dist/forms/Form/Form.d.ts +13 -2
  23. package/dist/forms/FormFeedback/FormFeedback.d.ts +1 -0
  24. package/dist/forms/FormFooter/FormFooter.d.ts +11 -5
  25. package/dist/forms/FormFooter/FormFooterActions/FormFooterActions.d.ts +2 -5
  26. package/dist/forms/FormFooter/types.d.ts +10 -0
  27. package/dist/forms/FormRow/FormRow.d.ts +6 -0
  28. package/dist/forms/FormSection/FormSection.d.ts +4 -0
  29. package/dist/forms/MultiSelectField/MultiSelectField.d.ts +6 -2
  30. package/dist/forms/NumberField/NumberField.d.ts +4 -0
  31. package/dist/forms/PasswordField/PasswordField.d.ts +3 -0
  32. package/dist/forms/PercentageField/PercentageField.d.ts +13 -0
  33. package/dist/forms/PhoneField/PhoneField.d.ts +10 -0
  34. package/dist/forms/PillSelectField/PillSelectField.d.ts +9 -0
  35. package/dist/forms/PillSelectField/types.d.ts +2 -0
  36. package/dist/forms/RadioGroupBoxOption/RadioGroupBoxOption.d.ts +7 -0
  37. package/dist/forms/RadioGroupField/RadioGroupField.d.ts +8 -1
  38. package/dist/forms/RadioGroupField/RadioGroupFieldContext.d.ts +2 -1
  39. package/dist/forms/RadioGroupOption/RadioGroupOption.d.ts +6 -1
  40. package/dist/forms/SelectField/SelectField.d.ts +20 -3
  41. package/dist/forms/SelectField/types.d.ts +27 -0
  42. package/dist/forms/TextAreaField/TextAreaField.d.ts +7 -1
  43. package/dist/forms/TextField/TextField.d.ts +8 -0
  44. package/dist/forms/TimeField/TimeField.d.ts +23 -1
  45. package/dist/forms/TimeRangeField/TimeRangeField.d.ts +15 -2
  46. package/dist/forms/WeekField/WeekField.d.ts +4 -0
  47. package/dist/forms/WeekSelectField/WeekSelectField.d.ts +4 -0
  48. package/dist/forms/hooks/useRadioGroupFieldControllers.d.ts +1 -2
  49. package/dist/forms/hooks/useSelectFieldControllers.d.ts +2 -2
  50. package/dist/forms/index.d.ts +2 -0
  51. package/dist/foundation/tokens/color/color-constants.d.ts +34 -0
  52. package/dist/foundation/tokens/color/color-types.d.ts +1 -1
  53. package/dist/foundation/tokens/dimension/dimension-tokens.d.ts +1 -0
  54. package/dist/foundation/tokens/layout/TokenTable.d.ts +14 -0
  55. package/dist/foundation/tokens/layout/layout-tokens.d.ts +12 -0
  56. package/dist/hooks/useIsOverflowing.d.ts +2 -0
  57. package/dist/index.css +755 -479
  58. package/dist/index.css.map +1 -1
  59. package/dist/index.d.ts +2 -1
  60. package/dist/index.js +1295 -941
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.modern.js +1431 -1098
  63. package/dist/index.modern.js.map +1 -1
  64. package/dist/ink_illustrations/components/design/Ink3DModeling.d.ts +7 -0
  65. package/dist/ink_illustrations/components/design/index.d.ts +1 -1
  66. package/dist/ink_illustrations/components/index.d.ts +2 -2
  67. package/dist/ink_illustrations/components/other/InkSculptureBust.d.ts +7 -0
  68. package/dist/ink_illustrations/components/other/index.d.ts +1 -1
  69. package/dist/ink_illustrations/components/{design/Ink3DModeling02.d.ts → travel/InkBoardingPass.d.ts} +2 -2
  70. package/dist/ink_illustrations/components/travel/InkVolcano.d.ts +7 -0
  71. package/dist/ink_illustrations/components/travel/index.d.ts +2 -2
  72. package/dist/ink_illustrations/components/weather/InkSun.d.ts +7 -0
  73. package/dist/ink_illustrations/components/weather/index.d.ts +1 -1
  74. package/dist/ink_illustrations/deprecatedAliases.d.ts +27 -0
  75. package/dist/ink_illustrations/index.d.ts +1 -0
  76. package/dist/layout/CalloutCard/CalloutCard.d.ts +1 -0
  77. package/dist/layout/Card/Card.d.ts +14 -0
  78. package/dist/layout/Inline/Inline.d.ts +20 -4
  79. package/dist/layout/Page/Page.d.ts +11 -3
  80. package/dist/layout/Page/PageBreadcrumbs/PageBreadcrumbs.d.ts +2 -2
  81. package/dist/layout/Page/types.d.ts +11 -2
  82. package/dist/layout/PageLayout/PageLayout.d.ts +18 -0
  83. package/dist/layout/PageLayout/types.d.ts +10 -0
  84. package/dist/layout/Stack/Stack.d.ts +16 -4
  85. package/dist/layout/index.d.ts +1 -0
  86. package/dist/lists/Accordion/Accordion.d.ts +10 -0
  87. package/dist/lists/Accordion/types.d.ts +4 -0
  88. package/dist/lists/ActionList/ActionList.d.ts +12 -0
  89. package/dist/lists/ActionList/type.d.ts +5 -0
  90. package/dist/lists/ActionListItem/ActionListItem.d.ts +17 -0
  91. package/dist/lists/BasicTable/BasicTable.d.ts +22 -0
  92. package/dist/lists/BasicTable/BasicTableSectionContext.d.ts +4 -0
  93. package/dist/lists/BasicTable/constants.d.ts +13 -0
  94. package/dist/lists/BasicTable/index.d.ts +1 -0
  95. package/dist/lists/BasicTable/types.d.ts +4 -0
  96. package/dist/lists/BasicTableBody/BasicTableBody.d.ts +9 -0
  97. package/dist/lists/BasicTableBody/index.d.ts +1 -0
  98. package/dist/lists/BasicTableCell/BasicTableCell.d.ts +14 -0
  99. package/dist/lists/BasicTableCell/index.d.ts +1 -0
  100. package/dist/lists/BasicTableHeader/BasicTableHeader.d.ts +9 -0
  101. package/dist/lists/BasicTableHeader/index.d.ts +1 -0
  102. package/dist/lists/BasicTableRow/BasicTableRow.d.ts +9 -0
  103. package/dist/lists/BasicTableRow/index.d.ts +1 -0
  104. package/dist/lists/DataTable/DataTable.d.ts +31 -8
  105. package/dist/lists/DataTable/types.d.ts +35 -0
  106. package/dist/lists/DataTableCell/DataTableCell.d.ts +1 -0
  107. package/dist/lists/DataTableEditableCell/DataTableEditableCell.d.ts +1 -0
  108. package/dist/lists/DataTableRow/DataTableRow.d.ts +12 -0
  109. package/dist/lists/index.d.ts +7 -1
  110. package/dist/media/Avatar/Avatar.d.ts +1 -0
  111. package/dist/media/Badge/Badge.d.ts +7 -2
  112. package/dist/media/Pill/Pill.d.ts +8 -0
  113. package/dist/media/Pill/constants.d.ts +2 -0
  114. package/dist/media/Pill/types.d.ts +3 -1
  115. package/dist/navigation/BreadcrumbItem/BreadcrumbItem.d.ts +1 -0
  116. package/dist/navigation/Breadcrumbs/Breadcrumbs.d.ts +1 -0
  117. package/dist/navigation/PrimaryNav/PrimaryNav.d.ts +1 -0
  118. package/dist/navigation/PrimaryNavFooter/PrimaryNavFooter.d.ts +1 -0
  119. package/dist/navigation/PrimaryNavItem/PrimaryNavItem.d.ts +1 -0
  120. package/dist/navigation/PrimaryNavSubItem/PrimaryNavSubItem.d.ts +1 -0
  121. package/dist/navigation/Tab/Tab.d.ts +1 -0
  122. package/dist/navigation/TabList/TabList.d.ts +1 -0
  123. package/dist/navigation/TabPanel/TabPanel.d.ts +1 -0
  124. package/dist/navigation/Tabs/Tabs.d.ts +1 -0
  125. package/dist/overlay/Calendar/Calendar.d.ts +15 -4
  126. package/dist/overlay/Dropdown/Dropdown.d.ts +1 -0
  127. package/dist/overlay/DropdownListDivider/DropdownListDivider.d.ts +1 -0
  128. package/dist/overlay/DropdownListItem/DropdownListItem.d.ts +1 -0
  129. package/dist/overlay/DropdownListItemSelectable/DropdownListItemSelectable.d.ts +1 -0
  130. package/dist/overlay/DropdownSubmenu/DropdownSubmenu.d.ts +1 -0
  131. package/dist/overlay/HintModal/HintModal.d.ts +1 -0
  132. package/dist/overlay/KebabMenu/types.d.ts +5 -0
  133. package/dist/overlay/Modal/Modal.d.ts +3 -0
  134. package/dist/overlay/Modal/ModalBody/ModalBody.d.ts +1 -0
  135. package/dist/overlay/Modal/ModalFooter/ModalFooter.d.ts +11 -6
  136. package/dist/overlay/Modal/ModalFooter/types.d.ts +10 -0
  137. package/dist/overlay/Popover/Popover.d.ts +8 -1
  138. package/dist/overlay/Tooltip/Tooltip.d.ts +2 -1
  139. package/dist/overlay/index.d.ts +1 -0
  140. package/dist/typography/KeyboardKey/KeyboardKey.d.ts +1 -0
  141. package/dist/typography/Text/Bold/Bold.d.ts +1 -0
  142. package/dist/typography/Text/Italic/Italic.d.ts +1 -0
  143. package/dist/typography/Text/Text.d.ts +23 -0
  144. package/dist/typography/Text/Underline/Underline.d.ts +1 -0
  145. package/dist/utils/formik.d.ts +5 -0
  146. package/llms-instructions/guidelines/ActionList.guidelines.md +1 -3
  147. package/llms-instructions/guidelines/Avatar.guidelines.md +6 -5
  148. package/llms-instructions/guidelines/Badge.guidelines.md +24 -8
  149. package/llms-instructions/guidelines/BasicTable.guidelines.md +80 -0
  150. package/llms-instructions/guidelines/Breadcrumbs.guidelines.md +2 -2
  151. package/llms-instructions/guidelines/Button.guidelines.md +3 -3
  152. package/llms-instructions/guidelines/Calendar.guidelines.md +12 -0
  153. package/llms-instructions/guidelines/Card.guidelines.md +2 -2
  154. package/llms-instructions/guidelines/CircularProgress.guidelines.md +1 -1
  155. package/llms-instructions/guidelines/DateFilter.guidelines.md +2 -2
  156. package/llms-instructions/guidelines/Dropdown.guidelines.md +3 -2
  157. package/llms-instructions/guidelines/EmptyState.guidelines.md +3 -1
  158. package/llms-instructions/guidelines/{Forms.guidelines.md → Form.guidelines.md} +41 -6
  159. package/llms-instructions/guidelines/Icons.guidelines.md +11 -10
  160. package/llms-instructions/guidelines/InkIllustrations.guidelines.md +5 -4
  161. package/llms-instructions/guidelines/Inline.guidelines.md +55 -0
  162. package/llms-instructions/guidelines/InlineBanner.guidelines.md +5 -3
  163. package/llms-instructions/guidelines/MultiSelectField.guidelines.md +2 -2
  164. package/llms-instructions/guidelines/Page.guidelines.md +65 -0
  165. package/llms-instructions/guidelines/PageLayout.guidelines.md +85 -0
  166. package/llms-instructions/guidelines/Paywall.guidelines.md +3 -2
  167. package/llms-instructions/guidelines/PersistentBanner.guidelines.md +2 -2
  168. package/llms-instructions/guidelines/Pill.guidelines.md +31 -3
  169. package/llms-instructions/guidelines/PillSelectField.guidelines.md +1 -1
  170. package/llms-instructions/guidelines/PrimaryNav.guidelines.md +144 -0
  171. package/llms-instructions/guidelines/SegmentedControl.guidelines.md +2 -2
  172. package/llms-instructions/guidelines/Skeleton.guidelines.md +3 -3
  173. package/llms-instructions/guidelines/Spinner.guidelines.md +6 -4
  174. package/llms-instructions/guidelines/Stack.guidelines.md +53 -0
  175. package/llms-instructions/guidelines/Text.guidelines.md +70 -0
  176. package/llms-instructions/guidelines/Toast.guidelines.md +2 -1
  177. package/llms-instructions/guidelines/Toggle.guidelines.md +2 -2
  178. package/llms-instructions/guidelines/ToolbarSelect.guidelines.md +2 -2
  179. package/llms-instructions/guidelines/Tooltip.guidelines.md +1 -1
  180. package/llms-instructions/llms-components.md +91 -19
  181. package/llms-instructions/llms-composing-components.md +583 -219
  182. package/llms-instructions/llms-icons-and-illustrations.md +305 -1011
  183. package/llms-instructions/llms-tokens.md +227 -164
  184. package/llms-instructions/llms.md +12 -28
  185. package/package.json +2 -2
  186. package/dist/ink_illustrations/components/other/InkS/321/201ulptureBust.d.ts +0 -7
  187. package/dist/ink_illustrations/components/travel/InkDrawing.d.ts +0 -7
  188. package/dist/ink_illustrations/components/travel/InkDrawing1.d.ts +0 -7
  189. package/dist/ink_illustrations/components/weather/InkGroup7975.d.ts +0 -7
  190. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/Ink3DGlasses.d.ts +0 -0
  191. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkAmusementPark.d.ts +0 -0
  192. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkBallet.d.ts +0 -0
  193. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkBowling.d.ts +0 -0
  194. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkCardGames.d.ts +0 -0
  195. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkCarouselWithHorses.d.ts +0 -0
  196. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkDiscoBall.d.ts +0 -0
  197. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkDj.d.ts +0 -0
  198. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkFirecracker.d.ts +0 -0
  199. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkJoystick.d.ts +0 -0
  200. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkMagicTricks.d.ts +0 -0
  201. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkMascarade.d.ts +0 -0
  202. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkNotesChart.d.ts +0 -0
  203. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkRollerSkating.d.ts +0 -0
  204. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkSlotMachine.d.ts +0 -0
  205. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/InkTheatre.d.ts +0 -0
  206. /package/dist/ink_illustrations/components/{enterteniment → entertainment}/index.d.ts +0 -0
  207. /package/dist/ink_illustrations/components/{sciency → science}/InkAnatomy.d.ts +0 -0
  208. /package/dist/ink_illustrations/components/{sciency → science}/InkAsteroid.d.ts +0 -0
  209. /package/dist/ink_illustrations/components/{sciency → science}/InkAstronaut.d.ts +0 -0
  210. /package/dist/ink_illustrations/components/{sciency → science}/InkBacteria.d.ts +0 -0
  211. /package/dist/ink_illustrations/components/{sciency → science}/InkChemistry.d.ts +0 -0
  212. /package/dist/ink_illustrations/components/{sciency → science}/InkDna.d.ts +0 -0
  213. /package/dist/ink_illustrations/components/{sciency → science}/InkLabTube.d.ts +0 -0
  214. /package/dist/ink_illustrations/components/{sciency → science}/InkMicroChips.d.ts +0 -0
  215. /package/dist/ink_illustrations/components/{sciency → science}/InkMicroscope.d.ts +0 -0
  216. /package/dist/ink_illustrations/components/{sciency → science}/InkNewtonsCradle.d.ts +0 -0
  217. /package/dist/ink_illustrations/components/{sciency → science}/InkNuclearEnergy.d.ts +0 -0
  218. /package/dist/ink_illustrations/components/{sciency → science}/InkPlanet.d.ts +0 -0
  219. /package/dist/ink_illustrations/components/{sciency → science}/InkPlantInTube.d.ts +0 -0
  220. /package/dist/ink_illustrations/components/{sciency → science}/InkRobotics.d.ts +0 -0
  221. /package/dist/ink_illustrations/components/{sciency → science}/InkSpaceTravel.d.ts +0 -0
  222. /package/dist/ink_illustrations/components/{sciency → science}/InkTelescope.d.ts +0 -0
  223. /package/dist/ink_illustrations/components/{sciency → science}/index.d.ts +0 -0
@@ -2,6 +2,8 @@
2
2
 
3
3
  In this document, you will find common examples and use cases for composing Sous Chef components to create user interfaces.
4
4
 
5
+ Every snippet is a complete TypeScript React file. It compiles when `@7shifts/sous-chef`, `formik` and `react-router-dom` are installed (the validation example also needs `yup`).
6
+
5
7
  ## Pages
6
8
 
7
9
  In Sous Chef, there is currently no component to build the full app layout structure as a whole, such as the navbar, top bar, and center area. However, it offers the `PageLayout` component and the `Page` component, which can be used together.
@@ -12,50 +14,61 @@ Use the `PageLayout` only when you have a group of pages, linked by a menu on th
12
14
  Example:
13
15
 
14
16
  ```tsx
15
- const MENU = [
17
+ import React from 'react';
18
+ import { MemoryRouter, Route, Routes } from 'react-router-dom';
19
+ import { Page, PageLayout, Text } from '@7shifts/sous-chef';
20
+ import type { PageLayoutMenu } from '@7shifts/sous-chef';
21
+
22
+ // Each menu `to` must match a `Route` path. `suffix` is shown in a `Badge`, so pass the count itself.
23
+ const MENU: PageLayoutMenu[] = [
16
24
  {
17
- to: '/employees',
18
- label: 'Employees',
19
- badge: '1'
25
+ to: '/active-employees',
26
+ label: 'Active Employees',
27
+ suffix: 1
20
28
  },
21
29
  {
22
30
  to: '/inactive-employees',
23
31
  label: 'Inactive Employees',
24
- badge: '2'
32
+ suffix: 2
25
33
  }
26
34
  ];
27
35
 
28
- return (
29
- // I'm using the MemoryRouter but it could be any other react router
30
- <MemoryRouter
31
- initialEntries={['/active-employees', '/inactive-employees']}
32
- initialIndex={0}
33
- >
34
- <PageLayout title="Employees" menu={MENU}>
35
- <Routes>
36
- <Route
37
- path="/active-employees"
38
- element={<ActiveEmployeesPage />}
39
- />
40
- <Route
41
- path="/inactive-employees"
42
- element={<InactiveEmployeesPage />}
43
- />
44
- </Routes>
45
- </PageLayout>
46
- </MemoryRouter>
47
- );
48
-
49
- // This is the example for the ActiveEmployeesPage
50
-
51
36
  const ActiveEmployeesPage = () => {
52
- return <Page title="Active employees">// Content goes here</Page>;
37
+ return (
38
+ <Page title="Active employees">
39
+ {/* Content goes here */}
40
+ <Text>List of active employees</Text>
41
+ </Page>
42
+ );
53
43
  };
54
44
 
55
- // This is the example for the InactiveEmployeesPage
45
+ const InactiveEmployeesPage = () => {
46
+ return (
47
+ <Page title="Inactive employees">
48
+ {/* Content goes here */}
49
+ <Text>List of inactive employees</Text>
50
+ </Page>
51
+ );
52
+ };
56
53
 
57
- const ActiveEmployeesPage = () => {
58
- return <Page title="Inactive employees">// Content goes here</Page>;
54
+ export const EmployeesSection = () => {
55
+ return (
56
+ // MemoryRouter is used here, but it could be any other react router
57
+ <MemoryRouter initialEntries={['/active-employees']}>
58
+ <PageLayout title="Employees" menu={MENU}>
59
+ <Routes>
60
+ <Route
61
+ path="/active-employees"
62
+ element={<ActiveEmployeesPage />}
63
+ />
64
+ <Route
65
+ path="/inactive-employees"
66
+ element={<InactiveEmployeesPage />}
67
+ />
68
+ </Routes>
69
+ </PageLayout>
70
+ </MemoryRouter>
71
+ );
59
72
  };
60
73
  ```
61
74
 
@@ -63,22 +76,28 @@ Notice that the `PageLayout` component is a container that holds a group of page
63
76
 
64
77
  ## Forms
65
78
 
66
- When it comes to forms in Sous Chef, we need to be clear on three concepts:
79
+ When it comes to forms in Sous Chef, we need to be clear on three concepts: the form UI, the form state and the form validation.
67
80
 
68
81
  ### Form UI
69
82
 
70
83
  By default, the `<Form>` component wraps all children in a `Stack` component. Because of that, all form fields will have the proper spacing of `20px`:
71
84
 
72
- ```
73
- <Form>
74
- <TextField name="firstName" label="First Name" />
75
- <TextField name="lastName" label="Last Name" />
76
- <FormFooter actions={{
77
- primary: <Button>Save</Button>,
78
- secondary: <Button>Cancel</Button>
79
- }}
80
- />
81
- </Form>
85
+ ```tsx
86
+ import React from 'react';
87
+ import { Button, Form, FormFooter, TextField } from '@7shifts/sous-chef';
88
+
89
+ export const EmployeeForm = () => (
90
+ <Form onSubmit={() => console.log('Saved')}>
91
+ <TextField name="firstName" label="First Name" />
92
+ <TextField name="lastName" label="Last Name" />
93
+ <FormFooter
94
+ actions={{
95
+ primary: <Button>Save</Button>,
96
+ secondary: <Button>Cancel</Button>
97
+ }}
98
+ />
99
+ </Form>
100
+ );
82
101
  ```
83
102
 
84
103
  On the example above, it will add the proper spacing for the form fields, however, for the form footer by design it has a larger space from the form fields. The `FormFooter` adds that space automatically.
@@ -87,19 +106,32 @@ Because of that, NEVER build your own form actions:
87
106
  NEVER DO THIS:
88
107
 
89
108
  ```tsx
90
- <Form>
91
- <TextField name="firstName" label="First Name" />
92
- <TextField name="lastName" label="Last Name" />
93
- // This won't add the proper spacing from the form fields
94
- <Inline>
95
- <Button theme="primary">Save</Button>
96
- <Button>Cancel</Button>
97
- </Inline>
98
- </Form>
109
+ import React from 'react';
110
+ import { Button, Form, Inline, TextField } from '@7shifts/sous-chef';
111
+
112
+ export const EmployeeForm = () => (
113
+ <Form>
114
+ <TextField name="firstName" label="First Name" />
115
+ <TextField name="lastName" label="Last Name" />
116
+ {/* This won't add the proper spacing from the form fields */}
117
+ <Inline>
118
+ <Button theme="primary">Save</Button>
119
+ <Button>Cancel</Button>
120
+ </Inline>
121
+ </Form>
122
+ );
99
123
  ```
100
124
 
101
125
  Notice, the `FormFooter` also adds the proper theme to the buttons as well as controlling the position of the buttons.
102
126
 
127
+ #### Footer actions and submit buttons
128
+
129
+ - `FormFooter` gives the `primary` action `type="submit"` and the `primary` theme, so you don't need to pass them. This only applies when the action is a Sous Chef `Button`; any other element is rendered as it is.
130
+ - Because the primary action submits the form, handle saving in the `Form` `onSubmit` (with Formik, in `useFormik({ onSubmit })`, which only runs when validation passes), NOT in an `onClick` on the primary `Button`. Pressing ENTER in a field then saves too.
131
+ - Always give `Form` an `onSubmit` or a `formik` prop. `Form` only prevents the browser's default submit when it has one of them, so a `Form` with neither does a native form submission and reloads the page when the primary button is clicked.
132
+ - `ModalFooter` only sets the theme (and the minimum width). It does NOT set `type="submit"`. When a form lives in a modal, pass `type="submit"` to the primary `Button` yourself (see the example below).
133
+ - A theme or type you pass explicitly always wins over these defaults.
134
+
103
135
  #### Form in a Modal
104
136
 
105
137
  The tricky part to understand when adding form in a modal is that the `Form` component needs to wrap the `ModalBody` and the `ModalFooter` so the form is accessible (user can hit the ENTER key to submit the form).
@@ -107,43 +139,59 @@ The tricky part to understand when adding form in a modal is that the `Form` com
107
139
  Example:
108
140
 
109
141
  ```tsx
110
- const [isOpen, setIsOpen] = useState(false);
111
-
112
- <>
113
- <Button onClick={() => setIsOpen(true)}>Show modal</Button>
114
- {isOpen && (
115
- <Modal
116
- header="Add Location"
117
- onClose={() => setIsOpen(false)}
118
- header="Add Location"
119
- >
120
- <Form
121
- onSubmit={() => {
122
- console.log('Will submit form!');
123
- setIsOpen(false);
124
- }}
125
- stackContent={false}
126
- >
127
- <ModalBody>
128
- <Stack>
129
- <TextField name="firstName" label="First Name" />
130
- <TextField name="lastName" label="First Name" />
131
- </Stack>
132
- </ModalBody>
133
- <ModalFooter
134
- actions={{
135
- primary: <Button type="submit">Create location</Button>,
136
- secondary: (
137
- <Button onClick={() => setIsOpen(false)}>
138
- Cancel
139
- </Button>
140
- )
141
- }}
142
- />
143
- </Form>
144
- </Modal>
145
- )}
146
- </>;
142
+ import React, { useState } from 'react';
143
+ import {
144
+ Button,
145
+ Form,
146
+ Modal,
147
+ ModalBody,
148
+ ModalFooter,
149
+ Stack,
150
+ TextField
151
+ } from '@7shifts/sous-chef';
152
+
153
+ export const AddLocationModal = () => {
154
+ const [isOpen, setIsOpen] = useState(false);
155
+
156
+ return (
157
+ <>
158
+ <Button onClick={() => setIsOpen(true)}>Show modal</Button>
159
+ {isOpen && (
160
+ <Modal header="Add Location" onClose={() => setIsOpen(false)}>
161
+ <Form
162
+ onSubmit={() => {
163
+ console.log('Will submit form!');
164
+ setIsOpen(false);
165
+ }}
166
+ stackContent={false}
167
+ >
168
+ <ModalBody>
169
+ <Stack>
170
+ <TextField name="name" label="Location Name" />
171
+ <TextField name="address" label="Address" />
172
+ </Stack>
173
+ </ModalBody>
174
+ <ModalFooter
175
+ actions={{
176
+ // ModalFooter does not add type="submit", so pass it
177
+ primary: (
178
+ <Button type="submit">
179
+ Create location
180
+ </Button>
181
+ ),
182
+ secondary: (
183
+ <Button onClick={() => setIsOpen(false)}>
184
+ Cancel
185
+ </Button>
186
+ )
187
+ }}
188
+ />
189
+ </Form>
190
+ </Modal>
191
+ )}
192
+ </>
193
+ );
194
+ };
147
195
  ```
148
196
 
149
197
  Notice that `stackContent={false}` is passed to the `Form` component. That is necessary so it does not add a `Stack` around the form children, because we don't want to add extra space to `ModalBody` and `ModalFooter`. However, inside the `ModalBody`, we still need to add a `Stack` around the form fields to guarantee proper spacing.
@@ -151,40 +199,54 @@ Notice that `stackContent={false}` is passed to the `Form` component. That is ne
151
199
  DON'T DO THIS:
152
200
 
153
201
  ```tsx
154
- const [isOpen, setIsOpen] = useState(false);
155
-
156
- <>
157
- <Button onClick={() => setIsOpen(true)}>Show modal</Button>
158
- {isOpen && (
159
- <Modal
160
- header="Add Location"
161
- onClose={() => setIsOpen(false)}
162
- header="Add Location"
163
- >
164
- <ModalBody>
165
- // The Form component is not wrapping the ModalFooter
166
- <Form
167
- onSubmit={() => {
168
- console.log('Will submit form!');
169
- setIsOpen(false);
170
- }}
171
- stackContent={false}
172
- >
173
- <TextField name="firstName" label="First Name" />
174
- <TextField name="lastName" label="First Name" />
175
- </Form>
176
- </ModalBody>
177
- <ModalFooter
178
- actions={{
179
- primary: <Button type="submit">Create location</Button>,
180
- secondary: (
181
- <Button onClick={() => setIsOpen(false)}>Cancel</Button>
182
- )
183
- }}
184
- />
185
- </Modal>
186
- )}
187
- </>;
202
+ import React, { useState } from 'react';
203
+ import {
204
+ Button,
205
+ Form,
206
+ Modal,
207
+ ModalBody,
208
+ ModalFooter,
209
+ TextField
210
+ } from '@7shifts/sous-chef';
211
+
212
+ export const AddLocationModal = () => {
213
+ const [isOpen, setIsOpen] = useState(false);
214
+
215
+ return (
216
+ <>
217
+ <Button onClick={() => setIsOpen(true)}>Show modal</Button>
218
+ {isOpen && (
219
+ <Modal header="Add Location" onClose={() => setIsOpen(false)}>
220
+ <ModalBody>
221
+ {/* The Form component is not wrapping the ModalFooter */}
222
+ <Form
223
+ onSubmit={() => {
224
+ console.log('Will submit form!');
225
+ setIsOpen(false);
226
+ }}
227
+ stackContent={false}
228
+ >
229
+ <TextField name="name" label="Location Name" />
230
+ <TextField name="address" label="Address" />
231
+ </Form>
232
+ </ModalBody>
233
+ <ModalFooter
234
+ actions={{
235
+ primary: (
236
+ <Button type="submit">Create location</Button>
237
+ ),
238
+ secondary: (
239
+ <Button onClick={() => setIsOpen(false)}>
240
+ Cancel
241
+ </Button>
242
+ )
243
+ }}
244
+ />
245
+ </Modal>
246
+ )}
247
+ </>
248
+ );
249
+ };
188
250
  ```
189
251
 
190
252
  The example above produces a good interface at first glance; however, it is NOT accessible. The user CAN'T press ENTER to submit the form.
@@ -200,18 +262,23 @@ Recommended for smaller forms when there is not much validation.
200
262
  Example:
201
263
 
202
264
  ```tsx
203
- const [firstName, setFirstName] = useState('');
204
-
205
- return (
206
- <Form onSubmit={() => console.log(firstName)}>
207
- <TextField
208
- name="firstName"
209
- label="First Name"
210
- value={firstName}
211
- onChange={setFirstName}
212
- />
213
- </Form>
214
- );
265
+ import React, { useState } from 'react';
266
+ import { Form, TextField } from '@7shifts/sous-chef';
267
+
268
+ export const FirstNameForm = () => {
269
+ const [firstName, setFirstName] = useState('');
270
+
271
+ return (
272
+ <Form onSubmit={() => console.log(firstName)}>
273
+ <TextField
274
+ name="firstName"
275
+ label="First Name"
276
+ value={firstName}
277
+ onChange={setFirstName}
278
+ />
279
+ </Form>
280
+ );
281
+ };
215
282
  ```
216
283
 
217
284
  Notice that in this case you need to pass the `value` and the `onChange` properties to make the form field controllable.
@@ -220,100 +287,373 @@ If there is any validation you can use the `error` prop:
220
287
  Example:
221
288
 
222
289
  ```tsx
223
- const [firstName, setFirstName] = useState('');
224
-
225
- return (
226
- <Form onSubmit={() => console.log(firstName)}>
227
- <TextField
228
- name="firstName"
229
- label="First Name"
230
- value={firstName}
231
- onChange={setFirstName}
232
- error={!firstName && 'First name required!'}
233
- />
234
- </Form>
235
- );
290
+ import React, { useState } from 'react';
291
+ import { Form, TextField } from '@7shifts/sous-chef';
292
+
293
+ export const FirstNameForm = () => {
294
+ const [firstName, setFirstName] = useState('');
295
+
296
+ return (
297
+ <Form onSubmit={() => console.log(firstName)}>
298
+ <TextField
299
+ name="firstName"
300
+ label="First Name"
301
+ value={firstName}
302
+ onChange={setFirstName}
303
+ error={!firstName && 'First name required!'}
304
+ />
305
+ </Form>
306
+ );
307
+ };
236
308
  ```
237
309
 
238
310
  Notice that in this case the validation is manual, and we would need to add other checks to make it a good user experience, for example, checking whether the field was touched before showing the error message. That is why, if you have validations, we recommend using Formik.
239
311
 
240
- ### Formik
312
+ #### Formik
241
313
 
242
314
  Keeping the state in Formik is recommended in most cases because it is robust and has great support for validations.
243
315
 
244
316
  Example:
245
317
 
246
318
  ```tsx
247
- const formik = useFormik({
248
- initialValues: {
249
- firstName: ''
250
- },
251
- onSubmit: (values) => console.log(values.firstName)
252
- });
319
+ import React from 'react';
320
+ import { useFormik } from 'formik';
321
+ import { Button, Form, FormFooter, TextField } from '@7shifts/sous-chef';
253
322
 
254
- return (
255
- <Form formik={formik}>
256
- <TextField name="firstName" label="First Name" />
257
- </Form>
258
- );
323
+ export const FirstNameForm = () => {
324
+ const formik = useFormik({
325
+ initialValues: {
326
+ firstName: ''
327
+ },
328
+ onSubmit: (values) => console.log(values.firstName)
329
+ });
330
+
331
+ return (
332
+ <Form formik={formik}>
333
+ <TextField name="firstName" label="First Name" />
334
+ <FormFooter actions={{ primary: <Button>Save</Button> }} />
335
+ </Form>
336
+ );
337
+ };
259
338
  ```
260
339
 
261
340
  Notice it is way simpler to build the UI using Formik. We just need to pass the `formik` prop to the Sous Chef `Form` component, then it will match the Formik state with the form fields by the `name` prop.
262
341
  So, in this case, the `name="firstName"` will be matched to the `firstName` value in formik. The same applies to all other Sous Chef form fields.
342
+ Names follow Formik's path syntax: `first_name` or `day-parts` match a key with that exact name, while `.` and `[]` read nested values, so `name="items[0].hours"` (or `items.0.hours`) is matched to `values.items[0].hours`.
343
+ If you pass both `formik` and `onSubmit` to `Form`, Formik still validates and calls its own `onSubmit` with the values. The `Form` `onSubmit` only receives the form controls (`HTMLFormControlsCollection`) and runs even when validation fails, so handle the submitted values in Formik's `onSubmit`.
344
+
345
+ ### Submit and Formik behaviour
346
+
347
+ Keep these rules in mind, they are the most common source of bugs:
348
+
349
+ - **Always pass `onSubmit` or `formik` to `Form`.** Without either, submitting does a native form submission and reloads the page.
350
+ - **With Formik, save the values in `useFormik({ onSubmit })`.** On every submit `Form` calls `formik.handleSubmit`, so Formik validates, marks every field as touched, and calls its own `onSubmit` only when the values are valid. If you also pass `onSubmit` to `Form`, it runs on every submit, even when validation fails, so don't save from it.
351
+ - **`Form` `onSubmit` receives `form.elements`, not the values.** The argument is the native `HTMLFormControlsCollection` of the `<form>` element (the default submit is already prevented). Read your values from your own state (or Formik) instead.
352
+ - **Formik errors only show once a field is touched.** Most fields mark themselves as touched on blur, and Formik marks every field as touched when the form is submitted. `RadioGroupField` and `WeekSelectField` have no blur handling, so their errors only show after a submit. An untouched field never shows its Formik error, even if `formik.errors` has one.
353
+ - **An explicit `value` or `error` prop overrides Formik.** If you pass `value` or `error` to a field inside a Formik form, that prop is shown instead of the Formik value or error. Only pass them when you really want to override Formik.
354
+ - **On some fields a custom `onChange` replaces the Formik update.** On `TextField`, `NumberField`, `CurrencyField`, `PercentageField`, `PasswordField`, `TextAreaField`, `ColorField`, `TimeField`, `DateField`, `WeekField`, `DateRangeField` and `TimeRangeField`, a custom `onChange` is called instead of `formik.setFieldValue`, so call `formik.setFieldValue(name, value)` yourself if you need both. On `SelectField`, `AsyncSelectField`, `MultiSelectField`, `PillSelectField`, `CheckboxField`, `RadioGroupField`, `PhoneField` and `WeekSelectField`, a custom `onChange` is called and Formik is updated too. In the same way, a custom `onBlur` on `DateField`, `WeekField`, `DateRangeField` or `TimeRangeField` replaces Formik's `setFieldTouched`.
355
+ - **Field `name`s follow Formik's path syntax.** `first_name` and `day-parts` are single keys, while `.` and `[]` read nested values (`items[0].hours`). Use the same path in `initialValues` and in the Yup schema.
356
+
357
+ ### Form value shapes
358
+
359
+ Each field emits (in `onChange`) and stores in Formik a specific value shape. Use these shapes for your `initialValues`, validation schemas and submit handlers. The last column is the value to use in `initialValues` for an empty field:
360
+
361
+ | Field | Emits / stores | Formik initial value |
362
+ | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | -------------------------------------- |
363
+ | `TextField`, `PasswordField`, `TextAreaField` | `string` | `''` |
364
+ | `NumberField`, `CurrencyField`, `PercentageField` | `string` (numbers are strings too, for example `"12.50"`) | `''` |
365
+ | `PhoneField` | E.164 `string`, for example `"+13065550123"`. It is reset to `''` when the user changes the country | `''` |
366
+ | `TimeField` | `string`, `"9:00 AM"` (12-hour format) or `"09:00"` (24-hour format) | `''` |
367
+ | `ColorField` | `string`, the light-theme hex of the picked color (not the token name) | `''` |
368
+ | `DateField` | `Date` set to the start of the day (`startOfDay`). Formik stores `null` when the field is cleared | `null` |
369
+ | `WeekField` | `Date`, the first day of the picked week (it depends on `weekStart`), set to the start of the day | `null` |
370
+ | `DateRangeField` | `{ start?: Date; end?: Date }` | `{ start: undefined, end: undefined }` |
371
+ | `TimeRangeField` | `{ start?: string; end?: string }`, each side in the `TimeField` format | `{ start: '', end: '' }` |
372
+ | `SelectField`, `AsyncSelectField` | the full option object `{ value, label }`, NOT just the `value`. `null` when cleared (`isClearable`) | `null` |
373
+ | `MultiSelectField`, `PillSelectField` | an array of option objects `{ value, label }[]` | `[]` |
374
+ | `WeekSelectField` | `Date[]`, the selected entries of `days` | `[]` |
375
+ | `CheckboxField` | `boolean` | `false` |
376
+ | `RadioGroupField` | `string \| number`, the `value` of the checked `RadioGroupOption` (with the same type) | `''` (or `null` for number values) |
377
+
378
+ For example, a `SelectField` named `role` stores `{ value: 'manager', label: 'Manager' }` in `formik.values.role`, so its initial value must be an option object (or `null`), and you read `values.role?.value` when submitting.
263
379
 
264
380
  ### Form validation
265
381
 
266
- For form validation, we recommend using `Formik` with `Yup`.
382
+ For form validation, we recommend using `Formik` with `Yup`. Pass the schema to `useFormik` through `validationSchema`, and every error shows in the field with the matching `name` (once the field is touched), WITHOUT passing the `error` prop.
267
383
 
268
- Example:
384
+ Always give every Yup rule a message. Without one, Yup shows its default message with the field path, for example "dateRange.start is a required field".
385
+
386
+ Match the Yup type to the value shape of each field:
387
+
388
+ - String fields: `Yup.string()`.
389
+ - `NumberField`, `CurrencyField` and `PercentageField` store strings, so `Yup.number()` needs a `transform` that turns `''` into `undefined`. Without it, an empty field fails with the `typeError` message instead of the `required` one, and an empty optional field never passes.
390
+ - `DateField` and `WeekField` store `null` when empty: `Yup.date().nullable().required('…')`.
391
+ - `DateRangeField` and `TimeRangeField` store an object: validate each side with `Yup.object({ start: …, end: … })`. The field shows the `start` error first, then the `end` one.
392
+ - `SelectField` and `AsyncSelectField` store the option object or `null`: `Yup.object().nullable().required('…')`.
393
+ - `MultiSelectField`, `PillSelectField` and `WeekSelectField` store arrays: `Yup.array().min(1, '…')`.
394
+ - `CheckboxField` stores a boolean: `Yup.boolean().oneOf([true], '…')` when it must be checked.
395
+ - `RadioGroupField` stores the option `value`: `Yup.string().required('…')` (or `Yup.number()` for number values).
396
+
397
+ Here is a complete form that binds every field type to Formik and validates it with Yup:
269
398
 
270
399
  ```tsx
400
+ import React from 'react';
271
401
  import { useFormik } from 'formik';
272
402
  import * as Yup from 'yup';
403
+ import {
404
+ AsyncSelectField,
405
+ Button,
406
+ CheckboxField,
407
+ ColorField,
408
+ CurrencyField,
409
+ DateField,
410
+ DateRangeField,
411
+ Form,
412
+ FormFooter,
413
+ FormRow,
414
+ FormSection,
415
+ MultiSelectField,
416
+ NumberField,
417
+ PasswordField,
418
+ PercentageField,
419
+ PhoneField,
420
+ PillSelectField,
421
+ RadioGroupField,
422
+ RadioGroupOption,
423
+ SelectField,
424
+ TextAreaField,
425
+ TextField,
426
+ TimeField,
427
+ TimeRangeField,
428
+ WeekField,
429
+ WeekSelectField
430
+ } from '@7shifts/sous-chef';
431
+ import type {
432
+ DateRange,
433
+ PillSelectOption,
434
+ SelectOption,
435
+ TimeRange
436
+ } from '@7shifts/sous-chef';
437
+
438
+ type FormValues = {
439
+ firstName: string;
440
+ password: string;
441
+ notes: string;
442
+ hourlyWage: string;
443
+ maxHours: string;
444
+ tipShare: string;
445
+ phone: string;
446
+ color: string;
447
+ startTime: string;
448
+ availability: TimeRange;
449
+ hireDate: Date | null;
450
+ firstWeek: Date | null;
451
+ vacation: DateRange;
452
+ role: SelectOption<string> | null;
453
+ location: SelectOption<number> | null;
454
+ skills: SelectOption<string>[];
455
+ preferredDays: PillSelectOption<string>[];
456
+ workingDays: Date[];
457
+ payType: string;
458
+ acceptsTerms: boolean;
459
+ };
460
+
461
+ // The 7 days of the week to pick from in `WeekSelectField`.
462
+ const WEEK_DAYS = Array.from(
463
+ { length: 7 },
464
+ (_, i) => new Date(2026, 5, 14 + i)
465
+ );
466
+
467
+ const initialValues: FormValues = {
468
+ firstName: '',
469
+ password: '',
470
+ notes: '',
471
+ hourlyWage: '',
472
+ maxHours: '',
473
+ tipShare: '',
474
+ phone: '',
475
+ color: '',
476
+ startTime: '',
477
+ availability: { start: '', end: '' },
478
+ hireDate: null,
479
+ firstWeek: null,
480
+ vacation: { start: undefined, end: undefined },
481
+ role: null,
482
+ location: null,
483
+ skills: [],
484
+ preferredDays: [],
485
+ workingDays: [],
486
+ payType: '',
487
+ acceptsTerms: false
488
+ };
273
489
 
274
- const schema = Yup.object().shape({
275
- firstName: Yup.string()
276
- .min(2, 'Too Short!')
277
- .max(50, 'Too Long!')
278
- .required('Required'),
279
- lastName: Yup.string()
280
- .min(2, 'Too Short!')
281
- .max(50, 'Too Long!')
282
- .required('Required'),
283
- email: Yup.string().email('Invalid email').required('Required'),
284
- birthdate: Yup.date().required('Required')
490
+ const optionSchema = Yup.object({
491
+ value: Yup.mixed().required('An option value is required'),
492
+ label: Yup.string().required('An option label is required')
285
493
  });
286
494
 
287
- const formik: any = useFormik({
288
- initialValues: {
289
- firstName: '',
290
- lastName: '',
291
- email: '',
292
- birthdate: null
293
- },
294
- validationSchema: schema,
295
- onSubmit: (submittedValues) => action('onSubmit')(submittedValues)
495
+ // Number-like fields store `''` when empty, which `Yup.number()` rejects as "not a number".
496
+ // Turn it into `undefined` so empty optional fields pass and empty required fields get the `required` message.
497
+ const emptyToUndefined = (value: number, originalValue: unknown) =>
498
+ originalValue === '' ? undefined : value;
499
+
500
+ const schema = Yup.object({
501
+ // TextField, PasswordField, TextAreaField, PhoneField, ColorField and TimeField store strings
502
+ firstName: Yup.string().required('Enter a first name'),
503
+ password: Yup.string()
504
+ .min(8, 'Use at least 8 characters')
505
+ .required('Enter a password'),
506
+ notes: Yup.string().max(200, 'Keep notes under 200 characters'),
507
+ phone: Yup.string().required('Enter a phone number'),
508
+ color: Yup.string().required('Pick a color'),
509
+ startTime: Yup.string().required('Pick a start time'),
510
+ // CurrencyField, NumberField and PercentageField store numbers as strings too
511
+ hourlyWage: Yup.number()
512
+ .transform(emptyToUndefined)
513
+ .typeError('Enter a number')
514
+ .min(0, 'The wage cannot be negative')
515
+ .required('Enter a wage'),
516
+ maxHours: Yup.number()
517
+ .transform(emptyToUndefined)
518
+ .typeError('Enter a number')
519
+ .required('Enter the max hours'),
520
+ tipShare: Yup.number()
521
+ .transform(emptyToUndefined)
522
+ .typeError('Enter a number')
523
+ .max(100, 'Max 100%'),
524
+ // Range fields store an object, so validate each side
525
+ availability: Yup.object({
526
+ start: Yup.string().required('Pick a start time'),
527
+ end: Yup.string().required('Pick an end time')
528
+ }),
529
+ vacation: Yup.object({
530
+ start: Yup.date().required('Pick a start date'),
531
+ end: Yup.date()
532
+ .min(Yup.ref('start'), 'The end date must be after the start date')
533
+ .required('Pick an end date')
534
+ }),
535
+ // DateField and WeekField store `null` when empty, so they must be nullable
536
+ hireDate: Yup.date().nullable().required('Pick a hire date'),
537
+ firstWeek: Yup.date().nullable().required('Pick a week'),
538
+ // SelectField and AsyncSelectField store the whole option object, or `null`
539
+ role: optionSchema.nullable().required('Pick a role'),
540
+ location: optionSchema.nullable().required('Pick a location'),
541
+ // MultiSelectField, PillSelectField and WeekSelectField store arrays
542
+ skills: Yup.array().of(optionSchema).min(1, 'Pick at least one skill'),
543
+ preferredDays: Yup.array().min(1, 'Pick at least one day'),
544
+ workingDays: Yup.array().min(1, 'Pick at least one working day'),
545
+ // RadioGroupField stores the `value` of the checked option
546
+ payType: Yup.string().required('Pick a pay type'),
547
+ // CheckboxField stores a boolean
548
+ acceptsTerms: Yup.boolean().oneOf([true], 'You must accept the terms')
296
549
  });
297
550
 
298
- return (
299
- <Form formik={formik}>
300
- <FormRow>
301
- <TextField name="firstName" label="First Name" />
302
- <TextField name="lastName" label="Last Name" />
303
- </FormRow>
304
- <TextField name="email" label="Email" />
305
- <DateField name="birthdate" label="birthdate" />
306
- <FormFooter
307
- actions={{
308
- primary: <Button disabled={!formik.isValid}>Save</Button>
309
- }}
310
- />
311
- </Form>
312
- );
551
+ const loadLocations = (search: string) =>
552
+ Promise.resolve({
553
+ options: [
554
+ { value: 1, label: 'Downtown' },
555
+ { value: 2, label: 'Uptown' }
556
+ ].filter((option) =>
557
+ option.label.toLowerCase().includes(search.toLowerCase())
558
+ ),
559
+ hasMore: false
560
+ });
561
+
562
+ export const EmployeeForm = () => {
563
+ const formik = useFormik<FormValues>({
564
+ initialValues,
565
+ validationSchema: schema,
566
+ onSubmit: (values) =>
567
+ console.log({
568
+ ...values,
569
+ // Selects store the option object: read `.value` to send the id
570
+ role: values.role?.value,
571
+ location: values.location?.value,
572
+ skills: values.skills.map((option) => option.value)
573
+ })
574
+ });
575
+
576
+ return (
577
+ <Form formik={formik}>
578
+ <FormSection title="Profile">
579
+ <TextField name="firstName" label="First name" />
580
+ <PasswordField name="password" label="Password" />
581
+ <TextAreaField name="notes" label="Notes (optional)" />
582
+ <PhoneField name="phone" label="Phone" />
583
+ <ColorField name="color" label="Color" />
584
+ </FormSection>
585
+ <FormSection title="Pay">
586
+ <FormRow>
587
+ <CurrencyField name="hourlyWage" label="Hourly wage" />
588
+ <NumberField name="maxHours" label="Max hours" />
589
+ <PercentageField
590
+ name="tipShare"
591
+ label="Tip share (optional)"
592
+ />
593
+ </FormRow>
594
+ <RadioGroupField name="payType" label="Pay type">
595
+ <RadioGroupOption value="hourly" label="Hourly" />
596
+ <RadioGroupOption value="salary" label="Salary" />
597
+ </RadioGroupField>
598
+ </FormSection>
599
+ <FormSection title="Schedule">
600
+ <FormRow>
601
+ <DateField name="hireDate" label="Hire date" />
602
+ <WeekField name="firstWeek" label="First week" />
603
+ </FormRow>
604
+ <DateRangeField name="vacation" label="Vacation" />
605
+ <FormRow>
606
+ <TimeField name="startTime" label="Usual start time" />
607
+ <TimeRangeField name="availability" label="Availability" />
608
+ </FormRow>
609
+ <WeekSelectField
610
+ name="workingDays"
611
+ label="Working days"
612
+ days={WEEK_DAYS}
613
+ />
614
+ <PillSelectField
615
+ name="preferredDays"
616
+ label="Preferred days"
617
+ options={[
618
+ { value: 'weekdays', label: 'Weekdays' },
619
+ { value: 'weekends', label: 'Weekends' }
620
+ ]}
621
+ />
622
+ </FormSection>
623
+ <FormSection title="Role">
624
+ <SelectField
625
+ name="role"
626
+ label="Role"
627
+ options={[
628
+ { value: 'server', label: 'Server' },
629
+ { value: 'cook', label: 'Cook' }
630
+ ]}
631
+ />
632
+ <AsyncSelectField
633
+ name="location"
634
+ label="Location"
635
+ loadOptions={loadLocations}
636
+ />
637
+ <MultiSelectField
638
+ name="skills"
639
+ label="Skills"
640
+ options={[
641
+ { value: 'bar', label: 'Bar' },
642
+ { value: 'grill', label: 'Grill' }
643
+ ]}
644
+ />
645
+ <CheckboxField
646
+ name="acceptsTerms"
647
+ label="I accept the terms and conditions"
648
+ />
649
+ </FormSection>
650
+ <FormFooter actions={{ primary: <Button>Save</Button> }} />
651
+ </Form>
652
+ );
653
+ };
313
654
  ```
314
655
 
315
- Notice that in this example, we define the validation schema with `Yup`, then send it to `formik` through `validationSchema`. If there is any error, it will display automatically in the form field WITHOUT the need to pass the `error` prop.
316
- Also, you can make use of `formik.isValid` and `formik.touched`, in this case the `formik.isValid` was used in the submit button.
656
+ You can also use `formik.isValid`, `formik.dirty` and `formik.touched` to drive the UI, for example to show a summary of the errors.
317
657
 
318
658
  ## Data Tables
319
659
 
@@ -324,6 +664,9 @@ Data tables can go from simple tables to more complex use-cases with pagination
324
664
  Example of simple table:
325
665
 
326
666
  ```tsx
667
+ import React from 'react';
668
+ import { DataTable } from '@7shifts/sous-chef';
669
+
327
670
  const ITEMS = [
328
671
  {
329
672
  date: 'Jun 22, 2019',
@@ -337,7 +680,7 @@ const ITEMS = [
337
680
  }
338
681
  ];
339
682
 
340
- <DataTable items={ITEMS} />;
683
+ export const HoursTable = () => <DataTable items={ITEMS} />;
341
684
  ```
342
685
 
343
686
  However, in most cases, you will need columns:
@@ -345,7 +688,11 @@ However, in most cases, you will need columns:
345
688
  Example using columns:
346
689
 
347
690
  ```tsx
348
- const COLUMNS = [
691
+ import React from 'react';
692
+ import { DataTable, Text } from '@7shifts/sous-chef';
693
+ import type { DataTableColumn } from '@7shifts/sous-chef';
694
+
695
+ const COLUMNS: DataTableColumn[] = [
349
696
  {
350
697
  label: 'Employee Name',
351
698
  name: 'employeeName'
@@ -370,11 +717,12 @@ const ITEMS = [
370
717
  {
371
718
  date: 'Jan 15, 2020',
372
719
  employeeName: 'Alex Andrade',
373
- hours: <Text color="red">8</Text>
720
+ // Use a color token name, never a hardcoded color
721
+ hours: <Text color="danger-color">8</Text>
374
722
  }
375
723
  ];
376
724
 
377
- <DataTable columns={COLUMNS} items={ITEMS} />;
725
+ export const HoursTable = () => <DataTable columns={COLUMNS} items={ITEMS} />;
378
726
  ```
379
727
 
380
728
  Notice in this example, when there is no use of the `itemComponent` prop, the cells will be matched using the column `name` and the object property in each `ITEMS` element.
@@ -385,10 +733,20 @@ Also notice, the `Hours` column is right-aligned. That means all the SORTING, AL
385
733
  It is recommended to use the `itemComponent` prop to fully customize how each row and cell will look:
386
734
 
387
735
  ```tsx
388
- import { DataTable, DataTableRow, Inline, Avatar } from '@7shifts/sous-chef';
389
- import type { DataTableCustomComponent } from '@7shifts/sous-chef';
390
-
391
- const COLUMNS = [
736
+ import React from 'react';
737
+ import {
738
+ Avatar,
739
+ DataTable,
740
+ DataTableCell,
741
+ DataTableRow,
742
+ Inline
743
+ } from '@7shifts/sous-chef';
744
+ import type {
745
+ DataTableColumn,
746
+ DataTableCustomComponent
747
+ } from '@7shifts/sous-chef';
748
+
749
+ const COLUMNS: DataTableColumn[] = [
392
750
  {
393
751
  name: 'employeeName',
394
752
  label: 'Employee',
@@ -408,15 +766,15 @@ type Item = {
408
766
  employeeName: string;
409
767
  date: string;
410
768
  hours: number;
411
- image: string;
769
+ image?: string;
412
770
  };
413
771
 
414
772
  const ITEMS: Item[] = [
415
773
  {
416
774
  employeeName: 'Steve Lawrence',
417
775
  date: 'Jun 22, 2019',
418
- hours: 15,
419
- image: IMAGE_URL
776
+ hours: 15
777
+ // No image: the Avatar shows a placeholder
420
778
  },
421
779
  {
422
780
  employeeName: 'Alex Andrade',
@@ -463,7 +821,11 @@ In order to use pagination, you need to specify the `onPreviousClick` and `onNex
463
821
  With this, it will render the Pagination Controls at the bottom of the table.
464
822
 
465
823
  ```tsx
466
- const COLUMNS = [
824
+ import React from 'react';
825
+ import { DataTable } from '@7shifts/sous-chef';
826
+ import type { DataTableColumn } from '@7shifts/sous-chef';
827
+
828
+ const COLUMNS: DataTableColumn[] = [
467
829
  {
468
830
  label: 'Employee',
469
831
  name: 'employeeName'
@@ -491,12 +853,14 @@ const ITEMS = [
491
853
  }
492
854
  ];
493
855
 
494
- <DataTable
495
- columns={COLUMNS}
496
- items={ITEMS}
497
- hasNext={true}
498
- hasPrevious={false}
499
- onNextClick={() => console.log('Fetch next page')}
500
- onPreviousClick={() => console.log('Fetch previous page')}
501
- />;
856
+ export const HoursTable = () => (
857
+ <DataTable
858
+ columns={COLUMNS}
859
+ items={ITEMS}
860
+ hasNext={true}
861
+ hasPrevious={false}
862
+ onNextClick={() => console.log('Fetch next page')}
863
+ onPreviousClick={() => console.log('Fetch previous page')}
864
+ />
865
+ );
502
866
  ```