@shlinkio/shlink-frontend-kit 0.9.8 → 0.9.10

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,102 @@
1
+ import { useMemo as T, useEffect as C, useRef as A, useCallback as d, useState as b } from "react";
2
+ function k(e, { elementsSelector: o, focusFirstItem: r = !1, vertical: n = !0, horizontal: t = !0 }) {
3
+ const s = T(() => {
4
+ const c = [];
5
+ return n && c.push("ArrowDown"), t && c.push("ArrowRight"), c;
6
+ }, [t, n]), u = T(() => {
7
+ const c = [];
8
+ return n && c.push("ArrowUp"), t && c.push("ArrowLeft"), c;
9
+ }, [t, n]), l = T(() => [...s, ...u], [s, u]);
10
+ C(() => {
11
+ const c = e.current;
12
+ if (!c)
13
+ return () => {
14
+ };
15
+ const f = new AbortController(), g = () => [...c.querySelectorAll(o)], w = g(), h = Math.max(w.findIndex((i) => i.dataset.selected === "true"), 0);
16
+ return w.forEach((i, a) => {
17
+ i.tabIndex = a === h ? 0 : -1, r && a === h && i.focus();
18
+ }), c.addEventListener("keydown", (i) => {
19
+ if (!l.includes(i.key))
20
+ return;
21
+ i.preventDefault();
22
+ const a = g(), p = a.findIndex((m) => m.tabIndex === 0), y = s.includes(i.key) ? a[p + 1] ?? a[0] : a[p - 1] ?? a[a.length - 1];
23
+ a.forEach((m) => {
24
+ m.tabIndex = -1;
25
+ }), y.tabIndex = 0, y.focus();
26
+ }, { signal: f.signal }), () => f.abort();
27
+ }, [l, e, o, r, s]);
28
+ }
29
+ function E(e, o = globalThis.setTimeout, r = globalThis.clearTimeout) {
30
+ const n = A(null), t = d(() => {
31
+ n.current && r(n.current);
32
+ }, [r]), s = d((u, l) => {
33
+ t(), n.current = o(() => {
34
+ u(), n.current = null;
35
+ }, l ?? e);
36
+ }, [t, e, o]);
37
+ return C(() => t, [t]), T(
38
+ () => ({ setTimeout: s, clearCurrentTimeout: t }),
39
+ [t, s]
40
+ );
41
+ }
42
+ const F = 2e3, I = (e = {}, o, r = globalThis.setTimeout, n = globalThis.clearTimeout) => {
43
+ const { initialValue: t = !1, delay: s = F } = typeof e == "boolean" ? {
44
+ initialValue: e,
45
+ delay: o
46
+ } : e, { setTimeout: u } = E(s, r, n), [l, c] = b(t), f = A(t), g = d(() => {
47
+ c(!f.current), u(() => c(f.current));
48
+ }, [u]);
49
+ return [l, g];
50
+ };
51
+ function L(e = !1, o = !1) {
52
+ const [r, n] = b(e), t = d(() => n((l) => !l), []), s = d(() => n(!0), []), u = d(() => n(!1), []);
53
+ return o ? { flag: r, toggle: t, setToTrue: s, setToFalse: u } : [r, t, s, u];
54
+ }
55
+ function D(e, o, r) {
56
+ if (!e || typeof e == "string")
57
+ return D({ currentField: e, newField: o, currentOrderDir: r });
58
+ const n = e;
59
+ if (n.currentField !== n.newField)
60
+ return "ASC";
61
+ const t = {
62
+ ASC: "DESC",
63
+ DESC: void 0
64
+ };
65
+ return n.currentOrderDir ? t[n.currentOrderDir] : "ASC";
66
+ }
67
+ function S(e, o, r) {
68
+ if (!e || typeof e == "string")
69
+ return S({ currentField: e, newField: o, currentOrderDir: r });
70
+ const n = e, t = D(n);
71
+ return {
72
+ field: t ? n.newField : void 0,
73
+ dir: t
74
+ };
75
+ }
76
+ const v = (e, { field: o, dir: r }) => !o || !r ? e : e.sort((n, t) => {
77
+ const s = r === "ASC" ? 1 : -1, u = r === "ASC" ? -1 : 1;
78
+ return n[o] > t[o] ? s : u;
79
+ }), M = (e) => e.dir ? `${e.field}-${e.dir}` : void 0, R = (e) => {
80
+ const [o, r] = e.split("-");
81
+ return { field: o, dir: r };
82
+ }, U = (e) => {
83
+ const [o, r] = b(e), n = d(
84
+ (t, s) => r(
85
+ t && typeof t == "object" ? t : { field: t, dir: s }
86
+ ),
87
+ []
88
+ );
89
+ return [o, n];
90
+ };
91
+ export {
92
+ k as a,
93
+ E as b,
94
+ I as c,
95
+ D as d,
96
+ S as e,
97
+ R as f,
98
+ U as g,
99
+ M as o,
100
+ v as s,
101
+ L as u
102
+ };
@@ -15,6 +15,8 @@ import { ReferenceType } from '@floating-ui/react-dom';
15
15
  import { ReferenceType as ReferenceType_2 } from '@floating-ui/react';
16
16
  import { RefObject } from 'react';
17
17
 
18
+ declare type AnchorProps = Omit<LinkProps, 'role' | 'aria-disabled' | 'tabIndex'>;
19
+
18
20
  export declare type BaseInputProps = {
19
21
  size?: Size;
20
22
  feedback?: 'error';
@@ -58,6 +60,8 @@ export declare type ButtonProps = PropsWithChildren<{
58
60
  solid?: boolean;
59
61
  } & (RegularButtonProps | LinkButtonProps_2)>;
60
62
 
63
+ declare type ButtonProps_2 = Omit<HTMLProps<HTMLButtonElement>, 'role' | 'disabled' | 'aria-disabled' | 'tabIndex'>;
64
+
61
65
  export declare const Card: ForwardRefExoticComponent<CardProps & RefAttributes<HTMLDivElement>> & {
62
66
  Body: ForwardRefExoticComponent<CardProps & RefAttributes<HTMLDivElement>>;
63
67
  Header: ForwardRefExoticComponent<CardProps & RefAttributes<HTMLDivElement>>;
@@ -131,6 +135,36 @@ export declare type DetailsProps = Omit<HTMLProps<HTMLDetailsElement>, 'ref'> &
131
135
  summaryClasses?: string;
132
136
  };
133
137
 
138
+ export declare const Dropdown: FC<DropdownProps> & {
139
+ Item: FC<MenuItemProps>;
140
+ Separator: FC;
141
+ Title: FC<{
142
+ children?: ReactNode | undefined;
143
+ }>;
144
+ Misc: FC<HTMLProps<HTMLDivElement>>;
145
+ };
146
+
147
+ export declare type DropdownProps = PropsWithChildren<{
148
+ buttonContent: RequiredReactNode;
149
+ buttonSize?: Size;
150
+ buttonClassName?: string;
151
+ buttonVariant?: 'button' | 'link';
152
+ buttonDisabled?: boolean;
153
+ /** Set as the button's `aria-label` attribute */
154
+ buttonLabel?: string;
155
+ /** Classes to be set on the containing wrapper element */
156
+ containerClassName?: string;
157
+ /** Classes to be set on the menu element */
158
+ menuClassName?: string;
159
+ /**
160
+ * Whether the menu should align with the right or the left side of the toggle button in case it is bigger.
161
+ * Defaults to 'left'.
162
+ */
163
+ menuAlignment?: 'left' | 'right';
164
+ /** Whether to hide the caret or not. Defaults to false */
165
+ caretless?: boolean;
166
+ }>;
167
+
134
168
  export declare const ELLIPSIS = "...";
135
169
 
136
170
  declare type Ellipsis = typeof ELLIPSIS;
@@ -246,6 +280,33 @@ export declare type ListboxProps<Item> = Omit<CardProps, 'id' | 'role' | 'aria-o
246
280
  noItemsMessage?: string;
247
281
  };
248
282
 
283
+ export declare const Menu: FC<MenuProps> & {
284
+ Item: FC<MenuItemProps>;
285
+ Separator: FC;
286
+ Title: FC<{
287
+ children?: ReactNode | undefined;
288
+ }>;
289
+ Misc: FC<HTMLProps<HTMLDivElement>>;
290
+ };
291
+
292
+ export declare type MenuItemProps = (ButtonProps_2 | AnchorProps) & {
293
+ selected?: boolean;
294
+ disabled?: boolean;
295
+ };
296
+
297
+ export declare type MenuProps = Omit<CardProps, 'role'> & {
298
+ /**
299
+ * Selector to determine elements that should be part of the focus sequence.
300
+ * Defaults to '[role="menuitem"]:not([disabled]):not([aria-disabled])'
301
+ */
302
+ focusableElementsSelector?: string;
303
+ /**
304
+ * Whether first focusable item should be focused or not.
305
+ * Defaults to false.
306
+ */
307
+ focusFirstItem?: boolean;
308
+ };
309
+
249
310
  /**
250
311
  * Component used to display a card with general information, about current page status, loading, etc.
251
312
  */
@@ -282,6 +343,22 @@ declare type NoTitleProps = {
282
343
 
283
344
  export declare type NumberOrEllipsis = number | Ellipsis;
284
345
 
346
+ declare type Order<Fields> = {
347
+ field?: Fields;
348
+ dir?: OrderDir;
349
+ };
350
+
351
+ declare type OrderDir = 'ASC' | 'DESC' | undefined;
352
+
353
+ export declare function OrderingDropdown<T extends string = string>({ items, order, onChange, prefixed, buttonVariant, ...rest }: OrderingDropdownProps<T>): JSX.Element;
354
+
355
+ export declare type OrderingDropdownProps<T extends string = string> = Omit<DropdownProps, 'buttonContent'> & {
356
+ items: Record<T, string>;
357
+ order: Order<T>;
358
+ onChange: (newOrder: Order<T>) => void;
359
+ prefixed?: boolean;
360
+ };
361
+
285
362
  export declare const pageIsEllipsis: (pageNumber: NumberOrEllipsis) => pageNumber is Ellipsis;
286
363
 
287
364
  export declare const Paginator: FC<PaginatorProps>;
@@ -346,6 +423,17 @@ export declare type RevealablePasswordInputProps = Omit<InputProps, 'type'> & {
346
423
 
347
424
  export declare const roundTen: (number: number) => number;
348
425
 
426
+ export declare const RowDropdown: FC<RowDropdownProps> & {
427
+ Item: FC<MenuItemProps>;
428
+ Separator: FC;
429
+ Title: FC<{
430
+ children?: ReactNode | undefined;
431
+ }>;
432
+ Misc: FC<HTMLProps<HTMLDivElement>>;
433
+ };
434
+
435
+ export declare type RowDropdownProps = Omit<DropdownProps, 'caretless' | 'buttonContent' | 'buttonVariant'>;
436
+
349
437
  /**
350
438
  * This component combines a SearchInput with a Listbox, to behave close to an editable combobox with autocomplete, as
351
439
  * described in https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-autocomplete-list/.