@saleor/macaw-ui 0.4.0 → 0.5.2

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 (264) hide show
  1. package/dist/ActionBar/ActionBar.d.ts +8 -0
  2. package/dist/ActionBar/ActionBar.stories.d.ts +4 -0
  3. package/dist/ActionBar/context.d.ts +9 -0
  4. package/dist/ActionBar/index.d.ts +2 -0
  5. package/dist/ActionBar/styles.d.ts +2 -0
  6. package/dist/Alert/Alert.d.ts +8 -0
  7. package/dist/Alert/Alert.stories.d.ts +12 -0
  8. package/dist/Alert/AlertBase.d.ts +8 -0
  9. package/dist/Alert/index.d.ts +2 -0
  10. package/dist/Alert/styles.d.ts +2 -0
  11. package/dist/Backlink/Backlink.d.ts +8 -0
  12. package/dist/Backlink/Backlink.stories.d.ts +5 -0
  13. package/dist/Backlink/context.d.ts +5 -0
  14. package/dist/Backlink/index.d.ts +2 -0
  15. package/dist/Backlink/styles.d.ts +2 -0
  16. package/dist/BaseList/BaseList.d.ts +26 -0
  17. package/dist/BaseList/context.d.ts +7 -0
  18. package/dist/BaseList/index.d.ts +1 -0
  19. package/dist/BaseList/styles.d.ts +5 -0
  20. package/dist/Button/Button.d.ts +16 -0
  21. package/dist/Button/index.d.ts +1 -0
  22. package/dist/Button/styles.d.ts +2 -0
  23. package/dist/ConfirmButton/ConfirmButton.d.ts +11 -0
  24. package/dist/ConfirmButton/ConfirmButton.stories.d.ts +8 -0
  25. package/dist/ConfirmButton/index.d.ts +1 -0
  26. package/dist/ConfirmButton/styles.d.ts +2 -0
  27. package/dist/DialogHeader/DialogHeader.d.ts +6 -0
  28. package/dist/DialogHeader/index.d.ts +1 -0
  29. package/dist/DialogHeader/styles.d.ts +1 -0
  30. package/dist/DialogTable/DialogTable.d.ts +6 -0
  31. package/dist/DialogTable/index.d.ts +1 -0
  32. package/dist/DialogTable/styles.d.ts +1 -0
  33. package/dist/Filter/Filter.d.ts +10 -0
  34. package/dist/Filter/Filter.stories.d.ts +5 -0
  35. package/dist/Filter/FilterBar.d.ts +11 -0
  36. package/dist/Filter/FilterContent.d.ts +7 -0
  37. package/dist/Filter/FilterField/MultipleSelectFilterField.d.ts +6 -0
  38. package/dist/Filter/FilterField/RangeFilterField.d.ts +7 -0
  39. package/dist/Filter/FilterField/SelectFilterField.d.ts +6 -0
  40. package/dist/Filter/FilterField/TextFilterField.d.ts +6 -0
  41. package/dist/Filter/FilterMenu.d.ts +9 -0
  42. package/dist/Filter/context.d.ts +4 -0
  43. package/dist/Filter/index.d.ts +4 -0
  44. package/dist/Filter/styles.d.ts +2 -0
  45. package/dist/Filter/types.d.ts +49 -0
  46. package/dist/Filter/utils.d.ts +8 -0
  47. package/dist/IconButton/IconButton.d.ts +8 -0
  48. package/dist/IconButton/index.d.ts +1 -0
  49. package/dist/IconButton/partials.d.ts +14 -0
  50. package/dist/IconButton/styles.d.ts +2 -0
  51. package/dist/LayoutButton/LayoutButton.d.ts +7 -0
  52. package/dist/LayoutButton/index.d.ts +1 -0
  53. package/dist/LayoutButton/styles.d.ts +2 -0
  54. package/dist/List/List.d.ts +13 -0
  55. package/dist/List/List.stories.d.ts +5 -0
  56. package/dist/List/context.d.ts +8 -0
  57. package/dist/List/index.d.ts +1 -0
  58. package/dist/List/styles.d.ts +1 -0
  59. package/dist/Notification/Notification.d.ts +3 -0
  60. package/dist/Notification/Notification.stories.d.ts +10 -0
  61. package/dist/Notification/index.d.ts +2 -0
  62. package/dist/Notification/styles.d.ts +2 -0
  63. package/dist/Notification/types.d.ts +16 -0
  64. package/dist/OffsettedList/OffsettedList.d.ts +12 -0
  65. package/dist/OffsettedList/OffsettedList.stories.d.ts +5 -0
  66. package/dist/OffsettedList/index.d.ts +1 -0
  67. package/dist/OffsettedList/styles.d.ts +2 -0
  68. package/dist/PageTabs/PageTab.d.ts +3 -0
  69. package/dist/PageTabs/PageTab.stories.d.ts +4 -0
  70. package/dist/PageTabs/PageTabPanel.d.ts +4 -0
  71. package/dist/PageTabs/PageTabs.d.ts +5 -0
  72. package/dist/PageTabs/index.d.ts +3 -0
  73. package/dist/PageTabs/styles.d.ts +2 -0
  74. package/dist/Pagination/Pagination.d.ts +10 -0
  75. package/dist/Pagination/PaginationActions.d.ts +11 -0
  76. package/dist/Pagination/PaginationRowNumberSelect.d.ts +11 -0
  77. package/dist/Pagination/TablePagination.d.ts +6 -0
  78. package/dist/Pagination/index.d.ts +4 -0
  79. package/dist/Pagination/styles.d.ts +2 -0
  80. package/dist/PillLink/PillLink.d.ts +15 -0
  81. package/dist/PillLink/index.d.ts +1 -0
  82. package/dist/PillLink/styles.d.ts +2 -0
  83. package/dist/ResponsiveTable/ResponsiveTable.d.ts +8 -0
  84. package/dist/ResponsiveTable/index.d.ts +1 -0
  85. package/dist/ResponsiveTable/styles.d.ts +2 -0
  86. package/dist/Savebar/ButtonTooltipDecorator.d.ts +6 -0
  87. package/dist/Savebar/Savebar.d.ts +14 -0
  88. package/dist/Savebar/Savebar.stories.d.ts +6 -0
  89. package/dist/Savebar/index.d.ts +1 -0
  90. package/dist/Savebar/styles.d.ts +2 -0
  91. package/dist/ScrollShadow/ScrollShadow.d.ts +6 -0
  92. package/dist/ScrollShadow/index.d.ts +1 -0
  93. package/dist/ScrollShadow/styles.d.ts +1 -0
  94. package/dist/Sidebar/ExpandButton.d.ts +6 -0
  95. package/dist/Sidebar/MenuItem.d.ts +11 -0
  96. package/dist/Sidebar/Sidebar.d.ts +6 -0
  97. package/dist/Sidebar/Sidebar.stories.d.ts +6 -0
  98. package/dist/Sidebar/fixtures.d.ts +2 -0
  99. package/dist/Sidebar/index.d.ts +4 -0
  100. package/dist/Sidebar/types.d.ts +16 -0
  101. package/dist/SidebarDrawer/MenuItemBtn.d.ts +7 -0
  102. package/dist/SidebarDrawer/SidebarDrawer.d.ts +4 -0
  103. package/dist/SidebarDrawer/SidebarDrawer.stories.d.ts +4 -0
  104. package/dist/SidebarDrawer/index.d.ts +2 -0
  105. package/dist/SidebarDrawer/styles.d.ts +2 -0
  106. package/dist/SquareButton/SquareButton.d.ts +3 -0
  107. package/dist/SquareButton/SquareButton.stories.d.ts +5 -0
  108. package/dist/SquareButton/index.d.ts +1 -0
  109. package/dist/StatusChip/StatusChip.d.ts +3 -0
  110. package/dist/StatusChip/StatusChip.stories.d.ts +8 -0
  111. package/dist/StatusChip/index.d.ts +2 -0
  112. package/dist/StatusChip/styles.d.ts +3 -0
  113. package/dist/StatusChip/types.d.ts +8 -0
  114. package/dist/Tooltip/Tooltip.d.ts +6 -0
  115. package/dist/Tooltip/Tooltip.stories.d.ts +7 -0
  116. package/dist/Tooltip/index.d.ts +1 -0
  117. package/dist/Tooltip/styles.d.ts +3 -0
  118. package/dist/UserChipMenu/UserChipMenu.d.ts +9 -0
  119. package/dist/UserChipMenu/UserChipMenu.stories.d.ts +6 -0
  120. package/dist/UserChipMenu/UserChipMenuItem.d.ts +6 -0
  121. package/dist/UserChipMenu/context.d.ts +4 -0
  122. package/dist/UserChipMenu/index.d.ts +2 -0
  123. package/dist/UserChipMenu/styles.d.ts +2 -0
  124. package/dist/cjs/index.js +2 -2
  125. package/dist/cjs/index.js.map +3 -3
  126. package/dist/esm/index.js +2 -2
  127. package/dist/esm/index.js.map +3 -3
  128. package/dist/extensions/index.d.ts +3 -0
  129. package/dist/extensions/sendMessage.d.ts +3 -0
  130. package/dist/extensions/types.d.ts +22 -0
  131. package/dist/extensions/useExtensionMessage.d.ts +2 -0
  132. package/dist/icons/ArrowDropdownIcon.d.ts +2 -0
  133. package/dist/icons/ArrowRightIcon.d.ts +1 -0
  134. package/dist/icons/CheckboxCheckedIcon.d.ts +1 -0
  135. package/dist/icons/CheckboxIcon.d.ts +1 -0
  136. package/dist/icons/CheckboxIndeterminateIcon.d.ts +1 -0
  137. package/dist/icons/CloseIcon.d.ts +1 -0
  138. package/dist/icons/CompleteIcon.d.ts +2 -0
  139. package/dist/icons/DeleteIcon.d.ts +1 -0
  140. package/dist/icons/EditIcon.d.ts +1 -0
  141. package/dist/icons/FilteringIcon.d.ts +1 -0
  142. package/dist/icons/ImageIcon.d.ts +1 -0
  143. package/dist/icons/InfoIcon.d.ts +2 -0
  144. package/dist/icons/Logo.d.ts +2 -0
  145. package/dist/icons/LogoLight.d.ts +2 -0
  146. package/dist/icons/MoreIcon.d.ts +1 -0
  147. package/dist/icons/NavigatorIcon.d.ts +1 -0
  148. package/dist/icons/NotAllowedIcon.d.ts +2 -0
  149. package/dist/icons/NotAllowedInvertedIcon.d.ts +2 -0
  150. package/dist/icons/PlusIcon.d.ts +1 -0
  151. package/dist/icons/RadioCheckedIcon.d.ts +1 -0
  152. package/dist/icons/RadioIcon.d.ts +1 -0
  153. package/dist/icons/SearchIcon.d.ts +1 -0
  154. package/dist/icons/WarningIcon.d.ts +2 -0
  155. package/dist/icons/index.d.ts +18 -0
  156. package/dist/index.d.ts +29 -0
  157. package/dist/index.js +2 -0
  158. package/dist/index.js.map +7 -0
  159. package/dist/localStorageKeys.d.ts +4 -0
  160. package/dist/mjs/index.js +5 -0
  161. package/dist/mjs/index.js.map +7 -0
  162. package/dist/theme/Baseline.d.ts +2 -0
  163. package/dist/theme/ThemeProvider.d.ts +17 -0
  164. package/dist/theme/context.d.ts +3 -0
  165. package/dist/theme/createSaleorTheme/createSaleorTheme.d.ts +3 -0
  166. package/dist/theme/createSaleorTheme/index.d.ts +2 -0
  167. package/dist/theme/createSaleorTheme/overrides/buttons.d.ts +3 -0
  168. package/dist/theme/createSaleorTheme/overrides/controls.d.ts +3 -0
  169. package/dist/theme/createSaleorTheme/overrides/index.d.ts +3 -0
  170. package/dist/theme/createSaleorTheme/overrides/inputs.d.ts +3 -0
  171. package/dist/theme/createSaleorTheme/overrides/tables.d.ts +3 -0
  172. package/dist/theme/createSaleorTheme/palette.d.ts +2 -0
  173. package/dist/theme/createSaleorTheme/shadows.d.ts +2 -0
  174. package/dist/theme/createSaleorTheme/types.d.ts +51 -0
  175. package/dist/theme/index.d.ts +4 -0
  176. package/dist/theme/styles.d.ts +5 -0
  177. package/dist/theme/themes.d.ts +3 -0
  178. package/dist/theme/types.d.ts +6 -0
  179. package/dist/theme/utils.d.ts +1 -0
  180. package/dist/theme/utils.test.d.ts +1 -0
  181. package/dist/tools/index.d.ts +2 -0
  182. package/dist/tools/useElementScroll.d.ts +12 -0
  183. package/dist/tools/useLocalStorage.d.ts +5 -0
  184. package/dist/tools/useWindowScroll.d.ts +4 -0
  185. package/dist/types/Autocomplete/Autocomplete.d.ts +23 -0
  186. package/dist/types/Autocomplete/Autocomplete.stories.d.ts +5 -0
  187. package/dist/types/Autocomplete/fixtures.d.ts +4 -0
  188. package/dist/types/Autocomplete/index.d.ts +1 -0
  189. package/dist/types/Autocomplete/styles.d.ts +2 -0
  190. package/dist/types/Backlink/Backlink.d.ts +6 -4
  191. package/dist/types/Filter/FilterField/AutocompleteFilterField.d.ts +6 -0
  192. package/dist/types/Filter/FilterField/MultipleValueAutocompleteFilterField.d.ts +6 -0
  193. package/dist/types/Filter/stories/Filter.stories.d.ts +5 -0
  194. package/dist/types/Filter/stories/FilterInteractive.stories.d.ts +4 -0
  195. package/dist/types/Filter/stories/labels.d.ts +8 -0
  196. package/dist/types/Filter/styles.d.ts +1 -1
  197. package/dist/types/Filter/types.d.ts +8 -2
  198. package/dist/types/Filter/utils.d.ts +4 -1
  199. package/dist/types/IconButton/IconButton.d.ts +44 -2
  200. package/dist/types/LayoutButton/LayoutButton.d.ts +29 -2
  201. package/dist/types/MultipleValueAutocomplete/MultipleValueAutocomplete.d.ts +26 -0
  202. package/dist/types/MultipleValueAutocomplete/MultipleValueAutocomplete.stories.d.ts +6 -0
  203. package/dist/types/MultipleValueAutocomplete/fixtures.d.ts +4 -0
  204. package/dist/types/MultipleValueAutocomplete/index.d.ts +1 -0
  205. package/dist/types/MultipleValueAutocomplete/styles.d.ts +2 -0
  206. package/dist/types/MultipleValueAutocomplete/useMultipleValueAutocomplete.d.ts +32 -0
  207. package/dist/types/StatusChip/styles.d.ts +3 -0
  208. package/dist/types/SwitchSelector/SwitchSelector.d.ts +2 -0
  209. package/dist/types/SwitchSelector/SwitchSelector.stories.d.ts +4 -0
  210. package/dist/types/SwitchSelector/SwitchSelectorButton.d.ts +8 -0
  211. package/dist/types/SwitchSelector/index.d.ts +2 -0
  212. package/dist/types/consts.d.ts +4 -0
  213. package/dist/types/index.d.ts +3 -0
  214. package/dist/types/tools/useTextWidth.d.ts +2 -0
  215. package/dist/types/utils/mergeRefs.d.ts +2 -0
  216. package/dist/types/utils/useMockAutocomplete.d.ts +10 -0
  217. package/dist/utils/Decorator.d.ts +4 -0
  218. package/dist/utils/useListStory.d.ts +21 -0
  219. package/package.json +10 -6
  220. package/src/Autocomplete/Autocomplete.stories.tsx +43 -0
  221. package/src/Autocomplete/Autocomplete.tsx +188 -0
  222. package/src/Autocomplete/fixtures.ts +122 -0
  223. package/src/Autocomplete/index.ts +1 -0
  224. package/src/Autocomplete/styles.ts +22 -0
  225. package/src/Backlink/Backlink.tsx +7 -7
  226. package/src/Backlink/styles.ts +1 -1
  227. package/src/Chip/styles.ts +2 -1
  228. package/src/Filter/Filter.tsx +88 -44
  229. package/src/Filter/FilterBar.tsx +15 -9
  230. package/src/Filter/FilterContent.tsx +8 -1
  231. package/src/Filter/FilterField/AutocompleteFilterField.tsx +61 -0
  232. package/src/Filter/FilterField/MultipleSelectFilterField.tsx +6 -2
  233. package/src/Filter/FilterField/MultipleValueAutocompleteFilterField.tsx +60 -0
  234. package/src/Filter/context.tsx +1 -1
  235. package/src/Filter/{Filter.stories.tsx → stories/Filter.stories.tsx} +47 -13
  236. package/src/Filter/stories/FilterInteractive.stories.tsx +97 -0
  237. package/src/Filter/stories/labels.ts +8 -0
  238. package/src/Filter/styles.ts +37 -6
  239. package/src/Filter/types.ts +8 -1
  240. package/src/Filter/utils.ts +71 -5
  241. package/src/IconButton/IconButton.tsx +29 -7
  242. package/src/LayoutButton/LayoutButton.tsx +39 -23
  243. package/src/MultipleValueAutocomplete/MultipleValueAutocomplete.stories.tsx +76 -0
  244. package/src/MultipleValueAutocomplete/MultipleValueAutocomplete.tsx +185 -0
  245. package/src/MultipleValueAutocomplete/fixtures.ts +122 -0
  246. package/src/MultipleValueAutocomplete/index.ts +1 -0
  247. package/src/MultipleValueAutocomplete/styles.ts +41 -0
  248. package/src/MultipleValueAutocomplete/useMultipleValueAutocomplete.ts +172 -0
  249. package/src/SwitchSelector/SwitchSelector.stories.tsx +63 -0
  250. package/src/SwitchSelector/SwitchSelector.tsx +20 -0
  251. package/src/SwitchSelector/SwitchSelectorButton.tsx +60 -0
  252. package/src/SwitchSelector/index.ts +2 -0
  253. package/src/consts.ts +4 -0
  254. package/src/index.tsx +3 -0
  255. package/src/theme/createSaleorTheme/createSaleorTheme.tsx +1 -1
  256. package/src/tools/useTextWidth.ts +20 -0
  257. package/src/utils/mergeRefs.ts +14 -0
  258. package/src/utils/useMockAutocomplete.ts +37 -0
  259. package/dist/types/Chip/ColorSwatch.d.ts +0 -6
  260. package/dist/types/Chip/common/ChipMovable.d.ts +0 -5
  261. package/dist/types/Chip/common/ChipRemovable.d.ts +0 -6
  262. package/dist/types/Chip/common/ChipSwatch.d.ts +0 -7
  263. package/dist/types/Chip/common/index.d.ts +0 -3
  264. package/src/Chip/.DS_Store +0 -0
@@ -1,24 +1,40 @@
1
1
  import ButtonBase from "@material-ui/core/ButtonBase";
2
+ import { IconButtonTypeMap as MuiIconButtonTypeMap } from "@material-ui/core/IconButton";
2
3
  import MuiIconButton, {
3
4
  IconButtonProps as MuiIconButtonProps,
4
5
  } from "@material-ui/core/IconButton";
6
+ import { OverrideProps } from "@material-ui/core/OverridableComponent";
5
7
  import clsx from "clsx";
6
8
  import React from "react";
7
9
 
8
10
  import { UserInteraction } from "../../types/utils";
9
11
  import useStyles from "./styles";
10
12
 
11
- export type IconButtonProps<T extends React.ElementType = "button"> = Omit<
12
- MuiIconButtonProps<T>,
13
- "variant"
14
- > & {
13
+ interface IconButtonInnerProps {
15
14
  error?: boolean;
16
15
  hoverOutline?: boolean;
17
16
  state?: UserInteraction;
18
17
  variant?: "primary" | "secondary";
19
- };
18
+ }
20
19
 
21
- export const IconButton: React.FC<IconButtonProps> = React.forwardRef(
20
+ export interface IconButtonTypeMap<
21
+ P = {},
22
+ D extends React.ElementType = "button"
23
+ > {
24
+ props: Omit<MuiIconButtonTypeMap<P, D>["props"], "variant"> &
25
+ IconButtonInnerProps & { href?: string } & OverrideProps<
26
+ MuiIconButtonTypeMap<P, D>,
27
+ "a"
28
+ >;
29
+ defaultComponent: D;
30
+ classKey: never;
31
+ }
32
+
33
+ export type IconButtonProps<T extends React.ElementType = "button"> =
34
+ MuiIconButtonProps<T, { component?: T }> &
35
+ IconButtonInnerProps & { href?: string };
36
+
37
+ const _IconButton: React.FC<IconButtonProps> = React.forwardRef(
22
38
  (
23
39
  {
24
40
  className,
@@ -64,4 +80,10 @@ export const IconButton: React.FC<IconButtonProps> = React.forwardRef(
64
80
  );
65
81
  }
66
82
  );
67
- IconButton.displayName = "Button";
83
+ _IconButton.displayName = "Button";
84
+
85
+ export const IconButton = _IconButton as <
86
+ T extends React.ElementType = "button"
87
+ >(
88
+ props: IconButtonProps<T> & { ref?: React.ForwardedRef<T> }
89
+ ) => ReturnType<typeof _IconButton>;
@@ -6,28 +6,44 @@ import React from "react";
6
6
  import { UserInteraction } from "../../types/utils";
7
7
  import useStyles from "./styles";
8
8
 
9
- export type LayoutButtonProps<T extends React.ElementType = "button"> =
10
- ButtonBaseProps<T> & {
11
- state?: UserInteraction;
12
- };
9
+ export type LayoutButtonProps<T extends React.ElementType> = ButtonBaseProps<
10
+ T,
11
+ { component?: T }
12
+ > & {
13
+ state?: UserInteraction;
14
+ };
13
15
 
14
- export const LayoutButton: React.FC<LayoutButtonProps> = React.forwardRef(
15
- ({ className, children, state = "default", ...rest }, ref) => {
16
- const classes = useStyles();
16
+ export const LayoutButtonInner = <T extends React.ElementType = "button">(
17
+ {
18
+ className,
19
+ children,
20
+ state = "default",
21
+ component,
22
+ ...rest
23
+ }: LayoutButtonProps<T>,
24
+ ref: React.ForwardedRef<HTMLButtonElement>
25
+ ) => {
26
+ const classes = useStyles();
17
27
 
18
- return (
19
- <ButtonBase
20
- className={clsx(classes.root, className, {
21
- [classes.hover]: state === "hover",
22
- [classes.active]: state === "active",
23
- })}
24
- disableRipple
25
- ref={ref}
26
- {...rest}
27
- >
28
- {children}
29
- </ButtonBase>
30
- );
31
- }
32
- );
33
- LayoutButton.displayName = "LayoutButton";
28
+ return (
29
+ <ButtonBase
30
+ className={clsx(classes.root, className, {
31
+ [classes.hover]: state === "hover",
32
+ [classes.active]: state === "active",
33
+ })}
34
+ component={component}
35
+ disableRipple
36
+ ref={ref}
37
+ {...rest}
38
+ >
39
+ {children}
40
+ </ButtonBase>
41
+ );
42
+ };
43
+ LayoutButtonInner.displayName = "LayoutButton";
44
+
45
+ export const LayoutButton = React.forwardRef(LayoutButtonInner) as <
46
+ T extends React.ElementType
47
+ >(
48
+ props: LayoutButtonProps<T> & { ref?: React.ForwardedRef<unknown> }
49
+ ) => ReturnType<typeof LayoutButtonInner>;
@@ -0,0 +1,76 @@
1
+ import { MenuItem } from "@material-ui/core";
2
+ import { Meta, Story } from "@storybook/react";
3
+ import React from "react";
4
+
5
+ import { Decorator, GuideDecorator } from "../utils/Decorator";
6
+ import { useMockAutocomplete } from "../utils/useMockAutocomplete";
7
+ import { choices } from "./fixtures";
8
+ import { MultipleValueAutocomplete } from "./MultipleValueAutocomplete";
9
+
10
+ export const Default: Story = () => {
11
+ const { results, search } = useMockAutocomplete(choices);
12
+
13
+ return (
14
+ <MultipleValueAutocomplete
15
+ fullWidth
16
+ choices={results}
17
+ label="Employees of the month"
18
+ onInputChange={search}
19
+ onChange={console.log}
20
+ >
21
+ {({ choices, getItemProps }) =>
22
+ choices.map((choice, choiceIndex) => (
23
+ <MenuItem {...getItemProps({ item: choice, index: choiceIndex })}>
24
+ {choice.label}
25
+ </MenuItem>
26
+ ))
27
+ }
28
+ </MultipleValueAutocomplete>
29
+ );
30
+ };
31
+
32
+ export const Loading: Story = () => (
33
+ <MultipleValueAutocomplete
34
+ fullWidth
35
+ choices={[]}
36
+ label="Employees of the month"
37
+ loading
38
+ >
39
+ {({ choices, getItemProps }) =>
40
+ choices.map((choice, choiceIndex) => (
41
+ <MenuItem {...getItemProps({ item: choice, index: choiceIndex })}>
42
+ {choice.label}
43
+ </MenuItem>
44
+ ))
45
+ }
46
+ </MultipleValueAutocomplete>
47
+ );
48
+
49
+ export const WithInitialState: Story = () => {
50
+ const { results, search, more } = useMockAutocomplete(choices);
51
+
52
+ return (
53
+ <MultipleValueAutocomplete
54
+ fullWidth
55
+ choices={results}
56
+ label="Employees of the month"
57
+ onInputChange={search}
58
+ initialValue={[results[1], results[4]]}
59
+ onScrollToBottom={more}
60
+ onChange={console.log}
61
+ >
62
+ {({ choices, getItemProps }) =>
63
+ choices.map((choice, choiceIndex) => (
64
+ <MenuItem {...getItemProps({ item: choice, index: choiceIndex })}>
65
+ {choice.label}
66
+ </MenuItem>
67
+ ))
68
+ }
69
+ </MultipleValueAutocomplete>
70
+ );
71
+ };
72
+
73
+ export default {
74
+ decorators: [Decorator, GuideDecorator],
75
+ title: "Autocomplete / Multiple choices",
76
+ } as Meta;
@@ -0,0 +1,185 @@
1
+ import CircularProgress from "@material-ui/core/CircularProgress";
2
+ import Grow from "@material-ui/core/Grow";
3
+ import Paper from "@material-ui/core/Paper";
4
+ import Popper, { PopperPlacementType } from "@material-ui/core/Popper";
5
+ import TextField, { StandardTextFieldProps } from "@material-ui/core/TextField";
6
+ import clsx from "clsx";
7
+ import { UseComboboxGetItemPropsOptions } from "downshift";
8
+ import React from "react";
9
+
10
+ import { SyntheticChangeEvent } from "../../types/utils";
11
+ import { ChipRemovable } from "../Chip";
12
+ import { Choice } from "../Filter";
13
+ import { IconButton } from "../IconButton";
14
+ import { PlusIcon } from "../icons";
15
+ import {
16
+ isScrolledToBottom,
17
+ useElementScroll,
18
+ } from "../tools/useElementScroll";
19
+ import { mergeRefs } from "../utils/mergeRefs";
20
+ import useStyles from "./styles";
21
+ import useMultipleValueAutocomplete from "./useMultipleValueAutocomplete";
22
+
23
+ export interface MultipleValueAutocompleteProps
24
+ extends Omit<StandardTextFieldProps, "onChange"> {
25
+ children: (data: {
26
+ getItemProps: (opts: UseComboboxGetItemPropsOptions<Choice>) => any;
27
+ highlightedIndex: number;
28
+ inputValue: string;
29
+ choices: Choice[];
30
+ }) => React.ReactNode | React.ReactNodeArray;
31
+ className?: string;
32
+ enableReinitialize?: boolean;
33
+ styles?: React.CSSProperties;
34
+ choices: Choice[];
35
+ label?: string;
36
+ loading?: boolean;
37
+ popperPlacement?: PopperPlacementType;
38
+ initialValue?: Choice[];
39
+ onChange?: (event: SyntheticChangeEvent<string[]>) => void;
40
+ onInputChange?: (value: string) => void;
41
+ onScrollToBottom?: () => void;
42
+ }
43
+
44
+ export const MultipleValueAutocomplete: React.FC<MultipleValueAutocompleteProps> =
45
+ ({
46
+ choices,
47
+ children,
48
+ enableReinitialize,
49
+ name,
50
+ InputProps,
51
+ initialValue = [],
52
+ loading,
53
+ popperPlacement = "bottom-start",
54
+ onChange,
55
+ onInputChange,
56
+ onScrollToBottom,
57
+ ...rest
58
+ }) => {
59
+ const classes = useStyles();
60
+ const {
61
+ anchor,
62
+ comboboxProps,
63
+ filteredChoices,
64
+ getItemProps,
65
+ getSelectedItemProps,
66
+ getToggleButtonProps,
67
+ highlightedIndex,
68
+ inputProps,
69
+ inputRef,
70
+ inputValue,
71
+ inputWidth,
72
+ isOpen,
73
+ labelProps,
74
+ menuProps,
75
+ ref,
76
+ removeSelectedItem,
77
+ selectedItems,
78
+ } = useMultipleValueAutocomplete({
79
+ choices,
80
+ enableReinitialize,
81
+ initialValue,
82
+ name,
83
+ onChange,
84
+ onInputChange,
85
+ });
86
+ const { anchor: dropdownRef, position, setAnchor } = useElementScroll();
87
+
88
+ React.useEffect(() => {
89
+ if (
90
+ isOpen &&
91
+ onScrollToBottom &&
92
+ dropdownRef &&
93
+ isScrolledToBottom(dropdownRef, position!, 5)
94
+ ) {
95
+ onScrollToBottom();
96
+ }
97
+ }, [position?.y, dropdownRef]);
98
+
99
+ return (
100
+ <>
101
+ <TextField
102
+ {...rest}
103
+ {...comboboxProps}
104
+ name={name}
105
+ InputLabelProps={{
106
+ shrink: isOpen || selectedItems.length || inputValue.length,
107
+ ...labelProps,
108
+ }}
109
+ ref={ref}
110
+ InputProps={{
111
+ ...InputProps,
112
+ ...inputProps,
113
+ classes: {
114
+ ...(InputProps?.classes ?? {}),
115
+ root: clsx(classes.inputContainer, InputProps?.classes?.root, {
116
+ [classes.inputContainerWithChips]: selectedItems.length > 0,
117
+ }),
118
+ input: clsx(classes.input, InputProps?.classes?.input),
119
+ },
120
+ startAdornment: selectedItems.map((item, index) => (
121
+ <ChipRemovable
122
+ key={`selected-item-${index}`}
123
+ {...getSelectedItemProps({ selectedItem: item, index })}
124
+ onRemove={() => removeSelectedItem(item)}
125
+ >
126
+ {item.label}
127
+ </ChipRemovable>
128
+ )),
129
+ endAdornment: (
130
+ <>
131
+ {loading && (
132
+ <div className={classes.loader}>
133
+ <CircularProgress size={24} />
134
+ </div>
135
+ )}
136
+ <IconButton
137
+ {...getToggleButtonProps()}
138
+ aria-label="toggle menu"
139
+ className={classes.icon}
140
+ hoverOutline={false}
141
+ type="button"
142
+ variant="secondary"
143
+ >
144
+ <PlusIcon />
145
+ </IconButton>
146
+ </>
147
+ ),
148
+ }}
149
+ inputProps={{ ref: inputRef, style: { width: inputWidth } }}
150
+ />
151
+ <Popper
152
+ className={clsx(classes.popper, menuProps.className)}
153
+ open={isOpen}
154
+ anchorEl={anchor.current}
155
+ transition
156
+ placement={popperPlacement}
157
+ >
158
+ {({ TransitionProps, placement }) => (
159
+ <Grow
160
+ {...TransitionProps}
161
+ style={{
162
+ transformOrigin:
163
+ placement === "bottom" ? "left top" : "left bottom",
164
+ }}
165
+ >
166
+ <Paper
167
+ className={classes.dropdown}
168
+ elevation={8}
169
+ style={{ width: anchor.current?.clientWidth }}
170
+ {...menuProps}
171
+ ref={mergeRefs(setAnchor, menuProps.ref)}
172
+ >
173
+ {children({
174
+ choices: filteredChoices,
175
+ highlightedIndex,
176
+ getItemProps,
177
+ inputValue,
178
+ })}
179
+ </Paper>
180
+ </Grow>
181
+ )}
182
+ </Popper>
183
+ </>
184
+ );
185
+ };
@@ -0,0 +1,122 @@
1
+ export const choices = [
2
+ {
3
+ label: "Hazel, Direct Integration Producer",
4
+ value: "hazel, direct integration producer",
5
+ },
6
+ {
7
+ label: "Audra, District Functionality Facilitator",
8
+ value: "audra, district functionality facilitator",
9
+ },
10
+ {
11
+ label: "Emilie, Product Integration Assistant",
12
+ value: "emilie, product integration assistant",
13
+ },
14
+ {
15
+ label: "Kyla, Central Interactions Director",
16
+ value: "kyla, central interactions director",
17
+ },
18
+ {
19
+ label: "Vida, Senior Usability Producer",
20
+ value: "vida, senior usability producer",
21
+ },
22
+ {
23
+ label: "Lonie, Chief Infrastructure Director",
24
+ value: "lonie, chief infrastructure director",
25
+ },
26
+ {
27
+ label: "Zola, Lead Operations Producer",
28
+ value: "zola, lead operations producer",
29
+ },
30
+ {
31
+ label: "Angel, District Operations Orchestrator",
32
+ value: "angel, district operations orchestrator",
33
+ },
34
+ {
35
+ label: "Glenda, Lead Accountability Technician",
36
+ value: "glenda, lead accountability technician",
37
+ },
38
+ {
39
+ label: "Kayley, National Web Facilitator",
40
+ value: "kayley, national web facilitator",
41
+ },
42
+ {
43
+ label: "Kali, National Configuration Planner",
44
+ value: "kali, national configuration planner",
45
+ },
46
+ {
47
+ label: "Lilian, Internal Branding Planner",
48
+ value: "lilian, internal branding planner",
49
+ },
50
+ {
51
+ label: "Lamar, Dynamic Integration Executive",
52
+ value: "lamar, dynamic integration executive",
53
+ },
54
+ {
55
+ label: "Leonel, Central Brand Strategist",
56
+ value: "leonel, central brand strategist",
57
+ },
58
+ {
59
+ label: "Broderick, Chief Division Liaison",
60
+ value: "broderick, chief division liaison",
61
+ },
62
+ {
63
+ label: "Kavon, Future Marketing Representative",
64
+ value: "kavon, future marketing representative",
65
+ },
66
+ {
67
+ label: "Sydnee, Corporate Marketing Liaison",
68
+ value: "sydnee, corporate marketing liaison",
69
+ },
70
+ {
71
+ label: "Jett, Future Data Specialist",
72
+ value: "jett, future data specialist",
73
+ },
74
+ {
75
+ label: "Theresia, International Tactics Assistant",
76
+ value: "theresia, international tactics assistant",
77
+ },
78
+ {
79
+ label: "Cesar, Direct Mobility Director",
80
+ value: "cesar, direct mobility director",
81
+ },
82
+ {
83
+ label: "Madonna, Investor Assurance Executive",
84
+ value: "madonna, investor assurance executive",
85
+ },
86
+ {
87
+ label: "Ima, Internal Research Facilitator",
88
+ value: "ima, internal research facilitator",
89
+ },
90
+ {
91
+ label: "Joanne, Investor Identity Coordinator",
92
+ value: "joanne, investor identity coordinator",
93
+ },
94
+ {
95
+ label: "Gavin, Future Web Assistant",
96
+ value: "gavin, future web assistant",
97
+ },
98
+ {
99
+ label: "Maverick, Internal Optimization Assistant",
100
+ value: "maverick, internal optimization assistant",
101
+ },
102
+ {
103
+ label: "Hudson, Regional Branding Representative",
104
+ value: "hudson, regional branding representative",
105
+ },
106
+ {
107
+ label: "Brooklyn, Human Paradigm Producer",
108
+ value: "brooklyn, human paradigm producer",
109
+ },
110
+ {
111
+ label: "Gussie, Future Configuration Supervisor",
112
+ value: "gussie, future configuration supervisor",
113
+ },
114
+ {
115
+ label: "Michel, Corporate Tactics Orchestrator",
116
+ value: "michel, corporate tactics orchestrator",
117
+ },
118
+ {
119
+ label: "Maxime, Customer Mobility Analyst",
120
+ value: "maxime, customer mobility analyst",
121
+ },
122
+ ];
@@ -0,0 +1 @@
1
+ export * from "./MultipleValueAutocomplete";
@@ -0,0 +1,41 @@
1
+ import { zIndex } from "../consts";
2
+ import { makeStyles } from "../theme";
3
+
4
+ const useStyles = makeStyles(
5
+ (theme) => ({
6
+ dropdown: {
7
+ maxHeight: 220,
8
+ overflow: "scroll",
9
+ },
10
+ icon: {
11
+ position: "absolute",
12
+ bottom: 4,
13
+ right: 4,
14
+ },
15
+ inputContainer: {
16
+ padding: "23px 80px 10px 12px",
17
+ flexWrap: "wrap",
18
+ gap: theme.spacing(1),
19
+ },
20
+ inputContainerWithChips: {
21
+ paddingTop: 27,
22
+ },
23
+ input: {
24
+ height: "1.1875em",
25
+ minWidth: "3rem",
26
+ padding: 0,
27
+ },
28
+ loader: {
29
+ position: "absolute",
30
+ bottom: theme.spacing(1),
31
+ right: theme.spacing(6),
32
+ },
33
+ popper: {
34
+ marginTop: theme.spacing(1),
35
+ zIndex: zIndex.popper,
36
+ },
37
+ }),
38
+ { name: "MultipleValueAutocomplete" }
39
+ );
40
+
41
+ export default useStyles;