@g4rcez/components 5.0.1 → 5.0.2
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/dist/components/core/button.d.ts +77 -0
- package/dist/components/core/button.d.ts.map +1 -0
- package/dist/components/core/button.jsx +79 -0
- package/dist/components/core/heading.d.ts +3 -0
- package/dist/components/core/heading.d.ts.map +1 -0
- package/dist/components/core/heading.jsx +4 -0
- package/dist/components/core/polymorph.d.ts +10 -0
- package/dist/components/core/polymorph.d.ts.map +1 -0
- package/dist/components/core/polymorph.jsx +5 -0
- package/dist/components/core/render-on-view.d.ts +7 -0
- package/dist/components/core/render-on-view.d.ts.map +1 -0
- package/dist/components/core/render-on-view.jsx +31 -0
- package/dist/components/core/resizable.d.ts +3 -0
- package/dist/components/core/resizable.d.ts.map +1 -0
- package/dist/components/core/resizable.jsx +51 -0
- package/dist/components/core/slot.d.ts +16 -0
- package/dist/components/core/slot.d.ts.map +1 -0
- package/dist/components/core/slot.jsx +156 -0
- package/dist/components/core/tag.d.ts +35 -0
- package/dist/components/core/tag.d.ts.map +1 -0
- package/dist/components/core/tag.jsx +53 -0
- package/dist/components/core/typography.d.ts +25 -0
- package/dist/components/core/typography.d.ts.map +1 -0
- package/dist/components/core/typography.jsx +20 -0
- package/dist/components/display/alert.d.ts +28 -0
- package/dist/components/display/alert.d.ts.map +1 -0
- package/dist/components/display/alert.jsx +61 -0
- package/dist/components/display/calendar.d.ts +42 -0
- package/dist/components/display/calendar.d.ts.map +1 -0
- package/dist/components/display/calendar.jsx +318 -0
- package/dist/components/display/card.d.ts +29 -0
- package/dist/components/display/card.d.ts.map +1 -0
- package/dist/components/display/card.jsx +43 -0
- package/dist/components/display/empty.d.ts +8 -0
- package/dist/components/display/empty.d.ts.map +1 -0
- package/dist/components/display/empty.jsx +11 -0
- package/dist/components/display/list.d.ts +16 -0
- package/dist/components/display/list.d.ts.map +1 -0
- package/dist/components/display/list.jsx +85 -0
- package/dist/components/display/notifications.d.ts +27 -0
- package/dist/components/display/notifications.d.ts.map +1 -0
- package/dist/components/display/notifications.jsx +130 -0
- package/dist/components/display/progress.d.ts +16 -0
- package/dist/components/display/progress.d.ts.map +1 -0
- package/dist/components/display/progress.jsx +21 -0
- package/dist/components/display/shortcut.d.ts +4 -0
- package/dist/components/display/shortcut.d.ts.map +1 -0
- package/dist/components/display/shortcut.jsx +23 -0
- package/dist/components/display/skeleton.d.ts +12 -0
- package/dist/components/display/skeleton.d.ts.map +1 -0
- package/dist/components/display/skeleton.jsx +19 -0
- package/dist/components/display/spinner.d.ts +5 -0
- package/dist/components/display/spinner.d.ts.map +1 -0
- package/dist/components/display/spinner.jsx +11 -0
- package/dist/components/display/stats.d.ts +12 -0
- package/dist/components/display/stats.d.ts.map +1 -0
- package/dist/components/display/stats.jsx +16 -0
- package/dist/components/display/step.d.ts +24 -0
- package/dist/components/display/step.d.ts.map +1 -0
- package/dist/components/display/step.jsx +145 -0
- package/dist/components/display/tabs.d.ts +24 -0
- package/dist/components/display/tabs.d.ts.map +1 -0
- package/dist/components/display/tabs.jsx +125 -0
- package/dist/components/display/timeline.d.ts +10 -0
- package/dist/components/display/timeline.d.ts.map +1 -0
- package/dist/components/display/timeline.jsx +25 -0
- package/dist/components/floating/command-palette.d.ts +49 -0
- package/dist/components/floating/command-palette.d.ts.map +1 -0
- package/dist/components/floating/command-palette.jsx +223 -0
- package/dist/components/floating/dropdown.d.ts +15 -0
- package/dist/components/floating/dropdown.d.ts.map +1 -0
- package/dist/components/floating/dropdown.jsx +56 -0
- package/dist/components/floating/expand.d.ts +11 -0
- package/dist/components/floating/expand.d.ts.map +1 -0
- package/dist/components/floating/expand.jsx +44 -0
- package/dist/components/floating/menu.d.ts +52 -0
- package/dist/components/floating/menu.d.ts.map +1 -0
- package/dist/components/floating/menu.jsx +165 -0
- package/dist/components/floating/modal.d.ts +60 -0
- package/dist/components/floating/modal.d.ts.map +1 -0
- package/dist/components/floating/modal.jsx +336 -0
- package/dist/components/floating/toolbar.d.ts +6 -0
- package/dist/components/floating/toolbar.d.ts.map +1 -0
- package/dist/components/floating/toolbar.jsx +5 -0
- package/dist/components/floating/tooltip.d.ts +17 -0
- package/dist/components/floating/tooltip.d.ts.map +1 -0
- package/dist/components/floating/tooltip.jsx +67 -0
- package/dist/components/floating/wizard.d.ts +26 -0
- package/dist/components/floating/wizard.d.ts.map +1 -0
- package/dist/components/floating/wizard.jsx +165 -0
- package/dist/components/form/autocomplete.d.ts +16 -0
- package/dist/components/form/autocomplete.d.ts.map +1 -0
- package/dist/components/form/autocomplete.jsx +290 -0
- package/dist/components/form/checkbox.d.ts +12 -0
- package/dist/components/form/checkbox.d.ts.map +1 -0
- package/dist/components/form/checkbox.jsx +12 -0
- package/dist/components/form/date-picker.d.ts +10 -0
- package/dist/components/form/date-picker.d.ts.map +1 -0
- package/dist/components/form/date-picker.jsx +115 -0
- package/dist/components/form/file-upload.d.ts +15 -0
- package/dist/components/form/file-upload.d.ts.map +1 -0
- package/dist/components/form/file-upload.jsx +138 -0
- package/dist/components/form/form.d.ts +3 -0
- package/dist/components/form/form.d.ts.map +1 -0
- package/dist/components/form/form.jsx +10 -0
- package/dist/components/form/formReset.d.ts +2 -0
- package/dist/components/form/formReset.d.ts.map +1 -0
- package/dist/components/form/formReset.jsx +17 -0
- package/dist/components/form/free-text.d.ts +11 -0
- package/dist/components/form/free-text.d.ts.map +1 -0
- package/dist/components/form/free-text.jsx +41 -0
- package/dist/components/form/input-field.d.ts +34 -0
- package/dist/components/form/input-field.d.ts.map +1 -0
- package/dist/components/form/input-field.jsx +58 -0
- package/dist/components/form/input.d.ts +52 -0
- package/dist/components/form/input.d.ts.map +1 -0
- package/dist/components/form/input.jsx +36 -0
- package/dist/components/form/multi-select.d.ts +19 -0
- package/dist/components/form/multi-select.d.ts.map +1 -0
- package/dist/components/form/multi-select.jsx +344 -0
- package/dist/components/form/radiobox.d.ts +7 -0
- package/dist/components/form/radiobox.d.ts.map +1 -0
- package/dist/components/form/radiobox.jsx +6 -0
- package/dist/components/form/select.d.ts +13 -0
- package/dist/components/form/select.d.ts.map +1 -0
- package/dist/components/form/select.jsx +44 -0
- package/dist/components/form/slider.d.ts +7 -0
- package/dist/components/form/slider.d.ts.map +1 -0
- package/dist/components/form/slider.jsx +45 -0
- package/dist/components/form/switch.d.ts +9 -0
- package/dist/components/form/switch.d.ts.map +1 -0
- package/dist/components/form/switch.jsx +46 -0
- package/dist/components/form/task-list.d.ts +3 -0
- package/dist/components/form/task-list.d.ts.map +1 -0
- package/dist/components/form/task-list.jsx +26 -0
- package/dist/components/form/textarea.d.ts +5 -0
- package/dist/components/form/textarea.d.ts.map +1 -0
- package/dist/components/form/textarea.jsx +26 -0
- package/dist/components/index.d.ts +45 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +44 -0
- package/dist/components/page-calendar/calendar-header.d.ts +16 -0
- package/dist/components/page-calendar/calendar-header.d.ts.map +1 -0
- package/dist/components/page-calendar/calendar-header.jsx +83 -0
- package/dist/components/page-calendar/day-view.d.ts +12 -0
- package/dist/components/page-calendar/day-view.d.ts.map +1 -0
- package/dist/components/page-calendar/day-view.jsx +89 -0
- package/dist/components/page-calendar/event-pill.d.ts +9 -0
- package/dist/components/page-calendar/event-pill.d.ts.map +1 -0
- package/dist/components/page-calendar/event-pill.jsx +25 -0
- package/dist/components/page-calendar/index.d.ts +4 -0
- package/dist/components/page-calendar/index.d.ts.map +1 -0
- package/dist/components/page-calendar/index.js +2 -0
- package/dist/components/page-calendar/month-view.d.ts +11 -0
- package/dist/components/page-calendar/month-view.d.ts.map +1 -0
- package/dist/components/page-calendar/month-view.jsx +46 -0
- package/dist/components/page-calendar/page-calendar.d.ts +18 -0
- package/dist/components/page-calendar/page-calendar.d.ts.map +1 -0
- package/dist/components/page-calendar/page-calendar.jsx +41 -0
- package/dist/components/page-calendar/page-calendar.types.d.ts +18 -0
- package/dist/components/page-calendar/page-calendar.types.d.ts.map +1 -0
- package/dist/components/page-calendar/page-calendar.types.js +1 -0
- package/dist/components/page-calendar/page-calendar.utils.d.ts +24 -0
- package/dist/components/page-calendar/page-calendar.utils.d.ts.map +1 -0
- package/dist/components/page-calendar/page-calendar.utils.js +93 -0
- package/dist/components/page-calendar/week-view.d.ts +11 -0
- package/dist/components/page-calendar/week-view.d.ts.map +1 -0
- package/dist/components/page-calendar/week-view.jsx +66 -0
- package/dist/components/table/filter.d.ts +42 -0
- package/dist/components/table/filter.d.ts.map +1 -0
- package/dist/components/table/filter.jsx +169 -0
- package/dist/components/table/group.d.ts +17 -0
- package/dist/components/table/group.d.ts.map +1 -0
- package/dist/components/table/group.jsx +75 -0
- package/dist/components/table/index.d.ts +19 -0
- package/dist/components/table/index.d.ts.map +1 -0
- package/dist/components/table/index.jsx +63 -0
- package/dist/components/table/inner-table.d.ts +29 -0
- package/dist/components/table/inner-table.d.ts.map +1 -0
- package/dist/components/table/inner-table.jsx +102 -0
- package/dist/components/table/metadata.d.ts +4 -0
- package/dist/components/table/metadata.d.ts.map +1 -0
- package/dist/components/table/metadata.jsx +36 -0
- package/dist/components/table/pagination.d.ts +5 -0
- package/dist/components/table/pagination.d.ts.map +1 -0
- package/dist/components/table/pagination.jsx +74 -0
- package/dist/components/table/row.d.ts +11 -0
- package/dist/components/table/row.d.ts.map +1 -0
- package/dist/components/table/row.jsx +49 -0
- package/dist/components/table/sort.d.ts +28 -0
- package/dist/components/table/sort.d.ts.map +1 -0
- package/dist/components/table/sort.jsx +109 -0
- package/dist/components/table/table-lib.d.ts +135 -0
- package/dist/components/table/table-lib.d.ts.map +1 -0
- package/dist/components/table/table-lib.js +83 -0
- package/dist/components/table/table.context.d.ts +10 -0
- package/dist/components/table/table.context.d.ts.map +1 -0
- package/dist/components/table/table.context.jsx +5 -0
- package/dist/components/table/thead.d.ts +9 -0
- package/dist/components/table/thead.d.ts.map +1 -0
- package/dist/components/table/thead.jsx +103 -0
- package/dist/config/context.d.ts +21 -0
- package/dist/config/context.d.ts.map +1 -0
- package/dist/config/context.js +12 -0
- package/dist/config/default-translations.d.ts +94 -0
- package/dist/config/default-translations.d.ts.map +1 -0
- package/dist/config/default-translations.jsx +87 -0
- package/dist/config/default-tweaks.d.ts +13 -0
- package/dist/config/default-tweaks.d.ts.map +1 -0
- package/dist/config/default-tweaks.js +4 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +2 -0
- package/dist/hooks/use-click-outside.d.ts +3 -0
- package/dist/hooks/use-click-outside.d.ts.map +1 -0
- package/dist/hooks/use-click-outside.js +17 -0
- package/dist/hooks/use-color-parser.d.ts +2 -0
- package/dist/hooks/use-color-parser.d.ts.map +1 -0
- package/dist/hooks/use-color-parser.js +9 -0
- package/dist/hooks/use-components-provider.d.ts +15 -0
- package/dist/hooks/use-components-provider.d.ts.map +1 -0
- package/dist/hooks/use-components-provider.jsx +22 -0
- package/dist/hooks/use-debounce.d.ts +5 -0
- package/dist/hooks/use-debounce.d.ts.map +1 -0
- package/dist/hooks/use-debounce.js +12 -0
- package/dist/hooks/use-floating-ref.d.ts +2 -0
- package/dist/hooks/use-floating-ref.d.ts.map +1 -0
- package/dist/hooks/use-floating-ref.js +6 -0
- package/dist/hooks/use-form.d.ts +394 -0
- package/dist/hooks/use-form.d.ts.map +1 -0
- package/dist/hooks/use-form.js +563 -0
- package/dist/hooks/use-hover.d.ts +3 -0
- package/dist/hooks/use-hover.d.ts.map +1 -0
- package/dist/hooks/use-hover.js +18 -0
- package/dist/hooks/use-input-id.d.ts +4 -0
- package/dist/hooks/use-input-id.d.ts.map +1 -0
- package/dist/hooks/use-input-id.js +5 -0
- package/dist/hooks/use-is-coarse-device.d.ts +2 -0
- package/dist/hooks/use-is-coarse-device.d.ts.map +1 -0
- package/dist/hooks/use-is-coarse-device.js +12 -0
- package/dist/hooks/use-locale.d.ts +3 -0
- package/dist/hooks/use-locale.d.ts.map +1 -0
- package/dist/hooks/use-locale.js +10 -0
- package/dist/hooks/use-media-query.d.ts +2 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +25 -0
- package/dist/hooks/use-on-event.d.ts +4 -0
- package/dist/hooks/use-on-event.d.ts.map +1 -0
- package/dist/hooks/use-on-event.js +10 -0
- package/dist/hooks/use-parent.d.ts +3 -0
- package/dist/hooks/use-parent.d.ts.map +1 -0
- package/dist/hooks/use-parent.js +21 -0
- package/dist/hooks/use-preferences.d.ts +2 -0
- package/dist/hooks/use-preferences.d.ts.map +1 -0
- package/dist/hooks/use-preferences.js +23 -0
- package/dist/hooks/use-previous.d.ts +2 -0
- package/dist/hooks/use-previous.d.ts.map +1 -0
- package/dist/hooks/use-previous.js +9 -0
- package/dist/hooks/use-reactive.d.ts +2 -0
- package/dist/hooks/use-reactive.d.ts.map +1 -0
- package/dist/hooks/use-reactive.js +9 -0
- package/dist/hooks/use-remove-scroll.d.ts +4 -0
- package/dist/hooks/use-remove-scroll.d.ts.map +1 -0
- package/dist/hooks/use-remove-scroll.js +48 -0
- package/dist/hooks/use-resize-observer.d.ts +2 -0
- package/dist/hooks/use-resize-observer.d.ts.map +1 -0
- package/dist/hooks/use-resize-observer.js +17 -0
- package/dist/hooks/use-stable-ref.d.ts +2 -0
- package/dist/hooks/use-stable-ref.d.ts.map +1 -0
- package/dist/hooks/use-stable-ref.js +9 -0
- package/dist/hooks/use-swipe.d.ts +8 -0
- package/dist/hooks/use-swipe.d.ts.map +1 -0
- package/dist/hooks/use-swipe.js +17 -0
- package/dist/hooks/use-translations.d.ts +92 -0
- package/dist/hooks/use-translations.d.ts.map +1 -0
- package/dist/hooks/use-translations.js +9 -0
- package/dist/hooks/use-tweaks.d.ts +3 -0
- package/dist/hooks/use-tweaks.d.ts.map +1 -0
- package/dist/hooks/use-tweaks.js +9 -0
- package/dist/hooks/use-window-size.d.ts +5 -0
- package/dist/hooks/use-window-size.d.ts.map +1 -0
- package/dist/hooks/use-window-size.js +14 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -7932
- package/dist/lib/combi-keys.d.ts +15 -0
- package/dist/lib/combi-keys.d.ts.map +1 -0
- package/dist/lib/combi-keys.js +60 -0
- package/dist/lib/dict.d.ts +9 -0
- package/dist/lib/dict.d.ts.map +1 -0
- package/dist/lib/dict.js +28 -0
- package/dist/lib/dom.d.ts +20 -0
- package/dist/lib/dom.d.ts.map +1 -0
- package/dist/lib/dom.js +185 -0
- package/dist/lib/fns.d.ts +11 -0
- package/dist/lib/fns.d.ts.map +1 -0
- package/dist/lib/fns.js +46 -0
- package/dist/lib/fzf.d.ts +16 -0
- package/dist/lib/fzf.d.ts.map +1 -0
- package/dist/lib/fzf.js +115 -0
- package/dist/lib/keyboard-area.d.ts +16 -0
- package/dist/lib/keyboard-area.d.ts.map +1 -0
- package/dist/lib/keyboard-area.js +14 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React, { createContext, useContext, useEffect, useRef } from "react";
|
|
3
|
+
import { Is } from "sidekicker";
|
|
4
|
+
import { useReactive } from "../../hooks/use-reactive";
|
|
5
|
+
import { useStableRef } from "../../hooks/use-stable-ref";
|
|
6
|
+
import { css } from "../../lib/dom";
|
|
7
|
+
import { keyboardKeys } from "../../lib/keyboard-area";
|
|
8
|
+
import { Polymorph } from "../core/polymorph";
|
|
9
|
+
import { Card } from "./card";
|
|
10
|
+
const Context = createContext("");
|
|
11
|
+
const isElementDisabled = (element) => element.hasAttribute("disabled") || element.getAttribute("aria-disabled") === "true";
|
|
12
|
+
const getNElement = (elements, currentIndex, direction) => {
|
|
13
|
+
const step = direction === "forward" ? 1 : -1;
|
|
14
|
+
const startIndex = currentIndex + step;
|
|
15
|
+
for (let i = startIndex; i >= 0 && i < elements.length; i += step) {
|
|
16
|
+
const element = elements[i];
|
|
17
|
+
if (!isElementDisabled(element))
|
|
18
|
+
return element;
|
|
19
|
+
}
|
|
20
|
+
return direction === "backward" ? getNElement(elements, elements.length - 1, "backward") : getNElement(elements, -1, "forward");
|
|
21
|
+
};
|
|
22
|
+
const moveOn = (ul, direction) => {
|
|
23
|
+
const items = Array.from(ul.querySelectorAll("li"));
|
|
24
|
+
const find = items.findIndex((x) => x.dataset.active === "true");
|
|
25
|
+
if (find === -1)
|
|
26
|
+
return null;
|
|
27
|
+
const item = getNElement(items, find, direction);
|
|
28
|
+
if (item === null)
|
|
29
|
+
return null;
|
|
30
|
+
item.querySelector("button")?.focus({ preventScroll: false });
|
|
31
|
+
return item.getAttribute("data-id") || "";
|
|
32
|
+
};
|
|
33
|
+
const moveToEdge = (ul, edge) => {
|
|
34
|
+
const items = Array.from(ul.querySelectorAll("li"));
|
|
35
|
+
const ordered = edge === "first" ? items : [...items].reverse();
|
|
36
|
+
for (const item of ordered) {
|
|
37
|
+
if (!isElementDisabled(item)) {
|
|
38
|
+
item.querySelector("button")?.focus({ preventScroll: false });
|
|
39
|
+
return item.getAttribute("data-id") || "";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
const actionKeys = {
|
|
45
|
+
[keyboardKeys.ArrowLeft]: (_, ul) => moveOn(ul, "backward"),
|
|
46
|
+
[keyboardKeys.ArrowRight]: (_, ul) => moveOn(ul, "forward"),
|
|
47
|
+
};
|
|
48
|
+
export const Tabs = (props) => {
|
|
49
|
+
const [active, setActive] = useReactive(props.active);
|
|
50
|
+
const ref = useRef(null);
|
|
51
|
+
const onChangeRef = useStableRef(props.onChange);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const header = ref.current;
|
|
54
|
+
if (header === null)
|
|
55
|
+
return;
|
|
56
|
+
let first = header.querySelector(`li[data-active=true]`);
|
|
57
|
+
if (first === null) {
|
|
58
|
+
first = header.querySelector(`li[data-id]`);
|
|
59
|
+
const id = first.getAttribute("data-id") || "";
|
|
60
|
+
setActive(id);
|
|
61
|
+
}
|
|
62
|
+
}, [props.active, setActive]);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (onChangeRef.current)
|
|
65
|
+
onChangeRef.current(active);
|
|
66
|
+
}, [onChangeRef, active]);
|
|
67
|
+
const items = React.Children.toArray(props.children);
|
|
68
|
+
const onClick = (e) => {
|
|
69
|
+
const anchor = e.currentTarget;
|
|
70
|
+
setActive(anchor.dataset.id || "");
|
|
71
|
+
};
|
|
72
|
+
const onKeyDown = (e) => {
|
|
73
|
+
if (ref.current === null)
|
|
74
|
+
return;
|
|
75
|
+
const k = e.key;
|
|
76
|
+
if (Is.keyof(actionKeys, k)) {
|
|
77
|
+
const fn = actionKeys[k];
|
|
78
|
+
const result = fn(e, ref.current);
|
|
79
|
+
if (result === null)
|
|
80
|
+
return;
|
|
81
|
+
setActive(result);
|
|
82
|
+
}
|
|
83
|
+
else if (k === "Home") {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
const result = moveToEdge(ref.current, "first");
|
|
86
|
+
if (result)
|
|
87
|
+
setActive(result);
|
|
88
|
+
}
|
|
89
|
+
else if (k === "End") {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
const result = moveToEdge(ref.current, "last");
|
|
92
|
+
if (result)
|
|
93
|
+
setActive(result);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return (<Context.Provider value={active}>
|
|
97
|
+
<Card className={props.className} container={css("pt-0 max-w-full w-full min-w-0", props.container)} header={<header className="relative mb-tabs-header-mb overflow-x-auto">
|
|
98
|
+
<div className="absolute bottom-0 h-tabs-divider-h w-full bg-card-border"/>
|
|
99
|
+
<nav className="min-w-0">
|
|
100
|
+
<ul role="tablist" onKeyDown={onKeyDown} ref={ref} className="flex w-0 min-w-full flex-1 justify-start overflow-x-auto">
|
|
101
|
+
{items.map((x) => {
|
|
102
|
+
const inner = x.props;
|
|
103
|
+
const current = active === inner.id;
|
|
104
|
+
return (<li data-id={inner.id} data-active={current} key={`tab-header-${inner.id}`} className={css("relative w-fit border-b border-transparent transition-all", current ? "border-primary font-medium text-primary" : "", inner.disabled ? "aria-disabled:text-disabled" : "")}>
|
|
105
|
+
<Polymorph role="tab" as="button" type="button" data-id={inner.id} id={`${inner.id}-tab`} aria-selected={current} disabled={inner.disabled} tabIndex={current ? 0 : -1} aria-controls={`${inner.id}-panel`} onClick={inner.disabled ? undefined : onClick} className="block w-full whitespace-nowrap px-tabs-item-px py-tabs-item-py disabled:cursor-not-allowed">
|
|
106
|
+
{inner.title}
|
|
107
|
+
</Polymorph>
|
|
108
|
+
</li>);
|
|
109
|
+
})}
|
|
110
|
+
</ul>
|
|
111
|
+
</nav>
|
|
112
|
+
</header>}>
|
|
113
|
+
{props.children}
|
|
114
|
+
</Card>
|
|
115
|
+
</Context.Provider>);
|
|
116
|
+
};
|
|
117
|
+
const useTabs = () => useContext(Context);
|
|
118
|
+
export const Tab = (props) => {
|
|
119
|
+
const active = useTabs();
|
|
120
|
+
if (props.id !== active)
|
|
121
|
+
return null;
|
|
122
|
+
return (<div role="tabpanel" tabIndex={0} id={`${props.id}-panel`} aria-labelledby={`${props.id}-tab`}>
|
|
123
|
+
{props.children}
|
|
124
|
+
</div>);
|
|
125
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { ComponentProps, ElementType, PropsWithChildren } from "react";
|
|
2
|
+
import { PolymorphicProps } from "../core/polymorph";
|
|
3
|
+
export declare const TimelineItem: {
|
|
4
|
+
(props: PropsWithChildren): React.JSX.Element;
|
|
5
|
+
Icon(props: PropsWithChildren<ComponentProps<"header">>): React.JSX.Element;
|
|
6
|
+
Body<T extends ElementType = "section">(props: PropsWithChildren<PolymorphicProps<object, T>>): React.JSX.Element;
|
|
7
|
+
Right<T extends ElementType = "button">(props: PolymorphicProps<object, T>): React.JSX.Element;
|
|
8
|
+
};
|
|
9
|
+
export declare const Timeline: (props: PropsWithChildren) => React.JSX.Element;
|
|
10
|
+
//# sourceMappingURL=timeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../../src/components/display/timeline.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE9E,OAAO,EAAa,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,eAAO,MAAM,YAAY;YAAW,iBAAiB;gBAUJ,iBAAiB,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;SAc9C,CAAC,SAAS,WAAW,qBAAqB,iBAAiB,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;UAQtF,CAAC,SAAS,WAAW,oBAAoB,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC;CAxBnH,CAAC;AAgCF,eAAO,MAAM,QAAQ,GAAI,OAAO,iBAAiB,sBAIhD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { css } from "../../lib/dom";
|
|
3
|
+
import { Polymorph } from "../core/polymorph";
|
|
4
|
+
export const TimelineItem = (props) => (<li data-component="timeline-item" className="relative pb-timeline-item-pb" role="listitem">
|
|
5
|
+
<span aria-hidden="true" className="absolute left-timeline-connector-left top-timeline-connector-top -ml-px h-full w-timeline-connector-w bg-card-border"/>
|
|
6
|
+
<div className="relative flex items-stretch justify-start space-x-3">{props.children}</div>
|
|
7
|
+
</li>);
|
|
8
|
+
TimelineItem.Icon = function TimelineIcon(props) {
|
|
9
|
+
return (<header {...props} className={css("flex size-timeline-icon-size items-center justify-center rounded-full bg-primary p-timeline-icon-p text-warn-foreground", props.className)}>
|
|
10
|
+
{props.children}
|
|
11
|
+
</header>);
|
|
12
|
+
};
|
|
13
|
+
TimelineItem.Body = function TimelineItemBody(props) {
|
|
14
|
+
return (<Polymorph {...props} className={css("min-w-0 flex-1", props.className)}>
|
|
15
|
+
{props.children}
|
|
16
|
+
</Polymorph>);
|
|
17
|
+
};
|
|
18
|
+
TimelineItem.Right = function TimelineItemRight(props) {
|
|
19
|
+
return (<footer className="flex gap-timeline-right-gap self-stretch px-timeline-right-px align-baseline">
|
|
20
|
+
<Polymorph {...props} type="button"/>
|
|
21
|
+
</footer>);
|
|
22
|
+
};
|
|
23
|
+
export const Timeline = (props) => (<ul data-component="timeline" role="list" className="flow-root [&>li:last-child>span[aria-hidden=true]]:hidden">
|
|
24
|
+
{props.children}
|
|
25
|
+
</ul>);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Icon, type IconProps } from "@phosphor-icons/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Label } from "../../types";
|
|
4
|
+
type ViewProps = {
|
|
5
|
+
text: string;
|
|
6
|
+
};
|
|
7
|
+
type CommandItem<T extends string, P extends object> = P & {
|
|
8
|
+
type: T;
|
|
9
|
+
hint?: string | string[];
|
|
10
|
+
Icon?: React.ReactElement;
|
|
11
|
+
enabled?: ((props: ViewProps) => boolean) | boolean;
|
|
12
|
+
};
|
|
13
|
+
type View = string | ((props: ViewProps) => string);
|
|
14
|
+
type CommandShortcutItem = CommandItem<"shortcut", {
|
|
15
|
+
title: View;
|
|
16
|
+
shortcut?: string;
|
|
17
|
+
action: (args: {
|
|
18
|
+
text: string;
|
|
19
|
+
setText: (state: string) => void;
|
|
20
|
+
setOpen: (state: boolean) => void;
|
|
21
|
+
event: KeyboardEvent | React.MouseEvent | React.KeyboardEvent;
|
|
22
|
+
}) => void | Promise<void>;
|
|
23
|
+
}>;
|
|
24
|
+
type CommandGroupItem = CommandItem<"group", {
|
|
25
|
+
title: View;
|
|
26
|
+
items: CommandItemTypes[];
|
|
27
|
+
}>;
|
|
28
|
+
export type CommandItemTypes = CommandGroupItem | CommandShortcutItem;
|
|
29
|
+
export type CommandPaletteProps = {
|
|
30
|
+
bind?: string;
|
|
31
|
+
open: boolean;
|
|
32
|
+
loading?: boolean;
|
|
33
|
+
emptyMessage?: Label;
|
|
34
|
+
footer?: React.ReactElement;
|
|
35
|
+
commands: CommandItemTypes[];
|
|
36
|
+
onChangeText?: (text: string) => void;
|
|
37
|
+
onChangeVisibility: (next: boolean) => void;
|
|
38
|
+
Preview?: React.FC<{
|
|
39
|
+
command: CommandItemTypes;
|
|
40
|
+
text: string;
|
|
41
|
+
}>;
|
|
42
|
+
Icon?: React.FC<IconProps & {
|
|
43
|
+
text: string;
|
|
44
|
+
Default: Icon;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
export declare const CommandPalette: (props: CommandPaletteProps) => React.JSX.Element;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=command-palette.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-palette.d.ts","sourceRoot":"","sources":["../../../src/components/floating/command-palette.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAc,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,KAAmE,MAAM,OAAO,CAAC;AAQxF,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAKpC,KAAK,SAAS,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IACvD,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC,GAAG,OAAO,CAAC;CACvD,CAAC;AAEF,KAAK,IAAI,GAAG,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,SAAS,KAAK,MAAM,CAAC,CAAC;AAEpD,KAAK,mBAAmB,GAAG,WAAW,CAClC,UAAU,EACV;IACI,KAAK,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,IAAI,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;QACjC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;QAClC,KAAK,EAAE,aAAa,GAAG,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC;KACjE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CACJ,CAAC;AAEF,KAAK,gBAAgB,GAAG,WAAW,CAAC,OAAO,EAAE;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAAC,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAiDtE,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,MAAM,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAC5B,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,kBAAkB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5C,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,OAAO,EAAE,gBAAgB,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChE,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC;AAmCF,eAAO,MAAM,cAAc,GAAI,OAAO,mBAAmB,sBAiNxD,CAAC"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { autoUpdate, useFloating, useInteractions, useListNavigation, useRole } from "@floating-ui/react";
|
|
3
|
+
import { FunnelIcon } from "@phosphor-icons/react";
|
|
4
|
+
import React, { forwardRef, Fragment, useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { Is } from "sidekicker";
|
|
6
|
+
import { useStableRef } from "../../hooks/use-stable-ref";
|
|
7
|
+
import { useTranslations } from "../../hooks/use-translations";
|
|
8
|
+
import { CombiKeys } from "../../lib/combi-keys";
|
|
9
|
+
import { Dict } from "../../lib/dict";
|
|
10
|
+
import { css, isChildVisible, isReactFC } from "../../lib/dom";
|
|
11
|
+
import { fzf } from "../../lib/fzf";
|
|
12
|
+
import { Shortcut } from "../display/shortcut";
|
|
13
|
+
import { SkeletonCell } from "../display/skeleton";
|
|
14
|
+
import { Modal } from "./modal";
|
|
15
|
+
const Group = (props) => (<span className="text-typography-sm flex h-full items-center text-left font-medium text-secondary">
|
|
16
|
+
{isReactFC(props.item.title) ? <props.item.title text={props.text}/> : props.item.title}
|
|
17
|
+
</span>);
|
|
18
|
+
const Item = forwardRef((props, ref) => {
|
|
19
|
+
const id = useId();
|
|
20
|
+
const active = props.active;
|
|
21
|
+
const item = props.item;
|
|
22
|
+
if (item.type === "group")
|
|
23
|
+
return (<div id={id} className="h-command-row-h px-command-group-px pb-command-group-pb pt-command-group-pt">
|
|
24
|
+
<Group text={props.text} item={item}/>
|
|
25
|
+
</div>);
|
|
26
|
+
if (item.type !== "shortcut")
|
|
27
|
+
return <Fragment />;
|
|
28
|
+
return (<button {...props} id={id} ref={ref} role="option" type="button" aria-selected={active} data-component="command-palette-item" className={css("flex h-command-row-h items-center justify-between rounded-command-radius p-command-item-p hover:bg-floating-hover", active ? "bg-floating-hover" : "")}>
|
|
29
|
+
<span className="flex items-center gap-command-item-gap">
|
|
30
|
+
{item.Icon ? item.Icon : null}
|
|
31
|
+
<span>{isReactFC(item.title) ? <item.title text={props.text}/> : item.title}</span>
|
|
32
|
+
</span>
|
|
33
|
+
{item.shortcut ? <Shortcut value={item.shortcut}/> : null}
|
|
34
|
+
</button>);
|
|
35
|
+
});
|
|
36
|
+
const getFuzzyData = (commands, value) => {
|
|
37
|
+
if (value.length === 0)
|
|
38
|
+
return commands;
|
|
39
|
+
const rules = [
|
|
40
|
+
{ key: "title", value },
|
|
41
|
+
{ key: "shortcut", value },
|
|
42
|
+
{ key: "hint", value },
|
|
43
|
+
];
|
|
44
|
+
const normalize = commands.map((x) => ({
|
|
45
|
+
...x,
|
|
46
|
+
title: Is.function(x.title) ? x.title({ text: value }) : x.title,
|
|
47
|
+
}));
|
|
48
|
+
const target = normalize.reduce((acc, x) => {
|
|
49
|
+
const enabled = Is.function(x.enabled) ? x.enabled({ text: value }) : (x.enabled ?? true);
|
|
50
|
+
if (enabled)
|
|
51
|
+
acc.push({ ...x, enabled: enabled });
|
|
52
|
+
return acc;
|
|
53
|
+
}, []);
|
|
54
|
+
const filter = fzf(target, "title", rules);
|
|
55
|
+
const withEnabled = normalize.filter((x) => (Is.function(x.enabled) ? x.enabled({ text: value }) : false));
|
|
56
|
+
return Dict.unique(filter.concat(withEnabled), (x) => x.title);
|
|
57
|
+
};
|
|
58
|
+
const loadingSkeleton = [0, 0, 0, 0, 0];
|
|
59
|
+
const findFirstClickable = (items) => {
|
|
60
|
+
for (let index = 0; index < items.length; index++) {
|
|
61
|
+
const element = items[index];
|
|
62
|
+
if (element.type === "shortcut")
|
|
63
|
+
return element;
|
|
64
|
+
const recursive = findFirstClickable(element.items);
|
|
65
|
+
if (recursive)
|
|
66
|
+
return recursive;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
};
|
|
70
|
+
export const CommandPalette = (props) => {
|
|
71
|
+
const id = useId();
|
|
72
|
+
const scrollContainerRef = useRef(null);
|
|
73
|
+
const [text, setText] = useState("");
|
|
74
|
+
const listRef = useRef([]);
|
|
75
|
+
const translations = useTranslations();
|
|
76
|
+
const valueRef = useStableRef(text);
|
|
77
|
+
const [activeIndex, setActiveIndex] = useState(null);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
setActiveIndex(null);
|
|
80
|
+
}, [text]);
|
|
81
|
+
const bindKey = props.bind ?? "Mod + k";
|
|
82
|
+
const root = useFloating({
|
|
83
|
+
open: props.open,
|
|
84
|
+
strategy: "absolute",
|
|
85
|
+
whileElementsMounted: autoUpdate,
|
|
86
|
+
onOpenChange: props.onChangeVisibility,
|
|
87
|
+
});
|
|
88
|
+
const commands = props.commands.flatMap((x) => (x.type === "group" ? [x, ...x.items] : [x]));
|
|
89
|
+
const fuzzy = getFuzzyData(commands, text);
|
|
90
|
+
const displayItems = text === ""
|
|
91
|
+
? commands
|
|
92
|
+
: [
|
|
93
|
+
{
|
|
94
|
+
type: "group",
|
|
95
|
+
title: "Results",
|
|
96
|
+
items: [],
|
|
97
|
+
},
|
|
98
|
+
...fuzzy.filter((x) => x.type !== "group"),
|
|
99
|
+
];
|
|
100
|
+
const listNav = useListNavigation(root.context, {
|
|
101
|
+
listRef,
|
|
102
|
+
loop: true,
|
|
103
|
+
activeIndex,
|
|
104
|
+
virtual: true,
|
|
105
|
+
allowEscape: false,
|
|
106
|
+
focusItemOnOpen: true,
|
|
107
|
+
focusItemOnHover: true,
|
|
108
|
+
openOnArrowKeyDown: true,
|
|
109
|
+
scrollItemIntoView: false,
|
|
110
|
+
selectedIndex: activeIndex,
|
|
111
|
+
disabledIndices: (n) => {
|
|
112
|
+
const item = displayItems[n];
|
|
113
|
+
if (item)
|
|
114
|
+
return item.type === "group";
|
|
115
|
+
return false;
|
|
116
|
+
},
|
|
117
|
+
onNavigate: (n) => {
|
|
118
|
+
if (Is.number(n)) {
|
|
119
|
+
if (!isChildVisible(scrollContainerRef.current, listRef.current[n]))
|
|
120
|
+
listRef.current[n]?.scrollIntoView({
|
|
121
|
+
block: "start",
|
|
122
|
+
inline: "start",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
setActiveIndex((prev) => {
|
|
126
|
+
if (Is.number(n))
|
|
127
|
+
return n;
|
|
128
|
+
return props.open ? (prev ?? 0) : null;
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const listRole = useRole(root.context, { role: "listbox" });
|
|
133
|
+
const { getItemProps, getReferenceProps, getFloatingProps } = useInteractions([listNav, listRole]);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const combi = new CombiKeys();
|
|
136
|
+
combi.add(bindKey, () => props.onChangeVisibility?.(true));
|
|
137
|
+
commands.forEach((cmd) => {
|
|
138
|
+
if (cmd.type === "group")
|
|
139
|
+
return;
|
|
140
|
+
if (cmd.type === "shortcut" && cmd.shortcut !== undefined)
|
|
141
|
+
combi.add(cmd.shortcut, (event) => cmd.action({
|
|
142
|
+
event,
|
|
143
|
+
setText,
|
|
144
|
+
text: valueRef.current,
|
|
145
|
+
setOpen: props.onChangeVisibility,
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
return combi.register();
|
|
149
|
+
}, [bindKey, commands, props, valueRef]);
|
|
150
|
+
const Icon = props.Icon ?? FunnelIcon;
|
|
151
|
+
return (<Fragment>
|
|
152
|
+
<Modal {...getFloatingProps()} animated={false} closable={false} open={props.open} overlayClickClose ariaTitle="Command palette" bodyClassName="px-0 py-0 pt-0" data-component="command-palette" onChange={props.onChangeVisibility} className="container relative overflow-clip py-0 md:max-w-screen-sm lg:max-w-screen-md">
|
|
153
|
+
<header className="sticky top-0 isolate z-floating flex h-command-header-h w-full items-center overflow-clip border-b border-floating-border bg-floating-background">
|
|
154
|
+
<div className="flex size-command-icon-size items-center justify-center">
|
|
155
|
+
{props.Icon ? <Icon Default={FunnelIcon} text={text} size={16}/> : <FunnelIcon size={16}/>}
|
|
156
|
+
</div>
|
|
157
|
+
<input {...getReferenceProps({
|
|
158
|
+
ref: root.refs.setReference,
|
|
159
|
+
onKeyDown: (e) => {
|
|
160
|
+
const item = Is.number(activeIndex) ? displayItems[activeIndex] : null;
|
|
161
|
+
const key = e.key;
|
|
162
|
+
if (key === "Enter") {
|
|
163
|
+
if (item) {
|
|
164
|
+
if (item.type === "shortcut")
|
|
165
|
+
item.action({
|
|
166
|
+
event: e,
|
|
167
|
+
text: text,
|
|
168
|
+
setOpen: props.onChangeVisibility,
|
|
169
|
+
setText,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
const item = findFirstClickable(fuzzy);
|
|
174
|
+
if (item?.type === "shortcut")
|
|
175
|
+
item.action({
|
|
176
|
+
event: e,
|
|
177
|
+
text: text,
|
|
178
|
+
setOpen: props.onChangeVisibility,
|
|
179
|
+
setText,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
})} value={text} data-combikeysbypass="true" placeholder="Search for..." onChange={(e) => setText(e.target.value)} className="text-typography-lg h-command-header-h w-full items-center bg-transparent px-command-input-px py-command-input-py pb-command-input-py text-left outline-none"/>
|
|
185
|
+
</header>
|
|
186
|
+
{props.loading ? (<div data-component="command-palette-list" className="my-command-list-my flex max-h-command-list-max-h w-full origin-[top_center] flex-col gap-command-list-gap overflow-y-auto px-command-group-px">
|
|
187
|
+
<div className="h-command-row-h px-command-group-px pb-command-group-pb pt-command-group-pt">
|
|
188
|
+
{translations.commandPaletteLoading}
|
|
189
|
+
</div>
|
|
190
|
+
{loadingSkeleton.map((_, i) => (<div key={`${id}-${i}-skeleton-index`} className={css("flex h-command-row-h items-center justify-between rounded-command-radius p-command-item-p hover:bg-primary hover:text-primary-foreground")}>
|
|
191
|
+
{SkeletonCell}
|
|
192
|
+
</div>))}
|
|
193
|
+
</div>) : (<div className="flex min-w-full flex-row flex-nowrap" data-component="command-palette-container">
|
|
194
|
+
<div ref={scrollContainerRef} data-component="command-palette-list" className="my-command-list-my flex h-fit max-h-command-list-max-h w-full origin-[top_center] flex-col gap-command-list-gap overflow-y-auto px-command-list-px">
|
|
195
|
+
{displayItems.map((item, index) => (<Item {...getItemProps({
|
|
196
|
+
onMouseEnter: () => setActiveIndex(index),
|
|
197
|
+
ref(node) {
|
|
198
|
+
listRef.current[index] = node;
|
|
199
|
+
},
|
|
200
|
+
onClick(e) {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
props.onChangeVisibility(false);
|
|
203
|
+
if (item.type === "shortcut")
|
|
204
|
+
item.action({
|
|
205
|
+
event: e,
|
|
206
|
+
text: text,
|
|
207
|
+
setOpen: props.onChangeVisibility,
|
|
208
|
+
setText,
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
})} item={item} text={text} active={activeIndex === index} key={`${id}-${item.type}-${index}`}/>))}
|
|
212
|
+
{displayItems.length === 1 ? (<div className={css("flex items-center justify-between rounded-command-radius p-command-item-p text-secondary")}>
|
|
213
|
+
{translations.commandPaletteEmpty ?? props.emptyMessage}
|
|
214
|
+
</div>) : null}
|
|
215
|
+
</div>
|
|
216
|
+
{props.Preview && Is.number(activeIndex) ? <props.Preview command={displayItems[activeIndex]} text={text}/> : null}
|
|
217
|
+
</div>)}
|
|
218
|
+
{props.footer ? (<footer className="flex h-command-footer-h items-center rounded-b-command-radius border-t border-floating-border p-command-footer-p">
|
|
219
|
+
{props.footer}
|
|
220
|
+
</footer>) : null}
|
|
221
|
+
</Modal>
|
|
222
|
+
</Fragment>);
|
|
223
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from "react";
|
|
2
|
+
type DropdownProps = {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
arrow?: boolean;
|
|
5
|
+
hover?: boolean;
|
|
6
|
+
returnFocus?: boolean;
|
|
7
|
+
restoreFocus?: boolean;
|
|
8
|
+
buttonProps?: React.HTMLProps<"button">;
|
|
9
|
+
onChange?: (nextValue: boolean) => void;
|
|
10
|
+
trigger: React.ReactElement | React.ReactNode;
|
|
11
|
+
title?: React.ReactNode | React.ReactElement | string;
|
|
12
|
+
};
|
|
13
|
+
export declare const Dropdown: (props: PropsWithChildren<DropdownProps>) => React.JSX.Element;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=dropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdown.d.ts","sourceRoot":"","sources":["../../../src/components/floating/dropdown.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,EAAY,iBAAiB,EAA+C,MAAM,OAAO,CAAC;AAExG,KAAK,aAAa,GAAG;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,OAAO,EAAE,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC;IAC9C,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC;CACzD,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,OAAO,iBAAiB,CAAC,aAAa,CAAC,sBA4E/D,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { arrow, autoUpdate, flip, FloatingArrow, FloatingFocusManager, FloatingPortal, offset, shift, useClick, useDismiss, useFloating, useHover, useInteractions, useRole, } from "@floating-ui/react";
|
|
3
|
+
import React, { Fragment, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
4
|
+
export const Dropdown = (props) => {
|
|
5
|
+
const headingId = useId();
|
|
6
|
+
const [open, setOpen] = useState(props.open);
|
|
7
|
+
useEffect(() => setOpen(props.open), [props.open]);
|
|
8
|
+
const arrowRef = useRef(null);
|
|
9
|
+
const middleware = useMemo(() => [
|
|
10
|
+
offset(10),
|
|
11
|
+
flip({ fallbackAxisSideDirection: "end" }),
|
|
12
|
+
shift(),
|
|
13
|
+
arrow({
|
|
14
|
+
padding: 5,
|
|
15
|
+
element: arrowRef,
|
|
16
|
+
}),
|
|
17
|
+
], []);
|
|
18
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
19
|
+
open,
|
|
20
|
+
middleware,
|
|
21
|
+
transform: true,
|
|
22
|
+
whileElementsMounted: autoUpdate,
|
|
23
|
+
onOpenChange: (nextValue, event) => {
|
|
24
|
+
const element = event?.relatedTarget;
|
|
25
|
+
if (element) {
|
|
26
|
+
if (element.dataset.floating === "true" && !nextValue)
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
setOpen(nextValue);
|
|
30
|
+
props.onChange?.(nextValue);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const click = useClick(context);
|
|
34
|
+
const hover = useHover(context, { enabled: props.hover ?? false });
|
|
35
|
+
const dismiss = useDismiss(context);
|
|
36
|
+
const role = useRole(context, { role: "dialog" });
|
|
37
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([click, dismiss, role, hover]);
|
|
38
|
+
return (<Fragment>
|
|
39
|
+
<button ref={refs.setReference} {...getReferenceProps(props.buttonProps)} type="button">
|
|
40
|
+
{props.trigger}
|
|
41
|
+
</button>
|
|
42
|
+
{open && (<FloatingPortal preserveTabOrder id={`${headingId}-portal`}>
|
|
43
|
+
<FloatingFocusManager guards restoreFocus={true} returnFocus={true} visuallyHiddenDismiss context={context} modal={false}>
|
|
44
|
+
<div className="relative isolate z-floating rounded-dropdown-radius border border-floating-border bg-floating-background p-dropdown-p shadow-shadow-floating" ref={refs.setFloating} aria-labelledby={headingId} style={floatingStyles} {...getFloatingProps()}>
|
|
45
|
+
<FloatingArrow ref={arrowRef} context={context} strokeWidth={0.1} className="fill-floating-background stroke-floating-border"/>
|
|
46
|
+
<header className="mb-dropdown-header-mb">
|
|
47
|
+
<h3 id={headingId} className="text-left text-typography-2xl font-medium leading-snug tracking-wide">
|
|
48
|
+
{props.title}
|
|
49
|
+
</h3>
|
|
50
|
+
</header>
|
|
51
|
+
{props.children}
|
|
52
|
+
</div>
|
|
53
|
+
</FloatingFocusManager>
|
|
54
|
+
</FloatingPortal>)}
|
|
55
|
+
</Fragment>);
|
|
56
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { motion } from "motion/react";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
import { Label, Override } from "../../types";
|
|
4
|
+
import { ButtonProps } from "../core/button";
|
|
5
|
+
export type ExpandProps = Override<ButtonProps<typeof motion.button>, {
|
|
6
|
+
trigger: Label;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const Expand: (props: PropsWithChildren<ExpandProps>) => import("react").JSX.Element;
|
|
11
|
+
//# sourceMappingURL=expand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.d.ts","sourceRoot":"","sources":["../../../src/components/floating/expand.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAmB,MAAM,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAsC,MAAM,OAAO,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAU,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,WAAW,GAAG,QAAQ,CAC9B,WAAW,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,EACjC;IACI,OAAO,EAAE,KAAK,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB,CACJ,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,OAAO,iBAAiB,CAAC,WAAW,CAAC,gCAmD3D,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { FloatingFocusManager, FloatingPortal, useClick, useDismiss, useFloating, useInteractions, useRole } from "@floating-ui/react";
|
|
3
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
4
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { Button } from "../core/button";
|
|
6
|
+
export const Expand = (props) => {
|
|
7
|
+
const root = useRef(null);
|
|
8
|
+
const id = useId();
|
|
9
|
+
const wrapperId = `${id}:wrapper`;
|
|
10
|
+
const titleId = `${id}:title`;
|
|
11
|
+
const [open, setOpen] = useState(props.open ?? false);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setOpen(props.open ?? false);
|
|
14
|
+
}, [props.open]);
|
|
15
|
+
const { context, refs } = useFloating({
|
|
16
|
+
transform: true,
|
|
17
|
+
open: open !== null,
|
|
18
|
+
nodeId: id,
|
|
19
|
+
onOpenChange: setOpen,
|
|
20
|
+
strategy: "absolute",
|
|
21
|
+
});
|
|
22
|
+
const click = useClick(context, { enabled: !(props.disabled ?? false) });
|
|
23
|
+
const role = useRole(context, { role: "dialog" });
|
|
24
|
+
const dismiss = useDismiss(context, {
|
|
25
|
+
escapeKey: true,
|
|
26
|
+
referencePress: true,
|
|
27
|
+
outsidePress: true,
|
|
28
|
+
});
|
|
29
|
+
const { getFloatingProps, getReferenceProps } = useInteractions([click, role, dismiss]);
|
|
30
|
+
return (<div className="relative inline-flex items-center justify-center" ref={root}>
|
|
31
|
+
<Button {...getReferenceProps(props)} as={motion.button} layoutId={wrapperId} ref={refs.setReference} size="small" onClick={() => setOpen(true)}>
|
|
32
|
+
<motion.span layoutId={titleId}>{props.trigger}</motion.span>
|
|
33
|
+
</Button>
|
|
34
|
+
<AnimatePresence>
|
|
35
|
+
{open ? (<FloatingPortal root={root}>
|
|
36
|
+
<FloatingFocusManager visuallyHiddenDismiss modal closeOnFocusOut context={context}>
|
|
37
|
+
<motion.div {...getFloatingProps()} ref={refs.setFloating} layoutId={wrapperId} className="absolute -left-1/4 -top-3/4">
|
|
38
|
+
{props.children}
|
|
39
|
+
</motion.div>
|
|
40
|
+
</FloatingFocusManager>
|
|
41
|
+
</FloatingPortal>) : null}
|
|
42
|
+
</AnimatePresence>
|
|
43
|
+
</div>);
|
|
44
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Icon } from "@phosphor-icons/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export type MenuProps = Partial<{
|
|
4
|
+
hover: boolean;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
nested: boolean;
|
|
7
|
+
asChild: boolean;
|
|
8
|
+
isParent: boolean;
|
|
9
|
+
restoreFocus: boolean;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
floatingClassName: string;
|
|
12
|
+
FloatingComponent: React.ElementType;
|
|
13
|
+
} & ({
|
|
14
|
+
label: string;
|
|
15
|
+
} | {
|
|
16
|
+
label: React.ReactElement;
|
|
17
|
+
title: string;
|
|
18
|
+
})>;
|
|
19
|
+
type MenuItemProps = {
|
|
20
|
+
title: string;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
Right?: Icon;
|
|
23
|
+
};
|
|
24
|
+
export declare const MenuItem: React.ForwardRefExoticComponent<Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof MenuItemProps> & MenuItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
25
|
+
export declare const Menu: React.ForwardRefExoticComponent<(Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "label" | "children" | "hover" | "open" | "asChild" | "restoreFocus" | "nested" | "isParent" | "floatingClassName" | "FloatingComponent"> & Partial<{
|
|
26
|
+
hover: boolean;
|
|
27
|
+
open?: boolean;
|
|
28
|
+
nested: boolean;
|
|
29
|
+
asChild: boolean;
|
|
30
|
+
isParent: boolean;
|
|
31
|
+
restoreFocus: boolean;
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
floatingClassName: string;
|
|
34
|
+
FloatingComponent: React.ElementType;
|
|
35
|
+
} & {
|
|
36
|
+
label: string;
|
|
37
|
+
}>, "ref"> | Omit<Omit<React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "label" | "children" | "hover" | "open" | "asChild" | "restoreFocus" | "nested" | "isParent" | "floatingClassName" | "FloatingComponent"> & Partial<{
|
|
38
|
+
hover: boolean;
|
|
39
|
+
open?: boolean;
|
|
40
|
+
nested: boolean;
|
|
41
|
+
asChild: boolean;
|
|
42
|
+
isParent: boolean;
|
|
43
|
+
restoreFocus: boolean;
|
|
44
|
+
children: React.ReactNode;
|
|
45
|
+
floatingClassName: string;
|
|
46
|
+
FloatingComponent: React.ElementType;
|
|
47
|
+
} & {
|
|
48
|
+
label: React.ReactElement;
|
|
49
|
+
title: string;
|
|
50
|
+
}>, "ref">) & React.RefAttributes<HTMLButtonElement>>;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/components/floating/menu.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAA2E,MAAM,OAAO,CAAC;AA6BhG,MAAM,MAAM,SAAS,GAAG,OAAO,CAC3B;IACI,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,KAAK,CAAC,WAAW,CAAC;CACxC,GAAG,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CACzE,CAAC;AA6LF,KAAK,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAEzE,eAAO,MAAM,QAAQ,oKAkCpB,CAAC;AAEF,eAAO,MAAM,IAAI;WA7OF,OAAO;WACP,OAAO;YACN,OAAO;aACN,OAAO;cACN,OAAO;kBACH,OAAO;cACX,KAAK,CAAC,SAAS;uBACN,MAAM;uBACN,KAAK,CAAC,WAAW;;WAC1B,MAAM;;WATT,OAAO;WACP,OAAO;YACN,OAAO;aACN,OAAO;cACN,OAAO;kBACH,OAAO;cACX,KAAK,CAAC,SAAS;uBACN,MAAM;uBACN,KAAK,CAAC,WAAW;;WACN,KAAK,CAAC,YAAY;WAAS,MAAM;qDA6OrE,CAAC"}
|