uikit-react-public 0.51.0 → 0.52.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/dist/components/MultiSelect/MultiSelect.d.ts +4 -0
- package/dist/components/MultiSelect/MultiSelect.stories.d.ts +206 -0
- package/dist/components/MultiSelect/MultiSelect.types.d.ts +128 -0
- package/dist/components/MultiSelect/__tests__/MultiSelect.test.d.ts +1 -0
- package/dist/components/MultiSelect/index.d.ts +2 -0
- package/dist/components/MultiSelect/subcomponents/CustomOption.d.ts +3 -0
- package/dist/components/MultiSelect/subcomponents/CustomSelect.d.ts +4 -0
- package/dist/components/MultiSelect/subcomponents/FilterInput.d.ts +16 -0
- package/dist/components/MultiSelect/subcomponents/Panel.d.ts +8 -0
- package/dist/components/MultiSelect/subcomponents/VisibleField.d.ts +17 -0
- package/dist/components/MultiSelect/subcomponents/index.d.ts +5 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +963 -498
- package/lib/components/MultiSelect/MultiSelect.mdx +151 -0
- package/lib/components/MultiSelect/MultiSelect.stories.tsx +308 -0
- package/lib/components/MultiSelect/MultiSelect.tsx +24 -0
- package/lib/components/MultiSelect/MultiSelect.types.ts +142 -0
- package/lib/components/MultiSelect/__tests__/MultiSelect.test.tsx +1300 -0
- package/lib/components/MultiSelect/__tests__/__snapshots__/MultiSelect.test.tsx.snap +44 -0
- package/lib/components/MultiSelect/index.ts +2 -0
- package/lib/components/MultiSelect/subcomponents/CustomOption.tsx +107 -0
- package/lib/components/MultiSelect/subcomponents/CustomSelect.tsx +701 -0
- package/lib/components/MultiSelect/subcomponents/FilterInput.tsx +90 -0
- package/lib/components/MultiSelect/subcomponents/Panel.tsx +69 -0
- package/lib/components/MultiSelect/subcomponents/VisibleField.tsx +147 -0
- package/lib/components/MultiSelect/subcomponents/index.tsx +5 -0
- package/lib/components/index.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import { useTheme } from '../../../theme';
|
|
3
|
+
import type { FilterInputProps } from '../MultiSelect.types';
|
|
4
|
+
|
|
5
|
+
type FilterInputComponentProps = {
|
|
6
|
+
value: string;
|
|
7
|
+
onChange: (value: string) => void;
|
|
8
|
+
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
9
|
+
onTabOut?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
inputRef?: React.RefObject<HTMLInputElement | null>;
|
|
13
|
+
className?: string;
|
|
14
|
+
ariaControls?: string;
|
|
15
|
+
ariaExpanded?: boolean;
|
|
16
|
+
ariaActiveDescendant?: string;
|
|
17
|
+
} & FilterInputProps;
|
|
18
|
+
|
|
19
|
+
const FilterInput = ({
|
|
20
|
+
value,
|
|
21
|
+
onChange,
|
|
22
|
+
onBlur,
|
|
23
|
+
onTabOut,
|
|
24
|
+
placeholder,
|
|
25
|
+
disabled,
|
|
26
|
+
inputRef,
|
|
27
|
+
className,
|
|
28
|
+
ariaControls,
|
|
29
|
+
ariaExpanded,
|
|
30
|
+
ariaActiveDescendant,
|
|
31
|
+
...rest
|
|
32
|
+
}: FilterInputComponentProps) => {
|
|
33
|
+
const [theme] = useTheme();
|
|
34
|
+
|
|
35
|
+
const handleOnKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
36
|
+
if (e.key === 'Tab') {
|
|
37
|
+
onTabOut?.(e);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Let parent handle key navigation
|
|
42
|
+
if (
|
|
43
|
+
e.key === 'Escape' ||
|
|
44
|
+
e.key === 'Enter' ||
|
|
45
|
+
e.key === 'ArrowUp' ||
|
|
46
|
+
e.key === 'ArrowDown'
|
|
47
|
+
)
|
|
48
|
+
return;
|
|
49
|
+
e.stopPropagation();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const style = css`
|
|
53
|
+
flex: 1;
|
|
54
|
+
border: none;
|
|
55
|
+
outline: none;
|
|
56
|
+
background: transparent;
|
|
57
|
+
font: inherit;
|
|
58
|
+
color: ${theme.colour.text.default};
|
|
59
|
+
&::placeholder {
|
|
60
|
+
color: ${theme.colour.text.tertiary};
|
|
61
|
+
}
|
|
62
|
+
&:disabled {
|
|
63
|
+
color: ${theme.colour.text.disabled};
|
|
64
|
+
cursor: not-allowed;
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
return (
|
|
68
|
+
<input
|
|
69
|
+
ref={inputRef}
|
|
70
|
+
className={cx(style, className)}
|
|
71
|
+
value={value}
|
|
72
|
+
placeholder={placeholder}
|
|
73
|
+
disabled={disabled}
|
|
74
|
+
onChange={(e) => onChange(e.target.value)}
|
|
75
|
+
onBlur={onBlur}
|
|
76
|
+
onClick={(e) => e.stopPropagation()}
|
|
77
|
+
onKeyDown={(e) => handleOnKeyDown(e)}
|
|
78
|
+
aria-autocomplete='list'
|
|
79
|
+
role='searchbox'
|
|
80
|
+
aria-haspopup='listbox'
|
|
81
|
+
aria-controls={ariaControls}
|
|
82
|
+
aria-expanded={ariaExpanded}
|
|
83
|
+
aria-activedescendant={ariaActiveDescendant}
|
|
84
|
+
aria-label='Filter options'
|
|
85
|
+
{...rest}
|
|
86
|
+
/>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default FilterInput;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import { useTheme } from '../../../theme';
|
|
3
|
+
import type { SelectDropdownWidth } from '../MultiSelect.types';
|
|
4
|
+
|
|
5
|
+
const NAME = 'ucl-uikit-multiselect__panel';
|
|
6
|
+
|
|
7
|
+
type PanelProps = React.ComponentPropsWithoutRef<'div'> & {
|
|
8
|
+
dropdownWidth?: SelectDropdownWidth;
|
|
9
|
+
referenceWidth?: number;
|
|
10
|
+
maxWidth?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const Panel = ({
|
|
14
|
+
className,
|
|
15
|
+
dropdownWidth = 'content',
|
|
16
|
+
referenceWidth,
|
|
17
|
+
maxWidth,
|
|
18
|
+
...props
|
|
19
|
+
}: PanelProps) => {
|
|
20
|
+
const [theme] = useTheme();
|
|
21
|
+
|
|
22
|
+
const handleClick = (event: React.MouseEvent) => {
|
|
23
|
+
// Missed clicks on the panel should not close the dropdown
|
|
24
|
+
event.stopPropagation();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const referenceWidthValue =
|
|
28
|
+
typeof referenceWidth === 'number' ? `${referenceWidth}px` : '100%';
|
|
29
|
+
const maxWidthValue =
|
|
30
|
+
typeof maxWidth === 'number'
|
|
31
|
+
? `min(${maxWidth}px, calc(100vw - (${theme.margin.m32} * 2)))`
|
|
32
|
+
: `calc(100vw - (${theme.margin.m32} * 2))`;
|
|
33
|
+
|
|
34
|
+
const baseStyle = css`
|
|
35
|
+
min-width: ${referenceWidthValue};
|
|
36
|
+
width: fit-content;
|
|
37
|
+
max-width: ${maxWidthValue};
|
|
38
|
+
max-height: min(400px, var(--ucl-overlay-available-height, 400px));
|
|
39
|
+
overflow-y: auto;
|
|
40
|
+
overflow-x: hidden;
|
|
41
|
+
box-sizing: border-box;
|
|
42
|
+
padding: ${theme.padding.p8} 0;
|
|
43
|
+
border: ${theme.border.b1} solid ${theme.colour.border.subtle};
|
|
44
|
+
background-color: ${theme.colour.fill.inverse};
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
const matchSelectWidthStyle = css`
|
|
48
|
+
width: ${referenceWidthValue};
|
|
49
|
+
max-width: ${referenceWidthValue};
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const style = cx(
|
|
53
|
+
NAME,
|
|
54
|
+
baseStyle,
|
|
55
|
+
dropdownWidth === 'match-select' && matchSelectWidthStyle,
|
|
56
|
+
className
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div
|
|
61
|
+
className={style}
|
|
62
|
+
data-testid={NAME}
|
|
63
|
+
onClick={handleClick}
|
|
64
|
+
{...props}
|
|
65
|
+
/>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default Panel;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import Icon from '../../Icon';
|
|
3
|
+
import { useTheme } from '../../../theme';
|
|
4
|
+
import { OptionData } from '../MultiSelect.types';
|
|
5
|
+
|
|
6
|
+
const NAME = 'ucl-uikit-multiselect__visible-field';
|
|
7
|
+
|
|
8
|
+
interface VisibleFieldProps<T> {
|
|
9
|
+
isOpen?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
selectedOptions: OptionData<T>[];
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
selectionCountLabel?: string;
|
|
14
|
+
filterable?: boolean;
|
|
15
|
+
clearable?: boolean;
|
|
16
|
+
onClear?: (event: React.MouseEvent | React.KeyboardEvent) => void;
|
|
17
|
+
clearButtonRef?: React.RefObject<HTMLButtonElement | null>;
|
|
18
|
+
className?: string;
|
|
19
|
+
chevronIconClassName?: string;
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const VisibleField = <T extends string | number>({
|
|
24
|
+
selectedOptions,
|
|
25
|
+
isOpen,
|
|
26
|
+
placeholder,
|
|
27
|
+
selectionCountLabel,
|
|
28
|
+
disabled,
|
|
29
|
+
filterable,
|
|
30
|
+
clearable = false,
|
|
31
|
+
onClear,
|
|
32
|
+
clearButtonRef,
|
|
33
|
+
className,
|
|
34
|
+
chevronIconClassName,
|
|
35
|
+
children,
|
|
36
|
+
}: VisibleFieldProps<T>) => {
|
|
37
|
+
const [theme] = useTheme();
|
|
38
|
+
const { md } = theme.typography.body;
|
|
39
|
+
|
|
40
|
+
const baseStyle = css`
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: space-between;
|
|
44
|
+
|
|
45
|
+
gap: 8px;
|
|
46
|
+
width: 100%;
|
|
47
|
+
font-family: ${md.fontFamily};
|
|
48
|
+
font-feature-settings: ${md.fontSettings};
|
|
49
|
+
font-size: ${md.fontSize}px;
|
|
50
|
+
font-weight: ${md.fontWeight};
|
|
51
|
+
line-height: ${md.lineHeight}%;
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
const style = cx(NAME, baseStyle, className);
|
|
55
|
+
|
|
56
|
+
const innerStyle = css`
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
white-space: nowrap;
|
|
59
|
+
text-overflow: ellipsis;
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
const chevronIconBaseStyle = css`
|
|
63
|
+
flex-shrink: 0;
|
|
64
|
+
margin-left: auto;
|
|
65
|
+
color: ${theme.colour.icon.default};
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
const chevronIconOpenStyle = css`
|
|
69
|
+
transform: rotate(180deg);
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
const chevronIconDisabledStyle = css`
|
|
73
|
+
color: ${theme.colour.icon.disabled};
|
|
74
|
+
`;
|
|
75
|
+
|
|
76
|
+
const chevronIconStyle = cx(
|
|
77
|
+
chevronIconBaseStyle,
|
|
78
|
+
isOpen && chevronIconOpenStyle,
|
|
79
|
+
disabled && chevronIconDisabledStyle,
|
|
80
|
+
chevronIconClassName
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const clearButtonStyle = css`
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
flex-shrink: 0;
|
|
88
|
+
margin-left: auto;
|
|
89
|
+
padding: 0;
|
|
90
|
+
border: none;
|
|
91
|
+
background: transparent;
|
|
92
|
+
color: ${theme.colour.icon.default};
|
|
93
|
+
cursor: pointer;
|
|
94
|
+
|
|
95
|
+
&:focus-visible {
|
|
96
|
+
outline: none;
|
|
97
|
+
box-shadow: ${theme.boxShadow.focus};
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
|
|
101
|
+
// const showClearButton = clearable && !!selectedOption && !disabled;
|
|
102
|
+
const hasSelection = selectedOptions.length > 0;
|
|
103
|
+
const showClearButton = clearable && hasSelection && !disabled;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div
|
|
107
|
+
className={style}
|
|
108
|
+
data-testid={NAME}
|
|
109
|
+
>
|
|
110
|
+
{filterable && isOpen ? (
|
|
111
|
+
<div className={innerStyle}>{children}</div>
|
|
112
|
+
) : (
|
|
113
|
+
<span className={innerStyle}>
|
|
114
|
+
{hasSelection
|
|
115
|
+
? selectedOptions.length >= 3
|
|
116
|
+
? `${selectedOptions.length}${
|
|
117
|
+
selectionCountLabel ? ` ${selectionCountLabel}` : ''
|
|
118
|
+
} selected`
|
|
119
|
+
: selectedOptions.map((o) => o.label).join(', ')
|
|
120
|
+
: placeholder || ''}
|
|
121
|
+
</span>
|
|
122
|
+
)}
|
|
123
|
+
{showClearButton ? (
|
|
124
|
+
<button
|
|
125
|
+
ref={clearButtonRef}
|
|
126
|
+
type='button'
|
|
127
|
+
className={clearButtonStyle}
|
|
128
|
+
aria-label='Clear selection'
|
|
129
|
+
data-testid={`${NAME}-clear-button`}
|
|
130
|
+
onClick={(event) => {
|
|
131
|
+
event.stopPropagation();
|
|
132
|
+
onClear?.(event);
|
|
133
|
+
}}
|
|
134
|
+
onKeyDown={(event) => {
|
|
135
|
+
event.stopPropagation();
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
<Icon.X />
|
|
139
|
+
</button>
|
|
140
|
+
) : (
|
|
141
|
+
<Icon.ChevronDown className={chevronIconStyle} />
|
|
142
|
+
)}
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export default VisibleField;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as CustomSelect } from './CustomSelect';
|
|
2
|
+
export { default as CustomOption } from './CustomOption';
|
|
3
|
+
export { default as Panel } from './Panel';
|
|
4
|
+
export { default as VisibleField } from './VisibleField';
|
|
5
|
+
export { default as FilterInput } from './FilterInput';
|
package/lib/components/index.ts
CHANGED
|
@@ -163,6 +163,9 @@ export type { MenuProps as MenuNewProps } from './MenuNew';
|
|
|
163
163
|
export { default as Select } from './Select';
|
|
164
164
|
export type { SelectProps } from './Select';
|
|
165
165
|
|
|
166
|
+
export { default as MultiSelect } from './MultiSelect';
|
|
167
|
+
export type { MultiSelectProps } from './MultiSelect';
|
|
168
|
+
|
|
166
169
|
export { default as Footer } from './Footer';
|
|
167
170
|
export type { FooterProps } from './Footer';
|
|
168
171
|
|