react-x11 2.25.0 → 2.26.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/package.json +1 -1
- package/src/components/Select.js +22 -2
- package/src/types/components.d.ts +10 -0
package/package.json
CHANGED
package/src/components/Select.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useEffect, useRef, useState } from 'react';
|
|
6
6
|
import { useAppOrNull } from '../appcontext.js';
|
|
7
|
+
import { flattenStyle } from '../styles.js';
|
|
7
8
|
import { capBand, capTrim, rowRadius, useTheme } from './theme.js';
|
|
8
9
|
import { Icon } from './Icon.js';
|
|
9
10
|
import {
|
|
@@ -282,6 +283,14 @@ function Option({
|
|
|
282
283
|
* the active option with wrapping; Home/End jump to the ends; Enter/Space
|
|
283
284
|
* pick the active option (or open the menu when closed); Escape closes.
|
|
284
285
|
* The active option is scrolled into view.
|
|
286
|
+
*
|
|
287
|
+
* `labelStyle` and `chevronStyle` are style slots over the caption and the
|
|
288
|
+
* chevron, each merged over the part's own default, as `<Slider>`'s are over
|
|
289
|
+
* its parts — so a select that has to wear someone else's look, a toolbar's
|
|
290
|
+
* or a web page's, is the widget restyled, with `style` on the trigger. The
|
|
291
|
+
* caption's `fontSize` is read back: the chevron is as tall as the capitals
|
|
292
|
+
* beside it. Any slot also chooses the drawn trigger over the platform's
|
|
293
|
+
* popup bezel, whose pixels no style reaches.
|
|
285
294
|
*/
|
|
286
295
|
export function Select({
|
|
287
296
|
value,
|
|
@@ -291,11 +300,18 @@ export function Select({
|
|
|
291
300
|
placeholder = 'Select…',
|
|
292
301
|
native,
|
|
293
302
|
style,
|
|
303
|
+
labelStyle,
|
|
304
|
+
chevronStyle,
|
|
294
305
|
...boxProps
|
|
295
306
|
}) {
|
|
296
307
|
const theme = useTheme();
|
|
297
308
|
const app = useAppOrNull();
|
|
298
|
-
const
|
|
309
|
+
const styled = Boolean(labelStyle || chevronStyle);
|
|
310
|
+
const nativeControls = useNativeControls(styled ? false : native);
|
|
311
|
+
// The size the caption is set in, where its slot names one: the chevron is
|
|
312
|
+
// measured against those capitals, and an `<Icon>`'s size does not inherit.
|
|
313
|
+
const ownSize = flattenStyle(labelStyle).fontSize;
|
|
314
|
+
const captionSize = typeof ownSize === 'number' ? ownSize : theme.fontSize;
|
|
299
315
|
const [open, setOpen] = useState(false);
|
|
300
316
|
const [anchor, setAnchor] = useState(null);
|
|
301
317
|
const [focused, setFocused] = useState(false);
|
|
@@ -572,6 +588,7 @@ export function Select({
|
|
|
572
588
|
ONE_LINE,
|
|
573
589
|
nativeControls && nativeTitleStyle('regular'),
|
|
574
590
|
{ color: current ? theme.text : theme.textMuted },
|
|
591
|
+
labelStyle,
|
|
575
592
|
],
|
|
576
593
|
},
|
|
577
594
|
current ? current.label : placeholder,
|
|
@@ -593,8 +610,11 @@ export function Select({
|
|
|
593
610
|
})
|
|
594
611
|
: h(Icon, {
|
|
595
612
|
name: 'chevronDown',
|
|
596
|
-
size: capBand(
|
|
613
|
+
size: capBand(captionSize),
|
|
597
614
|
color: theme.textMuted,
|
|
615
|
+
// `display: 'none'` leaves it out, for a trigger whose arrow is
|
|
616
|
+
// drawn by something else
|
|
617
|
+
style: chevronStyle,
|
|
598
618
|
}),
|
|
599
619
|
open &&
|
|
600
620
|
anchor &&
|
|
@@ -511,6 +511,16 @@ export interface SelectProps<T = unknown>
|
|
|
511
511
|
onChange?: (ev: WidgetChangeEvent<T>) => void;
|
|
512
512
|
placeholder?: string;
|
|
513
513
|
style?: StyleProp;
|
|
514
|
+
/**
|
|
515
|
+
* The caption's style — the value, or the placeholder — over the palette's
|
|
516
|
+
* `text` (`textMuted` for the placeholder). Its `fontSize`, as a number, is
|
|
517
|
+
* the one the chevron is sized against. Any slot chooses the drawn trigger
|
|
518
|
+
* over the platform's popup bezel.
|
|
519
|
+
*/
|
|
520
|
+
labelStyle?: StyleProp;
|
|
521
|
+
/** The chevron's style, over `textMuted` at the caption's cap height.
|
|
522
|
+
* `display: 'none'` leaves it out. */
|
|
523
|
+
chevronStyle?: StyleProp;
|
|
514
524
|
}
|
|
515
525
|
export function Select<T = unknown>(props: SelectProps<T>): ReactNode;
|
|
516
526
|
|