@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/src/Combobox.styles.ts
CHANGED
|
@@ -1,207 +1,193 @@
|
|
|
1
|
-
|
|
2
|
-
* Styles
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { css, cx, keyframes } from '@leafygreen-ui/emotion';
|
|
1
|
+
import { css, cx } from '@leafygreen-ui/emotion';
|
|
6
2
|
import { createUniqueClassName } from '@leafygreen-ui/lib';
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
|
|
3
|
+
import { palette } from '@leafygreen-ui/palette';
|
|
4
|
+
import isNull from 'lodash/isNull';
|
|
5
|
+
import {
|
|
6
|
+
focusRing,
|
|
7
|
+
fontFamilies,
|
|
8
|
+
hoverRing,
|
|
9
|
+
spacing,
|
|
10
|
+
typeScales,
|
|
11
|
+
} from '@leafygreen-ui/tokens';
|
|
12
|
+
import { ComboboxSize as Size, Overflow, Theme } from './Combobox.types';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Width of the widest character (in px)
|
|
14
16
|
*/
|
|
15
|
-
const maxCharWidth: Record<
|
|
16
|
-
[
|
|
17
|
-
[
|
|
17
|
+
export const maxCharWidth: Record<Size, number> = {
|
|
18
|
+
[Size.Default]: typeScales.body1.fontSize,
|
|
19
|
+
[Size.Large]: typeScales.body2.fontSize,
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
`;
|
|
22
|
+
/**
|
|
23
|
+
* Vertical padding on a chip (in px)
|
|
24
|
+
*/
|
|
25
|
+
export const chipWrapperPaddingY = {
|
|
26
|
+
[Size.Default]: 2,
|
|
27
|
+
[Size.Large]: 4,
|
|
28
|
+
} as const;
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
const modeStyle = (darkMode: boolean) => {
|
|
39
|
-
if (darkMode) {
|
|
40
|
-
return css``;
|
|
41
|
-
} else {
|
|
42
|
-
return css`
|
|
43
|
-
--lg-combobox-color-error: ${uiColors.red.base};
|
|
44
|
-
--lg-combobox-text-color: ${uiColors.gray.dark3};
|
|
45
|
-
--lg-combobox-text-color-disabled: ${uiColors.gray.dark1};
|
|
30
|
+
/**
|
|
31
|
+
* Height of the input element (in px)
|
|
32
|
+
*/
|
|
33
|
+
const inputHeight: Record<Size, number> = {
|
|
34
|
+
[Size.Default]:
|
|
35
|
+
typeScales.body1.lineHeight + 2 * chipWrapperPaddingY[Size.Default], // 20
|
|
36
|
+
[Size.Large]:
|
|
37
|
+
typeScales.body2.lineHeight + 2 * chipWrapperPaddingY[Size.Large], // 28
|
|
38
|
+
};
|
|
46
39
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Size of combobox x & y padding (in px)
|
|
42
|
+
*/
|
|
43
|
+
export const comboboxPadding: Record<Size, { x: number; y: number }> = {
|
|
44
|
+
[Size.Default]: {
|
|
45
|
+
y: (36 - inputHeight[Size.Default] - 2) / 2,
|
|
46
|
+
x: spacing[2] - 1,
|
|
47
|
+
},
|
|
48
|
+
[Size.Large]: {
|
|
49
|
+
y: (48 - inputHeight[Size.Large] - 2) / 2,
|
|
50
|
+
x: spacing[2] - 1,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
/** Width of the dropdown caret icon (in px) */
|
|
55
|
+
export const caretIconSize = spacing[3];
|
|
56
|
+
|
|
57
|
+
const minWidth: Record<Size, number> = {
|
|
58
|
+
[Size.Default]:
|
|
59
|
+
maxCharWidth[Size.Default] +
|
|
60
|
+
2 * comboboxPadding[Size.Default].x +
|
|
61
|
+
caretIconSize +
|
|
62
|
+
2, // + 2 for border: ;
|
|
63
|
+
[Size.Large]:
|
|
64
|
+
maxCharWidth[Size.Large] +
|
|
65
|
+
2 * comboboxPadding[Size.Large].x +
|
|
66
|
+
caretIconSize +
|
|
67
|
+
2, // + 2 for border: ;
|
|
68
|
+
};
|
|
54
69
|
|
|
55
|
-
|
|
56
|
-
--lg-combobox-shadow-focus: 0px 4px 4px rgba(6, 22, 33, 0.3);
|
|
57
|
-
`;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const sizeStyle = (size: ComboboxSize) => {
|
|
62
|
-
switch (size) {
|
|
63
|
-
case ComboboxSize.Default:
|
|
64
|
-
return css`
|
|
65
|
-
--lg-combobox-padding-y: 5px;
|
|
66
|
-
--lg-combobox-padding-x: 7px;
|
|
67
|
-
--lg-combobox-height: calc(
|
|
68
|
-
36px - 2px - 2 * var(--lg-combobox-padding-y)
|
|
69
|
-
);
|
|
70
|
-
--lg-combobox-font-size: ${typeScales.body1.fontSize +
|
|
71
|
-
1}px; // TODO: update this for redesign
|
|
72
|
-
--lg-combobox-line-height: ${typeScales.body1.lineHeight + 1}px;
|
|
73
|
-
`;
|
|
74
|
-
case ComboboxSize.Large:
|
|
75
|
-
return css`
|
|
76
|
-
--lg-combobox-padding-y: 9px;
|
|
77
|
-
--lg-combobox-padding-x: 11px;
|
|
78
|
-
--lg-combobox-height: calc(
|
|
79
|
-
48px - 2px - 2 * var(--lg-combobox-padding-y)
|
|
80
|
-
);
|
|
81
|
-
--lg-combobox-font-size: ${typeScales.body2.fontSize}px;
|
|
82
|
-
--lg-combobox-line-height: ${typeScales.body2.lineHeight}px;
|
|
83
|
-
`;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
70
|
+
export const chipClassName = createUniqueClassName('combobox-chip');
|
|
86
71
|
|
|
72
|
+
export const comboboxParentStyle = (
|
|
73
|
+
size: Size,
|
|
74
|
+
overflow?: Overflow,
|
|
75
|
+
): string => {
|
|
87
76
|
return cx(
|
|
88
|
-
modeStyle(darkMode),
|
|
89
|
-
sizeStyle(size),
|
|
90
77
|
css`
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
--lg-combobox-padding: var(--lg-combobox-padding-y)
|
|
95
|
-
var(--lg-combobox-padding-x) var(--lg-combobox-padding-y)
|
|
96
|
-
${overflow === 'scroll-x' ? '0' : 'var(--lg-combobox-padding-x)'};
|
|
97
|
-
width: var(--lg-combobox-width);
|
|
98
|
-
// TODO: Clean this up 🤮
|
|
99
|
-
min-width: calc(
|
|
100
|
-
${maxCharWidth[size]}px + var(--lg-combobox-padding-x) * 2 + 2px +
|
|
101
|
-
var(--lg-combobox-icon-height)
|
|
102
|
-
);
|
|
78
|
+
font-family: ${fontFamilies.default};
|
|
79
|
+
width: 100%;
|
|
80
|
+
min-width: ${minWidth[size]}px;
|
|
103
81
|
`,
|
|
82
|
+
{
|
|
83
|
+
[css`
|
|
84
|
+
width: unset;
|
|
85
|
+
`]: overflow === Overflow.expandX,
|
|
86
|
+
},
|
|
104
87
|
);
|
|
105
88
|
};
|
|
106
89
|
|
|
107
|
-
export const
|
|
90
|
+
export const baseComboboxStyles = css`
|
|
108
91
|
display: flex;
|
|
109
92
|
flex-wrap: nowrap;
|
|
110
93
|
align-items: center;
|
|
111
|
-
padding: var(--lg-combobox-padding);
|
|
112
|
-
color: var(--lg-combobox-text-color);
|
|
113
|
-
background-color: var(--lg-combobox-background-color);
|
|
114
|
-
box-shadow: var(--lg-combobox-shadow);
|
|
115
|
-
border: 1px solid var(--lg-combobox-border-color);
|
|
116
|
-
border-radius: var(--lg-combobox-border-radius);
|
|
117
|
-
width: var(--lg-combobox-width);
|
|
118
94
|
cursor: text;
|
|
119
95
|
transition: 150ms ease-in-out;
|
|
120
96
|
transition-property: background-color, box-shadow, border-color;
|
|
97
|
+
border: 1px solid;
|
|
98
|
+
width: inherit;
|
|
99
|
+
border-radius: 6px;
|
|
100
|
+
`;
|
|
121
101
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
cursor: not-allowed;
|
|
128
|
-
}
|
|
102
|
+
export const comboboxThemeStyles: Record<Theme, string> = {
|
|
103
|
+
[Theme.Light]: css`
|
|
104
|
+
color: ${palette.gray.dark3};
|
|
105
|
+
background-color: ${palette.white};
|
|
106
|
+
border-color: ${palette.gray.base};
|
|
129
107
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
108
|
+
&:hover {
|
|
109
|
+
box-shadow: ${hoverRing[Theme.Light].gray};
|
|
110
|
+
}
|
|
111
|
+
`,
|
|
112
|
+
[Theme.Dark]: css`
|
|
113
|
+
color: ${palette.gray.light2};
|
|
114
|
+
background-color: ${palette.gray.dark4};
|
|
115
|
+
border-color: ${palette.gray.base};
|
|
116
|
+
|
|
117
|
+
&:hover {
|
|
118
|
+
box-shadow: ${hoverRing[Theme.Dark].gray};
|
|
119
|
+
}
|
|
120
|
+
`,
|
|
121
|
+
};
|
|
134
122
|
|
|
135
|
-
export const
|
|
136
|
-
|
|
137
|
-
border-color: transparent;
|
|
138
|
-
background-color: var(--lg-combobox-background-color-focus);
|
|
139
|
-
// TODO: Remove for UI refresh & Darkmode
|
|
140
|
-
box-shadow: 0 0 0 3px ${uiColors.focus}, var(--lg-combobox-shadow-focus);
|
|
141
|
-
}
|
|
123
|
+
export const comboboxSizeStyles = (size: Size) => css`
|
|
124
|
+
padding: ${comboboxPadding[size].y}px ${comboboxPadding[size].x}px;
|
|
142
125
|
`;
|
|
143
126
|
|
|
144
|
-
export const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
127
|
+
export const comboboxDisabledStyles: Record<Theme, string> = {
|
|
128
|
+
[Theme.Light]: css`
|
|
129
|
+
cursor: not-allowed;
|
|
130
|
+
color: ${palette.gray.dark1};
|
|
131
|
+
background-color: ${palette.gray.light2};
|
|
132
|
+
border-color: ${palette.gray.light1};
|
|
133
|
+
`,
|
|
134
|
+
[Theme.Dark]: css`
|
|
135
|
+
cursor: not-allowed;
|
|
136
|
+
color: ${palette.gray.dark1};
|
|
137
|
+
background-color: ${palette.gray.dark3};
|
|
138
|
+
border-color: ${palette.gray.dark2};
|
|
139
|
+
`,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const comboboxErrorStyles: Record<Theme, string> = {
|
|
143
|
+
[Theme.Light]: css`
|
|
144
|
+
border-color: ${palette.red.base};
|
|
145
|
+
`,
|
|
146
|
+
[Theme.Dark]: css`
|
|
147
|
+
border-color: ${palette.red.light1};
|
|
148
|
+
`,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const comboboxFocusStyle: Record<Theme, string> = {
|
|
152
|
+
[Theme.Light]: css`
|
|
153
|
+
&:focus-within {
|
|
154
|
+
border-color: transparent;
|
|
155
|
+
background-color: ${palette.white};
|
|
156
|
+
box-shadow: ${focusRing[Theme.Light].input};
|
|
157
|
+
}
|
|
158
|
+
`,
|
|
159
|
+
[Theme.Dark]: css`
|
|
160
|
+
&:focus-within {
|
|
161
|
+
border-color: transparent;
|
|
162
|
+
background-color: ${palette.gray.dark4};
|
|
163
|
+
box-shadow: ${focusRing[Theme.Dark].input};
|
|
164
|
+
}
|
|
165
|
+
`,
|
|
160
166
|
};
|
|
161
167
|
|
|
162
168
|
export const inputWrapperStyle = ({
|
|
163
169
|
overflow,
|
|
164
|
-
isOpen,
|
|
165
|
-
selection,
|
|
166
170
|
size,
|
|
167
|
-
value,
|
|
168
171
|
}: {
|
|
169
172
|
overflow: Overflow;
|
|
170
|
-
|
|
171
|
-
selection: string | Array<string> | null;
|
|
172
|
-
size: ComboboxSize;
|
|
173
|
-
value?: string;
|
|
173
|
+
size: Size;
|
|
174
174
|
}) => {
|
|
175
|
-
const isMultiselect = isArray(selection) && selection.length > 0;
|
|
176
|
-
const inputLength = value?.length ?? 0;
|
|
177
|
-
|
|
178
175
|
const baseWrapperStyle = css`
|
|
179
176
|
flex-grow: 1;
|
|
180
|
-
width:
|
|
181
|
-
|
|
182
|
-
--lg-combobox-input-width: ${isMultiselect
|
|
183
|
-
? `${inputLength * maxCharWidth[size]}px`
|
|
184
|
-
: '100%'};
|
|
185
|
-
--lg-combobox-input-min-width: ${maxCharWidth[size]}px;
|
|
177
|
+
width: inherit;
|
|
186
178
|
`;
|
|
187
179
|
|
|
188
180
|
switch (overflow) {
|
|
189
|
-
case
|
|
181
|
+
case Overflow.scrollX: {
|
|
190
182
|
return css`
|
|
191
183
|
${baseWrapperStyle}
|
|
192
184
|
display: block;
|
|
193
|
-
height:
|
|
185
|
+
height: ${inputHeight[size]}px;
|
|
186
|
+
padding-left: ${comboboxPadding[size].x}px;
|
|
194
187
|
white-space: nowrap;
|
|
195
188
|
overflow-x: scroll;
|
|
196
|
-
padding-left: var(--lg-combobox-padding-x);
|
|
197
189
|
scroll-behavior: smooth;
|
|
198
190
|
scrollbar-width: none;
|
|
199
|
-
/*
|
|
200
|
-
* Immediate transition in, slow transition out.
|
|
201
|
-
* '-in' transition is handled by \`scroll-behavior\`
|
|
202
|
-
*/
|
|
203
|
-
--lg-combobox-input-transition: width ease-in-out
|
|
204
|
-
${isOpen ? '0' : '100ms'};
|
|
205
191
|
|
|
206
192
|
&::-webkit-scrollbar {
|
|
207
193
|
display: none;
|
|
@@ -221,193 +207,158 @@ export const inputWrapperStyle = ({
|
|
|
221
207
|
`;
|
|
222
208
|
}
|
|
223
209
|
|
|
224
|
-
case
|
|
210
|
+
case Overflow.expandX: {
|
|
225
211
|
return css`
|
|
226
212
|
${baseWrapperStyle}
|
|
227
213
|
display: flex;
|
|
228
214
|
gap: 4px;
|
|
229
215
|
flex-wrap: nowrap;
|
|
230
216
|
white-space: nowrap;
|
|
231
|
-
height:
|
|
232
|
-
--lg-combobox-input-transition: none;
|
|
217
|
+
height: ${inputHeight[size]}px;
|
|
233
218
|
`;
|
|
234
219
|
}
|
|
235
220
|
|
|
236
221
|
// TODO - look into animating input element height on wrap
|
|
237
|
-
case
|
|
222
|
+
case Overflow.expandY: {
|
|
238
223
|
return css`
|
|
239
224
|
${baseWrapperStyle}
|
|
240
225
|
display: flex;
|
|
241
226
|
flex-wrap: wrap;
|
|
242
227
|
gap: 4px;
|
|
243
228
|
overflow-x: visible;
|
|
244
|
-
min-height:
|
|
229
|
+
min-height: ${inputHeight[size]}px;
|
|
245
230
|
`;
|
|
246
231
|
}
|
|
247
232
|
}
|
|
248
233
|
};
|
|
249
234
|
|
|
250
|
-
export const
|
|
235
|
+
export const baseInputElementStyle = css`
|
|
236
|
+
font-family: ${fontFamilies.default};
|
|
237
|
+
width: 100%;
|
|
251
238
|
border: none;
|
|
252
239
|
cursor: inherit;
|
|
253
240
|
background-color: inherit;
|
|
241
|
+
color: inherit;
|
|
254
242
|
box-sizing: content-box;
|
|
255
243
|
padding: 0;
|
|
256
244
|
margin: 0;
|
|
257
245
|
text-overflow: ellipsis;
|
|
258
|
-
font-size: var(--lg-combobox-font-size);
|
|
259
|
-
line-height: var(--lg-combobox-line-height);
|
|
260
|
-
height: var(--lg-combobox-height);
|
|
261
|
-
width: var(--lg-combobox-input-width, 0);
|
|
262
|
-
min-width: var(--lg-combobox-input-min-width);
|
|
263
|
-
transition: var(--lg-combobox-input-transition);
|
|
264
246
|
|
|
247
|
+
&:placeholder-shown {
|
|
248
|
+
min-width: 100%;
|
|
249
|
+
}
|
|
265
250
|
&:focus {
|
|
266
251
|
outline: none;
|
|
267
252
|
}
|
|
268
253
|
`;
|
|
269
254
|
|
|
270
|
-
export const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
// Temporary styles to override redesigned icon-button
|
|
276
|
-
// TODO: Remove for UI refresh
|
|
277
|
-
export const clearButtonFocusOverrideStyles = css`
|
|
278
|
-
&:focus {
|
|
279
|
-
box-shadow: unset;
|
|
280
|
-
&::before {
|
|
281
|
-
background-color: ${uiColors.blue.light2};
|
|
255
|
+
export const inputElementThemeStyle: Record<Theme, string> = {
|
|
256
|
+
[Theme.Light]: css`
|
|
257
|
+
&::placeholder {
|
|
258
|
+
color: ${palette.gray.dark1};
|
|
282
259
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
padding-top: var(--lg-combobox-padding-y);
|
|
291
|
-
`;
|
|
260
|
+
`,
|
|
261
|
+
[Theme.Dark]: css`
|
|
262
|
+
&::placeholder {
|
|
263
|
+
color: ${palette.gray.light1};
|
|
264
|
+
}
|
|
265
|
+
`,
|
|
266
|
+
};
|
|
292
267
|
|
|
293
|
-
export const
|
|
294
|
-
|
|
295
|
-
|
|
268
|
+
export const inputElementSizeStyle: Record<Size, string> = {
|
|
269
|
+
[Size.Default]: css`
|
|
270
|
+
height: ${inputHeight[Size.Default]}px;
|
|
271
|
+
font-size: ${typeScales.body1.fontSize}px;
|
|
272
|
+
line-height: ${typeScales.body1.lineHeight}px;
|
|
273
|
+
min-width: ${maxCharWidth[Size.Default]}px;
|
|
274
|
+
padding-left: 4px;
|
|
275
|
+
`,
|
|
276
|
+
[Size.Large]: css`
|
|
277
|
+
height: ${inputHeight[Size.Large]}px;
|
|
278
|
+
font-size: ${typeScales.body2.fontSize}px;
|
|
279
|
+
line-height: ${typeScales.body2.lineHeight}px;
|
|
280
|
+
min-width: ${maxCharWidth[Size.Large]}px;
|
|
281
|
+
padding-left: 6px;
|
|
282
|
+
`,
|
|
283
|
+
};
|
|
296
284
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
285
|
+
// We don't transition the input width then overflow == expand-x
|
|
286
|
+
export const inputElementTransitionStyles = (
|
|
287
|
+
isOpen: boolean,
|
|
288
|
+
overflow: Overflow,
|
|
289
|
+
) =>
|
|
290
|
+
cx({
|
|
291
|
+
[css`
|
|
292
|
+
/*
|
|
293
|
+
* Immediate transition in, slow transition out.
|
|
294
|
+
* '-in' transition is handled by \`scroll-behavior\`
|
|
295
|
+
*/
|
|
296
|
+
transition: width ease-in-out ${isOpen ? '0s' : '100ms'};
|
|
297
|
+
`]: overflow !== Overflow.expandX,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Previously defined in inputWrapperStyle
|
|
301
|
+
/** Should only be applied to a multiselect */
|
|
302
|
+
export const multiselectInputElementStyle = (
|
|
303
|
+
size: Size,
|
|
304
|
+
inputValue?: string,
|
|
305
|
+
) => {
|
|
306
|
+
const inputLength = inputValue?.length ?? 0;
|
|
307
|
+
return css`
|
|
308
|
+
max-width: 100%;
|
|
309
|
+
width: ${inputLength * maxCharWidth[size]}px;
|
|
310
|
+
// TODO: This doesn't quite work. Fix this
|
|
311
|
+
max-width: calc(100% - ${2 * caretIconSize}px);
|
|
312
|
+
`;
|
|
313
|
+
};
|
|
308
314
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}) => {
|
|
321
|
-
let menuModeStyle, menuSizeStyle;
|
|
322
|
-
|
|
323
|
-
if (darkMode) {
|
|
324
|
-
menuModeStyle = css``;
|
|
325
|
-
} else {
|
|
326
|
-
menuModeStyle = css`
|
|
327
|
-
--lg-combobox-menu-color: ${uiColors.gray.dark3};
|
|
328
|
-
--lg-combobox-menu-message-color: ${uiColors.gray.dark1};
|
|
329
|
-
--lg-combobox-menu-background-color: ${uiColors.white};
|
|
330
|
-
--lg-combobox-menu-shadow: 0px 3px 7px rgba(0, 0, 0, 0.25);
|
|
331
|
-
--lg-combobox-item-hover-color: ${uiColors.gray.light2};
|
|
332
|
-
--lg-combobox-item-active-color: ${uiColors.blue.light3};
|
|
333
|
-
--lg-combobox-item-wedge-color: ${uiColors.blue.base};
|
|
315
|
+
// If there are chips, we remove the left padding from the input element
|
|
316
|
+
export const multiselectInputElementPadding = (
|
|
317
|
+
selection: string | Array<string> | null,
|
|
318
|
+
) => {
|
|
319
|
+
if (
|
|
320
|
+
typeof selection === 'object' &&
|
|
321
|
+
!isNull(selection) &&
|
|
322
|
+
selection.length > 0
|
|
323
|
+
)
|
|
324
|
+
return css`
|
|
325
|
+
padding-left: 0px;
|
|
334
326
|
`;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
switch (size) {
|
|
338
|
-
case ComboboxSize.Default:
|
|
339
|
-
menuSizeStyle = css`
|
|
340
|
-
--lg-combobox-menu-border-radius: 4px;
|
|
341
|
-
--lg-combobox-item-height: 36px;
|
|
342
|
-
--lg-combobox-item-padding-y: 8px;
|
|
343
|
-
--lg-combobox-item-padding-x: 12px;
|
|
344
|
-
--lg-combobox-item-font-size: ${typeScales.body1.fontSize +
|
|
345
|
-
1}px; // TODO: update this
|
|
346
|
-
--lg-combobox-item-line-height: ${typeScales.body1.lineHeight +
|
|
347
|
-
1}px; // TODO: update this
|
|
348
|
-
--lg-combobox-item-wedge-height: 22px;
|
|
349
|
-
`;
|
|
350
|
-
break;
|
|
351
|
-
case ComboboxSize.Large:
|
|
352
|
-
menuSizeStyle = css`
|
|
353
|
-
--lg-combobox-menu-border-radius: 4px;
|
|
354
|
-
--lg-combobox-item-height: 36px;
|
|
355
|
-
--lg-combobox-item-padding-y: 8px;
|
|
356
|
-
--lg-combobox-item-padding-x: 12px;
|
|
357
|
-
--lg-combobox-item-font-size: ${typeScales.body2.fontSize +
|
|
358
|
-
1}px; // TODO: update this
|
|
359
|
-
--lg-combobox-item-line-height: ${typeScales.body2.lineHeight +
|
|
360
|
-
1}px; // TODO: update this
|
|
361
|
-
--lg-combobox-item-wedge-height: 22px;
|
|
362
|
-
`;
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
return cx(
|
|
367
|
-
menuModeStyle,
|
|
368
|
-
menuSizeStyle,
|
|
369
|
-
css`
|
|
370
|
-
width: ${width}px;
|
|
371
|
-
border-radius: var(--lg-combobox-menu-border-radius);
|
|
372
|
-
|
|
373
|
-
& > * {
|
|
374
|
-
border-radius: inherit;
|
|
375
|
-
}
|
|
376
|
-
`,
|
|
377
|
-
);
|
|
327
|
+
return '';
|
|
378
328
|
};
|
|
379
329
|
|
|
380
|
-
export const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
margin: 0;
|
|
384
|
-
padding: 0;
|
|
385
|
-
font-family: ${fontFamilies.default};
|
|
386
|
-
color: var(--lg-combobox-menu-color);
|
|
387
|
-
background-color: var(--lg-combobox-menu-background-color);
|
|
388
|
-
box-shadow: var(--lg-combobox-menu-shadow);
|
|
389
|
-
border-radius: inherit;
|
|
390
|
-
overflow: auto;
|
|
391
|
-
min-height: var(--lg-combobox-item-height);
|
|
392
|
-
scroll-behavior: smooth;
|
|
330
|
+
export const clearButtonStyle = css`
|
|
331
|
+
// Add a negative margin so the button takes up the same space as the regular icons
|
|
332
|
+
margin-block: calc(${caretIconSize / 2}px - 100%);
|
|
393
333
|
`;
|
|
394
334
|
|
|
395
|
-
export const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
335
|
+
export const endIconStyle = (size: Size) => css`
|
|
336
|
+
height: ${caretIconSize}px;
|
|
337
|
+
width: ${caretIconSize}px;
|
|
338
|
+
margin-inline-end: calc(${comboboxPadding[size].x}px / 2);
|
|
399
339
|
`;
|
|
400
340
|
|
|
401
|
-
export const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
341
|
+
export const errorMessageThemeStyle: Record<Theme, string> = {
|
|
342
|
+
[Theme.Light]: css`
|
|
343
|
+
color: ${palette.red.base};
|
|
344
|
+
`,
|
|
345
|
+
[Theme.Dark]: css`
|
|
346
|
+
color: ${palette.red.light1};
|
|
347
|
+
`,
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
export const errorMessageSizeStyle: Record<Size, string> = {
|
|
351
|
+
[Size.Default]: css`
|
|
352
|
+
font-size: ${typeScales.body1.fontSize}px;
|
|
353
|
+
line-height: ${typeScales.body1.lineHeight}px;
|
|
354
|
+
padding-top: ${comboboxPadding[Size.Default].y}px;
|
|
355
|
+
`,
|
|
356
|
+
[Size.Large]: css`
|
|
357
|
+
font-size: ${typeScales.body2.fontSize}px;
|
|
358
|
+
line-height: ${typeScales.body2.lineHeight}px;
|
|
359
|
+
padding-top: ${comboboxPadding[Size.Large].y}px;
|
|
360
|
+
`,
|
|
361
|
+
};
|
|
362
|
+
export const labelDescriptionContainerStyle = css`
|
|
363
|
+
margin-bottom: 2px;
|
|
413
364
|
`;
|