glacia-native 0.5.0 → 0.5.2
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/LICENSE +29 -4
- package/README.md +27 -0
- package/lib/module/Bars.js +103 -9
- package/lib/module/Button.js +11 -8
- package/lib/module/Card.js +2 -2
- package/lib/module/Dialog.js +16 -17
- package/lib/module/Display.js +86 -8
- package/lib/module/Feedback.js +244 -21
- package/lib/module/Form.js +29 -33
- package/lib/module/Forms2.js +257 -13
- package/lib/module/Glass.js +2 -2
- package/lib/module/Input.js +12 -10
- package/lib/module/Message.js +84 -0
- package/lib/module/Overlays.js +195 -17
- package/lib/module/Pickers.js +16 -16
- package/lib/module/SegmentedControl.js +24 -11
- package/lib/module/Slider.js +24 -10
- package/lib/module/Switch.js +25 -10
- package/lib/module/TabBar.js +23 -13
- package/lib/module/Table.js +4 -3
- package/lib/module/Tabs.js +3 -2
- package/lib/module/ai.js +26 -18
- package/lib/module/charts/BarChart.js +11 -3
- package/lib/module/index.js +23 -2
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +10 -2
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/blur.js +78 -0
- package/lib/module/internal/fallback.js +120 -19
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/glow.js +36 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/lens.js +70 -0
- package/lib/module/internal/material.js +64 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +70 -4
- package/lib/module/internal/rim.js +35 -0
- package/lib/module/internal/tokens.js +80 -2
- package/lib/typescript/Bars.d.ts +67 -0
- package/lib/typescript/Display.d.ts +59 -0
- package/lib/typescript/Feedback.d.ts +58 -0
- package/lib/typescript/Forms2.d.ts +81 -0
- package/lib/typescript/Message.d.ts +67 -0
- package/lib/typescript/Overlays.d.ts +41 -0
- package/lib/typescript/SegmentedControl.d.ts +2 -0
- package/lib/typescript/Slider.d.ts +2 -0
- package/lib/typescript/Switch.d.ts +2 -0
- package/lib/typescript/TabBar.d.ts +2 -0
- package/lib/typescript/index.d.ts +9 -6
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +21 -0
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/blur.d.ts +24 -0
- package/lib/typescript/internal/fallback.d.ts +32 -2
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/glow.d.ts +11 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/lens.d.ts +47 -0
- package/lib/typescript/internal/material.d.ts +27 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +23 -0
- package/lib/typescript/internal/rim.d.ts +16 -0
- package/lib/typescript/internal/tokens.d.ts +89 -0
- package/package.json +12 -3
- package/src/Bars.tsx +239 -2
- package/src/Button.tsx +16 -9
- package/src/Card.tsx +2 -2
- package/src/Dialog.tsx +37 -26
- package/src/Display.tsx +237 -6
- package/src/Feedback.tsx +448 -35
- package/src/Form.tsx +60 -40
- package/src/Forms2.tsx +455 -8
- package/src/Glass.tsx +4 -0
- package/src/Input.tsx +15 -11
- package/src/Message.tsx +218 -0
- package/src/Overlays.tsx +269 -39
- package/src/Pickers.tsx +11 -6
- package/src/SegmentedControl.tsx +39 -9
- package/src/Slider.tsx +26 -10
- package/src/Switch.tsx +29 -10
- package/src/TabBar.tsx +39 -12
- package/src/Table.tsx +4 -3
- package/src/Tabs.tsx +5 -0
- package/src/ai.tsx +37 -23
- package/src/charts/BarChart.tsx +41 -3
- package/src/index.ts +43 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +25 -0
- package/src/internal/a11y.ts +105 -0
- package/src/internal/blur.ts +90 -0
- package/src/internal/fallback.tsx +170 -15
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/glow.tsx +62 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/lens.tsx +105 -0
- package/src/internal/material.ts +92 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +83 -4
- package/src/internal/rim.tsx +79 -0
- package/src/internal/tokens.ts +82 -1
package/src/Forms2.tsx
CHANGED
|
@@ -3,9 +3,10 @@ import type { StyleProp, ViewStyle } from "react-native";
|
|
|
3
3
|
|
|
4
4
|
import { Glass } from "./Glass";
|
|
5
5
|
import { Text } from "./Text";
|
|
6
|
-
import { colors, radii } from "./internal/tokens";
|
|
6
|
+
import { colors, controlSizes, palette as tokenPalette, radii } from "./internal/tokens";
|
|
7
7
|
import { primitives } from "./internal/primitives";
|
|
8
8
|
import { useIsDark } from "./internal/motion";
|
|
9
|
+
import { SelectedLens, lensFill } from "./internal/lens";
|
|
9
10
|
|
|
10
11
|
// ---------------------------------------------------------------------------
|
|
11
12
|
// Stepper
|
|
@@ -82,9 +83,9 @@ export const Stepper = forwardRef<any, StepperProps>(function Stepper(
|
|
|
82
83
|
accessibilityState={{ disabled: disabled || blocked }}
|
|
83
84
|
disabled={disabled || blocked}
|
|
84
85
|
onPress={action}
|
|
85
|
-
style={{ width:
|
|
86
|
+
style={{ width: 46, height: 34, alignItems: "center", justifyContent: "center", opacity: disabled || blocked ? 0.38 : 1 }}
|
|
86
87
|
>
|
|
87
|
-
<RNText style={{ fontSize:
|
|
88
|
+
<RNText style={{ fontSize: 17, fontWeight: "500", color: theme.foreground, lineHeight: 20 }}>
|
|
88
89
|
{sign}
|
|
89
90
|
</RNText>
|
|
90
91
|
</Pressable>
|
|
@@ -94,6 +95,7 @@ export const Stepper = forwardRef<any, StepperProps>(function Stepper(
|
|
|
94
95
|
<Glass
|
|
95
96
|
ref={ref}
|
|
96
97
|
effect="regular"
|
|
98
|
+
surface="control"
|
|
97
99
|
isDark={isDark}
|
|
98
100
|
testID={testID}
|
|
99
101
|
accessibilityRole="adjustable"
|
|
@@ -108,6 +110,7 @@ export const Stepper = forwardRef<any, StepperProps>(function Stepper(
|
|
|
108
110
|
flexDirection: "row",
|
|
109
111
|
alignItems: "center",
|
|
110
112
|
alignSelf: "flex-start",
|
|
113
|
+
height: 34,
|
|
111
114
|
borderRadius: radii.pill,
|
|
112
115
|
paddingHorizontal: 2,
|
|
113
116
|
opacity: disabled ? 0.38 : 1,
|
|
@@ -148,7 +151,7 @@ export interface ToggleProps {
|
|
|
148
151
|
testID?: string;
|
|
149
152
|
}
|
|
150
153
|
|
|
151
|
-
const toggleSizes = { sm: 30, md:
|
|
154
|
+
const toggleSizes = { sm: 30, md: 34, lg: 44 };
|
|
152
155
|
|
|
153
156
|
/**
|
|
154
157
|
* A button that stays pressed.
|
|
@@ -185,6 +188,8 @@ export const Toggle = forwardRef<any, ToggleProps>(function Toggle(
|
|
|
185
188
|
const [internal, setInternal] = useState(defaultPressed);
|
|
186
189
|
const isPressed = controlled !== undefined ? controlled : internal;
|
|
187
190
|
|
|
191
|
+
const [held, setHeld] = useState(false);
|
|
192
|
+
|
|
188
193
|
const dimension = toggleSizes[size];
|
|
189
194
|
|
|
190
195
|
const handlePress = () => {
|
|
@@ -202,11 +207,15 @@ export const Toggle = forwardRef<any, ToggleProps>(function Toggle(
|
|
|
202
207
|
accessibilityState={{ selected: isPressed, disabled }}
|
|
203
208
|
disabled={disabled}
|
|
204
209
|
onPress={handlePress}
|
|
210
|
+
onPressIn={() => setHeld(true)}
|
|
211
|
+
onPressOut={() => setHeld(false)}
|
|
205
212
|
style={({ pressed }: { pressed: boolean }) => ({ alignSelf: "flex-start", opacity: disabled ? 0.38 : pressed ? 0.8 : 1 })}
|
|
206
213
|
{...props}
|
|
207
214
|
>
|
|
208
215
|
<Glass
|
|
209
216
|
effect={variant === "ghost" ? "none" : "regular"}
|
|
217
|
+
surface="control"
|
|
218
|
+
pressed={held}
|
|
210
219
|
interactive={!disabled && variant !== "ghost"}
|
|
211
220
|
isDark={isDark}
|
|
212
221
|
tintColor={isPressed && variant !== "ghost" ? theme.glassActive : undefined}
|
|
@@ -228,7 +237,7 @@ export const Toggle = forwardRef<any, ToggleProps>(function Toggle(
|
|
|
228
237
|
<RNText
|
|
229
238
|
numberOfLines={1}
|
|
230
239
|
style={{
|
|
231
|
-
fontSize: size === "sm" ? 12 : size === "lg" ? 15 :
|
|
240
|
+
fontSize: size === "sm" ? 12 : size === "lg" ? 15 : 14,
|
|
232
241
|
fontWeight: isPressed ? "600" : "500",
|
|
233
242
|
color: isPressed ? theme.foreground : theme.muted,
|
|
234
243
|
}}
|
|
@@ -322,6 +331,7 @@ export const ToggleGroup = forwardRef<any, ToggleGroupProps>(function ToggleGrou
|
|
|
322
331
|
<Glass
|
|
323
332
|
ref={ref}
|
|
324
333
|
effect="regular"
|
|
334
|
+
surface="control"
|
|
325
335
|
isDark={isDark}
|
|
326
336
|
testID={testID}
|
|
327
337
|
accessibilityRole="radiogroup"
|
|
@@ -333,6 +343,12 @@ export const ToggleGroup = forwardRef<any, ToggleGroupProps>(function ToggleGrou
|
|
|
333
343
|
padding: 3,
|
|
334
344
|
gap: 3,
|
|
335
345
|
borderRadius: radii.pill,
|
|
346
|
+
// The web makes the group's own surface near-solid for legibility; the
|
|
347
|
+
// selected item is the glass lens on top of it.
|
|
348
|
+
backgroundColor: theme.surface,
|
|
349
|
+
shadowOpacity: 0.08,
|
|
350
|
+
shadowRadius: 8,
|
|
351
|
+
shadowOffset: { width: 0, height: 2 },
|
|
336
352
|
...(style as ViewStyle),
|
|
337
353
|
}}
|
|
338
354
|
{...props}
|
|
@@ -358,11 +374,11 @@ export const ToggleGroup = forwardRef<any, ToggleGroupProps>(function ToggleGrou
|
|
|
358
374
|
alignItems: "center",
|
|
359
375
|
justifyContent: "center",
|
|
360
376
|
gap: 6,
|
|
361
|
-
backgroundColor:
|
|
362
|
-
borderWidth: on ? 0.5 : 0,
|
|
363
|
-
borderColor: theme.edge,
|
|
377
|
+
backgroundColor: "transparent",
|
|
364
378
|
}}
|
|
365
379
|
>
|
|
380
|
+
{/* The chosen item is a lens; the group's rail is the glass. */}
|
|
381
|
+
{on ? <SelectedLens radius={radii.pill} isDark={isDark} style={lensFill} /> : null}
|
|
366
382
|
{item.icon ? <View>{item.icon}</View> : null}
|
|
367
383
|
<RNText
|
|
368
384
|
numberOfLines={1}
|
|
@@ -453,6 +469,7 @@ export const InputOTP = forwardRef<any, InputOTPProps>(function InputOTP(
|
|
|
453
469
|
<Glass
|
|
454
470
|
key={index}
|
|
455
471
|
effect="regular"
|
|
472
|
+
surface="field"
|
|
456
473
|
isDark={isDark}
|
|
457
474
|
tintColor={isActive ? theme.glassActive : undefined}
|
|
458
475
|
style={{
|
|
@@ -582,6 +599,7 @@ export const ButtonGroup = forwardRef<any, ButtonGroupProps>(function ButtonGrou
|
|
|
582
599
|
>
|
|
583
600
|
<Glass
|
|
584
601
|
effect="regular"
|
|
602
|
+
surface="control"
|
|
585
603
|
interactive={!item.disabled}
|
|
586
604
|
isDark={isDark}
|
|
587
605
|
style={{
|
|
@@ -606,3 +624,432 @@ export const ButtonGroup = forwardRef<any, ButtonGroupProps>(function ButtonGrou
|
|
|
606
624
|
</View>
|
|
607
625
|
);
|
|
608
626
|
});
|
|
627
|
+
|
|
628
|
+
// ---------------------------------------------------------------------------
|
|
629
|
+
// ColorPicker
|
|
630
|
+
|
|
631
|
+
export interface ColorPickerProps {
|
|
632
|
+
/** A palette of hex colours the caller supplies. */
|
|
633
|
+
colors?: string[];
|
|
634
|
+
/** Controlled value. Omit and the picker keeps its own. */
|
|
635
|
+
value?: string;
|
|
636
|
+
defaultValue?: string;
|
|
637
|
+
onChange?: (color: string) => void;
|
|
638
|
+
/** The swatch size. */
|
|
639
|
+
size?: "sm" | "md" | "lg";
|
|
640
|
+
/** Rows in the palette grid. Defaults to a single row. */
|
|
641
|
+
columns?: number;
|
|
642
|
+
/** Whether a custom row (hue + picker) appears below the palette. */
|
|
643
|
+
allowCustom?: boolean;
|
|
644
|
+
disabled?: boolean;
|
|
645
|
+
/** The accessible name. */
|
|
646
|
+
accessibilityLabel?: string;
|
|
647
|
+
style?: StyleProp<ViewStyle>;
|
|
648
|
+
isDark?: boolean;
|
|
649
|
+
testID?: string;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* A colour picker built from Glacia's own parts — no native widget.
|
|
654
|
+
*
|
|
655
|
+
* The palette is a grid of swatches from the caller's colours; the custom row
|
|
656
|
+
* is a hue track drawn as an SVG gradient (the resolver's shapes, so it works
|
|
657
|
+
* wherever the charts work) driven by the same Slider mechanics as the rest of
|
|
658
|
+
* the library: a drag along the track picks a hue, and a second track saturates
|
|
659
|
+
* it. The value is a hex string.
|
|
660
|
+
*
|
|
661
|
+
* The default palette is a small set of iOS-conventional colours, in case a
|
|
662
|
+
* caller wants a picker with no colour knowledge of its own.
|
|
663
|
+
*/
|
|
664
|
+
export const DEFAULT_PALETTE = tokenPalette.default;
|
|
665
|
+
|
|
666
|
+
/** Parses a hex colour into its red, green and blue channels. */
|
|
667
|
+
export function hexToRgb(hex: string): { r: number; g: number; b: number } | null {
|
|
668
|
+
const match = /^#?([0-9a-f]{6})$/i.exec(hex.trim());
|
|
669
|
+
if (!match) return null;
|
|
670
|
+
const raw = match[1]!;
|
|
671
|
+
return {
|
|
672
|
+
r: parseInt(raw.slice(0, 2), 16),
|
|
673
|
+
g: parseInt(raw.slice(2, 4), 16),
|
|
674
|
+
b: parseInt(raw.slice(4, 6), 16),
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** Builds a hue gradient's colours, sweeping red → orange → … → red. */
|
|
679
|
+
export function hueGradientColors(): string[] {
|
|
680
|
+
const stops = 12;
|
|
681
|
+
return Array.from({ length: stops }, (_u, i) => {
|
|
682
|
+
const angle = (i / stops) * 360;
|
|
683
|
+
const c = hslToRgb(angle, 1, 0.5);
|
|
684
|
+
return `#${c.r.toString(16).padStart(2, "0")}${c.g.toString(16).padStart(2, "0")}${c.b.toString(16).padStart(2, "0")}`;
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/** Converts an HSL triple (h 0–360, s/l 0–1) to an RGB hex string. */
|
|
689
|
+
function hslToRgb(h: number, s: number, l: number): { r: number; g: number; b: number } {
|
|
690
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
691
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
692
|
+
const m = l - c / 2;
|
|
693
|
+
let r = 0, g = 0, b = 0;
|
|
694
|
+
if (h < 60) { r = c; g = x; } else if (h < 120) { r = x; g = c; } else if (h < 180) { g = c; b = x; } else if (h < 240) { g = x; b = c; } else if (h < 300) { r = x; b = c; } else { r = c; b = x; }
|
|
695
|
+
return {
|
|
696
|
+
r: Math.round((r + m) * 255),
|
|
697
|
+
g: Math.round((g + m) * 255),
|
|
698
|
+
b: Math.round((b + m) * 255),
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
/** Converts an RGB triple to a hex string. */
|
|
703
|
+
export function rgbToHex(r: number, g: number, b: number): string {
|
|
704
|
+
const clamp = (n: number) => Math.max(0, Math.min(255, Math.round(n)));
|
|
705
|
+
return `#${clamp(r).toString(16).padStart(2, "0")}${clamp(g).toString(16).padStart(2, "0")}${clamp(b).toString(16).padStart(2, "0")}`;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
export const ColorPicker = forwardRef<any, ColorPickerProps>(function ColorPicker(
|
|
709
|
+
{
|
|
710
|
+
colors: palette,
|
|
711
|
+
value,
|
|
712
|
+
defaultValue,
|
|
713
|
+
onChange,
|
|
714
|
+
size = "md",
|
|
715
|
+
columns = 6,
|
|
716
|
+
allowCustom = true,
|
|
717
|
+
disabled = false,
|
|
718
|
+
accessibilityLabel = "Color",
|
|
719
|
+
style,
|
|
720
|
+
isDark: isDarkProp,
|
|
721
|
+
testID,
|
|
722
|
+
...props
|
|
723
|
+
},
|
|
724
|
+
ref,
|
|
725
|
+
) {
|
|
726
|
+
const isDark = useIsDark(isDarkProp);
|
|
727
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
728
|
+
const { View, Pressable, Text: RNText, PanResponder, Svg, Rect, Defs, LinearGradient, Stop } = primitives();
|
|
729
|
+
|
|
730
|
+
const swatches = palette && palette.length > 0 ? palette : DEFAULT_PALETTE;
|
|
731
|
+
|
|
732
|
+
const [internalValue, setInternalValue] = useState(defaultValue ?? swatches[0] ?? tokenPalette.fallback);
|
|
733
|
+
const activeColor = value !== undefined ? value : internalValue;
|
|
734
|
+
|
|
735
|
+
const setColor = (next: string) => {
|
|
736
|
+
if (disabled) return;
|
|
737
|
+
if (value === undefined) setInternalValue(next);
|
|
738
|
+
onChange?.(next);
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
// The custom row's two tracks: hue on the top, saturation on the bottom.
|
|
742
|
+
// Both are driven by PanResponder like the library's Slider — a press or a
|
|
743
|
+
// drag along a track reports the colour at that position.
|
|
744
|
+
const trackRef = useRef(0);
|
|
745
|
+
const swatchSize = controlSizes.swatch[size];
|
|
746
|
+
|
|
747
|
+
const hueColor = (h: number) => {
|
|
748
|
+
const c = hslToRgb(h, 1, 0.5);
|
|
749
|
+
return rgbToHex(c.r, c.g, c.b);
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
const colorAtFraction = (fraction: number, hue: number) => {
|
|
753
|
+
const sat = Math.max(0, Math.min(1, fraction));
|
|
754
|
+
const c = hslToRgb(hue, sat, 0.5);
|
|
755
|
+
return rgbToHex(c.r, c.g, c.b);
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
const hue = hexToRgb(activeColor) ? hueOf(activeColor) : 0;
|
|
759
|
+
|
|
760
|
+
const hueResponder = makeTrackResponder((fraction) => {
|
|
761
|
+
setColor(hueColor(fraction * 360));
|
|
762
|
+
}, PanResponder, trackRef);
|
|
763
|
+
|
|
764
|
+
const satResponder = makeTrackResponder((fraction) => {
|
|
765
|
+
setColor(colorAtFraction(fraction, hue));
|
|
766
|
+
}, PanResponder, trackRef);
|
|
767
|
+
|
|
768
|
+
const hueGradient = hueGradientColors();
|
|
769
|
+
|
|
770
|
+
return (
|
|
771
|
+
<View
|
|
772
|
+
ref={ref}
|
|
773
|
+
testID={testID}
|
|
774
|
+
accessibilityRole="adjustable"
|
|
775
|
+
accessibilityLabel={accessibilityLabel}
|
|
776
|
+
accessibilityValue={{ text: activeColor }}
|
|
777
|
+
style={{ gap: 12, opacity: disabled ? 0.38 : 1, ...(style as ViewStyle) }}
|
|
778
|
+
{...props}
|
|
779
|
+
>
|
|
780
|
+
{/* The palette grid. */}
|
|
781
|
+
<View style={{ flexDirection: "row", flexWrap: "wrap", gap: 8 }}>
|
|
782
|
+
{swatches.map((swatch, index) => {
|
|
783
|
+
const selected = swatch.toLowerCase() === activeColor.toLowerCase();
|
|
784
|
+
return (
|
|
785
|
+
<Pressable
|
|
786
|
+
key={`${swatch}-${index}`}
|
|
787
|
+
accessibilityRole="button"
|
|
788
|
+
accessibilityLabel={`${swatch} color`}
|
|
789
|
+
accessibilityState={{ selected }}
|
|
790
|
+
disabled={disabled}
|
|
791
|
+
onPress={() => setColor(swatch)}
|
|
792
|
+
style={{
|
|
793
|
+
width: swatchSize,
|
|
794
|
+
height: swatchSize,
|
|
795
|
+
borderRadius: swatchSize / 2,
|
|
796
|
+
backgroundColor: swatch,
|
|
797
|
+
borderWidth: selected ? 2 : 0.5,
|
|
798
|
+
borderColor: selected ? theme.fill : theme.separator,
|
|
799
|
+
}}
|
|
800
|
+
/>
|
|
801
|
+
);
|
|
802
|
+
})}
|
|
803
|
+
</View>
|
|
804
|
+
|
|
805
|
+
{allowCustom ? (
|
|
806
|
+
<View style={{ gap: 8 }}>
|
|
807
|
+
{/* Hue track */}
|
|
808
|
+
<View
|
|
809
|
+
style={{ height: controlSizes.picker.track, borderRadius: radii.md, overflow: "hidden" }}
|
|
810
|
+
{...(hueResponder ? hueResponder.panHandlers : {})}
|
|
811
|
+
>
|
|
812
|
+
<Svg width="100%" height="100%">
|
|
813
|
+
<Defs>
|
|
814
|
+
<LinearGradient id="hueGradient" x1="0" y1="0" x2="1" y2="0">
|
|
815
|
+
{hueGradient.map((color, i) => (
|
|
816
|
+
<Stop key={i} offset={i / (hueGradient.length - 1)} stopColor={color} />
|
|
817
|
+
))}
|
|
818
|
+
</LinearGradient>
|
|
819
|
+
</Defs>
|
|
820
|
+
<Rect x="0" y="0" width="100%" height="100%" fill="url(#hueGradient)" />
|
|
821
|
+
</Svg>
|
|
822
|
+
</View>
|
|
823
|
+
{/* Saturation track: the hue at full saturation fading to white. */}
|
|
824
|
+
<View
|
|
825
|
+
style={{ height: controlSizes.picker.track, borderRadius: radii.md, overflow: "hidden" }}
|
|
826
|
+
{...(satResponder ? satResponder.panHandlers : {})}
|
|
827
|
+
>
|
|
828
|
+
<Svg width="100%" height="100%">
|
|
829
|
+
<Defs>
|
|
830
|
+
<LinearGradient id="satGradient" x1="0" y1="0" x2="1" y2="0">
|
|
831
|
+
<Stop offset="0" stopColor={theme.neutralTop} />
|
|
832
|
+
<Stop offset="1" stopColor={hueColor(hue)} />
|
|
833
|
+
</LinearGradient>
|
|
834
|
+
</Defs>
|
|
835
|
+
<Rect x="0" y="0" width="100%" height="100%" fill="url(#satGradient)" />
|
|
836
|
+
</Svg>
|
|
837
|
+
</View>
|
|
838
|
+
<RNText style={{ fontSize: 12, color: theme.muted }}>{activeColor}</RNText>
|
|
839
|
+
</View>
|
|
840
|
+
) : null}
|
|
841
|
+
</View>
|
|
842
|
+
);
|
|
843
|
+
});
|
|
844
|
+
|
|
845
|
+
/** The hue (0–360) of a hex colour. */
|
|
846
|
+
function hueOf(hex: string): number {
|
|
847
|
+
const rgb = hexToRgb(hex);
|
|
848
|
+
if (!rgb) return 0;
|
|
849
|
+
const { r, g, b } = rgb;
|
|
850
|
+
const max = Math.max(r, g, b) / 255;
|
|
851
|
+
const min = Math.min(r, g, b) / 255;
|
|
852
|
+
const delta = max - min;
|
|
853
|
+
if (delta === 0) return 0;
|
|
854
|
+
let h = 0;
|
|
855
|
+
if (max === r / 255) h = ((g / 255 - b / 255) / delta) % 6;
|
|
856
|
+
else if (max === g / 255) h = (b / 255 - r / 255) / delta + 2;
|
|
857
|
+
else h = (r / 255 - g / 255) / delta + 4;
|
|
858
|
+
const degrees = h * 60;
|
|
859
|
+
return degrees < 0 ? degrees + 360 : degrees;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/** Builds a PanResponder that reports the fraction (0–1) across a track. */
|
|
863
|
+
function makeTrackResponder(
|
|
864
|
+
onFraction: (fraction: number) => void,
|
|
865
|
+
PanResponder: any,
|
|
866
|
+
trackRef: { current: number },
|
|
867
|
+
): any {
|
|
868
|
+
if (!PanResponder?.create) return null;
|
|
869
|
+
return PanResponder.create({
|
|
870
|
+
onStartShouldSetPanResponder: () => true,
|
|
871
|
+
onMoveShouldSetPanResponder: () => true,
|
|
872
|
+
onPanResponderGrant: (event: any) => {
|
|
873
|
+
const fraction = fractionAt(event, 100);
|
|
874
|
+
if (fraction !== null) onFraction(fraction);
|
|
875
|
+
},
|
|
876
|
+
onPanResponderMove: (event: any) => {
|
|
877
|
+
const fraction = fractionAt(event, 100);
|
|
878
|
+
if (fraction !== null) onFraction(fraction);
|
|
879
|
+
},
|
|
880
|
+
onPanResponderTerminationRequest: () => false,
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/** The fraction of the track under a touch, from the touch's X. */
|
|
885
|
+
function fractionAt(event: any, fallbackWidth: number): number | null {
|
|
886
|
+
const x = event?.nativeEvent?.locationX;
|
|
887
|
+
const width = event?.nativeEvent?.layoutMeasurement?.width ?? fallbackWidth;
|
|
888
|
+
if (typeof x !== "number" || typeof width !== "number" || width <= 0) return null;
|
|
889
|
+
return Math.max(0, Math.min(1, x / width));
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// ---------------------------------------------------------------------------
|
|
893
|
+
// Combobox
|
|
894
|
+
|
|
895
|
+
export interface ComboboxOption {
|
|
896
|
+
label: string;
|
|
897
|
+
value: string;
|
|
898
|
+
/** Extra text under the label, if any. */
|
|
899
|
+
description?: string;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
export interface ComboboxProps {
|
|
903
|
+
/** The options the user can choose from. */
|
|
904
|
+
options: ComboboxOption[];
|
|
905
|
+
/** Controlled value. Omit and the combobox keeps its own. */
|
|
906
|
+
value?: string;
|
|
907
|
+
defaultValue?: string;
|
|
908
|
+
onChange?: (value: string) => void;
|
|
909
|
+
/** A description of the underlying field. */
|
|
910
|
+
label?: string;
|
|
911
|
+
placeholder?: string;
|
|
912
|
+
disabled?: boolean;
|
|
913
|
+
/** Called when the dropdown's empty result shows. */
|
|
914
|
+
onEmpty?: () => void;
|
|
915
|
+
style?: StyleProp<ViewStyle>;
|
|
916
|
+
isDark?: boolean;
|
|
917
|
+
testID?: string;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* A type-to-search select.
|
|
922
|
+
*
|
|
923
|
+
* The Input patterns (real TextInput, themed placeholder, `value`/`defaultValue`)
|
|
924
|
+
* open a Menu-style glass dropdown whose list filters as the user types — every
|
|
925
|
+
* keystroke re-filters the options, so the visible set genuinely shrinks, never
|
|
926
|
+
* a list that stays put and pretends to search.
|
|
927
|
+
*
|
|
928
|
+
* The filter is a case-insensitive substring match on label and description. An
|
|
929
|
+
* empty result shows an explicit empty row, so the user sees a search that found
|
|
930
|
+
* nothing rather than a list that silently went blank. The dropdown stays open
|
|
931
|
+
* until an option is picked or the field loses focus.
|
|
932
|
+
*/
|
|
933
|
+
export const Combobox = forwardRef<any, ComboboxProps>(function Combobox(
|
|
934
|
+
{
|
|
935
|
+
options,
|
|
936
|
+
value,
|
|
937
|
+
defaultValue,
|
|
938
|
+
onChange,
|
|
939
|
+
label,
|
|
940
|
+
placeholder = "Search…",
|
|
941
|
+
disabled = false,
|
|
942
|
+
onEmpty,
|
|
943
|
+
style,
|
|
944
|
+
isDark: isDarkProp,
|
|
945
|
+
testID,
|
|
946
|
+
...props
|
|
947
|
+
},
|
|
948
|
+
ref,
|
|
949
|
+
) {
|
|
950
|
+
const isDark = useIsDark(isDarkProp);
|
|
951
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
952
|
+
const { View, TextInput, Text: RNText, Pressable } = primitives();
|
|
953
|
+
|
|
954
|
+
const [internalValue, setInternalValue] = useState(defaultValue ?? "");
|
|
955
|
+
const [query, setQuery] = useState("");
|
|
956
|
+
|
|
957
|
+
const selected = value !== undefined ? value : internalValue;
|
|
958
|
+
const selectedLabel = (options ?? []).find((option) => option.value === selected)?.label ?? "";
|
|
959
|
+
|
|
960
|
+
const setValue = (next: string) => {
|
|
961
|
+
if (disabled) return;
|
|
962
|
+
if (value === undefined) setInternalValue(next);
|
|
963
|
+
onChange?.(next);
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
// Filter as the user types.
|
|
967
|
+
// An option list that has not loaded yet is empty, not a crash: a combobox
|
|
968
|
+
// is frequently rendered before its options arrive.
|
|
969
|
+
const available = options ?? [];
|
|
970
|
+
const needle = query.trim().toLowerCase();
|
|
971
|
+
const matches = needle.length === 0
|
|
972
|
+
? available
|
|
973
|
+
: available.filter((option) =>
|
|
974
|
+
option.label.toLowerCase().includes(needle) ||
|
|
975
|
+
(option.description ?? "").toLowerCase().includes(needle),
|
|
976
|
+
);
|
|
977
|
+
|
|
978
|
+
return (
|
|
979
|
+
<View ref={ref} testID={testID} style={{ ...(style as ViewStyle) }}>
|
|
980
|
+
<Glass
|
|
981
|
+
surface="field"
|
|
982
|
+
isDark={isDark}
|
|
983
|
+
style={{
|
|
984
|
+
minHeight: 34,
|
|
985
|
+
paddingHorizontal: 14,
|
|
986
|
+
justifyContent: "center",
|
|
987
|
+
opacity: disabled ? 0.5 : 1,
|
|
988
|
+
}}
|
|
989
|
+
>
|
|
990
|
+
<TextInput
|
|
991
|
+
value={query}
|
|
992
|
+
onChangeText={(text: string) => setQuery(text)}
|
|
993
|
+
placeholder={placeholder}
|
|
994
|
+
accessibilityLabel={label ?? placeholder}
|
|
995
|
+
accessibilityState={{ disabled }}
|
|
996
|
+
editable={!disabled}
|
|
997
|
+
style={{
|
|
998
|
+
paddingVertical: 8,
|
|
999
|
+
fontSize: 15,
|
|
1000
|
+
color: theme.foreground,
|
|
1001
|
+
}}
|
|
1002
|
+
/>
|
|
1003
|
+
</Glass>
|
|
1004
|
+
{/* The dropdown: opens once there is something to match. */}
|
|
1005
|
+
{query.length > 0 ? (
|
|
1006
|
+
<Glass
|
|
1007
|
+
surface="overlay"
|
|
1008
|
+
isDark={isDark}
|
|
1009
|
+
style={{
|
|
1010
|
+
marginTop: 6,
|
|
1011
|
+
borderRadius: radii.md,
|
|
1012
|
+
// The web dropdown floats on its own shadow rather than sitting
|
|
1013
|
+
// flush on the page.
|
|
1014
|
+
shadowOpacity: 0.4,
|
|
1015
|
+
shadowRadius: 32,
|
|
1016
|
+
shadowOffset: { width: 0, height: 12 },
|
|
1017
|
+
}}
|
|
1018
|
+
>
|
|
1019
|
+
{matches.length === 0 ? (
|
|
1020
|
+
<View style={{ paddingHorizontal: 12, paddingVertical: 10 }}>
|
|
1021
|
+
<RNText style={{ fontSize: 14, color: theme.muted }}>No matches</RNText>
|
|
1022
|
+
</View>
|
|
1023
|
+
) : (
|
|
1024
|
+
matches.map((option, index) => {
|
|
1025
|
+
const isSelected = option.value === selected;
|
|
1026
|
+
return (
|
|
1027
|
+
<Pressable
|
|
1028
|
+
key={`${option.value}-${index}`}
|
|
1029
|
+
accessibilityRole="button"
|
|
1030
|
+
accessibilityLabel={option.label}
|
|
1031
|
+
accessibilityState={{ selected: isSelected }}
|
|
1032
|
+
onPress={() => {
|
|
1033
|
+
setValue(option.value);
|
|
1034
|
+
setQuery("");
|
|
1035
|
+
}}
|
|
1036
|
+
style={{ flexDirection: "row", alignItems: "center", paddingHorizontal: 12, paddingVertical: 10, backgroundColor: "transparent" }}
|
|
1037
|
+
>
|
|
1038
|
+
{isSelected ? (
|
|
1039
|
+
<SelectedLens radius={8} isDark={isDark} style={lensFill} />
|
|
1040
|
+
) : null}
|
|
1041
|
+
<View style={{ flex: 1 }}>
|
|
1042
|
+
<RNText style={{ fontSize: 15, color: theme.foreground }}>{option.label}</RNText>
|
|
1043
|
+
{option.description ? (
|
|
1044
|
+
<RNText style={{ fontSize: 12, color: theme.muted }} numberOfLines={1}>{option.description}</RNText>
|
|
1045
|
+
) : null}
|
|
1046
|
+
</View>
|
|
1047
|
+
</Pressable>
|
|
1048
|
+
);
|
|
1049
|
+
})
|
|
1050
|
+
)}
|
|
1051
|
+
</Glass>
|
|
1052
|
+
) : null}
|
|
1053
|
+
</View>
|
|
1054
|
+
);
|
|
1055
|
+
});
|
package/src/Glass.tsx
CHANGED
|
@@ -21,6 +21,8 @@ export const Glass = forwardRef<any, GlassProps>(function Glass(
|
|
|
21
21
|
effect = "regular",
|
|
22
22
|
tintColor,
|
|
23
23
|
interactive = false,
|
|
24
|
+
surface,
|
|
25
|
+
pressed,
|
|
24
26
|
testID,
|
|
25
27
|
style,
|
|
26
28
|
children,
|
|
@@ -36,6 +38,8 @@ export const Glass = forwardRef<any, GlassProps>(function Glass(
|
|
|
36
38
|
effect={effect}
|
|
37
39
|
tintColor={tintColor}
|
|
38
40
|
interactive={interactive}
|
|
41
|
+
surface={surface}
|
|
42
|
+
pressed={pressed}
|
|
39
43
|
testID={testID}
|
|
40
44
|
isDark={isDark}
|
|
41
45
|
style={style}
|
package/src/Input.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { forwardRef, useState, type ReactNode } from "react";
|
|
2
2
|
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
3
3
|
|
|
4
|
+
import { Glass } from "./Glass";
|
|
4
5
|
import { colors, radii } from "./internal/tokens";
|
|
5
6
|
import { primitives } from "./internal/primitives";
|
|
6
7
|
import { useIsDark } from "./internal/motion";
|
|
@@ -38,7 +39,7 @@ export interface InputProps {
|
|
|
38
39
|
onBlur?: () => void;
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
const heights = { sm:
|
|
42
|
+
const heights = { sm: 28, md: 34, lg: 44 };
|
|
42
43
|
const fontSizes = { sm: 14, md: 15, lg: 16 };
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -100,24 +101,27 @@ export const Input = forwardRef<any, InputProps>(function Input(
|
|
|
100
101
|
|
|
101
102
|
const fieldStyle: TextStyle = {
|
|
102
103
|
flex: 1,
|
|
103
|
-
paddingVertical: height_padding(size),
|
|
104
|
+
paddingVertical: multiline ? 0 : height_padding(size),
|
|
104
105
|
paddingHorizontal: 0,
|
|
105
106
|
fontSize: fontSizes[size],
|
|
106
107
|
color: theme.foreground,
|
|
107
108
|
};
|
|
108
109
|
|
|
109
110
|
return (
|
|
110
|
-
<
|
|
111
|
+
<Glass
|
|
112
|
+
surface="field"
|
|
113
|
+
isDark={isDark}
|
|
111
114
|
style={{
|
|
112
115
|
flexDirection: "row",
|
|
113
116
|
alignItems: multiline ? "flex-start" : "center",
|
|
114
117
|
gap: 8,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
// Fields are pills on the web; a multi-line field relaxes to the
|
|
119
|
+
// stack radius (18) because a pill around wrapped text reads wrong.
|
|
120
|
+
borderRadius: multiline ? 18 : radii.pill,
|
|
121
|
+
minHeight: multiline ? 84 : heights[size],
|
|
122
|
+
paddingHorizontal: 14,
|
|
123
|
+
paddingVertical: multiline ? 10 : 0,
|
|
124
|
+
borderColor: invalid ? theme.destructive : undefined,
|
|
121
125
|
opacity: disabled ? 0.5 : 1,
|
|
122
126
|
...(style as ViewStyle),
|
|
123
127
|
}}
|
|
@@ -165,13 +169,13 @@ export const Input = forwardRef<any, InputProps>(function Input(
|
|
|
165
169
|
</View>
|
|
166
170
|
|
|
167
171
|
{suffix}
|
|
168
|
-
</
|
|
172
|
+
</Glass>
|
|
169
173
|
);
|
|
170
174
|
});
|
|
171
175
|
|
|
172
176
|
/** Vertical padding tuned per size so the text sits optically centred. */
|
|
173
177
|
function height_padding(size: "sm" | "md" | "lg") {
|
|
174
|
-
return size === "sm" ?
|
|
178
|
+
return size === "sm" ? 4 : size === "lg" ? 10 : 7;
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
export interface TextareaProps extends Omit<InputProps, "size" | "multiline" | "minLines"> {
|