@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,117 @@
|
|
|
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
|
+
|
|
13
|
+
import {
|
|
14
|
+
Pagination,
|
|
15
|
+
PaginationProps,
|
|
16
|
+
} from '@adobe-commerce/elsie/components/Pagination';
|
|
17
|
+
import { expect, userEvent, within } from '@storybook/test';
|
|
18
|
+
import { useState } from 'preact/hooks';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A component that divides large content sets into multiple pages, allowing users to navigate through the data with controls like "Next," "Previous," or page numbers, enhancing performance and usability by limiting the number of items displayed per page.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const meta: Meta<PaginationProps> = {
|
|
25
|
+
title: 'Components/Pagination',
|
|
26
|
+
component: Pagination,
|
|
27
|
+
argTypes: {
|
|
28
|
+
totalPages: {
|
|
29
|
+
control: { type: 'number' },
|
|
30
|
+
description: 'The total number of pages in the pagination component.',
|
|
31
|
+
defaultValue: 10,
|
|
32
|
+
},
|
|
33
|
+
currentPage: {
|
|
34
|
+
control: { type: 'number' },
|
|
35
|
+
description: 'The current active page in the pagination.',
|
|
36
|
+
defaultValue: 1,
|
|
37
|
+
},
|
|
38
|
+
onChange: {
|
|
39
|
+
action: 'pageChanged',
|
|
40
|
+
description:
|
|
41
|
+
'Called when the page number is changed, and it takes the resulting page number.',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default meta;
|
|
47
|
+
|
|
48
|
+
type Story = StoryObj<PaginationProps>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { Pagination } from '@adobe-commerce/elsie/components/Pagination';
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export const ShortPagination: Story = {
|
|
57
|
+
name: 'Short pagination list',
|
|
58
|
+
args: { totalPages: 5 },
|
|
59
|
+
play: async ({ canvasElement }) => {
|
|
60
|
+
const canvas = within(canvasElement);
|
|
61
|
+
|
|
62
|
+
const item1 = canvas.getByTestId('dropin-pagination_list-item--1');
|
|
63
|
+
const item2 = canvas.getByTestId('dropin-pagination_list-item--2');
|
|
64
|
+
const item5 = canvas.getByTestId('dropin-pagination_list-item--5');
|
|
65
|
+
const nextButton = canvas.getByTestId('next-button');
|
|
66
|
+
|
|
67
|
+
expect(item1).toHaveClass('dropin-pagination_list-item--active');
|
|
68
|
+
expect(item2).not.toHaveClass('dropin-pagination_list-item--active');
|
|
69
|
+
|
|
70
|
+
await userEvent.click(nextButton);
|
|
71
|
+
|
|
72
|
+
expect(item1).not.toHaveClass('dropin-pagination_list-item--active');
|
|
73
|
+
expect(item2).toHaveClass('dropin-pagination_list-item--active');
|
|
74
|
+
|
|
75
|
+
await userEvent.click(nextButton);
|
|
76
|
+
await userEvent.click(nextButton);
|
|
77
|
+
await userEvent.click(nextButton);
|
|
78
|
+
|
|
79
|
+
expect(item5).toHaveClass('dropin-pagination_list-item--active');
|
|
80
|
+
},
|
|
81
|
+
render: (args) => {
|
|
82
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
83
|
+
const totalPages = args.totalPages;
|
|
84
|
+
|
|
85
|
+
const handlePageChange = (newPage: number) => {
|
|
86
|
+
setCurrentPage(newPage);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Pagination
|
|
91
|
+
totalPages={totalPages}
|
|
92
|
+
currentPage={currentPage}
|
|
93
|
+
onChange={handlePageChange}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const LongPagination: Story = {
|
|
100
|
+
name: 'Long pagination list',
|
|
101
|
+
render: () => {
|
|
102
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
103
|
+
const totalPages = 20;
|
|
104
|
+
|
|
105
|
+
const handlePageChange = (newPage: number) => {
|
|
106
|
+
setCurrentPage(newPage);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Pagination
|
|
111
|
+
totalPages={totalPages}
|
|
112
|
+
currentPage={currentPage}
|
|
113
|
+
onChange={handlePageChange}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
},
|
|
117
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
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 { classes, isNumber } from '@adobe-commerce/elsie/lib';
|
|
12
|
+
import { useCallback, useMemo } from 'preact/hooks';
|
|
13
|
+
import { ChevronDown } from '@adobe-commerce/elsie/icons';
|
|
14
|
+
import { Icon } from '@adobe-commerce/elsie/components/Icon';
|
|
15
|
+
import { useText } from '@adobe-commerce/elsie/i18n';
|
|
16
|
+
import '@adobe-commerce/elsie/components/Pagination/Pagination.css';
|
|
17
|
+
|
|
18
|
+
export interface PaginationProps {
|
|
19
|
+
className?: string;
|
|
20
|
+
currentPage?: number;
|
|
21
|
+
totalPages?: number;
|
|
22
|
+
onChange?: (currentPage: number) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type PaginationList = {
|
|
26
|
+
page: number | string;
|
|
27
|
+
isActive: boolean;
|
|
28
|
+
label: number | string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Pagination: FunctionComponent<PaginationProps> = ({
|
|
32
|
+
totalPages = 10,
|
|
33
|
+
currentPage = 1,
|
|
34
|
+
onChange,
|
|
35
|
+
className,
|
|
36
|
+
...props
|
|
37
|
+
}) => {
|
|
38
|
+
const translations = useText({
|
|
39
|
+
backwardButton: 'Dropin.Pagination.backwardButton.ariaLabel',
|
|
40
|
+
forwardButton: 'Dropin.Pagination.forwardButton.ariaLabel',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const handleForward = useCallback(() => {
|
|
44
|
+
const nextPage = Math.min(currentPage + 1, totalPages);
|
|
45
|
+
|
|
46
|
+
onChange?.(nextPage);
|
|
47
|
+
}, [currentPage, onChange, totalPages]);
|
|
48
|
+
|
|
49
|
+
const handleBackward = useCallback(() => {
|
|
50
|
+
const prevPage = Math.max(currentPage - 1, 1);
|
|
51
|
+
|
|
52
|
+
onChange?.(prevPage);
|
|
53
|
+
}, [currentPage, onChange]);
|
|
54
|
+
|
|
55
|
+
const handleSetPage = useCallback(
|
|
56
|
+
(currentPage: number | string) => {
|
|
57
|
+
if (isNumber(currentPage)) {
|
|
58
|
+
onChange?.(currentPage as number);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
[onChange]
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const createPages = useCallback(
|
|
65
|
+
(currentPage: number, totalPages: number): PaginationList[] => {
|
|
66
|
+
let pages: PaginationList[] = [];
|
|
67
|
+
|
|
68
|
+
const addPageRange = (start: number, end: number) => {
|
|
69
|
+
for (let i = start; i <= end; i++) {
|
|
70
|
+
pages.push({ page: i, isActive: i === currentPage, label: i });
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (totalPages <= 5) {
|
|
75
|
+
addPageRange(1, totalPages);
|
|
76
|
+
} else if (currentPage <= 2) {
|
|
77
|
+
addPageRange(1, 2);
|
|
78
|
+
pages.push({ page: 'ellipsis', isActive: false, label: '...' });
|
|
79
|
+
addPageRange(totalPages - 1, totalPages);
|
|
80
|
+
} else if (currentPage >= totalPages - 3) {
|
|
81
|
+
addPageRange(totalPages - 4, totalPages);
|
|
82
|
+
} else {
|
|
83
|
+
addPageRange(currentPage - 1, currentPage);
|
|
84
|
+
pages.push({ page: 'ellipsis', isActive: false, label: '...' });
|
|
85
|
+
addPageRange(totalPages - 1, totalPages);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return pages;
|
|
89
|
+
},
|
|
90
|
+
[]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const paginationList: PaginationList[] = useMemo(
|
|
94
|
+
() => createPages(currentPage, totalPages),
|
|
95
|
+
[createPages, currentPage, totalPages]
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<div {...props} className={classes(['dropin-pagination', className])}>
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
data-testid="prev-button"
|
|
103
|
+
aria-label={translations.backwardButton}
|
|
104
|
+
disabled={currentPage === 1}
|
|
105
|
+
onClick={handleBackward}
|
|
106
|
+
className={classes([
|
|
107
|
+
'dropin-pagination-arrow',
|
|
108
|
+
'dropin-pagination-arrow--backward',
|
|
109
|
+
])}
|
|
110
|
+
>
|
|
111
|
+
<Icon size="24" source={ChevronDown} />
|
|
112
|
+
</button>
|
|
113
|
+
<ul className="dropin-pagination_list">
|
|
114
|
+
{(paginationList as PaginationList[]).map((item, index) => (
|
|
115
|
+
<li
|
|
116
|
+
data-testid={`dropin-pagination_list-item--${item.page}`}
|
|
117
|
+
key={`${item.page}_${index}`}
|
|
118
|
+
className={classes([
|
|
119
|
+
'dropin-pagination_list-item',
|
|
120
|
+
`dropin-pagination_list-item--${item.page}`,
|
|
121
|
+
[`dropin-pagination_list-item--active`, item.isActive],
|
|
122
|
+
])}
|
|
123
|
+
>
|
|
124
|
+
<button
|
|
125
|
+
type="button"
|
|
126
|
+
data-testid={`set-page-button-${item.page}`}
|
|
127
|
+
onClick={() => handleSetPage(item.page)}
|
|
128
|
+
>
|
|
129
|
+
{item.label}
|
|
130
|
+
</button>
|
|
131
|
+
</li>
|
|
132
|
+
))}
|
|
133
|
+
</ul>
|
|
134
|
+
<button
|
|
135
|
+
type="button"
|
|
136
|
+
data-testid="next-button"
|
|
137
|
+
aria-label={translations.forwardButton}
|
|
138
|
+
disabled={currentPage === totalPages}
|
|
139
|
+
onClick={handleForward}
|
|
140
|
+
className={classes([
|
|
141
|
+
'dropin-pagination-arrow',
|
|
142
|
+
'dropin-pagination-arrow--forward',
|
|
143
|
+
])}
|
|
144
|
+
>
|
|
145
|
+
<Icon size="24" source={ChevronDown} />
|
|
146
|
+
</button>
|
|
147
|
+
</div>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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/Pagination/Pagination';
|
|
11
|
+
export { Pagination as default } from '@adobe-commerce/elsie/components/Pagination/Pagination';
|
|
@@ -0,0 +1,220 @@
|
|
|
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
|
+
.dropin-picker {
|
|
12
|
+
position: relative;
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
background-color: var(--color-neutral-50);
|
|
16
|
+
justify-content: space-between;
|
|
17
|
+
align-items: center;
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
gap: var(--spacing-small);
|
|
20
|
+
text-overflow: ellipsis;
|
|
21
|
+
white-space: nowrap;
|
|
22
|
+
overflow: hidden;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.dropin-picker select {
|
|
26
|
+
background-color: transparent;
|
|
27
|
+
border: var(--shape-border-width-1) solid var(--color-neutral-600);
|
|
28
|
+
border-radius: var(--shape-border-radius-1);
|
|
29
|
+
color: var(--color-neutral-700);
|
|
30
|
+
appearance: none;
|
|
31
|
+
box-shadow: none;
|
|
32
|
+
flex: 1;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
width: 100%;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
white-space: nowrap;
|
|
37
|
+
text-overflow: ellipsis;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.dropin-picker__select:focus {
|
|
41
|
+
outline: none;
|
|
42
|
+
border: var(--shape-border-width-1) solid var(--color-neutral-800);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Resulting height of 40px for medium size, 48px for large size */
|
|
46
|
+
.dropin-picker__medium .dropin-picker__select--primary,
|
|
47
|
+
.dropin-picker__medium .dropin-picker__select--secondary {
|
|
48
|
+
padding: 9px var(--spacing-xxbig) 9px var(--spacing-small);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.dropin-picker__large .dropin-picker__select--primary,
|
|
52
|
+
.dropin-picker__large .dropin-picker__select--secondary {
|
|
53
|
+
padding: 11px var(--spacing-xxbig) 11px var(--spacing-small);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.dropin-picker__select--medium {
|
|
57
|
+
font: var(--type-body-2-default-font);
|
|
58
|
+
letter-spacing: var(--type-body-2-default-letter-spacing);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.dropin-picker__select--large {
|
|
62
|
+
font: var(--type-body-1-default-font);
|
|
63
|
+
letter-spacing: var(--type-body-1-default-letter-spacing);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* Chevron */
|
|
67
|
+
.dropin-picker__chevronDown {
|
|
68
|
+
z-index: 1;
|
|
69
|
+
position: absolute;
|
|
70
|
+
color: var(--color-neutral-700);
|
|
71
|
+
right: var(--spacing-small);
|
|
72
|
+
display: block;
|
|
73
|
+
pointer-events: none;
|
|
74
|
+
padding: 0;
|
|
75
|
+
height: var(--icon-size);
|
|
76
|
+
width: var(--icon-size);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Floating label */
|
|
80
|
+
.dropin-picker__floatingLabel {
|
|
81
|
+
position: absolute;
|
|
82
|
+
pointer-events: none;
|
|
83
|
+
left: var(--spacing-small);
|
|
84
|
+
color: var(--color-neutral-700);
|
|
85
|
+
touch-action: manipulation;
|
|
86
|
+
transform: translateY(-50%);
|
|
87
|
+
transition: top 20ms ease-in, font-size 50ms ease-in;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.dropin-picker__select--floating:focus ~ label {
|
|
91
|
+
transition: all 40ms;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* Option selected */
|
|
95
|
+
.dropin-picker__selected select {
|
|
96
|
+
color: var(--color-neutral-800);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* Label position when option selected */
|
|
100
|
+
.dropin-picker__selected label {
|
|
101
|
+
top: 30%;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Label font when option selected */
|
|
105
|
+
.dropin-picker__medium.dropin-picker__floating.dropin-picker__selected label {
|
|
106
|
+
font: var(--type-details-caption-1-font);
|
|
107
|
+
letter-spacing: var(--type-details-caption-1-letter-spacing);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.dropin-picker__large.dropin-picker__floating.dropin-picker__selected label {
|
|
111
|
+
font: var(--type-details-caption-2-font);
|
|
112
|
+
letter-spacing: var(--type-details-caption-2-letter-spacing);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Resulting height of 56px no matter medium or large size */
|
|
116
|
+
.dropin-picker__medium.dropin-picker__floating select {
|
|
117
|
+
padding: 17px var(--spacing-small);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.dropin-picker__large.dropin-picker__floating select {
|
|
121
|
+
padding: 15px var(--spacing-small);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Resulting height of 56px when option selected */
|
|
125
|
+
.dropin-picker__large.dropin-picker__floating.dropin-picker__selected select {
|
|
126
|
+
padding: 25px var(--spacing-xxbig) 5px var(--spacing-small);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.dropin-picker__medium.dropin-picker__floating.dropin-picker__selected select {
|
|
130
|
+
padding: 27px var(--spacing-xxbig) 7px var(--spacing-small);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* Remove IE arrow */
|
|
134
|
+
select::-ms-expand {
|
|
135
|
+
display: none;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* Disabled */
|
|
139
|
+
.dropin-picker__disabled select.dropin-picker__select {
|
|
140
|
+
background-color: var(--color-neutral-300);
|
|
141
|
+
border: var(--shape-border-width-1) solid var(--color-neutral-500);
|
|
142
|
+
color: var(--color-neutral-500);
|
|
143
|
+
cursor: not-allowed;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.dropin-picker__disabled svg.dropin-picker__chevronDown {
|
|
147
|
+
color: var(--color-neutral-500);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* Error */
|
|
151
|
+
.dropin-picker__error select {
|
|
152
|
+
border: var(--shape-border-width-2) solid var(--color-alert-500);
|
|
153
|
+
color: var(--color-alert-500);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.dropin-picker__error .dropin-picker__select:focus {
|
|
157
|
+
border: var(--shape-border-width-2) solid var(--color-alert-500);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.dropin-picker__error .dropin-picker__chevronDown {
|
|
161
|
+
color: var(--color-alert-500);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.dropin-picker__error label {
|
|
165
|
+
color: var(--color-alert-500);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Secondary variant */
|
|
169
|
+
.dropin-picker select.dropin-picker__select--secondary {
|
|
170
|
+
border-top: var(--shape-border-width-1) solid transparent;
|
|
171
|
+
border-left: 0 none;
|
|
172
|
+
border-right: 0 none;
|
|
173
|
+
border-radius: 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.dropin-picker__disabled select.dropin-picker__select--secondary {
|
|
177
|
+
border-bottom: var(--shape-border-width-1) solid var(--color-neutral-500);
|
|
178
|
+
}
|
|
179
|
+
.dropin-picker__error select.dropin-picker__select--secondary {
|
|
180
|
+
border-top: var(--shape-border-width-1) solid transparent;
|
|
181
|
+
border-left: 0 none;
|
|
182
|
+
border-right: 0 none;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* Icon */
|
|
186
|
+
.dropin-picker__icon--placeholder {
|
|
187
|
+
z-index: 1;
|
|
188
|
+
position: absolute;
|
|
189
|
+
color: var(--color-neutral-700);
|
|
190
|
+
left: var(--spacing-small);
|
|
191
|
+
display: block;
|
|
192
|
+
pointer-events: none;
|
|
193
|
+
padding: 0;
|
|
194
|
+
height: var(--icon-size);
|
|
195
|
+
width: var(--icon-size);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.dropin-picker__icon select.dropin-picker__select {
|
|
199
|
+
padding-left: var(--spacing-xxbig);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.dropin-picker__floating.dropin-picker__selected.dropin-picker__icon select {
|
|
203
|
+
padding-left: var(--spacing-xxbig);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.dropin-picker__floating.dropin-picker__selected.dropin-picker__icon label {
|
|
207
|
+
left: var(--spacing-xxbig);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* Medium (portrait tablets and large phones, 768px and up) */
|
|
211
|
+
/* @media only screen and (min-width: 768px) { } */
|
|
212
|
+
|
|
213
|
+
/* Large (landscape tablets, 1024px and up) */
|
|
214
|
+
/* @media only screen and (min-width: 1024px) { } */
|
|
215
|
+
|
|
216
|
+
/* XLarge (laptops/desktops, 1366px and up) */
|
|
217
|
+
/* @media only screen and (min-width: 1366px) { } */
|
|
218
|
+
|
|
219
|
+
/* XXlarge (large laptops and desktops, 1920px and up) */
|
|
220
|
+
/* @media only screen and (min-width: 1920px) { } */
|