@nuskin/foundation-ui-components 1.0.0-develop.2 → 1.0.0-develop.4
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 +1 -1
- package/src/common/accordion/NsAccordion.tsx +77 -0
- package/src/common/accordion/NsAccordionHeader.tsx +56 -0
- package/src/common/accordion/NsAccordionItem.tsx +39 -0
- package/src/common/accordion/NsCollapse.tsx +56 -0
- package/src/common/accordion/NsToggleSection.tsx +30 -0
- package/src/common/accordion/ToggleSection.styled.tsx +28 -0
- package/src/common/accordion/index.ts +6 -0
- package/src/common/accordion/specs/NsAccordion.spec.tsx +91 -0
- package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +47 -0
- package/src/common/accordion/specs/NsAccordionItem.spec.tsx +38 -0
- package/src/common/accordion/specs/NsCollapse.spec.tsx +37 -0
- package/src/common/accordion/specs/NsToggleSection.spec.tsx +33 -0
- package/src/common/accordion/stories/NsAccordion.stories.tsx +47 -0
- package/src/common/accordion/stories/NsAccordionHeader.stories.tsx +40 -0
- package/src/common/accordion/stories/NsAccordionItem.stories.tsx +40 -0
- package/src/common/accordion/stories/NsCollapse.stories.tsx +35 -0
- package/src/common/accordion/stories/NsToggleSection.stories.tsx +23 -0
- package/src/common/accordion/stories/data.tsx +22 -0
- package/src/common/accordion/types.d.ts +73 -0
- package/src/common/alert/NsAlert.stories.tsx +15 -14
- package/src/common/alert/types.d.ts +22 -22
- package/src/common/auth-dropdown/NsAuthDropdown.stories.tsx +1 -1
- package/src/common/autocomplete/NsAutocomplete.spec.tsx +20 -8
- package/src/common/autocomplete/NsAutocomplete.stories.tsx +4 -1
- package/src/common/autocomplete/NsAutocomplete.styled.tsx +12 -0
- package/src/common/autocomplete/NsAutocomplete.tsx +36 -18
- package/src/common/autocomplete/types.d.ts +7 -1
- package/src/common/banner/NsBanner.stories.tsx +1 -1
- package/src/common/brand-components/NsBrand.stories.tsx +1 -1
- package/src/common/breadcrumb/NsBreadcrumb.spec.tsx +1 -7
- package/src/common/breadcrumb/NsBreadcrumb.stories.tsx +2 -4
- package/src/common/breadcrumb/data.ts +7 -0
- package/src/common/button/NsButton.spec.tsx +10 -11
- package/src/common/button/NsButton.stories.tsx +1 -1
- package/src/common/card/stories/NsBgCard.stories.tsx +1 -3
- package/src/common/card/stories/NsBrandProductCard.stories.tsx +1 -1
- package/src/common/card/stories/NsFfgCard.stories.tsx +1 -1
- package/src/common/card/stories/{data.js → data.ts} +1 -25
- package/src/common/carousal/NsScrollingCarousal.tsx +26 -2
- package/src/common/carousal/stories/NsScrollingCarousal.stories.tsx +1 -1
- package/src/common/carousal/types.d.ts +2 -0
- 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 +2 -2
- package/src/common/column-control/NsFlexColumns.tsx +5 -10
- package/src/common/column-control/NsGridColumns.tsx +5 -10
- package/src/common/column-control/specs/NsColumnControl.spec.tsx +1 -1
- package/src/common/column-control/specs/NsFlexColumns.spec.tsx +1 -1
- package/src/common/column-control/specs/NsGridColumns.spec.tsx +1 -1
- 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/stories/NsColumnControl.stories.tsx +6 -3
- package/src/common/column-control/stories/NsFlexColumns.stories.tsx +13 -9
- package/src/common/column-control/stories/NsGridColumns.stories.tsx +12 -8
- package/src/common/column-control/stories/common.tsx +1 -1
- package/src/common/column-control/styled/StyledFlex.tsx +7 -3
- package/src/common/column-control/styled/StyledGrid.tsx +9 -2
- package/src/common/column-control/styled/common.ts +2 -2
- package/src/common/column-control/types.d.ts +15 -16
- package/src/common/common.types.d.ts +1 -0
- package/src/common/dropdown/stories/NsDropdown.stories.tsx +1 -1
- package/src/common/dropdown/stories/NsDropdownCountry.stories.tsx +1 -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 +4 -25
- package/src/common/flag/NsFlag.stories.tsx +1 -1
- package/src/common/flag/NsFlag.tsx +0 -2
- package/src/common/icon/NsIcon.stories.tsx +1 -1
- package/src/common/image/NsImage.stories.tsx +1 -1
- package/src/common/image/NsNextImage.stories.tsx +1 -1
- package/src/common/image/types.d.ts +1 -0
- package/src/common/index.ts +3 -0
- package/src/common/input/NsInputField.stories.tsx +13 -10
- package/src/common/input/NsInputField.tsx +12 -5
- package/src/common/input/getAdornmentProps.tsx +4 -0
- package/src/common/input/types.d.ts +18 -1
- package/src/common/label/NsLabel.stories.tsx +5 -0
- package/src/common/label/NsLabel.tsx +16 -19
- package/src/common/label/types.d.ts +2 -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.spec.tsx +0 -5
- package/src/common/nav-tab/NsNavTab.stories.tsx +1 -1
- package/src/common/radiogroup/NsRadioGroup.spec.tsx +63 -0
- package/src/common/radiogroup/NsRadioGroup.stories.tsx +101 -0
- package/src/common/radiogroup/NsRadioGroup.styled.tsx +56 -0
- package/src/common/radiogroup/NsRadioGroup.tsx +46 -0
- package/src/common/radiogroup/index.ts +2 -0
- package/src/common/radiogroup/types.d.ts +19 -0
- package/src/common/select/NsSelect.spec.tsx +200 -0
- package/src/common/select/NsSelect.styled.tsx +89 -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/table/NsExpandableRow.tsx +68 -0
- package/src/common/table/NsTable.spec.tsx +69 -41
- package/src/common/table/NsTable.stories.tsx +48 -10
- package/src/common/table/NsTable.styled.ts +95 -4
- package/src/common/table/NsTable.tsx +78 -89
- package/src/common/table/NsTableHeader.tsx +52 -38
- package/src/common/table/NsTablePagination.tsx +21 -13
- package/src/common/table/types.d.ts +21 -8
- package/src/common/text-strip/NsTextStrip.stories.tsx +5 -4
- package/src/common/text-strip/NsTextStrip.tsx +5 -2
- package/src/common/text-strip/types.d.ts +7 -4
- package/src/common/typography/NsTypography.stories.tsx +1 -1
- package/src/common/validations/regex.ts +3 -0
- package/src/common/videos/NsVideo.stories.tsx +1 -1
- package/src/common/column-control/stories/NDivs.story.tsx +0 -35
- /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/card/{tests → specs}/NsFfgCard.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/Chevron.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/NsCarousal.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/NsScrollingCarousal.spec.tsx +0 -0
- /package/src/common/carousal/{tests → specs}/RenderBrand.spec.tsx +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import React from 'react'
|
|
1
2
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
3
|
import NsTable from './NsTable';
|
|
3
4
|
import { withCenterDecorator } from '../../stories/decorators/withCenterDecorator';
|
|
5
|
+
import { Item } from './types';
|
|
6
|
+
import { NsIcon } from '../icon';
|
|
4
7
|
|
|
5
8
|
type ComponentType = typeof NsTable;
|
|
6
9
|
type Story = StoryObj<ComponentType>;
|
|
@@ -9,15 +12,16 @@ const headers = [
|
|
|
9
12
|
{
|
|
10
13
|
label: 'Dessert (100g serving)',
|
|
11
14
|
id: 'name',
|
|
12
|
-
numeric: false
|
|
15
|
+
numeric: false,
|
|
16
|
+
sortable: false
|
|
13
17
|
},
|
|
14
|
-
{ label: 'Calories', id: 'calories' , numeric: true},
|
|
15
|
-
{ label: 'Fat (g)', id: 'fat', numeric: true },
|
|
16
|
-
{ label: 'Carbs (g)', id: 'carbs', numeric: true },
|
|
17
|
-
{ label: 'Protein (g)', id: 'protein', numeric: true },
|
|
18
|
-
{ label: 'Iron (%)', id: 'iron', numeric: false },
|
|
18
|
+
{ label: 'Calories', id: 'calories' , numeric: true, sortable: true},
|
|
19
|
+
{ label: 'Fat (g)', id: 'fat', numeric: true, sortable: true },
|
|
20
|
+
{ label: 'Carbs (g)', id: 'carbs', numeric: true, sortable: true },
|
|
21
|
+
{ label: 'Protein (g)', id: 'protein', numeric: true, sortable: true },
|
|
22
|
+
{ label: 'Iron (%)', id: 'iron', numeric: false, sortable: true },
|
|
19
23
|
];
|
|
20
|
-
|
|
24
|
+
|
|
21
25
|
const items = [
|
|
22
26
|
{
|
|
23
27
|
name: 'Frozen Yogurt',
|
|
@@ -106,9 +110,9 @@ export default {
|
|
|
106
110
|
component: NsTable,
|
|
107
111
|
decorators: [withCenterDecorator],
|
|
108
112
|
argTypes: {
|
|
109
|
-
rows: {
|
|
113
|
+
rows: {
|
|
110
114
|
control: 'select',
|
|
111
|
-
options: [5, 10, 25]
|
|
115
|
+
options: [5, 10, 25],
|
|
112
116
|
},
|
|
113
117
|
},
|
|
114
118
|
args: {
|
|
@@ -116,7 +120,41 @@ export default {
|
|
|
116
120
|
items: items,
|
|
117
121
|
rows: 5,
|
|
118
122
|
itemKey: 'name',
|
|
119
|
-
rowsPerPageOptions: [5, 10, 25]
|
|
123
|
+
rowsPerPageOptions: [5, 10, 25],
|
|
124
|
+
isExpandableAll: true,
|
|
125
|
+
showActions: true,
|
|
126
|
+
showExpandedContent: true,
|
|
127
|
+
loading: false,
|
|
128
|
+
expandableContent: (selectedItem: Item, index: number) => {
|
|
129
|
+
return (
|
|
130
|
+
<div key={index}>
|
|
131
|
+
<p>
|
|
132
|
+
Data: {selectedItem.name} , {selectedItem.calories}
|
|
133
|
+
</p>
|
|
134
|
+
<p>
|
|
135
|
+
Index: {index}
|
|
136
|
+
</p>
|
|
137
|
+
<p>
|
|
138
|
+
Expandable: True
|
|
139
|
+
</p>
|
|
140
|
+
</div>
|
|
141
|
+
)
|
|
142
|
+
},
|
|
143
|
+
actionClick: (row: Item) => {
|
|
144
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
console.log(row)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<button onClick={handleClick}>
|
|
151
|
+
<NsIcon
|
|
152
|
+
name='cart'
|
|
153
|
+
size='medium'
|
|
154
|
+
/>
|
|
155
|
+
</button>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
120
158
|
}
|
|
121
159
|
} as MetaStory;
|
|
122
160
|
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
// TODO: const ariel = #f8e9f8;
|
|
2
|
+
|
|
1
3
|
import { styled } from '@nuskin/foundation-theme';
|
|
2
4
|
import { getAppColor } from '@nuskin/foundation-theme/src/utils/color-utils';
|
|
3
5
|
import {
|
|
4
6
|
Table,
|
|
5
7
|
TableContainer,
|
|
6
8
|
TableSortLabel,
|
|
7
|
-
TableRow
|
|
9
|
+
TableRow,
|
|
10
|
+
TableCell
|
|
8
11
|
} from '@mui/material';
|
|
12
|
+
import Pagination from '@mui/material/Pagination';
|
|
13
|
+
import LinearProgress from '@mui/material/LinearProgress';
|
|
9
14
|
|
|
10
15
|
export const StyledTableContainer= styled(TableContainer)`
|
|
11
16
|
background-color: ${({ theme }) => getAppColor(theme, 'primary', 'white')};
|
|
@@ -16,18 +21,104 @@ export const StyledTable = styled(Table)`
|
|
|
16
21
|
`;
|
|
17
22
|
|
|
18
23
|
export const StyledTableSortLabel = styled(TableSortLabel)`
|
|
24
|
+
font-size: 12px;
|
|
25
|
+
text-transform: uppercase;
|
|
26
|
+
font-weight: 600;
|
|
27
|
+
line-height: 16px;
|
|
28
|
+
letter-spacing: 0.05em;
|
|
29
|
+
color: rgba(0, 0, 0, 0.54);
|
|
30
|
+
&:hover {
|
|
31
|
+
color: ${({ theme }) => getAppColor(theme, 'primary', 'black')};
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
export const StyledTableLabel = styled.span`
|
|
19
36
|
font-size: 12px;
|
|
20
37
|
text-transform: uppercase;
|
|
21
38
|
font-weight: 700;
|
|
22
39
|
line-height: 16px;
|
|
23
40
|
letter-spacing: 0.05em;
|
|
24
|
-
color:
|
|
41
|
+
color: rgba(0, 0, 0, 0.54);
|
|
42
|
+
&:hover {
|
|
43
|
+
cursor: default;
|
|
44
|
+
}
|
|
25
45
|
`;
|
|
26
46
|
|
|
27
47
|
export const StyledPageComponent = styled.div`
|
|
28
|
-
|
|
48
|
+
background-color: ${({ theme }) => getAppColor(theme, 'primary', 'white')};
|
|
29
49
|
`;
|
|
30
50
|
|
|
31
51
|
export const StyledEmptyRow = styled(TableRow)<{emptyRows: number}>`
|
|
32
|
-
height: ${({ emptyRows }) =>
|
|
52
|
+
height: ${({ emptyRows }) => 48 * emptyRows}px;
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
export const StyledTableRow = styled(TableRow)`
|
|
56
|
+
&:hover {
|
|
57
|
+
background-color: #f8e9f8 !important;
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
export const StyledTableLastCell = styled(TableCell)`
|
|
62
|
+
display: flex;
|
|
63
|
+
height: 49px;
|
|
64
|
+
align-items: center;
|
|
65
|
+
padding: 0 24px;
|
|
66
|
+
margin-bottom: -0.5px;
|
|
67
|
+
|
|
68
|
+
.action {
|
|
69
|
+
margin-left: auto;
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
export const StyledOriginalTableCell = styled(TableCell)`
|
|
74
|
+
height: 48px;
|
|
75
|
+
padding: 0 24px;
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
export const StyledPagination = styled(Pagination)`
|
|
79
|
+
.MuiPagination-ul {
|
|
80
|
+
display: flex;
|
|
81
|
+
justify-content: flex-end;
|
|
82
|
+
background-color: ${({ theme }) => getAppColor(theme, 'primary', 'white')};
|
|
83
|
+
}
|
|
84
|
+
& .MuiPaginationItem-previousNext {
|
|
85
|
+
margin: 0.3rem 10px;
|
|
86
|
+
width: 2rem;
|
|
87
|
+
height: 2rem;
|
|
88
|
+
border-radius: 4px;
|
|
89
|
+
}
|
|
90
|
+
& .MuiPaginationItem-page {
|
|
91
|
+
border-radius: 0px;
|
|
92
|
+
width: auto;
|
|
93
|
+
min-width: 34px;
|
|
94
|
+
padding: 0 5px;
|
|
95
|
+
font-size: 16px;
|
|
96
|
+
line-height: 17px;
|
|
97
|
+
border-color: ${({ theme }) => getAppColor(theme, 'primary', 'black')};
|
|
98
|
+
}
|
|
99
|
+
& .MuiPaginationItem-root.Mui-selected {
|
|
100
|
+
background-color: ${({ theme }) => getAppColor(theme, 'primary', 'black')};
|
|
101
|
+
color: ${({ theme }) => getAppColor(theme, 'primary', 'white')};
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
export const StyledExpandCell= styled(TableCell)`
|
|
106
|
+
padding-bottom: 0;
|
|
107
|
+
padding-top: 0;
|
|
108
|
+
&.remove {
|
|
109
|
+
border: 0;
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
export const StyledProgressCell = styled(TableCell)`
|
|
114
|
+
padding: 0;
|
|
115
|
+
border: 0;
|
|
116
|
+
`;
|
|
117
|
+
|
|
118
|
+
export const StyledLinearProgress = styled(LinearProgress)`
|
|
119
|
+
&& {
|
|
120
|
+
width: 100%;
|
|
121
|
+
height: 7px;
|
|
122
|
+
border-radius: 4px;
|
|
123
|
+
}
|
|
33
124
|
`;
|
|
@@ -1,24 +1,43 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import {
|
|
3
|
+
TableBody,
|
|
4
|
+
TableCell,
|
|
5
|
+
TableRow
|
|
6
|
+
} from '@mui/material';
|
|
7
|
+
import {
|
|
8
|
+
StyledTable,
|
|
9
|
+
StyledTableContainer,
|
|
10
|
+
StyledEmptyRow,
|
|
11
|
+
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'
|
|
6
20
|
import NsTableHeader from './NsTableHeader';
|
|
7
|
-
import
|
|
8
|
-
import
|
|
21
|
+
import NsTablePagination from './NsTablePagination'
|
|
22
|
+
import ExpandableRow from './NsExpandableRow'
|
|
23
|
+
import Grid from '@mui/material/Grid';
|
|
9
24
|
|
|
10
25
|
export default function NsTable({
|
|
11
26
|
headers = [],
|
|
12
27
|
items = [],
|
|
13
28
|
rows,
|
|
14
|
-
isShowSelector = true,
|
|
15
|
-
isPagination = false,
|
|
16
29
|
rowsPerPageOptions,
|
|
17
30
|
itemKey,
|
|
31
|
+
expandableContent,
|
|
32
|
+
actionClick,
|
|
33
|
+
showActions = true,
|
|
34
|
+
showExpandedContent = true,
|
|
35
|
+
loading = false,
|
|
36
|
+
isExpandableAll = false,
|
|
18
37
|
}: NsTableProps) {
|
|
19
38
|
const [order, setOrder] = useState<OrderType>('asc');
|
|
20
39
|
const [orderBy, setOrderBy] = useState<keyof Item>(itemKey);
|
|
21
|
-
const [
|
|
40
|
+
const [expandList, setExpandList] = useState<number[]>([]);
|
|
22
41
|
const [page, setPage] = useState(0);
|
|
23
42
|
const [rowsPerPage, setRowsPerPage] = useState(rows);
|
|
24
43
|
const [itemKeyList, setItemKeyList] = useState<string[]>([]);
|
|
@@ -38,44 +57,28 @@ export default function NsTable({
|
|
|
38
57
|
setOrderBy(property);
|
|
39
58
|
};
|
|
40
59
|
|
|
41
|
-
const
|
|
42
|
-
if
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
60
|
+
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]);
|
|
70
|
+
} else {
|
|
71
|
+
if(expandList.includes(index)) setExpandList([])
|
|
72
|
+
else setExpandList([index])
|
|
46
73
|
}
|
|
47
|
-
setSelected([]);
|
|
48
74
|
};
|
|
49
75
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
let newSelected: readonly (string | number)[] = [];
|
|
53
|
-
|
|
54
|
-
if (selectedIndex === -1) {
|
|
55
|
-
newSelected = newSelected.concat(selected, name);
|
|
56
|
-
} else if (selectedIndex === 0) {
|
|
57
|
-
newSelected = newSelected.concat(selected.slice(1));
|
|
58
|
-
} else if (selectedIndex === selected.length - 1) {
|
|
59
|
-
newSelected = newSelected.concat(selected.slice(0, -1));
|
|
60
|
-
} else if (selectedIndex > 0) {
|
|
61
|
-
newSelected = newSelected.concat(selected.slice(0, selectedIndex), selected.slice(selectedIndex + 1));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setSelected(newSelected);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const handleChangePage = (event: unknown, newPage: number) => {
|
|
68
|
-
setPage(newPage);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
72
|
-
setRowsPerPage(parseInt(event.target.value, 10));
|
|
73
|
-
setPage(0);
|
|
76
|
+
const handleChangePage = (newPage: number) => {
|
|
77
|
+
setPage(newPage-1);
|
|
74
78
|
};
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - items.length) : 0;
|
|
79
|
+
|
|
80
|
+
const emptyRows =
|
|
81
|
+
page > 0 ? Math.max(0, (1 + page) * rowsPerPage - items.length) : 0;
|
|
79
82
|
|
|
80
83
|
const visibleRows = React.useMemo(
|
|
81
84
|
() =>
|
|
@@ -92,50 +95,39 @@ export default function NsTable({
|
|
|
92
95
|
<StyledTable>
|
|
93
96
|
<NsTableHeader
|
|
94
97
|
headCells={headers}
|
|
95
|
-
numSelected={selected.length}
|
|
96
98
|
order={order}
|
|
97
99
|
orderBy={orderBy as string}
|
|
98
|
-
onSelectAllClick={handleSelectAllClick}
|
|
99
100
|
onRequestSort={handleRequestSort}
|
|
100
101
|
rowCount={items.length}
|
|
101
|
-
isShowSelector={isShowSelector}
|
|
102
102
|
/>
|
|
103
103
|
<TableBody>
|
|
104
|
+
{
|
|
105
|
+
loading ? (
|
|
106
|
+
<TableRow>
|
|
107
|
+
<StyledProgressCell colSpan={itemKeyList.length}>
|
|
108
|
+
<Grid container>
|
|
109
|
+
<Grid item xs={12}>
|
|
110
|
+
<StyledLinearProgress />
|
|
111
|
+
</Grid>
|
|
112
|
+
</Grid>
|
|
113
|
+
</StyledProgressCell>
|
|
114
|
+
</TableRow>
|
|
115
|
+
) : null
|
|
116
|
+
}
|
|
104
117
|
{visibleRows.map((row, index) => {
|
|
105
|
-
const isItemSelected = isSelected(row[itemKey]);
|
|
106
|
-
const labelId = `table-checkbox-${index}`;
|
|
107
|
-
const tableRowTestId = `table-row-${index}`;
|
|
108
118
|
return (
|
|
109
|
-
<
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
<TableCell padding="checkbox">
|
|
122
|
-
<NsCheckBox
|
|
123
|
-
checked={isItemSelected}
|
|
124
|
-
testid={labelId}
|
|
125
|
-
name={labelId}
|
|
126
|
-
label=""
|
|
127
|
-
className="ml-0 !important"
|
|
128
|
-
/>
|
|
129
|
-
</TableCell>
|
|
130
|
-
) : null}
|
|
131
|
-
{itemKeyList.map((id, index) => {
|
|
132
|
-
return (
|
|
133
|
-
<TableCell align="left" key={index}>
|
|
134
|
-
{row[id]}
|
|
135
|
-
</TableCell>
|
|
136
|
-
);
|
|
137
|
-
})}
|
|
138
|
-
</TableRow>
|
|
119
|
+
<ExpandableRow
|
|
120
|
+
key={index}
|
|
121
|
+
expandableContent={expandableContent}
|
|
122
|
+
isExpand={expandList.includes(index)}
|
|
123
|
+
handleClick={handleClick}
|
|
124
|
+
row={row}
|
|
125
|
+
index={index}
|
|
126
|
+
itemKeyList={itemKeyList}
|
|
127
|
+
actionClick={actionClick}
|
|
128
|
+
showActions={showActions}
|
|
129
|
+
showExpandedContent={showExpandedContent}
|
|
130
|
+
/>
|
|
139
131
|
);
|
|
140
132
|
})}
|
|
141
133
|
{emptyRows > 0 ? (
|
|
@@ -146,16 +138,13 @@ export default function NsTable({
|
|
|
146
138
|
</TableBody>
|
|
147
139
|
</StyledTable>
|
|
148
140
|
</StyledTableContainer>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
157
|
-
/>
|
|
158
|
-
) : null}
|
|
141
|
+
<NsTablePagination
|
|
142
|
+
rowsPerPageOptions={rowsPerPageOptions}
|
|
143
|
+
count={items.length}
|
|
144
|
+
rowsPerPage={rowsPerPage}
|
|
145
|
+
page={page+1}
|
|
146
|
+
onPageChange={handleChangePage}
|
|
147
|
+
/>
|
|
159
148
|
</div>
|
|
160
149
|
);
|
|
161
150
|
}
|
|
@@ -1,47 +1,61 @@
|
|
|
1
|
-
import type { NsTableHeaderProps,
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import {
|
|
4
|
-
|
|
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'
|
|
5
13
|
import { visuallyHidden } from '@mui/utils';
|
|
6
|
-
import NsCheckBox from '../checkbox/NsCheckbox';
|
|
7
14
|
|
|
8
15
|
export default function NsTableHeader(props: NsTableHeaderProps) {
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
|
|
14
25
|
return (
|
|
15
26
|
<TableHead>
|
|
16
27
|
<TableRow>
|
|
17
|
-
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
{
|
|
29
|
+
headCells.map((headCell) => (
|
|
30
|
+
headCell.sortable ? (
|
|
31
|
+
<TableCell
|
|
32
|
+
key={headCell.id}
|
|
33
|
+
sortDirection={orderBy == headCell.id ? order : false}
|
|
34
|
+
>
|
|
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
|
+
))}
|
|
45
59
|
</TableRow>
|
|
46
60
|
</TableHead>
|
|
47
61
|
);
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import type { NsTablePaginationProps } from './types
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import {
|
|
4
|
-
import { TablePagination } from '@mui/material';
|
|
1
|
+
import type { NsTablePaginationProps } from './types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { StyledPagination } from './NsTable.styled'
|
|
5
4
|
|
|
6
5
|
export default function NsTablePagination(props: NsTablePaginationProps) {
|
|
7
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
count,
|
|
8
|
+
rowsPerPage,
|
|
9
|
+
page,
|
|
10
|
+
onPageChange,
|
|
11
|
+
} = props;
|
|
12
|
+
|
|
13
|
+
const totalPage = Math.ceil(count / rowsPerPage);
|
|
14
|
+
const handleChange = (event: React.ChangeEvent<unknown>, value: number) => {
|
|
15
|
+
onPageChange(value);
|
|
16
|
+
};
|
|
8
17
|
|
|
9
18
|
return (
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
onRowsPerPageChange={onRowsPerPageChange}
|
|
19
|
+
<StyledPagination
|
|
20
|
+
count={totalPage}
|
|
21
|
+
page={page}
|
|
22
|
+
variant="outlined"
|
|
23
|
+
onChange={handleChange}
|
|
24
|
+
shape="rounded"
|
|
25
|
+
color="primary"
|
|
18
26
|
/>
|
|
19
27
|
);
|
|
20
28
|
}
|
|
@@ -5,8 +5,9 @@ export interface Header {
|
|
|
5
5
|
label: string;
|
|
6
6
|
id: string | number;
|
|
7
7
|
numeric: boolean;
|
|
8
|
+
sortable?: boolean;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
export interface Item {
|
|
11
12
|
[key: string]: string | number;
|
|
12
13
|
}
|
|
@@ -16,22 +17,23 @@ export interface NsTableProps {
|
|
|
16
17
|
items: Item[];
|
|
17
18
|
rows: number;
|
|
18
19
|
itemKey: string;
|
|
19
|
-
isShowSelector: boolean;
|
|
20
20
|
rowsPerPageOptions: number[];
|
|
21
|
-
|
|
21
|
+
isExpandableAll?: boolean;
|
|
22
|
+
showActions?: boolean;
|
|
23
|
+
showExpandedContent?: boolean;
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
expandableContent: (selectedItem: Item, index: number) => React.ReactNode;
|
|
26
|
+
actionClick: (item: Item) => React.ReactNode;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export type OrderType = 'asc' | 'desc';
|
|
25
30
|
|
|
26
31
|
export interface NsTableHeaderProps {
|
|
27
|
-
numSelected: number;
|
|
28
32
|
onRequestSort: (event: React.MouseEvent<unknown>, property: keyof Item) => void;
|
|
29
|
-
onSelectAllClick: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
30
33
|
order: OrderType;
|
|
31
34
|
orderBy: string;
|
|
32
35
|
rowCount: number;
|
|
33
36
|
headCells: readonly Header[];
|
|
34
|
-
isShowSelector: boolean;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export interface NsTablePaginationProps {
|
|
@@ -39,6 +41,17 @@ export interface NsTablePaginationProps {
|
|
|
39
41
|
count: number;
|
|
40
42
|
rowsPerPage: number;
|
|
41
43
|
page: number,
|
|
42
|
-
onPageChange: (
|
|
43
|
-
|
|
44
|
+
onPageChange: (number) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface NsTableRowProps {
|
|
48
|
+
expandableContent: (selectedItem: Item, index: number) => React.ReactNode;
|
|
49
|
+
isExpand: boolean;
|
|
50
|
+
handleClick: (index: number) => void;
|
|
51
|
+
row: Item;
|
|
52
|
+
index: number;
|
|
53
|
+
itemKeyList: string[];
|
|
54
|
+
showActions: boolean;
|
|
55
|
+
showExpandedContent: boolean;
|
|
56
|
+
actionClick: (item: Item) => React.ReactNode;
|
|
44
57
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
7
7
|
import { NsTextStrip } from '@/common/';
|
|
8
|
-
import { withCenterDecorator } from '
|
|
8
|
+
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
9
9
|
|
|
10
10
|
type ComponentType = typeof NsTextStrip;
|
|
11
11
|
type Story = StoryObj<ComponentType>;
|
|
@@ -16,8 +16,10 @@ export default {
|
|
|
16
16
|
component: NsTextStrip,
|
|
17
17
|
decorators: [withCenterDecorator],
|
|
18
18
|
argTypes: {
|
|
19
|
-
|
|
20
|
-
control: '
|
|
19
|
+
alignment: {
|
|
20
|
+
control: 'select',
|
|
21
|
+
options: ['center', 'start', 'end'],
|
|
22
|
+
description: 'specify whether items should be in center, start or end',
|
|
21
23
|
},
|
|
22
24
|
},
|
|
23
25
|
args: {
|
|
@@ -25,7 +27,6 @@ export default {
|
|
|
25
27
|
description: 'Download the app to access everything Nike',
|
|
26
28
|
link: { href: 'https://www.nike.com/in/help/a/shipping-delivery-gs', title: 'View Details' },
|
|
27
29
|
alignment: 'center',
|
|
28
|
-
justify: 'center',
|
|
29
30
|
},
|
|
30
31
|
} as MetaStory;
|
|
31
32
|
|