uikit-react-public 0.51.0 → 0.52.1
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 +1079 -525
- package/lib/components/Calendar/__tests__/__snapshots__/Calendar.test.tsx.snap +4 -4
- 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/lib/theme/Theme.mdx +2 -0
- package/lib/theme/light/lightColour.ts +3 -7
- package/lib/theme/original/originalColourNewStructure.ts +3 -7
- package/package.json +2 -2
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`MultiSelect > Snapshot: default 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
aria-expanded="false"
|
|
6
|
+
aria-haspopup="listbox"
|
|
7
|
+
class="ucl-uikit-multiselect css-186xh36"
|
|
8
|
+
data-testid="ucl-uikit-multiselect"
|
|
9
|
+
role="combobox"
|
|
10
|
+
tabindex="0"
|
|
11
|
+
>
|
|
12
|
+
<div
|
|
13
|
+
class="ucl-uikit-multiselect__visible-field css-1k5anab"
|
|
14
|
+
data-testid="ucl-uikit-multiselect__visible-field"
|
|
15
|
+
>
|
|
16
|
+
<span
|
|
17
|
+
class="css-16t5nns"
|
|
18
|
+
/>
|
|
19
|
+
<svg
|
|
20
|
+
class="ucl-uikit-icon css-1e7du5a"
|
|
21
|
+
data-testid="ucl-uikit-icon"
|
|
22
|
+
fill="none"
|
|
23
|
+
focusable="false"
|
|
24
|
+
height="24"
|
|
25
|
+
stroke="currentColor"
|
|
26
|
+
stroke-linecap="round"
|
|
27
|
+
stroke-linejoin="round"
|
|
28
|
+
stroke-width="2"
|
|
29
|
+
viewBox="0 0 24 24"
|
|
30
|
+
width="24"
|
|
31
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
32
|
+
>
|
|
33
|
+
<path
|
|
34
|
+
d="m6 9 6 6 6-6"
|
|
35
|
+
/>
|
|
36
|
+
</svg>
|
|
37
|
+
</div>
|
|
38
|
+
<span
|
|
39
|
+
aria-live="polite"
|
|
40
|
+
class="css-fj1rnv"
|
|
41
|
+
role="status"
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
`;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { css, cx } from '@emotion/css';
|
|
3
|
+
import { useTheme } from '../../../theme';
|
|
4
|
+
import { CustomOptionProps } from '../MultiSelect.types';
|
|
5
|
+
import Checkbox from '../../Checkbox';
|
|
6
|
+
|
|
7
|
+
const NAME = 'ucl-uikit-multiselect__option';
|
|
8
|
+
|
|
9
|
+
const CustomOption = <T extends string | number>({
|
|
10
|
+
value,
|
|
11
|
+
isSelected = false,
|
|
12
|
+
isActive = false,
|
|
13
|
+
onSelect,
|
|
14
|
+
lineBreak = false,
|
|
15
|
+
testId = NAME,
|
|
16
|
+
className,
|
|
17
|
+
children,
|
|
18
|
+
...props
|
|
19
|
+
}: CustomOptionProps<T>) => {
|
|
20
|
+
const [theme] = useTheme();
|
|
21
|
+
const internalRef = useRef<HTMLDivElement | null>(null);
|
|
22
|
+
|
|
23
|
+
// Scroll into view when selected & the Panel opens
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (isActive && internalRef.current) {
|
|
26
|
+
internalRef.current.scrollIntoView({
|
|
27
|
+
behavior: 'auto',
|
|
28
|
+
block: 'nearest',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}, [isActive]);
|
|
32
|
+
const { md } = theme.typography.body;
|
|
33
|
+
|
|
34
|
+
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
35
|
+
onSelect(event, value);
|
|
36
|
+
event.stopPropagation(); // Otherwise the panel will open again instantaneously
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleMouseDown = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
40
|
+
// Keep focus on the combobox/filter input so blur does not close the panel
|
|
41
|
+
// before the option click handler runs.
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const baseStyle = css`
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: 8px;
|
|
49
|
+
min-height: 40px;
|
|
50
|
+
box-sizing: border-box;
|
|
51
|
+
padding: ${theme.padding.p8} ${theme.padding.p16};
|
|
52
|
+
font-family: ${md.fontFamily};
|
|
53
|
+
font-feature-settings: ${md.fontSettings};
|
|
54
|
+
font-size: ${md.fontSize}px;
|
|
55
|
+
font-weight: ${md.fontWeight};
|
|
56
|
+
line-height: ${md.lineHeight}%;
|
|
57
|
+
background-color: ${theme.colour.fill.inverse};
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
|
|
60
|
+
&:hover {
|
|
61
|
+
background-color: ${theme.colour.fill.brandSubtleHover};
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const noLineWrapStyle = css`
|
|
66
|
+
white-space: nowrap;
|
|
67
|
+
text-overflow: ellipsis;
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
const lineBreakStyle = css`
|
|
71
|
+
word-break: break-all;
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
const selectedStyle = css`
|
|
75
|
+
background-color: ${theme.colour.fill.brandSubtleSelected};
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const style = cx(
|
|
79
|
+
NAME,
|
|
80
|
+
baseStyle,
|
|
81
|
+
!lineBreak && noLineWrapStyle,
|
|
82
|
+
lineBreak && lineBreakStyle,
|
|
83
|
+
isActive && selectedStyle,
|
|
84
|
+
className
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div
|
|
89
|
+
onMouseDown={handleMouseDown}
|
|
90
|
+
onClick={handleClick}
|
|
91
|
+
className={style}
|
|
92
|
+
data-testid={testId}
|
|
93
|
+
ref={internalRef}
|
|
94
|
+
{...props}
|
|
95
|
+
>
|
|
96
|
+
<Checkbox
|
|
97
|
+
checked={isSelected}
|
|
98
|
+
readOnly
|
|
99
|
+
tabIndex={-1}
|
|
100
|
+
aria-hidden='true'
|
|
101
|
+
/>
|
|
102
|
+
{children}
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default CustomOption;
|