@nuskin/foundation-ui-components 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/package.json +105 -101
  2. package/src/common/accordion/NsAccordion.tsx +32 -40
  3. package/src/common/accordion/NsAccordionHeader.tsx +29 -8
  4. package/src/common/accordion/NsAccordionItem.tsx +24 -4
  5. package/src/common/accordion/NsCollapse.tsx +96 -35
  6. package/src/common/accordion/NsToggleSection.tsx +16 -3
  7. package/src/common/accordion/ToggleSection.styled.tsx +11 -7
  8. package/src/common/accordion/colorMap.ts +117 -0
  9. package/src/common/accordion/enums.ts +18 -0
  10. package/src/common/accordion/index.ts +1 -0
  11. package/src/common/accordion/specs/NsAccordion.spec.tsx +101 -31
  12. package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +77 -10
  13. package/src/common/accordion/specs/NsAccordionItem.spec.tsx +27 -10
  14. package/src/common/accordion/specs/NsCollapse.spec.tsx +109 -17
  15. package/src/common/accordion/specs/NsToggleSection.spec.tsx +50 -14
  16. package/src/common/accordion/stories/NsAccordion.stories.tsx +32 -14
  17. package/src/common/accordion/stories/NsAccordionHeader.stories.tsx +6 -2
  18. package/src/common/accordion/stories/NsAccordionItem.stories.tsx +9 -4
  19. package/src/common/accordion/stories/NsCollapse.stories.tsx +20 -5
  20. package/src/common/accordion/stories/NsToggleSection.stories.tsx +7 -4
  21. package/src/common/accordion/stories/data.tsx +140 -19
  22. package/src/common/accordion/types.d.ts +55 -47
  23. package/src/common/alert/Header.tsx +29 -0
  24. package/src/common/alert/NsAlert.spec.tsx +46 -13
  25. package/src/common/alert/NsAlert.stories.tsx +3 -3
  26. package/src/common/alert/{NsAlert.styled.ts → NsAlert.styled.tsx} +22 -22
  27. package/src/common/alert/NsAlert.tsx +22 -87
  28. package/src/common/alert/types.d.ts +7 -7
  29. package/src/common/auth-dropdown/NsAuthDropdown.spec.tsx +23 -5
  30. package/src/common/auth-dropdown/NsAuthDropdown.stories.tsx +1 -1
  31. package/src/common/auth-dropdown/NsAuthDropdown.styled.ts +11 -7
  32. package/src/common/auth-dropdown/NsAuthDropdown.tsx +4 -4
  33. package/src/common/autocomplete/NsAutocomplete.spec.tsx +34 -11
  34. package/src/common/autocomplete/NsAutocomplete.stories.tsx +19 -3
  35. package/src/common/autocomplete/NsAutocomplete.tsx +63 -24
  36. package/src/common/autocomplete/mock/MockData.ts +50 -7
  37. package/src/common/autocomplete/mock/MockUI.tsx +2 -1
  38. package/src/common/autocomplete/types.d.ts +7 -4
  39. package/src/common/banner/NsBanner.spec.tsx +12 -3
  40. package/src/common/banner/NsBanner.stories.tsx +1 -1
  41. package/src/common/brand-components/NsBrand.stories.tsx +1 -1
  42. package/src/common/brand-components/NsBrandComponent.tsx +2 -2
  43. package/src/common/breadcrumb/NsBreadcrumb.spec.tsx +8 -3
  44. package/src/common/breadcrumb/NsBreadcrumb.stories.tsx +1 -1
  45. package/src/common/breadcrumb/data.ts +8 -5
  46. package/src/common/button/NsButton.spec.tsx +65 -49
  47. package/src/common/button/NsButton.stories.tsx +59 -2
  48. package/src/common/button/NsButton.styled.tsx +49 -66
  49. package/src/common/button/NsButton.tsx +1 -2
  50. package/src/common/button/helper.ts +82 -0
  51. package/src/common/button/types.d.ts +2 -0
  52. package/src/common/card/NsFfgCard.tsx +13 -7
  53. package/src/common/card/specs/NsFfgCard.spec.tsx +18 -8
  54. package/src/common/card/stories/NsBgCard.stories.tsx +1 -1
  55. package/src/common/card/stories/NsBrandProductCard.stories.tsx +1 -1
  56. package/src/common/card/stories/NsFfgCard.stories.tsx +48 -15
  57. package/src/common/card/styled/NsFfgStyled.tsx +10 -7
  58. package/src/common/card/types.d.ts +7 -4
  59. package/src/common/carousal/NsCarousal.tsx +3 -9
  60. package/src/common/carousal/stories/NSCarousal.stories.tsx +1 -1
  61. package/src/common/carousal/stories/NsScrollingCarousal.stories.tsx +1 -1
  62. package/src/common/cart-icon/NsCartIcon.spec.tsx +5 -16
  63. package/src/common/cart-icon/NsCartIcon.stories.tsx +2 -2
  64. package/src/common/cart-icon/NsCartIcon.styled.ts +7 -33
  65. package/src/common/cart-icon/NsCartIcon.tsx +5 -14
  66. package/src/common/cart-icon/types.d.ts +1 -0
  67. package/src/common/checkbox/NsCheckbox.stories.tsx +1 -1
  68. package/src/common/checkbox/NsCheckbox.styled.tsx +15 -16
  69. package/src/common/checkbox/NsCheckbox.tsx +1 -1
  70. package/src/common/column-control/stories/DivArray.stories.tsx +1 -1
  71. package/src/common/column-control/stories/NsColumnControl.stories.tsx +1 -1
  72. package/src/common/column-control/stories/NsFlexColumns.stories.tsx +1 -1
  73. package/src/common/column-control/stories/NsGridColumns.stories.tsx +1 -1
  74. package/src/common/column-control/styled/common.ts +1 -1
  75. package/src/common/column-control/utils.ts +4 -4
  76. package/src/common/common.types.d.ts +14 -5
  77. package/src/common/dropdown/NsDropdown.styled.tsx +23 -18
  78. package/src/common/dropdown/stories/NsDropdown.stories.tsx +1 -1
  79. package/src/common/dropdown/stories/NsDropdownCountry.stories.tsx +1 -1
  80. package/src/common/flag/NsFlag.stories.tsx +1 -1
  81. package/src/common/hooks/index.ts +2 -0
  82. package/src/common/hooks/specs/useWindowSize.spec.tsx +19 -0
  83. package/src/common/hooks/useAccordionMap.tsx +39 -0
  84. package/src/common/hooks/useWindowSize.tsx +30 -0
  85. package/src/common/icon/NsIcon.spec.tsx +1 -1
  86. package/src/common/icon/NsIcon.stories.tsx +4 -1
  87. package/src/common/icon/NsIcon.tsx +6 -2
  88. package/src/common/icon/NsIconVariants.ts +4 -1
  89. package/src/common/icon/icons/AlertErrorIcon.tsx +2 -2
  90. package/src/common/icon/icons/ArrowLeft.tsx +3 -6
  91. package/src/common/icon/icons/ArrowRight.tsx +6 -8
  92. package/src/common/icon/icons/Cart.tsx +7 -32
  93. package/src/common/icon/icons/CartBadge.tsx +2 -2
  94. package/src/common/icon/icons/CloseIcon.tsx +1 -1
  95. package/src/common/icon/icons/ErrorIcon.tsx +2 -2
  96. package/src/common/icon/icons/HamburgerIcon.tsx +5 -2
  97. package/src/common/icon/icons/SearchIcon.tsx +1 -1
  98. package/src/common/icon/icons/SuccessIcon.tsx +2 -7
  99. package/src/common/icon/icons/TrashIcon.tsx +1 -1
  100. package/src/common/icon/icons/UserIcon.tsx +3 -6
  101. package/src/common/icon/icons/UserOutline.tsx +24 -0
  102. package/src/common/icon/icons/WarningIcon.tsx +1 -1
  103. package/src/common/icon/icons/home.tsx +1 -1
  104. package/src/common/image/NsImage.spec.tsx +56 -6
  105. package/src/common/image/NsImage.stories.tsx +1 -1
  106. package/src/common/image/NsImage.tsx +23 -11
  107. package/src/common/image/NsNextImage.stories.tsx +1 -1
  108. package/src/common/index.ts +6 -2
  109. package/src/common/input/InputWrapper.tsx +12 -7
  110. package/src/common/input/NsInputField.tsx +1 -1
  111. package/src/common/label/NsLabel.stories.tsx +1 -1
  112. package/src/common/link/NsLink.stories.tsx +1 -1
  113. package/src/common/modal/NsModal.spec.tsx +46 -0
  114. package/src/common/modal/NsModal.styled.tsx +28 -0
  115. package/src/common/modal/NsModal.tsx +37 -0
  116. package/src/common/modal/helper-component/NsModalContentBox.tsx +32 -0
  117. package/src/common/modal/helper-component/NsModalDefault.tsx +25 -0
  118. package/src/common/modal/helper-component/NsModalStatus.tsx +15 -0
  119. package/src/common/modal/helper-component/NsModalStatusIcon.tsx +14 -0
  120. package/src/common/modal/helper-component/NsModalTitle.tsx +26 -0
  121. package/src/common/modal/index.ts +2 -0
  122. package/src/common/modal/model/NsModalVariantMap.tsx +24 -0
  123. package/src/common/modal/stories/NsModal.stories.tsx +85 -0
  124. package/src/common/modal/stories/mock.tsx +46 -0
  125. package/src/common/modal/types.ts +56 -0
  126. package/src/common/nav-product-card/NsNavProductCard.stories.tsx +1 -1
  127. package/src/common/nav-tab/NavDrawer.tsx +34 -0
  128. package/src/common/nav-tab/NavTitles.tsx +52 -0
  129. package/src/common/nav-tab/NsNavTab.spec.tsx +4 -5
  130. package/src/common/nav-tab/NsNavTab.stories.tsx +4 -4
  131. package/src/common/nav-tab/NsNavTab.styled.tsx +13 -7
  132. package/src/common/nav-tab/NsNavTab.tsx +21 -75
  133. package/src/common/nav-tab/index.ts +1 -1
  134. package/src/common/nav-tab/types.d.ts +3 -3
  135. package/src/common/radiogroup/NsRadioGroup.spec.tsx +24 -25
  136. package/src/common/radiogroup/NsRadioGroup.stories.tsx +14 -32
  137. package/src/common/radiogroup/NsRadioGroup.styled.tsx +20 -19
  138. package/src/common/radiogroup/NsRadioGroup.tsx +6 -5
  139. package/src/common/search-bar/NsSearchBar.tsx +1 -3
  140. package/src/common/select/NsSelect.spec.tsx +10 -17
  141. package/src/common/select/NsSelect.styled.tsx +53 -34
  142. package/src/common/select/stories/NsSelect.stories.tsx +11 -11
  143. package/src/common/select/types.d.ts +3 -3
  144. package/src/common/spinner/NsSpinner.spec.tsx +21 -0
  145. package/src/common/spinner/NsSpinner.stories.tsx +26 -0
  146. package/src/common/spinner/NsSpinner.styled.tsx +344 -0
  147. package/src/common/spinner/NsSpinner.tsx +14 -0
  148. package/src/common/spinner/icons/Spinner.tsx +161 -0
  149. package/src/common/spinner/index.ts +2 -0
  150. package/src/common/spinner/types.ts +5 -0
  151. package/src/common/table/NsTable.stories.tsx +1 -1
  152. package/src/common/table/NsTable.tsx +32 -49
  153. package/src/common/table/NsTableHeader.tsx +30 -51
  154. package/src/common/text-strip/NsTextStrip.stories.tsx +1 -1
  155. package/src/common/typography/NsTypography.stories.tsx +1 -1
  156. package/src/common/util.ts +1 -0
  157. package/src/common/utility/Show.tsx +13 -0
  158. package/src/common/utility/index.ts +1 -0
  159. package/src/common/videos/NsVideo.stories.tsx +1 -1
  160. package/src/common/videos/types.d.ts +1 -1
  161. /package/src/common/brand-components/{NsBrandContanier.styled.tsx → NsBrandContainer.styled.tsx} +0 -0
@@ -1,36 +1,128 @@
1
1
  import React from 'react';
2
2
  import { render, screen } from '@/test-utils/index';
3
- import { NsCollapse, AccordionVariant } from '@/common/index';
3
+ import { NsCollapse, AccordionVariant, AccordionItem } from '@/common/index';
4
+ import { createAccordionItem3_1 } from '../stories/data';
4
5
 
5
6
  describe('NsCollapse', () => {
6
- it('renders children when isOpen is true', () => {
7
+ it('1. renders children when isOpen is true', () => {
7
8
  const { getByText } = render(
8
- <NsCollapse isOpen variant={AccordionVariant.Basic}>
9
- <div>Child 1</div>
10
- <div>Child 2</div>
11
- </NsCollapse>
9
+ <NsCollapse
10
+ isOpen
11
+ variant={AccordionVariant.Basic}
12
+ content={
13
+ <>
14
+ <div>Child 1</div>
15
+ <div>Child 2</div>
16
+ </>
17
+ }
18
+ type="jsx"
19
+ isChild={false}
20
+ invert={false}
21
+ level={0}
22
+ />
12
23
  );
13
24
  expect(getByText('Child 1')).toBeInTheDocument();
14
25
  expect(getByText('Child 2')).toBeInTheDocument();
15
26
  });
27
+ it('2. renders children when isOpen is true and isChild is true', () => {
28
+ const content = 'renders children when isOpen is true and isChild is true';
29
+ const { getByText } = render(
30
+ <NsCollapse
31
+ isOpen
32
+ type="text"
33
+ variant={AccordionVariant.Basic}
34
+ content={content}
35
+ isChild={true}
36
+ invert={false}
37
+ level={0}
38
+ />
39
+ );
40
+ expect(getByText(content)).toBeInTheDocument();
41
+ });
42
+ it('3. renders children when isOpen is true and variant is compact and content is of type accordion', () => {
43
+ const accItem = createAccordionItem3_1();
44
+ const content = accItem.content as AccordionItem[];
45
+ const { getByText } = render(
46
+ <NsCollapse
47
+ isOpen
48
+ variant={AccordionVariant.Compact}
49
+ content={content}
50
+ type={accItem.type}
51
+ isChild={true}
52
+ invert={false}
53
+ level={0}
54
+ />
55
+ );
56
+ expect(getByText(content[0].title)).toBeInTheDocument();
57
+ expect(getByText(content[1].title)).toBeInTheDocument();
58
+ });
16
59
 
17
- it('does not render children when isOpen is false', () => {
60
+ it('4. does not render children when isOpen is false', () => {
61
+ const content = '<h2>Lorem ipsum dolor sit amet.</h2>';
62
+ render(
63
+ <NsCollapse
64
+ isOpen={false}
65
+ variant={AccordionVariant.Basic}
66
+ type="html"
67
+ content={content}
68
+ isChild={false}
69
+ invert={true}
70
+ level={0}
71
+ />
72
+ );
73
+ expect(screen.queryByText(content)).toBeNull();
74
+ });
75
+ it('5. renders html children when isOpen is true', () => {
76
+ const content = '<h2>Lorem ipsum dolor sit amet.</h2>';
18
77
  render(
19
- <NsCollapse isOpen={false} variant={AccordionVariant.Basic}>
20
- <div>Child 1</div>
21
- <div>Child 2</div>
22
- </NsCollapse>
78
+ <NsCollapse
79
+ isOpen={true}
80
+ variant={AccordionVariant.Compact}
81
+ type="html"
82
+ content={content}
83
+ isChild={false}
84
+ invert={true}
85
+ level={0}
86
+ />
23
87
  );
24
- expect(screen.queryByText('Child')).toBeNull();
88
+ expect(screen.queryByText(content)).toBeDefined();
25
89
  });
26
90
 
27
- it('renders with additional class name', () => {
91
+ it('6. renders with additional class name', () => {
92
+ const additionalClassName = 'custom-class';
93
+ const { container } = render(
94
+ <NsCollapse
95
+ type="jsx"
96
+ isOpen
97
+ variant={AccordionVariant.Gray}
98
+ content={
99
+ <>
100
+ <div>Child 1</div>
101
+ <div>Child 2</div>
102
+ </>
103
+ }
104
+ additionalProps={{ className: additionalClassName }}
105
+ isChild={false}
106
+ invert={false}
107
+ level={7}
108
+ />
109
+ );
110
+ expect(container.querySelector('section')).toHaveClass(`ns-collapse ${additionalClassName}`);
111
+ });
112
+ it('7. skipping allowMultipleExpanded in child data', () => {
113
+ const { content, type } = createAccordionItem3_1();
28
114
  const additionalClassName = 'custom-class';
29
115
  const { container } = render(
30
- <NsCollapse additionalProps={{ className: additionalClassName }} isOpen variant={AccordionVariant.Basic}>
31
- <div>Child 1</div>
32
- <div>Child 2</div>
33
- </NsCollapse>
116
+ <NsCollapse
117
+ type={type}
118
+ isOpen
119
+ variant={AccordionVariant.Gray}
120
+ content={content}
121
+ additionalProps={{ className: additionalClassName }}
122
+ isChild={false}
123
+ invert={true}
124
+ level={7}
125
+ />
34
126
  );
35
127
  expect(container.querySelector('section')).toHaveClass(`ns-collapse ${additionalClassName}`);
36
128
  });
@@ -6,33 +6,69 @@ import { render, fireEvent } from '@/test-utils/index';
6
6
 
7
7
  describe('NsToggleSection', () => {
8
8
  const title = 'Toggle Section Title';
9
- const content = 'Toggle Section Content';
10
-
11
- it('renders title correctly', () => {
9
+ const contentText = 'Toggle Section Content';
10
+ const content = <div className="p-2">{contentText}</div>;
11
+ it('1. renders title correctly', () => {
12
12
  const { getByText } = render(
13
- <NsToggleSection variant={AccordionVariant.Basic} title={title}>{content}</NsToggleSection>
13
+ <NsToggleSection
14
+ variant={AccordionVariant.Basic}
15
+ title={title}
16
+ content={content}
17
+ invert={false}
18
+ isChild={false}
19
+ type="jsx"
20
+ />
21
+ );
22
+ expect(getByText(title)).toBeInTheDocument();
23
+ });
24
+ it('2. renders title correctly', () => {
25
+ const { getByText } = render(
26
+ <NsToggleSection
27
+ variant={AccordionVariant.Compact}
28
+ title={title}
29
+ content={content}
30
+ invert={false}
31
+ isChild={false}
32
+ type="jsx"
33
+ />
14
34
  );
15
35
  expect(getByText(title)).toBeInTheDocument();
16
36
  });
17
37
 
18
- it('toggles content visibility when clicked on the section header', () => {
38
+ it('2. toggles content visibility when clicked on the section header', () => {
19
39
  const { getByText, queryByText } = render(
20
- <NsToggleSection variant={AccordionVariant.Basic} title={title}>{content}</NsToggleSection>
40
+ <NsToggleSection
41
+ variant={AccordionVariant.Basic}
42
+ title={title}
43
+ content={content}
44
+ invert={false}
45
+ isChild={false}
46
+ type="jsx"
47
+ />
21
48
  );
22
- expect(queryByText(content)).toBeNull();
49
+ const el = queryByText(contentText);
50
+ expect(el?.parentNode).toHaveStyle('opacity: 0;');
51
+
23
52
  fireEvent.click(getByText(title));
24
- expect(getByText(content)).toBeInTheDocument();
53
+ expect(el?.parentNode).toHaveStyle('opacity: 1;');
54
+
25
55
  fireEvent.click(getByText(title));
26
- expect(queryByText(content)).toBeNull();
56
+ expect(el?.parentNode).toHaveStyle('opacity: 0;');
27
57
  });
28
58
 
29
- it('sets defaultOpen prop correctly', () => {
59
+ it('3. sets defaultOpen prop correctly', () => {
30
60
  const { getByText } = render(
31
- <NsToggleSection variant={AccordionVariant.Basic} title={title} defaultOpen>
32
- {content}
33
- </NsToggleSection>
61
+ <NsToggleSection
62
+ variant={AccordionVariant.Basic}
63
+ title={title}
64
+ content={content}
65
+ invert={false}
66
+ isChild={false}
67
+ defaultOpen
68
+ type="jsx"
69
+ />
34
70
  );
35
71
 
36
- expect(getByText(content)).toBeInTheDocument();
72
+ expect(getByText(contentText)).toBeInTheDocument();
37
73
  });
38
74
  });
@@ -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 '../NsAccordion';
4
- import { contentArray } from './data';
5
- import { AccordionVariant } from '../types.d';
6
-
7
- type ComponentType = typeof NsAccordion;
8
- type Story = StoryObj<ComponentType>;
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
- contentArray: {
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
  },
@@ -26,22 +22,44 @@ export default {
26
22
  control: 'select',
27
23
  options: [...Object.values(AccordionVariant)],
28
24
  },
25
+ level: {
26
+ control: 'number',
27
+ description: `level = 1 means no padding on left from parent to child,
28
+ level = 2 means padding of 16px, level = 3 means padding of 32px and so on ..`,
29
+ },
29
30
  },
30
31
  args: {
31
32
  variant: AccordionVariant.Basic,
33
+ invert: false,
34
+ level: 2,
32
35
  },
33
- } as MetaStory;
36
+ } satisfies MetaStory;
37
+
38
+ export default meta;
39
+
40
+ type MetaStory = Meta<typeof NsAccordion>;
41
+ type Story = StoryObj<typeof meta>;
34
42
 
35
43
  export const SingleOpen: Story = {
36
44
  args: {
37
45
  allowMultipleExpanded: false,
38
- contentArray,
46
+ items: getAccordionData(),
47
+ invert: false,
48
+ },
49
+ play: ({ canvasElement }) => {
50
+ const canvas = within(canvasElement);
51
+ const el1 = canvas.getByText('Example - 1 JSX');
52
+ expect(el1).toBeInTheDocument();
53
+ expect(el1.closest('header')).toHaveAttribute('aria-expanded', 'true');
54
+ const el2 = canvas.getByText('Example - 2');
55
+ expect(el2).toBeInTheDocument();
56
+ expect(el2.closest('header')).toHaveAttribute('aria-expanded', 'false');
39
57
  },
40
58
  };
41
59
 
42
60
  export const MultipleOpen: Story = {
43
61
  args: {
44
62
  allowMultipleExpanded: true,
45
- contentArray,
63
+ items: getAccordionData(),
46
64
  },
47
65
  };
@@ -1,13 +1,13 @@
1
1
  import type { StoryObj, Meta } from '@storybook/react';
2
2
  import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
3
- import { NsAccordionHeader, NsIconVariants } from '../..';
3
+ import { AccordionVariant, NsAccordionHeader, NsIconVariants } from '../..';
4
4
 
5
5
  type ComponentType = typeof NsAccordionHeader;
6
6
  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: {
@@ -23,9 +23,13 @@ export default {
23
23
  },
24
24
  args: {
25
25
  title: 'Nuskin',
26
+ variant: AccordionVariant.Compact,
26
27
  onClick: () => {
27
28
  console.log('accordion header clicked');
28
29
  },
30
+ startIcon: {
31
+ name: 'home',
32
+ },
29
33
  openedIconName: 'arrowUp',
30
34
  closedIconName: 'arrowDown',
31
35
  isOpen: false,
@@ -1,13 +1,14 @@
1
1
  import type { StoryObj, Meta } from '@storybook/react';
2
2
  import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
3
- import { NsAccordionItem } from '@/common/index';
3
+ import { AccordionVariant, NsAccordionItem } from '../../';
4
+ import NsAccordionStory from './NsAccordion.stories';
4
5
 
5
6
  type ComponentType = typeof NsAccordionItem;
6
7
  type Story = StoryObj<ComponentType>;
7
8
  type MetaStory = Meta<ComponentType>;
8
9
 
9
10
  export default {
10
- title: 'Components/Accordion/NsAccordionItem',
11
+ title: 'Components/Containers/Accordion/NsAccordionItem',
11
12
  component: NsAccordionItem,
12
13
  decorators: [withCenterDecorator],
13
14
  argTypes: {
@@ -20,21 +21,25 @@ export default {
20
21
  control: 'string',
21
22
  description: 'text used for header of section',
22
23
  },
24
+ level: NsAccordionStory.argTypes.level,
25
+ variant: NsAccordionStory.argTypes.variant,
23
26
  },
24
27
  } as MetaStory;
25
28
 
26
29
  export const OpenSection: Story = {
27
30
  args: {
31
+ variant: AccordionVariant.Compact,
28
32
  isOpen: true,
29
- content: 'Nuskin Description',
33
+ content: <div className="p-2">Nuskin Description</div>,
30
34
  title: 'Nuskin',
31
35
  },
32
36
  };
33
37
 
34
38
  export const ClosedSection: Story = {
35
39
  args: {
40
+ variant: AccordionVariant.Compact,
36
41
  isOpen: false,
37
- content: 'Nuskin Description',
42
+ content: <div className="p-2">Nuskin Description</div>,
38
43
  title: 'Nuskin',
39
44
  },
40
45
  };
@@ -1,13 +1,14 @@
1
1
  import type { StoryObj, Meta } from '@storybook/react';
2
2
  import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
3
- import { NsCollapse } from '../';
3
+ import { AccordionContentTypeObject, AccordionVariant, NsCollapse } from '../';
4
+ import NsAccordionStory from './NsAccordion.stories';
4
5
 
5
6
  type ComponentType = typeof NsCollapse;
6
7
  type Story = StoryObj<ComponentType>;
7
8
  type MetaStory = Meta<ComponentType>;
8
9
 
9
10
  export default {
10
- title: 'Components/Accordion/NsCollapse',
11
+ title: 'Components/Containers/Accordion/NsCollapse',
11
12
  component: NsCollapse,
12
13
  decorators: [withCenterDecorator],
13
14
  argTypes: {
@@ -15,21 +16,35 @@ export default {
15
16
  control: 'boolean',
16
17
  description: 'if true renders NsCollapse in open state, and close state otherwise',
17
18
  },
18
- children: {
19
+ content: {
19
20
  control: 'React Node',
20
21
  description: 'Content for NsCollapse',
21
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: Object.values(AccordionContentTypeObject),
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,
22
37
  },
23
38
  } as MetaStory;
24
39
  export const Closed: Story = {
25
40
  args: {
26
41
  isOpen: false,
27
- children: 'Nuskin Description',
42
+ content: <div className="p-2">Nuskin Description</div>,
28
43
  },
29
44
  };
30
45
  export const Open: Story = {
31
46
  args: {
32
47
  isOpen: true,
33
- children: 'Nuskin Description',
48
+ content: <div className="p-2">Nuskin Description</div>,
34
49
  },
35
50
  };
@@ -1,22 +1,25 @@
1
1
  import type { StoryObj, Meta } from '@storybook/react';
2
2
  import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
3
- import { NsToggleSection } from '../..';
3
+ import { AccordionVariant, NsToggleSection } from '../..';
4
+ import NsAccordionStory from './NsAccordion.stories';
4
5
 
5
6
  type ComponentType = typeof NsToggleSection;
6
7
  type Story = StoryObj<ComponentType>;
7
8
  type MetaStory = Meta<ComponentType>;
8
9
 
9
10
  export default {
10
- title: 'Components/Accordion/NsToggleSection',
11
+ title: 'Components/Containers/Accordion/NsToggleSection',
11
12
  component: NsToggleSection,
12
13
  decorators: [withCenterDecorator],
13
14
  argTypes: {
15
+ level: NsAccordionStory.argTypes.level,
16
+ variant: NsAccordionStory.argTypes.variant,
14
17
  title: { control: 'string' },
15
18
  },
16
19
  args: {
20
+ variant: AccordionVariant.Compact,
17
21
  title: 'Nuskin',
18
- children: 'Nuskin Details',
19
-
22
+ content: <div className="p-2">Nuskin Details</div>,
20
23
  },
21
24
  } as MetaStory;
22
25
 
@@ -1,22 +1,143 @@
1
- import { NsAccordionProps } from '../types';
1
+ import { AccordionContentTypeObject, NsIconProps } from '../..';
2
+ import { AccordionItem } from '../types';
2
3
 
3
- export const contentArray: NsAccordionProps['contentArray'] = [
4
- {
5
- title: 'Nuskin',
6
- body: <div>Nuskin Details</div>,
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: AccordionContentTypeObject.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: AccordionContentTypeObject.jsx,
7
37
  isDefaultOpen: true,
8
- },
9
- {
10
- title: 'Nuskin',
11
- body: <div>Nuskin Details</div>,
38
+ };
39
+ }
40
+ function createAccordionItem2(): AccordionItem {
41
+ return {
42
+ ...getItem(),
12
43
  isDefaultOpen: true,
13
- },
14
- {
15
- title: 'Nuskin',
16
- body: <div>Nuskin Details</div>,
17
- },
18
- {
19
- title: 'Nuskin',
20
- body: <div>Nuskin Details</div>,
21
- },
22
- ];
44
+ icon: getIcon(),
45
+ title: 'Example - 2',
46
+ type: AccordionContentTypeObject.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: AccordionContentTypeObject.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: AccordionContentTypeObject.accordion,
65
+ content: [
66
+ createAccordionItem3_1(),
67
+ {
68
+ ...getItem(),
69
+
70
+ title: 'Example - 3.2',
71
+ type: AccordionContentTypeObject.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: AccordionContentTypeObject.accordion,
84
+ content: [
85
+ {
86
+ ...getItem(),
87
+ title: 'Example - 3.1.1',
88
+ type: AccordionContentTypeObject.text,
89
+ content: dummyText,
90
+ },
91
+ {
92
+ ...getItem(),
93
+ title: 'Example - 3.1.2',
94
+ type: AccordionContentTypeObject.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: AccordionContentTypeObject.accordion,
107
+ content: [
108
+ createAccordionItem4_1(),
109
+ {
110
+ ...getItem(),
111
+ title: 'Example - 4.2',
112
+ type: AccordionContentTypeObject.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: AccordionContentTypeObject.accordion,
124
+ content: [
125
+ {
126
+ ...getItem(),
127
+
128
+ title: 'Example - 4.1.1',
129
+ type: AccordionContentTypeObject.text,
130
+ content: dummyText,
131
+ },
132
+ {
133
+ ...getItem(),
134
+ type: AccordionContentTypeObject.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
+ }