@nuskin/foundation-ui-components 1.0.0-cft-35.13 → 1.0.0-develop.10
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/package.json +21 -11
- package/src/common/accordion/NsAccordion.tsx +69 -0
- package/src/common/accordion/NsAccordionHeader.tsx +77 -0
- package/src/common/accordion/NsAccordionItem.tsx +59 -0
- package/src/common/accordion/NsCollapse.tsx +110 -0
- package/src/common/accordion/NsToggleSection.tsx +43 -0
- package/src/common/accordion/ToggleSection.styled.tsx +32 -0
- package/src/common/accordion/colorMap.ts +117 -0
- package/src/common/accordion/enums.ts +8 -0
- package/src/common/accordion/index.ts +7 -0
- package/src/common/accordion/specs/NsAccordion.spec.tsx +163 -0
- package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +130 -0
- package/src/common/accordion/specs/NsAccordionItem.spec.tsx +79 -0
- package/src/common/accordion/specs/NsCollapse.spec.tsx +129 -0
- package/src/common/accordion/specs/NsToggleSection.spec.tsx +74 -0
- package/src/common/accordion/stories/NsAccordion.stories.tsx +65 -0
- package/src/common/accordion/stories/NsAccordionHeader.stories.tsx +44 -0
- package/src/common/accordion/stories/NsAccordionItem.stories.tsx +45 -0
- package/src/common/accordion/stories/NsCollapse.stories.tsx +50 -0
- package/src/common/accordion/stories/NsToggleSection.stories.tsx +26 -0
- package/src/common/accordion/stories/data.tsx +143 -0
- package/src/common/accordion/types.d.ts +81 -0
- package/src/common/alert/Header.tsx +29 -0
- package/src/common/alert/NsAlert.spec.tsx +62 -29
- package/src/common/alert/NsAlert.stories.tsx +18 -17
- package/src/common/alert/NsAlert.styled.tsx +124 -0
- package/src/common/alert/NsAlert.tsx +27 -110
- package/src/common/alert/index.ts +2 -2
- package/src/common/alert/types.d.ts +23 -23
- package/src/common/auth-dropdown/NsAuthDropdown.spec.tsx +24 -6
- package/src/common/auth-dropdown/NsAuthDropdown.stories.tsx +2 -2
- package/src/common/auth-dropdown/NsAuthDropdown.styled.ts +21 -16
- package/src/common/auth-dropdown/NsAuthDropdown.tsx +7 -6
- package/src/common/auth-dropdown/index.ts +1 -1
- package/src/common/auth-dropdown/types.d.ts +3 -1
- package/src/common/autocomplete/NsAutocomplete.spec.tsx +69 -24
- package/src/common/autocomplete/NsAutocomplete.stories.tsx +64 -7
- package/src/common/autocomplete/NsAutocomplete.styled.tsx +12 -0
- package/src/common/autocomplete/NsAutocomplete.tsx +100 -46
- package/src/common/autocomplete/index.ts +2 -1
- package/src/common/autocomplete/mock/MockData.ts +50 -7
- package/src/common/autocomplete/mock/MockUI.tsx +2 -1
- package/src/common/autocomplete/{types.ts → types.d.ts} +18 -8
- package/src/common/banner/NsBanner.spec.tsx +13 -4
- package/src/common/banner/NsBanner.stories.tsx +2 -2
- package/src/common/banner/NsBanner.styled.tsx +1 -1
- package/src/common/banner/NsBanner.tsx +1 -1
- package/src/common/banner/index.ts +1 -1
- package/src/common/brand-components/NsBrand.stories.tsx +2 -2
- package/src/common/brand-components/NsBrandComponent.tsx +6 -3
- package/src/common/brand-components/index.ts +1 -1
- package/src/common/breadcrumb/NsBreadcrumb.spec.tsx +8 -9
- package/src/common/breadcrumb/NsBreadcrumb.stories.tsx +3 -5
- package/src/common/breadcrumb/NsBreadcrumb.tsx +5 -3
- package/src/common/breadcrumb/data.ts +10 -0
- package/src/common/breadcrumb/index.ts +1 -1
- package/src/common/button/NsButton.spec.tsx +66 -51
- package/src/common/button/NsButton.stories.tsx +61 -4
- package/src/common/button/NsButton.styled.tsx +54 -72
- package/src/common/button/NsButton.tsx +9 -3
- package/src/common/button/helper.ts +82 -0
- package/src/common/button/index.ts +1 -1
- package/src/common/button/types.d.ts +3 -0
- package/src/common/card/NsFfgCard.tsx +14 -8
- package/src/common/card/specs/NsFfgCard.spec.tsx +33 -0
- package/src/common/card/stories/NsBgCard.stories.tsx +2 -4
- package/src/common/card/stories/NsBrandProductCard.stories.tsx +2 -2
- package/src/common/card/stories/NsFfgCard.stories.tsx +49 -16
- package/src/common/card/stories/{data.js → data.ts} +1 -25
- package/src/common/card/styled/NsFfgStyled.tsx +9 -7
- package/src/common/card/types.d.ts +7 -4
- package/src/common/carousal/NsScrollingCarousal.tsx +61 -0
- package/src/common/carousal/index.ts +3 -0
- package/src/common/carousal/{tests → specs}/NsCarousal.spec.tsx +2 -2
- package/src/common/carousal/specs/NsScrollingCarousal.spec.tsx +61 -0
- package/src/common/carousal/stories/NSCarousal.stories.tsx +2 -2
- package/src/common/carousal/stories/NsScrollingCarousal.stories.tsx +52 -0
- package/src/common/carousal/types.d.ts +23 -0
- package/src/common/cart-icon/NsCartIcon.spec.tsx +1 -1
- package/src/common/cart-icon/NsCartIcon.stories.tsx +2 -2
- package/src/common/cart-icon/NsCartIcon.tsx +1 -1
- package/src/common/cart-icon/index.ts +1 -1
- package/src/common/checkbox/NsCheckbox.spec.tsx +2 -2
- package/src/common/checkbox/NsCheckbox.stories.tsx +2 -2
- package/src/common/checkbox/NsCheckbox.styled.tsx +15 -16
- package/src/common/checkbox/NsCheckbox.tsx +2 -2
- package/src/common/checkbox/index.ts +1 -1
- package/src/common/checkbox/types.d.ts +1 -7
- package/src/common/column-control/NsColumnControl.tsx +1 -1
- package/src/common/column-control/NsFlexColumns.tsx +22 -0
- package/src/common/column-control/NsGridColumns.tsx +22 -0
- package/src/common/column-control/index.ts +3 -1
- package/src/common/column-control/{NsColumnControl.spec.tsx → specs/NsColumnControl.spec.tsx} +3 -3
- package/src/common/column-control/specs/NsFlexColumns.spec.tsx +24 -0
- package/src/common/column-control/specs/NsGridColumns.spec.tsx +24 -0
- package/src/common/column-control/stories/DivArray.stories.tsx +18 -0
- package/src/common/column-control/stories/DivArray.tsx +63 -0
- package/src/common/column-control/{NsColumnControl.stories.tsx → stories/NsColumnControl.stories.tsx} +9 -16
- package/src/common/column-control/stories/NsFlexColumns.stories.tsx +63 -0
- package/src/common/column-control/stories/NsGridColumns.stories.tsx +63 -0
- package/src/common/column-control/stories/common.tsx +14 -0
- package/src/common/column-control/styled/StyledFlex.tsx +45 -0
- package/src/common/column-control/styled/StyledGrid.tsx +40 -0
- package/src/common/column-control/styled/common.ts +27 -0
- package/src/common/column-control/types.d.ts +15 -16
- package/src/common/column-control/utils.ts +5 -5
- package/src/common/common.types.d.ts +21 -0
- package/src/common/dropdown/NsDropdown.spec.tsx +1 -1
- package/src/common/dropdown/NsDropdown.styled.tsx +23 -18
- package/src/common/dropdown/NsDropdown.tsx +1 -1
- package/src/common/dropdown/NsDropdownOption.tsx +1 -1
- package/src/common/dropdown/index.ts +1 -1
- package/src/common/dropdown/stories/NsDropdown.stories.tsx +2 -2
- package/src/common/dropdown/stories/NsDropdownCountry.stories.tsx +2 -2
- package/src/common/dropdown/types.d.ts +3 -1
- package/src/common/email-simple/NsEmailSimple.spec.tsx +145 -0
- package/src/common/email-simple/NsEmailSimple.stories.tsx +61 -0
- package/src/common/email-simple/NsEmailSimple.tsx +71 -0
- package/src/common/email-simple/index.ts +2 -0
- package/src/common/email-simple/types.d.ts +14 -0
- package/src/common/flag/NsFlag.spec.tsx +5 -25
- package/src/common/flag/NsFlag.stories.tsx +2 -2
- package/src/common/flag/NsFlag.styled.tsx +7 -9
- package/src/common/flag/NsFlag.tsx +1 -3
- package/src/common/flag/index.ts +1 -1
- package/src/common/flag/types.d.ts +0 -2
- package/src/common/hooks/index.ts +2 -0
- package/src/common/hooks/specs/useWindowSize.spec.tsx +19 -0
- package/src/common/hooks/useAccordionMap.tsx +39 -0
- package/src/common/hooks/useWindowSize.tsx +30 -0
- package/src/common/icon/NsIcon.spec.tsx +1 -1
- package/src/common/icon/NsIcon.stories.tsx +2 -2
- package/src/common/icon/NsIcon.styled.tsx +1 -1
- package/src/common/icon/NsIcon.tsx +1 -1
- package/src/common/icon/NsIconVariants.ts +9 -4
- package/src/common/icon/icons/AlertErrorIcon.tsx +15 -6
- package/src/common/icon/icons/HamburgerIcon.tsx +29 -0
- package/src/common/icon/icons/UserIcon.tsx +30 -0
- package/src/common/icon/icons/WarningIcon.tsx +14 -5
- package/src/common/icon/index.ts +1 -1
- package/src/common/icon/types.d.ts +1 -0
- package/src/common/image/NsImage.spec.tsx +57 -7
- package/src/common/image/NsImage.stories.tsx +2 -2
- package/src/common/image/NsImage.tsx +24 -12
- package/src/common/image/NsNextImage.spec.tsx +1 -1
- package/src/common/image/NsNextImage.stories.tsx +2 -2
- package/src/common/image/NsNextImage.tsx +1 -1
- package/src/common/image/index.ts +1 -1
- package/src/common/image/types.d.ts +1 -0
- package/src/common/index.ts +14 -10
- package/src/common/input/InputFieldWrapper.tsx +4 -4
- package/src/common/input/InputWrapper.tsx +12 -7
- package/src/common/input/NsInputField.stories.tsx +13 -10
- package/src/common/input/NsInputField.tsx +13 -6
- package/src/common/input/getAdornmentProps.tsx +5 -1
- package/src/common/input/index.ts +1 -1
- package/src/common/input/types.d.ts +18 -1
- package/src/common/label/NsLabel.stories.tsx +6 -1
- package/src/common/label/NsLabel.tsx +21 -20
- package/src/common/label/index.ts +1 -1
- package/src/common/label/types.d.ts +2 -1
- package/src/common/link/NsLink.spec.tsx +1 -1
- package/src/common/link/NsLink.stories.tsx +2 -2
- package/src/common/link/NsLink.tsx +1 -1
- package/src/common/link/index.ts +1 -1
- package/src/common/modal/NsModal.spec.tsx +46 -0
- package/src/common/modal/NsModal.styled.tsx +28 -0
- package/src/common/modal/NsModal.tsx +37 -0
- package/src/common/modal/helper-component/NsModalContentBox.tsx +32 -0
- package/src/common/modal/helper-component/NsModalDefault.tsx +25 -0
- package/src/common/modal/helper-component/NsModalStatus.tsx +15 -0
- package/src/common/modal/helper-component/NsModalStatusIcon.tsx +14 -0
- package/src/common/modal/helper-component/NsModalTitle.tsx +26 -0
- package/src/common/modal/index.ts +2 -0
- package/src/common/modal/model/NsModalVariantMap.tsx +24 -0
- package/src/common/modal/stories/NsModal.stories.tsx +86 -0
- package/src/common/modal/stories/mock.tsx +46 -0
- package/src/common/modal/types.ts +56 -0
- package/src/common/nav-product-card/NsNavProductCard.spec.tsx +1 -1
- package/src/common/nav-product-card/NsNavProductCard.stories.tsx +2 -2
- package/src/common/nav-product-card/NsNavProductCard.tsx +1 -1
- package/src/common/nav-product-card/index.ts +1 -1
- package/src/common/nav-tab/NsNavTab.spec.tsx +2 -7
- package/src/common/nav-tab/NsNavTab.stories.tsx +2 -2
- package/src/common/nav-tab/NsNavTab.styled.tsx +7 -4
- package/src/common/nav-tab/NsNavTab.tsx +1 -1
- package/src/common/nav-tab/index.ts +1 -1
- package/src/common/nav-tab/types.d.ts +2 -2
- package/src/common/radiogroup/NsRadioGroup.spec.tsx +63 -0
- package/src/common/radiogroup/NsRadioGroup.stories.tsx +84 -0
- package/src/common/radiogroup/NsRadioGroup.styled.tsx +52 -0
- package/src/common/radiogroup/NsRadioGroup.tsx +62 -0
- package/src/common/radiogroup/index.ts +2 -0
- package/src/common/radiogroup/types.d.ts +20 -0
- package/src/common/search-bar/NsSeachBar.spec.tsx +1 -1
- package/src/common/search-bar/NsSearchBar.tsx +1 -3
- package/src/common/select/NsSelect.spec.tsx +193 -0
- package/src/common/select/NsSelect.styled.tsx +104 -0
- package/src/common/select/NsSelect.tsx +117 -0
- package/src/common/select/NsSelectOption.tsx +30 -0
- package/src/common/select/index.ts +3 -0
- package/src/common/select/stories/NsSelect.stories.tsx +134 -0
- package/src/common/select/types.d.ts +34 -0
- package/src/common/spinner/NsSpinner.spec.tsx +21 -0
- package/src/common/spinner/NsSpinner.stories.tsx +26 -0
- package/src/common/spinner/NsSpinner.styled.tsx +344 -0
- package/src/common/spinner/NsSpinner.tsx +14 -0
- package/src/common/spinner/icons/Spinner.tsx +161 -0
- package/src/common/spinner/index.ts +2 -0
- package/src/common/spinner/types.ts +5 -0
- package/src/common/table/NsExpandableRow.tsx +68 -0
- package/src/common/table/NsTable.spec.tsx +174 -0
- package/src/common/table/NsTable.stories.tsx +161 -0
- package/src/common/table/NsTable.styled.ts +127 -0
- package/src/common/table/NsTable.tsx +133 -0
- package/src/common/table/NsTableHeader.tsx +41 -0
- package/src/common/table/NsTablePagination.tsx +28 -0
- package/src/common/table/helper.ts +33 -0
- package/src/common/table/index.ts +2 -0
- package/src/common/table/types.d.ts +57 -0
- package/src/common/text-strip/NsTextStrip.spec.tsx +30 -0
- package/src/common/text-strip/NsTextStrip.stories.tsx +33 -0
- package/src/common/text-strip/NsTextStrip.tsx +47 -0
- package/src/common/text-strip/index.ts +2 -0
- package/src/common/text-strip/types.d.ts +17 -0
- package/src/common/typography/NsTypography.stories.tsx +2 -2
- package/src/common/typography/NsTypography.tsx +1 -1
- package/src/common/typography/Typography.styled.tsx +4 -4
- package/src/common/typography/index.ts +1 -1
- package/src/common/util.ts +1 -0
- package/src/common/utility/Show.tsx +13 -0
- package/src/common/utility/index.ts +1 -0
- package/src/common/validations/regex.ts +3 -0
- package/src/common/videos/NsVideo.stories.tsx +2 -2
- package/src/common/videos/NsVideo.tsx +1 -1
- package/src/common/videos/index.ts +1 -1
- package/src/common/videos/types.d.ts +1 -1
- package/src/common/alert/NsAlert.styled.ts +0 -124
- package/src/common/card/tests/NsFfgCard.spec.tsx +0 -23
- package/src/common/column-control/NDivs.story.tsx +0 -35
- package/src/common/common.types.ts +0 -10
- /package/src/common/brand-components/{NsBrandContanier.styled.tsx → NsBrandContainer.styled.tsx} +0 -0
- /package/src/common/card/{tests → specs}/BrandLogo.spec.tsx +0 -0
- /package/src/common/card/{tests → specs}/NsBgCard.spec.tsx +0 -0
- /package/src/common/card/{tests → specs}/NsBrandProductCard.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/Chevron.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/RenderBrand.spec.tsx +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
+
import { AccordionVariant, NsAccordionItem } from '../../';
|
|
4
|
+
import NsAccordionStory from './NsAccordion.stories';
|
|
5
|
+
|
|
6
|
+
type ComponentType = typeof NsAccordionItem;
|
|
7
|
+
type Story = StoryObj<ComponentType>;
|
|
8
|
+
type MetaStory = Meta<ComponentType>;
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Components/Containers/Accordion/NsAccordionItem',
|
|
12
|
+
component: NsAccordionItem,
|
|
13
|
+
decorators: [withCenterDecorator],
|
|
14
|
+
argTypes: {
|
|
15
|
+
isOpen: {
|
|
16
|
+
control: 'boolean',
|
|
17
|
+
description: 'if true renders NsAccordionItem in open state, and close state otherwise',
|
|
18
|
+
},
|
|
19
|
+
content: {},
|
|
20
|
+
title: {
|
|
21
|
+
control: 'string',
|
|
22
|
+
description: 'text used for header of section',
|
|
23
|
+
},
|
|
24
|
+
level: NsAccordionStory.argTypes.level,
|
|
25
|
+
variant: NsAccordionStory.argTypes.variant,
|
|
26
|
+
},
|
|
27
|
+
} as MetaStory;
|
|
28
|
+
|
|
29
|
+
export const OpenSection: Story = {
|
|
30
|
+
args: {
|
|
31
|
+
variant: AccordionVariant.Compact,
|
|
32
|
+
isOpen: true,
|
|
33
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
34
|
+
title: 'Nuskin',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const ClosedSection: Story = {
|
|
39
|
+
args: {
|
|
40
|
+
variant: AccordionVariant.Compact,
|
|
41
|
+
isOpen: false,
|
|
42
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
43
|
+
title: 'Nuskin',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
+
import { AccordionVariant, NsCollapse } from '../';
|
|
4
|
+
import NsAccordionStory from './NsAccordion.stories';
|
|
5
|
+
|
|
6
|
+
type ComponentType = typeof NsCollapse;
|
|
7
|
+
type Story = StoryObj<ComponentType>;
|
|
8
|
+
type MetaStory = Meta<ComponentType>;
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Components/Containers/Accordion/NsCollapse',
|
|
12
|
+
component: NsCollapse,
|
|
13
|
+
decorators: [withCenterDecorator],
|
|
14
|
+
argTypes: {
|
|
15
|
+
isOpen: {
|
|
16
|
+
control: 'boolean',
|
|
17
|
+
description: 'if true renders NsCollapse in open state, and close state otherwise',
|
|
18
|
+
},
|
|
19
|
+
content: {
|
|
20
|
+
control: 'React Node',
|
|
21
|
+
description: 'Content for NsCollapse',
|
|
22
|
+
},
|
|
23
|
+
allowMultipleExpanded: {
|
|
24
|
+
control: 'boolean',
|
|
25
|
+
description: 'This prop is useful when content is an array of accordion items',
|
|
26
|
+
},
|
|
27
|
+
type: {
|
|
28
|
+
control: 'select',
|
|
29
|
+
values: ['jsx', 'html', 'text', 'accordion'],
|
|
30
|
+
description: 'This type should exactly match the content type to have accordion work correctly',
|
|
31
|
+
},
|
|
32
|
+
level: NsAccordionStory.argTypes.level,
|
|
33
|
+
variant: NsAccordionStory.argTypes.variant,
|
|
34
|
+
},
|
|
35
|
+
args: {
|
|
36
|
+
variant: AccordionVariant.Compact,
|
|
37
|
+
},
|
|
38
|
+
} as MetaStory;
|
|
39
|
+
export const Closed: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
isOpen: false,
|
|
42
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
export const Open: Story = {
|
|
46
|
+
args: {
|
|
47
|
+
isOpen: true,
|
|
48
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
+
import { AccordionVariant, NsToggleSection } from '../..';
|
|
4
|
+
import NsAccordionStory from './NsAccordion.stories';
|
|
5
|
+
|
|
6
|
+
type ComponentType = typeof NsToggleSection;
|
|
7
|
+
type Story = StoryObj<ComponentType>;
|
|
8
|
+
type MetaStory = Meta<ComponentType>;
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Components/Containers/Accordion/NsToggleSection',
|
|
12
|
+
component: NsToggleSection,
|
|
13
|
+
decorators: [withCenterDecorator],
|
|
14
|
+
argTypes: {
|
|
15
|
+
level: NsAccordionStory.argTypes.level,
|
|
16
|
+
variant: NsAccordionStory.argTypes.variant,
|
|
17
|
+
title: { control: 'string' },
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
variant: AccordionVariant.Compact,
|
|
21
|
+
title: 'Nuskin',
|
|
22
|
+
content: <div className="p-2">Nuskin Details</div>,
|
|
23
|
+
},
|
|
24
|
+
} as MetaStory;
|
|
25
|
+
|
|
26
|
+
export const DefaultAccordion: Story = {};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { NsIconProps } from '../..';
|
|
2
|
+
import { AccordionItem } from '../types';
|
|
3
|
+
|
|
4
|
+
const getItem = () => {
|
|
5
|
+
return {
|
|
6
|
+
id: parseInt(Math.random() * 10000000 + '') + '',
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
const getIcon = (name = '', color = '') => {
|
|
10
|
+
return {
|
|
11
|
+
name: (name || 'home') as NsIconProps['name'],
|
|
12
|
+
color: (color || 'primary') as NsIconProps['color'],
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export const getTextContent = (text = '') => {
|
|
16
|
+
return {
|
|
17
|
+
type: 'text' as AccordionItem['type'],
|
|
18
|
+
content: text || dummyText,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
const getJsxContent = (text = '') => {
|
|
22
|
+
return <div className="p-4">{text || 'Content type can be jsx, text, html or Accordion'}</div>;
|
|
23
|
+
};
|
|
24
|
+
export const dummyText = `1. Theme can be set to either ‘gray’ or ‘stripe’, adjusting only the appearance of
|
|
25
|
+
the topmost set of accordions.\n
|
|
26
|
+
2. Accordions can be nested repeatedly, internal accordions follow the ‘gray’ theme.\n
|
|
27
|
+
3. Color can be inverted by setting boolean ‘invert’ attribute. This inversion affects all levels of the accordion.\n
|
|
28
|
+
4. Per level offset of accordion can be changed by setting the level attribute.\n
|
|
29
|
+
Defaults to 1 which is zero offset - all level titles appear stacked directly over each other.`;
|
|
30
|
+
function createAccordionItem1(): AccordionItem {
|
|
31
|
+
return {
|
|
32
|
+
...getItem(),
|
|
33
|
+
icon: getIcon(),
|
|
34
|
+
title: 'Example - 1 JSX',
|
|
35
|
+
content: getJsxContent(),
|
|
36
|
+
type: 'jsx',
|
|
37
|
+
isDefaultOpen: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function createAccordionItem2(): AccordionItem {
|
|
41
|
+
return {
|
|
42
|
+
...getItem(),
|
|
43
|
+
isDefaultOpen: true,
|
|
44
|
+
icon: getIcon(),
|
|
45
|
+
title: 'Example - 2',
|
|
46
|
+
type: 'accordion',
|
|
47
|
+
content: [
|
|
48
|
+
{ ...getItem(), title: 'Example - 2.1', ...getTextContent() },
|
|
49
|
+
{
|
|
50
|
+
...getItem(),
|
|
51
|
+
icon: getIcon('hamburgerIcon', 'success'),
|
|
52
|
+
title: 'Example - 2.2',
|
|
53
|
+
type: 'jsx',
|
|
54
|
+
content: <div className="p-2">Example 2.2 Content</div>,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function createAccordionItem3(): AccordionItem {
|
|
60
|
+
return {
|
|
61
|
+
...getItem(),
|
|
62
|
+
icon: getIcon('hamburgerIcon', 'success'),
|
|
63
|
+
title: 'Example - 3',
|
|
64
|
+
type: 'accordion',
|
|
65
|
+
content: [
|
|
66
|
+
createAccordionItem3_1(),
|
|
67
|
+
{
|
|
68
|
+
...getItem(),
|
|
69
|
+
|
|
70
|
+
title: 'Example - 3.2',
|
|
71
|
+
type: 'text',
|
|
72
|
+
content: dummyText,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function createAccordionItem3_1(): AccordionItem {
|
|
79
|
+
return {
|
|
80
|
+
...getItem(),
|
|
81
|
+
title: 'Example - 3.1',
|
|
82
|
+
allowMultipleExpanded: true,
|
|
83
|
+
type: 'accordion',
|
|
84
|
+
content: [
|
|
85
|
+
{
|
|
86
|
+
...getItem(),
|
|
87
|
+
title: 'Example - 3.1.1',
|
|
88
|
+
type: 'text',
|
|
89
|
+
content: dummyText,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
...getItem(),
|
|
93
|
+
title: 'Example - 3.1.2',
|
|
94
|
+
type: 'text',
|
|
95
|
+
content: dummyText,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function createAccordionItem4(): AccordionItem {
|
|
102
|
+
return {
|
|
103
|
+
...getItem(),
|
|
104
|
+
icon: getIcon(),
|
|
105
|
+
title: 'Example - 4',
|
|
106
|
+
type: 'accordion',
|
|
107
|
+
content: [
|
|
108
|
+
createAccordionItem4_1(),
|
|
109
|
+
{
|
|
110
|
+
...getItem(),
|
|
111
|
+
title: 'Example - 4.2',
|
|
112
|
+
type: 'html',
|
|
113
|
+
content: '<h2>Lorem ipsum dolor sit amet.</h2>',
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function createAccordionItem4_1(): AccordionItem {
|
|
120
|
+
return {
|
|
121
|
+
...getItem(),
|
|
122
|
+
title: 'Example - 4.1',
|
|
123
|
+
type: 'accordion',
|
|
124
|
+
content: [
|
|
125
|
+
{
|
|
126
|
+
...getItem(),
|
|
127
|
+
|
|
128
|
+
title: 'Example - 4.1.1',
|
|
129
|
+
type: 'text',
|
|
130
|
+
content: dummyText,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
...getItem(),
|
|
134
|
+
type: 'jsx',
|
|
135
|
+
content: <div className="p-3">Example 4.1.2. content</div>,
|
|
136
|
+
title: 'Example - 4.1.2',
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export function getAccordionData(): AccordionItem[] {
|
|
142
|
+
return [createAccordionItem1(), createAccordionItem2(), createAccordionItem3(), createAccordionItem4()];
|
|
143
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { AdditionalProps } from '../common.types';
|
|
3
|
+
import { NsIconNameType, NsIconProps } from '../icon';
|
|
4
|
+
import { Variants } from '../typography';
|
|
5
|
+
import { AccordionVariantType } from './enums';
|
|
6
|
+
|
|
7
|
+
export type AccordionItem = {
|
|
8
|
+
allowMultipleExpanded?: boolean;
|
|
9
|
+
type: 'text' | 'html' | 'accordion' | 'jsx';
|
|
10
|
+
id: string;
|
|
11
|
+
content: string | AccordionItem[] | ReactElement;
|
|
12
|
+
icon?: NsIconProps;
|
|
13
|
+
title: string;
|
|
14
|
+
isDefaultOpen?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type NsAccordionProps = AdditionalProps & {
|
|
18
|
+
invert: boolean;
|
|
19
|
+
level: number;
|
|
20
|
+
variant: AccordionVariantType;
|
|
21
|
+
items?: AccordionItem[];
|
|
22
|
+
isChild?: boolean;
|
|
23
|
+
headerTypographyVariant?: Variants;
|
|
24
|
+
/** NsIcon's icon name to be shown in opened state */
|
|
25
|
+
openedIconName?: NsIconNameType;
|
|
26
|
+
/** NsIcon's icon name to be shown in closed state */
|
|
27
|
+
closedIconName?: NsIconNameType;
|
|
28
|
+
allowMultipleExpanded: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type CommonAccordionType = {
|
|
32
|
+
invert: boolean;
|
|
33
|
+
level: number;
|
|
34
|
+
variant: AccordionVariantType;
|
|
35
|
+
content: AccordionItem['content'];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type NsAccordionHeaderProps = AdditionalProps & {
|
|
39
|
+
title: string | ReactNode;
|
|
40
|
+
// eslint-disable-next-line no-unused-vars
|
|
41
|
+
onClick: (...args: any[]) => void;
|
|
42
|
+
/** a flag for the header, based on which header can change properties */
|
|
43
|
+
isOpen: boolean;
|
|
44
|
+
/** NsIcon's icon name to be shown in opened state */
|
|
45
|
+
openedIconName?: NsIconNameType;
|
|
46
|
+
/** NsIcon's icon name to be shown in closed state */
|
|
47
|
+
closedIconName?: NsIconNameType;
|
|
48
|
+
headerTypographyVariant?: Variants;
|
|
49
|
+
startIcon?: NsIconProps;
|
|
50
|
+
} & Pick<CommonAccordionType, 'invert' | 'variant'>;
|
|
51
|
+
|
|
52
|
+
export type NsCollapseProps = AdditionalProps & {
|
|
53
|
+
isOpen: boolean;
|
|
54
|
+
isChild: boolean;
|
|
55
|
+
allowMultipleExpanded?: boolean;
|
|
56
|
+
type: 'text' | 'html' | 'accordion' | 'jsx';
|
|
57
|
+
} & CommonAccordionType;
|
|
58
|
+
|
|
59
|
+
export type NsToggleSectionProps = AdditionalProps & {
|
|
60
|
+
title: string | ReactNode;
|
|
61
|
+
/** if true, NsToggle is rendered in open state, that collapsible section is visible */
|
|
62
|
+
defaultOpen?: boolean;
|
|
63
|
+
isChild: boolean;
|
|
64
|
+
type: 'text' | 'html' | 'accordion' | 'jsx';
|
|
65
|
+
} & Pick<CommonAccordionType, 'invert' | 'variant' | 'content'>;
|
|
66
|
+
|
|
67
|
+
export type NsAccordionItemProps = AdditionalProps & {
|
|
68
|
+
isOpen: boolean;
|
|
69
|
+
// eslint-disable-next-line no-unused-vars
|
|
70
|
+
toggleOpen(index: number, isOpen: boolean): void;
|
|
71
|
+
title: string | ReactNode;
|
|
72
|
+
headerTypographyVariant?: Variants;
|
|
73
|
+
/** NsIcon's icon name to be shown in opened state */
|
|
74
|
+
openedIconName?: NsIconNameType;
|
|
75
|
+
/** NsIcon's icon name to be shown in closed state */
|
|
76
|
+
closedIconName?: NsIconNameType;
|
|
77
|
+
startIcon?: NsIconProps;
|
|
78
|
+
isChild: boolean;
|
|
79
|
+
type: 'text' | 'html' | 'accordion' | 'jsx';
|
|
80
|
+
allowMultipleExpanded?: boolean;
|
|
81
|
+
} & CommonAccordionType;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FoundationTheme } from '@nuskin/foundation-theme';
|
|
3
|
+
|
|
4
|
+
import type { HeaderProps } from './types.d';
|
|
5
|
+
import { NsIconNameType } from '../icon/types';
|
|
6
|
+
|
|
7
|
+
export const colorMap: { [key: string]: FoundationTheme.PaletteColors } = {
|
|
8
|
+
error: 'error',
|
|
9
|
+
notice: 'info',
|
|
10
|
+
success: 'secondary',
|
|
11
|
+
warning: 'warning',
|
|
12
|
+
default: 'info',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const iconMap: { [key: string]: NsIconNameType } = {
|
|
16
|
+
error: 'alertError',
|
|
17
|
+
success: 'success',
|
|
18
|
+
warning: 'warning',
|
|
19
|
+
default: 'infoFilled',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const Header: React.FC<HeaderProps> = ({ children, head }) => (
|
|
23
|
+
<>
|
|
24
|
+
{children}
|
|
25
|
+
{head}
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export default Header;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render, fireEvent, screen, act } from '
|
|
3
|
-
// import { act } from 'react-dom/test-utils';
|
|
2
|
+
import { render, fireEvent, screen, act } from '@/test-utils/index';
|
|
4
3
|
import NsAlert from './NsAlert';
|
|
5
4
|
|
|
6
5
|
const addEventListenerMock = jest.spyOn(window, 'addEventListener');
|
|
7
6
|
const removeEventListenerMock = jest.spyOn(window, 'removeEventListener');
|
|
8
7
|
|
|
9
8
|
describe('NsAlert', () => {
|
|
10
|
-
test('renders alert with provided props', () => {
|
|
9
|
+
test('1. renders alert with provided props', () => {
|
|
11
10
|
render(
|
|
12
11
|
<NsAlert
|
|
13
12
|
context="error"
|
|
14
13
|
title="Error Alert"
|
|
15
|
-
|
|
14
|
+
threshold={800}
|
|
16
15
|
type="banner"
|
|
17
16
|
visible
|
|
18
17
|
head={<span>Alert Head</span>}
|
|
@@ -28,13 +27,13 @@ describe('NsAlert', () => {
|
|
|
28
27
|
expect(screen.getByText('Dismiss')).toBeInTheDocument();
|
|
29
28
|
});
|
|
30
29
|
|
|
31
|
-
test('calls onDismiss function when dismissed', () => {
|
|
30
|
+
test('2. calls onDismiss function when dismissed', () => {
|
|
32
31
|
const onDismissMock = jest.fn();
|
|
33
32
|
render(
|
|
34
33
|
<NsAlert
|
|
35
34
|
context="info"
|
|
36
35
|
title="Info Alert"
|
|
37
|
-
|
|
36
|
+
threshold={600}
|
|
38
37
|
type="auto"
|
|
39
38
|
visible
|
|
40
39
|
head={<span>Alert Head</span>}
|
|
@@ -49,12 +48,12 @@ describe('NsAlert', () => {
|
|
|
49
48
|
expect(onDismissMock).toHaveBeenCalled();
|
|
50
49
|
});
|
|
51
50
|
|
|
52
|
-
test('hides alert when not visible', () => {
|
|
51
|
+
test('3. hides alert when not visible', () => {
|
|
53
52
|
render(
|
|
54
53
|
<NsAlert
|
|
55
54
|
context="success"
|
|
56
55
|
title="Success Alert"
|
|
57
|
-
|
|
56
|
+
threshold={700}
|
|
58
57
|
type="card"
|
|
59
58
|
visible={false}
|
|
60
59
|
head={<span>Alert Head</span>}
|
|
@@ -65,47 +64,63 @@ describe('NsAlert', () => {
|
|
|
65
64
|
expect(screen.getByTestId('alert-container')).toHaveStyle('display: none');
|
|
66
65
|
});
|
|
67
66
|
|
|
68
|
-
test('adds and removes event listener on mount/unmount', () => {
|
|
67
|
+
test('4. adds and removes event listener on mount/unmount', () => {
|
|
69
68
|
act(() => {
|
|
70
|
-
render(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
render(
|
|
70
|
+
<NsAlert
|
|
71
|
+
context="notice"
|
|
72
|
+
title="Success Alert"
|
|
73
|
+
threshold={700}
|
|
74
|
+
type="card"
|
|
75
|
+
visible={false}
|
|
76
|
+
head={<span>Alert Head</span>}
|
|
77
|
+
body={<p>Alert Body</p>}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
79
80
|
});
|
|
80
|
-
|
|
81
|
+
|
|
81
82
|
expect(addEventListenerMock).toHaveBeenCalledWith('resize', expect.any(Function));
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
expect(removeEventListenerMock).toHaveBeenCalledWith('resize', expect.any(Function));
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
test('updates windowWidth on resize', () => {
|
|
87
|
+
test('5. updates windowWidth on resize and auto type and greater threshold to select card', () => {
|
|
88
88
|
const originalInnerWidth = window.innerWidth;
|
|
89
89
|
window.innerWidth = 500; // Set a desired window width for testing
|
|
90
|
-
|
|
90
|
+
|
|
91
|
+
act(() => {
|
|
92
|
+
render(<NsAlert threshold={2000} type="auto" />);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Simulate a resize event by restoring the original innerWidth
|
|
96
|
+
window.innerWidth = originalInnerWidth;
|
|
97
|
+
|
|
98
|
+
act(() => {
|
|
99
|
+
window.dispatchEvent(new Event('resize'));
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
test('6. updates windowWidth on resize', () => {
|
|
103
|
+
const originalInnerWidth = window.innerWidth;
|
|
104
|
+
window.innerWidth = 500; // Set a desired window width for testing
|
|
105
|
+
|
|
91
106
|
act(() => {
|
|
92
107
|
render(<NsAlert />);
|
|
93
108
|
});
|
|
94
|
-
|
|
109
|
+
|
|
95
110
|
// Simulate a resize event by restoring the original innerWidth
|
|
96
111
|
window.innerWidth = originalInnerWidth;
|
|
97
|
-
|
|
112
|
+
|
|
98
113
|
act(() => {
|
|
99
114
|
window.dispatchEvent(new Event('resize'));
|
|
100
115
|
});
|
|
101
116
|
});
|
|
102
117
|
|
|
103
|
-
test('get props error in console for types', () => {
|
|
118
|
+
test('7. get props error in console for types', () => {
|
|
104
119
|
render(
|
|
105
120
|
<NsAlert
|
|
106
121
|
context="warning"
|
|
107
122
|
title="warning Alert"
|
|
108
|
-
|
|
123
|
+
threshold={800}
|
|
109
124
|
type="noCard"
|
|
110
125
|
visible
|
|
111
126
|
head={<span>Alert Head</span>}
|
|
@@ -116,12 +131,12 @@ describe('NsAlert', () => {
|
|
|
116
131
|
expect(screen.getByTestId('alert-container')).toHaveStyle('display: block');
|
|
117
132
|
});
|
|
118
133
|
|
|
119
|
-
test('get props error in console for context', () => {
|
|
134
|
+
test('8. get props error in console for context', () => {
|
|
120
135
|
render(
|
|
121
136
|
<NsAlert
|
|
122
137
|
context="warningError"
|
|
123
138
|
title="warning Alert"
|
|
124
|
-
|
|
139
|
+
threshold={800}
|
|
125
140
|
type="card"
|
|
126
141
|
visible
|
|
127
142
|
head={<span>Alert Head</span>}
|
|
@@ -131,4 +146,22 @@ describe('NsAlert', () => {
|
|
|
131
146
|
|
|
132
147
|
expect(screen.getByTestId('alert-container')).toHaveStyle('display: block');
|
|
133
148
|
});
|
|
149
|
+
test('9. console.error to be called twice', () => {
|
|
150
|
+
const original = console.error;
|
|
151
|
+
console.error = jest.fn();
|
|
152
|
+
render(
|
|
153
|
+
<NsAlert
|
|
154
|
+
context=""
|
|
155
|
+
title="warning Alert"
|
|
156
|
+
threshold={2000}
|
|
157
|
+
type=""
|
|
158
|
+
visible
|
|
159
|
+
head={<span>Alert Head</span>}
|
|
160
|
+
body={<p>Alert Body</p>}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
expect(console.error).toHaveBeenCalledTimes(2);
|
|
164
|
+
console.error = original;
|
|
165
|
+
expect(screen.getByTestId('alert-container')).toHaveStyle('display: block');
|
|
166
|
+
});
|
|
134
167
|
});
|
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
3
|
import NsAlert from './NsAlert';
|
|
4
|
-
import { withCenterDecorator } from '
|
|
4
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
5
5
|
|
|
6
6
|
type ComponentType = typeof NsAlert;
|
|
7
7
|
type Story = StoryObj<ComponentType>;
|
|
8
8
|
type MetaStory = Meta<ComponentType>;
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
|
-
title: 'Components/NsAlert',
|
|
11
|
+
title: 'Components/Feedback/NsAlert',
|
|
12
12
|
component: NsAlert,
|
|
13
13
|
decorators: [withCenterDecorator],
|
|
14
14
|
argTypes: {
|
|
15
|
-
context: {
|
|
15
|
+
context: {
|
|
16
16
|
control: 'select',
|
|
17
|
-
options: ['error', 'info', 'notice', 'success', 'warning']
|
|
17
|
+
options: ['error', 'info', 'notice', 'success', 'warning'],
|
|
18
18
|
},
|
|
19
|
-
type: {
|
|
19
|
+
type: {
|
|
20
20
|
control: 'select',
|
|
21
|
-
options: ['auto', 'banner', 'card']
|
|
22
|
-
}
|
|
21
|
+
options: ['auto', 'banner', 'card'],
|
|
22
|
+
},
|
|
23
23
|
},
|
|
24
24
|
args: {
|
|
25
25
|
context: 'info',
|
|
26
26
|
title: 'Information',
|
|
27
|
-
|
|
27
|
+
threshold: 600,
|
|
28
28
|
type: 'banner',
|
|
29
29
|
visible: true,
|
|
30
30
|
onDismiss: () => {},
|
|
31
|
-
body:
|
|
32
|
-
|
|
31
|
+
body: (
|
|
32
|
+
<span>{`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
|
|
33
33
|
ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
|
|
34
|
-
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
35
|
-
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
|
|
36
|
-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa
|
|
37
|
-
qui officia deserunt mollit anim id est laborum.`}</
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
|
35
|
+
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
|
|
36
|
+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa
|
|
37
|
+
qui officia deserunt mollit anim id est laborum.`}</span>
|
|
38
|
+
),
|
|
39
|
+
foot: <span>Some message goes here.</span>,
|
|
40
|
+
},
|
|
40
41
|
} as MetaStory;
|
|
41
42
|
|
|
42
|
-
export const
|
|
43
|
+
export const Alert: Story = {};
|