@delacour/react-native-ui 0.1.0-alpha.20260925060916 → 0.1.0-alpha.20260925062055
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 +4 -2
- package/src/components/empty-state/AGENTS.md +90 -0
- package/src/components/empty-state/empty-state-content.tsx +17 -0
- package/src/components/empty-state/empty-state-description.tsx +12 -0
- package/src/components/empty-state/empty-state-header.tsx +17 -0
- package/src/components/empty-state/empty-state-media.tsx +56 -0
- package/src/components/empty-state/empty-state-title.tsx +18 -0
- package/src/components/empty-state/empty-state.context.tsx +65 -0
- package/src/components/empty-state/empty-state.tsx +84 -0
- package/src/components/empty-state/empty-state.types.ts +14 -0
- package/src/components/empty-state/empty-state.variants.test.ts +245 -0
- package/src/components/empty-state/empty-state.variants.ts +132 -0
- package/src/components/empty-state/index.ts +20 -0
- package/src/components/textarea/AGENTS.md +86 -0
- package/src/components/textarea/index.ts +16 -0
- package/src/components/textarea/textarea.tsx +157 -0
- package/src/components/textarea/textarea.variants.test.ts +219 -0
- package/src/components/textarea/textarea.variants.ts +171 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.20260925062055",
|
|
4
4
|
"description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"./chart": "./src/components/chart/index.ts",
|
|
41
41
|
"./checkbox": "./src/components/checkbox/index.ts",
|
|
42
42
|
"./chip": "./src/components/chip/index.ts",
|
|
43
|
+
"./empty-state": "./src/components/empty-state/index.ts",
|
|
43
44
|
"./field": "./src/components/field/index.ts",
|
|
44
45
|
"./icon": "./src/components/icon/index.ts",
|
|
45
46
|
"./input": "./src/components/input/index.ts",
|
|
@@ -58,6 +59,7 @@
|
|
|
58
59
|
"./switch": "./src/components/switch/index.ts",
|
|
59
60
|
"./tabs": "./src/components/tabs/index.ts",
|
|
60
61
|
"./text": "./src/components/text/index.ts",
|
|
62
|
+
"./textarea": "./src/components/textarea/index.ts",
|
|
61
63
|
"./toggle-button": "./src/components/toggle-button/index.ts",
|
|
62
64
|
"./expo/navigation-theme": "./src/expo/navigation-theme.tsx",
|
|
63
65
|
"./hooks/use-controllable-state": "./src/hooks/use-controllable-state.ts",
|
|
@@ -87,7 +89,7 @@
|
|
|
87
89
|
},
|
|
88
90
|
"peerDependencies": {
|
|
89
91
|
"@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
|
|
90
|
-
"@delacour/react-native-charts": "0.1.0-alpha.
|
|
92
|
+
"@delacour/react-native-charts": "0.1.0-alpha.20260925062055",
|
|
91
93
|
"@gorhom/bottom-sheet": "^5.2.8",
|
|
92
94
|
"@legendapp/list": ">=3.3",
|
|
93
95
|
"expo-linear-gradient": ">=15",
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# EmptyState
|
|
2
|
+
|
|
3
|
+
A placeholder for a list or a screen with nothing in it yet. Compound root plus
|
|
4
|
+
five parts: `Header`, `Media`, `Title`, `Description`, `Content`.
|
|
5
|
+
|
|
6
|
+
`import { EmptyState } from "@delacour/react-native-ui/empty-state";`
|
|
7
|
+
|
|
8
|
+
## Files
|
|
9
|
+
|
|
10
|
+
| File | What it holds |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| `index.ts` | → `@delacour/react-native-ui/empty-state` |
|
|
13
|
+
| `empty-state.tsx` | Root + the `Object.assign` compound surface |
|
|
14
|
+
| `empty-state-header.tsx` | `EmptyState.Header` |
|
|
15
|
+
| `empty-state-media.tsx` | `EmptyState.Media`, and the icon cascade it owns |
|
|
16
|
+
| `empty-state-title.tsx` | `EmptyState.Title` |
|
|
17
|
+
| `empty-state-description.tsx` | `EmptyState.Description` |
|
|
18
|
+
| `empty-state-content.tsx` | `EmptyState.Content` |
|
|
19
|
+
| `empty-state.context.tsx` | `EmptyStateProvider`, `useEmptyState()`, `useEmptyStateContext()`, `useEmptyStatePart()` |
|
|
20
|
+
| `empty-state.types.ts` | Prop types shared by two or more parts |
|
|
21
|
+
| `empty-state.variants.ts` | Pure `tv()` slots and the media colour map, no RN imports |
|
|
22
|
+
| `empty-state.variants.test.ts` | |
|
|
23
|
+
|
|
24
|
+
## Anatomy
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
<EmptyState>
|
|
28
|
+
<EmptyState.Header>
|
|
29
|
+
<EmptyState.Media variant="icon">
|
|
30
|
+
<Icon icon={IconInbox} />
|
|
31
|
+
</EmptyState.Media>
|
|
32
|
+
<EmptyState.Title>No messages</EmptyState.Title>
|
|
33
|
+
<EmptyState.Description>New conversations will show up here.</EmptyState.Description>
|
|
34
|
+
</EmptyState.Header>
|
|
35
|
+
<EmptyState.Content>
|
|
36
|
+
<Button onPress={compose}>New message</Button>
|
|
37
|
+
</EmptyState.Content>
|
|
38
|
+
</EmptyState>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Design
|
|
42
|
+
|
|
43
|
+
- **Variants**: `default`, `card`. **Sizes**: `sm`, `md`, `lg`. **Media
|
|
44
|
+
variants**: `default`, `icon`. Size drives the padding, both gaps, the media
|
|
45
|
+
box, the glyph inside it and both type scales — one axis rather than seven
|
|
46
|
+
numbers that drift apart. The tests assert every one of them ascends.
|
|
47
|
+
- **`default` grows; it never uses `flex-1`.** `flex-1` is a zero flex basis, so
|
|
48
|
+
inside a `ScrollView`'s content container, which has no height to grow into,
|
|
49
|
+
the block collapsed to nothing. `grow` keeps the content height as a floor and
|
|
50
|
+
fills whatever spare height a bounded parent has — which is what "fills its
|
|
51
|
+
container" has to mean in both places. A test holds the class.
|
|
52
|
+
- **`card` is dashed.** A dashed outline is the conventional mark of a slot
|
|
53
|
+
waiting for content, and it stops an embedded empty state reading as one
|
|
54
|
+
more populated card beside real ones. The corner is the card step,
|
|
55
|
+
`rounded-lg`, stepping to `rounded-md` at `sm` like `ListGroup` and
|
|
56
|
+
`Accordion`. The border is reserved on both variants (`border-transparent` on
|
|
57
|
+
`default`), so switching variant changes a colour and never the layout.
|
|
58
|
+
- **A size is padding, never a height.** The description respects OS font
|
|
59
|
+
scaling; a fixed height would clip it at a large accessibility step.
|
|
60
|
+
- **Icons are composed, never passed as props.** `Media` wraps its subtree in an
|
|
61
|
+
`IconDefaultsProvider` carrying the `mediaIcon` slot — a step on the shared
|
|
62
|
+
`--spacing-icon-*` scale — and `EMPTY_STATE_MEDIA_FOREGROUND_TOKEN[variant]`.
|
|
63
|
+
A bare glyph is `muted-foreground`, because the picture is decoration and must
|
|
64
|
+
not outweigh the title. Inside the tinted `icon` box it takes `foreground`:
|
|
65
|
+
`muted-foreground` on `bg-muted` is two greys a step apart.
|
|
66
|
+
- **The glyph uses the same three steps inside the box and out of it.** The
|
|
67
|
+
icon scale tops out at `icon-2xl`, so a bare glyph one step larger than the
|
|
68
|
+
boxed one would have left `md` and `lg` identical.
|
|
69
|
+
- **The media sits further from the title than the title from its
|
|
70
|
+
description.** The header's `gap` spaces the two lines; the media adds a
|
|
71
|
+
bottom margin on top of it, so text reads as one unit and the picture as
|
|
72
|
+
something above it.
|
|
73
|
+
- **`Media` is hidden from assistive technology by default.** The title already
|
|
74
|
+
says what the picture shows, and a screen reader saying "image" first only
|
|
75
|
+
delays it. Media that carries meaning of its own opts back in with
|
|
76
|
+
`accessibilityElementsHidden={false}` and `importantForAccessibility="auto"` —
|
|
77
|
+
both are spread after the defaults.
|
|
78
|
+
- **`Title` is announced as a header.** An empty screen's title is what the
|
|
79
|
+
screen *is*, and the heading rotor should land on it.
|
|
80
|
+
- **Actions are a wrapping row, not a column.** Two actions sit side by side and
|
|
81
|
+
fall to a second line only when they must. `className="flex-col"` stacks them.
|
|
82
|
+
Button size is the caller's choice — `Content` sets nothing on its children, so
|
|
83
|
+
a `Button` keeps every prop it already has.
|
|
84
|
+
- **Header and content cap at `max-w-sm`.** On a tablet or in landscape a
|
|
85
|
+
description stretched edge to edge is a line too long to read.
|
|
86
|
+
- **Colour goes on the text parts.** No `View` slot carries a `text-*` utility;
|
|
87
|
+
a React Native `View` cannot cascade colour to a `Text`. The tests assert it.
|
|
88
|
+
- **No state of its own.** An empty state is a presentation of *someone else's*
|
|
89
|
+
state — a list's length, a query's result. Loading and disabled belong to the
|
|
90
|
+
`Button`s inside it, which already have them.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { useEmptyStatePart } from "./empty-state.context";
|
|
4
|
+
import type { EmptyStateSlotProps } from "./empty-state.types";
|
|
5
|
+
import { emptyStateVariants } from "./empty-state.variants";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The action slot under the header — usually one or two `Button`s.
|
|
9
|
+
*
|
|
10
|
+
* A centred row that wraps, so two actions sit side by side and fall onto a
|
|
11
|
+
* second line only when they have to. Pass `className="flex-col"` to stack them.
|
|
12
|
+
*/
|
|
13
|
+
export function EmptyStateContent({ className, ...props }: EmptyStateSlotProps): ReactElement {
|
|
14
|
+
const { size } = useEmptyStatePart("EmptyState.Content");
|
|
15
|
+
return <View className={emptyStateVariants({ size }).content({ className })} {...props} />;
|
|
16
|
+
}
|
|
17
|
+
EmptyStateContent.displayName = "DelacourUI.EmptyState.Content";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { Text } from "../text";
|
|
3
|
+
import { useEmptyStatePart } from "./empty-state.context";
|
|
4
|
+
import type { EmptyStateTextProps } from "./empty-state.types";
|
|
5
|
+
import { emptyStateVariants } from "./empty-state.variants";
|
|
6
|
+
|
|
7
|
+
/** The supporting line under the title — a step down in scale, on the muted token. */
|
|
8
|
+
export function EmptyStateDescription({ className, ...props }: EmptyStateTextProps): ReactElement {
|
|
9
|
+
const { size } = useEmptyStatePart("EmptyState.Description");
|
|
10
|
+
return <Text className={emptyStateVariants({ size }).description({ className })} {...props} />;
|
|
11
|
+
}
|
|
12
|
+
EmptyStateDescription.displayName = "DelacourUI.EmptyState.Description";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { useEmptyStatePart } from "./empty-state.context";
|
|
4
|
+
import type { EmptyStateSlotProps } from "./empty-state.types";
|
|
5
|
+
import { emptyStateVariants } from "./empty-state.variants";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The centred column holding the media, the title and the description.
|
|
9
|
+
*
|
|
10
|
+
* Its own gap spaces the title from the description; the media adds a margin
|
|
11
|
+
* of its own on top, so the picture sits apart from the two lines of text.
|
|
12
|
+
*/
|
|
13
|
+
export function EmptyStateHeader({ className, ...props }: EmptyStateSlotProps): ReactElement {
|
|
14
|
+
const { size } = useEmptyStatePart("EmptyState.Header");
|
|
15
|
+
return <View className={emptyStateVariants({ size }).header({ className })} {...props} />;
|
|
16
|
+
}
|
|
17
|
+
EmptyStateHeader.displayName = "DelacourUI.EmptyState.Header";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ReactElement, useMemo } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import { IconDefaultsProvider } from "../icon";
|
|
4
|
+
import { useEmptyStatePart } from "./empty-state.context";
|
|
5
|
+
import type { EmptyStateSlotProps } from "./empty-state.types";
|
|
6
|
+
import {
|
|
7
|
+
EMPTY_STATE_MEDIA_FOREGROUND_TOKEN,
|
|
8
|
+
type EmptyStateMediaVariant,
|
|
9
|
+
emptyStateVariants,
|
|
10
|
+
} from "./empty-state.variants";
|
|
11
|
+
|
|
12
|
+
export type EmptyStateMediaProps = EmptyStateSlotProps & {
|
|
13
|
+
/**
|
|
14
|
+
* `icon` draws a tinted, rounded box sized for a glyph. `default` draws
|
|
15
|
+
* nothing behind its content, for an illustration or an image that sizes
|
|
16
|
+
* itself.
|
|
17
|
+
*/
|
|
18
|
+
variant?: EmptyStateMediaVariant;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The picture above the title.
|
|
23
|
+
*
|
|
24
|
+
* Its subtree inherits an icon size on the shared scale and a colour token, so a
|
|
25
|
+
* bare `<Icon icon={IconInbox} />` comes out right with nothing said at the call
|
|
26
|
+
* site — the same cascade a `Button` gives its icons.
|
|
27
|
+
*
|
|
28
|
+
* Hidden from assistive technology by default: the title already says what the
|
|
29
|
+
* picture shows, and a screen reader announcing "image" first only delays it.
|
|
30
|
+
* Pass `accessibilityElementsHidden={false}` and
|
|
31
|
+
* `importantForAccessibility="auto"` for media that carries meaning of its own.
|
|
32
|
+
*/
|
|
33
|
+
export function EmptyStateMedia({
|
|
34
|
+
variant = "default",
|
|
35
|
+
className,
|
|
36
|
+
children,
|
|
37
|
+
...props
|
|
38
|
+
}: EmptyStateMediaProps): ReactElement {
|
|
39
|
+
const { size } = useEmptyStatePart("EmptyState.Media");
|
|
40
|
+
const slots = emptyStateVariants({ size, media: variant });
|
|
41
|
+
const iconClassName = slots.mediaIcon();
|
|
42
|
+
const color = EMPTY_STATE_MEDIA_FOREGROUND_TOKEN[variant];
|
|
43
|
+
const iconDefaults = useMemo(() => ({ className: iconClassName, color }), [iconClassName, color]);
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<View
|
|
47
|
+
accessibilityElementsHidden
|
|
48
|
+
className={slots.media({ className })}
|
|
49
|
+
importantForAccessibility="no-hide-descendants"
|
|
50
|
+
{...props}
|
|
51
|
+
>
|
|
52
|
+
<IconDefaultsProvider value={iconDefaults}>{children}</IconDefaultsProvider>
|
|
53
|
+
</View>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
EmptyStateMedia.displayName = "DelacourUI.EmptyState.Media";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { Text } from "../text";
|
|
3
|
+
import { useEmptyStatePart } from "./empty-state.context";
|
|
4
|
+
import type { EmptyStateTextProps } from "./empty-state.types";
|
|
5
|
+
import { emptyStateVariants } from "./empty-state.variants";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The empty state's heading.
|
|
9
|
+
*
|
|
10
|
+
* Announced as a header, so a screen reader's heading rotor lands on it — the
|
|
11
|
+
* title is what an empty screen *is*. Carries its own colour and type scale
|
|
12
|
+
* from context: a React Native `View` does not cascade colour to a `Text`.
|
|
13
|
+
*/
|
|
14
|
+
export function EmptyStateTitle({ className, ...props }: EmptyStateTextProps): ReactElement {
|
|
15
|
+
const { size } = useEmptyStatePart("EmptyState.Title");
|
|
16
|
+
return <Text accessibilityRole="header" className={emptyStateVariants({ size }).title({ className })} {...props} />;
|
|
17
|
+
}
|
|
18
|
+
EmptyStateTitle.displayName = "DelacourUI.EmptyState.Title";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createContext, type ReactElement, type ReactNode, use } from "react";
|
|
2
|
+
import type { EmptyStateSize, EmptyStateVariant } from "./empty-state.variants";
|
|
3
|
+
|
|
4
|
+
export type EmptyStateContextValue = {
|
|
5
|
+
/** Size of the empty state. */
|
|
6
|
+
size: EmptyStateSize;
|
|
7
|
+
/** How the empty state sits on the screen. */
|
|
8
|
+
variant: EmptyStateVariant;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const EmptyStateContext = createContext<EmptyStateContextValue | null>(null);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Supplies the enclosing empty state's size and variant to its subtree.
|
|
15
|
+
*
|
|
16
|
+
* Lives in its own module, importing nothing but `empty-state.variants`, so a
|
|
17
|
+
* part can read it without importing `./empty-state` and closing a cycle
|
|
18
|
+
* through the root. See the package AGENTS.md, rule 3.
|
|
19
|
+
*/
|
|
20
|
+
export function EmptyStateProvider({
|
|
21
|
+
value,
|
|
22
|
+
children,
|
|
23
|
+
}: {
|
|
24
|
+
value: EmptyStateContextValue;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}): ReactElement {
|
|
27
|
+
return <EmptyStateContext value={value}>{children}</EmptyStateContext>;
|
|
28
|
+
}
|
|
29
|
+
EmptyStateProvider.displayName = "DelacourUI.EmptyState.Provider";
|
|
30
|
+
|
|
31
|
+
/** The enclosing empty state's context, or null outside an `<EmptyState>`. */
|
|
32
|
+
export function useEmptyStateContext(): EmptyStateContextValue | null {
|
|
33
|
+
return use(EmptyStateContext);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reads the enclosing empty state's size and variant.
|
|
38
|
+
*
|
|
39
|
+
* Lets a custom part — an illustration, a link row — scale with the block
|
|
40
|
+
* without the root passing props down. Throws outside an `<EmptyState>`; use
|
|
41
|
+
* {@link useEmptyStateContext} where the enclosing empty state is optional.
|
|
42
|
+
*/
|
|
43
|
+
export function useEmptyState(): EmptyStateContextValue {
|
|
44
|
+
const context = useEmptyStateContext();
|
|
45
|
+
if (!context) {
|
|
46
|
+
throw new Error("useEmptyState must be called inside an <EmptyState>.");
|
|
47
|
+
}
|
|
48
|
+
return context;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The enclosing empty state's context, for a compound part that cannot work
|
|
53
|
+
* without one.
|
|
54
|
+
*
|
|
55
|
+
* Internal: deliberately not re-exported from `index.ts`. A caller outside the
|
|
56
|
+
* library wants {@link useEmptyState}, whose error names the hook rather than a
|
|
57
|
+
* part.
|
|
58
|
+
*/
|
|
59
|
+
export function useEmptyStatePart(component: string): EmptyStateContextValue {
|
|
60
|
+
const context = useEmptyStateContext();
|
|
61
|
+
if (!context) {
|
|
62
|
+
throw new Error(`${component} must be rendered inside an <EmptyState>.`);
|
|
63
|
+
}
|
|
64
|
+
return context;
|
|
65
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode, useMemo } from "react";
|
|
2
|
+
import { View, type ViewProps } from "react-native";
|
|
3
|
+
import { type EmptyStateContextValue, EmptyStateProvider } from "./empty-state.context";
|
|
4
|
+
import { type EmptyStateSize, type EmptyStateVariant, emptyStateVariants } from "./empty-state.variants";
|
|
5
|
+
import { EmptyStateContent } from "./empty-state-content";
|
|
6
|
+
import { EmptyStateDescription } from "./empty-state-description";
|
|
7
|
+
import { EmptyStateHeader } from "./empty-state-header";
|
|
8
|
+
import { EmptyStateMedia } from "./empty-state-media";
|
|
9
|
+
import { EmptyStateTitle } from "./empty-state-title";
|
|
10
|
+
|
|
11
|
+
export type EmptyStateProps = ViewProps & {
|
|
12
|
+
/** `default` grows into its parent; `card` is a self-contained dashed block. */
|
|
13
|
+
variant?: EmptyStateVariant;
|
|
14
|
+
/** Drives the padding, both gaps, the media, the glyph and both type scales. */
|
|
15
|
+
size?: EmptyStateSize;
|
|
16
|
+
className?: string;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function EmptyStateRoot({
|
|
21
|
+
variant = "default",
|
|
22
|
+
size = "md",
|
|
23
|
+
className,
|
|
24
|
+
children,
|
|
25
|
+
...props
|
|
26
|
+
}: EmptyStateProps): ReactElement {
|
|
27
|
+
const context = useMemo<EmptyStateContextValue>(() => ({ size, variant }), [size, variant]);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<EmptyStateProvider value={context}>
|
|
31
|
+
<View className={emptyStateVariants({ size, variant }).root({ className })} {...props}>
|
|
32
|
+
{children}
|
|
33
|
+
</View>
|
|
34
|
+
</EmptyStateProvider>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A placeholder for a list or a screen with nothing in it yet: a picture, a
|
|
40
|
+
* title, a line of explanation, and the action that fixes it.
|
|
41
|
+
*
|
|
42
|
+
* `size` and `variant` reach the parts through context, so the title picks its
|
|
43
|
+
* own type scale and a bare `Icon` in `EmptyState.Media` its own size and
|
|
44
|
+
* colour. Actions are composed — put a `Button` in `EmptyState.Content`.
|
|
45
|
+
*
|
|
46
|
+
* `default` grows to fill a bounded parent and centres itself there, without
|
|
47
|
+
* collapsing inside a `ScrollView`. `card` is a dashed block for an empty
|
|
48
|
+
* section sitting beside populated ones.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* <EmptyState>
|
|
52
|
+
* <EmptyState.Header>
|
|
53
|
+
* <EmptyState.Media variant="icon">
|
|
54
|
+
* <Icon icon={IconInbox} />
|
|
55
|
+
* </EmptyState.Media>
|
|
56
|
+
* <EmptyState.Title>No messages</EmptyState.Title>
|
|
57
|
+
* <EmptyState.Description>New conversations will show up here.</EmptyState.Description>
|
|
58
|
+
* </EmptyState.Header>
|
|
59
|
+
* <EmptyState.Content>
|
|
60
|
+
* <Button onPress={compose}>New message</Button>
|
|
61
|
+
* </EmptyState.Content>
|
|
62
|
+
* </EmptyState>
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* <EmptyState size="sm" variant="card">
|
|
66
|
+
* <EmptyState.Header>
|
|
67
|
+
* <EmptyState.Title>No results</EmptyState.Title>
|
|
68
|
+
* <EmptyState.Description>Try a different search.</EmptyState.Description>
|
|
69
|
+
* </EmptyState.Header>
|
|
70
|
+
* </EmptyState>
|
|
71
|
+
*/
|
|
72
|
+
export const EmptyState = Object.assign(EmptyStateRoot, {
|
|
73
|
+
/** The centred column holding the media, the title and the description. */
|
|
74
|
+
Header: EmptyStateHeader,
|
|
75
|
+
/** The picture above the title. A bare `Icon` inside it inherits size and colour; `variant="icon"` tints a box behind it. */
|
|
76
|
+
Media: EmptyStateMedia,
|
|
77
|
+
/** The heading, announced as a header. Carries its own colour — a `View` cannot cascade one to a `Text`. */
|
|
78
|
+
Title: EmptyStateTitle,
|
|
79
|
+
/** The supporting line under the title, a step down in scale and on the muted token. */
|
|
80
|
+
Description: EmptyStateDescription,
|
|
81
|
+
/** The action slot under the header: a centred row that wraps. */
|
|
82
|
+
Content: EmptyStateContent,
|
|
83
|
+
displayName: "DelacourUI.EmptyState",
|
|
84
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TextProps, ViewProps } from "react-native";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The shape of the header and content slots.
|
|
6
|
+
*
|
|
7
|
+
* Shared by `EmptyState.Header` and `EmptyState.Content`, and extended by
|
|
8
|
+
* `EmptyState.Media`, so it lives in a leaf rather than in one of them
|
|
9
|
+
* arbitrarily.
|
|
10
|
+
*/
|
|
11
|
+
export type EmptyStateSlotProps = ViewProps & { className?: string; children?: ReactNode };
|
|
12
|
+
|
|
13
|
+
/** The shape of the two text parts, `EmptyState.Title` and `EmptyState.Description`. */
|
|
14
|
+
export type EmptyStateTextProps = TextProps & { className?: string };
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { declaredTokens } from "../../styles/theme-tokens.test";
|
|
3
|
+
import { ICON_SIZE_TOKENS } from "../../styles/tokens";
|
|
4
|
+
import {
|
|
5
|
+
EMPTY_STATE_MEDIA_FOREGROUND_TOKEN,
|
|
6
|
+
EMPTY_STATE_MEDIA_VARIANTS,
|
|
7
|
+
EMPTY_STATE_SIZES,
|
|
8
|
+
EMPTY_STATE_VARIANTS,
|
|
9
|
+
emptyStateVariants,
|
|
10
|
+
} from "./empty-state.variants";
|
|
11
|
+
|
|
12
|
+
const LIGHT = declaredTokens("light");
|
|
13
|
+
const DARK = declaredTokens("dark");
|
|
14
|
+
|
|
15
|
+
/** Tailwind's spacing step a class string sets a utility from, e.g. `p` or `gap`. */
|
|
16
|
+
function step(cls: string, utility: string): number {
|
|
17
|
+
return Number(cls.match(new RegExp(`\\b${utility}-([\\d.]+)\\b`))?.[1]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Position of a class string's font size on the type scale, largest last.
|
|
22
|
+
*
|
|
23
|
+
* Compared by step rather than points so a retune in `tokens.css` does not
|
|
24
|
+
* break a test that only means "bigger".
|
|
25
|
+
*/
|
|
26
|
+
const TEXT_SCALE = ["text-xs", "text-sm", "text-base", "text-lg", "text-xl", "text-2xl"] as const;
|
|
27
|
+
function textStep(cls: string): number {
|
|
28
|
+
return TEXT_SCALE.findIndex((name) => new RegExp(`\\b${name}\\b`).test(cls));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Position of a slot's `size-icon-*` token on the shared icon scale. */
|
|
32
|
+
function iconStep(cls: string): number {
|
|
33
|
+
const token = cls.match(/\bsize-(icon-[\w-]+)\b/)?.[1];
|
|
34
|
+
return ICON_SIZE_TOKENS.indexOf(token as (typeof ICON_SIZE_TOKENS)[number]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Every slot that is a `View` — none of them may carry a text colour. */
|
|
38
|
+
const VIEW_SLOTS = ["root", "header", "media", "content"] as const;
|
|
39
|
+
|
|
40
|
+
/** A strictly ascending, all-distinct scale. */
|
|
41
|
+
function expectAscending(scale: readonly number[]): void {
|
|
42
|
+
expect(scale.every(Number.isFinite)).toBe(true);
|
|
43
|
+
expect(new Set(scale).size).toBe(scale.length);
|
|
44
|
+
expect([...scale]).toEqual([...scale].sort((a, b) => a - b));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe("the theme.css reader", () => {
|
|
48
|
+
test("finds both variants", () => {
|
|
49
|
+
expect(LIGHT.size).toBeGreaterThan(0);
|
|
50
|
+
expect(DARK.size).toBeGreaterThan(0);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("emptyStateVariants root slot", () => {
|
|
55
|
+
test("defaults to the md default variant", () => {
|
|
56
|
+
const cls = emptyStateVariants().root();
|
|
57
|
+
expect(cls).toContain("bg-transparent");
|
|
58
|
+
expect(cls).toContain(`p-${step(emptyStateVariants({ size: "md" }).root(), "p")}`);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("centres its content on both axes, at every variant", () => {
|
|
62
|
+
for (const variant of EMPTY_STATE_VARIANTS) {
|
|
63
|
+
const cls = emptyStateVariants({ variant }).root();
|
|
64
|
+
expect(cls).toContain("items-center");
|
|
65
|
+
expect(cls).toContain("justify-center");
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// `grow`, never `flex-1`. `flex-1` is a zero basis, so inside a ScrollView's
|
|
70
|
+
// content container — which has no height to grow into — the empty state
|
|
71
|
+
// collapses to nothing. `grow` keeps the content height as a floor and fills
|
|
72
|
+
// whatever a bounded parent has spare.
|
|
73
|
+
test("the default variant grows into its parent without a zero basis", () => {
|
|
74
|
+
const cls = emptyStateVariants({ variant: "default" }).root();
|
|
75
|
+
expect(cls).toMatch(/\bgrow\b/);
|
|
76
|
+
expect(cls).not.toMatch(/\bflex-1\b/);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("the card variant is a card-shaped surface with a dashed border", () => {
|
|
80
|
+
const cls = emptyStateVariants({ variant: "card" }).root();
|
|
81
|
+
expect(cls).toContain("bg-card");
|
|
82
|
+
expect(cls).toContain("border-border");
|
|
83
|
+
expect(cls).toContain("border-dashed");
|
|
84
|
+
expect(cls).not.toMatch(/\bgrow\b/);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// The border is in the box on both variants, so switching to `card` changes
|
|
88
|
+
// a colour and not the layout.
|
|
89
|
+
test("reserves the border on every variant", () => {
|
|
90
|
+
for (const variant of EMPTY_STATE_VARIANTS) {
|
|
91
|
+
expect(emptyStateVariants({ variant }).root()).toMatch(/\bborder\b/);
|
|
92
|
+
}
|
|
93
|
+
expect(emptyStateVariants({ variant: "default" }).root()).toContain("border-transparent");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("a card is rounded-lg at md and lg, and steps down to rounded-md at sm", () => {
|
|
97
|
+
expect(emptyStateVariants({ variant: "card", size: "sm" }).root()).toContain("rounded-md");
|
|
98
|
+
expect(emptyStateVariants({ variant: "card", size: "md" }).root()).toContain("rounded-lg");
|
|
99
|
+
expect(emptyStateVariants({ variant: "card", size: "lg" }).root()).toContain("rounded-lg");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("gives the two variants distinct treatments", () => {
|
|
103
|
+
const seen = new Set(EMPTY_STATE_VARIANTS.map((variant) => emptyStateVariants({ variant }).root()));
|
|
104
|
+
expect(seen.size).toBe(EMPTY_STATE_VARIANTS.length);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("merges an incoming className last", () => {
|
|
108
|
+
const cls = emptyStateVariants({ variant: "card" }).root({ className: "bg-muted" });
|
|
109
|
+
expect(cls).toContain("bg-muted");
|
|
110
|
+
expect(cls).not.toContain("bg-card");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("emptyStateVariants size axis", () => {
|
|
115
|
+
test("scales padding and the gap between header and content together", () => {
|
|
116
|
+
const roots = EMPTY_STATE_SIZES.map((size) => emptyStateVariants({ size }).root());
|
|
117
|
+
expectAscending(roots.map((cls) => step(cls, "p")));
|
|
118
|
+
expectAscending(roots.map((cls) => step(cls, "gap")));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("scales the header's own gap", () => {
|
|
122
|
+
expectAscending(EMPTY_STATE_SIZES.map((size) => step(emptyStateVariants({ size }).header(), "gap")));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("scales the title and description type together, title always the larger", () => {
|
|
126
|
+
const titles = EMPTY_STATE_SIZES.map((size) => textStep(emptyStateVariants({ size }).title()));
|
|
127
|
+
const descriptions = EMPTY_STATE_SIZES.map((size) => textStep(emptyStateVariants({ size }).description()));
|
|
128
|
+
|
|
129
|
+
expect(titles.every((index) => index >= 0)).toBe(true);
|
|
130
|
+
expect(descriptions.every((index) => index >= 0)).toBe(true);
|
|
131
|
+
expect([...titles]).toEqual([...titles].sort((a, b) => a - b));
|
|
132
|
+
expect([...descriptions]).toEqual([...descriptions].sort((a, b) => a - b));
|
|
133
|
+
expect(new Set(titles).size).toBe(EMPTY_STATE_SIZES.length);
|
|
134
|
+
|
|
135
|
+
for (const [index, title] of titles.entries()) {
|
|
136
|
+
expect(title).toBeGreaterThan(descriptions[index] ?? Number.POSITIVE_INFINITY);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Padding, never a height. A fixed height clips the description at a large
|
|
141
|
+
// accessibility font step instead of letting the block grow.
|
|
142
|
+
test("takes no height", () => {
|
|
143
|
+
for (const size of EMPTY_STATE_SIZES) {
|
|
144
|
+
expect(emptyStateVariants({ size }).root()).not.toMatch(/\bh-/);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("emptyStateVariants header slot", () => {
|
|
150
|
+
test("is a centred column", () => {
|
|
151
|
+
const cls = emptyStateVariants().header();
|
|
152
|
+
expect(cls).toContain("items-center");
|
|
153
|
+
expect(cls).not.toContain("flex-row");
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("emptyStateVariants media slot", () => {
|
|
158
|
+
test("the icon media is a tinted, rounded square that scales with size", () => {
|
|
159
|
+
const boxes = EMPTY_STATE_SIZES.map((size) => emptyStateVariants({ size, media: "icon" }).media());
|
|
160
|
+
for (const cls of boxes) {
|
|
161
|
+
expect(cls).toContain("bg-muted");
|
|
162
|
+
expect(cls).toMatch(/\brounded-/);
|
|
163
|
+
}
|
|
164
|
+
expectAscending(boxes.map((cls) => step(cls, "size")));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("the default media paints nothing and takes no size, so an illustration sizes itself", () => {
|
|
168
|
+
for (const size of EMPTY_STATE_SIZES) {
|
|
169
|
+
const cls = emptyStateVariants({ size, media: "default" }).media();
|
|
170
|
+
expect(cls).not.toMatch(/\bbg-/);
|
|
171
|
+
expect(cls).not.toMatch(/\bsize-/);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// A glyph in an empty state has to sit on the scale `Icon`, `Spinner` and
|
|
176
|
+
// `Button` share rather than carry a private number.
|
|
177
|
+
test("gives every size a distinct icon token, increasing with it", () => {
|
|
178
|
+
for (const media of EMPTY_STATE_MEDIA_VARIANTS) {
|
|
179
|
+
const steps = EMPTY_STATE_SIZES.map((size) => iconStep(emptyStateVariants({ size, media }).mediaIcon()));
|
|
180
|
+
expect(steps.every((index) => index >= 0)).toBe(true);
|
|
181
|
+
expectAscending(steps);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// Media and title are one visual unit only if the glyph clears the title by
|
|
186
|
+
// more than the title clears its description.
|
|
187
|
+
test("sets the media apart from the title by more than the header gap", () => {
|
|
188
|
+
for (const size of EMPTY_STATE_SIZES) {
|
|
189
|
+
const slots = emptyStateVariants({ size });
|
|
190
|
+
expect(step(slots.media(), "mb")).toBeGreaterThan(0);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("text colour", () => {
|
|
196
|
+
test("lives on the title and description, never on a View slot", () => {
|
|
197
|
+
for (const variant of EMPTY_STATE_VARIANTS) {
|
|
198
|
+
for (const size of EMPTY_STATE_SIZES) {
|
|
199
|
+
const slots = emptyStateVariants({ variant, size });
|
|
200
|
+
for (const slot of VIEW_SLOTS) {
|
|
201
|
+
expect(slots[slot]()).not.toMatch(/\btext-(?!center\b)/);
|
|
202
|
+
}
|
|
203
|
+
expect(slots.title()).toContain("text-foreground");
|
|
204
|
+
expect(slots.description()).toContain("text-muted-foreground");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("title and description are centred", () => {
|
|
210
|
+
const slots = emptyStateVariants();
|
|
211
|
+
expect(slots.title()).toContain("text-center");
|
|
212
|
+
expect(slots.description()).toContain("text-center");
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
describe("EMPTY_STATE_MEDIA_FOREGROUND_TOKEN", () => {
|
|
217
|
+
test("names a token for every media variant", () => {
|
|
218
|
+
for (const media of EMPTY_STATE_MEDIA_VARIANTS) {
|
|
219
|
+
expect(EMPTY_STATE_MEDIA_FOREGROUND_TOKEN[media]).toBeTruthy();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("names only tokens both themes declare", () => {
|
|
224
|
+
for (const media of EMPTY_STATE_MEDIA_VARIANTS) {
|
|
225
|
+
const token = EMPTY_STATE_MEDIA_FOREGROUND_TOKEN[media];
|
|
226
|
+
expect(LIGHT.has(token)).toBe(true);
|
|
227
|
+
expect(DARK.has(token)).toBe(true);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// `muted-foreground` on `bg-muted` is two greys a step apart. The tinted box
|
|
232
|
+
// already says "decoration", so the glyph inside it takes full contrast.
|
|
233
|
+
test("draws the icon media's glyph at full contrast on its muted box", () => {
|
|
234
|
+
expect(EMPTY_STATE_MEDIA_FOREGROUND_TOKEN.icon).toBe("foreground");
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe("emptyStateVariants content slot", () => {
|
|
239
|
+
test("lays actions out in a centred, wrapping row", () => {
|
|
240
|
+
const cls = emptyStateVariants().content();
|
|
241
|
+
expect(cls).toContain("flex-row");
|
|
242
|
+
expect(cls).toContain("flex-wrap");
|
|
243
|
+
expect(cls).toContain("justify-center");
|
|
244
|
+
});
|
|
245
|
+
});
|