@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,25 +1,17 @@
1
1
  import React, { useState, useEffect } from 'react';
2
- import {
3
- TableBody,
4
- TableCell,
5
- TableRow
6
- } from '@mui/material';
2
+ import { TableBody, TableCell, TableRow } from '@mui/material';
7
3
  import {
8
4
  StyledTable,
9
5
  StyledTableContainer,
10
6
  StyledEmptyRow,
11
7
  StyledProgressCell,
12
- StyledLinearProgress
13
- } from './NsTable.styled'
14
- import type {
15
- NsTableProps,
16
- Item,
17
- OrderType,
18
- } from './types'
19
- import {stableSort, getComparator} from './helper'
8
+ StyledLinearProgress,
9
+ } from './NsTable.styled';
10
+ import type { NsTableProps, Item, OrderType } from './types';
11
+ import { stableSort, getComparator } from './helper';
20
12
  import NsTableHeader from './NsTableHeader';
21
- import NsTablePagination from './NsTablePagination'
22
- import ExpandableRow from './NsExpandableRow'
13
+ import NsTablePagination from './NsTablePagination';
14
+ import ExpandableRow from './NsExpandableRow';
23
15
  import Grid from '@mui/material/Grid';
24
16
 
25
17
  export default function NsTable({
@@ -37,13 +29,11 @@ export default function NsTable({
37
29
  }: NsTableProps) {
38
30
  const [order, setOrder] = useState<OrderType>('asc');
39
31
  const [orderBy, setOrderBy] = useState<keyof Item>(itemKey);
40
- const [expandList, setExpandList] = useState<number[]>([]);
32
+ const [expandMap, setExpandMap] = useState<{ [key: number]: boolean }>({});
41
33
  const [page, setPage] = useState(0);
42
34
  const [rowsPerPage, setRowsPerPage] = useState(rows);
43
- const [itemKeyList, setItemKeyList] = useState<string[]>([]);
44
-
45
- useEffect(() => {
46
- if (items.length) setItemKeyList(Object.keys(items[0]));
35
+ const itemKeyList = React.useMemo(() => {
36
+ return items.length ? Object.keys(items[0]) : [];
47
37
  }, [items]);
48
38
 
49
39
  useEffect(() => {
@@ -58,27 +48,18 @@ export default function NsTable({
58
48
  };
59
49
 
60
50
  const handleClick = (index: number) => {
61
- if(isExpandableAll) {
62
- let newList = expandList;
63
- if(newList.includes(index)) {
64
- let num = newList.indexOf(index);
65
- if (num > -1) newList.splice(num, 1);
66
- } else {
67
- newList.push(index);
68
- }
69
- setExpandList([...newList]);
51
+ if (isExpandableAll) {
52
+ setExpandMap((prevState) => ({ ...prevState, [index]: !prevState[index] }));
70
53
  } else {
71
- if(expandList.includes(index)) setExpandList([])
72
- else setExpandList([index])
54
+ setExpandMap({ [index]: !expandMap[index] });
73
55
  }
74
56
  };
75
57
 
76
58
  const handleChangePage = (newPage: number) => {
77
- setPage(newPage-1);
59
+ setPage(newPage - 1);
78
60
  };
79
-
80
- const emptyRows =
81
- page > 0 ? Math.max(0, (1 + page) * rowsPerPage - items.length) : 0;
61
+
62
+ const emptyRows = getEmptyRows();
82
63
 
83
64
  const visibleRows = React.useMemo(
84
65
  () =>
@@ -101,25 +82,23 @@ export default function NsTable({
101
82
  rowCount={items.length}
102
83
  />
103
84
  <TableBody>
104
- {
105
- loading ? (
106
- <TableRow>
107
- <StyledProgressCell colSpan={itemKeyList.length}>
108
- <Grid container>
109
- <Grid item xs={12}>
110
- <StyledLinearProgress />
111
- </Grid>
85
+ {loading ? (
86
+ <TableRow>
87
+ <StyledProgressCell colSpan={itemKeyList.length}>
88
+ <Grid container>
89
+ <Grid item xs={12}>
90
+ <StyledLinearProgress />
112
91
  </Grid>
113
- </StyledProgressCell>
114
- </TableRow>
115
- ) : null
116
- }
92
+ </Grid>
93
+ </StyledProgressCell>
94
+ </TableRow>
95
+ ) : null}
117
96
  {visibleRows.map((row, index) => {
118
97
  return (
119
98
  <ExpandableRow
120
99
  key={index}
121
100
  expandableContent={expandableContent}
122
- isExpand={expandList.includes(index)}
101
+ isExpand={expandMap[index]}
123
102
  handleClick={handleClick}
124
103
  row={row}
125
104
  index={index}
@@ -142,9 +121,13 @@ export default function NsTable({
142
121
  rowsPerPageOptions={rowsPerPageOptions}
143
122
  count={items.length}
144
123
  rowsPerPage={rowsPerPage}
145
- page={page+1}
124
+ page={page + 1}
146
125
  onPageChange={handleChangePage}
147
126
  />
148
127
  </div>
149
128
  );
129
+
130
+ function getEmptyRows() {
131
+ return page > 0 ? Math.max(0, (1 + page) * rowsPerPage - items.length) : 0;
132
+ }
150
133
  }
@@ -1,61 +1,40 @@
1
- import type { NsTableHeaderProps, Item} from './types'
2
- import React from 'react'
3
- import {
4
- TableHead,
5
- TableRow,
6
- Box,
7
- TableCell
8
- } from '@mui/material';
9
- import {
10
- StyledTableSortLabel,
11
- StyledTableLabel
12
- } from './NsTable.styled'
1
+ import type { NsTableHeaderProps, Item } from './types';
2
+ import React from 'react';
3
+ import { TableHead, TableRow, Box, TableCell } from '@mui/material';
4
+ import { StyledTableSortLabel, StyledTableLabel } from './NsTable.styled';
13
5
  import { visuallyHidden } from '@mui/utils';
14
6
 
15
7
  export default function NsTableHeader(props: NsTableHeaderProps) {
16
- const {
17
- order,
18
- orderBy,
19
- headCells,
20
- onRequestSort,
21
- } = props;
22
- const createSortHandler =
23
- (property: keyof Item) => (event: React.MouseEvent<unknown>) => { onRequestSort(event, property);};
24
-
8
+ const { order, orderBy, headCells, onRequestSort } = props;
9
+ const createSortHandler = (property: keyof Item) => (event: React.MouseEvent<unknown>) => {
10
+ onRequestSort(event, property);
11
+ };
12
+
25
13
  return (
26
14
  <TableHead>
27
15
  <TableRow>
28
- {
29
- headCells.map((headCell) => (
30
- headCell.sortable ? (
31
- <TableCell
32
- key={headCell.id}
33
- sortDirection={orderBy == headCell.id ? order : false}
16
+ {headCells.map((headCell) =>
17
+ headCell.sortable ? (
18
+ <TableCell key={headCell.id} sortDirection={orderBy === headCell.id ? order : false}>
19
+ <StyledTableSortLabel
20
+ active={orderBy === headCell.id}
21
+ direction={orderBy === headCell.id ? order : 'asc'}
22
+ onClick={createSortHandler(headCell.id)}
34
23
  >
35
- <StyledTableSortLabel
36
- active={orderBy == headCell.id}
37
- direction={orderBy == headCell.id ? order : 'asc'}
38
- onClick={createSortHandler(headCell.id)}
39
- >
40
- {headCell.label}
41
- {orderBy === headCell.id ? (
42
- <Box component="span" sx={visuallyHidden}>
43
- {order === 'desc' ? 'sorted descending' : 'sorted ascending'}
44
- </Box>
45
- ) : null}
46
- </StyledTableSortLabel>
47
- </TableCell>)
48
- : (
49
- <TableCell
50
- key={headCell.id}
51
- sortDirection={false}
52
- >
53
- <StyledTableLabel>
54
- {headCell.label}
55
- </StyledTableLabel>
56
- </TableCell>
57
- )
58
- ))}
24
+ {headCell.label}
25
+ {orderBy === headCell.id ? (
26
+ <Box component="span" sx={visuallyHidden}>
27
+ {order === 'desc' ? 'sorted descending' : 'sorted ascending'}
28
+ </Box>
29
+ ) : null}
30
+ </StyledTableSortLabel>
31
+ </TableCell>
32
+ ) : (
33
+ <TableCell key={headCell.id} sortDirection={false}>
34
+ <StyledTableLabel>{headCell.label}</StyledTableLabel>
35
+ </TableCell>
36
+ )
37
+ )}
59
38
  </TableRow>
60
39
  </TableHead>
61
40
  );
@@ -12,7 +12,7 @@ type Story = StoryObj<ComponentType>;
12
12
  type MetaStory = Meta<ComponentType>;
13
13
 
14
14
  export default {
15
- title: 'Components/NsTextStrip',
15
+ title: 'Components/Data Display/NsTextStrip',
16
16
  component: NsTextStrip,
17
17
  decorators: [withCenterDecorator],
18
18
  argTypes: {
@@ -7,7 +7,7 @@ type Story = StoryObj<ComponentType>;
7
7
  type MetaStory = Meta<ComponentType>;
8
8
 
9
9
  export default {
10
- title: 'Components/NsTypography',
10
+ title: 'Components/Data Display/NsTypography',
11
11
  component: NsTypography,
12
12
  decorators: [withCenterDecorator],
13
13
  argTypes: {
@@ -0,0 +1 @@
1
+ export const skipDarkModeEnabled = (key: string) => key !== 'darkModeEnabled';
@@ -0,0 +1,13 @@
1
+ import { PropsWithChildren, ReactElement } from 'react';
2
+
3
+ type ShowType = PropsWithChildren & {
4
+ when?: boolean;
5
+ elseContent?: ReactElement;
6
+ };
7
+ const Show = ({ when, children, elseContent }: ShowType): ReactElement => {
8
+ if (when) {
9
+ return <>{children}</>;
10
+ }
11
+ return <>{elseContent}</>;
12
+ };
13
+ export default Show;
@@ -0,0 +1 @@
1
+ export { default as Show } from './Show';
@@ -14,7 +14,7 @@ type Story = StoryObj<ComponentType>;
14
14
  type MetaStory = Meta<ComponentType>;
15
15
 
16
16
  export default {
17
- title: 'Components/NsVideo',
17
+ title: 'Components/Data Display/NsVideo',
18
18
  component: NsVideo,
19
19
  decorators: [withCenterDecorator],
20
20
  argTypes: {
@@ -1,4 +1,4 @@
1
- import { AdditionalProps } from '@/common/common.types';
1
+ import { AdditionalProps } from '../common.types';
2
2
 
3
3
  export type NsVideoProps = {
4
4
  src: string;