@wordpress/components 25.10.0 → 25.11.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 +16 -0
- package/build/autocomplete/index.js +104 -52
- package/build/autocomplete/index.js.map +1 -1
- package/build/dropdown-menu-v2-ariakit/index.js +217 -0
- package/build/dropdown-menu-v2-ariakit/index.js.map +1 -0
- package/build/dropdown-menu-v2-ariakit/styles.js +157 -0
- package/build/dropdown-menu-v2-ariakit/styles.js.map +1 -0
- package/build/dropdown-menu-v2-ariakit/types.js +6 -0
- package/build/dropdown-menu-v2-ariakit/types.js.map +1 -0
- package/build/input-control/styles/input-control-styles.js +23 -23
- package/build/input-control/styles/input-control-styles.js.map +1 -1
- package/build/mobile/global-styles-context/utils.native.js +1 -1
- package/build/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build/private-apis.js +9 -1
- package/build/private-apis.js.map +1 -1
- package/build/select-control/styles/select-control-styles.js +8 -8
- package/build/select-control/styles/select-control-styles.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build/tabs/index.js +2 -2
- package/build/tabs/index.js.map +1 -1
- package/build/tooltip/index.js +2 -2
- package/build/tooltip/index.js.map +1 -1
- package/build-module/autocomplete/index.js +104 -52
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/dropdown-menu-v2-ariakit/index.js +199 -0
- package/build-module/dropdown-menu-v2-ariakit/index.js.map +1 -0
- package/build-module/dropdown-menu-v2-ariakit/styles.js +136 -0
- package/build-module/dropdown-menu-v2-ariakit/styles.js.map +1 -0
- package/build-module/dropdown-menu-v2-ariakit/types.js +2 -0
- package/build-module/dropdown-menu-v2-ariakit/types.js.map +1 -0
- package/build-module/input-control/styles/input-control-styles.js +23 -23
- package/build-module/input-control/styles/input-control-styles.js.map +1 -1
- package/build-module/mobile/global-styles-context/utils.native.js +2 -2
- package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build-module/private-apis.js +9 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/select-control/styles/select-control-styles.js +8 -8
- package/build-module/select-control/styles/select-control-styles.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build-module/tabs/index.js +3 -3
- package/build-module/tabs/index.js.map +1 -1
- package/build-module/tooltip/index.js +2 -2
- package/build-module/tooltip/index.js.map +1 -1
- package/build-style/style-rtl.css +1 -1
- package/build-style/style.css +1 -1
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2-ariakit/index.d.ts +11 -0
- package/build-types/dropdown-menu-v2-ariakit/index.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts +16 -0
- package/build-types/dropdown-menu-v2-ariakit/stories/index.story.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/styles.d.ts +88 -0
- package/build-types/dropdown-menu-v2-ariakit/styles.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/test/index.d.ts +2 -0
- package/build-types/dropdown-menu-v2-ariakit/test/index.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2-ariakit/types.d.ts +174 -0
- package/build-types/dropdown-menu-v2-ariakit/types.d.ts.map +1 -0
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/package.json +21 -20
- package/src/autocomplete/index.tsx +136 -77
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +8 -8
- package/src/dropdown-menu-v2-ariakit/README.md +324 -0
- package/src/dropdown-menu-v2-ariakit/index.tsx +318 -0
- package/src/dropdown-menu-v2-ariakit/stories/index.story.tsx +506 -0
- package/src/dropdown-menu-v2-ariakit/styles.ts +297 -0
- package/src/dropdown-menu-v2-ariakit/test/index.tsx +1139 -0
- package/src/dropdown-menu-v2-ariakit/types.ts +186 -0
- package/src/input-control/styles/input-control-styles.tsx +2 -2
- package/src/mobile/global-styles-context/utils.native.js +2 -2
- package/src/private-apis.ts +16 -0
- package/src/select-control/styles/select-control-styles.ts +2 -2
- package/src/slot-fill/bubbles-virtually/slot-fill-provider.tsx +1 -1
- package/src/tabs/index.tsx +3 -3
- package/src/tabs/test/index.tsx +12 -3
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +8 -0
- package/src/tooltip/index.tsx +2 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line no-restricted-imports
|
|
5
|
+
import * as Ariakit from '@ariakit/react';
|
|
6
|
+
import { css, keyframes } from '@emotion/react';
|
|
7
|
+
import styled from '@emotion/styled';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import { COLORS, font, rtl, CONFIG } from '../utils';
|
|
13
|
+
import { space } from '../utils/space';
|
|
14
|
+
import Icon from '../icon';
|
|
15
|
+
import type { DropdownMenuContext } from './types';
|
|
16
|
+
|
|
17
|
+
const ANIMATION_PARAMS = {
|
|
18
|
+
SLIDE_AMOUNT: '2px',
|
|
19
|
+
DURATION: '400ms',
|
|
20
|
+
EASING: 'cubic-bezier( 0.16, 1, 0.3, 1 )',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const CONTENT_WRAPPER_PADDING = space( 2 );
|
|
24
|
+
const ITEM_PREFIX_WIDTH = space( 7 );
|
|
25
|
+
const ITEM_PADDING_INLINE_START = space( 2 );
|
|
26
|
+
const ITEM_PADDING_INLINE_END = space( 2.5 );
|
|
27
|
+
|
|
28
|
+
// TODO: should bring this into the config, and make themeable
|
|
29
|
+
const DEFAULT_BORDER_COLOR = COLORS.ui.borderDisabled;
|
|
30
|
+
const TOOLBAR_VARIANT_BORDER_COLOR = COLORS.gray[ '900' ];
|
|
31
|
+
const DEFAULT_BOX_SHADOW = `0 0 0 ${ CONFIG.borderWidth } ${ DEFAULT_BORDER_COLOR }, ${ CONFIG.popoverShadow }`;
|
|
32
|
+
const TOOLBAR_VARIANT_BOX_SHADOW = `0 0 0 ${ CONFIG.borderWidth } ${ TOOLBAR_VARIANT_BORDER_COLOR }`;
|
|
33
|
+
|
|
34
|
+
const slideUpAndFade = keyframes( {
|
|
35
|
+
'0%': {
|
|
36
|
+
opacity: 0,
|
|
37
|
+
transform: `translateY(${ ANIMATION_PARAMS.SLIDE_AMOUNT })`,
|
|
38
|
+
},
|
|
39
|
+
'100%': { opacity: 1, transform: 'translateY(0)' },
|
|
40
|
+
} );
|
|
41
|
+
|
|
42
|
+
const slideRightAndFade = keyframes( {
|
|
43
|
+
'0%': {
|
|
44
|
+
opacity: 0,
|
|
45
|
+
transform: `translateX(-${ ANIMATION_PARAMS.SLIDE_AMOUNT })`,
|
|
46
|
+
},
|
|
47
|
+
'100%': { opacity: 1, transform: 'translateX(0)' },
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
const slideDownAndFade = keyframes( {
|
|
51
|
+
'0%': {
|
|
52
|
+
opacity: 0,
|
|
53
|
+
transform: `translateY(-${ ANIMATION_PARAMS.SLIDE_AMOUNT })`,
|
|
54
|
+
},
|
|
55
|
+
'100%': { opacity: 1, transform: 'translateY(0)' },
|
|
56
|
+
} );
|
|
57
|
+
|
|
58
|
+
const slideLeftAndFade = keyframes( {
|
|
59
|
+
'0%': {
|
|
60
|
+
opacity: 0,
|
|
61
|
+
transform: `translateX(${ ANIMATION_PARAMS.SLIDE_AMOUNT })`,
|
|
62
|
+
},
|
|
63
|
+
'100%': { opacity: 1, transform: 'translateX(0)' },
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
export const DropdownMenu = styled( Ariakit.Menu )<
|
|
67
|
+
Pick< DropdownMenuContext, 'variant' >
|
|
68
|
+
>`
|
|
69
|
+
position: relative;
|
|
70
|
+
/* Same as popover component */
|
|
71
|
+
/* TODO: is there a way to read the sass variable? */
|
|
72
|
+
z-index: 1000000;
|
|
73
|
+
|
|
74
|
+
min-width: 220px;
|
|
75
|
+
max-height: var( --popover-available-height );
|
|
76
|
+
padding: ${ CONTENT_WRAPPER_PADDING };
|
|
77
|
+
|
|
78
|
+
background-color: ${ COLORS.ui.background };
|
|
79
|
+
border-radius: ${ CONFIG.radiusBlockUi };
|
|
80
|
+
${ ( props ) => css`
|
|
81
|
+
box-shadow: ${ props.variant === 'toolbar'
|
|
82
|
+
? TOOLBAR_VARIANT_BOX_SHADOW
|
|
83
|
+
: DEFAULT_BOX_SHADOW };
|
|
84
|
+
` }
|
|
85
|
+
|
|
86
|
+
overscroll-behavior: contain;
|
|
87
|
+
overflow: auto;
|
|
88
|
+
|
|
89
|
+
/* Only visible in Windows High Contrast mode */
|
|
90
|
+
outline: 2px solid transparent !important;
|
|
91
|
+
|
|
92
|
+
/* Animation */
|
|
93
|
+
animation-duration: ${ ANIMATION_PARAMS.DURATION };
|
|
94
|
+
animation-timing-function: ${ ANIMATION_PARAMS.EASING };
|
|
95
|
+
will-change: transform, opacity;
|
|
96
|
+
/* Default animation.*/
|
|
97
|
+
animation-name: ${ slideDownAndFade };
|
|
98
|
+
|
|
99
|
+
&[data-side='right'] {
|
|
100
|
+
animation-name: ${ slideLeftAndFade };
|
|
101
|
+
}
|
|
102
|
+
&[data-side='bottom'] {
|
|
103
|
+
animation-name: ${ slideUpAndFade };
|
|
104
|
+
}
|
|
105
|
+
&[data-side='left'] {
|
|
106
|
+
animation-name: ${ slideRightAndFade };
|
|
107
|
+
}
|
|
108
|
+
@media ( prefers-reduced-motion ) {
|
|
109
|
+
animation-duration: 0s;
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
112
|
+
|
|
113
|
+
const itemPrefix = css`
|
|
114
|
+
/* !important is to override some inline styles set by Ariakit */
|
|
115
|
+
width: ${ ITEM_PREFIX_WIDTH } !important;
|
|
116
|
+
/* !important is to override some inline styles set by Ariakit */
|
|
117
|
+
height: auto !important;
|
|
118
|
+
display: inline-flex;
|
|
119
|
+
align-items: center;
|
|
120
|
+
justify-content: center;
|
|
121
|
+
/* Prefixes don't get affected by the item's inline start padding */
|
|
122
|
+
margin-inline-start: calc( -1 * ${ ITEM_PADDING_INLINE_START } );
|
|
123
|
+
/*
|
|
124
|
+
Negative margin allows the suffix to be as tall as the whole item
|
|
125
|
+
(incl. padding) before increasing the items' height. This can be useful,
|
|
126
|
+
e.g., when using icons that are bigger than 20x20 px
|
|
127
|
+
*/
|
|
128
|
+
margin-top: ${ space( -2 ) };
|
|
129
|
+
margin-bottom: ${ space( -2 ) };
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
const itemSuffix = css`
|
|
133
|
+
width: max-content;
|
|
134
|
+
display: inline-flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
justify-content: center;
|
|
137
|
+
/* Push prefix to the inline-end of the item */
|
|
138
|
+
margin-inline-start: auto;
|
|
139
|
+
/* Minimum space between the item's content and suffix */
|
|
140
|
+
padding-inline-start: ${ space( 6 ) };
|
|
141
|
+
/*
|
|
142
|
+
Negative margin allows the suffix to be as tall as the whole item
|
|
143
|
+
(incl. padding) before increasing the items' height. This can be useful,
|
|
144
|
+
e.g., when using icons that are bigger than 20x20 px
|
|
145
|
+
*/
|
|
146
|
+
margin-top: ${ space( -2 ) };
|
|
147
|
+
margin-bottom: ${ space( -2 ) };
|
|
148
|
+
|
|
149
|
+
/*
|
|
150
|
+
Override color in normal conditions, but inherit the item's color
|
|
151
|
+
for altered conditions.
|
|
152
|
+
|
|
153
|
+
TODO:
|
|
154
|
+
- For now, used opacity like for disabled item, which makes it work
|
|
155
|
+
regardless of the theme
|
|
156
|
+
- how do we translate this for themes? Should we have a new variable
|
|
157
|
+
for "secondary" text?
|
|
158
|
+
*/
|
|
159
|
+
opacity: 0.6;
|
|
160
|
+
|
|
161
|
+
/* when the parent item is hovered / focused */
|
|
162
|
+
[data-active-item] > &,
|
|
163
|
+
/* when the parent item is a submenu trigger and the submenu is open */
|
|
164
|
+
[aria-expanded='true'] > &,
|
|
165
|
+
/* when the parent item is disabled */
|
|
166
|
+
[aria-disabled='true'] > & {
|
|
167
|
+
opacity: 1;
|
|
168
|
+
}
|
|
169
|
+
`;
|
|
170
|
+
|
|
171
|
+
export const ItemPrefixWrapper = styled.span`
|
|
172
|
+
${ itemPrefix }
|
|
173
|
+
`;
|
|
174
|
+
|
|
175
|
+
export const ItemSuffixWrapper = styled.span`
|
|
176
|
+
${ itemSuffix }
|
|
177
|
+
`;
|
|
178
|
+
|
|
179
|
+
const baseItem = css`
|
|
180
|
+
all: unset;
|
|
181
|
+
font-size: ${ font( 'default.fontSize' ) };
|
|
182
|
+
font-family: inherit;
|
|
183
|
+
font-weight: normal;
|
|
184
|
+
line-height: 20px;
|
|
185
|
+
color: ${ COLORS.gray[ 900 ] };
|
|
186
|
+
border-radius: ${ CONFIG.radiusBlockUi };
|
|
187
|
+
display: flex;
|
|
188
|
+
align-items: center;
|
|
189
|
+
padding: ${ space( 2 ) } ${ ITEM_PADDING_INLINE_END } ${ space( 2 ) }
|
|
190
|
+
${ ITEM_PADDING_INLINE_START };
|
|
191
|
+
position: relative;
|
|
192
|
+
user-select: none;
|
|
193
|
+
outline: none;
|
|
194
|
+
|
|
195
|
+
&[aria-disabled='true'] {
|
|
196
|
+
/*
|
|
197
|
+
TODO:
|
|
198
|
+
- we need a disabled color in the Theme variables
|
|
199
|
+
- design specs use opacity instead of setting a new text color
|
|
200
|
+
*/
|
|
201
|
+
opacity: 0.5;
|
|
202
|
+
pointer-events: none;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* Hover */
|
|
206
|
+
&[data-active-item] {
|
|
207
|
+
/* TODO: reconcile with global focus styles */
|
|
208
|
+
background-color: ${ COLORS.gray[ '100' ] };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/* Keyboard focus (focus-visible) */
|
|
212
|
+
&[data-focus-visible] {
|
|
213
|
+
box-shadow: 0 0 0 1.5px var( --wp-admin-theme-color );
|
|
214
|
+
|
|
215
|
+
/* Only visible in Windows High Contrast mode */
|
|
216
|
+
outline: 2px solid transparent;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* Active (ie. pressed, mouse down) */
|
|
220
|
+
&:active,
|
|
221
|
+
&[data-active] {
|
|
222
|
+
/* TODO: should there be a visual active state? */
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* When the item is the trigger of an open submenu */
|
|
226
|
+
${ DropdownMenu }:not(:focus) &:not(:focus)[aria-expanded="true"] {
|
|
227
|
+
/* TODO: should we style submenu triggers any different? */
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
svg {
|
|
231
|
+
fill: currentColor;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
&:not( :has( ${ ItemPrefixWrapper } ) ) {
|
|
235
|
+
padding-inline-start: ${ ITEM_PREFIX_WIDTH };
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
|
|
239
|
+
export const DropdownMenuItem = styled( Ariakit.MenuItem )`
|
|
240
|
+
${ baseItem }
|
|
241
|
+
`;
|
|
242
|
+
|
|
243
|
+
export const DropdownMenuCheckboxItem = styled( Ariakit.MenuItemCheckbox )`
|
|
244
|
+
${ baseItem }
|
|
245
|
+
`;
|
|
246
|
+
|
|
247
|
+
export const DropdownMenuRadioItem = styled( Ariakit.MenuItemRadio )`
|
|
248
|
+
${ baseItem }
|
|
249
|
+
`;
|
|
250
|
+
|
|
251
|
+
export const DropdownMenuGroup = styled( Ariakit.MenuGroup )``;
|
|
252
|
+
|
|
253
|
+
export const DropdownMenuGroupLabel = styled( Ariakit.MenuGroupLabel )`
|
|
254
|
+
box-sizing: border-box;
|
|
255
|
+
display: flex;
|
|
256
|
+
align-items: center;
|
|
257
|
+
min-height: ${ space( 8 ) };
|
|
258
|
+
|
|
259
|
+
padding: ${ space( 2 ) } ${ ITEM_PADDING_INLINE_END } ${ space( 2 ) }
|
|
260
|
+
${ ITEM_PREFIX_WIDTH };
|
|
261
|
+
/* TODO: color doesn't match available UI variables */
|
|
262
|
+
color: ${ COLORS.gray[ 700 ] };
|
|
263
|
+
|
|
264
|
+
/* TODO: font size doesn't match available ones via "font" utils */
|
|
265
|
+
font-size: 11px;
|
|
266
|
+
line-height: 1.4;
|
|
267
|
+
font-weight: 500;
|
|
268
|
+
text-transform: uppercase;
|
|
269
|
+
`;
|
|
270
|
+
|
|
271
|
+
export const DropdownMenuSeparator = styled( Ariakit.MenuSeparator )<
|
|
272
|
+
Pick< DropdownMenuContext, 'variant' >
|
|
273
|
+
>`
|
|
274
|
+
border: none;
|
|
275
|
+
height: ${ CONFIG.borderWidth };
|
|
276
|
+
/* TODO: doesn't match border color from variables */
|
|
277
|
+
background-color: ${ ( props ) =>
|
|
278
|
+
props.variant === 'toolbar'
|
|
279
|
+
? TOOLBAR_VARIANT_BORDER_COLOR
|
|
280
|
+
: DEFAULT_BORDER_COLOR };
|
|
281
|
+
/* Negative horizontal margin to make separator go from side to side */
|
|
282
|
+
margin: ${ space( 2 ) } calc( -1 * ${ CONTENT_WRAPPER_PADDING } );
|
|
283
|
+
|
|
284
|
+
/* Only visible in Windows High Contrast mode */
|
|
285
|
+
outline: 2px solid transparent;
|
|
286
|
+
`;
|
|
287
|
+
|
|
288
|
+
export const SubmenuChevronIcon = styled( Icon )`
|
|
289
|
+
${ rtl(
|
|
290
|
+
{
|
|
291
|
+
transform: `scaleX(1) translateX(${ space( 2 ) })`,
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
transform: `scaleX(-1) translateX(${ space( 2 ) })`,
|
|
295
|
+
}
|
|
296
|
+
) }
|
|
297
|
+
`;
|