@adobe-commerce/elsie 2.0.0 → 2.0.1-alpha-20260728135101

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 (249) hide show
  1. package/.elsie.js +3 -3
  2. package/CHANGELOG.md +385 -112
  3. package/LICENSE.md +257 -157
  4. package/README.md +4 -2
  5. package/__mocks__/svg.js +3 -3
  6. package/bin/builders/build/index.js +2 -1
  7. package/bin/builders/changeset/index.js +1 -1
  8. package/bin/builders/concurrently/index.js +1 -1
  9. package/bin/builders/generate/api/index.js +7 -7
  10. package/bin/builders/generate/component/index.js +8 -8
  11. package/bin/builders/generate/config/index.js +5 -5
  12. package/bin/builders/generate/config/templates/elsie.js +1 -1
  13. package/bin/builders/generate/container/index.js +7 -7
  14. package/bin/builders/generate/index.js +36 -36
  15. package/bin/builders/gql/index.js +28 -28
  16. package/bin/builders/gql/validate.js +116 -105
  17. package/bin/builders/lint/index.js +1 -1
  18. package/bin/builders/serve/index.js +1 -1
  19. package/bin/builders/storybook/index.js +9 -1
  20. package/bin/builders/types/index.js +1 -2
  21. package/bin/builders/types/validate-tsconfig.js +5 -5
  22. package/bin/index.js +12 -6
  23. package/bin/lib/cli.js +9 -8
  24. package/bin/lib/resolve-bin.js +9 -0
  25. package/bin/lib/validate-typeof.js +3 -3
  26. package/bin/lib/write-file.js +3 -3
  27. package/bin/lib/write-parent-index.js +4 -4
  28. package/config/eslint.mjs +2 -1
  29. package/config/jest.mjs +7 -2
  30. package/config/plugins/dts-normalize-relative-replacer.cjs +1 -1
  31. package/config/plugins/dts.mjs +4 -3
  32. package/config/prettier.json +25 -3
  33. package/config/setEnvVars.mjs +2 -2
  34. package/config/storybook/addon.js +5 -5
  35. package/config/storybook/components/FileTree/FileTree.jsx +4 -4
  36. package/config/storybook/components/FileTree/index.js +4 -4
  37. package/config/storybook/components/Flex/Flex.jsx +3 -3
  38. package/config/storybook/components/Flex/index.js +3 -3
  39. package/config/storybook/components/OptionsTable/OptionsTable.jsx +3 -3
  40. package/config/storybook/components/OptionsTable/index.js +4 -4
  41. package/config/storybook/components/Panel/Panel.tsx +7 -7
  42. package/config/storybook/components/Panel/index.ts +3 -3
  43. package/config/storybook/components/Screenshot/Screenshot.jsx +3 -3
  44. package/config/storybook/components/Screenshot/index.js +4 -4
  45. package/config/storybook/components/Steps/Steps.jsx +3 -3
  46. package/config/storybook/components/Steps/index.js +4 -4
  47. package/config/storybook/components/StoryWrapper/StoryWrapper.jsx +3 -3
  48. package/config/storybook/components/StoryWrapper/index.js +3 -3
  49. package/config/storybook/components/Summary/Summary.jsx +3 -3
  50. package/config/storybook/components/Summary/index.js +3 -3
  51. package/config/storybook/components/Variants/Variants.jsx +11 -7
  52. package/config/storybook/components/Variants/index.js +3 -3
  53. package/config/storybook/manager.js +3 -3
  54. package/config/storybook/preview.jsx +3 -3
  55. package/config/storybook/theming/fonts.css +12 -4
  56. package/config/storybook/theming/preview.css +3 -1
  57. package/config/storybook/theming/theme.js +3 -3
  58. package/config/vite.mjs +53 -26
  59. package/package.json +36 -34
  60. package/src/components/Accordion/Accordion.css +1 -1
  61. package/src/components/Accordion/Accordion.stories.tsx +18 -18
  62. package/src/components/Accordion/Accordion.tsx +12 -8
  63. package/src/components/Accordion/index.ts +3 -3
  64. package/src/components/ActionButton/ActionButton.stories.tsx +8 -8
  65. package/src/components/ActionButton/ActionButton.tsx +7 -5
  66. package/src/components/ActionButton/index.ts +3 -3
  67. package/src/components/ActionButtonGroup/ActionButtonGroup.stories.tsx +3 -3
  68. package/src/components/ActionButtonGroup/ActionButtonGroup.tsx +2 -2
  69. package/src/components/ActionButtonGroup/index.ts +3 -3
  70. package/src/components/AlertBanner/AlertBanner.stories.tsx +6 -6
  71. package/src/components/AlertBanner/AlertBanner.tsx +12 -10
  72. package/src/components/AlertBanner/index.ts +3 -3
  73. package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +14 -14
  74. package/src/components/Breadcrumbs/Breadcrumbs.tsx +3 -3
  75. package/src/components/Breadcrumbs/index.ts +3 -3
  76. package/src/components/Button/Button.mdx +24 -11
  77. package/src/components/Button/Button.stories.tsx +6 -6
  78. package/src/components/Button/Button.tsx +7 -8
  79. package/src/components/Button/index.ts +3 -3
  80. package/src/components/Card/Card.stories.tsx +6 -6
  81. package/src/components/Card/Card.tsx +3 -3
  82. package/src/components/Card/index.ts +3 -3
  83. package/src/components/CartItem/CartItem.stories.tsx +12 -12
  84. package/src/components/CartItem/CartItem.tsx +4 -2
  85. package/src/components/CartItem/CartItemSkeleton.tsx +3 -3
  86. package/src/components/CartItem/index.ts +3 -3
  87. package/src/components/CartList/CartList.tsx +3 -3
  88. package/src/components/CartList/index.ts +3 -3
  89. package/src/components/Checkbox/Checkbox.stories.tsx +17 -14
  90. package/src/components/Checkbox/Checkbox.tsx +8 -6
  91. package/src/components/Checkbox/index.ts +3 -3
  92. package/src/components/ColorSwatch/ColorSwatch.css +8 -4
  93. package/src/components/ColorSwatch/ColorSwatch.stories.tsx +6 -6
  94. package/src/components/ColorSwatch/ColorSwatch.tsx +8 -6
  95. package/src/components/ColorSwatch/index.ts +3 -3
  96. package/src/components/ContentGrid/ContentGrid.css +15 -15
  97. package/src/components/ContentGrid/ContentGrid.stories.tsx +4 -4
  98. package/src/components/ContentGrid/ContentGrid.tsx +3 -3
  99. package/src/components/ContentGrid/index.ts +3 -3
  100. package/src/components/Divider/Divider.stories.tsx +7 -4
  101. package/src/components/Divider/Divider.tsx +3 -3
  102. package/src/components/Divider/index.ts +4 -4
  103. package/src/components/Field/Field.stories.tsx +7 -7
  104. package/src/components/Field/Field.tsx +4 -2
  105. package/src/components/Field/index.ts +3 -3
  106. package/src/components/Header/Header.stories.tsx +9 -10
  107. package/src/components/Header/Header.tsx +11 -7
  108. package/src/components/Header/index.ts +3 -3
  109. package/src/components/Icon/Icon.stories.helpers.jsx +4 -4
  110. package/src/components/Icon/Icon.stories.tsx +74 -60
  111. package/src/components/Icon/Icon.tsx +77 -44
  112. package/src/components/Icon/index.ts +3 -3
  113. package/src/components/IllustratedMessage/IllustratedMessage.stories.tsx +8 -8
  114. package/src/components/IllustratedMessage/IllustratedMessage.tsx +7 -5
  115. package/src/components/IllustratedMessage/index.ts +3 -3
  116. package/src/components/Image/Image.stories.tsx +3 -3
  117. package/src/components/Image/Image.tsx +4 -4
  118. package/src/components/Image/index.ts +3 -3
  119. package/src/components/ImageSwatch/ImageSwatch.css +8 -4
  120. package/src/components/ImageSwatch/ImageSwatch.stories.tsx +10 -10
  121. package/src/components/ImageSwatch/ImageSwatch.tsx +25 -23
  122. package/src/components/ImageSwatch/index.ts +3 -3
  123. package/src/components/InLineAlert/InLineAlert.stories.tsx +12 -7
  124. package/src/components/InLineAlert/InLineAlert.tsx +4 -2
  125. package/src/components/InLineAlert/index.ts +3 -3
  126. package/src/components/Incrementer/Incrementer.stories.tsx +9 -9
  127. package/src/components/Incrementer/Incrementer.tsx +75 -37
  128. package/src/components/Incrementer/index.ts +3 -3
  129. package/src/components/Input/Input.css +4 -1
  130. package/src/components/Input/Input.stories.tsx +5 -5
  131. package/src/components/Input/Input.tsx +5 -3
  132. package/src/components/Input/index.ts +3 -3
  133. package/src/components/InputDate/InputDate.tsx +3 -3
  134. package/src/components/InputDate/index.ts +3 -3
  135. package/src/components/InputFile/InputFile.css +16 -16
  136. package/src/components/InputFile/InputFile.stories.tsx +21 -16
  137. package/src/components/InputFile/InputFile.tsx +8 -6
  138. package/src/components/InputFile/index.ts +5 -5
  139. package/src/components/InputPassword/InputPassword.stories.tsx +4 -4
  140. package/src/components/InputPassword/InputPassword.tsx +5 -4
  141. package/src/components/InputPassword/PasswordStatusIndicator/PasswordStatusIndicator.tsx +1 -1
  142. package/src/components/InputPassword/PasswordStatusIndicator/index.ts +3 -3
  143. package/src/components/InputPassword/index.ts +3 -3
  144. package/src/components/Modal/Modal.stories.tsx +27 -16
  145. package/src/components/Modal/Modal.tsx +10 -11
  146. package/src/components/Modal/index.ts +3 -3
  147. package/src/components/MultiSelect/MultiSelect.stories.tsx +15 -15
  148. package/src/components/MultiSelect/MultiSelect.tsx +15 -15
  149. package/src/components/Pagination/Pagination.css +1 -1
  150. package/src/components/Pagination/Pagination.stories.tsx +0 -1
  151. package/src/components/Pagination/Pagination.tsx +17 -12
  152. package/src/components/Pagination/PaginationButton.tsx +2 -3
  153. package/src/components/Pagination/index.ts +3 -3
  154. package/src/components/Picker/Picker.css +3 -1
  155. package/src/components/Picker/Picker.stories.tsx +1 -1
  156. package/src/components/Picker/Picker.tsx +8 -6
  157. package/src/components/Picker/index.ts +3 -3
  158. package/src/components/Portal/Portal.stories.tsx +50 -44
  159. package/src/components/Portal/Portal.tsx +4 -4
  160. package/src/components/Price/Price.stories.tsx +3 -3
  161. package/src/components/Price/Price.tsx +4 -2
  162. package/src/components/Price/index.ts +3 -3
  163. package/src/components/PriceRange/PriceRange.stories.tsx +3 -3
  164. package/src/components/PriceRange/PriceRange.tsx +8 -6
  165. package/src/components/PriceRange/index.ts +3 -3
  166. package/src/components/ProductItemCard/ProductItemCard.tsx +4 -2
  167. package/src/components/ProductItemCard/ProductItemCardSkeleton.tsx +16 -16
  168. package/src/components/ProductItemCard/index.ts +4 -4
  169. package/src/components/ProgressSpinner/ProgressSpinner.stories.tsx +8 -8
  170. package/src/components/ProgressSpinner/ProgressSpinner.tsx +7 -5
  171. package/src/components/ProgressSpinner/index.ts +3 -3
  172. package/src/components/RadioButton/RadioButton.stories.tsx +1 -1
  173. package/src/components/RadioButton/RadioButton.tsx +4 -2
  174. package/src/components/Skeleton/Skeleton.stories.tsx +4 -4
  175. package/src/components/Skeleton/Skeleton.tsx +11 -7
  176. package/src/components/Skeleton/index.ts +3 -3
  177. package/src/components/Table/Table.css +106 -99
  178. package/src/components/Table/Table.stories.tsx +404 -227
  179. package/src/components/Table/Table.tsx +11 -7
  180. package/src/components/Table/index.ts +4 -4
  181. package/src/components/Tag/Tag.stories.tsx +6 -6
  182. package/src/components/Tag/Tag.tsx +7 -5
  183. package/src/components/Tag/index.ts +3 -3
  184. package/src/components/TextArea/TextArea.css +3 -1
  185. package/src/components/TextArea/TextArea.stories.tsx +9 -6
  186. package/src/components/TextArea/TextArea.tsx +3 -3
  187. package/src/components/TextArea/index.ts +3 -3
  188. package/src/components/TextSwatch/TextSwatch.css +4 -2
  189. package/src/components/TextSwatch/TextSwatch.stories.tsx +8 -8
  190. package/src/components/TextSwatch/TextSwatch.tsx +12 -7
  191. package/src/components/TextSwatch/index.ts +3 -3
  192. package/src/components/ToggleButton/ToggleButton.css +6 -2
  193. package/src/components/ToggleButton/ToggleButton.stories.tsx +10 -6
  194. package/src/components/ToggleButton/ToggleButton.tsx +8 -3
  195. package/src/components/ToggleButton/index.ts +3 -3
  196. package/src/components/UIProvider/UIProvider.css +3 -2
  197. package/src/components/UIProvider/UIProvider.tsx +11 -7
  198. package/src/components/UIProvider/debugger.css +5 -6
  199. package/src/components/UIProvider/index.ts +3 -3
  200. package/src/docs/API/event-bus.mdx +64 -37
  201. package/src/docs/API/graphql.mdx +69 -36
  202. package/src/docs/API/initializer.mdx +58 -35
  203. package/src/docs/API/render.mdx +45 -32
  204. package/src/docs/Design/colors.mdx +10 -12
  205. package/src/docs/Design/grid.mdx +41 -14
  206. package/src/docs/Design/overview.mdx +20 -4
  207. package/src/docs/Design/shapes.mdx +8 -7
  208. package/src/docs/Design/spacing.mdx +3 -1
  209. package/src/docs/Design/typography.mdx +3 -2
  210. package/src/docs/Utilities/VComponent.mdx +27 -10
  211. package/src/docs/Utilities/classList.mdx +7 -5
  212. package/src/docs/Utilities/debounce.mdx +6 -7
  213. package/src/docs/Utilities/getCookie.mdx +1 -2
  214. package/src/docs/Utilities/getFormErrors.mdx +1 -2
  215. package/src/docs/Utilities/getFormValues.mdx +1 -2
  216. package/src/docs/Utilities/getPathValue.mdx +2 -4
  217. package/src/docs/Utilities/links.mdx +16 -7
  218. package/src/docs/cli-usage.mdx +8 -3
  219. package/src/docs/components/overview.mdx +14 -4
  220. package/src/docs/quick-start.mdx +69 -22
  221. package/src/docs/slots.mdx +74 -37
  222. package/src/docs/welcome.mdx +13 -4
  223. package/src/i18n/index.ts +3 -3
  224. package/src/lib/aem/assets.ts +9 -9
  225. package/src/lib/aem/configs.ts +16 -8
  226. package/src/lib/classes.ts +4 -4
  227. package/src/lib/config.ts +3 -3
  228. package/src/lib/debounce.ts +3 -3
  229. package/src/lib/deepmerge.ts +6 -13
  230. package/src/lib/deviceUtils.ts +3 -3
  231. package/src/lib/form-values.ts +3 -3
  232. package/src/lib/get-price-formatter.ts +8 -3
  233. package/src/lib/i18n.ts +3 -3
  234. package/src/lib/image-params-keymap.ts +4 -5
  235. package/src/lib/initializer.ts +11 -12
  236. package/src/lib/is-number.ts +3 -3
  237. package/src/lib/locale-config.ts +4 -4
  238. package/src/lib/render.tsx +14 -8
  239. package/src/lib/resolve-image.ts +19 -16
  240. package/src/lib/signals.ts +4 -4
  241. package/src/lib/slot.tsx +34 -27
  242. package/src/lib/tests.tsx +6 -8
  243. package/src/lib/types.ts +3 -3
  244. package/src/lib/vcomponent.tsx +3 -3
  245. package/src/shims/importmap.js +3107 -20
  246. package/static/assets/images/index.ts +3 -3
  247. package/storybook-stories.js +3 -3
  248. package/tests/__mocks__/browserMocks.ts +3 -3
  249. package/tests/__mocks__/fileMocks.ts +3 -3
@@ -147,7 +147,7 @@ export const DefaultImageSwatch: Story = {
147
147
  const canvas = within(canvasElement);
148
148
  const imageSwatch = await canvas.findByRole('radio');
149
149
  const spanElement = document.querySelector(
150
- '.dropin-image-swatch__span'
150
+ '.dropin-image-swatch__span',
151
151
  ) as HTMLElement;
152
152
  expect(spanElement).toBeVisible();
153
153
  await expect(imageSwatch).not.toBeChecked();
@@ -172,14 +172,14 @@ export const ImageSwatchSelected: Story = {
172
172
  const canvas = within(canvasElement);
173
173
  const imageSwatch = await canvas.findByRole('radio');
174
174
  const spanElement = document.querySelector(
175
- '.dropin-image-swatch__span'
175
+ '.dropin-image-swatch__span',
176
176
  ) as HTMLElement;
177
177
  expect(spanElement).toBeVisible();
178
178
  await expect(imageSwatch).toBeChecked();
179
179
  await expect(
180
180
  canvas.getByLabelText(
181
- 'Image Swatches: imageSwatch1Example swatch selected'
182
- )
181
+ 'Image Swatches: imageSwatch1Example swatch selected',
182
+ ),
183
183
  ).toBeChecked();
184
184
  },
185
185
  };
@@ -292,13 +292,13 @@ export const CustomImageNodeVNodeSwatch: Story = {
292
292
  const canvas = within(canvasElement);
293
293
  const imageSwatch = await canvas.findByRole('radio');
294
294
  const customImageContainer = canvasElement.querySelector(
295
- 'div[style*="position: relative"]'
295
+ 'div[style*="position: relative"]',
296
296
  );
297
297
  const customImage = canvasElement.querySelector(
298
- 'img[alt="Custom grayscale image - VNode"]'
298
+ 'img[alt="Custom grayscale image - VNode"]',
299
299
  );
300
300
  const customLabel = canvasElement.querySelector(
301
- 'span[style*="font-weight: bold"]'
301
+ 'span[style*="font-weight: bold"]',
302
302
  );
303
303
 
304
304
  expect(imageSwatch).toBeInTheDocument();
@@ -341,13 +341,13 @@ export const CustomImageNodeRenderFunctionSwatch: Story = {
341
341
  const canvas = within(canvasElement);
342
342
  const imageSwatch = await canvas.findByRole('radio');
343
343
  const customImageContainer = canvasElement.querySelector(
344
- 'div[style*="position: relative"]'
344
+ 'div[style*="position: relative"]',
345
345
  );
346
346
  const customImage = canvasElement.querySelector(
347
- 'img[alt="Custom grayscale image - Render Function"]'
347
+ 'img[alt="Custom grayscale image - Render Function"]',
348
348
  );
349
349
  const customLabel = canvasElement.querySelector(
350
- 'span[style*="font-weight: bold"]'
350
+ 'span[style*="font-weight: bold"]',
351
351
  );
352
352
 
353
353
  expect(imageSwatch).toBeInTheDocument();
@@ -28,8 +28,10 @@ export interface ImageNodeRenderProps extends ImageProps {
28
28
  };
29
29
  }
30
30
 
31
- export interface ImageSwatchProps
32
- extends Omit<HTMLAttributes<HTMLInputElement>, 'label'> {
31
+ export interface ImageSwatchProps extends Omit<
32
+ HTMLAttributes<HTMLInputElement>,
33
+ 'label'
34
+ > {
33
35
  name?: string;
34
36
  label?: string;
35
37
  groupAriaLabel?: string;
@@ -80,7 +82,7 @@ export const ImageSwatch: FunctionComponent<ImageSwatchProps> = ({
80
82
  }
81
83
  }
82
84
  },
83
- [onValue, onUpdateError]
85
+ [onValue, onUpdateError],
84
86
  );
85
87
 
86
88
  const handleOnValue = (e: Event) => {
@@ -132,26 +134,26 @@ export const ImageSwatch: FunctionComponent<ImageSwatchProps> = ({
132
134
  className,
133
135
  ])}
134
136
  >
135
- {typeof imageNode === 'function' ? (
136
- imageNode({
137
- ...imageProps,
138
- imageSwatchContext: {
139
- disabled,
140
- outOfStock,
141
- selected,
142
- value,
143
- label,
144
- groupAriaLabel,
145
- name,
146
- id,
147
- },
148
- })
149
- ) : imageNode || (
150
- <Image
151
- {...imageProps}
152
- className={classes(['dropin-image-swatch__content'])}
153
- />
154
- )}
137
+ {typeof imageNode === 'function'
138
+ ? imageNode({
139
+ ...imageProps,
140
+ imageSwatchContext: {
141
+ disabled,
142
+ outOfStock,
143
+ selected,
144
+ value,
145
+ label,
146
+ groupAriaLabel,
147
+ name,
148
+ id,
149
+ },
150
+ })
151
+ : imageNode || (
152
+ <Image
153
+ {...imageProps}
154
+ className={classes(['dropin-image-swatch__content'])}
155
+ />
156
+ )}
155
157
  </span>
156
158
  </label>
157
159
  );
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  export * from '@adobe-commerce/elsie/components/ImageSwatch/ImageSwatch';
@@ -2,17 +2,22 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  // https://storybook.js.org/docs/7.0/preact/writing-stories/introduction
11
- import { CartItem, CartList, Image, Price } from '@adobe-commerce/elsie/components';
11
+ import {
12
+ CartItem,
13
+ CartList,
14
+ Image,
15
+ Price,
16
+ } from '@adobe-commerce/elsie/components';
12
17
  import { IconsList } from '@adobe-commerce/elsie/components/Icon/Icon.stories.helpers';
13
18
  import {
14
19
  InLineAlert as component,
15
- InLineAlertProps
20
+ InLineAlertProps,
16
21
  } from '@adobe-commerce/elsie/components/InLineAlert';
17
22
  import type { Meta, StoryObj } from '@storybook/preact-vite';
18
23
  import { action } from 'storybook/actions';
@@ -57,7 +62,7 @@ const meta: Meta<InLineAlertProps> = {
57
62
  },
58
63
  additionalActions: {
59
64
  description:
60
- 'An array of additional action objects that must contain `label` and `onClick()` properties, and may optionally include an `\'aria-label\'` to give the rendered button a unique accessible name (falls back to `label` when omitted)',
65
+ "An array of additional action objects that must contain `label` and `onClick()` properties, and may optionally include an `'aria-label'` to give the rendered button a unique accessible name (falls back to `label` when omitted)",
61
66
  },
62
67
  icon: {
63
68
  description: 'Icon `(FunctionComponent)`',
@@ -77,7 +82,7 @@ const meta: Meta<InLineAlertProps> = {
77
82
  description: 'List of items to display in the alert',
78
83
  type: { name: 'other', value: 'VNode' },
79
84
  control: { disable: true },
80
- }
85
+ },
81
86
  },
82
87
  };
83
88
 
@@ -15,8 +15,10 @@ import { FunctionComponent, VNode } from 'preact';
15
15
  import { HTMLAttributes } from 'preact/compat';
16
16
 
17
17
  import '@adobe-commerce/elsie/components/InLineAlert/InLineAlert.css';
18
- export interface InLineAlertProps
19
- extends Omit<HTMLAttributes<HTMLDivElement>, 'icon'> {
18
+ export interface InLineAlertProps extends Omit<
19
+ HTMLAttributes<HTMLDivElement>,
20
+ 'icon'
21
+ > {
20
22
  variant?: 'primary' | 'secondary';
21
23
  heading: string;
22
24
  description?: string;
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  export * from '@adobe-commerce/elsie/components/InLineAlert/InLineAlert';
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  // https://storybook.js.org/docs/7.0/preact/writing-stories/introduction
@@ -103,15 +103,15 @@ export const Primary: Story = {
103
103
  },
104
104
  play: async () => {
105
105
  const canvasElement = document.querySelector(
106
- '#storybook-root'
106
+ '#storybook-root',
107
107
  ) as HTMLElement;
108
108
  const canvas = within(canvasElement);
109
109
  const decreaseButton = document.querySelector(
110
- 'button[aria-label="Decrease Quantity"]'
110
+ 'button[aria-label="Decrease Quantity"]',
111
111
  ) as HTMLElement;
112
112
  const inputField = document.querySelector('input') as HTMLElement;
113
113
  const increaseButton = document.querySelector(
114
- 'button[aria-label="Increase Quantity"]'
114
+ 'button[aria-label="Increase Quantity"]',
115
115
  ) as HTMLElement;
116
116
 
117
117
  // Without this wait test failing intermittently as click event is triggering before even element fully loaded
@@ -155,11 +155,11 @@ export const WithError = {
155
155
  },
156
156
  play: async () => {
157
157
  const canvasElement = document.querySelector(
158
- '#storybook-root'
158
+ '#storybook-root',
159
159
  ) as HTMLElement;
160
160
  const canvas = within(canvasElement);
161
161
  const increaseButton = document.querySelector(
162
- 'button[aria-label="Increase Quantity"]'
162
+ 'button[aria-label="Increase Quantity"]',
163
163
  ) as HTMLElement;
164
164
 
165
165
  await new Promise((resolve) => setTimeout(resolve, 500));
@@ -167,7 +167,7 @@ export const WithError = {
167
167
  await expect(await canvas.findByDisplayValue('1001')).toBeTruthy();
168
168
 
169
169
  const error = document.querySelector(
170
- '.dropin-incrementer__content--error-message'
170
+ '.dropin-incrementer__content--error-message',
171
171
  ) as HTMLElement;
172
172
 
173
173
  await expect(error).toBeVisible();
@@ -2,13 +2,13 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  import { FunctionComponent } from 'preact';
11
- import { useState, useCallback, useEffect } from 'preact/hooks';
11
+ import { useState, useEffect, useRef } from 'preact/hooks';
12
12
  import { HTMLAttributes } from 'preact/compat';
13
13
  import { classes, debounce } from '@adobe-commerce/elsie/lib';
14
14
  import { Add, Minus } from '@adobe-commerce/elsie/icons';
@@ -16,8 +16,10 @@ import { Icon } from '@adobe-commerce/elsie/components/Icon';
16
16
  import { Localizer, Text } from '@adobe-commerce/elsie/i18n';
17
17
  import '@adobe-commerce/elsie/components/Incrementer/Incrementer.css';
18
18
 
19
- export interface IncrementerProps
20
- extends Omit<HTMLAttributes<HTMLInputElement>, 'size'> {
19
+ export interface IncrementerProps extends Omit<
20
+ HTMLAttributes<HTMLInputElement>,
21
+ 'size'
22
+ > {
21
23
  name?: string;
22
24
  size?: 'medium' | 'large';
23
25
  onValue?: (value: any) => void;
@@ -48,9 +50,11 @@ export const Incrementer: FunctionComponent<IncrementerProps> = ({
48
50
  }) => {
49
51
  const [currentValue, setCurrentValue] = useState<number>(Number(value));
50
52
  const [isEmpty, setIsEmpty] = useState<boolean>(false);
53
+ const isFocusedRef = useRef<boolean>(false);
51
54
  const minValue = Number(min);
52
55
  const maxValue = Number(max);
53
- const isInvalid = error || isEmpty || currentValue < minValue || currentValue > maxValue;
56
+ const isInvalid =
57
+ error || isEmpty || currentValue < minValue || currentValue > maxValue;
54
58
 
55
59
  const errorMessage = isEmpty
56
60
  ? 'Dropin.Incrementer.requiredMessage'
@@ -60,38 +64,49 @@ export const Incrementer: FunctionComponent<IncrementerProps> = ({
60
64
  ? 'Dropin.Incrementer.maxQuantityMessage'
61
65
  : 'Dropin.Incrementer.errorMessage';
62
66
 
63
- // Add this effect to synchronize internal state with external value prop
67
+ // Keep callback refs current so debounced handlers never capture stale closures
68
+ const onValueRef = useRef(onValue);
69
+ useEffect(() => {
70
+ onValueRef.current = onValue;
71
+ }, [onValue]);
72
+
73
+ const onUpdateErrorRef = useRef(onUpdateError);
74
+ useEffect(() => {
75
+ onUpdateErrorRef.current = onUpdateError;
76
+ }, [onUpdateError]);
77
+
78
+ const invoke = (newValue: number) => {
79
+ try {
80
+ onValueRef.current?.(newValue);
81
+ } catch (e) {
82
+ onUpdateErrorRef.current?.(e as Error);
83
+ }
84
+ };
85
+
86
+ // Created once — stable across re-renders caused by cart/data events
87
+ // Buttons: 200ms debounce, created once, never recreated
88
+ const debouncedButtonHandler = useRef(debounce(invoke, 200)).current;
89
+
90
+ // True while the input debounce timer is still pending.
91
+ // Blur only calls invoke if it's cancelling a live timer — not if the timer already fired.
92
+ const hasPendingInputRef = useRef(false);
93
+ const debouncedInputHandler = useRef(
94
+ debounce((newValue: number) => {
95
+ hasPendingInputRef.current = false;
96
+ invoke(newValue);
97
+ }, 1000),
98
+ ).current;
99
+
100
+ // Skip server sync while user is actively typing to prevent flicker
64
101
  useEffect(() => {
65
102
  const propValue = Number(value);
66
- if (propValue !== currentValue) {
103
+ if (!isFocusedRef.current && propValue !== currentValue) {
67
104
  setCurrentValue(propValue);
68
105
  setIsEmpty(false);
69
106
  }
70
107
  // eslint-disable-next-line react-hooks/exhaustive-deps
71
108
  }, [value]);
72
109
 
73
- // eslint-disable-next-line react-hooks/exhaustive-deps
74
- const debouncedOnValueHandler = useCallback(
75
- debounce(async (newValue: any) => {
76
- if (onValue) {
77
- try {
78
- onValue(newValue);
79
- } catch (e) {
80
- if (onUpdateError) {
81
- onUpdateError(e as Error);
82
- }
83
- }
84
- }
85
- }, 200),
86
- [onValue, onUpdateError]
87
- );
88
-
89
- const handleIncrementer = (_value: number) => {
90
- setIsEmpty(false);
91
- debouncedOnValueHandler(_value);
92
- setCurrentValue(_value);
93
- };
94
-
95
110
  return (
96
111
  <div
97
112
  className={classes([
@@ -125,7 +140,14 @@ export const Incrementer: FunctionComponent<IncrementerProps> = ({
125
140
  'dropin-incrementer__decrease-button',
126
141
  [`dropin-incrementer__decrease-button--disabled`, disabled],
127
142
  ])}
128
- onClick={() => handleIncrementer(currentValue - 1)}
143
+ onMouseDown={(e) => e.preventDefault()}
144
+ onClick={() => {
145
+ setIsEmpty(false);
146
+ debouncedInputHandler.cancel();
147
+ hasPendingInputRef.current = false;
148
+ setCurrentValue(currentValue - 1);
149
+ debouncedButtonHandler(currentValue - 1);
150
+ }}
129
151
  disabled={disabled || currentValue < minValue + 1}
130
152
  aria-label={
131
153
  (<Text id="Dropin.Incrementer.decreaseLabel" />) as any
@@ -153,17 +175,26 @@ export const Incrementer: FunctionComponent<IncrementerProps> = ({
153
175
  name={name}
154
176
  value={isEmpty ? '' : currentValue}
155
177
  disabled={disabled}
178
+ onFocus={() => {
179
+ isFocusedRef.current = true;
180
+ }}
156
181
  onBlur={() => {
157
- if (!isEmpty) {
158
- handleIncrementer(Number(currentValue));
159
- }
182
+ isFocusedRef.current = false;
183
+ debouncedInputHandler.cancel();
184
+ const wasPending = hasPendingInputRef.current;
185
+ hasPendingInputRef.current = false;
186
+ if (!isEmpty && wasPending) invoke(Number(currentValue));
160
187
  }}
161
188
  onChange={(e) => {
162
189
  const newValue = e.currentTarget.value;
163
190
  if (newValue === '') {
164
191
  setIsEmpty(true);
165
192
  } else {
166
- handleIncrementer(Number(newValue));
193
+ setIsEmpty(false);
194
+ setCurrentValue(Number(newValue));
195
+ debouncedButtonHandler.cancel();
196
+ hasPendingInputRef.current = true;
197
+ debouncedInputHandler(Number(newValue));
167
198
  }
168
199
  }}
169
200
  {...props}
@@ -184,7 +215,14 @@ export const Incrementer: FunctionComponent<IncrementerProps> = ({
184
215
  'dropin-incrementer__increase-button',
185
216
  [`dropin-incrementer__increase-button--disabled`, disabled],
186
217
  ])}
187
- onClick={() => handleIncrementer(currentValue + 1)}
218
+ onMouseDown={(e) => e.preventDefault()}
219
+ onClick={() => {
220
+ setIsEmpty(false);
221
+ debouncedInputHandler.cancel();
222
+ hasPendingInputRef.current = false;
223
+ setCurrentValue(currentValue + 1);
224
+ debouncedButtonHandler(currentValue + 1);
225
+ }}
188
226
  disabled={disabled || currentValue > maxValue - 1}
189
227
  aria-label={
190
228
  (<Text id="Dropin.Incrementer.increaseLabel" />) as any
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  export * from '@adobe-commerce/elsie/components/Incrementer/Incrementer';
@@ -174,7 +174,10 @@ div.dropin-input-container--secondary .dropin-input--disabled {
174
174
  pointer-events: none;
175
175
  transform: translateY(-50%);
176
176
  top: 50%;
177
- transition: top 50ms ease-in, left 50ms ease-in, font-size 50ms ease-in;
177
+ transition:
178
+ top 50ms ease-in,
179
+ left 50ms ease-in,
180
+ font-size 50ms ease-in;
178
181
  z-index: 1;
179
182
  }
180
183
 
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  // https://storybook.js.org/docs/7.0/preact/writing-stories/introduction
@@ -120,7 +120,7 @@ export const Primary: Story = {
120
120
  const inputField = document.querySelector('input') as HTMLElement;
121
121
  await userEvent.type(inputField, 'Storybook Test Text! input max length');
122
122
  await expect(
123
- await canvas.findByDisplayValue('Storybook Test Text!')
123
+ await canvas.findByDisplayValue('Storybook Test Text!'),
124
124
  ).toBeTruthy();
125
125
  await userEvent.clear(inputField);
126
126
  await expect(await canvas.findByDisplayValue('')).toBeTruthy();
@@ -147,7 +147,7 @@ export const Secondary: Story = {
147
147
  const inputField = document.querySelector('input') as HTMLElement;
148
148
  await userEvent.type(inputField, 'Storybook Test Text! input max length');
149
149
  await expect(
150
- await canvas.findByDisplayValue('Storybook Test Text!')
150
+ await canvas.findByDisplayValue('Storybook Test Text!'),
151
151
  ).toBeTruthy();
152
152
  await userEvent.clear(inputField);
153
153
  await expect(await canvas.findByDisplayValue('')).toBeTruthy();
@@ -19,8 +19,10 @@ import { FunctionComponent, VNode } from 'preact';
19
19
  import { HTMLAttributes } from 'preact/compat';
20
20
  import { useCallback } from 'preact/hooks';
21
21
 
22
- export interface InputProps
23
- extends Omit<HTMLAttributes<HTMLInputElement>, 'size' | 'icon'> {
22
+ export interface InputProps extends Omit<
23
+ HTMLAttributes<HTMLInputElement>,
24
+ 'size' | 'icon'
25
+ > {
24
26
  id?: string;
25
27
  name?: string;
26
28
  variant?: 'primary' | 'secondary';
@@ -71,7 +73,7 @@ export const Input: FunctionComponent<InputProps> = ({
71
73
  }
72
74
  }
73
75
  }, 200),
74
- [onValue, onUpdateError]
76
+ [onValue, onUpdateError],
75
77
  );
76
78
 
77
79
  const handleOnValue = (e: Event) => {
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  export * from '@adobe-commerce/elsie/components/Input/Input';
@@ -64,7 +64,7 @@ export const InputDate: FunctionComponent<InputDateProps> = ({
64
64
  input?.focus();
65
65
  input?.showPicker();
66
66
  },
67
- []
67
+ [],
68
68
  );
69
69
 
70
70
  const handleOnBlur: JSX.MouseEventHandler<HTMLInputElement> = useCallback(
@@ -72,7 +72,7 @@ export const InputDate: FunctionComponent<InputDateProps> = ({
72
72
  setIsPickerOpen(false);
73
73
  onBlur?.(event);
74
74
  },
75
- [onBlur]
75
+ [onBlur],
76
76
  );
77
77
 
78
78
  const handleInputChange: JSX.MouseEventHandler<HTMLInputElement> =
@@ -81,7 +81,7 @@ export const InputDate: FunctionComponent<InputDateProps> = ({
81
81
  setInternalValue((event.target as HTMLInputElement).value);
82
82
  onChange?.(event);
83
83
  },
84
- [onChange]
84
+ [onChange],
85
85
  );
86
86
 
87
87
  return (
@@ -2,9 +2,9 @@
2
2
  * Copyright 2024 Adobe
3
3
  * All Rights Reserved.
4
4
  *
5
- * NOTICE: Adobe permits you to use, modify, and distribute this
6
- * file in accordance with the terms of the Adobe license agreement
7
- * accompanying it.
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
8
  *******************************************************************/
9
9
 
10
10
  export * from '@adobe-commerce/elsie/components/InputDate/InputDate';
@@ -10,30 +10,30 @@
10
10
  /* https://cssguidelin.es/#bem-like-naming */
11
11
 
12
12
  .dropin-input-file__input {
13
- display: none;
13
+ display: none;
14
14
  }
15
15
 
16
16
  .dropin-input-file__label {
17
- border: 0 none;
18
- cursor: pointer;
19
- border-radius: var(--shape-border-radius-3);
20
- padding: var(--spacing-xsmall) var(--spacing-medium);
21
- display: flex;
22
- justify-content: center;
23
- align-items: center;
24
- background: var(--color-brand-500);
25
- color: var(--color-neutral-50);
26
- font: var(--type-button-2-font);
27
- letter-spacing: var(--type-button-2-letter-spacing);
17
+ border: 0 none;
18
+ cursor: pointer;
19
+ border-radius: var(--shape-border-radius-3);
20
+ padding: var(--spacing-xsmall) var(--spacing-medium);
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ background: var(--color-brand-500);
25
+ color: var(--color-neutral-50);
26
+ font: var(--type-button-2-font);
27
+ letter-spacing: var(--type-button-2-letter-spacing);
28
28
  }
29
29
 
30
30
  .dropin-input-file__label:hover {
31
- background-color: var(--color-button-hover);
31
+ background-color: var(--color-button-hover);
32
32
  }
33
33
 
34
34
  .dropin-input-file__icon {
35
- height: 24px;
36
- margin-right: var(--spacing-xsmall);
35
+ height: 24px;
36
+ margin-right: var(--spacing-xsmall);
37
37
  }
38
38
 
39
39
  /* Medium (portrait tablets and large phones, 768px and up) */
@@ -46,4 +46,4 @@
46
46
  /* @media only screen and (min-width: 1366px) { } */
47
47
 
48
48
  /* XXlarge (large laptops and desktops, 1920px and up) */
49
- /* @media only screen and (min-width: 1920px) { } */
49
+ /* @media only screen and (min-width: 1920px) { } */