@enablo/swirlcn-ui 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +30 -2
- package/dist/chunk-3DJWDNQL.js +77 -0
- package/dist/chunk-7XUCETA6.js +447 -0
- package/dist/chunk-KZESIYUN.js +18 -0
- package/dist/flip.d.ts +98 -0
- package/dist/flip.js +158 -0
- package/dist/fonts/Inter-italic.var.woff2 +0 -0
- package/dist/fonts/Inter.var.woff2 +0 -0
- package/dist/fonts/OFL.txt +96 -0
- package/dist/index.d.ts +2459 -0
- package/dist/index.js +8439 -0
- package/dist/server.d.ts +144 -0
- package/dist/server.js +88 -0
- package/dist/spacing-BQaEPbUv.d.ts +59 -0
- package/dist/theme.css +146 -0
- package/package.json +84 -3
- package/src/components/accordion.tsx +102 -0
- package/src/components/action-list.tsx +294 -0
- package/src/components/alert-dialog.tsx +155 -0
- package/src/components/autocomplete.tsx +313 -0
- package/src/components/avatar.tsx +258 -0
- package/src/components/badge.tsx +100 -0
- package/src/components/banner.tsx +112 -0
- package/src/components/button-group.tsx +87 -0
- package/src/components/button.tsx +362 -0
- package/src/components/card.tsx +186 -0
- package/src/components/carousel.tsx +245 -0
- package/src/components/checkbox.tsx +125 -0
- package/src/components/chip.tsx +153 -0
- package/src/components/color-input.tsx +98 -0
- package/src/components/data-cell.tsx +230 -0
- package/src/components/date-input.tsx +223 -0
- package/src/components/date-picker.tsx +276 -0
- package/src/components/description-list.tsx +97 -0
- package/src/components/dialog.tsx +405 -0
- package/src/components/empty-state.tsx +63 -0
- package/src/components/file-chip.tsx +206 -0
- package/src/components/file-uploader.tsx +148 -0
- package/src/components/flip-app-header.tsx +104 -0
- package/src/components/flip-brand.tsx +77 -0
- package/src/components/flip-theme.tsx +95 -0
- package/src/components/form-control.tsx +397 -0
- package/src/components/form-group.tsx +26 -0
- package/src/components/heading.tsx +70 -0
- package/src/components/icon.tsx +119 -0
- package/src/components/image-grid.tsx +285 -0
- package/src/components/inline-notification.tsx +167 -0
- package/src/components/inline-status.tsx +100 -0
- package/src/components/input.tsx +390 -0
- package/src/components/label.tsx +28 -0
- package/src/components/lightbox.tsx +314 -0
- package/src/components/link.tsx +46 -0
- package/src/components/list.tsx +40 -0
- package/src/components/menu.tsx +530 -0
- package/src/components/option-list.tsx +582 -0
- package/src/components/pagination.tsx +336 -0
- package/src/components/popover.tsx +194 -0
- package/src/components/progress.tsx +158 -0
- package/src/components/radio-group.tsx +136 -0
- package/src/components/resource-list.tsx +686 -0
- package/src/components/search.tsx +127 -0
- package/src/components/select.tsx +456 -0
- package/src/components/separator.tsx +93 -0
- package/src/components/skeleton-box.tsx +63 -0
- package/src/components/skeleton-text.tsx +66 -0
- package/src/components/spinner.tsx +83 -0
- package/src/components/stack.tsx +86 -0
- package/src/components/status-indicator.tsx +31 -0
- package/src/components/switch.tsx +90 -0
- package/src/components/table.tsx +242 -0
- package/src/components/tabs.tsx +147 -0
- package/src/components/tag.tsx +169 -0
- package/src/components/text.tsx +126 -0
- package/src/components/textarea.tsx +130 -0
- package/src/components/theme-provider.tsx +115 -0
- package/src/components/thumbnail.tsx +250 -0
- package/src/components/time-input.tsx +123 -0
- package/src/components/toast.tsx +217 -0
- package/src/components/toggle-group.tsx +124 -0
- package/src/components/toolbar.tsx +105 -0
- package/src/components/tooltip.tsx +97 -0
- package/src/components/tree-navigation.tsx +194 -0
- package/src/components/tree-view.tsx +292 -0
- package/src/flip.ts +12 -0
- package/src/index.ts +317 -0
- package/src/lib/date-mask.ts +176 -0
- package/src/lib/field-context.ts +86 -0
- package/src/lib/flip-app-script.ts +38 -0
- package/src/lib/flip-host.ts +84 -0
- package/src/lib/flip-theme-css.ts +90 -0
- package/src/lib/focus.ts +18 -0
- package/src/lib/glyphs.ts +137 -0
- package/src/lib/spacing.ts +93 -0
- package/src/lib/theme-context.ts +27 -0
- package/src/lib/theme-script.ts +49 -0
- package/src/lib/use-mobile.ts +17 -0
- package/src/lib/utils.ts +28 -0
- package/src/server.ts +20 -0
- package/src/styles/fonts/Inter-italic.var.woff2 +0 -0
- package/src/styles/fonts/Inter.var.woff2 +0 -0
- package/src/styles/fonts/OFL.txt +96 -0
- package/src/styles/theme.css +146 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { cn } from "../lib/utils";
|
|
2
|
+
|
|
3
|
+
export interface ChipProps
|
|
4
|
+
extends Omit<React.HTMLAttributes<HTMLElement>, "children" | "onClick"> {
|
|
5
|
+
/** The chip's text. Interchangeable with `children`. */
|
|
6
|
+
label?: React.ReactNode;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
/** Leading icon, 20px. Ignored when `avatar` is given, as in Swirl. */
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
/** Leading avatar, in place of an icon. Pass a 24px (`2xs`) `Avatar`. */
|
|
11
|
+
avatar?: React.ReactNode;
|
|
12
|
+
/** Trailing icon, 20px. */
|
|
13
|
+
trailingIcon?: React.ReactNode;
|
|
14
|
+
/** Anything else after the label, such as a `Badge`. */
|
|
15
|
+
trailingContent?: React.ReactNode;
|
|
16
|
+
/** Border and text colour. `pressed` overrides it. */
|
|
17
|
+
intent?: "default" | "critical" | "highlight";
|
|
18
|
+
/** Colour the leading icon with the highlight colour. */
|
|
19
|
+
iconColor?: "default" | "highlight";
|
|
20
|
+
/** Render as a button and fire `onClick`. Implied by `pressed`. */
|
|
21
|
+
interactive?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Make the chip a toggle button. `true` fills it with the primary colour.
|
|
24
|
+
* Leave undefined for a chip that is not a toggle.
|
|
25
|
+
*/
|
|
26
|
+
pressed?: boolean;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
29
|
+
/** Show a remove button after the label, which fires `onRemove`. */
|
|
30
|
+
removable?: boolean;
|
|
31
|
+
onRemove?: () => void;
|
|
32
|
+
removeButtonLabel?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Swirl's chip: a compact, rounded label for a filter, a selection or an
|
|
37
|
+
* attribute. Static by default; `interactive` makes it a button, `pressed` a
|
|
38
|
+
* toggle, and `removable` adds a remove button beside it.
|
|
39
|
+
*/
|
|
40
|
+
export function Chip({
|
|
41
|
+
className,
|
|
42
|
+
label,
|
|
43
|
+
children,
|
|
44
|
+
icon,
|
|
45
|
+
avatar,
|
|
46
|
+
trailingIcon,
|
|
47
|
+
trailingContent,
|
|
48
|
+
intent = "default",
|
|
49
|
+
iconColor = "default",
|
|
50
|
+
interactive = false,
|
|
51
|
+
pressed,
|
|
52
|
+
disabled,
|
|
53
|
+
onClick,
|
|
54
|
+
removable = false,
|
|
55
|
+
onRemove,
|
|
56
|
+
removeButtonLabel = "Remove",
|
|
57
|
+
...props
|
|
58
|
+
}: ChipProps) {
|
|
59
|
+
const isButton = interactive || pressed !== undefined;
|
|
60
|
+
const Root = isButton ? "button" : "span";
|
|
61
|
+
// Intent colouring yields to the pressed fill and to the disabled state.
|
|
62
|
+
const tinted = !pressed && !disabled;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<span className={cn("relative inline-flex max-w-full", className)}>
|
|
66
|
+
<Root
|
|
67
|
+
type={isButton ? "button" : undefined}
|
|
68
|
+
disabled={isButton ? disabled : undefined}
|
|
69
|
+
aria-pressed={pressed !== undefined ? pressed : undefined}
|
|
70
|
+
onClick={onClick}
|
|
71
|
+
className={cn(
|
|
72
|
+
"peer inline-flex h-8 max-w-full flex-col overflow-hidden rounded-[1.25rem] p-0",
|
|
73
|
+
"border border-border bg-surface-raised-50 text-sm leading-5 font-medium text-subdued backdrop-blur-s",
|
|
74
|
+
isButton && [
|
|
75
|
+
"cursor-pointer disabled:cursor-default disabled:text-disabled",
|
|
76
|
+
"not-disabled:hover:bg-surface-raised-50-hovered not-disabled:active:bg-surface-raised-50-pressed",
|
|
77
|
+
"outline-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-focus",
|
|
78
|
+
],
|
|
79
|
+
tinted && intent === "critical" && "border-border-critical text-critical",
|
|
80
|
+
tinted && intent === "highlight" && "border-border-highlight text-highlight",
|
|
81
|
+
pressed && [
|
|
82
|
+
"border-primary bg-primary text-on-primary",
|
|
83
|
+
"not-disabled:hover:border-primary-hovered not-disabled:hover:bg-primary-hovered",
|
|
84
|
+
"not-disabled:active:border-primary-pressed not-disabled:active:bg-primary-pressed",
|
|
85
|
+
"disabled:border-primary-disabled disabled:bg-primary-disabled disabled:text-disabled",
|
|
86
|
+
],
|
|
87
|
+
)}
|
|
88
|
+
{...props}
|
|
89
|
+
>
|
|
90
|
+
<span className={cn("inline-flex h-full max-w-full items-center px-3", removable && "pr-8")}>
|
|
91
|
+
{avatar && (
|
|
92
|
+
<span className="-ml-2 mr-1 inline-flex size-6 shrink-0 items-center overflow-hidden">
|
|
93
|
+
{avatar}
|
|
94
|
+
</span>
|
|
95
|
+
)}
|
|
96
|
+
{icon && !avatar && (
|
|
97
|
+
<span
|
|
98
|
+
className={cn(
|
|
99
|
+
"-ml-1.5 mr-1 inline-flex shrink-0 items-center [&>svg]:size-5",
|
|
100
|
+
pressed
|
|
101
|
+
? "text-on-primary"
|
|
102
|
+
: disabled && isButton
|
|
103
|
+
? "text-disabled"
|
|
104
|
+
: tinted && intent === "critical"
|
|
105
|
+
? "text-critical"
|
|
106
|
+
: (tinted && intent === "highlight") || iconColor === "highlight"
|
|
107
|
+
? "text-highlight"
|
|
108
|
+
: "text-icon-default",
|
|
109
|
+
)}
|
|
110
|
+
>
|
|
111
|
+
{icon}
|
|
112
|
+
</span>
|
|
113
|
+
)}
|
|
114
|
+
<span className="grow truncate">{label ?? children}</span>
|
|
115
|
+
{trailingIcon && (
|
|
116
|
+
<span className="ml-2 inline-flex shrink-0 [&>svg]:size-5">{trailingIcon}</span>
|
|
117
|
+
)}
|
|
118
|
+
{trailingContent && <span className="ml-2 inline-flex shrink-0">{trailingContent}</span>}
|
|
119
|
+
</span>
|
|
120
|
+
</Root>
|
|
121
|
+
{removable && (
|
|
122
|
+
<button
|
|
123
|
+
type="button"
|
|
124
|
+
aria-label={removeButtonLabel}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
onClick={onRemove}
|
|
127
|
+
className={cn(
|
|
128
|
+
"absolute top-1 right-1 inline-flex size-6 cursor-pointer items-center justify-center rounded-full p-0",
|
|
129
|
+
"bg-transparent text-icon-default outline-none disabled:cursor-default disabled:text-disabled",
|
|
130
|
+
"not-disabled:hover:bg-state-hovered not-disabled:active:bg-state-pressed",
|
|
131
|
+
"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-focus",
|
|
132
|
+
tinted && intent === "critical" && "text-critical",
|
|
133
|
+
tinted && intent === "highlight" && "text-highlight",
|
|
134
|
+
// On a pressed chip the button shares the fill, following the
|
|
135
|
+
// chip's own hover and press.
|
|
136
|
+
pressed && [
|
|
137
|
+
"bg-primary text-on-primary not-disabled:hover:bg-primary-hovered not-disabled:active:bg-primary-pressed",
|
|
138
|
+
"peer-hover:bg-primary-hovered peer-active:bg-primary-pressed",
|
|
139
|
+
"disabled:bg-transparent",
|
|
140
|
+
],
|
|
141
|
+
)}
|
|
142
|
+
>
|
|
143
|
+
<svg viewBox="0 0 24 24" className="size-5" aria-hidden focusable={false}>
|
|
144
|
+
<path
|
|
145
|
+
d="M12 13.6L7.19999 18.4C6.98333 18.6167 6.71666 18.725 6.39999 18.725C6.08333 18.725 5.81666 18.6167 5.59999 18.4C5.38333 18.1834 5.27499 17.9167 5.27499 17.6C5.27499 17.2834 5.38333 17.0167 5.59999 16.8L10.4 12L5.59999 7.20002C5.38333 6.98336 5.27499 6.71669 5.27499 6.40002C5.27499 6.08336 5.38333 5.81669 5.59999 5.60002C5.81666 5.38336 6.08333 5.27502 6.39999 5.27502C6.71666 5.27502 6.98333 5.38336 7.19999 5.60002L12 10.4L16.8 5.60002C17.0167 5.38336 17.2833 5.27502 17.6 5.27502C17.9167 5.27502 18.1833 5.38336 18.4 5.60002C18.6167 5.81669 18.725 6.08336 18.725 6.40002C18.725 6.71669 18.6167 6.98336 18.4 7.20002L13.6 12L18.4 16.8C18.6167 17.0167 18.725 17.2834 18.725 17.6C18.725 17.9167 18.6167 18.1834 18.4 18.4C18.1833 18.6167 17.9167 18.725 17.6 18.725C17.2833 18.725 17.0167 18.6167 16.8 18.4L12 13.6Z"
|
|
146
|
+
fill="currentColor"
|
|
147
|
+
/>
|
|
148
|
+
</svg>
|
|
149
|
+
</button>
|
|
150
|
+
)}
|
|
151
|
+
</span>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { HexColorPicker } from "react-colorful";
|
|
3
|
+
import { cn } from "../lib/utils";
|
|
4
|
+
import { useField } from "../lib/field-context";
|
|
5
|
+
import { Input, type InputProps } from "./input";
|
|
6
|
+
import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "./popover";
|
|
7
|
+
|
|
8
|
+
export interface ColorInputProps
|
|
9
|
+
extends Omit<InputProps, "value" | "defaultValue" | "onChange" | "type" | "prefix" | "suffix" | "maxLength"> {
|
|
10
|
+
/** A hex colour such as "#0037af". */
|
|
11
|
+
value?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
/** Called with the text as it is typed, and with each colour picked. */
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
/** Accessible name of the swatch that opens the picker. */
|
|
16
|
+
pickerButtonLabel?: string;
|
|
17
|
+
/** Accessible name of the picker popover. */
|
|
18
|
+
pickerLabel?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Swirl's colour input: a hex field with a swatch that opens a colour
|
|
23
|
+
* picker. Put it in a `FormControl`.
|
|
24
|
+
*
|
|
25
|
+
* <FormControl label="Brand colour">
|
|
26
|
+
* <ColorInput defaultValue="#0037af" />
|
|
27
|
+
* </FormControl>
|
|
28
|
+
*
|
|
29
|
+
* The picker is react-colorful's, from the author of the vanilla-colorful
|
|
30
|
+
* picker Swirl uses.
|
|
31
|
+
*/
|
|
32
|
+
export function ColorInput({
|
|
33
|
+
value: valueProp,
|
|
34
|
+
defaultValue,
|
|
35
|
+
onValueChange,
|
|
36
|
+
pickerButtonLabel = "Open color picker",
|
|
37
|
+
pickerLabel = "Color picker",
|
|
38
|
+
disabled: disabledProp,
|
|
39
|
+
readOnly: readOnlyProp,
|
|
40
|
+
className,
|
|
41
|
+
...props
|
|
42
|
+
}: ColorInputProps) {
|
|
43
|
+
const field = useField();
|
|
44
|
+
const disabled = disabledProp ?? field?.disabled ?? false;
|
|
45
|
+
const readOnly = readOnlyProp ?? field?.readOnly ?? false;
|
|
46
|
+
const [uncontrolled, setUncontrolled] = React.useState(defaultValue ?? "");
|
|
47
|
+
const value = valueProp ?? uncontrolled;
|
|
48
|
+
|
|
49
|
+
const update = (next: string) => {
|
|
50
|
+
if (valueProp === undefined) setUncontrolled(next);
|
|
51
|
+
onValueChange?.(next);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const compact = field ? field.inline || field.labelPosition === "outside" : true;
|
|
55
|
+
const collapsed = Boolean(field && !compact && field.labelAsPlaceholder);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Popover>
|
|
59
|
+
<PopoverAnchor asChild>
|
|
60
|
+
<div className="relative flex w-full cursor-text items-center">
|
|
61
|
+
<Input
|
|
62
|
+
{...props}
|
|
63
|
+
type="text"
|
|
64
|
+
maxLength={7}
|
|
65
|
+
spellCheck={false}
|
|
66
|
+
autoComplete="off"
|
|
67
|
+
value={value}
|
|
68
|
+
onChange={(event) => update(event.target.value)}
|
|
69
|
+
disabled={disabled}
|
|
70
|
+
readOnly={readOnly}
|
|
71
|
+
// Unlike a text input, Swirl greys this one out fully when disabled.
|
|
72
|
+
className={cn("grow disabled:text-disabled", className)}
|
|
73
|
+
/>
|
|
74
|
+
<PopoverTrigger asChild>
|
|
75
|
+
<button
|
|
76
|
+
type="button"
|
|
77
|
+
aria-label={pickerButtonLabel}
|
|
78
|
+
disabled={readOnly}
|
|
79
|
+
// The swatch shows the colour. Swirl blanks it when disabled (its
|
|
80
|
+
// --s-border-subdued token doesn't exist, so it renders transparent).
|
|
81
|
+
style={{ backgroundColor: disabled ? "transparent" : value || undefined }}
|
|
82
|
+
className={cn(
|
|
83
|
+
"shrink-0 cursor-pointer appearance-none rounded-s border border-border p-0",
|
|
84
|
+
"outline-offset-2 outline-focus focus:not-focus-visible:outline-none focus-visible:outline-2 focus-visible:outline-solid",
|
|
85
|
+
// Swirl's 44px swatch rides up into the label's row; a compact field gets a small one.
|
|
86
|
+
compact ? "-my-0.5 -mr-1 size-6" : "-mt-5 size-11",
|
|
87
|
+
collapsed && "invisible",
|
|
88
|
+
)}
|
|
89
|
+
/>
|
|
90
|
+
</PopoverTrigger>
|
|
91
|
+
</div>
|
|
92
|
+
</PopoverAnchor>
|
|
93
|
+
<PopoverContent label={pickerLabel} align="end" padded={false} className="flex justify-center px-4 py-2">
|
|
94
|
+
<HexColorPicker color={value || "#000000"} onChange={update} />
|
|
95
|
+
</PopoverContent>
|
|
96
|
+
</Popover>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
import { Glyph } from "../lib/glyphs";
|
|
4
|
+
import { Tooltip } from "./tooltip";
|
|
5
|
+
|
|
6
|
+
export interface DataCellProps extends Omit<React.ComponentProps<"div">, "content"> {
|
|
7
|
+
label?: React.ReactNode;
|
|
8
|
+
value?: React.ReactNode;
|
|
9
|
+
/** An info icon after the label, with this tooltip. */
|
|
10
|
+
tooltip?: React.ReactNode;
|
|
11
|
+
/** Before the label, such as a small avatar. */
|
|
12
|
+
media?: React.ReactNode;
|
|
13
|
+
/** After the value, such as a tag or buttons. */
|
|
14
|
+
suffix?: React.ReactNode;
|
|
15
|
+
/** A control in place of the value, such as an input. */
|
|
16
|
+
content?: React.ReactNode;
|
|
17
|
+
intent?: "default" | "subdued" | "info" | "critical" | "warning" | "success" | "special" | "translucent";
|
|
18
|
+
size?: "s" | "m";
|
|
19
|
+
/** Stack the label over the value at every width, not only on phones. */
|
|
20
|
+
vertical?: boolean;
|
|
21
|
+
/** Makes the cell a button. */
|
|
22
|
+
interactive?: boolean;
|
|
23
|
+
/** Makes the cell a link. */
|
|
24
|
+
href?: string;
|
|
25
|
+
linkTarget?: string;
|
|
26
|
+
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const intents = {
|
|
30
|
+
default: "bg-surface-raised-50",
|
|
31
|
+
subdued: "bg-surface-raised",
|
|
32
|
+
info: "bg-surface-info-subdued",
|
|
33
|
+
critical: "bg-surface-critical-subdued",
|
|
34
|
+
warning: "bg-surface-warning-subdued",
|
|
35
|
+
success: "bg-surface-success-subdued",
|
|
36
|
+
special: "bg-[var(--s-decorative-grape-surface-subdued)]",
|
|
37
|
+
translucent: "bg-[var(--s-surface-on-image-default)]",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Swirl's data cell: a label and its value on one tinted row, which stacks
|
|
42
|
+
* on phones. Group cells in a `DataCellStack`.
|
|
43
|
+
*
|
|
44
|
+
* <DataCell label="Email" value="ada@example.com" />
|
|
45
|
+
*/
|
|
46
|
+
export function DataCell({
|
|
47
|
+
label,
|
|
48
|
+
value,
|
|
49
|
+
tooltip,
|
|
50
|
+
media,
|
|
51
|
+
suffix,
|
|
52
|
+
content,
|
|
53
|
+
intent = "default",
|
|
54
|
+
size = "m",
|
|
55
|
+
vertical = false,
|
|
56
|
+
interactive = false,
|
|
57
|
+
href,
|
|
58
|
+
linkTarget,
|
|
59
|
+
onClick,
|
|
60
|
+
className,
|
|
61
|
+
...props
|
|
62
|
+
}: DataCellProps) {
|
|
63
|
+
const id = React.useId();
|
|
64
|
+
const isInteractive = interactive || Boolean(href);
|
|
65
|
+
const Tag = href ? "a" : interactive ? "button" : "div";
|
|
66
|
+
const hasLabel = label !== undefined && label !== null && label !== "";
|
|
67
|
+
const labelId = `${id}-label`;
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div data-data-cell="" data-size={size} className="block w-full" {...props}>
|
|
71
|
+
<Tag
|
|
72
|
+
{...(href ? { href, target: linkTarget, rel: linkTarget === "_blank" ? "noreferrer" : undefined } : {})}
|
|
73
|
+
{...(Tag === "button" ? { type: "button" as const } : {})}
|
|
74
|
+
onClick={onClick}
|
|
75
|
+
className={cn(
|
|
76
|
+
"flex w-full appearance-none items-center gap-2 border-0 px-4 py-3 text-left text-inherit no-underline",
|
|
77
|
+
size === "m"
|
|
78
|
+
? "rounded-[var(--data-cell-radius,var(--radius-l))]"
|
|
79
|
+
: "gap-1 rounded-[var(--data-cell-radius,var(--radius-s))] p-2",
|
|
80
|
+
intents[intent],
|
|
81
|
+
isInteractive &&
|
|
82
|
+
cn(
|
|
83
|
+
"relative cursor-pointer outline-focus focus:not-focus-visible:outline-none focus-visible:outline-2 focus-visible:outline-solid",
|
|
84
|
+
"after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:content-['']",
|
|
85
|
+
intent === "default"
|
|
86
|
+
? "hover:bg-surface-raised-50-hovered active:bg-surface-raised-50-pressed"
|
|
87
|
+
: "hover:after:bg-state-hovered active:after:bg-state-pressed",
|
|
88
|
+
),
|
|
89
|
+
className,
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
{media !== undefined && (
|
|
93
|
+
// Icon avatars sit on the page colour here, as in Swirl.
|
|
94
|
+
<div aria-hidden className="flex shrink-0 items-center [&_[data-avatar-icon]]:bg-surface">
|
|
95
|
+
{media}
|
|
96
|
+
</div>
|
|
97
|
+
)}
|
|
98
|
+
<div
|
|
99
|
+
className={cn(
|
|
100
|
+
"flex min-w-0 flex-1 justify-between",
|
|
101
|
+
size === "s" ? "gap-2" : "gap-6",
|
|
102
|
+
vertical
|
|
103
|
+
? "flex-col items-start gap-1"
|
|
104
|
+
: "max-md:flex-col max-md:items-start max-md:gap-1 md:items-center",
|
|
105
|
+
)}
|
|
106
|
+
>
|
|
107
|
+
{hasLabel && (
|
|
108
|
+
<div className={cn("min-w-0 shrink-0", !vertical && "md:w-[calc(160px+0.25rem+16px)]")}>
|
|
109
|
+
<span className="flex items-center gap-1">
|
|
110
|
+
<span
|
|
111
|
+
id={labelId}
|
|
112
|
+
role={isInteractive ? undefined : "term"}
|
|
113
|
+
className={cn(
|
|
114
|
+
"block text-sm leading-5 font-normal text-subdued",
|
|
115
|
+
!vertical && "max-w-40 truncate",
|
|
116
|
+
)}
|
|
117
|
+
>
|
|
118
|
+
{label}
|
|
119
|
+
</span>
|
|
120
|
+
{tooltip !== undefined && (
|
|
121
|
+
<Tooltip content={tooltip} side="right">
|
|
122
|
+
<span tabIndex={0} className="inline-flex size-4 shrink-0 text-subdued outline-focus focus-visible:outline-2 [&>svg]:size-full">
|
|
123
|
+
<Glyph name="info" />
|
|
124
|
+
</span>
|
|
125
|
+
</Tooltip>
|
|
126
|
+
)}
|
|
127
|
+
</span>
|
|
128
|
+
</div>
|
|
129
|
+
)}
|
|
130
|
+
{(content !== undefined || value !== undefined) && (
|
|
131
|
+
<div
|
|
132
|
+
role={isInteractive ? undefined : "definition"}
|
|
133
|
+
aria-labelledby={hasLabel && !isInteractive ? labelId : undefined}
|
|
134
|
+
className={cn(
|
|
135
|
+
"flex min-w-0 shrink items-center gap-1",
|
|
136
|
+
(vertical || !hasLabel) && "w-full",
|
|
137
|
+
vertical ? "flex-col items-start" : "max-md:flex-col max-md:items-start",
|
|
138
|
+
)}
|
|
139
|
+
>
|
|
140
|
+
{content !== undefined ? (
|
|
141
|
+
<div className="w-full">{content}</div>
|
|
142
|
+
) : (
|
|
143
|
+
<div
|
|
144
|
+
className={cn(
|
|
145
|
+
"min-w-0 flex-1 text-sm leading-5 text-foreground",
|
|
146
|
+
size === "s" ? "font-medium" : "font-semibold",
|
|
147
|
+
vertical ? "whitespace-normal" : "truncate",
|
|
148
|
+
)}
|
|
149
|
+
>
|
|
150
|
+
{value}
|
|
151
|
+
</div>
|
|
152
|
+
)}
|
|
153
|
+
</div>
|
|
154
|
+
)}
|
|
155
|
+
</div>
|
|
156
|
+
{suffix !== undefined && <div className="shrink-0">{suffix}</div>}
|
|
157
|
+
</Tag>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface DataCellStackProps extends React.ComponentProps<"div"> {
|
|
163
|
+
label?: React.ReactNode;
|
|
164
|
+
hideLabel?: boolean;
|
|
165
|
+
description?: React.ReactNode;
|
|
166
|
+
/** Actions in the header, such as Edit. */
|
|
167
|
+
cta?: React.ReactNode;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Swirl's data cell stack: `DataCell`s under a heading, joined into one
|
|
172
|
+
* block with large outer corners and small inner ones.
|
|
173
|
+
*/
|
|
174
|
+
export function DataCellStack({
|
|
175
|
+
label,
|
|
176
|
+
hideLabel = false,
|
|
177
|
+
description,
|
|
178
|
+
cta,
|
|
179
|
+
className,
|
|
180
|
+
children,
|
|
181
|
+
...props
|
|
182
|
+
}: DataCellStackProps) {
|
|
183
|
+
const id = React.useId();
|
|
184
|
+
const showLabel = label !== undefined && !hideLabel;
|
|
185
|
+
return (
|
|
186
|
+
<div role="group" className={cn("flex w-full flex-col gap-4", className)} {...props}>
|
|
187
|
+
{(showLabel || description !== undefined || cta !== undefined) && (
|
|
188
|
+
<header className="flex w-full items-start justify-between gap-2">
|
|
189
|
+
<div className="flex flex-col items-start gap-1">
|
|
190
|
+
{showLabel && (
|
|
191
|
+
<h3 id={`${id}-label`} className="m-0 text-base leading-6 font-semibold text-foreground">
|
|
192
|
+
{label}
|
|
193
|
+
</h3>
|
|
194
|
+
)}
|
|
195
|
+
{description !== undefined && (
|
|
196
|
+
<p id={`${id}-description`} className="m-0 text-sm leading-5 text-subdued">
|
|
197
|
+
{description}
|
|
198
|
+
</p>
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
{cta !== undefined && <div className="flex shrink-0 items-center">{cta}</div>}
|
|
202
|
+
</header>
|
|
203
|
+
)}
|
|
204
|
+
<div
|
|
205
|
+
role="list"
|
|
206
|
+
aria-labelledby={showLabel ? `${id}-label` : undefined}
|
|
207
|
+
aria-describedby={description !== undefined ? `${id}-description` : undefined}
|
|
208
|
+
className={cn(
|
|
209
|
+
"flex flex-col gap-0.5",
|
|
210
|
+
// Large outer corners, small inner ones; size s cells use base for the outer ones.
|
|
211
|
+
"[&>[data-data-cell]:first-child:not(:last-child)]:[--data-cell-radius:var(--radius-l)_var(--radius-l)_var(--radius-s)_var(--radius-s)]",
|
|
212
|
+
"[&>[data-data-cell]:last-child:not(:first-child)]:[--data-cell-radius:var(--radius-s)_var(--radius-s)_var(--radius-l)_var(--radius-l)]",
|
|
213
|
+
"[&>[data-data-cell]:not(:first-child):not(:last-child)]:[--data-cell-radius:var(--radius-s)]",
|
|
214
|
+
"[&>[data-data-cell][data-size=s]:first-child:not(:last-child)]:[--data-cell-radius:var(--radius-base)_var(--radius-base)_var(--radius-s)_var(--radius-s)]",
|
|
215
|
+
"[&>[data-data-cell][data-size=s]:last-child:not(:first-child)]:[--data-cell-radius:var(--radius-s)_var(--radius-s)_var(--radius-base)_var(--radius-base)]",
|
|
216
|
+
"[&>[data-data-cell][data-size=s]:first-child:last-child]:[--data-cell-radius:var(--radius-base)]",
|
|
217
|
+
)}
|
|
218
|
+
>
|
|
219
|
+
{React.Children.map(children, (child) =>
|
|
220
|
+
React.isValidElement(child) ? <DataCellListItem>{child}</DataCellListItem> : child,
|
|
221
|
+
)}
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Gives each cell in a stack the list item role, keeping its data attributes on the outside. */
|
|
228
|
+
function DataCellListItem({ children }: { children: React.ReactElement }) {
|
|
229
|
+
return React.cloneElement(children as React.ReactElement<{ role?: string }>, { role: "listitem" });
|
|
230
|
+
}
|