@leafygreen-ui/combobox 1.2.2 → 2.0.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/CHANGELOG.md +18 -0
- package/dist/Chip.d.ts.map +1 -1
- package/dist/Combobox.d.ts.map +1 -1
- package/dist/Combobox.styles.d.ts +39 -39
- package/dist/Combobox.styles.d.ts.map +1 -1
- package/dist/Combobox.types.d.ts +5 -0
- package/dist/Combobox.types.d.ts.map +1 -1
- package/dist/ComboboxContext.d.ts +5 -1
- package/dist/ComboboxContext.d.ts.map +1 -1
- package/dist/ComboboxGroup.d.ts.map +1 -1
- package/dist/ComboboxMenu/ComboboxMenu.d.ts +10 -0
- package/dist/ComboboxMenu/ComboboxMenu.d.ts.map +1 -0
- package/dist/ComboboxMenu/Menu.styles.d.ts +25 -0
- package/dist/ComboboxMenu/Menu.styles.d.ts.map +1 -0
- package/dist/ComboboxOption.d.ts.map +1 -1
- package/dist/Menu.styles.d.ts +21 -0
- package/dist/Menu.styles.d.ts.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +8 -9
- package/src/Chip.tsx +125 -91
- package/src/Combobox.story.tsx +2 -0
- package/src/Combobox.styles.ts +250 -299
- package/src/Combobox.tsx +156 -189
- package/src/Combobox.types.ts +7 -0
- package/src/ComboboxContext.tsx +16 -1
- package/src/ComboboxGroup.tsx +27 -17
- package/src/ComboboxMenu/ComboboxMenu.tsx +161 -0
- package/src/ComboboxMenu/Menu.styles.ts +131 -0
- package/src/ComboboxOption.tsx +120 -32
- package/src/Menu.styles.ts +110 -0
- package/tsconfig.json +0 -3
- package/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafygreen-ui/combobox",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "leafyGreen UI Kit Combobox",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -20,19 +20,18 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@leafygreen-ui/checkbox": "^
|
|
23
|
+
"@leafygreen-ui/checkbox": "^9.0.0",
|
|
24
24
|
"@leafygreen-ui/emotion": "^4.0.0",
|
|
25
25
|
"@leafygreen-ui/icon": "^11.10.0",
|
|
26
|
-
"@leafygreen-ui/icon-button": "^
|
|
27
|
-
"@leafygreen-ui/inline-definition": "^
|
|
28
|
-
"@leafygreen-ui/interaction-ring": "^3.0.0",
|
|
26
|
+
"@leafygreen-ui/icon-button": "^13.0.0",
|
|
27
|
+
"@leafygreen-ui/inline-definition": "^4.0.1",
|
|
29
28
|
"@leafygreen-ui/hooks": "^7.3.0",
|
|
30
|
-
"@leafygreen-ui/lib": "^9.
|
|
29
|
+
"@leafygreen-ui/lib": "^9.4.0",
|
|
31
30
|
"@leafygreen-ui/palette": "^3.4.0",
|
|
32
|
-
"@leafygreen-ui/popover": "^
|
|
31
|
+
"@leafygreen-ui/popover": "^9.0.0",
|
|
33
32
|
"@leafygreen-ui/tokens": "^1.3.1",
|
|
34
|
-
"@leafygreen-ui/tooltip": "^7.0.
|
|
35
|
-
"@leafygreen-ui/typography": "^
|
|
33
|
+
"@leafygreen-ui/tooltip": "^7.0.4",
|
|
34
|
+
"@leafygreen-ui/typography": "^13.0.0"
|
|
36
35
|
},
|
|
37
36
|
"homepage": "https://github.com/mongodb/leafygreen-ui/tree/main/packages/combobox",
|
|
38
37
|
"repository": {
|
package/src/Chip.tsx
CHANGED
|
@@ -1,85 +1,81 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
|
-
import { ChipProps, ComboboxSize } from './Combobox.types';
|
|
2
|
+
import { ChipProps, ComboboxSize as Size, Theme } from './Combobox.types';
|
|
3
3
|
import Icon from '@leafygreen-ui/icon';
|
|
4
|
-
import { ComboboxContext } from './ComboboxContext';
|
|
4
|
+
import { ComboboxContext, useDarkMode } from './ComboboxContext';
|
|
5
5
|
import { css, cx } from '@leafygreen-ui/emotion';
|
|
6
|
-
import {
|
|
6
|
+
import { palette } from '@leafygreen-ui/palette';
|
|
7
7
|
import InlineDefinition from '@leafygreen-ui/inline-definition';
|
|
8
8
|
import { keyMap } from '@leafygreen-ui/lib';
|
|
9
|
-
import { chipClassName } from './Combobox.styles';
|
|
9
|
+
import { chipClassName, chipWrapperPaddingY } from './Combobox.styles';
|
|
10
10
|
import { typeScales } from '@leafygreen-ui/tokens';
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
switch (size) {
|
|
34
|
-
case ComboboxSize.Default:
|
|
35
|
-
chipSizeStyle = css`
|
|
36
|
-
--lg-combobox-chip-height: 24px;
|
|
37
|
-
--lg-combobox-chip-border-radius: 4px;
|
|
38
|
-
--lg-combobox-chip-font-size: 14px;
|
|
39
|
-
--lg-combobox-chip-line-height: 20px;
|
|
40
|
-
--lg-combobox-chip-padding-x: 6px;
|
|
41
|
-
`;
|
|
42
|
-
break;
|
|
43
|
-
case ComboboxSize.Large:
|
|
44
|
-
chipSizeStyle = css`
|
|
45
|
-
--lg-combobox-chip-height: 28px;
|
|
46
|
-
--lg-combobox-chip-border-radius: 4px;
|
|
47
|
-
--lg-combobox-chip-font-size: ${typeScales.body2.fontSize}px;
|
|
48
|
-
--lg-combobox-chip-line-height: ${typeScales.body2.lineHeight}px;
|
|
49
|
-
--lg-combobox-chip-padding-x: 6px;
|
|
50
|
-
`;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return cx(
|
|
55
|
-
chipModeStyle,
|
|
56
|
-
chipSizeStyle,
|
|
57
|
-
css`
|
|
58
|
-
display: inline-flex;
|
|
59
|
-
align-items: center;
|
|
60
|
-
overflow: hidden;
|
|
61
|
-
white-space: nowrap;
|
|
62
|
-
height: var(--lg-combobox-chip-height);
|
|
63
|
-
font-size: var(--lg-combobox-chip-font-size);
|
|
64
|
-
line-height: var(--lg-combobox-chip-line-height);
|
|
65
|
-
border-radius: var(--lg-combobox-chip-border-radius);
|
|
66
|
-
color: var(--lg-combobox-chip-text-color);
|
|
67
|
-
background-color: var(--lg-combobox-chip-background-color);
|
|
68
|
-
|
|
69
|
-
// TODO - refine these styles
|
|
70
|
-
/* &:focus, */
|
|
71
|
-
&:focus-within {
|
|
72
|
-
background-color: var(--lg-combobox-chip-focus-color);
|
|
73
|
-
}
|
|
74
|
-
`,
|
|
75
|
-
);
|
|
12
|
+
const chipWrapperBaseStyle = css`
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
white-space: nowrap;
|
|
17
|
+
box-sizing: border-box;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const chipWrapperSizeStyle: Record<Size, string> = {
|
|
21
|
+
[Size.Default]: css`
|
|
22
|
+
font-size: ${typeScales.body1.fontSize}px;
|
|
23
|
+
line-height: ${typeScales.body1.lineHeight}px;
|
|
24
|
+
border-radius: 4px;
|
|
25
|
+
`,
|
|
26
|
+
[Size.Large]: css`
|
|
27
|
+
font-size: ${typeScales.body2.fontSize}px;
|
|
28
|
+
line-height: ${typeScales.body2.lineHeight}px;
|
|
29
|
+
border-radius: 4px;
|
|
30
|
+
`,
|
|
76
31
|
};
|
|
77
32
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
33
|
+
const chipWrapperThemeStyle: Record<Theme, string> = {
|
|
34
|
+
[Theme.Light]: css`
|
|
35
|
+
color: ${palette.black};
|
|
36
|
+
background-color: ${palette.gray.light2};
|
|
37
|
+
|
|
38
|
+
// TODO: - refine these styles with Design
|
|
39
|
+
&:focus-within {
|
|
40
|
+
background-color: ${palette.blue.light2};
|
|
41
|
+
}
|
|
42
|
+
`,
|
|
43
|
+
[Theme.Dark]: css`
|
|
44
|
+
color: ${palette.gray.light2};
|
|
45
|
+
background-color: ${palette.gray.dark2};
|
|
46
|
+
|
|
47
|
+
&:focus-within {
|
|
48
|
+
background-color: ${palette.blue.dark2};
|
|
49
|
+
}
|
|
50
|
+
`,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const disabledChipWrapperStyle: Record<Theme, string> = {
|
|
54
|
+
[Theme.Light]: css`
|
|
55
|
+
cursor: not-allowed;
|
|
56
|
+
color: ${palette.gray.base};
|
|
57
|
+
background-color: ${palette.gray.light3};
|
|
58
|
+
`,
|
|
59
|
+
[Theme.Dark]: css`
|
|
60
|
+
cursor: not-allowed;
|
|
61
|
+
color: ${palette.gray.dark2};
|
|
62
|
+
background-color: ${palette.gray.dark4};
|
|
63
|
+
box-shadow: inset 0 0 1px 1px ${palette.gray.dark2}; ;
|
|
64
|
+
`,
|
|
65
|
+
};
|
|
81
66
|
|
|
82
|
-
const
|
|
67
|
+
const chipTextSizeStyle: Record<Size, string> = {
|
|
68
|
+
[Size.Default]: css`
|
|
69
|
+
padding-inline: 6px;
|
|
70
|
+
padding-block: ${chipWrapperPaddingY[Size.Default]}px;
|
|
71
|
+
`,
|
|
72
|
+
[Size.Large]: css`
|
|
73
|
+
padding-inline: 10px;
|
|
74
|
+
padding-block: ${chipWrapperPaddingY[Size.Large]}px;
|
|
75
|
+
`,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const chipButtonStyle = css`
|
|
83
79
|
position: relative;
|
|
84
80
|
display: flex;
|
|
85
81
|
align-items: center;
|
|
@@ -89,25 +85,48 @@ const chipButton = css`
|
|
|
89
85
|
outline: none;
|
|
90
86
|
border: none;
|
|
91
87
|
background-color: transparent;
|
|
92
|
-
color: var(--lg-combobox-chip-icon-color);
|
|
93
88
|
cursor: pointer;
|
|
94
89
|
transition: background-color 100ms ease-in-out;
|
|
95
|
-
|
|
96
|
-
&:before {
|
|
97
|
-
content: '';
|
|
98
|
-
position: absolute;
|
|
99
|
-
top: 0;
|
|
100
|
-
left: 0;
|
|
101
|
-
height: 100%;
|
|
102
|
-
width: 1px;
|
|
103
|
-
background-color: var(--lg-combobox-chip-hover-color);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
&:hover {
|
|
107
|
-
background-color: var(--lg-combobox-chip-hover-color);
|
|
108
|
-
}
|
|
109
90
|
`;
|
|
110
91
|
|
|
92
|
+
const chipButtonThemeStyle: Record<Theme, string> = {
|
|
93
|
+
[Theme.Light]: css`
|
|
94
|
+
color: ${palette.gray.dark2};
|
|
95
|
+
|
|
96
|
+
&:hover {
|
|
97
|
+
color: ${palette.black};
|
|
98
|
+
background-color: ${palette.gray.light1};
|
|
99
|
+
}
|
|
100
|
+
`,
|
|
101
|
+
[Theme.Dark]: css`
|
|
102
|
+
color: ${palette.gray.light1};
|
|
103
|
+
|
|
104
|
+
&:hover {
|
|
105
|
+
color: ${palette.gray.light3};
|
|
106
|
+
background-color: ${palette.gray.dark1};
|
|
107
|
+
}
|
|
108
|
+
`,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const chipButtonDisabledStyle: Record<Theme, string> = {
|
|
112
|
+
[Theme.Light]: css`
|
|
113
|
+
cursor: not-allowed;
|
|
114
|
+
color: ${palette.gray.dark2};
|
|
115
|
+
&:hover {
|
|
116
|
+
color: inherit;
|
|
117
|
+
background-color: unset;
|
|
118
|
+
}
|
|
119
|
+
`,
|
|
120
|
+
[Theme.Dark]: css`
|
|
121
|
+
cursor: not-allowed;
|
|
122
|
+
color: ${palette.gray.dark2};
|
|
123
|
+
&:hover {
|
|
124
|
+
color: inherit;
|
|
125
|
+
background-color: unset;
|
|
126
|
+
}
|
|
127
|
+
`,
|
|
128
|
+
};
|
|
129
|
+
|
|
111
130
|
export const Chip = React.forwardRef<HTMLSpanElement, ChipProps>(
|
|
112
131
|
({ displayName, isFocused, onRemove, onFocus }: ChipProps, forwardedRef) => {
|
|
113
132
|
const {
|
|
@@ -117,6 +136,7 @@ export const Chip = React.forwardRef<HTMLSpanElement, ChipProps>(
|
|
|
117
136
|
chipTruncationLocation = 'end',
|
|
118
137
|
chipCharacterLimit = 12,
|
|
119
138
|
} = useContext(ComboboxContext);
|
|
139
|
+
const theme = useDarkMode(darkMode);
|
|
120
140
|
|
|
121
141
|
const isTruncated =
|
|
122
142
|
!!chipCharacterLimit &&
|
|
@@ -199,14 +219,26 @@ export const Chip = React.forwardRef<HTMLSpanElement, ChipProps>(
|
|
|
199
219
|
aria-selected={isFocused}
|
|
200
220
|
data-testid="lg-combobox-chip"
|
|
201
221
|
ref={forwardedRef}
|
|
202
|
-
className={cx(
|
|
222
|
+
className={cx(
|
|
223
|
+
chipClassName,
|
|
224
|
+
chipWrapperBaseStyle,
|
|
225
|
+
chipWrapperThemeStyle[theme],
|
|
226
|
+
chipWrapperSizeStyle[size],
|
|
227
|
+
{
|
|
228
|
+
[disabledChipWrapperStyle[theme]]: disabled,
|
|
229
|
+
},
|
|
230
|
+
)}
|
|
203
231
|
onClick={handleChipClick}
|
|
204
232
|
onKeyDown={handleKeyDown}
|
|
205
233
|
tabIndex={-1}
|
|
206
234
|
>
|
|
207
|
-
<span className={
|
|
235
|
+
<span className={cx(chipTextSizeStyle[size])}>
|
|
208
236
|
{truncatedName ? (
|
|
209
|
-
<InlineDefinition
|
|
237
|
+
<InlineDefinition
|
|
238
|
+
darkMode={darkMode}
|
|
239
|
+
definition={displayName}
|
|
240
|
+
align="bottom"
|
|
241
|
+
>
|
|
210
242
|
{truncatedName}
|
|
211
243
|
</InlineDefinition>
|
|
212
244
|
) : (
|
|
@@ -218,7 +250,9 @@ export const Chip = React.forwardRef<HTMLSpanElement, ChipProps>(
|
|
|
218
250
|
aria-disabled={disabled}
|
|
219
251
|
disabled={disabled}
|
|
220
252
|
ref={buttonRef}
|
|
221
|
-
className={
|
|
253
|
+
className={cx(chipButtonStyle, chipButtonThemeStyle[theme], {
|
|
254
|
+
[chipButtonDisabledStyle[theme]]: disabled,
|
|
255
|
+
})}
|
|
222
256
|
onClick={handleButtonClick}
|
|
223
257
|
>
|
|
224
258
|
<Icon glyph="X" />
|