@delacour/react-native-ui 0.1.0-alpha.20260925053522 → 0.1.0-alpha.20260925055209

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@delacour/react-native-ui",
3
- "version": "0.1.0-alpha.20260925053522",
4
- "description": "React Native UI components \u2014 Uniwind, Reanimated, Gesture Handler",
3
+ "version": "0.1.0-alpha.20260925055209",
4
+ "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -50,6 +50,7 @@
50
50
  "./separator": "./src/components/separator/index.ts",
51
51
  "./slider": "./src/components/slider/index.ts",
52
52
  "./spinner": "./src/components/spinner/index.ts",
53
+ "./surface": "./src/components/surface/index.ts",
53
54
  "./switch": "./src/components/switch/index.ts",
54
55
  "./tabs": "./src/components/tabs/index.ts",
55
56
  "./text": "./src/components/text/index.ts",
@@ -81,7 +82,7 @@
81
82
  },
82
83
  "peerDependencies": {
83
84
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
84
- "@delacour/react-native-charts": "0.1.0-alpha.20260925053522",
85
+ "@delacour/react-native-charts": "0.1.0-alpha.20260925055209",
85
86
  "@gorhom/bottom-sheet": "^5.2.8",
86
87
  "@legendapp/list": ">=3.3",
87
88
  "expo-linear-gradient": ">=15",
@@ -0,0 +1,72 @@
1
+ # Surface
2
+
3
+ A rounded container on one of the theme's surface fills — the plane a card, an
4
+ alert or a settings panel is drawn on. A single styled `View` with a context, so
5
+ components built on it (`Card`, `Alert`) can read the plane they sit on.
6
+
7
+ `import { Surface } from "@delacour/react-native-ui/surface";`
8
+
9
+ ## Files
10
+
11
+ | File | What it holds |
12
+ | --- | --- |
13
+ | `index.ts` | → `@delacour/react-native-ui/surface` |
14
+ | `surface.tsx` | `Surface` |
15
+ | `surface.context.tsx` | `SurfaceProvider`, `useSurface()`, `useSurfaceContext()` |
16
+ | `surface.variants.ts` | The `tv()`, `SURFACE_FOREGROUND_TOKENS`, and the two pure resolvers — no RN imports |
17
+ | `surface.variants.test.ts` | |
18
+
19
+ ## Design
20
+
21
+ - **The API is `variant`, `padding`, `className` and `children`, and it stays
22
+ that small.** `Card` and `Alert` are built on this; every prop added here is
23
+ one they inherit and have to document. Anything else a caller needs — a
24
+ margin, a tinted border, a fixed height — is a class, merged last through the
25
+ `tv()`.
26
+ - **Variants**: `default`, `secondary`, `tertiary`, `transparent`.
27
+ **Padding**: `none`, `sm`, `md`, `lg` — `p-0`, `p-3`, `p-4`, `p-6`. `md`
28
+ rather than `default` for the middle step, so one step name means "the
29
+ default step" across the library.
30
+ - **The variants are a ladder, not a palette.** `default` is `bg-card` with a
31
+ `border-border` hairline; `secondary` and `tertiary` are the fills beneath it;
32
+ `transparent` keeps the padding and corner and paints nothing. Only `default`
33
+ colours its border: in light `--card` sits a percent above `--background`, and
34
+ without the hairline a card on a page is white on near-white. Every variant
35
+ still reserves the same one-point `border`, so changing variant never moves
36
+ the content.
37
+ - **A surface that names no variant steps from the one it sits in.**
38
+ `resolveSurfaceVariant` makes a top-level surface `default`, and a nested one
39
+ `default → secondary → tertiary → secondary`. `tertiary` is *quieter* than
40
+ `secondary` — half a step back toward the page, see `theme.css` — so a strict
41
+ ascent would run out of fills at the fourth level; what the resolver
42
+ guarantees, and the tests assert, is that a surface never resolves to the fill
43
+ it sits on. An explicit `variant` always wins.
44
+ - **A transparent surface passes its parent's plane through.**
45
+ `resolveSurfacePlane` publishes the plane a surface's children sit on, and for
46
+ `transparent` that is whatever it sits on itself. Without it, a surface inside
47
+ a transparent wrapper inside a card would restart at `default` — the card's
48
+ own fill — and disappear into it.
49
+ - **The corner is `rounded-lg`, with `border-continuous`.** `rounded-lg` is the
50
+ step `--radius` names, which is the card corner — see the corner-scale note in
51
+ [the package AGENTS.md](../../../AGENTS.md). `border-continuous` is Uniwind's
52
+ utility for iOS's `borderCurve: "continuous"`, the squircle rather than a
53
+ circular arc; Android ignores it. It is registered in `TW_MERGE_CONFIG` as a
54
+ class group of its own — unregistered, tailwind-merge read it as a border
55
+ *colour* and dropped it against `border-border`.
56
+ - **`padding="none"` clips, and nothing else does.** It is the step for content
57
+ bled to the edge — an image, a chart — and that content has to take the
58
+ corner with it. Clipping at every padding would crop anything a child draws
59
+ past its own box.
60
+ - **No shadow.** Nothing in this package casts one — React Native's shadow
61
+ props disagree between platforms — so depth here is carried by fill, and the
62
+ tests assert no variant emits one. A caller who wants one writes `shadow-md`
63
+ and gets the theme's `--shadow-md`.
64
+ - **No text treatment.** The root carries no `text-*` (rule 1), and the surface
65
+ publishes no `TextClassProvider` either: `Text`'s presets set their own
66
+ colour, so the cascade would reach only a bare `Text` — and a provider marks
67
+ every `Text` beneath it as nested, which strips `Text.Code` of its chip.
68
+ `SURFACE_FOREGROUND_TOKENS` maps each fill to its `X-foreground` token for a
69
+ caller that wants it, as a class or through `useThemeColor`.
70
+ - **No role.** A surface is layout, not a landmark; it adds nothing a screen
71
+ reader could announce. `ViewProps` pass through, so a caller that does mean
72
+ one — `accessibilityRole="summary"` — sets it.
@@ -0,0 +1,15 @@
1
+ export { Surface, type SurfaceProps } from "./surface";
2
+ export { type SurfaceContextValue, SurfaceProvider, useSurface, useSurfaceContext } from "./surface.context";
3
+ export {
4
+ resolveSurfacePlane,
5
+ resolveSurfaceVariant,
6
+ SURFACE_FILLED_VARIANTS,
7
+ SURFACE_FOREGROUND_TOKENS,
8
+ SURFACE_PADDINGS,
9
+ SURFACE_VARIANTS,
10
+ type SurfacePadding,
11
+ type SurfacePlane,
12
+ type SurfaceVariant,
13
+ type SurfaceVariantProps,
14
+ surfaceVariants,
15
+ } from "./surface.variants";
@@ -0,0 +1,54 @@
1
+ import { createContext, type ReactElement, type ReactNode, use } from "react";
2
+ import type { SurfacePlane, SurfaceVariant } from "./surface.variants";
3
+
4
+ export type SurfaceContextValue = {
5
+ /** The fill the enclosing surface resolved to — explicit, or stepped from its own parent. */
6
+ variant: SurfaceVariant;
7
+ /**
8
+ * The fill content inside the enclosing surface sits on. The same as
9
+ * `variant` unless that is `transparent`, which paints nothing and passes the
10
+ * plane beneath it through — `null` when there is none.
11
+ */
12
+ plane: SurfacePlane | null;
13
+ };
14
+
15
+ const SurfaceContext = createContext<SurfaceContextValue | null>(null);
16
+
17
+ /**
18
+ * Supplies the enclosing surface's fill to its subtree.
19
+ *
20
+ * Lives in its own module, importing nothing but `surface.variants`, so a
21
+ * component built on a surface can read it without importing `../surface` and
22
+ * closing a cycle through `surface.tsx`. See AGENTS.md rule 3.
23
+ */
24
+ export function SurfaceProvider({
25
+ value,
26
+ children,
27
+ }: {
28
+ value: SurfaceContextValue;
29
+ children: ReactNode;
30
+ }): ReactElement {
31
+ return <SurfaceContext value={value}>{children}</SurfaceContext>;
32
+ }
33
+ SurfaceProvider.displayName = "DelacourUI.Surface.Provider";
34
+
35
+ /** The enclosing surface's context, or null outside a `<Surface>`. */
36
+ export function useSurfaceContext(): SurfaceContextValue | null {
37
+ return use(SurfaceContext);
38
+ }
39
+
40
+ /**
41
+ * Reads the enclosing surface's fill.
42
+ *
43
+ * Lets a custom child match the plane it sits on — pick an icon colour from
44
+ * `SURFACE_FOREGROUND_TOKENS[plane]`, or a divider that reads against it —
45
+ * without the surface passing props down. Throws outside a `<Surface>`; use
46
+ * {@link useSurfaceContext} where the enclosing surface is optional.
47
+ */
48
+ export function useSurface(): SurfaceContextValue {
49
+ const context = useSurfaceContext();
50
+ if (!context) {
51
+ throw new Error("useSurface must be called inside a <Surface>.");
52
+ }
53
+ return context;
54
+ }
@@ -0,0 +1,70 @@
1
+ import { type ReactElement, type ReactNode, useMemo } from "react";
2
+ import { View, type ViewProps } from "react-native";
3
+ import { type SurfaceContextValue, SurfaceProvider, useSurfaceContext } from "./surface.context";
4
+ import {
5
+ resolveSurfacePlane,
6
+ resolveSurfaceVariant,
7
+ type SurfacePadding,
8
+ type SurfaceVariant,
9
+ surfaceVariants,
10
+ } from "./surface.variants";
11
+
12
+ export type SurfaceProps = ViewProps & {
13
+ /**
14
+ * The fill. Omitted, a top-level surface is the `default` card and a nested
15
+ * one steps to the next fill, so it never vanishes into the surface it sits on.
16
+ */
17
+ variant?: SurfaceVariant;
18
+ /** Inner spacing. `none` also clips, for content bled to the corners. */
19
+ padding?: SurfacePadding;
20
+ className?: string;
21
+ children?: ReactNode;
22
+ };
23
+
24
+ /**
25
+ * A rounded container on one of the theme's surface fills — the plane a card,
26
+ * an alert or a settings panel is drawn on.
27
+ *
28
+ * The variants are a ladder rather than a palette. `default` is the card,
29
+ * hairlined so it holds its edge on the page; `secondary` and `tertiary` are
30
+ * the fills beneath it; `transparent` keeps the padding and corner and paints
31
+ * nothing. A surface that names no variant reads the one it sits in and steps
32
+ * to the next fill, so nesting builds depth without naming a colour.
33
+ *
34
+ * It publishes no text treatment. `Text`'s presets already carry their own
35
+ * colour, so a class cascade would reach only a bare `Text` — and
36
+ * would mark every `Text` beneath it as nested, which strips `Text.Code` of its
37
+ * chip. A caller that wants the fill's own token reads
38
+ * `SURFACE_FOREGROUND_TOKENS[useSurface().plane]`.
39
+ *
40
+ * @example
41
+ * <Surface>
42
+ * <Text.Label>Account</Text.Label>
43
+ * <Surface className="mt-3">
44
+ * <Text color="muted">Signed in as sam@example.com</Text>
45
+ * </Surface>
46
+ * </Surface>
47
+ *
48
+ * @example
49
+ * <Surface padding="none">
50
+ * <Image className="h-40 w-full" source={cover} />
51
+ * </Surface>
52
+ */
53
+ export function Surface({ variant, padding = "md", className, children, ...props }: SurfaceProps): ReactElement {
54
+ const parent = useSurfaceContext();
55
+ const parentPlane = parent?.plane ?? null;
56
+
57
+ const resolved = resolveSurfaceVariant({ parentPlane, variant });
58
+ const plane = resolveSurfacePlane({ parentPlane, variant: resolved });
59
+
60
+ const context = useMemo<SurfaceContextValue>(() => ({ plane, variant: resolved }), [plane, resolved]);
61
+
62
+ return (
63
+ <SurfaceProvider value={context}>
64
+ <View className={surfaceVariants({ padding, variant: resolved }).root({ className })} {...props}>
65
+ {children}
66
+ </View>
67
+ </SurfaceProvider>
68
+ );
69
+ }
70
+ Surface.displayName = "DelacourUI.Surface";
@@ -0,0 +1,180 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import {
5
+ resolveSurfacePlane,
6
+ resolveSurfaceVariant,
7
+ SURFACE_FILLED_VARIANTS,
8
+ SURFACE_FOREGROUND_TOKENS,
9
+ SURFACE_PADDINGS,
10
+ SURFACE_VARIANTS,
11
+ surfaceVariants,
12
+ } from "./surface.variants";
13
+
14
+ /** Every class string the variant function can produce, one per combination. */
15
+ function everyRoot(): string[] {
16
+ return SURFACE_VARIANTS.flatMap((variant) =>
17
+ SURFACE_PADDINGS.map((padding) => surfaceVariants({ padding, variant }).root())
18
+ );
19
+ }
20
+
21
+ describe("surfaceVariants root slot", () => {
22
+ test("defaults to the card surface with md padding", () => {
23
+ const cls = surfaceVariants().root();
24
+ expect(cls).toContain("bg-card");
25
+ expect(cls).toContain("border-border");
26
+ expect(cls).toContain("p-4");
27
+ });
28
+
29
+ test("maps each variant to its fill", () => {
30
+ expect(surfaceVariants({ variant: "default" }).root()).toContain("bg-card");
31
+ expect(surfaceVariants({ variant: "secondary" }).root()).toContain("bg-secondary");
32
+ expect(surfaceVariants({ variant: "tertiary" }).root()).toContain("bg-tertiary");
33
+ expect(surfaceVariants({ variant: "transparent" }).root()).toContain("bg-transparent");
34
+ });
35
+
36
+ test("gives every variant a distinct surface", () => {
37
+ const seen = new Set(SURFACE_VARIANTS.map((variant) => surfaceVariants({ variant }).root()));
38
+ expect(seen.size).toBe(SURFACE_VARIANTS.length);
39
+ });
40
+
41
+ // A card on a page is white on near-white in light. The hairline is what
42
+ // holds its edge; the filled rungs below it are separated by their fill.
43
+ test("only the default variant draws a visible border", () => {
44
+ expect(surfaceVariants({ variant: "default" }).root()).toContain("border-border");
45
+ for (const variant of SURFACE_VARIANTS.filter((name) => name !== "default")) {
46
+ expect(surfaceVariants({ variant }).root()).not.toContain("border-border");
47
+ }
48
+ });
49
+
50
+ // Every variant carries the same one-point border box, so switching variant
51
+ // never moves the content by a pixel.
52
+ test("every variant reserves the same border width", () => {
53
+ for (const cls of everyRoot()) {
54
+ expect(cls).toMatch(/(^|\s)border(\s|$)/);
55
+ }
56
+ });
57
+
58
+ test("is card-shaped, with a continuous corner, at every variant and padding", () => {
59
+ for (const cls of everyRoot()) {
60
+ expect(cls).toContain("rounded-lg");
61
+ expect(cls).toContain("border-continuous");
62
+ }
63
+ });
64
+
65
+ test("maps each padding to its step", () => {
66
+ expect(surfaceVariants({ padding: "none" }).root()).toContain("p-0");
67
+ expect(surfaceVariants({ padding: "sm" }).root()).toContain("p-3");
68
+ expect(surfaceVariants({ padding: "md" }).root()).toContain("p-4");
69
+ expect(surfaceVariants({ padding: "lg" }).root()).toContain("p-6");
70
+ });
71
+
72
+ // `none` is for content that bleeds to the edge — an image, a chart — and
73
+ // that content has to take the corner with it.
74
+ test("clips only when its content touches the edge", () => {
75
+ expect(surfaceVariants({ padding: "none" }).root()).toContain("overflow-hidden");
76
+ for (const padding of SURFACE_PADDINGS.filter((name) => name !== "none")) {
77
+ expect(surfaceVariants({ padding }).root()).not.toContain("overflow-hidden");
78
+ }
79
+ });
80
+
81
+ // Rule 1: a React Native View does not cascade colour to a Text descendant.
82
+ test("carries no text treatment on the root", () => {
83
+ for (const cls of everyRoot()) {
84
+ expect(cls).not.toMatch(/\btext-/);
85
+ }
86
+ });
87
+
88
+ test("draws no shadow anywhere", () => {
89
+ for (const cls of everyRoot()) {
90
+ expect(cls).not.toMatch(/shadow/);
91
+ }
92
+ });
93
+
94
+ test("merges an incoming className last", () => {
95
+ expect(surfaceVariants().root({ className: "mt-3" })).toContain("mt-3");
96
+ expect(surfaceVariants().root({ className: "bg-popover" })).not.toContain("bg-card");
97
+ expect(surfaceVariants().root({ className: "p-8" })).not.toMatch(/\bp-4\b/);
98
+ });
99
+
100
+ // `border-continuous` is Uniwind's, and a merger that read it as a colour
101
+ // would drop it the moment a caller tinted the border.
102
+ test("keeps its corner curve when a caller recolours the border", () => {
103
+ expect(surfaceVariants().root({ className: "border-destructive" })).toContain("border-continuous");
104
+ });
105
+ });
106
+
107
+ describe("SURFACE_FOREGROUND_TOKENS", () => {
108
+ test("names the X-foreground token for each fill", () => {
109
+ expect(SURFACE_FOREGROUND_TOKENS).toEqual({
110
+ default: "card-foreground",
111
+ secondary: "secondary-foreground",
112
+ tertiary: "tertiary-foreground",
113
+ });
114
+ });
115
+
116
+ // Every token named here has to exist, or the class compiles to nothing and
117
+ // the text keeps whatever colour it inherited.
118
+ test("every token is declared in theme.css", () => {
119
+ const css = readFileSync(join(import.meta.dir, "../../styles/theme.css"), "utf8");
120
+ for (const token of Object.values(SURFACE_FOREGROUND_TOKENS)) {
121
+ expect(css).toContain(`--color-${token}: var(--${token})`);
122
+ }
123
+ });
124
+ });
125
+
126
+ describe("resolveSurfaceVariant", () => {
127
+ test("an explicit variant always wins", () => {
128
+ for (const variant of SURFACE_VARIANTS) {
129
+ expect(resolveSurfaceVariant({ parentPlane: null, variant })).toBe(variant);
130
+ expect(resolveSurfaceVariant({ parentPlane: "secondary", variant })).toBe(variant);
131
+ }
132
+ });
133
+
134
+ test("a top-level surface is the default card", () => {
135
+ expect(resolveSurfaceVariant({ parentPlane: null })).toBe("default");
136
+ });
137
+
138
+ test("a nested surface steps to the next fill", () => {
139
+ expect(resolveSurfaceVariant({ parentPlane: "default" })).toBe("secondary");
140
+ expect(resolveSurfaceVariant({ parentPlane: "secondary" })).toBe("tertiary");
141
+ expect(resolveSurfaceVariant({ parentPlane: "tertiary" })).toBe("secondary");
142
+ });
143
+
144
+ // The point of the ladder: whatever depth it is nested at, a surface never
145
+ // resolves to the fill it is sitting on, or it would vanish into it.
146
+ test("never resolves to the fill of the plane it sits on", () => {
147
+ for (const parentPlane of SURFACE_FILLED_VARIANTS) {
148
+ expect(resolveSurfaceVariant({ parentPlane })).not.toBe(parentPlane);
149
+ }
150
+ });
151
+
152
+ test("never resolves to transparent on its own", () => {
153
+ for (const parentPlane of [null, ...SURFACE_FILLED_VARIANTS]) {
154
+ expect(resolveSurfaceVariant({ parentPlane })).not.toBe("transparent");
155
+ }
156
+ });
157
+ });
158
+
159
+ describe("resolveSurfacePlane", () => {
160
+ test("a filled surface is the plane its children sit on", () => {
161
+ for (const variant of SURFACE_FILLED_VARIANTS) {
162
+ expect(resolveSurfacePlane({ parentPlane: null, variant })).toBe(variant);
163
+ expect(resolveSurfacePlane({ parentPlane: "tertiary", variant })).toBe(variant);
164
+ }
165
+ });
166
+
167
+ // A transparent surface paints nothing, so what its children sit on is
168
+ // still whatever it sits on.
169
+ test("a transparent surface passes its parent's plane through", () => {
170
+ expect(resolveSurfacePlane({ parentPlane: null, variant: "transparent" })).toBeNull();
171
+ for (const parentPlane of SURFACE_FILLED_VARIANTS) {
172
+ expect(resolveSurfacePlane({ parentPlane, variant: "transparent" })).toBe(parentPlane);
173
+ }
174
+ });
175
+
176
+ test("a surface inside a transparent one steps from the plane beneath both", () => {
177
+ const through = resolveSurfacePlane({ parentPlane: "default", variant: "transparent" });
178
+ expect(resolveSurfaceVariant({ parentPlane: through })).toBe("secondary");
179
+ });
180
+ });
@@ -0,0 +1,133 @@
1
+ import type { VariantProps } from "tailwind-variants";
2
+ import { tv } from "../../lib/tv";
3
+
4
+ export const SURFACE_VARIANTS = ["default", "secondary", "tertiary", "transparent"] as const;
5
+
6
+ export const SURFACE_PADDINGS = ["none", "sm", "md", "lg"] as const;
7
+
8
+ export type SurfaceVariant = (typeof SURFACE_VARIANTS)[number];
9
+ export type SurfacePadding = (typeof SURFACE_PADDINGS)[number];
10
+
11
+ /** The variants that paint a fill — every one but `transparent`. */
12
+ export const SURFACE_FILLED_VARIANTS = ["default", "secondary", "tertiary"] as const;
13
+
14
+ /**
15
+ * A fill something can sit on. `transparent` is not one: it paints nothing, so
16
+ * whatever is inside it still sits on the plane beneath.
17
+ */
18
+ export type SurfacePlane = (typeof SURFACE_FILLED_VARIANTS)[number];
19
+
20
+ /**
21
+ * Theme token for content drawn on each fill — `X-foreground` on an `X`
22
+ * surface, per the package's token rule. A class is `text-${token}`; a value,
23
+ * for an icon or a gradient stop, is `useThemeColor(token)`.
24
+ */
25
+ export const SURFACE_FOREGROUND_TOKENS = {
26
+ default: "card-foreground",
27
+ secondary: "secondary-foreground",
28
+ tertiary: "tertiary-foreground",
29
+ } as const satisfies Record<SurfacePlane, string>;
30
+
31
+ /**
32
+ * The fill a nested surface takes when it names none, keyed by the plane it
33
+ * sits on.
34
+ *
35
+ * `tertiary` is quieter than `secondary` — half a step back toward the page —
36
+ * so a third level returns to `secondary` rather than stopping. What matters is
37
+ * that each surface differs from its immediate parent; a strictly ascending
38
+ * ladder would run out of fills at the fourth level and start vanishing into
39
+ * its own parent.
40
+ */
41
+ const NEXT_PLANE = {
42
+ default: "secondary",
43
+ secondary: "tertiary",
44
+ tertiary: "secondary",
45
+ } as const satisfies Record<SurfacePlane, SurfacePlane>;
46
+
47
+ /**
48
+ * Styling for a surface.
49
+ *
50
+ * The root is card-shaped — `rounded-lg`, the corner `--radius` names, see the
51
+ * corner-scale note in the package AGENTS.md — with `border-continuous`, which
52
+ * gives iOS's continuous corner rather than a circular arc. Android ignores it.
53
+ *
54
+ * Every variant reserves the same one-point `border`, transparent unless the
55
+ * variant colours it, so changing variant never moves the content. Only
56
+ * `default` colours it: `--card` sits a percent above `--background` in light,
57
+ * and without the hairline a card on a page is white on near-white. The filled
58
+ * rungs below it are told apart by their fill.
59
+ *
60
+ * `padding: "none"` clips, and nothing else does. It is the one step whose
61
+ * content touches the edge — an image or a chart bled to the corners — and that
62
+ * content has to take the corner with it. Clipping everywhere would crop
63
+ * anything a child draws past its own box.
64
+ *
65
+ * No shadow, on purpose. Nothing in this package casts one — React Native's
66
+ * shadow props disagree between platforms — so depth here is carried by fill.
67
+ *
68
+ * The root carries no `text-*`: a React Native `View` does not cascade colour
69
+ * to a `Text` descendant, so a class here would reach nothing.
70
+ *
71
+ * Free of React Native imports so it stays unit-testable — `bun test` cannot
72
+ * parse React Native's Flow-typed source. See AGENTS.md.
73
+ */
74
+ export const surfaceVariants = tv({
75
+ slots: {
76
+ root: "rounded-lg border border-continuous border-transparent",
77
+ },
78
+ variants: {
79
+ variant: {
80
+ default: { root: "border-border bg-card" },
81
+ secondary: { root: "bg-secondary" },
82
+ tertiary: { root: "bg-tertiary" },
83
+ transparent: { root: "bg-transparent" },
84
+ },
85
+ padding: {
86
+ none: { root: "overflow-hidden p-0" },
87
+ sm: { root: "p-3" },
88
+ md: { root: "p-4" },
89
+ lg: { root: "p-6" },
90
+ },
91
+ },
92
+ defaultVariants: {
93
+ variant: "default",
94
+ padding: "md",
95
+ },
96
+ });
97
+
98
+ export type SurfaceVariantProps = VariantProps<typeof surfaceVariants>;
99
+
100
+ /**
101
+ * The fill a surface draws.
102
+ *
103
+ * An explicit `variant` always wins. Without one, a surface at the top of the
104
+ * tree is the `default` card, and a surface nested in another steps to the next
105
+ * fill, so a panel inside a card is told apart from the card with nothing said
106
+ * at the call site — and a `Card` built on this gets the same for free.
107
+ */
108
+ export function resolveSurfaceVariant({
109
+ parentPlane,
110
+ variant,
111
+ }: {
112
+ parentPlane: SurfacePlane | null;
113
+ variant?: SurfaceVariant;
114
+ }): SurfaceVariant {
115
+ if (variant) {
116
+ return variant;
117
+ }
118
+ return parentPlane ? NEXT_PLANE[parentPlane] : "default";
119
+ }
120
+
121
+ /**
122
+ * The plane a surface's children sit on: its own fill, or — for a transparent
123
+ * surface, which paints none — the plane it sits on itself.
124
+ */
125
+ export function resolveSurfacePlane({
126
+ parentPlane,
127
+ variant,
128
+ }: {
129
+ parentPlane: SurfacePlane | null;
130
+ variant: SurfaceVariant;
131
+ }): SurfacePlane | null {
132
+ return variant === "transparent" ? parentPlane : variant;
133
+ }
@@ -134,3 +134,17 @@ describe("cn with the semantic size tokens", () => {
134
134
  expect(cn("border-input", "text-input-md")).toBe("border-input text-input-md");
135
135
  });
136
136
  });
137
+
138
+ describe("cn with Uniwind's corner-curve utilities", () => {
139
+ // `border-continuous` is a Uniwind utility, not a Tailwind one, and a bare
140
+ // tailwind-merge files it under border *colour* — so it and `border-border`
141
+ // were judged to conflict and one of them was silently dropped.
142
+ test("a corner curve and a border colour both survive", () => {
143
+ expect(cn("border-continuous", "border-border")).toBe("border-continuous border-border");
144
+ expect(cn("border-border", "border-continuous")).toBe("border-border border-continuous");
145
+ });
146
+
147
+ test("one corner curve replaces the other", () => {
148
+ expect(cn("border-continuous", "border-circular")).toBe("border-circular");
149
+ });
150
+ });
package/src/lib/cn.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type ClassValue, clsx } from "clsx";
2
2
  import { extendTailwindMerge } from "tailwind-merge";
3
- import { TW_MERGE_CONFIG } from "../styles/tokens";
3
+ import { type CustomClassGroupId, TW_MERGE_CONFIG } from "../styles/tokens";
4
4
 
5
5
  /**
6
6
  * tailwind-merge, taught the semantic size tokens from `tokens.css`.
@@ -15,7 +15,7 @@ import { TW_MERGE_CONFIG } from "../styles/tokens";
15
15
  *
16
16
  * `tv()` needs the same treatment for its own merger — see `lib/tv.ts`.
17
17
  */
18
- const twMerge = extendTailwindMerge(TW_MERGE_CONFIG);
18
+ const twMerge = extendTailwindMerge<CustomClassGroupId>(TW_MERGE_CONFIG);
19
19
 
20
20
  /**
21
21
  * Merges class names and resolves Tailwind conflicts so the last utility wins.
@@ -68,9 +68,16 @@ export const CHART_SIZE_TOKENS = ["chart-sm", "chart-md", "chart-lg"] as const;
68
68
  * `text-button-md` as an unrecognised utility — which is how a size token ends
69
69
  * up colliding with a colour and silently dropping it. One config, read by
70
70
  * `lib/cn.ts` and `lib/tv.ts`, so they cannot drift apart.
71
+ *
72
+ * `border-curve` is Uniwind's, not Tailwind's: `border-continuous` sets iOS's
73
+ * `borderCurve`. Unregistered, tailwind-merge reads it as a border *colour*,
74
+ * and `border-continuous border-border` loses one of the two.
71
75
  */
72
76
  export const TW_MERGE_CONFIG = {
73
77
  extend: {
78
+ classGroups: {
79
+ "border-curve": ["border-continuous", "border-circular"],
80
+ },
74
81
  theme: {
75
82
  radius: [...BUTTON_RADIUS_TOKENS],
76
83
  spacing: [
@@ -84,3 +91,6 @@ export const TW_MERGE_CONFIG = {
84
91
  },
85
92
  },
86
93
  } as const;
94
+
95
+ /** Class groups `TW_MERGE_CONFIG` adds, which tailwind-merge's extension has to be told about by name. */
96
+ export type CustomClassGroupId = keyof typeof TW_MERGE_CONFIG.extend.classGroups;