orbital-ds 0.25.0 → 0.28.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.
@@ -0,0 +1,175 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { AlertCircleIcon, FileIcon, PaperclipIcon, RotateCcwIcon, XIcon } from "lucide-react";
4
+ import * as React from "react";
5
+ import { useDsLocale, useDsMessages } from "../hooks/use-ds-messages.js";
6
+ import { dsFormat } from "../lib/i18n.js";
7
+ import { cn } from "../lib/utils.js";
8
+ import {
9
+ Attachment,
10
+ AttachmentAction,
11
+ AttachmentActions,
12
+ AttachmentContent,
13
+ AttachmentDescription,
14
+ AttachmentMedia,
15
+ AttachmentTitle
16
+ } from "./attachment.js";
17
+ import { buttonVariants } from "./button.js";
18
+ import { Dropzone, formatBytes } from "./dropzone.js";
19
+ import { Progress } from "./progress.js";
20
+ import { Spinner } from "./spinner.js";
21
+ function FileUpload({
22
+ preset = "drop",
23
+ files,
24
+ onFilesChange,
25
+ upload,
26
+ accept,
27
+ maxSize,
28
+ maxFiles,
29
+ multiple = true,
30
+ disabled = false,
31
+ title,
32
+ hint,
33
+ description,
34
+ icon,
35
+ label,
36
+ name,
37
+ id,
38
+ className
39
+ }) {
40
+ const t = useDsMessages();
41
+ const locale = useDsLocale();
42
+ const [own, setOwn] = React.useState([]);
43
+ const items = files ?? own;
44
+ const itemsRef = React.useRef(items);
45
+ itemsRef.current = items;
46
+ const changeRef = React.useRef(onFilesChange);
47
+ changeRef.current = onFilesChange;
48
+ const controlled = files !== void 0;
49
+ const controllers = React.useRef(/* @__PURE__ */ new Map());
50
+ const counter = React.useRef(0);
51
+ const uid = React.useId();
52
+ const commit = React.useCallback(
53
+ (next) => {
54
+ itemsRef.current = next;
55
+ if (!controlled) setOwn(next);
56
+ changeRef.current?.(next);
57
+ },
58
+ [controlled]
59
+ );
60
+ const patch = React.useCallback(
61
+ (itemId, change) => {
62
+ if (!itemsRef.current.some((i) => i.id === itemId)) return;
63
+ commit(itemsRef.current.map((i) => i.id === itemId ? { ...i, ...change } : i));
64
+ },
65
+ [commit]
66
+ );
67
+ const start = React.useCallback(
68
+ (item) => {
69
+ if (!upload) return;
70
+ const ac = new AbortController();
71
+ controllers.current.set(item.id, ac);
72
+ upload(item.file, (p) => patch(item.id, { progress: Math.min(100, Math.max(0, p)) }), ac.signal).then(
73
+ () => patch(item.id, { status: "done", progress: 100, error: void 0 }),
74
+ (e) => {
75
+ if (ac.signal.aborted) return;
76
+ patch(item.id, { status: "error", error: e instanceof Error ? e.message : void 0 });
77
+ }
78
+ ).finally(() => controllers.current.delete(item.id));
79
+ },
80
+ [upload, patch]
81
+ );
82
+ React.useEffect(() => {
83
+ const map = controllers.current;
84
+ return () => {
85
+ for (const ac of map.values()) ac.abort();
86
+ };
87
+ }, []);
88
+ const remove = (itemId) => {
89
+ controllers.current.get(itemId)?.abort();
90
+ controllers.current.delete(itemId);
91
+ commit(itemsRef.current.filter((i) => i.id !== itemId));
92
+ };
93
+ const retry = (item) => {
94
+ patch(item.id, { status: "uploading", progress: 0, error: void 0 });
95
+ start(item);
96
+ };
97
+ const onFiles = (accepted) => {
98
+ const created = accepted.map((file) => ({
99
+ id: `${uid}-${counter.current++}`,
100
+ file,
101
+ status: upload ? "uploading" : "ready",
102
+ progress: 0
103
+ }));
104
+ if (!multiple) {
105
+ for (const ac of controllers.current.values()) ac.abort();
106
+ controllers.current.clear();
107
+ }
108
+ commit(multiple ? [...itemsRef.current, ...created] : created.slice(0, 1));
109
+ for (const item of multiple ? created : created.slice(0, 1)) start(item);
110
+ };
111
+ const remaining = multiple && maxFiles != null ? Math.max(0, maxFiles - items.length) : void 0;
112
+ const zoneDisabled = disabled || remaining === 0;
113
+ const statusText = (item) => item.status === "uploading" ? t.fileUploadUploading : item.status === "done" ? t.fileUploadDone : item.status === "error" ? item.error ?? t.fileUploadFailed : "";
114
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "file-upload", "data-preset": preset, className: cn("flex w-full flex-col gap-3", className), children: [
115
+ /* @__PURE__ */ jsx(
116
+ Dropzone,
117
+ {
118
+ accept,
119
+ maxSize,
120
+ maxFiles: remaining,
121
+ multiple,
122
+ disabled: zoneDisabled,
123
+ onFiles,
124
+ name,
125
+ id,
126
+ ...preset === "drop" ? { title, hint, description, icon } : {},
127
+ areaClassName: preset === "button" ? "items-start border-0 bg-transparent p-0 hover:bg-transparent data-[state=drag-over]:bg-accent data-[state=error]:bg-transparent" : void 0,
128
+ children: preset === "button" ? /* @__PURE__ */ jsxs("span", { className: "flex flex-wrap items-center gap-2", children: [
129
+ /* @__PURE__ */ jsxs("span", { className: buttonVariants({ variant: "outline" }), children: [
130
+ icon ?? /* @__PURE__ */ jsx(PaperclipIcon, {}),
131
+ label ?? t.fileUploadAttach
132
+ ] }),
133
+ description ? /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: description }) : null
134
+ ] }) : void 0
135
+ }
136
+ ),
137
+ items.length > 0 ? /* @__PURE__ */ jsx("ul", { "data-slot": "file-upload-list", "aria-live": "polite", className: "flex flex-col gap-2", children: items.map((item) => /* @__PURE__ */ jsx("li", { "data-slot": "file-upload-item", "data-status": item.status, className: "flex", children: /* @__PURE__ */ jsxs(
138
+ Attachment,
139
+ {
140
+ state: item.status === "ready" ? "done" : item.status,
141
+ orientation: "horizontal",
142
+ className: "w-full",
143
+ children: [
144
+ /* @__PURE__ */ jsx(AttachmentMedia, { children: item.status === "uploading" ? /* @__PURE__ */ jsx(Spinner, { role: "presentation", "aria-label": void 0, "aria-hidden": "true" }) : item.status === "error" ? /* @__PURE__ */ jsx(AlertCircleIcon, {}) : /* @__PURE__ */ jsx(FileIcon, {}) }),
145
+ /* @__PURE__ */ jsxs(AttachmentContent, { children: [
146
+ /* @__PURE__ */ jsx(AttachmentTitle, { children: item.file.name }),
147
+ /* @__PURE__ */ jsx(AttachmentDescription, { children: [formatBytes(item.file.size, locale), statusText(item)].filter(Boolean).join(" \xB7 ") }),
148
+ item.status === "uploading" ? /* @__PURE__ */ jsx(Progress, { value: item.progress, "aria-label": item.file.name, className: "mt-1.5" }) : null
149
+ ] }),
150
+ /* @__PURE__ */ jsxs(AttachmentActions, { children: [
151
+ item.status === "error" && upload ? /* @__PURE__ */ jsx(
152
+ AttachmentAction,
153
+ {
154
+ "aria-label": dsFormat(t.fileUploadRetry, { name: item.file.name }),
155
+ onClick: () => retry(item),
156
+ children: /* @__PURE__ */ jsx(RotateCcwIcon, {})
157
+ }
158
+ ) : null,
159
+ /* @__PURE__ */ jsx(
160
+ AttachmentAction,
161
+ {
162
+ "aria-label": dsFormat(t.fileUploadRemove, { name: item.file.name }),
163
+ onClick: () => remove(item.id),
164
+ children: /* @__PURE__ */ jsx(XIcon, {})
165
+ }
166
+ )
167
+ ] })
168
+ ]
169
+ }
170
+ ) }, item.id)) }) : null
171
+ ] });
172
+ }
173
+ export {
174
+ FileUpload
175
+ };
@@ -1,6 +1,8 @@
1
1
  import * as React from 'react';
2
2
 
3
- declare function FilterBar({ className, children, actions, onClear, canClear, ...props }: React.ComponentProps<"div"> & {
3
+ type FilterBarPreset = "inline" | "compact" | "stacked";
4
+ declare function FilterBar({ preset, className, children, actions, onClear, canClear, ...props }: React.ComponentProps<"div"> & {
5
+ preset?: FilterBarPreset;
4
6
  /** Acciones de la vista (exportar, guardar vista…), al final de la fila. */
5
7
  actions?: React.ReactNode;
6
8
  /** Si se pasa, muestra «Quitar filtros». */
@@ -33,4 +35,4 @@ declare function FilterMenu({ className, label, icon, value, onValueChange, opti
33
35
  id?: string;
34
36
  }): React.JSX.Element;
35
37
 
36
- export { FilterBar, FilterMenu, type FilterOption };
38
+ export { FilterBar, type FilterBarPreset, FilterMenu, type FilterOption };
@@ -14,7 +14,13 @@ import {
14
14
  DropdownMenuTrigger
15
15
  } from "./dropdown-menu.js";
16
16
  import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
17
+ const BAR_PRESETS = {
18
+ inline: "",
19
+ compact: "[--ds-filter-gap:var(--ds-filter-gap-compact)]",
20
+ stacked: "flex-col items-stretch [&>[data-slot=filter-bar-actions]]:ms-0"
21
+ };
17
22
  function FilterBar({
23
+ preset = "inline",
18
24
  className,
19
25
  children,
20
26
  actions,
@@ -27,8 +33,10 @@ function FilterBar({
27
33
  "div",
28
34
  {
29
35
  "data-slot": "filter-bar",
36
+ "data-preset": preset,
30
37
  className: cn(
31
38
  "flex w-full flex-wrap items-center gap-(--ds-filter-gap)",
39
+ BAR_PRESETS[preset],
32
40
  className
33
41
  ),
34
42
  ...props,
@@ -3,7 +3,10 @@ import { IconTile } from './icon-tile.js';
3
3
  import 'class-variance-authority/types';
4
4
  import 'class-variance-authority';
5
5
 
6
- declare function PageHeader({ className, ...props }: React.ComponentProps<"header">): React.JSX.Element;
6
+ type PageHeaderPreset = "page" | "compact" | "canvas";
7
+ declare function PageHeader({ preset, className, ...props }: React.ComponentProps<"header"> & {
8
+ preset?: PageHeaderPreset;
9
+ }): React.JSX.Element;
7
10
  declare function PageHeaderBreadcrumb({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
8
11
  declare function PageHeaderTitle({ className, ...props }: React.ComponentProps<"h1">): React.JSX.Element;
9
12
  declare function PageHeaderDescription({ className, ...props }: React.ComponentProps<"p">): React.JSX.Element;
@@ -16,4 +19,4 @@ declare function SectionHeaderTitle({ className, ...props }: React.ComponentProp
16
19
  declare function SectionHeaderDescription({ className, ...props }: React.ComponentProps<"p">): React.JSX.Element;
17
20
  declare function SectionHeaderActions({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
18
21
 
19
- export { PageHeader, PageHeaderActions, PageHeaderBreadcrumb, PageHeaderDescription, PageHeaderNotice, PageHeaderTitle, SectionHeader, SectionHeaderActions, SectionHeaderDescription, SectionHeaderIcon, SectionHeaderTitle };
22
+ export { PageHeader, PageHeaderActions, PageHeaderBreadcrumb, PageHeaderDescription, PageHeaderNotice, type PageHeaderPreset, PageHeaderTitle, SectionHeader, SectionHeaderActions, SectionHeaderDescription, SectionHeaderIcon, SectionHeaderTitle };
@@ -1,13 +1,24 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { cn } from "../lib/utils.js";
3
3
  import { IconTile } from "./icon-tile.js";
4
- function PageHeader({ className, ...props }) {
4
+ const HEADER_PRESETS = {
5
+ page: "",
6
+ compact: "[--ds-page-title-size:var(--ds-page-title-size-compact)] [--ds-page-title-size-wide:var(--ds-page-title-size-compact-wide)] mb-(--ds-section-gap)",
7
+ canvas: "max-w-none"
8
+ };
9
+ function PageHeader({
10
+ preset = "page",
11
+ className,
12
+ ...props
13
+ }) {
5
14
  return /* @__PURE__ */ jsx(
6
15
  "header",
7
16
  {
8
17
  "data-slot": "page-header",
18
+ "data-preset": preset,
9
19
  className: cn(
10
20
  "group/page-header @container/page-header mx-auto mb-(--ds-page-gap) grid w-full max-w-(--ds-page-max-w) grid-cols-1 gap-x-(--ds-page-gap) gap-y-0 [grid-template-areas:'breadcrumb'_'title'_'description'_'actions'_'notice'] @2xl/page-header:grid-cols-[minmax(0,1fr)_auto] @2xl/page-header:[grid-template-areas:'breadcrumb_breadcrumb'_'title_actions'_'description_actions'_'notice_notice']",
21
+ HEADER_PRESETS[preset],
11
22
  className
12
23
  ),
13
24
  ...props
@@ -23,7 +34,7 @@ function PageHeaderTitle({ className, ...props }) {
23
34
  {
24
35
  "data-slot": "page-header-title",
25
36
  className: cn(
26
- "min-w-0 text-2xl leading-tight font-(--ds-heading-weight) text-foreground [grid-area:title] @2xl/page-header:text-3xl",
37
+ "min-w-0 text-(length:--ds-page-title-size) leading-tight font-(--ds-heading-weight) text-foreground [grid-area:title] @2xl/page-header:text-(length:--ds-page-title-size-wide)",
27
38
  className
28
39
  ),
29
40
  ...props
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+
3
+ type PageLoaderPreset = "splash" | "route" | "section" | "overlay";
4
+ type PageLoaderIndicator = "orbit" | "pulse" | "bars";
5
+ declare function PageLoader({ preset, indicator, message, messages, interval, value, mark, delay, className, }: {
6
+ preset?: PageLoaderPreset;
7
+ indicator?: PageLoaderIndicator;
8
+ /** Texto fijo bajo el indicador. */
9
+ message?: string;
10
+ /** Varios textos que rotan (cargas largas: «Conectando…», «Preparando tu espacio…»). */
11
+ messages?: string[];
12
+ /** Milisegundos entre mensajes. */
13
+ interval?: number;
14
+ /** Avance 0–100. Sin valor, indeterminado. */
15
+ value?: number;
16
+ /** Marca o logo (preset splash). */
17
+ mark?: React.ReactNode;
18
+ /** Milisegundos antes de mostrarse; evita el parpadeo en cargas cortas. */
19
+ delay?: number;
20
+ className?: string;
21
+ }): React.JSX.Element;
22
+
23
+ export { PageLoader, type PageLoaderIndicator, type PageLoaderPreset };
@@ -0,0 +1,163 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { useDsMessages } from "../hooks/use-ds-messages.js";
5
+ import { cn } from "../lib/utils.js";
6
+ const PRESETS = {
7
+ splash: {
8
+ delay: 0,
9
+ frame: "fixed inset-0 z-(--ds-z-overlay) flex-col gap-6 bg-background"
10
+ },
11
+ route: {
12
+ delay: 150,
13
+ frame: "fixed inset-x-0 top-0 z-(--ds-z-overlay) h-(--ds-pageloader-route-h) pointer-events-none"
14
+ },
15
+ section: {
16
+ delay: 150,
17
+ frame: "min-h-(--ds-pageloader-min-h) w-full flex-col gap-4"
18
+ },
19
+ overlay: {
20
+ delay: 150,
21
+ frame: "absolute inset-0 z-(--ds-z-raised) flex-col gap-4 bg-background/70 backdrop-blur-(--ds-scrim-blur)"
22
+ }
23
+ };
24
+ function Indicator({ kind }) {
25
+ if (kind === "pulse") {
26
+ return /* @__PURE__ */ jsxs("span", { "aria-hidden": "true", className: "relative grid size-(--ds-pageloader-size) place-items-center", children: [
27
+ /* @__PURE__ */ jsx("span", { className: "absolute inset-0 animate-ds-pageloader-wave rounded-full bg-primary motion-reduce:animate-none" }),
28
+ /* @__PURE__ */ jsx("span", { className: "absolute inset-0 animate-ds-pageloader-wave rounded-full bg-primary [animation-delay:calc(var(--ds-motion-pulse)/-2)] motion-reduce:animate-none" }),
29
+ /* @__PURE__ */ jsx("span", { className: "size-(--ds-pageloader-dot) rounded-full bg-primary" })
30
+ ] });
31
+ }
32
+ if (kind === "bars") {
33
+ return /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "flex h-(--ds-pageloader-size) items-center gap-1.5", children: [0, 1, 2, 3].map((i) => /* @__PURE__ */ jsx(
34
+ "span",
35
+ {
36
+ className: "h-full w-(--ds-pageloader-bar-w) origin-center animate-ds-pageloader-bars rounded-full bg-primary motion-reduce:animate-none",
37
+ style: { animationDelay: `calc(var(--ds-motion-pulse) * ${i} / -6)` }
38
+ },
39
+ i
40
+ )) });
41
+ }
42
+ return /* @__PURE__ */ jsxs(
43
+ "span",
44
+ {
45
+ "aria-hidden": "true",
46
+ className: "relative grid size-(--ds-pageloader-size) place-items-center rounded-full border-(length:--ds-pageloader-stroke) border-(--ds-track-bg)",
47
+ children: [
48
+ /* @__PURE__ */ jsx("span", { className: "absolute inset-0 animate-ds-orbit motion-reduce:animate-none", children: /* @__PURE__ */ jsx("span", { className: "absolute inset-x-0 top-0 mx-auto size-(--ds-pageloader-dot) -translate-y-1/2 rounded-full bg-primary" }) }),
49
+ /* @__PURE__ */ jsx("span", { className: "size-(--ds-pageloader-core) animate-ds-ring-inner rounded-full bg-primary/25 motion-reduce:animate-none" })
50
+ ]
51
+ }
52
+ );
53
+ }
54
+ function PageLoader({
55
+ preset = "section",
56
+ indicator = "orbit",
57
+ message,
58
+ messages,
59
+ interval = 2400,
60
+ value,
61
+ mark,
62
+ delay,
63
+ className
64
+ }) {
65
+ const t = useDsMessages();
66
+ const base = PRESETS[preset];
67
+ const wait = delay ?? base.delay;
68
+ const [visible, setVisible] = React.useState(wait <= 0);
69
+ const [index, setIndex] = React.useState(0);
70
+ React.useEffect(() => {
71
+ if (wait <= 0) return setVisible(true);
72
+ const id = window.setTimeout(() => setVisible(true), wait);
73
+ return () => window.clearTimeout(id);
74
+ }, [wait]);
75
+ const list = messages && messages.length > 0 ? messages : null;
76
+ React.useEffect(() => {
77
+ if (!list || list.length < 2) return;
78
+ const id = window.setInterval(() => setIndex((i) => (i + 1) % list.length), interval);
79
+ return () => window.clearInterval(id);
80
+ }, [list, interval]);
81
+ const text = list ? list[index % list.length] : message;
82
+ const determinate = typeof value === "number" && Number.isFinite(value);
83
+ const pct = determinate ? Math.min(Math.max(value, 0), 100) : 0;
84
+ const state = visible ? "visible" : "waiting";
85
+ if (preset === "route") {
86
+ return /* @__PURE__ */ jsxs(
87
+ "div",
88
+ {
89
+ role: "status",
90
+ "aria-busy": "true",
91
+ "data-slot": "page-loader",
92
+ "data-preset": preset,
93
+ "data-state": state,
94
+ className: cn(base.frame, !visible && "hidden", className),
95
+ children: [
96
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: text ?? t.loading }),
97
+ /* @__PURE__ */ jsx(
98
+ "span",
99
+ {
100
+ "aria-hidden": "true",
101
+ className: "relative block size-full overflow-hidden bg-(--ds-track-bg) [--ds-dir:1] rtl:[--ds-dir:-1]",
102
+ children: /* @__PURE__ */ jsx(
103
+ "span",
104
+ {
105
+ className: cn(
106
+ "absolute inset-y-0 start-0 bg-primary",
107
+ determinate ? "transition-[width] duration-(--ds-motion-slow) ease-(--ds-ease-standard) motion-reduce:transition-none" : "w-2/5 animate-ds-indeterminate motion-reduce:animate-none"
108
+ ),
109
+ style: determinate ? { width: `${pct}%` } : void 0
110
+ }
111
+ )
112
+ }
113
+ )
114
+ ]
115
+ }
116
+ );
117
+ }
118
+ return /* @__PURE__ */ jsxs(
119
+ "div",
120
+ {
121
+ role: "status",
122
+ "aria-busy": "true",
123
+ "data-slot": "page-loader",
124
+ "data-preset": preset,
125
+ "data-indicator": indicator,
126
+ "data-state": state,
127
+ className: cn("items-center justify-center text-center", base.frame, visible ? "flex" : "hidden", className),
128
+ children: [
129
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: text ?? t.loading }),
130
+ mark && preset === "splash" ? /* @__PURE__ */ jsx("span", { "data-slot": "page-loader-mark", "aria-hidden": "true", className: "grid place-items-center", children: mark }) : null,
131
+ /* @__PURE__ */ jsx(Indicator, { kind: indicator }),
132
+ text ? /* @__PURE__ */ jsx(
133
+ "span",
134
+ {
135
+ "data-slot": "page-loader-message",
136
+ "aria-hidden": "true",
137
+ className: "max-w-prose px-4 text-sm text-muted-foreground animate-in fade-in motion-reduce:animate-none",
138
+ children: text
139
+ },
140
+ text
141
+ ) : null,
142
+ determinate ? /* @__PURE__ */ jsx(
143
+ "span",
144
+ {
145
+ "data-slot": "page-loader-progress",
146
+ "aria-hidden": "true",
147
+ className: "relative h-(--ds-loader-bar-h) w-(--ds-pageloader-progress-w) overflow-hidden rounded-full bg-(--ds-track-bg)",
148
+ children: /* @__PURE__ */ jsx(
149
+ "span",
150
+ {
151
+ className: "absolute inset-y-0 start-0 bg-primary transition-[width] duration-(--ds-motion-slow) ease-(--ds-ease-standard) motion-reduce:transition-none",
152
+ style: { width: `${pct}%` }
153
+ }
154
+ )
155
+ }
156
+ ) : null
157
+ ]
158
+ }
159
+ );
160
+ }
161
+ export {
162
+ PageLoader
163
+ };