@nuskin/foundation-ui-components 1.32.0 → 1.32.1-td-849.2
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
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
PropsWithChildren,
|
|
3
|
+
ReactElement,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
|
|
3
9
|
import {
|
|
4
10
|
Autocomplete,
|
|
5
11
|
AutocompleteRenderInputParams,
|
|
6
|
-
ListSubheader,
|
|
7
12
|
Popper,
|
|
8
|
-
useMediaQuery,
|
|
9
|
-
useTheme,
|
|
10
13
|
} from '@mui/material';
|
|
11
14
|
|
|
12
15
|
import { LineLoader } from './helper/LineLoader';
|
|
13
16
|
import { RecentClearAll } from './helper/RecentClearAll';
|
|
14
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
renderGroupBy,
|
|
19
|
+
renderGroupName,
|
|
20
|
+
renderOptionLabel,
|
|
21
|
+
} from './helper/renderGroupName';
|
|
15
22
|
import { SeeMoreButton } from './helper/SeeMoreButton';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
import {
|
|
24
|
+
StyledPopper,
|
|
25
|
+
StyledTextField,
|
|
26
|
+
} from './NsAutocomplete.styled';
|
|
27
|
+
import {
|
|
28
|
+
ComponentBoxProps,
|
|
29
|
+
NsAutocompleteProps,
|
|
30
|
+
OptionsProps,
|
|
31
|
+
} from './types.d';
|
|
19
32
|
|
|
20
|
-
const LISTBOX_PADDING = 8;
|
|
21
33
|
const noop = () => {};
|
|
22
|
-
const OuterElementContext = React.createContext({});
|
|
23
|
-
|
|
24
34
|
const NsAutocomplete = ({
|
|
25
35
|
id = 'custom_autocomplete_dropdown',
|
|
26
36
|
options,
|
|
@@ -41,9 +51,9 @@ const NsAutocomplete = ({
|
|
|
41
51
|
isFilterEnabled = true,
|
|
42
52
|
fullWidth,
|
|
43
53
|
onKeypress,
|
|
44
|
-
}: PropsWithChildren<NsAutocompleteProps>):
|
|
45
|
-
const listboxRef = useRef<any | null>(null);
|
|
54
|
+
}: PropsWithChildren<NsAutocompleteProps>):ReactElement => {
|
|
46
55
|
const [scrollTopPosition, setScrollTopPosition] = useState(0);
|
|
56
|
+
const listboxRef = useRef<HTMLUListElement | null>(null);
|
|
47
57
|
|
|
48
58
|
useEffect(() => {
|
|
49
59
|
if (listboxRef.current && options.length > 0) {
|
|
@@ -51,13 +61,6 @@ const NsAutocomplete = ({
|
|
|
51
61
|
}
|
|
52
62
|
}, [options, scrollTopPosition]);
|
|
53
63
|
|
|
54
|
-
const OuterElementType = React.forwardRef((props: any, ref) => {
|
|
55
|
-
const outerProps = React.useContext(OuterElementContext);
|
|
56
|
-
return <ul ref={ref} {...props} {...outerProps} />;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
OuterElementType.displayName = 'OuterElementType';
|
|
60
|
-
|
|
61
64
|
const renderInput = (params: AutocompleteRenderInputParams) => (
|
|
62
65
|
<StyledTextField
|
|
63
66
|
{...(params as any)}
|
|
@@ -80,132 +83,59 @@ const NsAutocomplete = ({
|
|
|
80
83
|
</li>
|
|
81
84
|
);
|
|
82
85
|
|
|
83
|
-
const
|
|
84
|
-
const { data, index, style } = props;
|
|
85
|
-
const dataSet = data[index];
|
|
86
|
-
const option = dataSet?.[1];
|
|
87
|
-
const inlineStyle = {
|
|
88
|
-
top: (style.top as number) + LISTBOX_PADDING,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
if (Object.hasOwn(dataSet, 'group')) {
|
|
92
|
-
return (
|
|
93
|
-
<ListSubheader key={dataSet.key} component="div" style={inlineStyle}>
|
|
94
|
-
{dataSet.group}
|
|
95
|
-
</ListSubheader>
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
86
|
+
const renderListBoxComponent = ({ children, ...rest }: ComponentBoxProps): React.JSX.Element => {
|
|
99
87
|
return (
|
|
100
|
-
<
|
|
101
|
-
{
|
|
102
|
-
|
|
88
|
+
<ul
|
|
89
|
+
aria-labelledby={rest['aria-labelledby']}
|
|
90
|
+
onMouseDown={rest.onMouseDown}
|
|
91
|
+
role={rest.role}
|
|
92
|
+
id={rest.id}
|
|
93
|
+
className={rest.className}
|
|
94
|
+
ref={listboxRef}
|
|
95
|
+
style={{
|
|
96
|
+
maxHeight: '300px',
|
|
97
|
+
padding: '0',
|
|
98
|
+
margin: '0',
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
<RecentClearAll
|
|
102
|
+
show={clear?.show ?? false}
|
|
103
|
+
text={clear?.text ?? 'Clear All'}
|
|
104
|
+
onClick={clear?.onClear ?? noop}
|
|
105
|
+
testId="autocomplete-clear-id"
|
|
106
|
+
recentSearchText={clear?.recentSearchText ?? 'Your Recent Searches'}
|
|
107
|
+
/>
|
|
108
|
+
{children}
|
|
109
|
+
<SeeMoreButton
|
|
110
|
+
onSeeMore={seeMore?.onSeeMore}
|
|
111
|
+
show={seeMore?.show}
|
|
112
|
+
text={seeMore?.text}
|
|
113
|
+
options={options}
|
|
114
|
+
setScrollTopPosition={setScrollTopPosition}
|
|
115
|
+
listboxRef={listboxRef}
|
|
116
|
+
/>
|
|
117
|
+
</ul>
|
|
103
118
|
);
|
|
104
119
|
};
|
|
105
|
-
|
|
106
|
-
const useResetCache = (data: any) => {
|
|
107
|
-
const ref = React.useRef<VariableSizeList>(null);
|
|
108
|
-
React.useEffect(() => {
|
|
109
|
-
if (ref.current != null) {
|
|
110
|
-
ref.current.resetAfterIndex(0, true);
|
|
111
|
-
}
|
|
112
|
-
}, [data]);
|
|
113
|
-
return ref;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const ListboxComponent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLElement>>(
|
|
117
|
-
function ListboxComponent(props, ref) {
|
|
118
|
-
const { children, ...other } = props;
|
|
119
|
-
const itemData: React.ReactElement[] = [];
|
|
120
|
-
(children as React.ReactElement[]).forEach(
|
|
121
|
-
(item: React.ReactElement & { children?: React.ReactElement[] }) => {
|
|
122
|
-
itemData.push(item);
|
|
123
|
-
itemData.push(...(item.children || []));
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
const theme = useTheme();
|
|
128
|
-
const smUp = useMediaQuery(theme.breakpoints.up('sm'), {
|
|
129
|
-
noSsr: true,
|
|
130
|
-
});
|
|
131
|
-
const itemCount = itemData.length;
|
|
132
|
-
const itemSize = smUp ? 36 : 48;
|
|
133
|
-
|
|
134
|
-
const getChildSize = (child: React.ReactElement) => {
|
|
135
|
-
if (Object.hasOwn(child, 'group')) {
|
|
136
|
-
return 48;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return itemSize;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const getHeight = () => {
|
|
143
|
-
if (itemCount > 8) {
|
|
144
|
-
return 8 * itemSize;
|
|
145
|
-
}
|
|
146
|
-
return itemData.map(getChildSize).reduce((a, b) => a + b, 0);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const gridRef = useResetCache(itemCount);
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<>
|
|
153
|
-
<RecentClearAll
|
|
154
|
-
show={clear?.show ?? false}
|
|
155
|
-
text={clear?.text ?? 'Clear All'}
|
|
156
|
-
onClick={clear?.onClear ?? noop}
|
|
157
|
-
testId="autocomplete-clear-id"
|
|
158
|
-
recentSearchText={clear?.recentSearchText ?? 'Your Recent Searches'}
|
|
159
|
-
/>
|
|
160
|
-
<div ref={ref}>
|
|
161
|
-
<OuterElementContext.Provider value={other}>
|
|
162
|
-
<VariableSizeList
|
|
163
|
-
itemData={itemData}
|
|
164
|
-
height={getHeight() + 2 * LISTBOX_PADDING}
|
|
165
|
-
width="100%"
|
|
166
|
-
ref={gridRef}
|
|
167
|
-
outerElementType={OuterElementType}
|
|
168
|
-
innerElementType="ul"
|
|
169
|
-
itemSize={(index) => getChildSize(itemData[index])}
|
|
170
|
-
overscanCount={5}
|
|
171
|
-
itemCount={itemCount}
|
|
172
|
-
>
|
|
173
|
-
{renderRow}
|
|
174
|
-
</VariableSizeList>
|
|
175
|
-
</OuterElementContext.Provider>
|
|
176
|
-
</div>
|
|
177
|
-
<SeeMoreButton
|
|
178
|
-
onSeeMore={seeMore?.onSeeMore}
|
|
179
|
-
show={seeMore?.show}
|
|
180
|
-
text={seeMore?.text}
|
|
181
|
-
options={options}
|
|
182
|
-
setScrollTopPosition={setScrollTopPosition}
|
|
183
|
-
listboxRef={listboxRef}
|
|
184
|
-
/>
|
|
185
|
-
</>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
);
|
|
189
|
-
|
|
190
120
|
return (
|
|
191
121
|
<>
|
|
192
122
|
<LineLoader show={loading ?? false} />
|
|
193
123
|
<Autocomplete
|
|
194
|
-
|
|
124
|
+
openOnFocus
|
|
195
125
|
id={id}
|
|
196
|
-
|
|
126
|
+
disablePortal
|
|
197
127
|
className={className}
|
|
128
|
+
options={options}
|
|
198
129
|
loading={loading}
|
|
199
130
|
noOptionsText={noOptionsText}
|
|
200
|
-
PopperComponent={fullWidth ? StyledPopper : Popper}
|
|
201
|
-
ListboxComponent={ListboxComponent}
|
|
202
|
-
options={options}
|
|
203
131
|
groupBy={renderGroupBy}
|
|
204
132
|
getOptionLabel={renderOptionLabel}
|
|
205
|
-
renderOption={
|
|
206
|
-
renderGroup={(params) => params as any}
|
|
207
|
-
onChange={onChange}
|
|
133
|
+
renderOption={renderOption as any}
|
|
208
134
|
renderInput={renderInput}
|
|
135
|
+
PopperComponent={fullWidth ? StyledPopper : Popper} // TODO:https://code.tls.nuskin.io/ns-am/content-foundation/nuskin-app/-/jobs/1355817
|
|
136
|
+
ListboxComponent={renderListBoxComponent}
|
|
137
|
+
renderGroup={renderGroupName}
|
|
138
|
+
onChange={onChange}
|
|
209
139
|
onInputChange={onInputChange}
|
|
210
140
|
value={value}
|
|
211
141
|
onFocus={onFocus ?? noop}
|
|
@@ -6,17 +6,22 @@ import { NsTypography, OptionsProps } from '../../';
|
|
|
6
6
|
|
|
7
7
|
const { getGenomeColor } = ColorUtils;
|
|
8
8
|
export const ListStyled = styled.div`
|
|
9
|
+
position: sticky;
|
|
10
|
+
bottom: 0;
|
|
11
|
+
right: 0;
|
|
9
12
|
display: flex;
|
|
10
13
|
width: 100%;
|
|
11
14
|
flex-direction: row;
|
|
12
15
|
align-items: center;
|
|
13
16
|
gap: 10px;
|
|
14
17
|
padding: 0;
|
|
15
|
-
margin: 4px
|
|
18
|
+
margin: 0px 4px;
|
|
16
19
|
cursor: pointer;
|
|
17
20
|
&:hover {
|
|
18
21
|
background: ${({ theme }) => getGenomeColor(theme, 'A10')};
|
|
19
22
|
}
|
|
23
|
+
background-color: white;
|
|
24
|
+
height: 30px;
|
|
20
25
|
`;
|
|
21
26
|
|
|
22
27
|
type SeeMoreButtonProps = {
|