@true-engineering/true-react-common-ui-kit 3.8.0 → 3.9.0
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/README.md +16 -0
- package/dist/components/Checkbox/Checkbox.d.ts +2 -2
- package/dist/components/NewMoreMenu/NewMoreMenu.d.ts +1 -1
- package/dist/components/NewMoreMenu/NewMoreMenu.styles.d.ts +3 -1
- package/dist/components/ScrollIntoViewIfNeeded/ScrollIntoViewIfNeeded.d.ts +1 -1
- package/dist/components/Select/Select.d.ts +4 -4
- package/dist/components/Select/components/SelectList/SelectList.d.ts +5 -6
- package/dist/components/Select/components/SelectListItem/SelectListItem.d.ts +2 -2
- package/dist/components/WithPopup/WithPopup.d.ts +2 -0
- package/dist/components/WithPopup/WithPopup.styles.d.ts +1 -1
- package/dist/true-react-common-ui-kit.js +59 -32
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +59 -32
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Checkbox/Checkbox.tsx +88 -85
- package/src/components/NewMoreMenu/NewMoreMenu.stories.tsx +1 -0
- package/src/components/NewMoreMenu/NewMoreMenu.styles.ts +5 -5
- package/src/components/NewMoreMenu/NewMoreMenu.tsx +18 -2
- package/src/components/Select/Select.tsx +609 -580
- package/src/components/Select/components/SelectList/SelectList.tsx +156 -157
- package/src/components/Select/components/SelectListItem/SelectListItem.tsx +72 -68
- package/src/components/WithPopup/WithPopup.stories.tsx +1 -0
- package/src/components/WithPopup/WithPopup.styles.ts +4 -0
- package/src/components/WithPopup/WithPopup.tsx +13 -2
|
@@ -1,157 +1,156 @@
|
|
|
1
|
-
import { ReactNode, useMemo
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
4
|
-
addDataTestId,
|
|
5
|
-
isNotEmpty,
|
|
6
|
-
isReactNodeNotEmpty,
|
|
7
|
-
|
|
8
|
-
} from '
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
convertValueToString,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
)}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
classes.
|
|
106
|
-
classes.
|
|
107
|
-
|
|
108
|
-
)}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
1
|
+
import { ReactNode, useMemo } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import {
|
|
4
|
+
addDataTestId,
|
|
5
|
+
isNotEmpty,
|
|
6
|
+
isReactNodeNotEmpty,
|
|
7
|
+
} from '@true-engineering/true-react-platform-helpers';
|
|
8
|
+
import { ICommonProps } from '../../../../types';
|
|
9
|
+
import { ScrollIntoViewIfNeeded } from '../../../ScrollIntoViewIfNeeded';
|
|
10
|
+
import { ALL_OPTION_INDEX, DEFAULT_OPTION_INDEX } from '../../constants';
|
|
11
|
+
import { IMultipleSelectValue } from '../../types';
|
|
12
|
+
import { ISelectListItemProps, SelectListItem } from '../SelectListItem';
|
|
13
|
+
import { useStyles, ISelectListStyles } from './SelectList.styles';
|
|
14
|
+
|
|
15
|
+
export interface ISelectListProps<Value>
|
|
16
|
+
extends ICommonProps<ISelectListStyles>,
|
|
17
|
+
Pick<ISelectListItemProps, 'onToggleCheckbox' | 'onOptionSelect'> {
|
|
18
|
+
options: Value[] | Readonly<Value[]>;
|
|
19
|
+
focusedIndex?: number;
|
|
20
|
+
activeValue?: Value | Value[];
|
|
21
|
+
noMatchesLabel?: string;
|
|
22
|
+
isLoading?: boolean;
|
|
23
|
+
loadingLabel?: ReactNode;
|
|
24
|
+
defaultOptionLabel?: ReactNode;
|
|
25
|
+
allOptionsLabel?: ReactNode;
|
|
26
|
+
areAllOptionsSelected?: boolean;
|
|
27
|
+
shouldScrollToList?: boolean;
|
|
28
|
+
customListHeader?: ReactNode;
|
|
29
|
+
isOptionDisabled: (value: Value) => boolean;
|
|
30
|
+
convertValueToString: (value: Value) => string | undefined;
|
|
31
|
+
convertValueToReactNode?: (value: Value, isDisabled: boolean) => ReactNode;
|
|
32
|
+
convertValueToId: (value: Value) => string | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function SelectList<Value>({
|
|
36
|
+
options,
|
|
37
|
+
focusedIndex,
|
|
38
|
+
activeValue,
|
|
39
|
+
defaultOptionLabel,
|
|
40
|
+
noMatchesLabel = 'Совпадений не найдено',
|
|
41
|
+
isLoading,
|
|
42
|
+
loadingLabel = 'Загрузка...',
|
|
43
|
+
tweakStyles,
|
|
44
|
+
testId,
|
|
45
|
+
shouldScrollToList = true,
|
|
46
|
+
areAllOptionsSelected,
|
|
47
|
+
customListHeader,
|
|
48
|
+
isOptionDisabled,
|
|
49
|
+
allOptionsLabel,
|
|
50
|
+
onOptionSelect,
|
|
51
|
+
onToggleCheckbox,
|
|
52
|
+
convertValueToString,
|
|
53
|
+
convertValueToReactNode = convertValueToString,
|
|
54
|
+
convertValueToId,
|
|
55
|
+
}: ISelectListProps<Value>): JSX.Element {
|
|
56
|
+
const classes = useStyles({ theme: tweakStyles });
|
|
57
|
+
|
|
58
|
+
const isMultiSelect = isNotEmpty(onToggleCheckbox);
|
|
59
|
+
const multiSelectValue = activeValue as IMultipleSelectValue<Value> | undefined;
|
|
60
|
+
const selectedOptionsCount = multiSelectValue?.length ?? 0;
|
|
61
|
+
|
|
62
|
+
// MultiSelect
|
|
63
|
+
const activeOptionsIdMap = useMemo(
|
|
64
|
+
() => (isMultiSelect ? multiSelectValue?.map(convertValueToId) ?? [] : []),
|
|
65
|
+
[isMultiSelect, multiSelectValue, convertValueToId],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const optionsDisableMap = useMemo(
|
|
69
|
+
() => options.map((o) => isOptionDisabled(o)),
|
|
70
|
+
[options, isOptionDisabled],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const listOptions = useMemo(
|
|
74
|
+
() => options.map((opt, i) => convertValueToReactNode(opt, optionsDisableMap[i])),
|
|
75
|
+
[options, convertValueToReactNode, optionsDisableMap],
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const isActiveOption = (item: Value): boolean =>
|
|
79
|
+
isMultiSelect
|
|
80
|
+
? activeOptionsIdMap.includes(convertValueToId(item))
|
|
81
|
+
: isNotEmpty(activeValue) &&
|
|
82
|
+
convertValueToId(activeValue as Value) === convertValueToId(item);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<ScrollIntoViewIfNeeded
|
|
86
|
+
active={shouldScrollToList && !isMultiSelect}
|
|
87
|
+
className={clsx(classes.root, {
|
|
88
|
+
[classes.withListHeader]: isReactNodeNotEmpty(customListHeader),
|
|
89
|
+
})}
|
|
90
|
+
>
|
|
91
|
+
{isReactNodeNotEmpty(customListHeader) && (
|
|
92
|
+
<div className={classes.listHeader}>{customListHeader}</div>
|
|
93
|
+
)}
|
|
94
|
+
<div className={classes.list} {...addDataTestId(testId)}>
|
|
95
|
+
{isLoading ? (
|
|
96
|
+
<div className={clsx(classes.cell, classes.loading)}>{loadingLabel}</div>
|
|
97
|
+
) : (
|
|
98
|
+
<>
|
|
99
|
+
{isReactNodeNotEmpty(defaultOptionLabel) && (
|
|
100
|
+
<ScrollIntoViewIfNeeded
|
|
101
|
+
active={focusedIndex === DEFAULT_OPTION_INDEX}
|
|
102
|
+
options={{ block: 'nearest' }}
|
|
103
|
+
className={clsx(
|
|
104
|
+
classes.cell,
|
|
105
|
+
classes.defaultCell,
|
|
106
|
+
focusedIndex === DEFAULT_OPTION_INDEX && classes.focused,
|
|
107
|
+
)}
|
|
108
|
+
onClick={(event) => onOptionSelect(DEFAULT_OPTION_INDEX, event)}
|
|
109
|
+
>
|
|
110
|
+
{defaultOptionLabel}
|
|
111
|
+
</ScrollIntoViewIfNeeded>
|
|
112
|
+
)}
|
|
113
|
+
{isReactNodeNotEmpty(allOptionsLabel) && (
|
|
114
|
+
<SelectListItem
|
|
115
|
+
classes={classes}
|
|
116
|
+
index={ALL_OPTION_INDEX}
|
|
117
|
+
isSemiChecked={selectedOptionsCount > 0 && !areAllOptionsSelected}
|
|
118
|
+
isActive={areAllOptionsSelected}
|
|
119
|
+
isFocused={focusedIndex === ALL_OPTION_INDEX}
|
|
120
|
+
onOptionSelect={onOptionSelect}
|
|
121
|
+
onToggleCheckbox={onToggleCheckbox}
|
|
122
|
+
>
|
|
123
|
+
{allOptionsLabel}
|
|
124
|
+
</SelectListItem>
|
|
125
|
+
)}
|
|
126
|
+
{listOptions.map((opt, i) => {
|
|
127
|
+
const optionValue = options[i];
|
|
128
|
+
const isFocused = focusedIndex === i;
|
|
129
|
+
const isActive = isActiveOption(optionValue);
|
|
130
|
+
// проверяем, что опция задизейблена
|
|
131
|
+
const isDisabled = optionsDisableMap[i];
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<SelectListItem
|
|
135
|
+
key={i}
|
|
136
|
+
classes={classes}
|
|
137
|
+
index={i}
|
|
138
|
+
isDisabled={isDisabled}
|
|
139
|
+
isActive={isActive}
|
|
140
|
+
isFocused={isFocused}
|
|
141
|
+
onOptionSelect={onOptionSelect}
|
|
142
|
+
onToggleCheckbox={onToggleCheckbox}
|
|
143
|
+
>
|
|
144
|
+
{opt}
|
|
145
|
+
</SelectListItem>
|
|
146
|
+
);
|
|
147
|
+
})}
|
|
148
|
+
{listOptions.length === 0 && (
|
|
149
|
+
<div className={clsx(classes.cell, classes.noMatchesLabel)}>{noMatchesLabel}</div>
|
|
150
|
+
)}
|
|
151
|
+
</>
|
|
152
|
+
)}
|
|
153
|
+
</div>
|
|
154
|
+
</ScrollIntoViewIfNeeded>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
@@ -1,68 +1,72 @@
|
|
|
1
|
-
import { ReactNode, MouseEvent, FC } from 'react';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import { Classes } from 'jss';
|
|
4
|
-
import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
5
|
-
import { addDataAttributes } from '../../../../helpers';
|
|
6
|
-
import { Checkbox } from '../../../Checkbox';
|
|
7
|
-
import { ScrollIntoViewIfNeeded } from '../../../ScrollIntoViewIfNeeded';
|
|
8
|
-
import { checkboxStyles } from './SelectListItem.styles';
|
|
9
|
-
|
|
10
|
-
export interface ISelectListItemProps {
|
|
11
|
-
index: number;
|
|
12
|
-
isSemiChecked?: boolean;
|
|
13
|
-
isDisabled?: boolean;
|
|
14
|
-
isActive?: boolean;
|
|
15
|
-
isFocused?: boolean;
|
|
16
|
-
children: ReactNode;
|
|
17
|
-
classes: Classes<'cellWithCheckbox' | 'cell' | 'focused' | 'active' | 'disabled'>; // TODO: !!!
|
|
18
|
-
onOptionSelect: (index: number, event: MouseEvent<HTMLElement>) => void;
|
|
19
|
-
onToggleCheckbox?: (
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
1
|
+
import { ReactNode, MouseEvent, FC, KeyboardEvent, ChangeEvent } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { Classes } from 'jss';
|
|
4
|
+
import { isNotEmpty } from '@true-engineering/true-react-platform-helpers';
|
|
5
|
+
import { addDataAttributes } from '../../../../helpers';
|
|
6
|
+
import { Checkbox } from '../../../Checkbox';
|
|
7
|
+
import { ScrollIntoViewIfNeeded } from '../../../ScrollIntoViewIfNeeded';
|
|
8
|
+
import { checkboxStyles } from './SelectListItem.styles';
|
|
9
|
+
|
|
10
|
+
export interface ISelectListItemProps {
|
|
11
|
+
index: number;
|
|
12
|
+
isSemiChecked?: boolean;
|
|
13
|
+
isDisabled?: boolean;
|
|
14
|
+
isActive?: boolean;
|
|
15
|
+
isFocused?: boolean;
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
classes: Classes<'cellWithCheckbox' | 'cell' | 'focused' | 'active' | 'disabled'>; // TODO: !!!
|
|
18
|
+
onOptionSelect: (index: number, event: MouseEvent<HTMLElement>) => void;
|
|
19
|
+
onToggleCheckbox?: (
|
|
20
|
+
index: number,
|
|
21
|
+
isSelected: boolean,
|
|
22
|
+
event: ChangeEvent<HTMLElement> | KeyboardEvent,
|
|
23
|
+
) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const SelectListItem: FC<ISelectListItemProps> = ({
|
|
27
|
+
classes,
|
|
28
|
+
index,
|
|
29
|
+
isSemiChecked,
|
|
30
|
+
isDisabled,
|
|
31
|
+
isActive,
|
|
32
|
+
children,
|
|
33
|
+
isFocused,
|
|
34
|
+
onOptionSelect,
|
|
35
|
+
onToggleCheckbox,
|
|
36
|
+
}) => {
|
|
37
|
+
const isMultiSelect = isNotEmpty(onToggleCheckbox);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<ScrollIntoViewIfNeeded
|
|
41
|
+
active={isFocused}
|
|
42
|
+
options={{ block: 'nearest' }}
|
|
43
|
+
className={clsx(classes.cell, {
|
|
44
|
+
[classes.cellWithCheckbox]: isMultiSelect,
|
|
45
|
+
[classes.focused]: isFocused,
|
|
46
|
+
[classes.active]: isActive && !isMultiSelect,
|
|
47
|
+
[classes.disabled]: isDisabled,
|
|
48
|
+
})}
|
|
49
|
+
{...addDataAttributes({
|
|
50
|
+
disabled: isDisabled,
|
|
51
|
+
active: isActive,
|
|
52
|
+
focused: isFocused,
|
|
53
|
+
})}
|
|
54
|
+
onClick={!isDisabled && !isMultiSelect ? (event) => onOptionSelect(index, event) : undefined}
|
|
55
|
+
>
|
|
56
|
+
{isMultiSelect ? (
|
|
57
|
+
<Checkbox
|
|
58
|
+
value={index}
|
|
59
|
+
isChecked={isActive || isSemiChecked}
|
|
60
|
+
isSemiChecked={isSemiChecked}
|
|
61
|
+
isDisabled={isDisabled}
|
|
62
|
+
tweakStyles={checkboxStyles}
|
|
63
|
+
onSelect={(v, event) => onToggleCheckbox(index, v.isSelected, event)}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</Checkbox>
|
|
67
|
+
) : (
|
|
68
|
+
children
|
|
69
|
+
)}
|
|
70
|
+
</ScrollIntoViewIfNeeded>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
@@ -25,6 +25,8 @@ export interface IWithPopupProps extends ICommonProps<IWithPopupStyles> {
|
|
|
25
25
|
middlewares?: Middleware[];
|
|
26
26
|
/** @default eventType === 'click' ? 'bottom-end' : 'top' */
|
|
27
27
|
placement?: Placement;
|
|
28
|
+
/** @default false */
|
|
29
|
+
shouldHideOnScroll?: boolean;
|
|
28
30
|
/** @default true */
|
|
29
31
|
shouldRenderInBody?: boolean;
|
|
30
32
|
/** @default 'click' */
|
|
@@ -44,6 +46,7 @@ export const WithPopup: FC<IWithPopupProps> = ({
|
|
|
44
46
|
middlewares,
|
|
45
47
|
eventType = 'click',
|
|
46
48
|
placement = eventType === 'click' ? 'bottom-end' : 'top',
|
|
49
|
+
shouldHideOnScroll = false,
|
|
47
50
|
shouldRenderInBody = false,
|
|
48
51
|
hoverDelay = 0,
|
|
49
52
|
popupOffset = DEFAULT_OFFSET,
|
|
@@ -85,7 +88,10 @@ export const WithPopup: FC<IWithPopupProps> = ({
|
|
|
85
88
|
delay: { open: hoverDelay },
|
|
86
89
|
});
|
|
87
90
|
const click = useClick(context, { enabled: eventType === 'click', toggle: false });
|
|
88
|
-
const dismiss = useDismiss(context, {
|
|
91
|
+
const dismiss = useDismiss(context, {
|
|
92
|
+
enabled: eventType === 'click',
|
|
93
|
+
ancestorScroll: shouldHideOnScroll,
|
|
94
|
+
});
|
|
89
95
|
|
|
90
96
|
const { getReferenceProps, getFloatingProps } = useInteractions([hover, click, dismiss]);
|
|
91
97
|
|
|
@@ -108,7 +114,12 @@ export const WithPopup: FC<IWithPopupProps> = ({
|
|
|
108
114
|
<FloatingPortal
|
|
109
115
|
root={!shouldRenderInBody ? (refs.reference.current as HTMLDivElement) : undefined}
|
|
110
116
|
>
|
|
111
|
-
<div
|
|
117
|
+
<div
|
|
118
|
+
style={floatingStyles}
|
|
119
|
+
className={classes.popup}
|
|
120
|
+
ref={refs.setFloating}
|
|
121
|
+
{...getFloatingProps()}
|
|
122
|
+
>
|
|
112
123
|
{isFunction(Popup) ? <Popup onClose={handleClose} /> : Popup}
|
|
113
124
|
</div>
|
|
114
125
|
</FloatingPortal>
|