@oxy.so/bloom 7.16.1 → 7.17.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/docs/adoption-matrix.mdx +4 -4
- package/docs/carousel.mdx +22 -0
- package/docs/overlay.mdx +9 -0
- package/docs/search.mdx +18 -1
- package/docs/text-field.mdx +15 -0
- package/lib/commonjs/accordion/Accordion.web.js +1 -0
- package/lib/commonjs/accordion/Accordion.web.js.map +1 -1
- package/lib/commonjs/carousel/Carousel.js +50 -20
- package/lib/commonjs/carousel/Carousel.js.map +1 -1
- package/lib/commonjs/overlay/ModalKeyboard.js +4 -6
- package/lib/commonjs/overlay/ModalKeyboard.js.map +1 -1
- package/lib/commonjs/overlay/modal-keyboard.js +44 -0
- package/lib/commonjs/overlay/modal-keyboard.js.map +1 -1
- package/lib/commonjs/search/Search.js +11 -2
- package/lib/commonjs/search/Search.js.map +1 -1
- package/lib/commonjs/search/types.js +6 -0
- package/lib/commonjs/search/types.js.map +1 -0
- package/lib/commonjs/text-field/FieldBox.js +83 -0
- package/lib/commonjs/text-field/FieldBox.js.map +1 -0
- package/lib/commonjs/text-field/TextField.js +17 -7
- package/lib/commonjs/text-field/TextField.js.map +1 -1
- package/lib/module/accordion/Accordion.web.js +1 -0
- package/lib/module/accordion/Accordion.web.js.map +1 -1
- package/lib/module/carousel/Carousel.js +50 -20
- package/lib/module/carousel/Carousel.js.map +1 -1
- package/lib/module/overlay/ModalKeyboard.js +5 -7
- package/lib/module/overlay/ModalKeyboard.js.map +1 -1
- package/lib/module/overlay/modal-keyboard.js +43 -0
- package/lib/module/overlay/modal-keyboard.js.map +1 -1
- package/lib/module/search/Search.js +11 -2
- package/lib/module/search/Search.js.map +1 -1
- package/lib/module/search/types.js +4 -0
- package/lib/module/search/types.js.map +1 -0
- package/lib/module/text-field/FieldBox.js +79 -0
- package/lib/module/text-field/FieldBox.js.map +1 -0
- package/lib/module/text-field/TextField.js +17 -7
- package/lib/module/text-field/TextField.js.map +1 -1
- package/lib/typescript/commonjs/carousel/Carousel.d.ts +1 -1
- package/lib/typescript/commonjs/carousel/Carousel.d.ts.map +1 -1
- package/lib/typescript/commonjs/carousel/index.d.ts +1 -1
- package/lib/typescript/commonjs/carousel/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/carousel/types.d.ts +7 -0
- package/lib/typescript/commonjs/carousel/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/overlay/modal-keyboard.d.ts +2 -0
- package/lib/typescript/commonjs/overlay/modal-keyboard.d.ts.map +1 -1
- package/lib/typescript/commonjs/search/Search.d.ts +6 -6
- package/lib/typescript/commonjs/search/Search.d.ts.map +1 -1
- package/lib/typescript/commonjs/search/index.d.ts +1 -0
- package/lib/typescript/commonjs/search/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/search/types.d.ts +15 -0
- package/lib/typescript/commonjs/search/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/text-field/FieldBox.d.ts +19 -0
- package/lib/typescript/commonjs/text-field/FieldBox.d.ts.map +1 -0
- package/lib/typescript/commonjs/text-field/TextField.d.ts +1 -1
- package/lib/typescript/commonjs/text-field/TextField.d.ts.map +1 -1
- package/lib/typescript/commonjs/text-field/types.d.ts +4 -0
- package/lib/typescript/commonjs/text-field/types.d.ts.map +1 -1
- package/lib/typescript/module/carousel/Carousel.d.ts +1 -1
- package/lib/typescript/module/carousel/Carousel.d.ts.map +1 -1
- package/lib/typescript/module/carousel/index.d.ts +1 -1
- package/lib/typescript/module/carousel/index.d.ts.map +1 -1
- package/lib/typescript/module/carousel/types.d.ts +7 -0
- package/lib/typescript/module/carousel/types.d.ts.map +1 -1
- package/lib/typescript/module/overlay/modal-keyboard.d.ts +2 -0
- package/lib/typescript/module/overlay/modal-keyboard.d.ts.map +1 -1
- package/lib/typescript/module/search/Search.d.ts +6 -6
- package/lib/typescript/module/search/Search.d.ts.map +1 -1
- package/lib/typescript/module/search/index.d.ts +1 -0
- package/lib/typescript/module/search/index.d.ts.map +1 -1
- package/lib/typescript/module/search/types.d.ts +15 -0
- package/lib/typescript/module/search/types.d.ts.map +1 -0
- package/lib/typescript/module/text-field/FieldBox.d.ts +19 -0
- package/lib/typescript/module/text-field/FieldBox.d.ts.map +1 -0
- package/lib/typescript/module/text-field/TextField.d.ts +1 -1
- package/lib/typescript/module/text-field/TextField.d.ts.map +1 -1
- package/lib/typescript/module/text-field/types.d.ts +4 -0
- package/lib/typescript/module/text-field/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/accordion/Accordion.web.tsx +1 -1
- package/src/carousel/Carousel.tsx +37 -12
- package/src/carousel/index.ts +1 -1
- package/src/carousel/types.ts +9 -0
- package/src/overlay/ModalKeyboard.tsx +5 -5
- package/src/overlay/modal-keyboard.ts +30 -0
- package/src/search/Search.tsx +7 -13
- package/src/search/index.ts +2 -0
- package/src/search/types.ts +15 -0
- package/src/text-field/FieldBox.tsx +51 -0
- package/src/text-field/TextField.tsx +15 -7
- package/src/text-field/types.ts +4 -0
|
@@ -330,6 +330,8 @@ const CarouselComponent = function Carousel({
|
|
|
330
330
|
showArrows = true,
|
|
331
331
|
arrowsPlacement = 'header',
|
|
332
332
|
arrowsVisibility = 'always',
|
|
333
|
+
arrowButtonProps,
|
|
334
|
+
hideUnavailableArrows = false,
|
|
333
335
|
showDots = true,
|
|
334
336
|
align = 'start',
|
|
335
337
|
gap = 16,
|
|
@@ -364,6 +366,8 @@ const CarouselComponent = function Carousel({
|
|
|
364
366
|
controlledIndexRef.current = controlledIndex;
|
|
365
367
|
|
|
366
368
|
const scrollRef = useRef<ScrollView>(null);
|
|
369
|
+
const previousArrowRef = useRef<View>(null);
|
|
370
|
+
const nextArrowRef = useRef<View>(null);
|
|
367
371
|
const offsets = useRef(new Map<string, SlideOffset>());
|
|
368
372
|
const scroll = useRef({ x: 0, contentWidth: 0 });
|
|
369
373
|
const [trackWidth, setTrackWidth] = useState(0);
|
|
@@ -632,19 +636,40 @@ const CarouselComponent = function Carousel({
|
|
|
632
636
|
|
|
633
637
|
const overlay = arrowsPlacement === 'overlay';
|
|
634
638
|
const arrowsVisible = showArrows && count > 0;
|
|
635
|
-
//
|
|
636
|
-
//
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
639
|
+
// Slots stay mounted at the same edges even when their controls are hidden.
|
|
640
|
+
// Hover opacity belongs to the slot, leaving the button's recipe authoritative.
|
|
641
|
+
const arrow = (button: React.ReactElement, unavailable: boolean, ref: React.RefObject<View | null>) => {
|
|
642
|
+
const hidden = hideUnavailableArrows && unavailable;
|
|
643
|
+
return hideUnavailableArrows || (IS_WEB && arrowsVisibility === 'hover')
|
|
644
|
+
? <View ref={ref} {...webDataSet({ bloomCarouselArrow: '' })}
|
|
645
|
+
aria-hidden={hidden || undefined}
|
|
646
|
+
accessibilityElementsHidden={hidden}
|
|
647
|
+
importantForAccessibility={hidden ? 'no-hide-descendants' : 'auto'}
|
|
648
|
+
pointerEvents={hidden ? 'none' : 'auto'}
|
|
649
|
+
style={{ flexShrink: 0, ...(hidden ? { opacity: 0 } : undefined) }}>{button}</View>
|
|
650
|
+
: button;
|
|
651
|
+
};
|
|
652
|
+
useLayoutEffect(() => {
|
|
653
|
+
if (!IS_WEB || !hideUnavailableArrows || typeof HTMLElement === 'undefined') return;
|
|
654
|
+
const activeElement = document.activeElement;
|
|
655
|
+
for (const [unavailable, ref] of [[atStart, previousArrowRef], [atEnd, nextArrowRef]] as const) {
|
|
656
|
+
const slot: unknown = ref.current;
|
|
657
|
+
if (unavailable && slot instanceof HTMLElement && slot.contains(activeElement)) {
|
|
658
|
+
const trackNode: unknown = scrollRef.current?.getScrollableNode();
|
|
659
|
+
if (trackNode instanceof HTMLElement) trackNode.focus({ preventScroll: true });
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}, [atStart, atEnd, hideUnavailableArrows]);
|
|
641
664
|
const arrowButtons = <>
|
|
642
|
-
{arrow(<Button size={overlay ? 'lg' : 'sm'}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
665
|
+
{arrow(<Button size={overlay ? 'lg' : 'sm'} appearance="subtle" tone="neutral" {...arrowButtonProps}
|
|
666
|
+
icon={rtl ? RiArrowRightSLine : RiArrowLeftSLine}
|
|
667
|
+
accessibilityLabel={previousLabel} disabled={atStart} onPress={() => step(-1)} />,
|
|
668
|
+
atStart, previousArrowRef)}
|
|
669
|
+
{arrow(<Button size={overlay ? 'lg' : 'sm'} appearance="subtle" tone="neutral" {...arrowButtonProps}
|
|
670
|
+
icon={rtl ? RiArrowLeftSLine : RiArrowRightSLine}
|
|
671
|
+
accessibilityLabel={nextLabel} disabled={atEnd} onPress={() => step(1)} />,
|
|
672
|
+
atEnd, nextArrowRef)}
|
|
648
673
|
</>;
|
|
649
674
|
// iOS snapping reads physical offsets even though its imperative command and
|
|
650
675
|
// scroll events use logical offsets. Android converts snap offsets internally.
|
package/src/carousel/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Carousel, CarouselItem } from './Carousel';
|
|
2
|
-
export type { CarouselProps, CarouselItemProps } from './types';
|
|
2
|
+
export type { CarouselProps, CarouselItemProps, CarouselArrowButtonProps } from './types';
|
package/src/carousel/types.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import type { ButtonProps } from '../button/types';
|
|
4
|
+
|
|
5
|
+
/** Visual options only; the carousel retains navigation, names and disabled state. */
|
|
6
|
+
export type CarouselArrowButtonProps = Pick<ButtonProps,
|
|
7
|
+
'className' | 'material' | 'appearance' | 'tone' | 'size' | 'iconSize'>;
|
|
3
8
|
|
|
4
9
|
export interface CarouselProps {
|
|
5
10
|
/** `CarouselItem`s. Each is labelled "N of M" for assistive technology. */
|
|
@@ -25,6 +30,10 @@ export interface CarouselProps {
|
|
|
25
30
|
* them visible. showArrows still controls whether they are rendered.
|
|
26
31
|
*/
|
|
27
32
|
arrowsVisibility?: 'always' | 'hover';
|
|
33
|
+
/** Optional visual recipe for both arrow buttons. Navigation remains carousel-owned. */
|
|
34
|
+
arrowButtonProps?: CarouselArrowButtonProps;
|
|
35
|
+
/** Hide unavailable arrows without moving their slots; hidden controls are not focusable. Defaults to false. */
|
|
36
|
+
hideUnavailableArrows?: boolean;
|
|
28
37
|
/** Position indicator below the track. Defaults to `true`. */
|
|
29
38
|
showDots?: boolean;
|
|
30
39
|
/** Where a slide comes to rest when it snaps. Defaults to `'start'`. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import type { View } from 'react-native';
|
|
3
3
|
|
|
4
|
-
import { initialFocusWithin, listenForEscape, wrapTab } from './modal-keyboard';
|
|
4
|
+
import { initialFocusWithin, listenForEscape, restoreFocusWhenAvailable, wrapTab } from './modal-keyboard';
|
|
5
5
|
import { useOverlayLayerContext } from './Overlay';
|
|
6
6
|
import { isTopmostOverlayLayer } from './stack';
|
|
7
7
|
|
|
@@ -39,20 +39,20 @@ export function ModalKeyboard({ panelRef, closing = false, dismissible, dismiss
|
|
|
39
39
|
const state = useRef({ closing, dismissible, dismiss });
|
|
40
40
|
state.current = { closing, dismissible, dismiss };
|
|
41
41
|
const opener = useRef<HTMLElement | null>(null);
|
|
42
|
+
const cancelRestore = useRef<(() => void) | undefined>(undefined);
|
|
42
43
|
|
|
43
44
|
const restoreFocus = useCallback(() => {
|
|
44
45
|
const target = opener.current;
|
|
45
46
|
opener.current = null;
|
|
46
47
|
if (!target?.isConnected || typeof document === 'undefined') return;
|
|
47
48
|
const panel = panelRef.current as unknown as HTMLElement | null;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// moved focus on purpose while closing keeps its choice.
|
|
51
|
-
if (!active || active === document.body || panel?.contains(active)) target.focus({ preventScroll: true });
|
|
49
|
+
cancelRestore.current?.();
|
|
50
|
+
cancelRestore.current = restoreFocusWhenAvailable(target, panel);
|
|
52
51
|
}, [panelRef]);
|
|
53
52
|
|
|
54
53
|
useEffect(() => {
|
|
55
54
|
if (typeof window === 'undefined' || typeof document === 'undefined') return;
|
|
55
|
+
cancelRestore.current?.();
|
|
56
56
|
const active = document.activeElement;
|
|
57
57
|
opener.current = active instanceof HTMLElement && active !== document.body ? active : null;
|
|
58
58
|
const panel = () => panelRef.current as unknown as HTMLElement | null;
|
|
@@ -140,3 +140,33 @@ export function listenForEscape(claim: () => boolean, dismiss: () => void): () =
|
|
|
140
140
|
pending = null;
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
/** A modal may begin closing before its opener stops being inert. */
|
|
145
|
+
export function restoreFocusWhenAvailable(target: HTMLElement, panel: HTMLElement | null): () => void {
|
|
146
|
+
if (!hasDom()) return () => {};
|
|
147
|
+
let observer: MutationObserver | undefined;
|
|
148
|
+
let done = false;
|
|
149
|
+
const cancel = () => {
|
|
150
|
+
done = true;
|
|
151
|
+
observer?.disconnect();
|
|
152
|
+
document.removeEventListener('focusin', attempt);
|
|
153
|
+
};
|
|
154
|
+
function attempt() {
|
|
155
|
+
if (done) return;
|
|
156
|
+
if (!target.isConnected) { cancel(); return; }
|
|
157
|
+
const active = document.activeElement;
|
|
158
|
+
// Closing must not steal a host's deliberate destination, or focus from a
|
|
159
|
+
// subsequently opened modal. A removed focused panel leaves body active.
|
|
160
|
+
if (active && active !== document.body && !panel?.contains(active)) { cancel(); return; }
|
|
161
|
+
if (target.closest('[inert]')) return;
|
|
162
|
+
cancel();
|
|
163
|
+
target.focus({ preventScroll: true });
|
|
164
|
+
}
|
|
165
|
+
observer = new MutationObserver(attempt);
|
|
166
|
+
// Watch the actual inert boundary lifecycle, never an assumed exit duration.
|
|
167
|
+
// Child changes also terminate the observer when its opener is removed.
|
|
168
|
+
observer.observe(document.body, { subtree:true, childList:true, attributes:true, attributeFilter:['inert'] });
|
|
169
|
+
document.addEventListener('focusin', attempt);
|
|
170
|
+
attempt();
|
|
171
|
+
return cancel;
|
|
172
|
+
}
|
package/src/search/Search.tsx
CHANGED
|
@@ -2,6 +2,8 @@ import { forwardRef, useCallback, useMemo, useRef } from 'react';
|
|
|
2
2
|
import { Platform, type TextInput, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { mergeRefs } from '../hooks/merge-refs';
|
|
5
|
+
import { FieldBox } from '../text-field/FieldBox';
|
|
6
|
+
import type { SearchProps } from './types';
|
|
5
7
|
import { useDirectionProps, useIsRtl } from '../hooks/use-is-rtl';
|
|
6
8
|
import { useCommonMessages } from '../locale/common-messages';
|
|
7
9
|
import { useMessages } from '../locale/messages';
|
|
@@ -11,20 +13,12 @@ import { useTheme } from '../theme/use-theme';
|
|
|
11
13
|
import { atoms as a } from '../styles';
|
|
12
14
|
import { borderRadius } from '../styles/tokens';
|
|
13
15
|
import { GlyphButton } from '../button';
|
|
14
|
-
import { TextField, TextFieldIcon, TextFieldInput
|
|
16
|
+
import { TextField, TextFieldIcon, TextFieldInput } from '../text-field';
|
|
15
17
|
import { RiSearchLine as MagnifyingGlassIcon } from '../icons/remix/RiSearchLine';
|
|
16
18
|
import { RiCloseLine as X } from '../icons/remix/RiCloseLine';
|
|
17
19
|
|
|
18
|
-
type SearchProps = Omit<TextFieldInputProps, 'label'> & {
|
|
19
|
-
label?: TextFieldInputProps['label'];
|
|
20
|
-
/**
|
|
21
|
-
* Called when the user presses the clear (X) button.
|
|
22
|
-
*/
|
|
23
|
-
onClearText?: () => void;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
20
|
export const Search = forwardRef<TextInput, SearchProps>(
|
|
27
|
-
function Search({ value, label: labelProp, onClearText, onFocus, onPressIn, ...rest }, ref) {
|
|
21
|
+
function Search({ value, label: labelProp, onClearText, onFocus, onPressIn, fieldClassName, fieldChromeClassName, containerClassName, containerStyle, ...rest }, ref) {
|
|
28
22
|
const theme = useTheme();
|
|
29
23
|
const direction = useDirectionProps();
|
|
30
24
|
const rtl = useIsRtl();
|
|
@@ -69,8 +63,8 @@ export const Search = forwardRef<TextInput, SearchProps>(
|
|
|
69
63
|
);
|
|
70
64
|
|
|
71
65
|
return (
|
|
72
|
-
<
|
|
73
|
-
<TextField radius={borderRadius.full}>
|
|
66
|
+
<FieldBox {...direction} className={containerClassName} style={containerStyle} baseStyle={[a.w_full, a.relative]}>
|
|
67
|
+
<TextField radius={borderRadius.full} className={fieldClassName} chromeClassName={fieldChromeClassName}>
|
|
74
68
|
<TextFieldIcon icon={MagnifyingGlassIcon} />
|
|
75
69
|
<TextFieldInput
|
|
76
70
|
inputRef={refs}
|
|
@@ -113,7 +107,7 @@ export const Search = forwardRef<TextInput, SearchProps>(
|
|
|
113
107
|
/>
|
|
114
108
|
</View>
|
|
115
109
|
)}
|
|
116
|
-
</
|
|
110
|
+
</FieldBox>
|
|
117
111
|
);
|
|
118
112
|
},
|
|
119
113
|
);
|
package/src/search/index.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import type { TextFieldInputProps } from '../text-field/types';
|
|
3
|
+
|
|
4
|
+
export type SearchProps = Omit<TextFieldInputProps, 'label'> & {
|
|
5
|
+
label?: TextFieldInputProps['label'];
|
|
6
|
+
/** Called when the user presses the clear button. */
|
|
7
|
+
onClearText?: () => void;
|
|
8
|
+
/** Field layout classes (height, width and padding). */
|
|
9
|
+
fieldClassName?: string;
|
|
10
|
+
/** Inset surface classes (background, border/ring and radius). */
|
|
11
|
+
fieldChromeClassName?: string;
|
|
12
|
+
/** Classes on the outer layout box, including the clear control. */
|
|
13
|
+
containerClassName?: string;
|
|
14
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Platform, View, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import { styled } from 'react-native-css';
|
|
4
|
+
import { useInteractiveWebCss } from '../styles/interactive-web-css';
|
|
5
|
+
import { resolveNativeWebStyle } from '../styles/resolve-native-web-style';
|
|
6
|
+
|
|
7
|
+
// The field owns two distinct boxes: layout and a non-layout inset ring. Keep
|
|
8
|
+
// their defaults below caller classes without moving the ring into box sizing.
|
|
9
|
+
const properties = ['width', 'minWidth', 'flex', 'flexDirection', 'alignItems', 'position',
|
|
10
|
+
'paddingLeft', 'paddingRight', 'paddingInlineStart', 'paddingInlineEnd', 'borderRadius',
|
|
11
|
+
'borderWidth', 'borderColor', 'backgroundColor', 'zIndex', 'top', 'right', 'bottom', 'left',
|
|
12
|
+
'transitionProperty', 'transitionDuration', 'transitionTimingFunction'] as const;
|
|
13
|
+
const cssName = (name: string) => name.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
|
|
14
|
+
const fallbacks: Record<string, string> = { borderWidth:'0px', minWidth:'0px', flex:'0 0 auto', flexDirection:'column' };
|
|
15
|
+
const CSS = `@layer base { [data-bloom-field-box] { display:flex; box-sizing:border-box; border-style:solid; border-width:0; min-width:0; ${properties.map(name => `${cssName(name)}:var(--bloom-field-${cssName(name)},${fallbacks[name] ?? 'initial'});`).join('')} } }`;
|
|
16
|
+
interface FieldBoxProps {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: StyleProp<ViewStyle>;
|
|
20
|
+
baseStyle?: StyleProp<ViewStyle>;
|
|
21
|
+
stateStyle?: StyleProp<ViewStyle>;
|
|
22
|
+
dir?: 'rtl';
|
|
23
|
+
pointerEvents?: 'none' | 'auto';
|
|
24
|
+
onClick?: () => void;
|
|
25
|
+
onMouseOver?: () => void;
|
|
26
|
+
onMouseOut?: () => void;
|
|
27
|
+
testID?: string;
|
|
28
|
+
}
|
|
29
|
+
function FieldBoxComponent({ children, className, style, baseStyle, stateStyle, dir, pointerEvents, onClick,
|
|
30
|
+
onMouseOver, onMouseOut, testID }: FieldBoxProps) {
|
|
31
|
+
useInteractiveWebCss('bloom-field-box', CSS);
|
|
32
|
+
if (Platform.OS !== 'web') return <View pointerEvents={pointerEvents} testID={testID}
|
|
33
|
+
style={[baseStyle, style, stateStyle]}>{children}</View>;
|
|
34
|
+
const defaults = resolveNativeWebStyle(baseStyle);
|
|
35
|
+
const variables: Record<string, unknown> = {};
|
|
36
|
+
for (const name of properties) {
|
|
37
|
+
const value = defaults[name as keyof React.CSSProperties];
|
|
38
|
+
if (value === undefined || value === null) { variables[`--bloom-field-${cssName(name)}`] = 'initial'; continue; }
|
|
39
|
+
const unit = typeof value === 'number' && !['flex', 'zIndex'].includes(name) ? 'px' : '';
|
|
40
|
+
variables[`--bloom-field-${cssName(name)}`] = `${value}${unit}`;
|
|
41
|
+
}
|
|
42
|
+
return <div data-bloom-field-box="" data-testid={testID} className={className} dir={dir ?? 'ltr'}
|
|
43
|
+
onClick={onClick} onMouseOver={onMouseOver} onMouseOut={onMouseOut}
|
|
44
|
+
style={{ ...variables, ...resolveNativeWebStyle(style), ...resolveNativeWebStyle(stateStyle), pointerEvents }}>
|
|
45
|
+
{/* RNW resolves logical styles from its own direction context. This
|
|
46
|
+
context carrier has no CSS box; the div remains the sole layout host. */}
|
|
47
|
+
<View {...{ dir: dir ?? 'ltr' }} style={{ display: 'contents' }}>{children}</View>
|
|
48
|
+
</div>;
|
|
49
|
+
}
|
|
50
|
+
const NativeFieldBox = styled(FieldBoxComponent, { className: 'style' });
|
|
51
|
+
export const FieldBox = Platform.OS === 'web' ? FieldBoxComponent : NativeFieldBox;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useBloomAppearance } from '../appearance';
|
|
2
|
+
import { FieldBox } from './FieldBox';
|
|
2
3
|
import { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
4
|
import {
|
|
4
5
|
type AccessibilityProps,
|
|
@@ -88,6 +89,7 @@ interface TextFieldContextValue {
|
|
|
88
89
|
addonFocused: boolean;
|
|
89
90
|
/** Inside an `InputGroup`: the group paints the shell, so the field draws none. */
|
|
90
91
|
bare: boolean;
|
|
92
|
+
chromeClassName?: string;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/**
|
|
@@ -167,6 +169,8 @@ export function TextField({
|
|
|
167
169
|
size: sizeProp,
|
|
168
170
|
radius = TEXT_FIELD_RADIUS,
|
|
169
171
|
leadingAddon,
|
|
172
|
+
className,
|
|
173
|
+
chromeClassName,
|
|
170
174
|
style,
|
|
171
175
|
}: TextFieldProps) {
|
|
172
176
|
const theme = useTheme();
|
|
@@ -223,15 +227,18 @@ export function TextField({
|
|
|
223
227
|
palette,
|
|
224
228
|
radius,
|
|
225
229
|
bare,
|
|
230
|
+
chromeClassName,
|
|
226
231
|
}),
|
|
227
|
-
[inputRef, hovered, onHoverIn, onHoverOut, focused, onFocus, onBlur, addonFocused, invalid, resolvedDisabled, size, palette, radius, bare],
|
|
232
|
+
[inputRef, hovered, onHoverIn, onHoverOut, focused, onFocus, onBlur, addonFocused, invalid, resolvedDisabled, size, palette, radius, bare, chromeClassName],
|
|
228
233
|
);
|
|
229
234
|
|
|
230
235
|
return (
|
|
231
236
|
<Context.Provider value={context}>
|
|
232
|
-
<
|
|
237
|
+
<FieldBox
|
|
233
238
|
{...direction}
|
|
234
|
-
|
|
239
|
+
className={className}
|
|
240
|
+
style={style}
|
|
241
|
+
baseStyle={[
|
|
235
242
|
a.flex_row,
|
|
236
243
|
a.align_center,
|
|
237
244
|
a.relative,
|
|
@@ -243,7 +250,6 @@ export function TextField({
|
|
|
243
250
|
? TEXT_FIELD_ADDON_PADDING[size]
|
|
244
251
|
: { paddingHorizontal: TEXT_FIELD_GEOMETRY[size].paddingHorizontal },
|
|
245
252
|
],
|
|
246
|
-
style,
|
|
247
253
|
]}
|
|
248
254
|
{...(IS_WEB
|
|
249
255
|
? ({
|
|
@@ -256,7 +262,7 @@ export function TextField({
|
|
|
256
262
|
<LeadingAddon onFocusChange={setAddonFocused}>{leadingAddon}</LeadingAddon>
|
|
257
263
|
) : null}
|
|
258
264
|
{children}
|
|
259
|
-
</
|
|
265
|
+
</FieldBox>
|
|
260
266
|
</Context.Provider>
|
|
261
267
|
);
|
|
262
268
|
}
|
|
@@ -328,9 +334,11 @@ function Chrome({ invalid }: { invalid: boolean }) {
|
|
|
328
334
|
disabled: ctx.disabled,
|
|
329
335
|
});
|
|
330
336
|
return (
|
|
331
|
-
<
|
|
337
|
+
<FieldBox
|
|
332
338
|
pointerEvents="none"
|
|
333
|
-
|
|
339
|
+
className={ctx.chromeClassName}
|
|
340
|
+
stateStyle={ctx.disabled || invalid ? paint : ctx.focused || ctx.addonFocused ? { borderColor: paint.borderColor } : undefined}
|
|
341
|
+
baseStyle={[
|
|
334
342
|
a.z_10,
|
|
335
343
|
a.absolute,
|
|
336
344
|
a.inset_0,
|
package/src/text-field/types.ts
CHANGED
|
@@ -8,6 +8,10 @@ export type { TextFieldSize } from './shared';
|
|
|
8
8
|
|
|
9
9
|
export type TextFieldProps = React.PropsWithChildren<
|
|
10
10
|
{
|
|
11
|
+
/** Classes on the layout host: width, height and padding. */
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Classes on the inset surface: background, border/ring and radius. State paint remains authoritative. */
|
|
14
|
+
chromeClassName?: string;
|
|
11
15
|
invalid?: boolean;
|
|
12
16
|
isInvalid?: boolean;
|
|
13
17
|
/**
|