@enablo/swirlcn-ui 0.0.0-stage → 0.5.1
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,336 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
import { Button } from "./button";
|
|
4
|
+
|
|
5
|
+
const glyph = (d: string) => (
|
|
6
|
+
<svg viewBox="0 0 24 24" aria-hidden focusable={false}>
|
|
7
|
+
<path d={d} fill="currentColor" />
|
|
8
|
+
</svg>
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const DoubleArrowLeftIcon = () => glyph("M16.475 17.3067L11.875 12.7067C11.775 12.6067 11.7043 12.4983 11.663 12.3817C11.621 12.265 11.6 12.14 11.6 12.0067C11.6 11.8733 11.621 11.7483 11.663 11.6317C11.7043 11.515 11.775 11.4067 11.875 11.3067L16.475 6.70667C16.6583 6.52334 16.8873 6.42734 17.162 6.41867C17.4373 6.41067 17.675 6.50667 17.875 6.70667C18.0583 6.89001 18.15 7.12334 18.15 7.40667C18.15 7.69001 18.0583 7.92334 17.875 8.10667L14 12.0067L17.875 15.9067C18.0583 16.09 18.154 16.319 18.162 16.5937C18.1707 16.869 18.075 17.1067 17.875 17.3067C17.6917 17.49 17.4583 17.5817 17.175 17.5817C16.8917 17.5817 16.6583 17.49 16.475 17.3067ZM9.875 17.3067L5.275 12.7067C5.175 12.6067 5.10433 12.4983 5.063 12.3817C5.021 12.265 5 12.14 5 12.0067C5 11.8733 5.021 11.7483 5.063 11.6317C5.10433 11.515 5.175 11.4067 5.275 11.3067L9.875 6.70667C10.0583 6.52334 10.2877 6.42734 10.563 6.41867C10.8377 6.41067 11.075 6.50667 11.275 6.70667C11.4583 6.89001 11.55 7.12334 11.55 7.40667C11.55 7.69001 11.4583 7.92334 11.275 8.10667L7.4 12.0067L11.275 15.9067C11.4583 16.09 11.5543 16.319 11.563 16.5937C11.571 16.869 11.475 17.1067 11.275 17.3067C11.0917 17.49 10.8583 17.5817 10.575 17.5817C10.2917 17.5817 10.0583 17.49 9.875 17.3067Z");
|
|
12
|
+
const DoubleArrowRightIcon = () => glyph("M6.12754 17.2937C5.94421 17.1104 5.85254 16.877 5.85254 16.5937C5.85254 16.3104 5.94421 16.077 6.12754 15.8937L10.0025 11.9937L6.12754 8.0937C5.94421 7.91037 5.84854 7.68103 5.84054 7.4057C5.83187 7.13103 5.92754 6.8937 6.12754 6.6937C6.31087 6.51037 6.54421 6.4187 6.82754 6.4187C7.11087 6.4187 7.34421 6.51037 7.52754 6.6937L12.1275 11.2937C12.2275 11.3937 12.2985 11.502 12.3405 11.6187C12.3819 11.7354 12.4025 11.8604 12.4025 11.9937C12.4025 12.127 12.3819 12.252 12.3405 12.3687C12.2985 12.4854 12.2275 12.5937 12.1275 12.6937L7.52754 17.2937C7.34421 17.477 7.11487 17.5727 6.83954 17.5807C6.56487 17.5894 6.32754 17.4937 6.12754 17.2937ZM12.7275 17.2937C12.5442 17.1104 12.4525 16.877 12.4525 16.5937C12.4525 16.3104 12.5442 16.077 12.7275 15.8937L16.6025 11.9937L12.7275 8.0937C12.5442 7.91037 12.4482 7.68103 12.4395 7.4057C12.4315 7.13103 12.5275 6.8937 12.7275 6.6937C12.9109 6.51037 13.1442 6.4187 13.4275 6.4187C13.7109 6.4187 13.9442 6.51037 14.1275 6.6937L18.7275 11.2937C18.8275 11.3937 18.8982 11.502 18.9395 11.6187C18.9815 11.7354 19.0025 11.8604 19.0025 11.9937C19.0025 12.127 18.9815 12.252 18.9395 12.3687C18.8982 12.4854 18.8275 12.5937 18.7275 12.6937L14.1275 17.2937C13.9442 17.477 13.7152 17.5727 13.4405 17.5807C13.1652 17.5894 12.9275 17.4937 12.7275 17.2937Z");
|
|
13
|
+
const ChevronLeftIcon = () => glyph("M13.2 17.4L8.59999 12.8C8.48333 12.6834 8.39999 12.5584 8.34999 12.425C8.29999 12.2917 8.27499 12.15 8.27499 12C8.27499 11.85 8.29999 11.7084 8.34999 11.575C8.39999 11.4417 8.48333 11.3167 8.59999 11.2L13.2 6.60002C13.4167 6.38336 13.6833 6.27502 14 6.27502C14.3167 6.27502 14.5833 6.38336 14.8 6.60002C15.0167 6.81669 15.125 7.08336 15.125 7.40002C15.125 7.71669 15.0167 7.98336 14.8 8.20002L11 12L14.8 15.8C15.0167 16.0167 15.125 16.2834 15.125 16.6C15.125 16.9167 15.0167 17.1834 14.8 17.4C14.5833 17.6167 14.3167 17.725 14 17.725C13.6833 17.725 13.4167 17.6167 13.2 17.4Z");
|
|
14
|
+
const ChevronRightIcon = () => glyph("M8.59999 17.4C8.38333 17.1834 8.27499 16.9167 8.27499 16.6C8.27499 16.2834 8.38333 16.0167 8.59999 15.8L12.4 12L8.59999 8.20002C8.38333 7.98336 8.27499 7.71669 8.27499 7.40002C8.27499 7.08336 8.38333 6.81669 8.59999 6.60002C8.81666 6.38336 9.08333 6.27502 9.39999 6.27502C9.71666 6.27502 9.98333 6.38336 10.2 6.60002L14.8 11.2C14.9167 11.3167 15 11.4417 15.05 11.575C15.1 11.7084 15.125 11.85 15.125 12C15.125 12.15 15.1 12.2917 15.05 12.425C15 12.5584 14.9167 12.6834 14.8 12.8L10.2 17.4C9.98333 17.6167 9.71666 17.725 9.39999 17.725C9.08333 17.725 8.81666 17.6167 8.59999 17.4Z");
|
|
15
|
+
const ExpandMoreIcon = () => (
|
|
16
|
+
<svg
|
|
17
|
+
viewBox="0 0 16 16"
|
|
18
|
+
className="pointer-events-none absolute top-1/2 right-0 size-4 -translate-y-1/2"
|
|
19
|
+
aria-hidden
|
|
20
|
+
focusable={false}
|
|
21
|
+
>
|
|
22
|
+
<path
|
|
23
|
+
d="M7.99999 10.05C7.89999 10.05 7.80554 10.0334 7.71665 10C7.62777 9.9667 7.54443 9.9167 7.46665 9.85003L4.38332 6.7667C4.23888 6.62225 4.16954 6.44714 4.17532 6.24137C4.18065 6.03603 4.25554 5.86114 4.39999 5.7167C4.54443 5.57225 4.72221 5.50003 4.93332 5.50003C5.14443 5.50003 5.32221 5.57225 5.46665 5.7167L7.99999 8.25003L10.55 5.70003C10.6944 5.55559 10.8695 5.48625 11.0753 5.49203C11.2807 5.49737 11.4555 5.57225 11.6 5.7167C11.7444 5.86114 11.8167 6.03892 11.8167 6.25003C11.8167 6.46114 11.7444 6.63892 11.6 6.78337L8.53332 9.85003C8.45554 9.9167 8.37221 9.9667 8.28332 10C8.19443 10.0334 8.09999 10.05 7.99999 10.05Z"
|
|
24
|
+
fill="currentColor"
|
|
25
|
+
/>
|
|
26
|
+
</svg>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export interface PaginationProps extends Omit<React.ComponentProps<"nav">, "onChange"> {
|
|
30
|
+
/** Current page, 1-based. */
|
|
31
|
+
page: number;
|
|
32
|
+
/** Total number of pages. */
|
|
33
|
+
pageCount: number;
|
|
34
|
+
onPageChange: (page: number) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Swirl's variants: `default` shows "3 out of 20" between the buttons,
|
|
37
|
+
* `simple` only the buttons, and `advanced` a field to type a page into.
|
|
38
|
+
* `numbered` is a row of page buttons, which Swirl does not have.
|
|
39
|
+
*/
|
|
40
|
+
variant?: "default" | "simple" | "advanced" | "numbered";
|
|
41
|
+
/** Show the "Items per page" select before the buttons. */
|
|
42
|
+
showPageSizeSelect?: boolean;
|
|
43
|
+
pageSize?: number;
|
|
44
|
+
pageSizeOptions?: number[];
|
|
45
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
46
|
+
/** How many page buttons to show around the current page, with `numbered`. */
|
|
47
|
+
siblingCount?: number;
|
|
48
|
+
label?: string;
|
|
49
|
+
firstPageLabel?: string;
|
|
50
|
+
previousLabel?: string;
|
|
51
|
+
nextLabel?: string;
|
|
52
|
+
lastPageLabel?: string;
|
|
53
|
+
/** The word between the page and the page count: "3 out of 20". */
|
|
54
|
+
pageLabel?: string;
|
|
55
|
+
/** Accessible name of the page field in the `advanced` variant. */
|
|
56
|
+
pageSelectLabel?: string;
|
|
57
|
+
pageSizeSelectLabel?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Swirl's pagination: first, previous, next and last page buttons around the
|
|
62
|
+
* current page. It renders even with one page, with every button disabled.
|
|
63
|
+
*/
|
|
64
|
+
export function Pagination({
|
|
65
|
+
className,
|
|
66
|
+
page,
|
|
67
|
+
pageCount,
|
|
68
|
+
onPageChange,
|
|
69
|
+
variant = "default",
|
|
70
|
+
showPageSizeSelect = false,
|
|
71
|
+
pageSize = 10,
|
|
72
|
+
pageSizeOptions = [10, 25, 50],
|
|
73
|
+
onPageSizeChange,
|
|
74
|
+
siblingCount = 1,
|
|
75
|
+
label = "Pagination",
|
|
76
|
+
firstPageLabel = "First page",
|
|
77
|
+
previousLabel = "Previous page",
|
|
78
|
+
nextLabel = "Next page",
|
|
79
|
+
lastPageLabel = "Last page",
|
|
80
|
+
pageLabel = "out of",
|
|
81
|
+
pageSelectLabel = "Select a page",
|
|
82
|
+
pageSizeSelectLabel = "Items per page:",
|
|
83
|
+
...props
|
|
84
|
+
}: PaginationProps) {
|
|
85
|
+
if (variant === "numbered") {
|
|
86
|
+
return (
|
|
87
|
+
<NumberedPagination
|
|
88
|
+
className={className}
|
|
89
|
+
page={page}
|
|
90
|
+
pageCount={pageCount}
|
|
91
|
+
onPageChange={onPageChange}
|
|
92
|
+
siblingCount={siblingCount}
|
|
93
|
+
label={label}
|
|
94
|
+
previousLabel={previousLabel}
|
|
95
|
+
nextLabel={nextLabel}
|
|
96
|
+
{...props}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const go = (to: number) => {
|
|
102
|
+
const next = Math.min(Math.max(to, 1), pageCount);
|
|
103
|
+
if (next !== page) onPageChange(next);
|
|
104
|
+
};
|
|
105
|
+
const pageText = `${page.toLocaleString()} ${pageLabel} ${pageCount.toLocaleString()}`;
|
|
106
|
+
const button = (buttonLabel: string, icon: React.ReactNode, disabled: boolean, to: number) => (
|
|
107
|
+
<li>
|
|
108
|
+
<Button
|
|
109
|
+
intent="primary"
|
|
110
|
+
hideLabel
|
|
111
|
+
label={buttonLabel}
|
|
112
|
+
icon={icon}
|
|
113
|
+
disabled={disabled}
|
|
114
|
+
onClick={() => go(to)}
|
|
115
|
+
/>
|
|
116
|
+
</li>
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<nav aria-label={label} className={cn("block w-fit", className)} {...props}>
|
|
121
|
+
<ul className="m-0 flex list-none items-center justify-start p-0 leading-6 desktop:text-sm desktop:leading-5">
|
|
122
|
+
{showPageSizeSelect && (
|
|
123
|
+
<li>
|
|
124
|
+
<label className="flex shrink-0 items-center gap-2 pr-6 whitespace-nowrap">
|
|
125
|
+
<span className="text-foreground">{pageSizeSelectLabel}</span>
|
|
126
|
+
<span className="relative flex items-center text-interactive-primary">
|
|
127
|
+
<select
|
|
128
|
+
className={cn(
|
|
129
|
+
"cursor-pointer appearance-none border-none bg-transparent pr-5 font-medium text-inherit",
|
|
130
|
+
"outline-focus focus:not-focus-visible:outline-none",
|
|
131
|
+
)}
|
|
132
|
+
value={pageSize}
|
|
133
|
+
onChange={(event) => {
|
|
134
|
+
const next = Number(event.target.value);
|
|
135
|
+
if (next !== pageSize) onPageSizeChange?.(next);
|
|
136
|
+
}}
|
|
137
|
+
>
|
|
138
|
+
{pageSizeOptions.map((option) => (
|
|
139
|
+
<option key={option} value={option}>
|
|
140
|
+
{option}
|
|
141
|
+
</option>
|
|
142
|
+
))}
|
|
143
|
+
</select>
|
|
144
|
+
<ExpandMoreIcon />
|
|
145
|
+
</span>
|
|
146
|
+
</label>
|
|
147
|
+
</li>
|
|
148
|
+
)}
|
|
149
|
+
{button(firstPageLabel, <DoubleArrowLeftIcon />, page <= 1, 1)}
|
|
150
|
+
{button(previousLabel, <ChevronLeftIcon />, page <= 1, page - 1)}
|
|
151
|
+
{variant === "simple" ? (
|
|
152
|
+
<li className="sr-only">
|
|
153
|
+
<span aria-current="page">{pageText}</span>
|
|
154
|
+
</li>
|
|
155
|
+
) : (
|
|
156
|
+
<li className="px-2">
|
|
157
|
+
{variant === "advanced" ? (
|
|
158
|
+
<span aria-current="page" className="flex items-center gap-2 whitespace-nowrap">
|
|
159
|
+
<PageInput page={page} pageCount={pageCount} label={pageSelectLabel} onPage={go} />
|
|
160
|
+
<span aria-hidden>
|
|
161
|
+
{pageLabel} {pageCount.toLocaleString()}
|
|
162
|
+
</span>
|
|
163
|
+
</span>
|
|
164
|
+
) : (
|
|
165
|
+
<span aria-current="page">{pageText}</span>
|
|
166
|
+
)}
|
|
167
|
+
</li>
|
|
168
|
+
)}
|
|
169
|
+
{button(nextLabel, <ChevronRightIcon />, page >= pageCount, page + 1)}
|
|
170
|
+
{button(lastPageLabel, <DoubleArrowRightIcon />, page >= pageCount, pageCount)}
|
|
171
|
+
</ul>
|
|
172
|
+
</nav>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The `advanced` variant's page field. Out-of-range entries snap to the
|
|
178
|
+
* nearest page, and the page changes half a second after typing stops.
|
|
179
|
+
*/
|
|
180
|
+
function PageInput({
|
|
181
|
+
page,
|
|
182
|
+
pageCount,
|
|
183
|
+
label,
|
|
184
|
+
onPage,
|
|
185
|
+
}: {
|
|
186
|
+
page: number;
|
|
187
|
+
pageCount: number;
|
|
188
|
+
label: string;
|
|
189
|
+
onPage: (page: number) => void;
|
|
190
|
+
}) {
|
|
191
|
+
const [draft, setDraft] = React.useState(String(page));
|
|
192
|
+
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
|
|
193
|
+
|
|
194
|
+
// Show the new page when it changes from outside, adjusting state during
|
|
195
|
+
// render rather than in an effect, so there is no extra render with the
|
|
196
|
+
// old number.
|
|
197
|
+
const [shownPage, setShownPage] = React.useState(page);
|
|
198
|
+
if (page !== shownPage) {
|
|
199
|
+
setShownPage(page);
|
|
200
|
+
setDraft(String(page));
|
|
201
|
+
}
|
|
202
|
+
React.useEffect(() => () => clearTimeout(timer.current), []);
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<input
|
|
206
|
+
type="text"
|
|
207
|
+
inputMode="numeric"
|
|
208
|
+
aria-label={label}
|
|
209
|
+
value={draft}
|
|
210
|
+
className={cn(
|
|
211
|
+
"inline-flex w-13 rounded-sm border-none bg-transparent p-2 text-center leading-6 text-inherit",
|
|
212
|
+
"shadow-[inset_0_0_0_1px_var(--color-border-strong)] desktop:text-sm desktop:leading-5",
|
|
213
|
+
"outline-focus focus:not-focus-visible:outline-none",
|
|
214
|
+
)}
|
|
215
|
+
onFocus={(event) => event.target.select()}
|
|
216
|
+
onChange={(event) => {
|
|
217
|
+
clearTimeout(timer.current);
|
|
218
|
+
const text = event.target.value.trim();
|
|
219
|
+
// Let the field be cleared while typing a new number.
|
|
220
|
+
if (text === "") return setDraft("");
|
|
221
|
+
let next = Number(text);
|
|
222
|
+
if (Number.isNaN(next)) next = page;
|
|
223
|
+
next = Math.min(Math.max(Math.trunc(next), 1), pageCount);
|
|
224
|
+
setDraft(String(next));
|
|
225
|
+
if (next !== page) timer.current = setTimeout(() => onPage(next), 500);
|
|
226
|
+
}}
|
|
227
|
+
onBlur={() => {
|
|
228
|
+
if (draft === "") setDraft(String(page));
|
|
229
|
+
}}
|
|
230
|
+
/>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* ------------------------------------------------------------- numbered */
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Builds the page list, collapsing long ranges with ellipses.
|
|
238
|
+
*
|
|
239
|
+
* Always returns first and last page plus a window around the current one, so
|
|
240
|
+
* the control's width stays stable as the user moves through the pages.
|
|
241
|
+
*/
|
|
242
|
+
function pageItems(page: number, pageCount: number, siblingCount: number): (number | "gap")[] {
|
|
243
|
+
// first + last + current + 2 ellipses + the window either side
|
|
244
|
+
const slots = siblingCount * 2 + 5;
|
|
245
|
+
if (pageCount <= slots) return Array.from({ length: pageCount }, (_, i) => i + 1);
|
|
246
|
+
|
|
247
|
+
const left = Math.max(page - siblingCount, 1);
|
|
248
|
+
const right = Math.min(page + siblingCount, pageCount);
|
|
249
|
+
|
|
250
|
+
const showLeftGap = left > 2;
|
|
251
|
+
const showRightGap = right < pageCount - 1;
|
|
252
|
+
|
|
253
|
+
const items: (number | "gap")[] = [1];
|
|
254
|
+
if (showLeftGap) items.push("gap");
|
|
255
|
+
|
|
256
|
+
for (let i = showLeftGap ? left : 2; i <= (showRightGap ? right : pageCount - 1); i++) {
|
|
257
|
+
items.push(i);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (showRightGap) items.push("gap");
|
|
261
|
+
items.push(pageCount);
|
|
262
|
+
|
|
263
|
+
return items;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function NumberedPagination({
|
|
267
|
+
className,
|
|
268
|
+
page,
|
|
269
|
+
pageCount,
|
|
270
|
+
onPageChange,
|
|
271
|
+
siblingCount,
|
|
272
|
+
label,
|
|
273
|
+
previousLabel,
|
|
274
|
+
nextLabel,
|
|
275
|
+
...props
|
|
276
|
+
}: Omit<React.ComponentProps<"nav">, "onChange"> & {
|
|
277
|
+
page: number;
|
|
278
|
+
pageCount: number;
|
|
279
|
+
onPageChange: (page: number) => void;
|
|
280
|
+
siblingCount: number;
|
|
281
|
+
label: string;
|
|
282
|
+
previousLabel: string;
|
|
283
|
+
nextLabel: string;
|
|
284
|
+
}) {
|
|
285
|
+
if (pageCount <= 1) return null;
|
|
286
|
+
|
|
287
|
+
const items = pageItems(page, pageCount, siblingCount);
|
|
288
|
+
|
|
289
|
+
return (
|
|
290
|
+
<nav aria-label={label} className={cn("flex items-center gap-1", className)} {...props}>
|
|
291
|
+
<Button
|
|
292
|
+
variant="ghost"
|
|
293
|
+
size="s"
|
|
294
|
+
hideLabel
|
|
295
|
+
label={previousLabel}
|
|
296
|
+
icon={<ChevronLeftIcon />}
|
|
297
|
+
disabled={page <= 1}
|
|
298
|
+
onClick={() => onPageChange(page - 1)}
|
|
299
|
+
/>
|
|
300
|
+
|
|
301
|
+
{items.map((item, index) =>
|
|
302
|
+
item === "gap" ? (
|
|
303
|
+
<span
|
|
304
|
+
key={`gap-${index}`}
|
|
305
|
+
aria-hidden
|
|
306
|
+
className="px-1 text-sm text-subdued select-none"
|
|
307
|
+
>
|
|
308
|
+
…
|
|
309
|
+
</span>
|
|
310
|
+
) : (
|
|
311
|
+
<Button
|
|
312
|
+
key={item}
|
|
313
|
+
variant={item === page ? "flat" : "ghost"}
|
|
314
|
+
intent={item === page ? "primary" : "default"}
|
|
315
|
+
size="s"
|
|
316
|
+
label={String(item)}
|
|
317
|
+
aria-label={`Page ${item}`}
|
|
318
|
+
aria-current={item === page ? "page" : undefined}
|
|
319
|
+
onClick={() => onPageChange(item)}
|
|
320
|
+
className="min-w-8"
|
|
321
|
+
/>
|
|
322
|
+
),
|
|
323
|
+
)}
|
|
324
|
+
|
|
325
|
+
<Button
|
|
326
|
+
variant="ghost"
|
|
327
|
+
size="s"
|
|
328
|
+
hideLabel
|
|
329
|
+
label={nextLabel}
|
|
330
|
+
icon={<ChevronRightIcon />}
|
|
331
|
+
disabled={page >= pageCount}
|
|
332
|
+
onClick={() => onPageChange(page + 1)}
|
|
333
|
+
/>
|
|
334
|
+
</nav>
|
|
335
|
+
);
|
|
336
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Dialog as DialogPrimitive, Popover as PopoverPrimitive } from "radix-ui";
|
|
3
|
+
import { cn } from "../lib/utils";
|
|
4
|
+
import { useMobile } from "../lib/use-mobile";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Swirl's popover. On desktop it is a Radix popover; below 768px it becomes
|
|
8
|
+
* a bottom sheet over a backdrop, which this file builds from a Radix dialog
|
|
9
|
+
* so focus, Escape and outside clicks keep working. The parts read which one
|
|
10
|
+
* they are in from this context.
|
|
11
|
+
*/
|
|
12
|
+
const SheetContext = React.createContext(false);
|
|
13
|
+
|
|
14
|
+
export interface PopoverProps extends React.ComponentProps<typeof PopoverPrimitive.Root> {
|
|
15
|
+
/** Below 768px, open as a bottom sheet over a backdrop, as Swirl does. Defaults to true. */
|
|
16
|
+
mobileBottomSheet?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Popover({ mobileBottomSheet = true, ...props }: PopoverProps) {
|
|
20
|
+
const sheet = useMobile() && mobileBottomSheet;
|
|
21
|
+
return (
|
|
22
|
+
<SheetContext.Provider value={sheet}>
|
|
23
|
+
{sheet ? <DialogPrimitive.Root {...props} /> : <PopoverPrimitive.Root {...props} />}
|
|
24
|
+
</SheetContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function PopoverTrigger(props: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
|
29
|
+
return React.useContext(SheetContext) ? (
|
|
30
|
+
<DialogPrimitive.Trigger {...props} />
|
|
31
|
+
) : (
|
|
32
|
+
<PopoverPrimitive.Trigger {...props} />
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function PopoverClose(props: React.ComponentProps<typeof PopoverPrimitive.Close>) {
|
|
37
|
+
return React.useContext(SheetContext) ? (
|
|
38
|
+
<DialogPrimitive.Close {...props} />
|
|
39
|
+
) : (
|
|
40
|
+
<PopoverPrimitive.Close {...props} />
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Positions the popover against this element instead of the trigger. A plain wrapper in the sheet. */
|
|
45
|
+
export function PopoverAnchor({
|
|
46
|
+
asChild,
|
|
47
|
+
children,
|
|
48
|
+
...props
|
|
49
|
+
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
|
50
|
+
if (!React.useContext(SheetContext)) {
|
|
51
|
+
return (
|
|
52
|
+
<PopoverPrimitive.Anchor asChild={asChild} {...props}>
|
|
53
|
+
{children}
|
|
54
|
+
</PopoverPrimitive.Anchor>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return asChild ? children : <div {...props}>{children}</div>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Swirl's frosted surface: a see-through fill with a backdrop blur and a light outline. */
|
|
61
|
+
const translucentSurface = [
|
|
62
|
+
"bg-transparent outline-1 outline-border-translucent",
|
|
63
|
+
"before:absolute before:inset-0 before:-z-10 before:rounded-[inherit] before:bg-translucent-low before:backdrop-blur-l",
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
export interface PopoverContentProps
|
|
67
|
+
extends React.ComponentProps<typeof PopoverPrimitive.Content> {
|
|
68
|
+
/** Accessible name of the popover. Swirl requires one. */
|
|
69
|
+
label?: string;
|
|
70
|
+
/** Pad the content by 4px, as Swirl does for menus and lists. Defaults to true. */
|
|
71
|
+
padded?: boolean;
|
|
72
|
+
/** The frosted, see-through surface. Defaults to true, as in Swirl; false draws the solid overlay colour. */
|
|
73
|
+
translucent?: boolean;
|
|
74
|
+
/** Draw the small arrow pointing at the trigger. Desktop only; Swirl has no arrow. */
|
|
75
|
+
arrow?: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The popover's panel. `className` styles the scrolling body inside it, so
|
|
80
|
+
* padding, layout and width set there apply to the content.
|
|
81
|
+
*
|
|
82
|
+
* On desktop it opens under the trigger's start edge, up to 22.5rem wide and
|
|
83
|
+
* 22rem tall before it scrolls. Below 768px it slides up from the bottom.
|
|
84
|
+
*/
|
|
85
|
+
export function PopoverContent({
|
|
86
|
+
className,
|
|
87
|
+
label,
|
|
88
|
+
padded = true,
|
|
89
|
+
translucent = true,
|
|
90
|
+
arrow = false,
|
|
91
|
+
align = "start",
|
|
92
|
+
side,
|
|
93
|
+
sideOffset = 8,
|
|
94
|
+
alignOffset,
|
|
95
|
+
avoidCollisions,
|
|
96
|
+
collisionBoundary,
|
|
97
|
+
collisionPadding = 8,
|
|
98
|
+
arrowPadding,
|
|
99
|
+
sticky,
|
|
100
|
+
hideWhenDetached,
|
|
101
|
+
updatePositionStrategy,
|
|
102
|
+
children,
|
|
103
|
+
...props
|
|
104
|
+
}: PopoverContentProps) {
|
|
105
|
+
const sheet = React.useContext(SheetContext);
|
|
106
|
+
|
|
107
|
+
if (sheet) {
|
|
108
|
+
return (
|
|
109
|
+
<DialogPrimitive.Portal>
|
|
110
|
+
<DialogPrimitive.Overlay
|
|
111
|
+
className={cn(
|
|
112
|
+
"fixed inset-0 z-50 bg-black/20 duration-150",
|
|
113
|
+
"data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
|
114
|
+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0",
|
|
115
|
+
"motion-reduce:animate-none",
|
|
116
|
+
)}
|
|
117
|
+
/>
|
|
118
|
+
<DialogPrimitive.Content
|
|
119
|
+
aria-describedby={undefined}
|
|
120
|
+
className={cn(
|
|
121
|
+
"fixed inset-x-0 bottom-0 z-50 overflow-hidden rounded-t-xl text-foreground outline-none",
|
|
122
|
+
translucent ? translucentSurface : "bg-surface-overlay",
|
|
123
|
+
"duration-150 data-[state=open]:animate-in data-[state=open]:slide-in-from-bottom",
|
|
124
|
+
"data-[state=closed]:animate-out data-[state=closed]:slide-out-to-bottom",
|
|
125
|
+
"motion-reduce:animate-none",
|
|
126
|
+
)}
|
|
127
|
+
{...(props as React.ComponentProps<typeof DialogPrimitive.Content>)}
|
|
128
|
+
>
|
|
129
|
+
<DialogPrimitive.Title className="sr-only">{label ?? "Popover"}</DialogPrimitive.Title>
|
|
130
|
+
<span
|
|
131
|
+
aria-hidden
|
|
132
|
+
className={cn(
|
|
133
|
+
"absolute top-2 left-1/2 h-1.5 w-10 -translate-x-1/2 rounded-[0.1875rem]",
|
|
134
|
+
translucent ? "bg-[var(--s-border-on-translucent)]" : "bg-border",
|
|
135
|
+
)}
|
|
136
|
+
/>
|
|
137
|
+
<div
|
|
138
|
+
className={cn(
|
|
139
|
+
"max-h-[90vh] w-full overflow-x-hidden overflow-y-auto overscroll-contain py-6",
|
|
140
|
+
className,
|
|
141
|
+
)}
|
|
142
|
+
>
|
|
143
|
+
{children}
|
|
144
|
+
</div>
|
|
145
|
+
</DialogPrimitive.Content>
|
|
146
|
+
</DialogPrimitive.Portal>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<PopoverPrimitive.Portal>
|
|
152
|
+
<PopoverPrimitive.Content
|
|
153
|
+
aria-label={label}
|
|
154
|
+
align={align}
|
|
155
|
+
side={side}
|
|
156
|
+
sideOffset={sideOffset}
|
|
157
|
+
alignOffset={alignOffset}
|
|
158
|
+
avoidCollisions={avoidCollisions}
|
|
159
|
+
collisionBoundary={collisionBoundary}
|
|
160
|
+
collisionPadding={collisionPadding}
|
|
161
|
+
arrowPadding={arrowPadding}
|
|
162
|
+
sticky={sticky}
|
|
163
|
+
hideWhenDetached={hideWhenDetached}
|
|
164
|
+
updatePositionStrategy={updatePositionStrategy}
|
|
165
|
+
className={cn(
|
|
166
|
+
"relative z-50 max-w-[22.5rem] rounded-base text-foreground shadow-level-2 outline-none",
|
|
167
|
+
translucent ? translucentSurface : "bg-surface-overlay",
|
|
168
|
+
// Swirl scales the panel in from the corner nearest the trigger.
|
|
169
|
+
"duration-150 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-0",
|
|
170
|
+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0",
|
|
171
|
+
"origin-(--radix-popover-content-transform-origin) motion-reduce:animate-none",
|
|
172
|
+
)}
|
|
173
|
+
{...props}
|
|
174
|
+
>
|
|
175
|
+
<div
|
|
176
|
+
className={cn(
|
|
177
|
+
"max-h-[min(22rem,var(--radix-popover-content-available-height))] overflow-x-hidden overflow-y-auto overscroll-contain rounded-[inherit]",
|
|
178
|
+
padded && "p-1",
|
|
179
|
+
className,
|
|
180
|
+
)}
|
|
181
|
+
>
|
|
182
|
+
{children}
|
|
183
|
+
</div>
|
|
184
|
+
{arrow && (
|
|
185
|
+
<PopoverPrimitive.Arrow
|
|
186
|
+
className={translucent ? "fill-translucent-low" : "fill-surface-overlay"}
|
|
187
|
+
width={12}
|
|
188
|
+
height={6}
|
|
189
|
+
/>
|
|
190
|
+
)}
|
|
191
|
+
</PopoverPrimitive.Content>
|
|
192
|
+
</PopoverPrimitive.Portal>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Progress as ProgressPrimitive } from "radix-ui";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
|
|
4
|
+
export type ProgressSize = "xs" | "s" | "m" | "l";
|
|
5
|
+
export type ProgressIntent = "primary" | "critical" | "success" | "warning";
|
|
6
|
+
|
|
7
|
+
export interface ProgressProps
|
|
8
|
+
extends Omit<React.ComponentProps<typeof ProgressPrimitive.Root>, "value"> {
|
|
9
|
+
/** 0-100, or `null`/undefined for an indeterminate indicator. */
|
|
10
|
+
value?: number | null;
|
|
11
|
+
/** Swirl's `bar`, or a `circle` ring. */
|
|
12
|
+
variant?: "bar" | "circle";
|
|
13
|
+
/**
|
|
14
|
+
* Bars are 1, 2, 4 or 8px thick; circles 20, 24, 48 or 96px wide. `m` is
|
|
15
|
+
* Swirl's default.
|
|
16
|
+
*/
|
|
17
|
+
size?: ProgressSize;
|
|
18
|
+
/** Colour of the filled part. Swirl has only `primary`. */
|
|
19
|
+
intent?: ProgressIntent;
|
|
20
|
+
/** Show the percentage beside a bar. */
|
|
21
|
+
showValue?: boolean;
|
|
22
|
+
label?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const barSizes = {
|
|
26
|
+
xs: "h-px",
|
|
27
|
+
s: "h-0.5",
|
|
28
|
+
m: "h-1",
|
|
29
|
+
l: "h-2",
|
|
30
|
+
} as const satisfies Record<ProgressSize, string>;
|
|
31
|
+
|
|
32
|
+
const barIntents = {
|
|
33
|
+
primary: "bg-border-highlight",
|
|
34
|
+
critical: "bg-surface-critical",
|
|
35
|
+
success: "bg-surface-success",
|
|
36
|
+
warning: "bg-surface-warning",
|
|
37
|
+
} as const satisfies Record<ProgressIntent, string>;
|
|
38
|
+
|
|
39
|
+
/* Swirl's circle geometry: ring radius and stroke width, per size. */
|
|
40
|
+
const circleSizes = {
|
|
41
|
+
xs: { radius: 8, stroke: 2, className: "size-5" },
|
|
42
|
+
s: { radius: 10, stroke: 2, className: "size-6" },
|
|
43
|
+
m: { radius: 20, stroke: 4, className: "size-12" },
|
|
44
|
+
l: { radius: 40, stroke: 8, className: "size-24" },
|
|
45
|
+
} as const satisfies Record<ProgressSize, { radius: number; stroke: number; className: string }>;
|
|
46
|
+
|
|
47
|
+
const circleIntents = {
|
|
48
|
+
primary: "stroke-interactive-primary",
|
|
49
|
+
critical: "stroke-surface-critical",
|
|
50
|
+
success: "stroke-surface-success",
|
|
51
|
+
warning: "stroke-surface-warning",
|
|
52
|
+
} as const satisfies Record<ProgressIntent, string>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Swirl's progress indicator: a thin bar, or a ring with `variant="circle"`.
|
|
56
|
+
*
|
|
57
|
+
* With no `value` it animates indefinitely and omits `aria-valuenow`, so
|
|
58
|
+
* assistive tech announces "busy" rather than a misleading 0%.
|
|
59
|
+
*/
|
|
60
|
+
export function Progress({
|
|
61
|
+
className,
|
|
62
|
+
value,
|
|
63
|
+
variant = "bar",
|
|
64
|
+
size = "m",
|
|
65
|
+
intent = "primary",
|
|
66
|
+
showValue = false,
|
|
67
|
+
label,
|
|
68
|
+
...props
|
|
69
|
+
}: ProgressProps) {
|
|
70
|
+
const indeterminate = value === null || value === undefined;
|
|
71
|
+
const clamped = indeterminate ? 0 : Math.min(100, Math.max(0, value));
|
|
72
|
+
|
|
73
|
+
if (variant === "circle") {
|
|
74
|
+
const { radius, stroke, className: box } = circleSizes[size];
|
|
75
|
+
const centre = radius + stroke;
|
|
76
|
+
const circumference = Math.round(radius * 2 * Math.PI);
|
|
77
|
+
// An indeterminate ring shows a quarter arc and spins.
|
|
78
|
+
const offset = Math.round(circumference * ((100 - (indeterminate ? 25 : clamped)) / 100));
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<ProgressPrimitive.Root
|
|
82
|
+
value={indeterminate ? null : clamped}
|
|
83
|
+
aria-label={label}
|
|
84
|
+
className={cn("relative inline-flex shrink-0 overflow-hidden", box, className)}
|
|
85
|
+
{...props}
|
|
86
|
+
>
|
|
87
|
+
<svg
|
|
88
|
+
viewBox={`0 0 ${centre * 2} ${centre * 2}`}
|
|
89
|
+
className={cn(
|
|
90
|
+
"absolute inset-0 size-full -rotate-90",
|
|
91
|
+
indeterminate && "animate-spin motion-reduce:animate-none",
|
|
92
|
+
)}
|
|
93
|
+
aria-hidden
|
|
94
|
+
focusable={false}
|
|
95
|
+
>
|
|
96
|
+
<circle
|
|
97
|
+
cx={centre}
|
|
98
|
+
cy={centre}
|
|
99
|
+
r={radius}
|
|
100
|
+
fill="none"
|
|
101
|
+
strokeWidth={stroke}
|
|
102
|
+
strokeLinecap="round"
|
|
103
|
+
className="stroke-surface-sunken-pressed"
|
|
104
|
+
/>
|
|
105
|
+
<circle
|
|
106
|
+
cx={centre}
|
|
107
|
+
cy={centre}
|
|
108
|
+
r={radius}
|
|
109
|
+
fill="none"
|
|
110
|
+
strokeWidth={stroke}
|
|
111
|
+
strokeLinecap="round"
|
|
112
|
+
strokeDasharray={circumference}
|
|
113
|
+
strokeDashoffset={offset}
|
|
114
|
+
className={cn(
|
|
115
|
+
"transition-[stroke-dashoffset] duration-250 motion-reduce:transition-none",
|
|
116
|
+
circleIntents[intent],
|
|
117
|
+
)}
|
|
118
|
+
/>
|
|
119
|
+
</svg>
|
|
120
|
+
</ProgressPrimitive.Root>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const bar = (
|
|
125
|
+
<ProgressPrimitive.Root
|
|
126
|
+
value={indeterminate ? null : clamped}
|
|
127
|
+
aria-label={label}
|
|
128
|
+
className={cn(
|
|
129
|
+
"relative block w-full overflow-hidden rounded-full bg-surface-sunken-pressed",
|
|
130
|
+
barSizes[size],
|
|
131
|
+
className,
|
|
132
|
+
)}
|
|
133
|
+
{...props}
|
|
134
|
+
>
|
|
135
|
+
<ProgressPrimitive.Indicator
|
|
136
|
+
className={cn(
|
|
137
|
+
"size-full rounded-full",
|
|
138
|
+
barIntents[intent],
|
|
139
|
+
indeterminate
|
|
140
|
+
? "animate-progress-indeterminate origin-left motion-reduce:animate-none"
|
|
141
|
+
: "transition-transform duration-250 motion-reduce:transition-none",
|
|
142
|
+
)}
|
|
143
|
+
style={indeterminate ? undefined : { transform: `translateX(-${100 - clamped}%)` }}
|
|
144
|
+
/>
|
|
145
|
+
</ProgressPrimitive.Root>
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (!showValue) return bar;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div className="flex items-center gap-2">
|
|
152
|
+
{bar}
|
|
153
|
+
<span className="w-10 shrink-0 text-right text-sm text-subdued tabular-nums">
|
|
154
|
+
{indeterminate ? "" : `${Math.round(clamped)}%`}
|
|
155
|
+
</span>
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
}
|