@nuskin/foundation-ui-components 1.0.0-develop.5 → 1.0.0-develop.6
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/autocomplete/NsAutocomplete.spec.tsx +10 -0
- package/src/common/autocomplete/NsAutocomplete.stories.tsx +44 -6
- package/src/common/autocomplete/NsAutocomplete.tsx +18 -15
- package/src/common/autocomplete/types.d.ts +8 -6
- package/src/common/breadcrumb/NsBreadcrumb.tsx +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuskin/foundation-ui-components",
|
|
3
|
-
"version": "1.0.0-develop.
|
|
3
|
+
"version": "1.0.0-develop.6",
|
|
4
4
|
"description": "It is a foundation library written in react, that provides common components to all UI pages",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "src/common/index.ts",
|
|
@@ -14,6 +14,8 @@ describe('CustomAutocomplete', () => {
|
|
|
14
14
|
onSelect={() => {}}
|
|
15
15
|
placeholder="autocomplete-input"
|
|
16
16
|
renderOptions={OptionUiComponent}
|
|
17
|
+
inputValue=""
|
|
18
|
+
value=""
|
|
17
19
|
/>
|
|
18
20
|
);
|
|
19
21
|
const autocompleteInput = screen.getByPlaceholderText('autocomplete-input');
|
|
@@ -27,6 +29,8 @@ describe('CustomAutocomplete', () => {
|
|
|
27
29
|
onSelect={() => {}}
|
|
28
30
|
renderOptions={OptionUiComponent}
|
|
29
31
|
placeholder="autocomplete-input"
|
|
32
|
+
inputValue=""
|
|
33
|
+
value=""
|
|
30
34
|
/>
|
|
31
35
|
);
|
|
32
36
|
const autocompleteInput = screen.getByPlaceholderText('autocomplete-input');
|
|
@@ -48,6 +52,8 @@ describe('CustomAutocomplete', () => {
|
|
|
48
52
|
options={AutocompleteMockList}
|
|
49
53
|
renderOptions={OptionUiComponent}
|
|
50
54
|
placeholder="autocomplete-input"
|
|
55
|
+
inputValue=""
|
|
56
|
+
value=""
|
|
51
57
|
/>
|
|
52
58
|
);
|
|
53
59
|
const autocompleteInput = screen.getByPlaceholderText('autocomplete-input');
|
|
@@ -71,6 +77,8 @@ describe('CustomAutocomplete', () => {
|
|
|
71
77
|
show: true,
|
|
72
78
|
onSeeMore: () => ({}),
|
|
73
79
|
}}
|
|
80
|
+
inputValue=""
|
|
81
|
+
value=""
|
|
74
82
|
/>
|
|
75
83
|
);
|
|
76
84
|
const autocompleteInput = screen.getByPlaceholderText('autocomplete-input');
|
|
@@ -94,6 +102,8 @@ describe('CustomAutocomplete', () => {
|
|
|
94
102
|
show: true,
|
|
95
103
|
onClear: () => ({}),
|
|
96
104
|
}}
|
|
105
|
+
inputValue=""
|
|
106
|
+
value=""
|
|
97
107
|
/>
|
|
98
108
|
);
|
|
99
109
|
const autocompleteInput = screen.getByPlaceholderText('autocomplete-input');
|
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
* @description NsAutocomplete component.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React from 'react';
|
|
7
|
+
import React, { useState } from 'react';
|
|
8
8
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
9
9
|
|
|
10
10
|
import { withCenterDecorator } from '@/stories/decorators/withCenterDecorator';
|
|
11
11
|
import { NsAutocomplete } from './';
|
|
12
12
|
import { AutocompleteMockList } from './mock/MockData';
|
|
13
13
|
import { OptionUiComponent } from './mock/MockUI';
|
|
14
|
-
import { NsAutocompleteProps } from './types.d';
|
|
14
|
+
import { NsAutocompleteProps, OptionsProps } from './types.d';
|
|
15
15
|
import { NsIcon } from '../icon';
|
|
16
|
+
import { IconButton } from '@mui/material';
|
|
16
17
|
|
|
17
18
|
type ComponentType = typeof NsAutocomplete;
|
|
18
19
|
type Story = StoryObj<ComponentType>;
|
|
@@ -31,24 +32,61 @@ export default {
|
|
|
31
32
|
options: AutocompleteMockList,
|
|
32
33
|
seeMore: {
|
|
33
34
|
text: 'See More Results',
|
|
34
|
-
show:
|
|
35
|
+
show: true,
|
|
35
36
|
onSeeMore: () => {
|
|
36
37
|
throw new Error('Function not implemented.');
|
|
37
38
|
},
|
|
38
39
|
},
|
|
39
40
|
clear: {
|
|
40
41
|
text: 'Clear Recent Searches',
|
|
41
|
-
show:
|
|
42
|
+
show: true,
|
|
42
43
|
onClear: () => {
|
|
43
44
|
throw new Error('Function not implemented.');
|
|
44
45
|
},
|
|
45
46
|
},
|
|
46
47
|
iconStart: <NsIcon name="search" />,
|
|
47
|
-
iconEnd: <NsIcon name="close" size=
|
|
48
|
+
iconEnd: <NsIcon name="close" size="small" />,
|
|
48
49
|
placeholder: 'search',
|
|
49
50
|
},
|
|
50
51
|
} as MetaStory;
|
|
51
52
|
|
|
53
|
+
const RenderAutocomplete = (args: NsAutocompleteProps) => {
|
|
54
|
+
const [selectedOption, setSelectedOption] = useState<string | OptionsProps | null>(null);
|
|
55
|
+
const [searchTerms, setSearchTerms] = useState<string>('');
|
|
56
|
+
|
|
57
|
+
const onSelect = (value: string | OptionsProps | null) => {
|
|
58
|
+
setSelectedOption(value);
|
|
59
|
+
setSearchTerms((value = ''));
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const handleInputChange = (newValue: string) => {
|
|
63
|
+
setSearchTerms(newValue);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const onInputClear = () => {
|
|
67
|
+
setSelectedOption(null);
|
|
68
|
+
setSearchTerms('');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div>
|
|
73
|
+
<NsAutocomplete
|
|
74
|
+
{...args}
|
|
75
|
+
onChange={handleInputChange}
|
|
76
|
+
onSelect={onSelect}
|
|
77
|
+
renderOptions={OptionUiComponent}
|
|
78
|
+
iconEnd={
|
|
79
|
+
<IconButton onClick={onInputClear}>
|
|
80
|
+
<NsIcon name="close" size="small" />
|
|
81
|
+
</IconButton>
|
|
82
|
+
}
|
|
83
|
+
value={selectedOption}
|
|
84
|
+
inputValue={searchTerms}
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
52
90
|
export const Autocomplete: Story = {
|
|
53
|
-
render:
|
|
91
|
+
render: RenderAutocomplete,
|
|
54
92
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
import { Autocomplete, AutocompleteRenderGroupParams, List, AutocompleteRenderInputParams } from '@mui/material';
|
|
3
3
|
import { NsTypography, NsButton } from '../';
|
|
4
4
|
import { NsAutocompleteProps, OptionsProps, ComponentBoxProps } from './types.d';
|
|
@@ -18,23 +18,23 @@ const NsAutocomplete = ({
|
|
|
18
18
|
className,
|
|
19
19
|
iconStart,
|
|
20
20
|
iconEnd,
|
|
21
|
+
inputValue,
|
|
22
|
+
value,
|
|
21
23
|
}: PropsWithChildren<NsAutocompleteProps>) => {
|
|
22
|
-
const inputRef = useRef(null);
|
|
23
|
-
|
|
24
|
-
const [selectedOption, setSelectedOption] = useState<OptionsProps | null>(null);
|
|
25
24
|
const OptionUI = renderOptions;
|
|
26
25
|
|
|
27
|
-
const handleSelect = (event: React.SyntheticEvent<Element, Event>, value: OptionsProps | null) => {
|
|
28
|
-
setSelectedOption(value);
|
|
26
|
+
const handleSelect = (event: React.SyntheticEvent<Element, Event>, value: string | OptionsProps | null) => {
|
|
29
27
|
onSelect ? onSelect(value) : null;
|
|
30
28
|
};
|
|
31
29
|
|
|
30
|
+
const handleInputChange = (event: React.SyntheticEvent<Element, Event>, newInputValue: string) => {
|
|
31
|
+
onChange ? onChange(newInputValue) : null;
|
|
32
|
+
};
|
|
33
|
+
|
|
32
34
|
const renderInput = (params: AutocompleteRenderInputParams) => (
|
|
33
35
|
<StyledTextField
|
|
34
36
|
{...params}
|
|
35
|
-
onChange={onChange}
|
|
36
37
|
placeholder={placeholder}
|
|
37
|
-
inputRef={inputRef}
|
|
38
38
|
InputProps={{
|
|
39
39
|
...params.InputProps,
|
|
40
40
|
startAdornment: iconStart,
|
|
@@ -61,23 +61,23 @@ const NsAutocomplete = ({
|
|
|
61
61
|
{group}
|
|
62
62
|
</NsTypography>
|
|
63
63
|
) : null}
|
|
64
|
-
<
|
|
64
|
+
<ul className="p-0">{children}</ul>
|
|
65
65
|
</li>
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
const renderClearButton = () => {
|
|
69
|
-
const { show, onClear, text = '
|
|
69
|
+
const { show, onClear, text = 'Clear Search' } = clear || {};
|
|
70
70
|
if (!show) {
|
|
71
71
|
return null;
|
|
72
72
|
}
|
|
73
73
|
return (
|
|
74
|
-
<
|
|
74
|
+
<li className="text-right p-3">
|
|
75
75
|
<NsButton onClick={onClear} data-testid="autocomplete-clear-id">
|
|
76
76
|
<NsTypography variant={'p-xs'} weight="bold">
|
|
77
77
|
{text}
|
|
78
78
|
</NsTypography>
|
|
79
79
|
</NsButton>
|
|
80
|
-
</
|
|
80
|
+
</li>
|
|
81
81
|
);
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -87,13 +87,13 @@ const NsAutocomplete = ({
|
|
|
87
87
|
return null;
|
|
88
88
|
}
|
|
89
89
|
return (
|
|
90
|
-
<
|
|
90
|
+
<li className="text-center p-3">
|
|
91
91
|
<NsButton onClick={onSeeMore} data-testid="autocomplete-loadmore-id">
|
|
92
92
|
<NsTypography variant="p-xs" weight="bold">
|
|
93
93
|
{text}
|
|
94
94
|
</NsTypography>
|
|
95
95
|
</NsButton>
|
|
96
|
-
</
|
|
96
|
+
</li>
|
|
97
97
|
);
|
|
98
98
|
};
|
|
99
99
|
|
|
@@ -120,7 +120,10 @@ const NsAutocomplete = ({
|
|
|
120
120
|
ListboxComponent={renderListBoxComponent}
|
|
121
121
|
renderGroup={renderGroupName}
|
|
122
122
|
onChange={handleSelect}
|
|
123
|
-
|
|
123
|
+
onInputChange={handleInputChange}
|
|
124
|
+
value={value}
|
|
125
|
+
inputValue={inputValue}
|
|
126
|
+
freeSolo
|
|
124
127
|
/>
|
|
125
128
|
);
|
|
126
129
|
};
|
|
@@ -6,27 +6,29 @@ import { ComponentsProps } from '@mui/material';
|
|
|
6
6
|
export type NsAutocompleteProps = {
|
|
7
7
|
id?: string;
|
|
8
8
|
options: OptionsProps[];
|
|
9
|
-
loading?:boolean;
|
|
9
|
+
loading?: boolean;
|
|
10
10
|
renderOptions: React.ComponentType<any>;
|
|
11
|
-
noOptionsText
|
|
11
|
+
noOptionsText?: string;
|
|
12
12
|
// eslint-disable-next-line no-unused-vars
|
|
13
|
-
onSelect?: (params: OptionsProps | null) => void;
|
|
13
|
+
onSelect?: (params: string | OptionsProps | null) => void;
|
|
14
14
|
// eslint-disable-next-line no-unused-vars
|
|
15
|
-
onChange?: (params) => void;
|
|
15
|
+
onChange?: (params: string) => void;
|
|
16
16
|
clear?: {
|
|
17
17
|
text: string;
|
|
18
18
|
show?: boolean; //default to false
|
|
19
|
-
onClear: () =>
|
|
19
|
+
onClear: () => void;
|
|
20
20
|
};
|
|
21
21
|
seeMore?: {
|
|
22
22
|
text: string;
|
|
23
23
|
show?: boolean; //default to false
|
|
24
|
-
onSeeMore: () =>
|
|
24
|
+
onSeeMore: () => void;
|
|
25
25
|
};
|
|
26
26
|
placeholder?: string;
|
|
27
27
|
className?: string;
|
|
28
28
|
iconStart?: string | React.ReactNode;
|
|
29
29
|
iconEnd?: string | React.ReactNode;
|
|
30
|
+
inputValue: string;
|
|
31
|
+
value: string | OptionsProps | null;
|
|
30
32
|
} & AdditionalProps;
|
|
31
33
|
|
|
32
34
|
export type ListUiProps = {
|
|
@@ -18,8 +18,8 @@ const NsBreadcrumb = (props: PropsWithChildren<NsBreadcrumbProps>) => {
|
|
|
18
18
|
const { items, iconVisibility } = props;
|
|
19
19
|
|
|
20
20
|
const theme = useTheme();
|
|
21
|
-
const neutral80 = color('neutral', '80')(theme);
|
|
22
|
-
const neutral60 = color('neutral', '60')(theme);
|
|
21
|
+
const neutral80 = color('neutral', '80')({ theme });
|
|
22
|
+
const neutral60 = color('neutral', '60')({ theme });
|
|
23
23
|
|
|
24
24
|
const getLabel = (item: ItemProps) => {
|
|
25
25
|
if (item?.href) {
|