@adobe-commerce/elsie 1.0.0-alpha04071347
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.
- package/.elsie.js +21 -0
- package/.eslintrc.js +18 -0
- package/README.md +52 -0
- package/__mocks__/svg.js +11 -0
- package/bin/builders/build/index.js +20 -0
- package/bin/builders/generate/api/index.js +65 -0
- package/bin/builders/generate/api/templates/function.js +9 -0
- package/bin/builders/generate/api/templates/index.js +7 -0
- package/bin/builders/generate/api/templates/story.js +23 -0
- package/bin/builders/generate/api/templates/unit-test.js +15 -0
- package/bin/builders/generate/component/index.js +87 -0
- package/bin/builders/generate/component/templates/Component.js +43 -0
- package/bin/builders/generate/component/templates/css.js +24 -0
- package/bin/builders/generate/component/templates/index.js +8 -0
- package/bin/builders/generate/component/templates/stories.js +46 -0
- package/bin/builders/generate/component/templates/unit-test.js +19 -0
- package/bin/builders/generate/config/index.js +54 -0
- package/bin/builders/generate/config/templates/elsie.js +29 -0
- package/bin/builders/generate/container/index.js +65 -0
- package/bin/builders/generate/container/templates/Component.js +18 -0
- package/bin/builders/generate/container/templates/index.js +8 -0
- package/bin/builders/generate/container/templates/stories.js +34 -0
- package/bin/builders/generate/container/templates/unit-test.js +19 -0
- package/bin/builders/generate/index.js +283 -0
- package/bin/builders/gql/createOrClearDirectory.js +33 -0
- package/bin/builders/gql/getSchemaRef.js +25 -0
- package/bin/builders/gql/index.js +71 -0
- package/bin/builders/lint/index.js +5 -0
- package/bin/builders/serve/index.js +44 -0
- package/bin/builders/storybook/index.js +5 -0
- package/bin/builders/test/index.js +5 -0
- package/bin/index.js +26 -0
- package/bin/lib/cli.js +8 -0
- package/bin/lib/config.js +12 -0
- package/bin/lib/log-message.js +11 -0
- package/bin/lib/string.js +26 -0
- package/bin/lib/validate-typeof.js +28 -0
- package/bin/lib/write-file.js +30 -0
- package/bin/lib/write-parent-index.js +45 -0
- package/config/eslint.js +113 -0
- package/config/jest.js +90 -0
- package/config/prettier.js +16 -0
- package/config/setEnvVars.js +14 -0
- package/config/storybook/addon.js +130 -0
- package/config/storybook/components/FileTree/FileTree.jsx +192 -0
- package/config/storybook/components/FileTree/index.js +10 -0
- package/config/storybook/components/Flex/Flex.jsx +21 -0
- package/config/storybook/components/Flex/Flex.module.css +29 -0
- package/config/storybook/components/Flex/index.js +10 -0
- package/config/storybook/components/OptionsTable/OptionsTable.jsx +88 -0
- package/config/storybook/components/OptionsTable/OptionsTable.module.css +104 -0
- package/config/storybook/components/OptionsTable/index.js +10 -0
- package/config/storybook/components/Panel/Panel.module.css +56 -0
- package/config/storybook/components/Panel/Panel.tsx +46 -0
- package/config/storybook/components/Panel/index.ts +10 -0
- package/config/storybook/components/Screenshot/Screenshot.jsx +23 -0
- package/config/storybook/components/Screenshot/Screenshot.module.css +28 -0
- package/config/storybook/components/Screenshot/index.js +10 -0
- package/config/storybook/components/Steps/Steps.jsx +21 -0
- package/config/storybook/components/Steps/Steps.module.css +43 -0
- package/config/storybook/components/Steps/index.js +10 -0
- package/config/storybook/components/StoryWrapper/StoryWrapper.jsx +18 -0
- package/config/storybook/components/StoryWrapper/StoryWrapper.module.css +22 -0
- package/config/storybook/components/StoryWrapper/index.js +10 -0
- package/config/storybook/components/Summary/Summary.jsx +19 -0
- package/config/storybook/components/Summary/Summary.module.css +20 -0
- package/config/storybook/components/Summary/index.js +10 -0
- package/config/storybook/components/Variants/Variants.js +57 -0
- package/config/storybook/components/Variants/docs.css +48 -0
- package/config/storybook/components/Variants/index.js +10 -0
- package/config/storybook/components/video/index.jsx +28 -0
- package/config/storybook/manager.js +23 -0
- package/config/storybook/preview.jsx +88 -0
- package/config/storybook/theming/fonts.css +68 -0
- package/config/storybook/theming/logo.svg +19 -0
- package/config/storybook/theming/manager.css +63 -0
- package/config/storybook/theming/preview.css +93 -0
- package/config/storybook/theming/theme.js +61 -0
- package/config/tsconfig-base.json +16 -0
- package/config/tsconfig-preact.json +15 -0
- package/config/vite.mjs +306 -0
- package/package.json +113 -0
- package/post-release.sh +5 -0
- package/src/components/Accordion/Accordion.css +88 -0
- package/src/components/Accordion/Accordion.stories.tsx +582 -0
- package/src/components/Accordion/Accordion.tsx +177 -0
- package/src/components/Accordion/index.ts +11 -0
- package/src/components/ActionButton/ActionButton.css +100 -0
- package/src/components/ActionButton/ActionButton.stories.tsx +169 -0
- package/src/components/ActionButton/ActionButton.tsx +53 -0
- package/src/components/ActionButton/index.ts +10 -0
- package/src/components/ActionButtonGroup/ActionButtonGroup.css +77 -0
- package/src/components/ActionButtonGroup/ActionButtonGroup.stories.tsx +97 -0
- package/src/components/ActionButtonGroup/ActionButtonGroup.tsx +91 -0
- package/src/components/ActionButtonGroup/index.ts +10 -0
- package/src/components/AlertBanner/AlertBanner.css +144 -0
- package/src/components/AlertBanner/AlertBanner.stories.tsx +165 -0
- package/src/components/AlertBanner/AlertBanner.tsx +90 -0
- package/src/components/AlertBanner/index.ts +11 -0
- package/src/components/Breadcrumbs/Breadcrumbs.css +60 -0
- package/src/components/Breadcrumbs/Breadcrumbs.stories.tsx +195 -0
- package/src/components/Breadcrumbs/Breadcrumbs.tsx +71 -0
- package/src/components/Breadcrumbs/index.ts +11 -0
- package/src/components/Button/Button.css +213 -0
- package/src/components/Button/Button.mdx +133 -0
- package/src/components/Button/Button.stories.tsx +398 -0
- package/src/components/Button/Button.tsx +121 -0
- package/src/components/Button/index.ts +11 -0
- package/src/components/Card/Card.css +34 -0
- package/src/components/Card/Card.stories.tsx +76 -0
- package/src/components/Card/Card.tsx +34 -0
- package/src/components/Card/index.ts +10 -0
- package/src/components/CartItem/CartItem.css +509 -0
- package/src/components/CartItem/CartItem.stories.tsx +628 -0
- package/src/components/CartItem/CartItem.tsx +467 -0
- package/src/components/CartItem/CartItemSkeleton.tsx +38 -0
- package/src/components/CartItem/index.ts +12 -0
- package/src/components/CartList/CartList.css +35 -0
- package/src/components/CartList/CartList.stories.tsx +111 -0
- package/src/components/CartList/CartList.tsx +40 -0
- package/src/components/CartList/index.ts +11 -0
- package/src/components/Checkbox/Checkbox.css +255 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +290 -0
- package/src/components/Checkbox/Checkbox.tsx +138 -0
- package/src/components/Checkbox/index.ts +10 -0
- package/src/components/ColorSwatch/ColorSwatch.css +132 -0
- package/src/components/ColorSwatch/ColorSwatch.stories.tsx +274 -0
- package/src/components/ColorSwatch/ColorSwatch.tsx +127 -0
- package/src/components/ColorSwatch/index.ts +11 -0
- package/src/components/ContentGrid/ContentGrid.css +54 -0
- package/src/components/ContentGrid/ContentGrid.stories.tsx +137 -0
- package/src/components/ContentGrid/ContentGrid.tsx +57 -0
- package/src/components/ContentGrid/index.ts +11 -0
- package/src/components/Divider/Divider.css +22 -0
- package/src/components/Divider/Divider.stories.tsx +62 -0
- package/src/components/Divider/Divider.tsx +33 -0
- package/src/components/Divider/index.ts +11 -0
- package/src/components/Field/Field.css +83 -0
- package/src/components/Field/Field.stories.tsx +238 -0
- package/src/components/Field/Field.tsx +84 -0
- package/src/components/Field/index.ts +10 -0
- package/src/components/Header/Header.css +56 -0
- package/src/components/Header/Header.stories.tsx +180 -0
- package/src/components/Header/Header.tsx +81 -0
- package/src/components/Header/index.ts +11 -0
- package/src/components/Icon/Icon.css +26 -0
- package/src/components/Icon/Icon.stories.helpers.jsx +21 -0
- package/src/components/Icon/Icon.stories.tsx +98 -0
- package/src/components/Icon/Icon.tsx +112 -0
- package/src/components/Icon/index.ts +10 -0
- package/src/components/IllustratedMessage/IllustratedMessage.css +61 -0
- package/src/components/IllustratedMessage/IllustratedMessage.stories.tsx +126 -0
- package/src/components/IllustratedMessage/IllustratedMessage.tsx +78 -0
- package/src/components/IllustratedMessage/index.ts +11 -0
- package/src/components/Image/Image.css +52 -0
- package/src/components/Image/Image.stories.tsx +89 -0
- package/src/components/Image/Image.tsx +66 -0
- package/src/components/Image/index.ts +10 -0
- package/src/components/ImageSwatch/ImageSwatch.css +154 -0
- package/src/components/ImageSwatch/ImageSwatch.stories.tsx +310 -0
- package/src/components/ImageSwatch/ImageSwatch.tsx +123 -0
- package/src/components/ImageSwatch/index.ts +11 -0
- package/src/components/InLineAlert/InLineAlert.css +116 -0
- package/src/components/InLineAlert/InLineAlert.stories.tsx +326 -0
- package/src/components/InLineAlert/InLineAlert.tsx +128 -0
- package/src/components/InLineAlert/index.ts +11 -0
- package/src/components/Incrementer/Incrementer.css +165 -0
- package/src/components/Incrementer/Incrementer.stories.tsx +172 -0
- package/src/components/Incrementer/Incrementer.tsx +192 -0
- package/src/components/Incrementer/index.ts +10 -0
- package/src/components/Input/Input.css +304 -0
- package/src/components/Input/Input.stories.tsx +155 -0
- package/src/components/Input/Input.tsx +166 -0
- package/src/components/Input/index.ts +11 -0
- package/src/components/InputDate/InputDate.css +56 -0
- package/src/components/InputDate/InputDate.stories.tsx +117 -0
- package/src/components/InputDate/InputDate.tsx +120 -0
- package/src/components/InputDate/index.ts +11 -0
- package/src/components/InputPassword/InputPassword.css +31 -0
- package/src/components/InputPassword/InputPassword.stories.tsx +148 -0
- package/src/components/InputPassword/InputPassword.tsx +135 -0
- package/src/components/InputPassword/PasswordStatusIndicator/PasswordStatusIndicator.css +31 -0
- package/src/components/InputPassword/PasswordStatusIndicator/PasswordStatusIndicator.tsx +96 -0
- package/src/components/InputPassword/PasswordStatusIndicator/index.ts +11 -0
- package/src/components/InputPassword/index.ts +11 -0
- package/src/components/Modal/Modal.css +125 -0
- package/src/components/Modal/Modal.stories.tsx +250 -0
- package/src/components/Modal/Modal.tsx +157 -0
- package/src/components/Modal/index.ts +10 -0
- package/src/components/Pagination/Pagination.css +95 -0
- package/src/components/Pagination/Pagination.stories.tsx +117 -0
- package/src/components/Pagination/Pagination.tsx +149 -0
- package/src/components/Pagination/index.ts +11 -0
- package/src/components/Picker/Picker.css +220 -0
- package/src/components/Picker/Picker.stories.tsx +318 -0
- package/src/components/Picker/Picker.tsx +203 -0
- package/src/components/Picker/index.ts +10 -0
- package/src/components/Price/Price.css +57 -0
- package/src/components/Price/Price.stories.tsx +110 -0
- package/src/components/Price/Price.tsx +75 -0
- package/src/components/Price/index.ts +10 -0
- package/src/components/PriceRange/PriceRange.css +66 -0
- package/src/components/PriceRange/PriceRange.stories.tsx +240 -0
- package/src/components/PriceRange/PriceRange.tsx +248 -0
- package/src/components/PriceRange/index.ts +11 -0
- package/src/components/ProgressSpinner/ProgressSpinner.css +91 -0
- package/src/components/ProgressSpinner/ProgressSpinner.stories.tsx +300 -0
- package/src/components/ProgressSpinner/ProgressSpinner.tsx +86 -0
- package/src/components/ProgressSpinner/index.ts +11 -0
- package/src/components/RadioButton/RadioButton.css +134 -0
- package/src/components/RadioButton/RadioButton.stories.tsx +126 -0
- package/src/components/RadioButton/RadioButton.tsx +86 -0
- package/src/components/RadioButton/index.ts +11 -0
- package/src/components/Skeleton/Skeleton.css +145 -0
- package/src/components/Skeleton/Skeleton.stories.tsx +265 -0
- package/src/components/Skeleton/Skeleton.tsx +133 -0
- package/src/components/Skeleton/index.ts +10 -0
- package/src/components/Tag/Tag.css +26 -0
- package/src/components/Tag/Tag.stories.tsx +103 -0
- package/src/components/Tag/Tag.tsx +38 -0
- package/src/components/Tag/index.ts +11 -0
- package/src/components/TextArea/TextArea.css +140 -0
- package/src/components/TextArea/TextArea.stories.tsx +130 -0
- package/src/components/TextArea/TextArea.tsx +89 -0
- package/src/components/TextArea/index.ts +11 -0
- package/src/components/TextSwatch/TextSwatch.css +152 -0
- package/src/components/TextSwatch/TextSwatch.stories.tsx +277 -0
- package/src/components/TextSwatch/TextSwatch.tsx +131 -0
- package/src/components/TextSwatch/index.ts +11 -0
- package/src/components/ToggleButton/ToggleButton.css +95 -0
- package/src/components/ToggleButton/ToggleButton.stories.tsx +190 -0
- package/src/components/ToggleButton/ToggleButton.tsx +75 -0
- package/src/components/ToggleButton/index.ts +11 -0
- package/src/components/UIProvider/UIProvider.css +140 -0
- package/src/components/UIProvider/UIProvider.tsx +61 -0
- package/src/components/UIProvider/debugger.css +47 -0
- package/src/components/UIProvider/index.ts +10 -0
- package/src/components/UIProvider/normalize.css +26 -0
- package/src/components/index.ts +49 -0
- package/src/docs/API/event-bus.mdx +52 -0
- package/src/docs/API/graphql.mdx +214 -0
- package/src/docs/API/initializer.mdx +119 -0
- package/src/docs/API/render.mdx +125 -0
- package/src/docs/Design/colors.mdx +202 -0
- package/src/docs/Design/designBlocks.jsx +87 -0
- package/src/docs/Design/getTokenData.ts +28 -0
- package/src/docs/Design/grid.mdx +365 -0
- package/src/docs/Design/overview.mdx +69 -0
- package/src/docs/Design/shapes.mdx +100 -0
- package/src/docs/Design/spacing.mdx +22 -0
- package/src/docs/Design/typography.mdx +126 -0
- package/src/docs/Utilities/classList.mdx +52 -0
- package/src/docs/Utilities/debounce.mdx +49 -0
- package/src/docs/Utilities/deepmerge.mdx +12 -0
- package/src/docs/Utilities/getFormErrors.mdx +41 -0
- package/src/docs/Utilities/getFormValues.mdx +38 -0
- package/src/docs/assets/Banner.png +0 -0
- package/src/docs/assets/Colors.png +0 -0
- package/src/docs/assets/DropinBanner.png +0 -0
- package/src/docs/assets/ShapeStyles.png +0 -0
- package/src/docs/assets/Spacing.png +0 -0
- package/src/docs/assets/Typography.png +0 -0
- package/src/docs/cli-usage.mdx +181 -0
- package/src/docs/components/overview.mdx +124 -0
- package/src/docs/quick-start.mdx +245 -0
- package/src/docs/slots.mdx +211 -0
- package/src/docs/welcome.mdx +52 -0
- package/src/i18n/en_US.json +146 -0
- package/src/i18n/index.ts +26 -0
- package/src/icons/Add.svg +9 -0
- package/src/icons/AddressBook.svg +3 -0
- package/src/icons/Bulk.svg +24 -0
- package/src/icons/Burger.svg +5 -0
- package/src/icons/Card.svg +7 -0
- package/src/icons/Cart.svg +11 -0
- package/src/icons/Check.svg +8 -0
- package/src/icons/CheckWithCircle.svg +4 -0
- package/src/icons/ChevronDown.svg +3 -0
- package/src/icons/ChevronRight.svg +8 -0
- package/src/icons/ChevronUp.svg +3 -0
- package/src/icons/Close.svg +4 -0
- package/src/icons/Coupon.svg +3 -0
- package/src/icons/Date.svg +4 -0
- package/src/icons/Delivery.svg +11 -0
- package/src/icons/EmptyBox.svg +3 -0
- package/src/icons/Eye.svg +3 -0
- package/src/icons/EyeClose.svg +3 -0
- package/src/icons/Gift.svg +3 -0
- package/src/icons/GiftCard.svg +3 -0
- package/src/icons/Heart.svg +3 -0
- package/src/icons/HeartFilled.svg +3 -0
- package/src/icons/InfoFilled.svg +3 -0
- package/src/icons/Locker.svg +11 -0
- package/src/icons/Minus.svg +3 -0
- package/src/icons/Order.svg +6 -0
- package/src/icons/OrderError.svg +15 -0
- package/src/icons/OrderSuccess.svg +15 -0
- package/src/icons/PaymentError.svg +16 -0
- package/src/icons/Placeholder.svg +3 -0
- package/src/icons/PlaceholderFilled.svg +4 -0
- package/src/icons/Search.svg +9 -0
- package/src/icons/SearchFilled.svg +10 -0
- package/src/icons/Sort.svg +12 -0
- package/src/icons/Star.svg +8 -0
- package/src/icons/Trash.svg +7 -0
- package/src/icons/User.svg +5 -0
- package/src/icons/View.svg +14 -0
- package/src/icons/Wallet.svg +6 -0
- package/src/icons/Warning.svg +12 -0
- package/src/icons/WarningFilled.svg +3 -0
- package/src/icons/WarningWithCircle.svg +4 -0
- package/src/icons/index.ts +42 -0
- package/src/lib/classes.ts +34 -0
- package/src/lib/config.ts +24 -0
- package/src/lib/debounce.ts +16 -0
- package/src/lib/deepmerge.ts +45 -0
- package/src/lib/deviceUtils.ts +16 -0
- package/src/lib/form-values.ts +31 -0
- package/src/lib/i18n.ts +18 -0
- package/src/lib/image-params-keymap.ts +36 -0
- package/src/lib/index.ts +24 -0
- package/src/lib/initializer.ts +134 -0
- package/src/lib/is-number.ts +12 -0
- package/src/lib/render.tsx +138 -0
- package/src/lib/resolve-image.ts +101 -0
- package/src/lib/signals.ts +11 -0
- package/src/lib/slot.tsx +434 -0
- package/src/lib/tests.tsx +47 -0
- package/src/lib/types.ts +16 -0
- package/src/lib/vcomponent.tsx +42 -0
- package/static/assets/images/Card.png +0 -0
- package/static/assets/images/example.jpg +0 -0
- package/static/assets/images/index.ts +11 -0
- package/static/dropin.png +0 -0
- package/static/favicon.svg +14 -0
- package/storybook-stories.js +21 -0
- package/tests/__mocks__/browserMocks.ts +28 -0
- package/tests/__mocks__/fileMocks.ts +12 -0
- package/tests/__mocks__/styleMock.ts +0 -0
- package/types/icons.d.ts +18 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* Copyright 2024 Adobe
|
|
3
|
+
* All Rights Reserved.
|
|
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.
|
|
8
|
+
*******************************************************************/
|
|
9
|
+
|
|
10
|
+
/* https://cssguidelin.es/#bem-like-naming */
|
|
11
|
+
|
|
12
|
+
/* Content */
|
|
13
|
+
.dropin-incrementer__content {
|
|
14
|
+
border-radius: var(--shape-border-radius-1);
|
|
15
|
+
border: solid var(--shape-border-width-1) var(--color-neutral-600);
|
|
16
|
+
display: grid;
|
|
17
|
+
grid-template-columns: var(--spacing-xxbig) auto var(--spacing-xxbig);
|
|
18
|
+
height: var(--spacing-xbig);
|
|
19
|
+
opacity: 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.dropin-incrementer__content--disabled {
|
|
23
|
+
background: var(--color-neutral-300);
|
|
24
|
+
border-radius: var(--shape-border-radius-1);
|
|
25
|
+
border: solid var(--shape-border-width-1) var(--color-neutral-500);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.dropin-incrementer__content--large {
|
|
29
|
+
height: var(--spacing-xxbig);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.dropin-incrementer__content:hover {
|
|
33
|
+
border: solid var(--shape-border-width-1) var(--color-neutral-700);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.dropin-incrementer__content:active {
|
|
37
|
+
border: solid var(--shape-border-width-1) var(--color-neutral-800);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.dropin-incrementer__content--error:hover,
|
|
41
|
+
.dropin-incrementer__content--error {
|
|
42
|
+
border: var(--shape-border-width-2) solid var(--color-alert-500);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.dropin-incrementer__content--error-message {
|
|
46
|
+
color: var(--color-alert-800);
|
|
47
|
+
font: var(--type-details-caption-2-font);
|
|
48
|
+
letter-spacing: var(--type-details-caption-2-letter-spacing);
|
|
49
|
+
text-align: left;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* Footer */
|
|
53
|
+
.dropin-incrementer__footer {
|
|
54
|
+
font: var(--type-details-caption-2-font);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* Buttons */
|
|
58
|
+
.dropin-incrementer__decrease-button > svg,
|
|
59
|
+
.dropin-incrementer__increase-button > svg {
|
|
60
|
+
align-items: center;
|
|
61
|
+
justify-content: center;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.dropin-incrementer__button-container {
|
|
65
|
+
align-items: center;
|
|
66
|
+
border-radius: var(--shape-border-radius-1);
|
|
67
|
+
display: grid;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
background: var(--color-neutral-50);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.dropin-incrementer__button-container--disabled {
|
|
73
|
+
background-color: var(--color-neutral-300);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.dropin-incrementer__decrease-button,
|
|
77
|
+
.dropin-incrementer__increase-button {
|
|
78
|
+
align-items: center;
|
|
79
|
+
background-color: var(--color-neutral-50);
|
|
80
|
+
border-radius: var(--shape-border-radius-3);
|
|
81
|
+
border: none;
|
|
82
|
+
display: grid;
|
|
83
|
+
height: var(--spacing-medium);
|
|
84
|
+
width: var(--spacing-medium);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.dropin-incrementer__decrease-button:enabled,
|
|
88
|
+
.dropin-incrementer__increase-button:enabled {
|
|
89
|
+
cursor: pointer;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.dropin-incrementer__decrease-button--disabled,
|
|
93
|
+
.dropin-incrementer__increase-button--disabled {
|
|
94
|
+
background-color: var(--color-neutral-300);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.dropin-incrementer__increase-button:focus-visible,
|
|
98
|
+
.dropin-incrementer__decrease-button:focus-visible {
|
|
99
|
+
outline: var(--shape-border-width-1) solid var(--color-brand-500);
|
|
100
|
+
box-shadow: 0px 0px 0px var(--shape-border-radius-1) var(--color-neutral-500);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.dropin-incrementer__decrease-button:focus:not(:focus-visible),
|
|
104
|
+
.dropin-incrementer__increase-button:focus:not(:focus-visible) {
|
|
105
|
+
background-color: var(--color-neutral-50);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.dropin-incrementer__decrease-button:hover:enabled,
|
|
109
|
+
.dropin-incrementer__increase-button:hover:enabled,
|
|
110
|
+
.dropin-incrementer__decrease-button:focus,
|
|
111
|
+
.dropin-incrementer__increase-button:focus {
|
|
112
|
+
background: var(--color-neutral-300);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Input */
|
|
116
|
+
.dropin-incrementer__input {
|
|
117
|
+
box-sizing: border-box;
|
|
118
|
+
text-align: center;
|
|
119
|
+
min-width: var(--spacing-xxbig);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.dropin-incrementer__input:disabled {
|
|
123
|
+
background-color: var(--color-neutral-300);
|
|
124
|
+
color: var(--color-neutral-500);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.dropin-incrementer__input::-webkit-outer-spin-button,
|
|
128
|
+
.dropin-incrementer__input::-webkit-inner-spin-button {
|
|
129
|
+
-webkit-appearance: none;
|
|
130
|
+
margin: 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.dropin-incrementer__input:focus-within {
|
|
134
|
+
border: none;
|
|
135
|
+
box-sizing: border-box;
|
|
136
|
+
text-align: center;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.dropin-incrementer__input:focus-within[type='number'] {
|
|
140
|
+
box-shadow: none;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* Firefox */
|
|
144
|
+
.dropin-incrementer__input[type='number'] {
|
|
145
|
+
-moz-appearance: textfield;
|
|
146
|
+
box-shadow: none;
|
|
147
|
+
border: none;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
textarea:focus,
|
|
151
|
+
input:focus {
|
|
152
|
+
outline: none;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* Medium (portrait tablets and large phones, 768px and up) */
|
|
156
|
+
/* @media only screen and (min-width: 768px) { } */
|
|
157
|
+
|
|
158
|
+
/* Large (landscape tablets, 1024px and up) */
|
|
159
|
+
/* @media only screen and (min-width: 1024px) { } */
|
|
160
|
+
|
|
161
|
+
/* XLarge (laptops/desktops, 1366px and up) */
|
|
162
|
+
/* @media only screen and (min-width: 1366px) { } */
|
|
163
|
+
|
|
164
|
+
/* XXlarge (large laptops and desktops, 1920px and up) */
|
|
165
|
+
/* @media only screen and (min-width: 1920px) { } */
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* Copyright 2024 Adobe
|
|
3
|
+
* All Rights Reserved.
|
|
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.
|
|
8
|
+
*******************************************************************/
|
|
9
|
+
|
|
10
|
+
// https://storybook.js.org/docs/7.0/preact/writing-stories/introduction
|
|
11
|
+
import type { Meta, StoryObj } from '@storybook/preact';
|
|
12
|
+
import {
|
|
13
|
+
Incrementer,
|
|
14
|
+
IncrementerProps,
|
|
15
|
+
} from '@adobe-commerce/elsie/components/Incrementer';
|
|
16
|
+
import { action } from '@storybook/addon-actions';
|
|
17
|
+
import { expect, userEvent, within } from '@storybook/test';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Use Incrementer to let users increase or decrease a value.
|
|
21
|
+
*/
|
|
22
|
+
const meta: Meta<IncrementerProps> = {
|
|
23
|
+
title: 'Components/Incrementer',
|
|
24
|
+
component: Incrementer,
|
|
25
|
+
argTypes: {
|
|
26
|
+
name: {
|
|
27
|
+
description: 'Field name (used for mapping the value in a form)',
|
|
28
|
+
type: {
|
|
29
|
+
required: false,
|
|
30
|
+
name: 'string',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
value: {
|
|
34
|
+
description: 'Field value',
|
|
35
|
+
type: 'string',
|
|
36
|
+
},
|
|
37
|
+
size: {
|
|
38
|
+
description: 'medium | large',
|
|
39
|
+
defaultValue: { summary: 'medium' },
|
|
40
|
+
options: ['medium', 'large'],
|
|
41
|
+
control: { type: 'radio' },
|
|
42
|
+
type: 'string',
|
|
43
|
+
},
|
|
44
|
+
min: {
|
|
45
|
+
description: 'Minimum value',
|
|
46
|
+
type: 'number',
|
|
47
|
+
},
|
|
48
|
+
max: {
|
|
49
|
+
description: 'Maximum value',
|
|
50
|
+
type: 'number',
|
|
51
|
+
},
|
|
52
|
+
disabled: {
|
|
53
|
+
description: 'Whether or not the field is disabled',
|
|
54
|
+
control: 'boolean',
|
|
55
|
+
defaultValue: false,
|
|
56
|
+
},
|
|
57
|
+
'aria-label': {
|
|
58
|
+
description: 'Aria label',
|
|
59
|
+
type: 'string',
|
|
60
|
+
},
|
|
61
|
+
onValue: {
|
|
62
|
+
description: 'Callback function to handle value change',
|
|
63
|
+
type: 'function',
|
|
64
|
+
},
|
|
65
|
+
onUpdateError: {
|
|
66
|
+
description: 'Callback function to handle error',
|
|
67
|
+
type: 'function',
|
|
68
|
+
},
|
|
69
|
+
error: {
|
|
70
|
+
description: 'Whether or not the field shows an error',
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
},
|
|
73
|
+
success: {
|
|
74
|
+
description:
|
|
75
|
+
'Whether or not the field value has been updated successfully',
|
|
76
|
+
type: 'boolean',
|
|
77
|
+
},
|
|
78
|
+
maxLength: {
|
|
79
|
+
description: 'Maximum length of the input field',
|
|
80
|
+
type: 'number',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default meta;
|
|
86
|
+
|
|
87
|
+
type Story = StoryObj<IncrementerProps>;
|
|
88
|
+
|
|
89
|
+
export const Primary: Story = {
|
|
90
|
+
args: {
|
|
91
|
+
size: 'medium',
|
|
92
|
+
onValue: action('onValue'),
|
|
93
|
+
name: 'incrementerField',
|
|
94
|
+
value: '1',
|
|
95
|
+
min: 1,
|
|
96
|
+
max: 100,
|
|
97
|
+
disabled: false,
|
|
98
|
+
'aria-label': 'Quantity',
|
|
99
|
+
},
|
|
100
|
+
play: async () => {
|
|
101
|
+
const canvasElement = document.querySelector(
|
|
102
|
+
'#storybook-root'
|
|
103
|
+
) as HTMLElement;
|
|
104
|
+
const canvas = within(canvasElement);
|
|
105
|
+
const decreaseButton = document.querySelector(
|
|
106
|
+
'button[aria-label="Decrease Quantity"]'
|
|
107
|
+
) as HTMLElement;
|
|
108
|
+
const inputField = document.querySelector('input') as HTMLElement;
|
|
109
|
+
const increaseButton = document.querySelector(
|
|
110
|
+
'button[aria-label="Increase Quantity"]'
|
|
111
|
+
) as HTMLElement;
|
|
112
|
+
|
|
113
|
+
// Without this wait test failing intermittently as click event is triggering before even element fully loaded
|
|
114
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
115
|
+
await userEvent.click(increaseButton);
|
|
116
|
+
await expect(await canvas.findByDisplayValue('2')).toBeTruthy();
|
|
117
|
+
|
|
118
|
+
await userEvent.click(decreaseButton);
|
|
119
|
+
await expect(await canvas.findByDisplayValue('1')).toBeTruthy();
|
|
120
|
+
|
|
121
|
+
await userEvent.clear(inputField);
|
|
122
|
+
await userEvent.type(inputField, '99');
|
|
123
|
+
await expect(await canvas.findByDisplayValue('99')).toBeTruthy();
|
|
124
|
+
|
|
125
|
+
await userEvent.click(increaseButton);
|
|
126
|
+
await expect(await canvas.findByDisplayValue('100')).toBeTruthy();
|
|
127
|
+
|
|
128
|
+
await userEvent.click(increaseButton);
|
|
129
|
+
await expect(await canvas.findByDisplayValue('100')).toBeTruthy();
|
|
130
|
+
|
|
131
|
+
await userEvent.click(decreaseButton);
|
|
132
|
+
await expect(await canvas.findByDisplayValue('99')).toBeTruthy();
|
|
133
|
+
|
|
134
|
+
await userEvent.clear(inputField);
|
|
135
|
+
await userEvent.type(inputField, '1');
|
|
136
|
+
await expect(await canvas.findByDisplayValue('1')).toBeTruthy();
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const WithError = {
|
|
141
|
+
args: {
|
|
142
|
+
size: 'medium',
|
|
143
|
+
onValue: action('onValue'),
|
|
144
|
+
onBlur: action('onBlur'),
|
|
145
|
+
name: 'incrementerField',
|
|
146
|
+
value: '1001',
|
|
147
|
+
min: 1,
|
|
148
|
+
max: 100,
|
|
149
|
+
disabled: false,
|
|
150
|
+
'aria-label': 'Quantity',
|
|
151
|
+
},
|
|
152
|
+
play: async () => {
|
|
153
|
+
const canvasElement = document.querySelector(
|
|
154
|
+
'#storybook-root'
|
|
155
|
+
) as HTMLElement;
|
|
156
|
+
const canvas = within(canvasElement);
|
|
157
|
+
const increaseButton = document.querySelector(
|
|
158
|
+
'button[aria-label="Increase Quantity"]'
|
|
159
|
+
) as HTMLElement;
|
|
160
|
+
|
|
161
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
162
|
+
await userEvent.click(increaseButton);
|
|
163
|
+
await expect(await canvas.findByDisplayValue('1001')).toBeTruthy();
|
|
164
|
+
|
|
165
|
+
const error = document.querySelector(
|
|
166
|
+
'.dropin-incrementer__content--error-message'
|
|
167
|
+
) as HTMLElement;
|
|
168
|
+
|
|
169
|
+
await expect(error).toBeVisible();
|
|
170
|
+
await expect(error).toHaveTextContent('Maximum quantity is 100');
|
|
171
|
+
},
|
|
172
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* Copyright 2024 Adobe
|
|
3
|
+
* All Rights Reserved.
|
|
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.
|
|
8
|
+
*******************************************************************/
|
|
9
|
+
|
|
10
|
+
import { FunctionComponent } from 'preact';
|
|
11
|
+
import { useState, useCallback } from 'preact/hooks';
|
|
12
|
+
import { HTMLAttributes } from 'preact/compat';
|
|
13
|
+
import { classes, debounce } from '@adobe-commerce/elsie/lib';
|
|
14
|
+
import { Add, Minus } from '@adobe-commerce/elsie/icons';
|
|
15
|
+
import { Icon } from '@adobe-commerce/elsie/components/Icon';
|
|
16
|
+
import { Localizer, Text } from '@adobe-commerce/elsie/i18n';
|
|
17
|
+
import '@adobe-commerce/elsie/components/Incrementer/Incrementer.css';
|
|
18
|
+
|
|
19
|
+
export interface IncrementerProps
|
|
20
|
+
extends Omit<HTMLAttributes<HTMLInputElement>, 'size'> {
|
|
21
|
+
name?: string;
|
|
22
|
+
size?: 'medium' | 'large';
|
|
23
|
+
onValue?: (value: any) => void;
|
|
24
|
+
onUpdateError?: (error: Error) => void;
|
|
25
|
+
error?: boolean;
|
|
26
|
+
success?: boolean;
|
|
27
|
+
min?: number;
|
|
28
|
+
max?: number;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
maxLength?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const Incrementer: FunctionComponent<IncrementerProps> = ({
|
|
34
|
+
name,
|
|
35
|
+
value = '1',
|
|
36
|
+
className,
|
|
37
|
+
disabled,
|
|
38
|
+
error,
|
|
39
|
+
success,
|
|
40
|
+
min,
|
|
41
|
+
max,
|
|
42
|
+
onValue,
|
|
43
|
+
onUpdateError,
|
|
44
|
+
size = 'medium',
|
|
45
|
+
...props
|
|
46
|
+
}) => {
|
|
47
|
+
const [currentValue, setCurrentValue] = useState<number>(Number(value));
|
|
48
|
+
const minValue = Number(min);
|
|
49
|
+
const maxValue = Number(max);
|
|
50
|
+
const isInvalid = error || currentValue < minValue || currentValue > maxValue;
|
|
51
|
+
|
|
52
|
+
const errorMessage =
|
|
53
|
+
currentValue < minValue
|
|
54
|
+
? 'Dropin.Incrementer.minQuantityMessage'
|
|
55
|
+
: currentValue > maxValue
|
|
56
|
+
? 'Dropin.Incrementer.maxQuantityMessage'
|
|
57
|
+
: 'Dropin.Incrementer.errorMessage';
|
|
58
|
+
|
|
59
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
|
+
const debouncedOnValueHandler = useCallback(
|
|
61
|
+
debounce(async (newValue: any) => {
|
|
62
|
+
if (onValue) {
|
|
63
|
+
try {
|
|
64
|
+
onValue(newValue);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (onUpdateError) {
|
|
67
|
+
onUpdateError(e as Error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, 200),
|
|
72
|
+
[onValue, onUpdateError]
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const handleIncrementer = (_value: number) => {
|
|
76
|
+
let newValue = _value;
|
|
77
|
+
debouncedOnValueHandler(newValue);
|
|
78
|
+
setCurrentValue(newValue);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div
|
|
83
|
+
className={classes([
|
|
84
|
+
'dropin-incrementer',
|
|
85
|
+
`dropin-incrementer--${size}`,
|
|
86
|
+
className,
|
|
87
|
+
])}
|
|
88
|
+
>
|
|
89
|
+
<div
|
|
90
|
+
className={classes([
|
|
91
|
+
'dropin-incrementer__content',
|
|
92
|
+
`dropin-incrementer__content--${size}`,
|
|
93
|
+
[`dropin-incrementer__content--error`, isInvalid],
|
|
94
|
+
[`dropin-incrementer__content--success`, success],
|
|
95
|
+
[`dropin-incrementer__content--disabled`, disabled],
|
|
96
|
+
])}
|
|
97
|
+
>
|
|
98
|
+
{/* Minus Button */}
|
|
99
|
+
<div
|
|
100
|
+
className={classes([
|
|
101
|
+
'dropin-incrementer__button-container',
|
|
102
|
+
[`dropin-incrementer__button-container--disabled`, disabled],
|
|
103
|
+
])}
|
|
104
|
+
>
|
|
105
|
+
<Localizer>
|
|
106
|
+
<button
|
|
107
|
+
type="button"
|
|
108
|
+
className={classes([
|
|
109
|
+
'dropin-incrementer__decrease-button',
|
|
110
|
+
[`dropin-incrementer__decrease-button--disabled`, disabled],
|
|
111
|
+
])}
|
|
112
|
+
onClick={() => handleIncrementer(currentValue - 1)}
|
|
113
|
+
disabled={disabled || currentValue < minValue + 1}
|
|
114
|
+
aria-label={
|
|
115
|
+
(<Text id="Dropin.Incrementer.decreaseLabel" />) as any
|
|
116
|
+
}
|
|
117
|
+
>
|
|
118
|
+
<Icon
|
|
119
|
+
source={Minus}
|
|
120
|
+
size="16"
|
|
121
|
+
stroke="1"
|
|
122
|
+
viewBox="4 2 20 20"
|
|
123
|
+
className="dropin-incrementer__down"
|
|
124
|
+
/>
|
|
125
|
+
</button>
|
|
126
|
+
</Localizer>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
{/* Input Field */}
|
|
130
|
+
<input
|
|
131
|
+
className="dropin-incrementer__input"
|
|
132
|
+
max={max}
|
|
133
|
+
min={min}
|
|
134
|
+
step={1}
|
|
135
|
+
type="number"
|
|
136
|
+
name={name}
|
|
137
|
+
value={currentValue}
|
|
138
|
+
disabled={disabled}
|
|
139
|
+
onBlur={() => {
|
|
140
|
+
handleIncrementer(Number(currentValue));
|
|
141
|
+
}}
|
|
142
|
+
onChange={(e) => {
|
|
143
|
+
const newValue = e.currentTarget.value;
|
|
144
|
+
if (newValue !== '') {
|
|
145
|
+
handleIncrementer(Number(newValue));
|
|
146
|
+
}
|
|
147
|
+
}}
|
|
148
|
+
{...props}
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
<div
|
|
152
|
+
className={classes([
|
|
153
|
+
'dropin-incrementer__button-container',
|
|
154
|
+
[`dropin-incrementer__button-container--disabled`, disabled],
|
|
155
|
+
])}
|
|
156
|
+
>
|
|
157
|
+
{/* Plus/Add button */}
|
|
158
|
+
<Localizer>
|
|
159
|
+
<button
|
|
160
|
+
type="button"
|
|
161
|
+
className={classes([
|
|
162
|
+
'dropin-incrementer__increase-button',
|
|
163
|
+
[`dropin-incrementer__increase-button--disabled`, disabled],
|
|
164
|
+
])}
|
|
165
|
+
onClick={() => handleIncrementer(currentValue + 1)}
|
|
166
|
+
disabled={disabled || currentValue > maxValue - 1}
|
|
167
|
+
aria-label={
|
|
168
|
+
(<Text id="Dropin.Incrementer.increaseLabel" />) as any
|
|
169
|
+
}
|
|
170
|
+
>
|
|
171
|
+
<Icon
|
|
172
|
+
source={Add}
|
|
173
|
+
size="16"
|
|
174
|
+
stroke="1"
|
|
175
|
+
viewBox="4 2 20 20"
|
|
176
|
+
className="dropin-incrementer__add"
|
|
177
|
+
/>
|
|
178
|
+
</button>
|
|
179
|
+
</Localizer>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
{isInvalid && (
|
|
183
|
+
<p className="dropin-incrementer__content--error-message">
|
|
184
|
+
<Text
|
|
185
|
+
id={errorMessage}
|
|
186
|
+
fields={{ minQuantity: min, maxQuantity: max }}
|
|
187
|
+
/>
|
|
188
|
+
</p>
|
|
189
|
+
)}
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* Copyright 2024 Adobe
|
|
3
|
+
* All Rights Reserved.
|
|
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.
|
|
8
|
+
*******************************************************************/
|
|
9
|
+
|
|
10
|
+
export * from '@adobe-commerce/elsie/components/Incrementer/Incrementer';
|