@delacour/react-native-ui 0.1.0-alpha.20261007125731 → 0.1.0-alpha.20261009010050

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.
Files changed (30) hide show
  1. package/package.json +5 -3
  2. package/src/components/feedback/AGENTS.md +95 -0
  3. package/src/components/feedback/feedback-action.tsx +16 -0
  4. package/src/components/feedback/feedback-cancel.tsx +34 -0
  5. package/src/components/feedback/feedback-close.tsx +21 -0
  6. package/src/components/feedback/feedback-content.tsx +24 -0
  7. package/src/components/feedback/feedback-field.tsx +70 -0
  8. package/src/components/feedback/feedback-footer.tsx +21 -0
  9. package/src/components/feedback/feedback-panel.tsx +54 -0
  10. package/src/components/feedback/feedback-submit.tsx +74 -0
  11. package/src/components/feedback/feedback-title.tsx +34 -0
  12. package/src/components/feedback/feedback-trigger.tsx +20 -0
  13. package/src/components/feedback/feedback.context.tsx +73 -0
  14. package/src/components/feedback/feedback.tsx +135 -0
  15. package/src/components/feedback/feedback.variants.test.ts +185 -0
  16. package/src/components/feedback/feedback.variants.ts +128 -0
  17. package/src/components/feedback/index.ts +24 -0
  18. package/src/components/stack-card/AGENTS.md +169 -0
  19. package/src/components/stack-card/index.ts +37 -0
  20. package/src/components/stack-card/stack-card-action.tsx +66 -0
  21. package/src/components/stack-card/stack-card-actions.tsx +18 -0
  22. package/src/components/stack-card/stack-card-card.tsx +71 -0
  23. package/src/components/stack-card/stack-card-empty.tsx +30 -0
  24. package/src/components/stack-card/stack-card-slot.tsx +90 -0
  25. package/src/components/stack-card/stack-card-stamp.tsx +76 -0
  26. package/src/components/stack-card/stack-card.context.tsx +117 -0
  27. package/src/components/stack-card/stack-card.tsx +557 -0
  28. package/src/components/stack-card/stack-card.types.ts +26 -0
  29. package/src/components/stack-card/stack-card.variants.test.ts +355 -0
  30. package/src/components/stack-card/stack-card.variants.ts +360 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delacour/react-native-ui",
3
- "version": "0.1.0-alpha.20261007125731",
3
+ "version": "0.1.0-alpha.20261009010050",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -48,6 +48,7 @@
48
48
  "./dialog": "./src/components/dialog/index.ts",
49
49
  "./drawer": "./src/components/drawer/index.ts",
50
50
  "./empty-state": "./src/components/empty-state/index.ts",
51
+ "./feedback": "./src/components/feedback/index.ts",
51
52
  "./field": "./src/components/field/index.ts",
52
53
  "./icon": "./src/components/icon/index.ts",
53
54
  "./input": "./src/components/input/index.ts",
@@ -68,6 +69,7 @@
68
69
  "./skeleton": "./src/components/skeleton/index.ts",
69
70
  "./slider": "./src/components/slider/index.ts",
70
71
  "./spinner": "./src/components/spinner/index.ts",
72
+ "./stack-card": "./src/components/stack-card/index.ts",
71
73
  "./steps": "./src/components/steps/index.ts",
72
74
  "./surface": "./src/components/surface/index.ts",
73
75
  "./swipe": "./src/components/swipe/index.ts",
@@ -108,8 +110,8 @@
108
110
  },
109
111
  "peerDependencies": {
110
112
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
111
- "@delacour/react-native-bottom-sheet": "0.1.0-alpha.20261007125731",
112
- "@delacour/react-native-charts": "0.1.0-alpha.20261007125731",
113
+ "@delacour/react-native-bottom-sheet": "0.1.0-alpha.20261009010050",
114
+ "@delacour/react-native-charts": "0.1.0-alpha.20261009010050",
113
115
  "@legendapp/list": ">=3.3",
114
116
  "expo-linear-gradient": ">=15",
115
117
  "expo-router": ">=57",
@@ -0,0 +1,95 @@
1
+ # Feedback
2
+
3
+ A dialog for writing: "What should we fix first?", a bug report, a one-question survey. It is a
4
+ [`Dialog`](../dialog/AGENTS.md) whose text field sits in a **recessed well** that says "type here",
5
+ with the actions on the band around it. Compound root plus `Feedback.Trigger`, `Feedback.Content`,
6
+ `Feedback.Panel`, `Feedback.Title`, `Feedback.Close`, `Feedback.Field`, `Feedback.Footer`,
7
+ `Feedback.Action`, `Feedback.Cancel` and `Feedback.Submit`, and `useFeedback()`.
8
+
9
+ `import { Feedback } from "@delacour/react-native-ui/feedback";`
10
+
11
+ Not for confirmations or warnings — those are a `Dialog`. Like every overlay it draws through
12
+ `Overlay.Portal`, so the app mounts `OverlayProvider` once at its root.
13
+
14
+ ## Files
15
+
16
+ | File | What it holds |
17
+ | --- | --- |
18
+ | `index.ts` | → `@delacour/react-native-ui/feedback` |
19
+ | `feedback.tsx` | Root — the open state, the draft, the send state — wrapping a `Dialog`, and the `Object.assign` surface |
20
+ | `feedback.context.tsx` | **Leaf.** `FeedbackProvider`, `useFeedback()`, `useFeedbackContext()`, `useFeedbackPart()` |
21
+ | `feedback-trigger.tsx` | `Feedback.Trigger` — `Dialog.Trigger` |
22
+ | `feedback-content.tsx` | `Feedback.Content` — `Dialog.Content` on the muted band, tighter padding |
23
+ | `feedback-panel.tsx` | `Feedback.Panel` — the well, in a clip that eases to its measured height |
24
+ | `feedback-title.tsx` | `Feedback.Title` — `Dialog.Title`; publishes a string title as the field's label |
25
+ | `feedback-close.tsx` | `Feedback.Close` — `Dialog.Close`, in the well's corner |
26
+ | `feedback-field.tsx` | `Feedback.Field` — a bare multiline `TextInput` bound to the draft |
27
+ | `feedback-footer.tsx` | `Feedback.Footer` |
28
+ | `feedback-action.tsx` | `Feedback.Action` — a `secondary` `Button` for custom actions |
29
+ | `feedback-cancel.tsx` | `Feedback.Cancel` — closes, keeps the draft |
30
+ | `feedback-submit.tsx` | `Feedback.Submit` — the gate, the trimmed value, the wait on a promise |
31
+ | `feedback.variants.ts` | The slotted `tv()`, the row and motion constants, `canSubmitFeedback` and the field-height resolvers — no RN imports |
32
+ | `feedback.variants.test.ts` | Slots, tokens in both themes, the submit gate, the field heights |
33
+
34
+ ## Design
35
+
36
+ - **Everything a dialog does is Dialog's.** `Feedback` renders a `Dialog` and its parts *are*
37
+ Dialog's parts with classes merged over them — open state, portal, scrim, motion, the `modal`
38
+ band, the back button, the escape gesture, focus on open and return, and the keyboard lift that
39
+ keeps the footer above the keyboard. Nothing is restated, so a fix to Dialog is a fix here. The
40
+ import is `../dialog`: Dialog never imports Feedback, so there is no cycle to route around.
41
+ - **The shell is the band; the panel is the well.** `Feedback.Content` merges `bg-muted` and `p-2`
42
+ over Dialog's `bg-popover` and `p-5` through the same `tv` merge, so the corner, hairline and
43
+ width cap stay Dialog's. `Feedback.Panel` is `bg-background` with `rounded-md` — one step down
44
+ the corner ramp from the card it sits in, so the two read as nested — and a hairline. The well's
45
+ page colour against the band's muted one is what says "type here" without a field border.
46
+ - **The field has no box.** `Feedback.Field` is a raw `TextInput`, not an `Input`: the well is
47
+ its box, and an `Input` would draw a second border inside the first. It restates `font-sans` for
48
+ `Input`'s reason (a `TextInput` inherits nothing), sets `text-input-md` with paragraph leading
49
+ (`leading-6`, `FEEDBACK_FIELD_LINE_HEIGHT`, pinned by a test), and takes `Input`'s `accent-*`
50
+ placeholder, caret and selection classes from `input.variants` — a leaf, so no cycle.
51
+ - **The field is floored at `minRows` and capped at `maxRows`.** Six rows and twelve by default,
52
+ as a style (`resolveFeedbackFieldHeightStyle`) because a runtime number cannot be a class.
53
+ Between the two React Native's multiline `TextInput` sizes itself. `maxRows` is not in the
54
+ original spec: without a cap a long message grows the card until Dialog's lift, which keeps the
55
+ title on screen first, has to give up the footer to the keyboard.
56
+ - **The draft lives on the root, above `Dialog.Content`.** Content unmounts when the exit animation
57
+ ends; the root does not, so an uncontrolled draft survives a close and a reopen. Cancel, Close,
58
+ the scrim and back all keep it — a long message put down for a moment must not be thrown away.
59
+ `useFeedback().clear()` is the one way to empty it.
60
+ - **Submit never closes.** `canSubmitFeedback` gates it (empty and whitespace are empty;
61
+ `canSubmitEmpty` lets an empty one through for chips or a rating; disabled outranks both), and
62
+ `onSubmit` gets the trimmed text. A returned promise turns on the button's loading state and
63
+ makes the field read-only until it settles — and the dialog is still open, so a failure can be
64
+ shown in the well with the draft intact. The caller closes and clears on success. A rejection is
65
+ not swallowed: handle failures inside `onSubmit`, or the app's unhandled-rejection reporting sees
66
+ it, which is better than a send that failed silently.
67
+ - **The well eases between heights; the shell never jumps.** A multi-step flow (rating → text →
68
+ thanks) is the caller swapping the panel's and footer's children. `Feedback.Panel` measures the
69
+ well with `onLayout` and animates a clip around it to that height over `FEEDBACK_PANEL_RESIZE_MS`
70
+ (200ms). The spec named a Reanimated `LinearTransition` on the panel; that animates the panel's
71
+ frame inside a shell that has already snapped to its final size and re-centred, which is exactly
72
+ the jump to avoid. A real height changing on every frame moves the shell through ordinary layout
73
+ and keeps it centred — Accordion's reasoning for its own panel. The first layout lands without
74
+ animating, and under reduce motion every change does.
75
+ - **The field's label is the title.** `Feedback.Title` publishes its children to the root when
76
+ they are a plain string, and `Feedback.Field` uses that as its default `accessibilityLabel`, so
77
+ a screen reader announces the question rather than only the placeholder. A non-string title
78
+ publishes nothing; pass `accessibilityLabel` then.
79
+ - **Close sits in the well, not the shell.** `Feedback.Close` is `Dialog.Close` with its slot
80
+ re-pinned to the well's corner (`top-3 right-3`, against the panel's `p-4`); the title keeps
81
+ Dialog's `pr-8` clearance.
82
+ - **No blur backdrop.** As for every overlay: frosted scrims need `expo-blur`, not a peer.
83
+
84
+ ## Testing
85
+
86
+ `bun test` reaches `feedbackVariants`, the tokens in both themes, `canSubmitFeedback` and the
87
+ field-height resolvers. Opening, the submit gate, the async send, the draft across close and
88
+ reopen, the keyboard, the multi-step resize and every dismissal path are verified on a simulator
89
+ through `/feedback` in the playground.
90
+
91
+ Preview media is held back with the rest of the overlays (see `docs/plans/overlays/README.md`).
92
+ When a capture tool is back, re-add `capture` with these settings and run
93
+ `bun run previews -- -- --only feedback`: `basic` `{ flow: "feedback/basic", frame: "device", hero: true }`,
94
+ and `sending`, `multi-step` `{ flow: "feedback/<id>", frame: "device" }`. The flows are in
95
+ `.argent/flows/previews/feedback/`.
@@ -0,0 +1,16 @@
1
+ import type { ReactElement } from "react";
2
+ import { Button, type ButtonProps } from "../button";
3
+
4
+ export type FeedbackActionProps = ButtonProps;
5
+
6
+ /**
7
+ * A custom footer action — "Skip", "Back", "Attach screenshot" — as a
8
+ * `secondary` `Button`. Pass `variant` to change it.
9
+ *
10
+ * @example
11
+ * <Feedback.Action onPress={back}>Back</Feedback.Action>
12
+ */
13
+ export function FeedbackAction({ variant = "secondary", ...props }: FeedbackActionProps): ReactElement {
14
+ return <Button variant={variant} {...props} />;
15
+ }
16
+ FeedbackAction.displayName = "DelacourUI.Feedback.Action";
@@ -0,0 +1,34 @@
1
+ import { type ReactElement, useCallback } from "react";
2
+ import { Button, type ButtonProps } from "../button";
3
+ import { useFeedbackPart } from "./feedback.context";
4
+
5
+ export type FeedbackCancelProps = ButtonProps;
6
+
7
+ /**
8
+ * Closes the dialog and keeps the draft — a `secondary` `Button` labelled
9
+ * "Cancel" unless given children. Clearing on cancel would throw away a long
10
+ * message the user only meant to put down for a moment.
11
+ *
12
+ * @example
13
+ * <Feedback.Cancel />
14
+ */
15
+ export function FeedbackCancel({
16
+ variant = "secondary",
17
+ children = "Cancel",
18
+ onPress,
19
+ ...props
20
+ }: FeedbackCancelProps): ReactElement {
21
+ const { close } = useFeedbackPart("Feedback.Cancel");
22
+
23
+ const handlePress = useCallback(() => {
24
+ close();
25
+ onPress?.();
26
+ }, [close, onPress]);
27
+
28
+ return (
29
+ <Button onPress={handlePress} variant={variant} {...props}>
30
+ {children}
31
+ </Button>
32
+ );
33
+ }
34
+ FeedbackCancel.displayName = "DelacourUI.Feedback.Cancel";
@@ -0,0 +1,21 @@
1
+ import type { ReactElement } from "react";
2
+ import { Dialog, type DialogCloseProps } from "../dialog";
3
+ import { feedbackVariants } from "./feedback.variants";
4
+
5
+ export type FeedbackCloseProps = DialogCloseProps;
6
+
7
+ /**
8
+ * The ✕ in the well's top-right corner — `Dialog.Close`, positioned against
9
+ * the panel rather than the shell. `Feedback.Title`'s `pr-8` reserves its
10
+ * clearance. Labelled `"Close"`; the draft is kept.
11
+ *
12
+ * With `asChild` it donates the close to its child, as `Dialog.Close` does.
13
+ *
14
+ * @example
15
+ * <Feedback.Close />
16
+ */
17
+ export function FeedbackClose(props: FeedbackCloseProps): ReactElement {
18
+ if (props.asChild) return <Dialog.Close {...props} />;
19
+ return <Dialog.Close {...props} className={feedbackVariants().close({ className: props.className })} />;
20
+ }
21
+ FeedbackClose.displayName = "DelacourUI.Feedback.Close";
@@ -0,0 +1,24 @@
1
+ import type { ReactElement } from "react";
2
+ import { Dialog, type DialogContentProps } from "../dialog";
3
+ import { feedbackVariants } from "./feedback.variants";
4
+
5
+ export type FeedbackContentProps = DialogContentProps;
6
+
7
+ /**
8
+ * The shell — a `Dialog.Content` on the muted band.
9
+ *
10
+ * Portal, scrim, motion, keyboard lift, back button, escape and focus are all
11
+ * Dialog's. This only swaps the card's fill for `bg-muted` and tightens its
12
+ * padding, so the `Feedback.Panel` inside reads as a well sunk into it and the
13
+ * footer's actions sit on the band around it.
14
+ *
15
+ * @example
16
+ * <Feedback.Content>
17
+ * <Feedback.Panel>…</Feedback.Panel>
18
+ * <Feedback.Footer>…</Feedback.Footer>
19
+ * </Feedback.Content>
20
+ */
21
+ export function FeedbackContent({ className, ...props }: FeedbackContentProps): ReactElement {
22
+ return <Dialog.Content className={feedbackVariants().content({ className })} {...props} />;
23
+ }
24
+ FeedbackContent.displayName = "DelacourUI.Feedback.Content";
@@ -0,0 +1,70 @@
1
+ import { type ReactElement, useCallback } from "react";
2
+ import { TextInput, type TextInputProps } from "react-native";
3
+ import { resolvePlaceholderAccentClass, resolveSelectionAccentClass } from "../input/input.variants";
4
+ import { useFeedbackPart } from "./feedback.context";
5
+ import { feedbackVariants, resolveFeedbackFieldHeightStyle } from "./feedback.variants";
6
+
7
+ export type FeedbackFieldProps = Omit<TextInputProps, "value" | "onChangeText" | "multiline"> & {
8
+ className?: string;
9
+ /** Rows before it grows. Default 6. */
10
+ minRows?: number;
11
+ /** Rows it grows to before it scrolls. Default 12. */
12
+ maxRows?: number;
13
+ /** Read-only — while sending, say. A send in flight makes it read-only on its own. */
14
+ isDisabled?: boolean;
15
+ };
16
+
17
+ /**
18
+ * Where the message is written: a bare multiline `TextInput` with no box of
19
+ * its own, because the well around it is the box.
20
+ *
21
+ * The draft is the root's — `value` and `onChangeText` are withheld — so it
22
+ * survives the dialog closing and reopening, and `useFeedback().clear()` is
23
+ * the one way to empty it. It is floored at `minRows` and grows to `maxRows`
24
+ * before it scrolls (`resolveFeedbackFieldHeightStyle`), as a style, since a
25
+ * runtime number cannot be a Tailwind class.
26
+ *
27
+ * While a promise from `Feedback.Submit` is in flight it is read-only, so what
28
+ * is being sent is what stays on screen. Its label defaults to the title's
29
+ * text when the title is a plain string.
30
+ *
31
+ * Placeholder, caret and selection take `Input`'s `accent-*` defaults.
32
+ *
33
+ * @example
34
+ * <Feedback.Field placeholder="Tell us what got in your way" />
35
+ */
36
+ export function FeedbackField({
37
+ className,
38
+ minRows,
39
+ maxRows,
40
+ isDisabled = false,
41
+ accessibilityLabel,
42
+ editable,
43
+ style,
44
+ ...props
45
+ }: FeedbackFieldProps): ReactElement {
46
+ const { value, setValue, isSending, titleText } = useFeedbackPart("Feedback.Field");
47
+ const isReadOnly = isDisabled || isSending;
48
+ const selectionAccent = resolveSelectionAccentClass({});
49
+
50
+ const handleChangeText = useCallback((text: string) => setValue(text), [setValue]);
51
+
52
+ return (
53
+ <TextInput
54
+ accessibilityLabel={accessibilityLabel ?? titleText}
55
+ accessibilityState={{ disabled: isReadOnly }}
56
+ className={feedbackVariants().field({ className })}
57
+ cursorColorClassName={selectionAccent}
58
+ placeholderTextColorClassName={resolvePlaceholderAccentClass()}
59
+ selectionColorClassName={selectionAccent}
60
+ style={[resolveFeedbackFieldHeightStyle({ maxRows, minRows }), style]}
61
+ textAlignVertical="top"
62
+ {...props}
63
+ editable={isReadOnly ? false : editable}
64
+ multiline
65
+ onChangeText={handleChangeText}
66
+ value={value}
67
+ />
68
+ );
69
+ }
70
+ FeedbackField.displayName = "DelacourUI.Feedback.Field";
@@ -0,0 +1,21 @@
1
+ import type { ReactElement } from "react";
2
+ import { View, type ViewProps } from "react-native";
3
+ import { feedbackVariants } from "./feedback.variants";
4
+
5
+ export type FeedbackFooterProps = ViewProps & { className?: string };
6
+
7
+ /**
8
+ * The actions, on the band under the well — an end-aligned row, inset less
9
+ * than the well so the buttons line up with the shell's edge rather than the
10
+ * well's text.
11
+ *
12
+ * @example
13
+ * <Feedback.Footer>
14
+ * <Feedback.Cancel />
15
+ * <Feedback.Submit onSubmit={send} />
16
+ * </Feedback.Footer>
17
+ */
18
+ export function FeedbackFooter({ className, ...props }: FeedbackFooterProps): ReactElement {
19
+ return <View className={feedbackVariants().footer({ className })} {...props} />;
20
+ }
21
+ FeedbackFooter.displayName = "DelacourUI.Feedback.Footer";
@@ -0,0 +1,54 @@
1
+ import { type ReactElement, useCallback } from "react";
2
+ import { type LayoutChangeEvent, View, type ViewProps } from "react-native";
3
+ import Animated, { useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from "react-native-reanimated";
4
+ import { FEEDBACK_PANEL_RESIZE_MS, feedbackVariants } from "./feedback.variants";
5
+
6
+ export type FeedbackPanelProps = ViewProps & { className?: string };
7
+
8
+ /** No height measured yet: the clip wraps its content until the first layout. */
9
+ const UNMEASURED = -1;
10
+
11
+ /**
12
+ * The recessed well the title, the close and the field sit in.
13
+ *
14
+ * **Its height is measured and animated, never laid out.** The well is drawn
15
+ * inside a clip whose height follows the well's own `onLayout` on a short
16
+ * timing, so when a multi-step flow swaps the panel's children — a rating, then
17
+ * a message, then thanks — the clip eases to the new height. The shell grows
18
+ * with it through ordinary layout and stays centred on every frame, so it never
19
+ * jumps; a layout transition on the panel alone would animate the panel inside
20
+ * a shell that had already snapped to its final size. The first layout lands
21
+ * without animating, and under reduce motion every change does.
22
+ *
23
+ * @example
24
+ * <Feedback.Panel>
25
+ * <Feedback.Title>What should we fix first?</Feedback.Title>
26
+ * <Feedback.Close />
27
+ * <Feedback.Field placeholder="Tell us what got in your way" />
28
+ * </Feedback.Panel>
29
+ */
30
+ export function FeedbackPanel({ className, onLayout, ...props }: FeedbackPanelProps): ReactElement {
31
+ const isReduced = useReducedMotion();
32
+ const height = useSharedValue(UNMEASURED);
33
+
34
+ const handleLayout = useCallback(
35
+ (event: LayoutChangeEvent) => {
36
+ const next = event.nativeEvent.layout.height;
37
+ height.value =
38
+ height.value === UNMEASURED || isReduced ? next : withTiming(next, { duration: FEEDBACK_PANEL_RESIZE_MS });
39
+ onLayout?.(event);
40
+ },
41
+ [height, isReduced, onLayout]
42
+ );
43
+
44
+ const clipStyle = useAnimatedStyle(() => (height.value === UNMEASURED ? {} : { height: height.value }));
45
+
46
+ const slots = feedbackVariants();
47
+
48
+ return (
49
+ <Animated.View className={slots.clip()} style={clipStyle}>
50
+ <View className={slots.panel({ className })} onLayout={handleLayout} {...props} />
51
+ </Animated.View>
52
+ );
53
+ }
54
+ FeedbackPanel.displayName = "DelacourUI.Feedback.Panel";
@@ -0,0 +1,74 @@
1
+ import { type ReactElement, useCallback } from "react";
2
+ import { Button, type ButtonProps } from "../button";
3
+ import { useFeedbackPart } from "./feedback.context";
4
+ import { canSubmitFeedback } from "./feedback.variants";
5
+
6
+ export type FeedbackSubmitProps = Omit<ButtonProps, "onPress"> & {
7
+ /** Receives the trimmed message. Does NOT close — sending has to finish first. */
8
+ onSubmit: (value: string) => void | Promise<void>;
9
+ /** Allow submitting an empty message (e.g. when chips were picked). Default false. */
10
+ canSubmitEmpty?: boolean;
11
+ };
12
+
13
+ /** Whether a value is a promise, without trusting `instanceof` across realms. */
14
+ function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
15
+ return typeof value === "object" && value !== null && typeof (value as PromiseLike<unknown>).then === "function";
16
+ }
17
+
18
+ /**
19
+ * Sends the message — a primary `Button` labelled "Send" unless given children.
20
+ *
21
+ * Disabled while `canSubmitFeedback` says no: an empty or whitespace draft,
22
+ * unless `canSubmitEmpty`. `onSubmit` receives the trimmed text.
23
+ *
24
+ * **It never closes the dialog.** When `onSubmit` returns a promise the button
25
+ * shows its loading state and the field turns read-only until the promise
26
+ * settles, and then the dialog is still open — so a failure can be shown in
27
+ * the well with the draft intact. Close and clear from `onSubmit` on success,
28
+ * through `useFeedback()` or controlled state. Handle a failure inside
29
+ * `onSubmit`: a rejection is not caught here, so it still reaches the app's
30
+ * unhandled-rejection reporting rather than vanishing.
31
+ *
32
+ * @example
33
+ * <Feedback.Submit
34
+ * onSubmit={async (message) => {
35
+ * await send(message);
36
+ * clear();
37
+ * close();
38
+ * }}
39
+ * />
40
+ */
41
+ export function FeedbackSubmit({
42
+ onSubmit,
43
+ canSubmitEmpty = false,
44
+ isDisabled = false,
45
+ isLoading = false,
46
+ children = "Send",
47
+ ...props
48
+ }: FeedbackSubmitProps): ReactElement {
49
+ const { value, isSending, setSending } = useFeedbackPart("Feedback.Submit");
50
+ const canSubmit = canSubmitFeedback({ canSubmitEmpty, isDisabled, value });
51
+
52
+ const handlePress = useCallback(() => {
53
+ if (!canSubmit || isSending) return;
54
+ const result = onSubmit(value.trim());
55
+ if (!isPromiseLike(result)) return;
56
+
57
+ setSending(true);
58
+ const settle = () => setSending(false);
59
+ void Promise.resolve(result).finally(settle);
60
+ }, [canSubmit, isSending, onSubmit, setSending, value]);
61
+
62
+ return (
63
+ <Button
64
+ isDisabled={!canSubmit}
65
+ isLoading={isLoading || isSending}
66
+ onPress={handlePress}
67
+ variant="primary"
68
+ {...props}
69
+ >
70
+ {children}
71
+ </Button>
72
+ );
73
+ }
74
+ FeedbackSubmit.displayName = "DelacourUI.Feedback.Submit";
@@ -0,0 +1,34 @@
1
+ import { type ReactElement, useEffect } from "react";
2
+ import { Dialog, type DialogTitleProps } from "../dialog";
3
+ import { useFeedbackPart } from "./feedback.context";
4
+ import { feedbackVariants } from "./feedback.variants";
5
+
6
+ export type FeedbackTitleProps = DialogTitleProps;
7
+
8
+ /**
9
+ * The question the dialog asks — a `Dialog.Title`, inside the well.
10
+ *
11
+ * It is what the dialog is labelled by and where accessibility focus lands on
12
+ * open, exactly as in a `Dialog`. When its children are a plain string, that
13
+ * string also becomes `Feedback.Field`'s default `accessibilityLabel`, so the
14
+ * field announces the question rather than only its placeholder.
15
+ *
16
+ * @example
17
+ * <Feedback.Title>What should we fix first?</Feedback.Title>
18
+ */
19
+ export function FeedbackTitle({ className, children, ...props }: FeedbackTitleProps): ReactElement {
20
+ const { setTitleText } = useFeedbackPart("Feedback.Title");
21
+ const text = typeof children === "string" ? children : undefined;
22
+
23
+ useEffect(() => {
24
+ setTitleText(text);
25
+ return () => setTitleText(undefined);
26
+ }, [setTitleText, text]);
27
+
28
+ return (
29
+ <Dialog.Title className={feedbackVariants().title({ className })} {...props}>
30
+ {children}
31
+ </Dialog.Title>
32
+ );
33
+ }
34
+ FeedbackTitle.displayName = "DelacourUI.Feedback.Title";
@@ -0,0 +1,20 @@
1
+ import type { ReactElement } from "react";
2
+ import { Dialog, type DialogTriggerProps } from "../dialog";
3
+
4
+ export type FeedbackTriggerProps = DialogTriggerProps;
5
+
6
+ /**
7
+ * The control that opens the feedback dialog — `Dialog.Trigger`, unchanged.
8
+ *
9
+ * `asChild` donates the open to a `Button` rather than wrapping it, for the
10
+ * reason `Dialog.Trigger` gives: two tap gestures nested are not simultaneous.
11
+ *
12
+ * @example
13
+ * <Feedback.Trigger asChild>
14
+ * <Button variant="secondary">Give feedback</Button>
15
+ * </Feedback.Trigger>
16
+ */
17
+ export function FeedbackTrigger(props: FeedbackTriggerProps): ReactElement {
18
+ return <Dialog.Trigger {...props} />;
19
+ }
20
+ FeedbackTrigger.displayName = "DelacourUI.Feedback.Trigger";
@@ -0,0 +1,73 @@
1
+ import { createContext, type ReactElement, type ReactNode, use } from "react";
2
+
3
+ export type FeedbackContextValue = {
4
+ /** The draft as typed — untrimmed. */
5
+ value: string;
6
+ /** Replaces the draft. Reports through `onValueChange`. */
7
+ setValue: (value: string) => void;
8
+ /** Whether the dialog is open. */
9
+ isOpen: boolean;
10
+ /** Closes the dialog. The draft is kept. */
11
+ close: () => void;
12
+ /** Empties the draft — after a successful send, say. */
13
+ clear: () => void;
14
+ };
15
+
16
+ /** What the parts share that a caller has no use for. */
17
+ export type FeedbackInternalValue = FeedbackContextValue & {
18
+ /** Whether a promise `onSubmit` returned is still in flight. */
19
+ isSending: boolean;
20
+ setSending: (isSending: boolean) => void;
21
+ /** The title's text when it is a plain string — the field's default label. */
22
+ titleText: string | undefined;
23
+ setTitleText: (text: string | undefined) => void;
24
+ };
25
+
26
+ const FeedbackContext = createContext<FeedbackInternalValue | null>(null);
27
+
28
+ /**
29
+ * Supplies the feedback dialog's draft and send state to its parts.
30
+ *
31
+ * Its own module, importing nothing but React, so a part can read it without
32
+ * importing `./feedback` — that import would close a cycle, and Metro serves a
33
+ * partially initialised module for one.
34
+ */
35
+ export function FeedbackProvider({
36
+ value,
37
+ children,
38
+ }: {
39
+ value: FeedbackInternalValue;
40
+ children: ReactNode;
41
+ }): ReactElement {
42
+ return <FeedbackContext value={value}>{children}</FeedbackContext>;
43
+ }
44
+ FeedbackProvider.displayName = "DelacourUI.Feedback.Provider";
45
+
46
+ /** The enclosing feedback dialog's context, or null outside a `<Feedback>`. */
47
+ export function useFeedbackContext(): FeedbackContextValue | null {
48
+ return use(FeedbackContext);
49
+ }
50
+
51
+ /**
52
+ * Reads the enclosing feedback dialog's draft, its setters and its open state.
53
+ *
54
+ * Lets a custom child — a row of chips, a rating step — read or replace the
55
+ * draft, and lets an `onSubmit` close and clear once the send has gone through.
56
+ * Throws outside a `<Feedback>`.
57
+ */
58
+ export function useFeedback(): FeedbackContextValue {
59
+ const context = use(FeedbackContext);
60
+ if (!context) {
61
+ throw new Error("useFeedback must be called inside a <Feedback>.");
62
+ }
63
+ return context;
64
+ }
65
+
66
+ /** The full context, for a part that cannot work without one. Internal. */
67
+ export function useFeedbackPart(component: string): FeedbackInternalValue {
68
+ const context = use(FeedbackContext);
69
+ if (!context) {
70
+ throw new Error(`${component} must be rendered inside a <Feedback>.`);
71
+ }
72
+ return context;
73
+ }