@nuskin/foundation-ui-components 1.0.0-develop.3 → 1.0.0-develop.5
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 +9 -4
- 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 +93 -0
- package/src/common/accordion/specs/NsAccordionHeader.spec.tsx +63 -0
- package/src/common/accordion/specs/NsAccordionItem.spec.tsx +62 -0
- package/src/common/accordion/specs/NsCollapse.spec.tsx +37 -0
- package/src/common/accordion/specs/NsToggleSection.spec.tsx +38 -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.spec.tsx +0 -1
- package/src/common/alert/NsAlert.styled.ts +10 -10
- package/src/common/alert/NsAlert.tsx +4 -3
- package/src/common/alert/types.d.ts +22 -22
- package/src/common/auth-dropdown/NsAuthDropdown.styled.ts +12 -11
- package/src/common/auth-dropdown/NsAuthDropdown.tsx +2 -1
- package/src/common/auth-dropdown/types.d.ts +3 -1
- package/src/common/autocomplete/NsAutocomplete.spec.tsx +20 -8
- package/src/common/autocomplete/NsAutocomplete.stories.tsx +3 -0
- 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/brand-components/NsBrandComponent.tsx +3 -0
- package/src/common/breadcrumb/NsBreadcrumb.tsx +4 -2
- package/src/common/button/NsButton.spec.tsx +11 -12
- package/src/common/button/NsButton.stories.tsx +1 -1
- package/src/common/button/NsButton.styled.tsx +25 -23
- package/src/common/button/NsButton.tsx +9 -2
- package/src/common/button/types.d.ts +1 -0
- package/src/common/checkbox/NsCheckbox.styled.tsx +2 -2
- package/src/common/common.types.d.ts +2 -0
- package/src/common/dropdown/types.d.ts +3 -1
- package/src/common/email-simple/NsEmailSimple.spec.tsx +145 -0
- package/src/common/email-simple/NsEmailSimple.stories.tsx +61 -0
- package/src/common/email-simple/NsEmailSimple.tsx +71 -0
- package/src/common/email-simple/index.ts +2 -0
- package/src/common/email-simple/types.d.ts +14 -0
- package/src/common/flag/NsFlag.spec.tsx +4 -24
- package/src/common/flag/NsFlag.styled.tsx +5 -5
- package/src/common/flag/NsFlag.tsx +0 -2
- package/src/common/icon/types.d.ts +1 -0
- package/src/common/image/types.d.ts +1 -0
- package/src/common/index.ts +3 -0
- package/src/common/input/InputFieldWrapper.tsx +4 -4
- package/src/common/input/NsInputField.stories.tsx +11 -9
- package/src/common/input/NsInputField.tsx +12 -5
- package/src/common/input/getAdornmentProps.tsx +4 -0
- package/src/common/input/types.d.ts +3 -1
- package/src/common/label/NsLabel.stories.tsx +3 -0
- package/src/common/label/NsLabel.tsx +18 -17
- package/src/common/label/types.d.ts +2 -1
- package/src/common/nav-tab/NsNavTab.spec.tsx +0 -5
- package/src/common/nav-tab/NsNavTab.styled.tsx +7 -4
- package/src/common/radiogroup/NsRadioGroup.spec.tsx +64 -0
- package/src/common/radiogroup/NsRadioGroup.stories.tsx +102 -0
- package/src/common/radiogroup/NsRadioGroup.styled.tsx +50 -0
- package/src/common/radiogroup/NsRadioGroup.tsx +61 -0
- package/src/common/radiogroup/index.ts +2 -0
- package/src/common/radiogroup/types.d.ts +20 -0
- package/src/common/select/NsSelect.spec.tsx +200 -0
- package/src/common/select/NsSelect.styled.tsx +85 -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 +45 -7
- package/src/common/table/NsTable.styled.ts +106 -12
- 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.tsx +10 -7
- package/src/common/typography/Typography.styled.tsx +3 -3
- package/src/common/validations/regex.ts +3 -0
- /package/src/common/card/{tests → specs}/BrandLogo.spec.tsx +0 -0
- /package/src/common/card/{tests → specs}/NsBgCard.spec.tsx +0 -0
- /package/src/common/card/{tests → specs}/NsBrandProductCard.spec.tsx +0 -0
- /package/src/common/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
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
3
|
+
import NsSelect from '../NsSelect';
|
|
4
|
+
import NsSelectOption from '../NsSelectOption';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Components/NsSelect',
|
|
8
|
+
decorators: [
|
|
9
|
+
(story) => <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>{story()}</div>,
|
|
10
|
+
],
|
|
11
|
+
component: NsSelect,
|
|
12
|
+
argTypes: {
|
|
13
|
+
type: { control: 'select', options: ['unfilled', 'outlined'] },
|
|
14
|
+
disabled: { control: 'boolean' },
|
|
15
|
+
selectBorderColor: {
|
|
16
|
+
control: 'select',
|
|
17
|
+
options: ['primary', 'secondary', 'accentColorA', 'accentColorB', 'accentColorC'],
|
|
18
|
+
},
|
|
19
|
+
placeholder: { control: 'text' },
|
|
20
|
+
closeOnMouseLeave: { control: 'boolean' },
|
|
21
|
+
showListDivider: { control: 'boolean' },
|
|
22
|
+
label: { control: 'text' },
|
|
23
|
+
name: { control: 'text' },
|
|
24
|
+
menuProps:{ control: 'text' },
|
|
25
|
+
reverseArrowControls:{ control: 'boolean' },
|
|
26
|
+
validateOnBlur:{ control: 'boolean' },
|
|
27
|
+
autoComplete: { control: 'text' },
|
|
28
|
+
rules: {control: 'array'},
|
|
29
|
+
},
|
|
30
|
+
parameters: {
|
|
31
|
+
options: [
|
|
32
|
+
{ label: 'Alabama', value: 'AL' },
|
|
33
|
+
{ label: 'Alaska', value: 'AK' },
|
|
34
|
+
{ label: 'Arizona', value: 'AZ' },
|
|
35
|
+
{ label: 'Arkansas', value: 'AR' },
|
|
36
|
+
{ label: 'California', value: 'CA' },
|
|
37
|
+
{ label: 'Colorado', value: 'CO' },
|
|
38
|
+
{ label: 'Connecticut', value: 'CT' },
|
|
39
|
+
{ label: 'Delaware', value: 'DE' },
|
|
40
|
+
{ label: 'District of Columbia', value: 'DC' },
|
|
41
|
+
{ label: 'Florida', value: 'FL' },
|
|
42
|
+
{ label: 'Georgia', value: 'GA' },
|
|
43
|
+
{ label: 'Hawaii', value: 'HI' },
|
|
44
|
+
{ label: 'Idaho', value: 'ID' },
|
|
45
|
+
{ label: 'Illinois', value: 'IL' },
|
|
46
|
+
{ label: 'Indiana', value: 'IN' },
|
|
47
|
+
{ label: 'Iowa', value: 'IA' },
|
|
48
|
+
{ label: 'Kansas', value: 'KA' },
|
|
49
|
+
{ label: 'Kentucky', value: 'KY' },
|
|
50
|
+
{ label: 'Louisiana', value: 'LA' },
|
|
51
|
+
{ label: 'Maine', value: 'ME' },
|
|
52
|
+
{ label: 'Maryland', value: 'MY' },
|
|
53
|
+
{ label: 'Massachusetts', value: 'MA' },
|
|
54
|
+
{ label: 'Michigan', value: 'MC' },
|
|
55
|
+
{ label: 'Minnesota', value: 'MN' },
|
|
56
|
+
{ label: 'Mississippi', value: 'MI' },
|
|
57
|
+
{ label: 'Missouri', value: 'MO' },
|
|
58
|
+
{ label: 'Montana', value: 'MT' },
|
|
59
|
+
{ label: 'Nebraska', value: 'NE' },
|
|
60
|
+
{ label: 'Nevada', value: 'NA' },
|
|
61
|
+
{ label: 'New Hampshire', value: 'NH' },
|
|
62
|
+
{ label: 'New Jersey', value: 'NJ' },
|
|
63
|
+
{ label: 'New Mexico', value: 'NM' },
|
|
64
|
+
{ label: 'New York', value: 'NY' },
|
|
65
|
+
{ label: 'North Carolina', value: 'NC' },
|
|
66
|
+
{ label: 'North Dakota', value: 'CD' },
|
|
67
|
+
{ label: 'Ohio', value: 'OH' },
|
|
68
|
+
{ label: 'Oklahoma', value: 'OK' },
|
|
69
|
+
{ label: 'Oregon', value: 'OR' },
|
|
70
|
+
{ label: 'Pennsylvania', value: 'PA' },
|
|
71
|
+
{ label: 'Rhode Island', value: 'RI' },
|
|
72
|
+
{ label: 'South Carolina', value: 'SC' },
|
|
73
|
+
{ label: 'South Dakota', value: 'SD' },
|
|
74
|
+
{ label: 'Tennessee', value: 'TN' },
|
|
75
|
+
{ label: 'Texas', value: 'TX' },
|
|
76
|
+
{ label: 'Utah', value: 'UT' },
|
|
77
|
+
{ label: 'Vermont', value: 'VT' },
|
|
78
|
+
{ label: 'Virginia', value: 'VA' },
|
|
79
|
+
{ label: 'Washington', value: 'WA' },
|
|
80
|
+
{ label: 'West Virginia', value: 'WV' },
|
|
81
|
+
{ label: 'Wisconsin', value: 'WN' },
|
|
82
|
+
{ label: 'Wyoming', value: 'WY' },
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
args: {
|
|
86
|
+
type: 'outlined',
|
|
87
|
+
disabled: false,
|
|
88
|
+
selectBorderColor: 'primary',
|
|
89
|
+
closeOnMouseLeave: false,
|
|
90
|
+
showListDivider: true,
|
|
91
|
+
selectedValue: '',
|
|
92
|
+
selectedLabel: '',
|
|
93
|
+
label: 'State',
|
|
94
|
+
placeholder:'',
|
|
95
|
+
name:'',
|
|
96
|
+
menuProps:'auto',
|
|
97
|
+
reverseArrowControls: false,
|
|
98
|
+
itemText:'Text',
|
|
99
|
+
itemValue:'Value',
|
|
100
|
+
validateOnBlur: false,
|
|
101
|
+
autoComplete: '',
|
|
102
|
+
rules:[]
|
|
103
|
+
},
|
|
104
|
+
} as ComponentMeta<typeof NsSelect>;
|
|
105
|
+
|
|
106
|
+
export const Select: ComponentStory<typeof NsSelect> = (args, context) => {
|
|
107
|
+
const [selectedLabel, setSelectedLabel] = useState(args.selectedLabel);
|
|
108
|
+
const [selectedValue, setSelectedValue] = useState(args.selectedValue);
|
|
109
|
+
|
|
110
|
+
const options = context.parameters.options;
|
|
111
|
+
const handleSelect = (value: string) => {
|
|
112
|
+
setSelectedValue(value);
|
|
113
|
+
options.find((option: any) => {
|
|
114
|
+
if (option.value === value) {
|
|
115
|
+
setSelectedLabel(option.label);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
console.log('Selected:', value);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<NsSelect
|
|
123
|
+
{...args}
|
|
124
|
+
selectedValue={selectedValue}
|
|
125
|
+
selectedLabel={selectedLabel}
|
|
126
|
+
onSelect={handleSelect}
|
|
127
|
+
label={args.label}
|
|
128
|
+
>
|
|
129
|
+
{options.map((option: any) => (
|
|
130
|
+
<NsSelectOption key={option.value} value={option.value} label={option.label} />
|
|
131
|
+
))}
|
|
132
|
+
</NsSelect>
|
|
133
|
+
);
|
|
134
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { FoundationTheme } from '@nuskin/foundation-theme';
|
|
3
|
+
|
|
4
|
+
export interface SelectProps {
|
|
5
|
+
selectedValue: string;
|
|
6
|
+
selectedLabel: string;
|
|
7
|
+
onSelect: (arg: string) => void; // eslint-disable-line
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
type?: 'outlined' | 'unfilled';
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
selectBorderColor?: FoundationTheme.PaletteColors;
|
|
13
|
+
closeOnMouseLeave?: boolean;
|
|
14
|
+
showListDivider?: boolean;
|
|
15
|
+
label?: string;
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
name?: string;
|
|
18
|
+
errorMessage?: string;
|
|
19
|
+
menuProps?: string | object;
|
|
20
|
+
reverseArrowControls?: boolean;
|
|
21
|
+
itemText?: string;
|
|
22
|
+
itemValue?: string;
|
|
23
|
+
validateOnBlur?: boolean;
|
|
24
|
+
autoComplete?: string;
|
|
25
|
+
rules?: any[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SelectOptionProps {
|
|
29
|
+
value: string;
|
|
30
|
+
label: string;
|
|
31
|
+
selectedValue?: string;
|
|
32
|
+
onSelect?: (arg: string) => void; // eslint-disable-line
|
|
33
|
+
showListDivider?: boolean;
|
|
34
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TableRow } from '@mui/material';
|
|
3
|
+
import {
|
|
4
|
+
StyledTableRow,
|
|
5
|
+
StyledTableLastCell,
|
|
6
|
+
StyledExpandCell,
|
|
7
|
+
StyledOriginalTableCell
|
|
8
|
+
} from './NsTable.styled'
|
|
9
|
+
import type {
|
|
10
|
+
NsTableRowProps
|
|
11
|
+
} from './types'
|
|
12
|
+
import Box from '@mui/material/Box';
|
|
13
|
+
import Collapse from '@mui/material/Collapse';
|
|
14
|
+
|
|
15
|
+
export default function ExpandableRow({
|
|
16
|
+
expandableContent,
|
|
17
|
+
isExpand,
|
|
18
|
+
handleClick,
|
|
19
|
+
row,
|
|
20
|
+
itemKeyList,
|
|
21
|
+
index,
|
|
22
|
+
showActions,
|
|
23
|
+
showExpandedContent,
|
|
24
|
+
actionClick
|
|
25
|
+
}: NsTableRowProps) {
|
|
26
|
+
const tableRowTestId = `table-row-${index}`;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<React.Fragment>
|
|
30
|
+
<StyledTableRow
|
|
31
|
+
hover
|
|
32
|
+
onClick={() => handleClick(index)}
|
|
33
|
+
tabIndex={-1}
|
|
34
|
+
key={index}
|
|
35
|
+
className='cursor-pointer'
|
|
36
|
+
data-testid={tableRowTestId}
|
|
37
|
+
>
|
|
38
|
+
{
|
|
39
|
+
itemKeyList.map((id, i) => {
|
|
40
|
+
return ((i === itemKeyList.length - 1) && showActions) ? (
|
|
41
|
+
<StyledTableLastCell align="justify" key={id}>
|
|
42
|
+
<span>{row[id]}</span>
|
|
43
|
+
<span className='action'>{actionClick(row)}</span>
|
|
44
|
+
</StyledTableLastCell>
|
|
45
|
+
) : (
|
|
46
|
+
<StyledOriginalTableCell align="left" key={id}>{row[id]}</StyledOriginalTableCell>
|
|
47
|
+
)
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
</StyledTableRow>
|
|
51
|
+
{
|
|
52
|
+
showExpandedContent ? (
|
|
53
|
+
<TableRow>
|
|
54
|
+
<StyledExpandCell colSpan={itemKeyList.length} className={!isExpand ? 'remove' : ''}>
|
|
55
|
+
<Collapse in={isExpand} unmountOnExit>
|
|
56
|
+
<Box className='m-px'>
|
|
57
|
+
{
|
|
58
|
+
expandableContent(row, index)
|
|
59
|
+
}
|
|
60
|
+
</Box>
|
|
61
|
+
</Collapse>
|
|
62
|
+
</StyledExpandCell>
|
|
63
|
+
</TableRow>
|
|
64
|
+
) : null
|
|
65
|
+
}
|
|
66
|
+
</React.Fragment>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
@@ -1,11 +1,45 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, fireEvent, screen } from '@/test-utils/index';
|
|
3
3
|
import NsTable from './NsTable';
|
|
4
|
+
import { Item } from './types';
|
|
5
|
+
import { NsIcon } from '../icon';
|
|
6
|
+
|
|
7
|
+
const expandableContent = (selectedItem: Item, index: number) => {
|
|
8
|
+
return (
|
|
9
|
+
<div key={index}>
|
|
10
|
+
<p>
|
|
11
|
+
Data: {selectedItem.name} , {selectedItem.calories}
|
|
12
|
+
</p>
|
|
13
|
+
<p>
|
|
14
|
+
Index: {index}
|
|
15
|
+
</p>
|
|
16
|
+
<p>
|
|
17
|
+
Expandable: True
|
|
18
|
+
</p>
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const actionClick = (row: Item) => {
|
|
24
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
25
|
+
event.stopPropagation();
|
|
26
|
+
console.log(row)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<button onClick={handleClick}>
|
|
31
|
+
<NsIcon
|
|
32
|
+
name='cart'
|
|
33
|
+
size='medium'
|
|
34
|
+
/>
|
|
35
|
+
</button>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
4
38
|
|
|
5
39
|
describe('NsTable', () => {
|
|
6
40
|
const headers = [
|
|
7
|
-
{ id: 'name', label: 'Name', numeric: false },
|
|
8
|
-
{ id: 'age', label: 'Age', numeric: true },
|
|
41
|
+
{ id: 'name', label: 'Name', numeric: false, sortable: true },
|
|
42
|
+
{ id: 'age', label: 'Age', numeric: true, sortable: true },
|
|
9
43
|
];
|
|
10
44
|
|
|
11
45
|
const items = [
|
|
@@ -20,7 +54,6 @@ describe('NsTable', () => {
|
|
|
20
54
|
];
|
|
21
55
|
|
|
22
56
|
const rows = 5;
|
|
23
|
-
const isShowSelector = true;
|
|
24
57
|
const rowsPerPageOptions = [5, 10, 15];
|
|
25
58
|
const itemKey = 'name';
|
|
26
59
|
|
|
@@ -30,10 +63,14 @@ describe('NsTable', () => {
|
|
|
30
63
|
headers={headers}
|
|
31
64
|
items={items}
|
|
32
65
|
rows={rows}
|
|
33
|
-
isShowSelector={isShowSelector}
|
|
34
66
|
rowsPerPageOptions={rowsPerPageOptions}
|
|
35
67
|
itemKey={itemKey}
|
|
36
|
-
|
|
68
|
+
isExpandableAll={true}
|
|
69
|
+
loading={true}
|
|
70
|
+
showActions={false}
|
|
71
|
+
showExpandedContent={false}
|
|
72
|
+
expandableContent={expandableContent}
|
|
73
|
+
actionClick={actionClick}
|
|
37
74
|
/>
|
|
38
75
|
);
|
|
39
76
|
|
|
@@ -43,82 +80,72 @@ describe('NsTable', () => {
|
|
|
43
80
|
expect(screen.getByText('Maria')).toBeInTheDocument();
|
|
44
81
|
expect(screen.getByText('28')).toBeInTheDocument();
|
|
45
82
|
expect(screen.getByText('31')).toBeInTheDocument();
|
|
46
|
-
expect(screen.getByRole('button', { name: 'Rows per page: 5' })).toBeInTheDocument();
|
|
47
83
|
});
|
|
48
84
|
|
|
49
|
-
it('
|
|
85
|
+
it('expandable true click', () => {
|
|
50
86
|
render(
|
|
51
87
|
<NsTable
|
|
52
88
|
headers={headers}
|
|
53
89
|
items={items}
|
|
54
90
|
rows={rows}
|
|
55
|
-
isShowSelector={isShowSelector}
|
|
56
91
|
rowsPerPageOptions={rowsPerPageOptions}
|
|
57
92
|
itemKey={itemKey}
|
|
58
|
-
|
|
93
|
+
isExpandableAll={true}
|
|
94
|
+
expandableContent={expandableContent}
|
|
95
|
+
actionClick={actionClick}
|
|
59
96
|
/>
|
|
60
97
|
);
|
|
61
98
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
fireEvent.click(button);
|
|
99
|
+
|
|
100
|
+
expect(screen.getByTestId('table-row-0')).toBeInTheDocument();
|
|
65
101
|
|
|
66
|
-
|
|
67
|
-
fireEvent.click(button);
|
|
68
|
-
expect(screen.getByTestId('table-row-3')).toHaveAttribute('aria-checked', 'false');
|
|
69
|
-
});
|
|
102
|
+
const button = screen.getByTestId('table-row-0');
|
|
70
103
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
headers={headers}
|
|
75
|
-
items={items}
|
|
76
|
-
rows={rows}
|
|
77
|
-
isShowSelector={!isShowSelector}
|
|
78
|
-
rowsPerPageOptions={rowsPerPageOptions}
|
|
79
|
-
itemKey={itemKey}
|
|
80
|
-
isPagination
|
|
81
|
-
/>
|
|
82
|
-
);
|
|
104
|
+
fireEvent.click(button);
|
|
105
|
+
expect(screen.getByText('Expandable: True')).toBeInTheDocument();
|
|
106
|
+
fireEvent.click(button);
|
|
83
107
|
});
|
|
84
108
|
|
|
85
|
-
it('
|
|
109
|
+
it('expandable false click', () => {
|
|
86
110
|
render(
|
|
87
111
|
<NsTable
|
|
88
112
|
headers={headers}
|
|
89
113
|
items={items}
|
|
90
114
|
rows={rows}
|
|
91
|
-
isShowSelector={isShowSelector}
|
|
92
115
|
rowsPerPageOptions={rowsPerPageOptions}
|
|
93
116
|
itemKey={itemKey}
|
|
94
|
-
|
|
117
|
+
isExpandableAll={false}
|
|
118
|
+
expandableContent={expandableContent}
|
|
119
|
+
actionClick={actionClick}
|
|
95
120
|
/>
|
|
96
121
|
);
|
|
97
122
|
|
|
98
|
-
expect(screen.getByTestId('
|
|
123
|
+
expect(screen.getByTestId('table-row-0')).toBeInTheDocument();
|
|
99
124
|
|
|
100
|
-
const button = screen.getByTestId('
|
|
125
|
+
const button = screen.getByTestId('table-row-0');
|
|
101
126
|
|
|
102
127
|
fireEvent.click(button);
|
|
103
|
-
expect(screen.
|
|
128
|
+
expect(screen.getByText('Expandable: True')).toBeInTheDocument();
|
|
129
|
+
fireEvent.click(button);
|
|
104
130
|
});
|
|
105
131
|
|
|
106
|
-
it('
|
|
132
|
+
it('pagination next button click event', async () => {
|
|
107
133
|
render(
|
|
108
134
|
<NsTable
|
|
109
135
|
headers={headers}
|
|
110
136
|
items={items}
|
|
111
137
|
rows={rows}
|
|
112
|
-
isShowSelector={isShowSelector}
|
|
113
138
|
rowsPerPageOptions={rowsPerPageOptions}
|
|
114
139
|
itemKey={itemKey}
|
|
115
|
-
|
|
140
|
+
isExpandableAll={true}
|
|
141
|
+
expandableContent={expandableContent}
|
|
142
|
+
actionClick={actionClick}
|
|
116
143
|
/>
|
|
117
144
|
);
|
|
118
145
|
|
|
119
|
-
expect(screen.getByTestId('
|
|
146
|
+
expect(screen.getByTestId('NavigateNextIcon')).toBeInTheDocument();
|
|
120
147
|
|
|
121
|
-
const button = screen.getByTestId('
|
|
148
|
+
const button = screen.getByTestId('NavigateNextIcon');
|
|
122
149
|
fireEvent.click(button);
|
|
123
150
|
expect(screen.getByText('Sandy')).toBeInTheDocument();
|
|
124
151
|
});
|
|
@@ -129,10 +156,11 @@ describe('NsTable', () => {
|
|
|
129
156
|
headers={headers}
|
|
130
157
|
items={items}
|
|
131
158
|
rows={rows}
|
|
132
|
-
isShowSelector={isShowSelector}
|
|
133
159
|
rowsPerPageOptions={rowsPerPageOptions}
|
|
134
160
|
itemKey={itemKey}
|
|
135
|
-
|
|
161
|
+
isExpandableAll={true}
|
|
162
|
+
expandableContent={expandableContent}
|
|
163
|
+
actionClick={actionClick}
|
|
136
164
|
/>
|
|
137
165
|
);
|
|
138
166
|
|
|
@@ -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
|
-
import { withCenterDecorator } from '
|
|
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>;
|
|
@@ -10,12 +13,13 @@ const headers = [
|
|
|
10
13
|
label: 'Dessert (100g serving)',
|
|
11
14
|
id: 'name',
|
|
12
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 = [
|
|
@@ -117,7 +121,41 @@ export default {
|
|
|
117
121
|
rows: 5,
|
|
118
122
|
itemKey: 'name',
|
|
119
123
|
rowsPerPageOptions: [5, 10, 25],
|
|
120
|
-
|
|
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
|
+
}
|
|
158
|
+
}
|
|
121
159
|
} as MetaStory;
|
|
122
160
|
|
|
123
161
|
export const NasTable: Story = {};
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// TODO: const ariel = #f8e9f8;
|
|
2
|
+
|
|
3
|
+
import { styled, ColorUtils } from '@nuskin/foundation-theme';
|
|
4
|
+
|
|
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';
|
|
14
|
+
|
|
15
|
+
const { color } = ColorUtils;
|
|
9
16
|
|
|
10
17
|
export const StyledTableContainer= styled(TableContainer)`
|
|
11
|
-
background-color: ${(
|
|
18
|
+
background-color: ${color('primary', 'white')};
|
|
12
19
|
`;
|
|
13
20
|
|
|
14
21
|
export const StyledTable = styled(Table)`
|
|
@@ -16,18 +23,105 @@ export const StyledTable = styled(Table)`
|
|
|
16
23
|
`;
|
|
17
24
|
|
|
18
25
|
export const StyledTableSortLabel = styled(TableSortLabel)`
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
font-size: 12px;
|
|
27
|
+
text-transform: uppercase;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
line-height: 16px;
|
|
30
|
+
letter-spacing: 0.05em;
|
|
31
|
+
color: rgba(0, 0, 0, 0.54);
|
|
32
|
+
&:hover {
|
|
33
|
+
color: ${color('primary', 'black')};
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const StyledTableLabel = styled.span`
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
text-transform: uppercase;
|
|
40
|
+
font-weight: 700;
|
|
41
|
+
line-height: 16px;
|
|
42
|
+
letter-spacing: 0.05em;
|
|
43
|
+
color: rgba(0, 0, 0, 0.54);
|
|
44
|
+
&:hover {
|
|
45
|
+
cursor: default;
|
|
46
|
+
}
|
|
25
47
|
`;
|
|
26
48
|
|
|
27
49
|
export const StyledPageComponent = styled.div`
|
|
28
|
-
background-color: ${(
|
|
50
|
+
background-color: ${color('primary', 'white')};
|
|
29
51
|
`;
|
|
30
52
|
|
|
31
53
|
export const StyledEmptyRow = styled(TableRow)<{emptyRows: number}>`
|
|
32
|
-
|
|
54
|
+
height: ${({ emptyRows }) => 48 * emptyRows}px;
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
// [Todo-Arun] - Move f8e9f8 to custom color palette
|
|
58
|
+
export const StyledTableRow = styled(TableRow)`
|
|
59
|
+
&:hover {
|
|
60
|
+
background-color: #f8e9f8 !important;
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
export const StyledTableLastCell = styled(TableCell)`
|
|
65
|
+
display: flex;
|
|
66
|
+
height: 49px;
|
|
67
|
+
align-items: center;
|
|
68
|
+
padding: 0 24px;
|
|
69
|
+
margin-bottom: -0.5px;
|
|
70
|
+
|
|
71
|
+
.action {
|
|
72
|
+
margin-left: auto;
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
export const StyledOriginalTableCell = styled(TableCell)`
|
|
77
|
+
height: 48px;
|
|
78
|
+
padding: 0 24px;
|
|
79
|
+
`;
|
|
80
|
+
|
|
81
|
+
export const StyledPagination = styled(Pagination)`
|
|
82
|
+
.MuiPagination-ul {
|
|
83
|
+
display: flex;
|
|
84
|
+
justify-content: flex-end;
|
|
85
|
+
background-color: ${color('primary', 'white')};
|
|
86
|
+
}
|
|
87
|
+
& .MuiPaginationItem-previousNext {
|
|
88
|
+
margin: 0.3rem 10px;
|
|
89
|
+
width: 2rem;
|
|
90
|
+
height: 2rem;
|
|
91
|
+
border-radius: 4px;
|
|
92
|
+
}
|
|
93
|
+
& .MuiPaginationItem-page {
|
|
94
|
+
border-radius: 0px;
|
|
95
|
+
width: auto;
|
|
96
|
+
min-width: 34px;
|
|
97
|
+
padding: 0 5px;
|
|
98
|
+
font-size: 16px;
|
|
99
|
+
line-height: 17px;
|
|
100
|
+
border-color: ${color('primary', 'black')};
|
|
101
|
+
}
|
|
102
|
+
& .MuiPaginationItem-root.Mui-selected {
|
|
103
|
+
background-color: ${color('primary', 'black')};
|
|
104
|
+
color: ${color('primary', 'white')};
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
export const StyledExpandCell= styled(TableCell)`
|
|
109
|
+
padding-bottom: 0;
|
|
110
|
+
padding-top: 0;
|
|
111
|
+
&.remove {
|
|
112
|
+
border: 0;
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
|
|
116
|
+
export const StyledProgressCell = styled(TableCell)`
|
|
117
|
+
padding: 0;
|
|
118
|
+
border: 0;
|
|
119
|
+
`;
|
|
120
|
+
|
|
121
|
+
export const StyledLinearProgress = styled(LinearProgress)`
|
|
122
|
+
&& {
|
|
123
|
+
width: 100%;
|
|
124
|
+
height: 7px;
|
|
125
|
+
border-radius: 4px;
|
|
126
|
+
}
|
|
33
127
|
`;
|