@nuskin/foundation-ui-components 1.0.0-develop.6 → 1.0.0-develop.7
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 +17 -12
- package/src/common/accordion/NsAccordion.tsx +29 -39
- package/src/common/accordion/NsAccordionHeader.tsx +32 -17
- package/src/common/accordion/NsAccordionItem.tsx +16 -4
- package/src/common/accordion/NsCollapse.tsx +73 -35
- package/src/common/accordion/NsToggleSection.tsx +14 -3
- package/src/common/accordion/ToggleSection.styled.tsx +8 -7
- package/src/common/accordion/colorMap.ts +117 -0
- package/src/common/accordion/enums.ts +15 -0
- package/src/common/accordion/index.ts +1 -0
- package/src/common/accordion/specs/NsAccordion.spec.tsx +100 -31
- package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +77 -10
- package/src/common/accordion/specs/NsAccordionItem.spec.tsx +23 -10
- package/src/common/accordion/specs/NsCollapse.spec.tsx +106 -17
- package/src/common/accordion/specs/NsToggleSection.spec.tsx +46 -14
- package/src/common/accordion/stories/NsAccordion.stories.tsx +27 -14
- package/src/common/accordion/stories/NsAccordionHeader.stories.tsx +4 -1
- package/src/common/accordion/stories/NsAccordionItem.stories.tsx +3 -3
- package/src/common/accordion/stories/NsCollapse.stories.tsx +3 -3
- package/src/common/accordion/stories/NsToggleSection.stories.tsx +2 -3
- package/src/common/accordion/stories/data.tsx +157 -19
- package/src/common/accordion/types.d.ts +56 -49
- package/src/common/alert/Header.tsx +29 -0
- package/src/common/alert/NsAlert.spec.tsx +46 -13
- package/src/common/alert/NsAlert.stories.tsx +3 -3
- package/src/common/alert/{NsAlert.styled.ts → NsAlert.styled.tsx} +22 -22
- package/src/common/alert/NsAlert.tsx +22 -87
- package/src/common/alert/types.d.ts +7 -7
- package/src/common/auth-dropdown/NsAuthDropdown.spec.tsx +23 -5
- package/src/common/auth-dropdown/NsAuthDropdown.stories.tsx +1 -1
- package/src/common/auth-dropdown/NsAuthDropdown.styled.ts +11 -7
- package/src/common/auth-dropdown/NsAuthDropdown.tsx +4 -4
- package/src/common/autocomplete/NsAutocomplete.spec.tsx +29 -6
- package/src/common/autocomplete/NsAutocomplete.stories.tsx +1 -1
- package/src/common/autocomplete/NsAutocomplete.tsx +18 -8
- package/src/common/autocomplete/mock/MockUI.tsx +1 -0
- package/src/common/banner/NsBanner.spec.tsx +12 -3
- package/src/common/banner/NsBanner.stories.tsx +1 -1
- package/src/common/brand-components/NsBrand.stories.tsx +1 -1
- package/src/common/brand-components/NsBrandComponent.tsx +2 -2
- package/src/common/breadcrumb/NsBreadcrumb.spec.tsx +8 -3
- package/src/common/breadcrumb/NsBreadcrumb.stories.tsx +1 -1
- package/src/common/breadcrumb/data.ts +8 -5
- package/src/common/button/NsButton.spec.tsx +65 -49
- package/src/common/button/NsButton.stories.tsx +59 -2
- package/src/common/button/NsButton.styled.tsx +49 -66
- package/src/common/button/NsButton.tsx +1 -2
- package/src/common/button/helper.ts +82 -0
- package/src/common/button/types.d.ts +2 -0
- package/src/common/card/stories/NsBgCard.stories.tsx +1 -1
- package/src/common/card/stories/NsBrandProductCard.stories.tsx +1 -1
- package/src/common/card/stories/NsFfgCard.stories.tsx +5 -2
- package/src/common/card/styled/NsFfgStyled.tsx +1 -1
- package/src/common/carousal/stories/NSCarousal.stories.tsx +1 -1
- package/src/common/carousal/stories/NsScrollingCarousal.stories.tsx +1 -1
- package/src/common/cart-icon/NsCartIcon.stories.tsx +1 -1
- package/src/common/checkbox/NsCheckbox.stories.tsx +1 -1
- package/src/common/checkbox/NsCheckbox.styled.tsx +15 -16
- package/src/common/checkbox/NsCheckbox.tsx +1 -1
- package/src/common/column-control/stories/DivArray.stories.tsx +1 -1
- package/src/common/column-control/stories/NsColumnControl.stories.tsx +1 -1
- package/src/common/column-control/stories/NsFlexColumns.stories.tsx +1 -1
- package/src/common/column-control/stories/NsGridColumns.stories.tsx +1 -1
- package/src/common/column-control/styled/common.ts +1 -1
- package/src/common/column-control/utils.ts +4 -4
- package/src/common/common.types.d.ts +11 -1
- package/src/common/dropdown/NsDropdown.styled.tsx +23 -18
- package/src/common/dropdown/stories/NsDropdown.stories.tsx +1 -1
- package/src/common/dropdown/stories/NsDropdownCountry.stories.tsx +1 -1
- package/src/common/flag/NsFlag.stories.tsx +1 -1
- 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.stories.tsx +1 -1
- package/src/common/icon/NsIconVariants.ts +1 -0
- package/src/common/image/NsImage.spec.tsx +56 -6
- package/src/common/image/NsImage.stories.tsx +1 -1
- package/src/common/image/NsImage.tsx +23 -11
- package/src/common/image/NsNextImage.stories.tsx +1 -1
- package/src/common/index.ts +2 -0
- package/src/common/input/InputWrapper.tsx +12 -7
- package/src/common/input/NsInputField.tsx +1 -1
- package/src/common/label/NsLabel.stories.tsx +1 -1
- package/src/common/link/NsLink.stories.tsx +1 -1
- package/src/common/nav-product-card/NsNavProductCard.stories.tsx +1 -1
- package/src/common/nav-tab/NsNavTab.stories.tsx +1 -1
- package/src/common/radiogroup/NsRadioGroup.spec.tsx +24 -25
- package/src/common/radiogroup/NsRadioGroup.stories.tsx +14 -32
- package/src/common/radiogroup/NsRadioGroup.styled.tsx +17 -15
- package/src/common/radiogroup/NsRadioGroup.tsx +6 -5
- package/src/common/search-bar/NsSearchBar.tsx +1 -3
- package/src/common/select/NsSelect.spec.tsx +10 -17
- package/src/common/select/NsSelect.styled.tsx +53 -34
- package/src/common/select/stories/NsSelect.stories.tsx +11 -11
- package/src/common/select/types.d.ts +3 -3
- 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/NsTable.stories.tsx +1 -1
- package/src/common/table/NsTable.tsx +32 -49
- package/src/common/table/NsTableHeader.tsx +30 -51
- package/src/common/text-strip/NsTextStrip.stories.tsx +1 -1
- package/src/common/typography/NsTypography.stories.tsx +1 -1
- package/src/common/util.ts +1 -0
- package/src/common/videos/NsVideo.stories.tsx +1 -1
- package/src/common/videos/types.d.ts +1 -1
- /package/src/common/brand-components/{NsBrandContanier.styled.tsx → NsBrandContainer.styled.tsx} +0 -0
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
2
2
|
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
3
|
-
import NsAccordion from '
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type MetaStory = Meta<ComponentType>;
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
title: 'Components/Accordion/NsAccordion',
|
|
3
|
+
import { NsAccordion, AccordionVariant } from '../..';
|
|
4
|
+
import { getAccordionData } from './data';
|
|
5
|
+
import { within } from '@storybook/testing-library';
|
|
6
|
+
import { expect } from '@storybook/jest';
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Components/Containers/Accordion',
|
|
13
9
|
component: NsAccordion,
|
|
14
10
|
decorators: [withCenterDecorator],
|
|
15
11
|
argTypes: {
|
|
@@ -18,7 +14,7 @@ export default {
|
|
|
18
14
|
description: `if true, then multiple sections can remain open at a same time, and if false,
|
|
19
15
|
opening a section will close other sections of the accordion`,
|
|
20
16
|
},
|
|
21
|
-
|
|
17
|
+
items: {
|
|
22
18
|
description: ` this should be an array of objects, each object should have 3 properties,
|
|
23
19
|
title, body and isDefaultOpen`,
|
|
24
20
|
},
|
|
@@ -29,19 +25,36 @@ export default {
|
|
|
29
25
|
},
|
|
30
26
|
args: {
|
|
31
27
|
variant: AccordionVariant.Basic,
|
|
28
|
+
invert: false,
|
|
29
|
+
level: 2,
|
|
32
30
|
},
|
|
33
|
-
}
|
|
31
|
+
} satisfies MetaStory;
|
|
32
|
+
|
|
33
|
+
export default meta;
|
|
34
|
+
|
|
35
|
+
type MetaStory = Meta<typeof NsAccordion>;
|
|
36
|
+
type Story = StoryObj<typeof meta>;
|
|
34
37
|
|
|
35
38
|
export const SingleOpen: Story = {
|
|
36
39
|
args: {
|
|
37
40
|
allowMultipleExpanded: false,
|
|
38
|
-
|
|
41
|
+
items: getAccordionData(),
|
|
42
|
+
invert: false,
|
|
43
|
+
},
|
|
44
|
+
play: ({ canvasElement }) => {
|
|
45
|
+
const canvas = within(canvasElement);
|
|
46
|
+
const el1 = canvas.getByText('Example - 1 JSX');
|
|
47
|
+
expect(el1).toBeInTheDocument();
|
|
48
|
+
expect(el1.closest('header')).toHaveAttribute('aria-expanded', 'true');
|
|
49
|
+
const el2 = canvas.getByText('Example - 2');
|
|
50
|
+
expect(el2).toBeInTheDocument();
|
|
51
|
+
expect(el2.closest('header')).toHaveAttribute('aria-expanded', 'false');
|
|
39
52
|
},
|
|
40
53
|
};
|
|
41
54
|
|
|
42
55
|
export const MultipleOpen: Story = {
|
|
43
56
|
args: {
|
|
44
57
|
allowMultipleExpanded: true,
|
|
45
|
-
|
|
58
|
+
items: getAccordionData(),
|
|
46
59
|
},
|
|
47
60
|
};
|
|
@@ -7,7 +7,7 @@ type Story = StoryObj<ComponentType>;
|
|
|
7
7
|
type MetaStory = Meta<ComponentType>;
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: 'Components/Accordion/NsAccordionHeader',
|
|
10
|
+
title: 'Components/Containers/Accordion/NsAccordionHeader',
|
|
11
11
|
component: NsAccordionHeader,
|
|
12
12
|
decorators: [withCenterDecorator],
|
|
13
13
|
argTypes: {
|
|
@@ -26,6 +26,9 @@ export default {
|
|
|
26
26
|
onClick: () => {
|
|
27
27
|
console.log('accordion header clicked');
|
|
28
28
|
},
|
|
29
|
+
startIcon: {
|
|
30
|
+
name: 'home',
|
|
31
|
+
},
|
|
29
32
|
openedIconName: 'arrowUp',
|
|
30
33
|
closedIconName: 'arrowDown',
|
|
31
34
|
isOpen: false,
|
|
@@ -7,7 +7,7 @@ type Story = StoryObj<ComponentType>;
|
|
|
7
7
|
type MetaStory = Meta<ComponentType>;
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: 'Components/Accordion/NsAccordionItem',
|
|
10
|
+
title: 'Components/Containers/Accordion/NsAccordionItem',
|
|
11
11
|
component: NsAccordionItem,
|
|
12
12
|
decorators: [withCenterDecorator],
|
|
13
13
|
argTypes: {
|
|
@@ -26,7 +26,7 @@ export default {
|
|
|
26
26
|
export const OpenSection: Story = {
|
|
27
27
|
args: {
|
|
28
28
|
isOpen: true,
|
|
29
|
-
content:
|
|
29
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
30
30
|
title: 'Nuskin',
|
|
31
31
|
},
|
|
32
32
|
};
|
|
@@ -34,7 +34,7 @@ export const OpenSection: Story = {
|
|
|
34
34
|
export const ClosedSection: Story = {
|
|
35
35
|
args: {
|
|
36
36
|
isOpen: false,
|
|
37
|
-
content:
|
|
37
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
38
38
|
title: 'Nuskin',
|
|
39
39
|
},
|
|
40
40
|
};
|
|
@@ -7,7 +7,7 @@ type Story = StoryObj<ComponentType>;
|
|
|
7
7
|
type MetaStory = Meta<ComponentType>;
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: 'Components/Accordion/NsCollapse',
|
|
10
|
+
title: 'Components/Containers/Accordion/NsCollapse',
|
|
11
11
|
component: NsCollapse,
|
|
12
12
|
decorators: [withCenterDecorator],
|
|
13
13
|
argTypes: {
|
|
@@ -24,12 +24,12 @@ export default {
|
|
|
24
24
|
export const Closed: Story = {
|
|
25
25
|
args: {
|
|
26
26
|
isOpen: false,
|
|
27
|
-
|
|
27
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
export const Open: Story = {
|
|
31
31
|
args: {
|
|
32
32
|
isOpen: true,
|
|
33
|
-
|
|
33
|
+
content: <div className="p-2">Nuskin Description</div>,
|
|
34
34
|
},
|
|
35
35
|
};
|
|
@@ -7,7 +7,7 @@ type Story = StoryObj<ComponentType>;
|
|
|
7
7
|
type MetaStory = Meta<ComponentType>;
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: 'Components/Accordion/NsToggleSection',
|
|
10
|
+
title: 'Components/Containers/Accordion/NsToggleSection',
|
|
11
11
|
component: NsToggleSection,
|
|
12
12
|
decorators: [withCenterDecorator],
|
|
13
13
|
argTypes: {
|
|
@@ -15,8 +15,7 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
args: {
|
|
17
17
|
title: 'Nuskin',
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
content: <div className="p-2">Nuskin Details</div>,
|
|
20
19
|
},
|
|
21
20
|
} as MetaStory;
|
|
22
21
|
|
|
@@ -1,22 +1,160 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NsIconProps } from '../..';
|
|
2
|
+
import { AccordionItem, ItemContent } from '../types';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
{
|
|
5
|
-
|
|
6
|
-
|
|
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 ItemContent['type'],
|
|
18
|
+
data: 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(),
|
|
7
36
|
isDefaultOpen: true,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function createAccordionItem2(): AccordionItem {
|
|
40
|
+
return {
|
|
41
|
+
...getItem(),
|
|
12
42
|
isDefaultOpen: true,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
43
|
+
icon: getIcon(),
|
|
44
|
+
title: 'Example - 2',
|
|
45
|
+
content: {
|
|
46
|
+
type: 'accordion',
|
|
47
|
+
data: [
|
|
48
|
+
{ ...getItem(), title: 'Example - 2.1', content: getTextContent() },
|
|
49
|
+
{
|
|
50
|
+
...getItem(),
|
|
51
|
+
icon: getIcon('hamburgerIcon', 'success'),
|
|
52
|
+
title: 'Example - 2.2',
|
|
53
|
+
content: <div className="p-2">Example 2.2 Content</div>,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function createAccordionItem3(): AccordionItem {
|
|
60
|
+
return {
|
|
61
|
+
...getItem(),
|
|
62
|
+
icon: getIcon('hamburgerIcon', 'success'),
|
|
63
|
+
title: 'Example - 3',
|
|
64
|
+
content: {
|
|
65
|
+
type: 'accordion',
|
|
66
|
+
data: [
|
|
67
|
+
createAccordionItem3_1(),
|
|
68
|
+
{
|
|
69
|
+
...getItem(),
|
|
70
|
+
|
|
71
|
+
title: 'Example - 3.2',
|
|
72
|
+
content: {
|
|
73
|
+
type: 'text',
|
|
74
|
+
data: dummyText,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function createAccordionItem3_1(): AccordionItem {
|
|
83
|
+
return {
|
|
84
|
+
...getItem(),
|
|
85
|
+
title: 'Example - 3.1',
|
|
86
|
+
content: {
|
|
87
|
+
type: 'accordion',
|
|
88
|
+
allowMultipleExpanded: true,
|
|
89
|
+
data: [
|
|
90
|
+
{
|
|
91
|
+
...getItem(),
|
|
92
|
+
title: 'Example - 3.1.1',
|
|
93
|
+
content: {
|
|
94
|
+
type: 'text',
|
|
95
|
+
data: dummyText,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
...getItem(),
|
|
100
|
+
title: 'Example - 3.1.2',
|
|
101
|
+
content: {
|
|
102
|
+
type: 'text',
|
|
103
|
+
data: dummyText,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function createAccordionItem4(): AccordionItem {
|
|
112
|
+
return {
|
|
113
|
+
...getItem(),
|
|
114
|
+
icon: getIcon(),
|
|
115
|
+
title: 'Example - 4',
|
|
116
|
+
content: {
|
|
117
|
+
type: 'accordion',
|
|
118
|
+
data: [
|
|
119
|
+
createAccordionItem4_1(),
|
|
120
|
+
{
|
|
121
|
+
...getItem(),
|
|
122
|
+
title: 'Example - 4.2',
|
|
123
|
+
content: {
|
|
124
|
+
type: 'html',
|
|
125
|
+
data: '<h2>Lorem ipsum dolor sit amet.</h2>',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createAccordionItem4_1(): AccordionItem {
|
|
134
|
+
return {
|
|
135
|
+
...getItem(),
|
|
136
|
+
title: 'Example - 4.1',
|
|
137
|
+
content: {
|
|
138
|
+
type: 'accordion',
|
|
139
|
+
data: [
|
|
140
|
+
{
|
|
141
|
+
...getItem(),
|
|
142
|
+
|
|
143
|
+
title: 'Example - 4.1.1',
|
|
144
|
+
content: {
|
|
145
|
+
type: 'text',
|
|
146
|
+
data: dummyText,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
...getItem(),
|
|
151
|
+
content: <div className="p-3">Example 4.1.2. content</div>,
|
|
152
|
+
title: 'Example - 4.1.2',
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
export function getAccordionData(): AccordionItem[] {
|
|
159
|
+
return [createAccordionItem1(), createAccordionItem2(), createAccordionItem3(), createAccordionItem4()];
|
|
160
|
+
}
|
|
@@ -1,73 +1,80 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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 interface ItemContent {
|
|
8
|
+
type: 'text' | 'html' | 'accordion' | 'jsx';
|
|
9
|
+
allowMultipleExpanded?: boolean;
|
|
10
|
+
data: string | AccordionItem[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type AccordionItem = {
|
|
14
|
+
id: string;
|
|
15
|
+
content: ItemContent | ReactElement;
|
|
16
|
+
icon?: NsIconProps;
|
|
17
|
+
title: string;
|
|
18
|
+
isDefaultOpen?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type NsAccordionProps = AdditionalProps & {
|
|
22
|
+
invert: boolean;
|
|
23
|
+
level: number;
|
|
24
|
+
variant: AccordionVariantType;
|
|
25
|
+
items?: AccordionItem[];
|
|
26
|
+
isChild?: boolean;
|
|
27
|
+
headerTypographyVariant?: Variants;
|
|
28
|
+
/** NsIcon's icon name to be shown in opened state */
|
|
29
|
+
openedIconName?: NsIconNameType;
|
|
30
|
+
/** NsIcon's icon name to be shown in closed state */
|
|
31
|
+
closedIconName?: NsIconNameType;
|
|
32
|
+
allowMultipleExpanded: boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type CommonAccordionType = {
|
|
36
|
+
invert: boolean;
|
|
37
|
+
level: number;
|
|
38
|
+
variant: AccordionVariantType;
|
|
39
|
+
content: AccordionItem['content'];
|
|
40
|
+
};
|
|
5
41
|
|
|
6
42
|
export type NsAccordionHeaderProps = AdditionalProps & {
|
|
7
43
|
title: string | ReactNode;
|
|
8
44
|
// eslint-disable-next-line no-unused-vars
|
|
9
45
|
onClick: (...args: any[]) => void;
|
|
10
46
|
/** a flag for the header, based on which header can change properties */
|
|
11
|
-
isOpen
|
|
47
|
+
isOpen: boolean;
|
|
12
48
|
/** NsIcon's icon name to be shown in opened state */
|
|
13
49
|
openedIconName?: NsIconNameType;
|
|
14
50
|
/** NsIcon's icon name to be shown in closed state */
|
|
15
51
|
closedIconName?: NsIconNameType;
|
|
16
|
-
variant: AccordionVariant;
|
|
17
52
|
headerTypographyVariant?: Variants;
|
|
18
|
-
|
|
53
|
+
startIcon?: NsIconProps;
|
|
54
|
+
} & Pick<CommonAccordionType, 'invert' | 'variant'>;
|
|
19
55
|
|
|
20
|
-
export type NsCollapseProps = AdditionalProps &
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}>;
|
|
25
|
-
|
|
26
|
-
export type NsFramerCollapseProps = NsCollapseProps & {
|
|
27
|
-
transitionDetails?: {
|
|
28
|
-
duration?: number;
|
|
29
|
-
ease?: number[];
|
|
30
|
-
};
|
|
31
|
-
};
|
|
56
|
+
export type NsCollapseProps = AdditionalProps & {
|
|
57
|
+
isOpen: boolean;
|
|
58
|
+
isChild: boolean;
|
|
59
|
+
} & CommonAccordionType;
|
|
32
60
|
|
|
33
|
-
export type NsToggleSectionProps = AdditionalProps &
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}>;
|
|
61
|
+
export type NsToggleSectionProps = AdditionalProps & {
|
|
62
|
+
title: string | ReactNode;
|
|
63
|
+
/** if true, NsToggle is rendered in open state, that collapsible section is visible */
|
|
64
|
+
defaultOpen?: boolean;
|
|
65
|
+
isChild: boolean;
|
|
66
|
+
} & Pick<CommonAccordionType, 'invert' | 'variant' | 'content'>;
|
|
40
67
|
|
|
41
68
|
export type NsAccordionItemProps = AdditionalProps & {
|
|
42
69
|
isOpen: boolean;
|
|
43
70
|
// eslint-disable-next-line no-unused-vars
|
|
44
71
|
toggleOpen(index: number, isOpen: boolean): void;
|
|
45
72
|
title: string | ReactNode;
|
|
46
|
-
content: ReactNode;
|
|
47
|
-
variant: AccordionVariant;
|
|
48
|
-
headerTypographyVariant?: Variants;
|
|
49
|
-
/** NsIcon's icon name to be shown in opened state */
|
|
50
|
-
openedIconName?: NsIconNameType;
|
|
51
|
-
/** NsIcon's icon name to be shown in closed state */
|
|
52
|
-
closedIconName?: NsIconNameType;
|
|
53
|
-
};
|
|
54
|
-
export type NsAccordionProps = AdditionalProps & {
|
|
55
|
-
allowMultipleExpanded: boolean;
|
|
56
|
-
contentArray: {
|
|
57
|
-
title: string | ReactNode;
|
|
58
|
-
body: ReactNode;
|
|
59
|
-
isDefaultOpen?: boolean;
|
|
60
|
-
}[];
|
|
61
|
-
variant: AccordionVariant;
|
|
62
73
|
headerTypographyVariant?: Variants;
|
|
63
74
|
/** NsIcon's icon name to be shown in opened state */
|
|
64
75
|
openedIconName?: NsIconNameType;
|
|
65
76
|
/** NsIcon's icon name to be shown in closed state */
|
|
66
77
|
closedIconName?: NsIconNameType;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Basic = 'basic', // basic is as per figma
|
|
71
|
-
// eslint-disable-next-line no-unused-vars
|
|
72
|
-
Compact = 'compact', // compact is as per test.nuskin.com
|
|
73
|
-
}
|
|
78
|
+
startIcon?: NsIconProps;
|
|
79
|
+
isChild: boolean;
|
|
80
|
+
} & 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;
|
|
@@ -6,12 +6,12 @@ const addEventListenerMock = jest.spyOn(window, 'addEventListener');
|
|
|
6
6
|
const removeEventListenerMock = jest.spyOn(window, 'removeEventListener');
|
|
7
7
|
|
|
8
8
|
describe('NsAlert', () => {
|
|
9
|
-
test('renders alert with provided props', () => {
|
|
9
|
+
test('1. renders alert with provided props', () => {
|
|
10
10
|
render(
|
|
11
11
|
<NsAlert
|
|
12
12
|
context="error"
|
|
13
13
|
title="Error Alert"
|
|
14
|
-
|
|
14
|
+
threshold={800}
|
|
15
15
|
type="banner"
|
|
16
16
|
visible
|
|
17
17
|
head={<span>Alert Head</span>}
|
|
@@ -27,13 +27,13 @@ describe('NsAlert', () => {
|
|
|
27
27
|
expect(screen.getByText('Dismiss')).toBeInTheDocument();
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
test('calls onDismiss function when dismissed', () => {
|
|
30
|
+
test('2. calls onDismiss function when dismissed', () => {
|
|
31
31
|
const onDismissMock = jest.fn();
|
|
32
32
|
render(
|
|
33
33
|
<NsAlert
|
|
34
34
|
context="info"
|
|
35
35
|
title="Info Alert"
|
|
36
|
-
|
|
36
|
+
threshold={600}
|
|
37
37
|
type="auto"
|
|
38
38
|
visible
|
|
39
39
|
head={<span>Alert Head</span>}
|
|
@@ -48,12 +48,12 @@ describe('NsAlert', () => {
|
|
|
48
48
|
expect(onDismissMock).toHaveBeenCalled();
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
test('hides alert when not visible', () => {
|
|
51
|
+
test('3. hides alert when not visible', () => {
|
|
52
52
|
render(
|
|
53
53
|
<NsAlert
|
|
54
54
|
context="success"
|
|
55
55
|
title="Success Alert"
|
|
56
|
-
|
|
56
|
+
threshold={700}
|
|
57
57
|
type="card"
|
|
58
58
|
visible={false}
|
|
59
59
|
head={<span>Alert Head</span>}
|
|
@@ -64,13 +64,13 @@ describe('NsAlert', () => {
|
|
|
64
64
|
expect(screen.getByTestId('alert-container')).toHaveStyle('display: none');
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test('adds and removes event listener on mount/unmount', () => {
|
|
67
|
+
test('4. adds and removes event listener on mount/unmount', () => {
|
|
68
68
|
act(() => {
|
|
69
69
|
render(
|
|
70
70
|
<NsAlert
|
|
71
71
|
context="notice"
|
|
72
72
|
title="Success Alert"
|
|
73
|
-
|
|
73
|
+
threshold={700}
|
|
74
74
|
type="card"
|
|
75
75
|
visible={false}
|
|
76
76
|
head={<span>Alert Head</span>}
|
|
@@ -84,7 +84,22 @@ describe('NsAlert', () => {
|
|
|
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
|
+
const originalInnerWidth = window.innerWidth;
|
|
89
|
+
window.innerWidth = 500; // Set a desired window width for testing
|
|
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', () => {
|
|
88
103
|
const originalInnerWidth = window.innerWidth;
|
|
89
104
|
window.innerWidth = 500; // Set a desired window width for testing
|
|
90
105
|
|
|
@@ -100,12 +115,12 @@ describe('NsAlert', () => {
|
|
|
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
|
});
|
|
@@ -8,7 +8,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: {
|
|
@@ -24,7 +24,7 @@ export default {
|
|
|
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: () => {},
|
|
@@ -40,4 +40,4 @@ export default {
|
|
|
40
40
|
},
|
|
41
41
|
} as MetaStory;
|
|
42
42
|
|
|
43
|
-
export const
|
|
43
|
+
export const Alert: Story = {};
|