nish-ui 2.2.0 → 3.0.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/README.md +5 -1
- package/dist/chart.js +1 -1
- package/dist/elements-all.js +58 -58
- package/dist/elements-charts.js +1 -1
- package/dist/elements-data.js +1 -1
- package/dist/elements-forms.js +1 -1
- package/dist/elements.js +4 -4
- package/dist/esm/components/accordion.js +3 -2
- package/dist/esm/components/app-shell.js +3 -2
- package/dist/esm/components/avatar.js +4 -3
- package/dist/esm/components/breadcrumbs.js +3 -2
- package/dist/esm/components/calendar-base.js +4 -3
- package/dist/esm/components/canvas/legend.js +3 -2
- package/dist/esm/components/canvas/node.js +3 -2
- package/dist/esm/components/canvas/system-canvas.js +3 -2
- package/dist/esm/components/carousel.js +3 -2
- package/dist/esm/components/charts.js +8 -7
- package/dist/esm/components/combobox.js +3 -2
- package/dist/esm/components/command.js +4 -3
- package/dist/esm/components/context-menu.js +3 -2
- package/dist/esm/components/data.js +4 -3
- package/dist/esm/components/date-picker.js +4 -3
- package/dist/esm/components/date-range-picker.js +4 -3
- package/dist/esm/components/display.js +7 -6
- package/dist/esm/components/drawer.js +3 -2
- package/dist/esm/components/error-boundary.js +4 -2
- package/dist/esm/components/feedback.js +7 -6
- package/dist/esm/components/file-dropzone.js +3 -2
- package/dist/esm/components/filters.js +4 -3
- package/dist/esm/components/flow.js +6 -5
- package/dist/esm/components/forms.js +13 -8
- package/dist/esm/components/hooks.js +2 -2
- package/dist/esm/components/hover-card.js +2 -2
- package/dist/esm/components/inbox.js +4 -2
- package/dist/esm/components/layout.js +5 -4
- package/dist/esm/components/media.js +3 -2
- package/dist/esm/components/menu.js +5 -4
- package/dist/esm/components/modal.js +4 -3
- package/dist/esm/components/more-sheet.js +3 -2
- package/dist/esm/components/multi-select.js +3 -2
- package/dist/esm/components/nav-items.js +4 -3
- package/dist/esm/components/nav.js +5 -4
- package/dist/esm/components/overlay-dialog.js +3 -2
- package/dist/esm/components/pagination.js +3 -2
- package/dist/esm/components/popover.js +2 -2
- package/dist/esm/components/portal.js +2 -2
- package/dist/esm/components/progress.js +3 -2
- package/dist/esm/components/provider.js +34 -5
- package/dist/esm/components/range-calendar.js +4 -3
- package/dist/esm/components/service-tokens.js +4 -3
- package/dist/esm/components/settings.js +4 -3
- package/dist/esm/components/slider.js +3 -2
- package/dist/esm/components/split.js +4 -3
- package/dist/esm/components/strings.js +174 -65
- package/dist/esm/components/tag-input.js +3 -2
- package/dist/esm/components/theme-toggle.js +3 -2
- package/dist/esm/components/time-field.js +4 -3
- package/dist/esm/components/toast-card.js +155 -0
- package/dist/esm/components/toast-store.js +136 -0
- package/dist/esm/components/toast.js +38 -241
- package/dist/esm/components/tooltip.js +2 -2
- package/dist/esm/components/virtual-table.js +3 -2
- package/dist/esm/index.js +0 -20
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/system-canvas.js +4 -0
- package/dist/esm/theme.js +7 -7
- package/dist/format.js +1 -1
- package/dist/index.d.ts +11 -14
- package/dist/system-canvas.d.ts +183 -2
- package/dist/theme.d.ts +3 -3
- package/dist/theme.global.js +21 -145
- package/dist/theme.js +21 -145
- package/package.json +1 -1
- package/dist/system-canvas-BLuWd69H.d.ts +0 -183
|
@@ -1,28 +1,77 @@
|
|
|
1
1
|
// src/components/strings.ts
|
|
2
|
-
var
|
|
2
|
+
var OVERLAY_STRINGS = {
|
|
3
3
|
close: "Close",
|
|
4
4
|
cancel: "Cancel",
|
|
5
5
|
menu: "Menu",
|
|
6
6
|
back: "Back: ",
|
|
7
|
-
contextMenu: "Actions"
|
|
8
|
-
|
|
7
|
+
contextMenu: "Actions"
|
|
8
|
+
};
|
|
9
|
+
var SHELL_STRINGS = {
|
|
10
|
+
sections: "Sections",
|
|
11
|
+
more: "More",
|
|
12
|
+
hubTitle: "Back to nish.software",
|
|
13
|
+
hubLabel: "\u2190 nish.software",
|
|
14
|
+
moreActions: "More actions",
|
|
15
|
+
skipToContent: "Skip to content",
|
|
16
|
+
sidebar: "Sidebar",
|
|
17
|
+
expandSidebar: "Expand sidebar",
|
|
18
|
+
collapseSidebar: "Collapse sidebar",
|
|
19
|
+
newCount: (value) => `${value} new`
|
|
20
|
+
};
|
|
21
|
+
var STATUS_STRINGS = {
|
|
22
|
+
loading: "Loading",
|
|
23
|
+
failedToLoad: "Failed to load",
|
|
24
|
+
retry: "Retry",
|
|
25
|
+
nothingHere: "Nothing here yet",
|
|
26
|
+
loadingNamed: (label) => `Loading ${label}`,
|
|
27
|
+
offline: "You're offline",
|
|
28
|
+
actions: "Actions"
|
|
29
|
+
};
|
|
30
|
+
var THEME_STRINGS = {
|
|
31
|
+
theme: "Theme",
|
|
32
|
+
themeSystem: "System",
|
|
33
|
+
themeLight: "Light",
|
|
34
|
+
themeDark: "Dark",
|
|
35
|
+
themeToggleLabel: (current, next) => `Theme: ${current}. Switch to ${next}`,
|
|
36
|
+
themePreset: "Theme preset",
|
|
37
|
+
themePresetPlaceholder: "Preset\u2026"
|
|
38
|
+
};
|
|
39
|
+
var ERROR_STRINGS = {
|
|
40
|
+
errorStaleTitle: "A new version is available",
|
|
41
|
+
errorStaleBody: "Reload the page to get the latest version.",
|
|
42
|
+
errorTitle: "Something went wrong",
|
|
43
|
+
errorBody: "An unexpected error occurred.",
|
|
44
|
+
errorDetails: "Details",
|
|
45
|
+
errorTryAgain: "Try again",
|
|
46
|
+
errorReload: "Reload page"
|
|
47
|
+
};
|
|
48
|
+
var DISPLAY_STRINGS = {
|
|
9
49
|
dismiss: "Dismiss",
|
|
10
50
|
moreCount: (count) => `${count} more`,
|
|
11
51
|
copy: "Copy",
|
|
12
52
|
copied: "Copied",
|
|
13
|
-
hubTitle: "Back to nish.software",
|
|
14
|
-
hubLabel: "\u2190 nish.software",
|
|
15
|
-
moreActions: "More actions",
|
|
16
|
-
more: "More",
|
|
17
53
|
legend: "Legend",
|
|
54
|
+
noData: "No data",
|
|
55
|
+
noDataNamed: (label) => `${label}: no data`
|
|
56
|
+
};
|
|
57
|
+
var FIELD_STRINGS = {
|
|
18
58
|
optional: "Optional",
|
|
19
59
|
search: "Search",
|
|
20
60
|
clearSearch: "Clear search",
|
|
21
61
|
remove: "Remove",
|
|
22
62
|
removeNamed: (name) => `Remove ${name}`,
|
|
23
|
-
noMatches: "No matches",
|
|
24
63
|
clear: "Clear",
|
|
64
|
+
noMatches: "No matches",
|
|
25
65
|
searching: "Searching\u2026",
|
|
66
|
+
removeTag: (tag) => `Remove ${tag}`
|
|
67
|
+
};
|
|
68
|
+
var FILTER_STRINGS = {
|
|
69
|
+
filters: "Filters",
|
|
70
|
+
clearFilters: "Clear filters",
|
|
71
|
+
done: "Done",
|
|
72
|
+
activeCount: (n) => `${n} active`
|
|
73
|
+
};
|
|
74
|
+
var PICKER_STRINGS = {
|
|
26
75
|
invalidDate: "Enter a valid date.",
|
|
27
76
|
chooseDate: "Choose date",
|
|
28
77
|
changeDate: (date) => `Change date, ${date}`,
|
|
@@ -37,15 +86,15 @@ var DEFAULT_STRINGS = {
|
|
|
37
86
|
changeDates: (range) => `Change dates, ${range}`,
|
|
38
87
|
dateRange: (from, to) => `${from} to ${to}`,
|
|
39
88
|
rangeStarted: (start) => `Start date ${start}. Pick the end date.`,
|
|
40
|
-
invalidDateRange: "Enter a valid date range."
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
dayPeriod: "AM/PM",
|
|
44
|
-
invalidTime: "Enter a valid time.",
|
|
89
|
+
invalidDateRange: "Enter a valid date range."
|
|
90
|
+
};
|
|
91
|
+
var MULTI_SELECT_STRINGS = {
|
|
45
92
|
optionAdded: (l) => `Added ${l}`,
|
|
46
93
|
optionRemoved: (l) => `Removed ${l}`,
|
|
47
94
|
clearAll: "Clear all",
|
|
48
|
-
maxSelected: (n) => `You can pick up to ${n}
|
|
95
|
+
maxSelected: (n) => `You can pick up to ${n}`
|
|
96
|
+
};
|
|
97
|
+
var CAROUSEL_STRINGS = {
|
|
49
98
|
carouselRole: "carousel",
|
|
50
99
|
slideRole: "slide",
|
|
51
100
|
slideLabel: (n, c) => `${n} of ${c}`,
|
|
@@ -54,66 +103,53 @@ var DEFAULT_STRINGS = {
|
|
|
54
103
|
goToSlide: (n) => `Go to slide ${n}`,
|
|
55
104
|
slidePicker: "Choose slide",
|
|
56
105
|
startRotation: "Start slide rotation",
|
|
57
|
-
stopRotation: "Stop slide rotation"
|
|
106
|
+
stopRotation: "Stop slide rotation"
|
|
107
|
+
};
|
|
108
|
+
var COMMAND_STRINGS = {
|
|
58
109
|
searchPlaceholder: "Search\u2026",
|
|
59
110
|
noResults: "No results",
|
|
60
|
-
results: "Results"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
actions: "Actions",
|
|
65
|
-
offline: "You're offline",
|
|
66
|
-
nothingHere: "Nothing here yet",
|
|
67
|
-
loadingNamed: (label) => `Loading ${label}`,
|
|
111
|
+
results: "Results"
|
|
112
|
+
};
|
|
113
|
+
var TABLE_STRINGS = {
|
|
114
|
+
sortAnnounce: (header, dir) => dir ? `Sorted by ${header}, ${dir === "asc" ? "ascending" : "descending"}` : "Sorting cleared",
|
|
68
115
|
sortBy: "Sort by",
|
|
69
|
-
sortDefault: "Default"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
filters: "Filters",
|
|
73
|
-
clearFilters: "Clear filters",
|
|
74
|
-
done: "Done",
|
|
75
|
-
activeCount: (n) => `${n} active`,
|
|
76
|
-
newCount: (value) => `${value} new`,
|
|
77
|
-
sections: "Sections",
|
|
78
|
-
theme: "Theme",
|
|
79
|
-
sidebar: "Sidebar",
|
|
80
|
-
expandSidebar: "Expand sidebar",
|
|
81
|
-
collapseSidebar: "Collapse sidebar",
|
|
82
|
-
skipToContent: "Skip to content",
|
|
83
|
-
themeSystem: "System",
|
|
84
|
-
themeLight: "Light",
|
|
85
|
-
themeDark: "Dark",
|
|
86
|
-
themeToggleLabel: (current, next) => `Theme: ${current}. Switch to ${next}`,
|
|
87
|
-
themePreset: "Theme preset",
|
|
88
|
-
themePresetPlaceholder: "Preset\u2026",
|
|
89
|
-
errorStaleTitle: "A new version is available",
|
|
90
|
-
errorStaleBody: "Reload the page to get the latest version.",
|
|
91
|
-
errorTitle: "Something went wrong",
|
|
92
|
-
errorBody: "An unexpected error occurred.",
|
|
93
|
-
errorDetails: "Details",
|
|
94
|
-
errorTryAgain: "Try again",
|
|
95
|
-
errorReload: "Reload page",
|
|
116
|
+
sortDefault: "Default"
|
|
117
|
+
};
|
|
118
|
+
var SETTINGS_STRINGS = {
|
|
96
119
|
saving: "Saving\u2026",
|
|
97
120
|
saved: "Saved",
|
|
98
121
|
saveFailed: "Could not save",
|
|
99
|
-
enterNumber: "Enter a number"
|
|
122
|
+
enterNumber: "Enter a number"
|
|
123
|
+
};
|
|
124
|
+
var SPLIT_STRINGS = {
|
|
100
125
|
resizeColumns: "Resize columns",
|
|
101
126
|
resizeRows: "Resize rows",
|
|
102
|
-
layoutPresets: "Layout presets"
|
|
127
|
+
layoutPresets: "Layout presets"
|
|
128
|
+
};
|
|
129
|
+
var MEDIA_STRINGS = {
|
|
103
130
|
live: "Live",
|
|
104
|
-
offlineBadge: "Offline"
|
|
131
|
+
offlineBadge: "Offline"
|
|
132
|
+
};
|
|
133
|
+
var PROGRESS_STRINGS = {
|
|
105
134
|
progress: "Progress",
|
|
135
|
+
progressIndeterminate: "Loading"
|
|
136
|
+
};
|
|
137
|
+
var FLOW_STRINGS = {
|
|
106
138
|
workflow: "Workflow",
|
|
107
139
|
activity: "Activity",
|
|
108
140
|
other: "Other",
|
|
109
141
|
waiting: "Waiting",
|
|
110
|
-
noActivity: "No activity yet"
|
|
142
|
+
noActivity: "No activity yet"
|
|
143
|
+
};
|
|
144
|
+
var CANVAS_STRINGS = {
|
|
111
145
|
systemMap: "System map",
|
|
112
146
|
zoomOut: "Zoom out",
|
|
113
147
|
zoomIn: "Zoom in",
|
|
114
148
|
fitToScreen: "Fit to screen",
|
|
115
149
|
followActivity: "Follow activity",
|
|
116
|
-
canvasLines: "Lines"
|
|
150
|
+
canvasLines: "Lines"
|
|
151
|
+
};
|
|
152
|
+
var TOKEN_STRINGS = {
|
|
117
153
|
serviceTokens: "Service tokens",
|
|
118
154
|
serviceTokensIntro: "Machine clients, like the nish MCP server, use these tokens to read this app. Revoking one stops it at once.",
|
|
119
155
|
loadingServiceTokens: "Loading service tokens",
|
|
@@ -122,7 +158,9 @@ var DEFAULT_STRINGS = {
|
|
|
122
158
|
tokenRevokedAt: (when) => `Revoked ${when}`,
|
|
123
159
|
tokenRevokeNamed: (name) => `Revoke ${name}`,
|
|
124
160
|
tokenRevokeTitle: (name) => `Revoke ${name}?`,
|
|
125
|
-
tokenRevokeFailed: "Could not revoke the token."
|
|
161
|
+
tokenRevokeFailed: "Could not revoke the token."
|
|
162
|
+
};
|
|
163
|
+
var INBOX_STRINGS = {
|
|
126
164
|
inboxMarkHandled: "Mark handled",
|
|
127
165
|
inboxSnooze: "Snooze",
|
|
128
166
|
inboxActions: "Actions",
|
|
@@ -131,23 +169,94 @@ var DEFAULT_STRINGS = {
|
|
|
131
169
|
inboxSnoozed: "Snoozed",
|
|
132
170
|
inboxHandled: "Handled",
|
|
133
171
|
inboxFilterBySource: "Filter by source",
|
|
134
|
-
inboxHappened: (count) => `Happened ${count} times
|
|
172
|
+
inboxHappened: (count) => `Happened ${count} times`
|
|
173
|
+
};
|
|
174
|
+
var PAGING_STRINGS = {
|
|
135
175
|
previousPage: "Previous page",
|
|
136
176
|
nextPage: "Next page",
|
|
137
177
|
pageLabel: (n) => `Page ${n}`,
|
|
138
178
|
paginationLabel: "Pagination",
|
|
139
|
-
breadcrumbs: "Breadcrumbs"
|
|
140
|
-
|
|
179
|
+
breadcrumbs: "Breadcrumbs"
|
|
180
|
+
};
|
|
181
|
+
var FILE_STRINGS = {
|
|
141
182
|
dropzoneLabel: "Drop files here or browse",
|
|
142
183
|
browseFiles: "Browse files",
|
|
143
|
-
removeFile: (name) => `Remove ${name}
|
|
184
|
+
removeFile: (name) => `Remove ${name}`
|
|
185
|
+
};
|
|
186
|
+
var AVATAR_STRINGS = {
|
|
144
187
|
avatar: "Avatar",
|
|
145
|
-
avatarMore: (count) => `${count} more
|
|
188
|
+
avatarMore: (count) => `${count} more`
|
|
189
|
+
};
|
|
190
|
+
var SLIDER_STRINGS = {
|
|
146
191
|
sliderMin: "Minimum",
|
|
147
|
-
sliderMax: "Maximum"
|
|
148
|
-
|
|
149
|
-
|
|
192
|
+
sliderMax: "Maximum"
|
|
193
|
+
};
|
|
194
|
+
var ACCORDION_STRINGS = {
|
|
195
|
+
accordion: "Accordion"
|
|
196
|
+
};
|
|
197
|
+
var TIME_STRINGS = {
|
|
198
|
+
hour: "Hour",
|
|
199
|
+
minute: "Minute",
|
|
200
|
+
dayPeriod: "AM/PM",
|
|
201
|
+
invalidTime: "Enter a valid time."
|
|
150
202
|
};
|
|
203
|
+
var DEFAULT_STRINGS = /* @__PURE__ */ Object.assign(
|
|
204
|
+
{},
|
|
205
|
+
OVERLAY_STRINGS,
|
|
206
|
+
SHELL_STRINGS,
|
|
207
|
+
STATUS_STRINGS,
|
|
208
|
+
THEME_STRINGS,
|
|
209
|
+
ERROR_STRINGS,
|
|
210
|
+
DISPLAY_STRINGS,
|
|
211
|
+
FIELD_STRINGS,
|
|
212
|
+
FILTER_STRINGS,
|
|
213
|
+
PICKER_STRINGS,
|
|
214
|
+
MULTI_SELECT_STRINGS,
|
|
215
|
+
CAROUSEL_STRINGS,
|
|
216
|
+
COMMAND_STRINGS,
|
|
217
|
+
TABLE_STRINGS,
|
|
218
|
+
SETTINGS_STRINGS,
|
|
219
|
+
SPLIT_STRINGS,
|
|
220
|
+
MEDIA_STRINGS,
|
|
221
|
+
PROGRESS_STRINGS,
|
|
222
|
+
FLOW_STRINGS,
|
|
223
|
+
CANVAS_STRINGS,
|
|
224
|
+
TOKEN_STRINGS,
|
|
225
|
+
INBOX_STRINGS,
|
|
226
|
+
PAGING_STRINGS,
|
|
227
|
+
FILE_STRINGS,
|
|
228
|
+
AVATAR_STRINGS,
|
|
229
|
+
SLIDER_STRINGS,
|
|
230
|
+
ACCORDION_STRINGS,
|
|
231
|
+
TIME_STRINGS
|
|
232
|
+
);
|
|
151
233
|
export {
|
|
152
|
-
|
|
234
|
+
ACCORDION_STRINGS,
|
|
235
|
+
AVATAR_STRINGS,
|
|
236
|
+
CANVAS_STRINGS,
|
|
237
|
+
CAROUSEL_STRINGS,
|
|
238
|
+
COMMAND_STRINGS,
|
|
239
|
+
DEFAULT_STRINGS,
|
|
240
|
+
DISPLAY_STRINGS,
|
|
241
|
+
ERROR_STRINGS,
|
|
242
|
+
FIELD_STRINGS,
|
|
243
|
+
FILE_STRINGS,
|
|
244
|
+
FILTER_STRINGS,
|
|
245
|
+
FLOW_STRINGS,
|
|
246
|
+
INBOX_STRINGS,
|
|
247
|
+
MEDIA_STRINGS,
|
|
248
|
+
MULTI_SELECT_STRINGS,
|
|
249
|
+
OVERLAY_STRINGS,
|
|
250
|
+
PAGING_STRINGS,
|
|
251
|
+
PICKER_STRINGS,
|
|
252
|
+
PROGRESS_STRINGS,
|
|
253
|
+
SETTINGS_STRINGS,
|
|
254
|
+
SHELL_STRINGS,
|
|
255
|
+
SLIDER_STRINGS,
|
|
256
|
+
SPLIT_STRINGS,
|
|
257
|
+
STATUS_STRINGS,
|
|
258
|
+
TABLE_STRINGS,
|
|
259
|
+
THEME_STRINGS,
|
|
260
|
+
TIME_STRINGS,
|
|
261
|
+
TOKEN_STRINGS
|
|
153
262
|
};
|
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
import { cn } from "../cn.js";
|
|
11
11
|
import { Chip } from "./forms.js";
|
|
12
12
|
import { fieldClass } from "./primitives.js";
|
|
13
|
-
import {
|
|
13
|
+
import { useStrings } from "./provider.js";
|
|
14
|
+
import { FIELD_STRINGS } from "./strings.js";
|
|
14
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
16
|
function setRef(ref, node) {
|
|
16
17
|
if (typeof ref === "function") ref(node);
|
|
@@ -42,7 +43,7 @@ function TagInput({
|
|
|
42
43
|
"aria-invalid": ariaInvalid,
|
|
43
44
|
...rest
|
|
44
45
|
}) {
|
|
45
|
-
const strings =
|
|
46
|
+
const strings = useStrings(FIELD_STRINGS);
|
|
46
47
|
const auto = useId();
|
|
47
48
|
const input = useRef(null);
|
|
48
49
|
const controlled = value !== void 0;
|
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
} from "../theme.js";
|
|
18
18
|
import { MonitorIcon, MoonIcon, SunIcon } from "./icons.js";
|
|
19
19
|
import { IconButton } from "./primitives.js";
|
|
20
|
-
import {
|
|
20
|
+
import { useStrings } from "./provider.js";
|
|
21
|
+
import { THEME_STRINGS } from "./strings.js";
|
|
21
22
|
import { Segmented } from "./segmented.js";
|
|
22
23
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
23
24
|
var SERVER_SNAPSHOT = { choice: "system", theme: DEFAULT_THEME };
|
|
@@ -66,7 +67,7 @@ function ThemeToggle({
|
|
|
66
67
|
elsewhereLabel = "set on another site",
|
|
67
68
|
...rest
|
|
68
69
|
}) {
|
|
69
|
-
const strings =
|
|
70
|
+
const strings = useStrings(THEME_STRINGS);
|
|
70
71
|
const { choice, theme, scheme, setChoice } = useTheme();
|
|
71
72
|
const extra = PRESETS.filter((p) => p.id !== "dark" && p.id !== "light");
|
|
72
73
|
const isPreset = extra.some((p) => p.id === choice);
|
|
@@ -9,7 +9,8 @@ import { useIsoLayoutEffect } from "./client.js";
|
|
|
9
9
|
import { setRef } from "./forms-classes.js";
|
|
10
10
|
import { fieldClass } from "./primitives-classes.js";
|
|
11
11
|
import { Select } from "./primitives.js";
|
|
12
|
-
import {
|
|
12
|
+
import { useStrings, useNishContext } from "./provider.js";
|
|
13
|
+
import { TIME_STRINGS } from "./strings.js";
|
|
13
14
|
import {
|
|
14
15
|
dayPeriodNames,
|
|
15
16
|
draftFromTime,
|
|
@@ -62,8 +63,8 @@ function TimeField({
|
|
|
62
63
|
className,
|
|
63
64
|
...rest
|
|
64
65
|
}) {
|
|
65
|
-
const strings =
|
|
66
|
-
const config =
|
|
66
|
+
const strings = useStrings(TIME_STRINGS);
|
|
67
|
+
const config = useNishContext();
|
|
67
68
|
const loc = resolveLocale(locale ?? config.locale ?? getDefaultLocale());
|
|
68
69
|
const cycle = hourCycle ?? hourCycleFor(loc);
|
|
69
70
|
const st = normalizeStep(step);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/toast-card.tsx
|
|
4
|
+
import { useRef } from "react";
|
|
5
|
+
import { cn } from "../cn.js";
|
|
6
|
+
import { AlertTriangleIcon, CheckCircleIcon, InfoIcon, XIcon } from "./icons.js";
|
|
7
|
+
import { useStrings } from "./provider.js";
|
|
8
|
+
import { DISPLAY_STRINGS } from "./strings.js";
|
|
9
|
+
import { dismissToast, pauseTimer, resumeTimer } from "./toast-store.js";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var TONE = {
|
|
12
|
+
success: {
|
|
13
|
+
icon: /* @__PURE__ */ jsx(CheckCircleIcon, { size: 15, className: "text-th-ok" }),
|
|
14
|
+
className: "border-th-ok/35"
|
|
15
|
+
},
|
|
16
|
+
error: {
|
|
17
|
+
icon: /* @__PURE__ */ jsx(AlertTriangleIcon, { size: 15, className: "text-th-loss" }),
|
|
18
|
+
className: "border-th-loss/40"
|
|
19
|
+
},
|
|
20
|
+
warn: {
|
|
21
|
+
icon: /* @__PURE__ */ jsx(AlertTriangleIcon, { size: 15, className: "text-th-warn" }),
|
|
22
|
+
className: "border-th-warn/40"
|
|
23
|
+
},
|
|
24
|
+
info: {
|
|
25
|
+
icon: /* @__PURE__ */ jsx(InfoIcon, { size: 15, className: "text-th-accent" }),
|
|
26
|
+
className: "border-th-line-strong"
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var SWIPE_DISMISS_FRACTION = 0.35;
|
|
30
|
+
var SWIPE_DISMISS_VELOCITY = 0.5;
|
|
31
|
+
var SWIPE_SLOP = 8;
|
|
32
|
+
function ToastCard({ t }) {
|
|
33
|
+
const strings = useStrings(DISPLAY_STRINGS);
|
|
34
|
+
const ref = useRef(null);
|
|
35
|
+
const drag = useRef(null);
|
|
36
|
+
const setOffset = (dx, width) => {
|
|
37
|
+
const el = ref.current;
|
|
38
|
+
if (!el) return;
|
|
39
|
+
el.style.transform = dx === 0 ? "" : `translateX(${dx}px)`;
|
|
40
|
+
el.style.opacity = dx === 0 ? "" : String(Math.max(0, 1 - Math.abs(dx) / width));
|
|
41
|
+
};
|
|
42
|
+
const onDown = (e) => {
|
|
43
|
+
if (e.pointerType === "mouse") return;
|
|
44
|
+
drag.current = {
|
|
45
|
+
pointerId: e.pointerId,
|
|
46
|
+
startX: e.clientX,
|
|
47
|
+
startY: e.clientY,
|
|
48
|
+
lastX: e.clientX,
|
|
49
|
+
lastT: e.timeStamp,
|
|
50
|
+
velocity: 0,
|
|
51
|
+
active: false
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const onMove = (e) => {
|
|
55
|
+
const d = drag.current;
|
|
56
|
+
const el = ref.current;
|
|
57
|
+
if (!d || !el || d.pointerId !== e.pointerId) return;
|
|
58
|
+
const dx = e.clientX - d.startX;
|
|
59
|
+
if (!d.active) {
|
|
60
|
+
if (Math.abs(dx) < SWIPE_SLOP || Math.abs(dx) < Math.abs(e.clientY - d.startY)) return;
|
|
61
|
+
d.active = true;
|
|
62
|
+
el.setPointerCapture(e.pointerId);
|
|
63
|
+
pauseTimer(t.id);
|
|
64
|
+
}
|
|
65
|
+
const dt = e.timeStamp - d.lastT;
|
|
66
|
+
if (dt > 0) d.velocity = (e.clientX - d.lastX) / dt;
|
|
67
|
+
d.lastX = e.clientX;
|
|
68
|
+
d.lastT = e.timeStamp;
|
|
69
|
+
setOffset(dx, el.offsetWidth);
|
|
70
|
+
};
|
|
71
|
+
const onUp = (e) => {
|
|
72
|
+
const d = drag.current;
|
|
73
|
+
const el = ref.current;
|
|
74
|
+
drag.current = null;
|
|
75
|
+
if (!d || !el || d.pointerId !== e.pointerId || !d.active) return;
|
|
76
|
+
const dx = e.clientX - d.startX;
|
|
77
|
+
const width = el.offsetWidth;
|
|
78
|
+
const flung = Math.abs(d.velocity) > SWIPE_DISMISS_VELOCITY && Math.sign(d.velocity) === Math.sign(dx);
|
|
79
|
+
if (Math.abs(dx) > width * SWIPE_DISMISS_FRACTION || flung) {
|
|
80
|
+
dismissToast(t.id);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
el.style.transition = "transform 160ms var(--nish-ease-out), opacity 160ms var(--nish-ease-out)";
|
|
84
|
+
setOffset(0, width);
|
|
85
|
+
window.setTimeout(() => {
|
|
86
|
+
if (ref.current) ref.current.style.transition = "";
|
|
87
|
+
}, 180);
|
|
88
|
+
resumeTimer(t.id);
|
|
89
|
+
};
|
|
90
|
+
const onCancel = (e) => {
|
|
91
|
+
const d = drag.current;
|
|
92
|
+
drag.current = null;
|
|
93
|
+
if (!d?.active || d.pointerId !== e.pointerId) return;
|
|
94
|
+
setOffset(0, ref.current?.offsetWidth || 1);
|
|
95
|
+
resumeTimer(t.id);
|
|
96
|
+
};
|
|
97
|
+
const leave = (e) => {
|
|
98
|
+
if (!e.currentTarget.contains(e.relatedTarget)) resumeTimer(t.id);
|
|
99
|
+
};
|
|
100
|
+
const enter = (e) => {
|
|
101
|
+
if (!e.currentTarget.contains(e.relatedTarget)) pauseTimer(t.id);
|
|
102
|
+
};
|
|
103
|
+
return /* @__PURE__ */ jsxs(
|
|
104
|
+
"div",
|
|
105
|
+
{
|
|
106
|
+
ref,
|
|
107
|
+
onPointerDown: onDown,
|
|
108
|
+
onPointerMove: onMove,
|
|
109
|
+
onPointerUp: onUp,
|
|
110
|
+
onPointerCancel: onCancel,
|
|
111
|
+
onPointerEnter: (e) => e.pointerType === "mouse" && pauseTimer(t.id),
|
|
112
|
+
onPointerLeave: (e) => e.pointerType === "mouse" && resumeTimer(t.id),
|
|
113
|
+
onFocus: enter,
|
|
114
|
+
onBlur: leave,
|
|
115
|
+
className: cn(
|
|
116
|
+
"pointer-events-auto flex w-full max-w-md items-start gap-2.5 rounded-xl border bg-th-elevated px-3.5 py-3 shadow-pop",
|
|
117
|
+
"touch-pan-y animate-[nish-rise-in_160ms_var(--nish-ease-out)]",
|
|
118
|
+
"max-sm:[html[data-nish-layer-open]_&]:animate-[nish-toast-in-top_200ms_var(--nish-ease-out)]",
|
|
119
|
+
TONE[t.tone].className
|
|
120
|
+
),
|
|
121
|
+
children: [
|
|
122
|
+
/* @__PURE__ */ jsx("span", { className: "mt-0.5 shrink-0", children: TONE[t.tone].icon }),
|
|
123
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
124
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-snug text-th-hi", children: t.title }),
|
|
125
|
+
t.body ? /* @__PURE__ */ jsx("p", { className: "mt-0.5 break-words text-xs leading-snug text-th-hi2", children: t.body }) : null
|
|
126
|
+
] }),
|
|
127
|
+
t.action ? /* @__PURE__ */ jsx(
|
|
128
|
+
"button",
|
|
129
|
+
{
|
|
130
|
+
type: "button",
|
|
131
|
+
onClick: () => {
|
|
132
|
+
t.action?.onClick();
|
|
133
|
+
dismissToast(t.id);
|
|
134
|
+
},
|
|
135
|
+
className: "-my-1 inline-flex shrink-0 items-center justify-center rounded-md px-2 py-1 text-sm font-medium text-th-accent transition-colors hover:bg-th-accent-soft pointer-coarse:-my-2.5 pointer-coarse:min-h-11 pointer-coarse:min-w-11",
|
|
136
|
+
children: t.action.label
|
|
137
|
+
}
|
|
138
|
+
) : null,
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
"button",
|
|
141
|
+
{
|
|
142
|
+
type: "button",
|
|
143
|
+
onClick: () => dismissToast(t.id),
|
|
144
|
+
"aria-label": strings.dismiss,
|
|
145
|
+
className: "-m-1 inline-flex shrink-0 items-center justify-center rounded-md p-1 text-th-hi3 transition-colors hover:bg-th-overlay hover:text-th-hi pointer-coarse:-my-2 pointer-coarse:min-h-11 pointer-coarse:min-w-11",
|
|
146
|
+
children: /* @__PURE__ */ jsx(XIcon, { size: 14 })
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
ToastCard
|
|
155
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/toast-store.ts
|
|
4
|
+
import { useSyncExternalStore } from "react";
|
|
5
|
+
import { shared } from "../runtime.js";
|
|
6
|
+
var AUTO_DISMISS_MS = 4e3;
|
|
7
|
+
var MAX_VISIBLE = 4;
|
|
8
|
+
var cachedStore;
|
|
9
|
+
function store() {
|
|
10
|
+
return cachedStore ??= shared("toast", () => ({
|
|
11
|
+
items: [],
|
|
12
|
+
nextId: 1,
|
|
13
|
+
subs: /* @__PURE__ */ new Set(),
|
|
14
|
+
timers: /* @__PURE__ */ new Map()
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
var emit = () => store().subs.forEach((fn) => fn());
|
|
18
|
+
function startTimer(id, ms) {
|
|
19
|
+
const t = {
|
|
20
|
+
handle: null,
|
|
21
|
+
remaining: ms,
|
|
22
|
+
started: Date.now(),
|
|
23
|
+
paused: 0
|
|
24
|
+
};
|
|
25
|
+
t.handle = setTimeout(() => dismissToast(id), ms);
|
|
26
|
+
store().timers.set(id, t);
|
|
27
|
+
}
|
|
28
|
+
function clearTimer(id) {
|
|
29
|
+
const { timers } = store();
|
|
30
|
+
const t = timers.get(id);
|
|
31
|
+
if (t?.handle != null) clearTimeout(t.handle);
|
|
32
|
+
timers.delete(id);
|
|
33
|
+
}
|
|
34
|
+
function pauseTimer(id) {
|
|
35
|
+
const t = store().timers.get(id);
|
|
36
|
+
if (!t) return;
|
|
37
|
+
t.paused += 1;
|
|
38
|
+
if (t.paused > 1 || t.handle == null) return;
|
|
39
|
+
clearTimeout(t.handle);
|
|
40
|
+
t.handle = null;
|
|
41
|
+
t.remaining = Math.max(0, t.remaining - (Date.now() - t.started));
|
|
42
|
+
}
|
|
43
|
+
function resumeTimer(id) {
|
|
44
|
+
const t = store().timers.get(id);
|
|
45
|
+
if (!t || t.paused === 0) return;
|
|
46
|
+
t.paused -= 1;
|
|
47
|
+
if (t.paused > 0) return;
|
|
48
|
+
t.started = Date.now();
|
|
49
|
+
t.handle = setTimeout(() => dismissToast(id), Math.max(t.remaining, 1e3));
|
|
50
|
+
}
|
|
51
|
+
function dismissToast(id) {
|
|
52
|
+
clearTimer(id);
|
|
53
|
+
const s = store();
|
|
54
|
+
const next = s.items.filter((t) => t.id !== id);
|
|
55
|
+
if (next.length === s.items.length) return;
|
|
56
|
+
s.items = next;
|
|
57
|
+
emit();
|
|
58
|
+
}
|
|
59
|
+
var isKept = (t) => t.duration === "sticky" || t.tone === "error";
|
|
60
|
+
function push(tone, title, bodyOrOptions) {
|
|
61
|
+
const o = typeof bodyOrOptions === "string" ? { body: bodyOrOptions } : bodyOrOptions ?? {};
|
|
62
|
+
const s = store();
|
|
63
|
+
const id = s.nextId++;
|
|
64
|
+
const asked = o.duration === Infinity ? "sticky" : o.duration;
|
|
65
|
+
const duration = asked ?? (tone === "error" ? "sticky" : AUTO_DISMISS_MS);
|
|
66
|
+
const item = {
|
|
67
|
+
id,
|
|
68
|
+
tone,
|
|
69
|
+
title,
|
|
70
|
+
body: o.body,
|
|
71
|
+
action: o.action,
|
|
72
|
+
slot: o.id,
|
|
73
|
+
duration
|
|
74
|
+
};
|
|
75
|
+
const old = o.id ? s.items.find((t) => t.slot === o.id) : void 0;
|
|
76
|
+
if (old) {
|
|
77
|
+
clearTimer(old.id);
|
|
78
|
+
s.items = s.items.map((t) => t === old ? item : t);
|
|
79
|
+
} else {
|
|
80
|
+
let excess = s.items.length + 1 - MAX_VISIBLE;
|
|
81
|
+
const kept = [];
|
|
82
|
+
for (const t of s.items) {
|
|
83
|
+
if (excess > 0 && !isKept(t)) {
|
|
84
|
+
excess--;
|
|
85
|
+
clearTimer(t.id);
|
|
86
|
+
} else {
|
|
87
|
+
kept.push(t);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
s.items = [...kept, item];
|
|
91
|
+
}
|
|
92
|
+
emit();
|
|
93
|
+
if (duration !== "sticky") startTimer(id, duration);
|
|
94
|
+
return id;
|
|
95
|
+
}
|
|
96
|
+
var toast = /* @__PURE__ */ Object.assign((title, o) => push("info", title, o), {
|
|
97
|
+
success: (title, o) => push("success", title, o),
|
|
98
|
+
error: (title, o) => push("error", title, o),
|
|
99
|
+
warn: (title, o) => push("warn", title, o),
|
|
100
|
+
info: (title, o) => push("info", title, o),
|
|
101
|
+
promise: (promise, messages) => {
|
|
102
|
+
const slot = "nish-promise-" + store().nextId;
|
|
103
|
+
push("info", messages.loading, { duration: "sticky", id: slot });
|
|
104
|
+
promise.then(
|
|
105
|
+
(value) => {
|
|
106
|
+
push("success", typeof messages.success === "function" ? messages.success(value) : messages.success, { id: slot });
|
|
107
|
+
},
|
|
108
|
+
(error) => {
|
|
109
|
+
push("error", typeof messages.error === "function" ? messages.error(error) : messages.error, { id: slot });
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
return promise;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
function useToast() {
|
|
116
|
+
return toast;
|
|
117
|
+
}
|
|
118
|
+
function useToasts() {
|
|
119
|
+
return useSyncExternalStore(
|
|
120
|
+
(fn) => {
|
|
121
|
+
const { subs } = store();
|
|
122
|
+
subs.add(fn);
|
|
123
|
+
return () => subs.delete(fn);
|
|
124
|
+
},
|
|
125
|
+
() => store().items,
|
|
126
|
+
() => store().items
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
dismissToast,
|
|
131
|
+
pauseTimer,
|
|
132
|
+
resumeTimer,
|
|
133
|
+
toast,
|
|
134
|
+
useToast,
|
|
135
|
+
useToasts
|
|
136
|
+
};
|