@terrafirmagreg-team/ui 0.0.0-stage → 0.1.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/package.json +93 -3
- package/src/components/blocks/button/icon-button.tsx +48 -0
- package/src/components/blocks/canvas/chevron-edge.tsx +134 -0
- package/src/components/blocks/canvas/flow-canvas.tsx +177 -0
- package/src/components/blocks/canvas/flow-toolbar.tsx +32 -0
- package/src/components/blocks/canvas/flow-viewport.tsx +243 -0
- package/src/components/blocks/git/github-info.tsx +77 -0
- package/src/components/blocks/lang/content.tsx +22 -0
- package/src/components/blocks/lang/flag.tsx +24 -0
- package/src/components/blocks/lang/link.tsx +22 -0
- package/src/components/blocks/lang/redirect.tsx +47 -0
- package/src/components/blocks/lang/switcher.tsx +53 -0
- package/src/components/blocks/lang/untranslated-callout.tsx +28 -0
- package/src/components/blocks/link/link-preview.tsx +256 -0
- package/src/components/blocks/list/row.tsx +91 -0
- package/src/components/blocks/media/glb/model.tsx +243 -0
- package/src/components/blocks/media/glb/scene.tsx +372 -0
- package/src/components/blocks/media/glb/viewer.tsx +51 -0
- package/src/components/blocks/media/image.tsx +135 -0
- package/src/components/blocks/media/slideshow.tsx +177 -0
- package/src/components/blocks/nav/breadcrumb.tsx +50 -0
- package/src/components/blocks/nav/link.tsx +85 -0
- package/src/components/blocks/nav/site-menu.tsx +77 -0
- package/src/components/blocks/nav/site-title.tsx +60 -0
- package/src/components/blocks/nav/switcher.tsx +205 -0
- package/src/components/blocks/page/empty-state.tsx +31 -0
- package/src/components/blocks/page/heading.tsx +53 -0
- package/src/components/blocks/page/pager.tsx +112 -0
- package/src/components/blocks/readability/menu.tsx +431 -0
- package/src/components/blocks/readability/track.tsx +164 -0
- package/src/components/blocks/search/command.tsx +79 -0
- package/src/components/blocks/search/dialog.tsx +712 -0
- package/src/components/blocks/search/provider.tsx +117 -0
- package/src/components/blocks/sidebar.tsx +406 -0
- package/src/components/blocks/theme/toggle.tsx +71 -0
- package/src/components/blocks/tooltip/hint.tsx +27 -0
- package/src/components/blocks/viewer/controls.tsx +279 -0
- package/src/components/blocks/viewer/float-bar.tsx +50 -0
- package/src/components/layouts/layout.tsx +93 -0
- package/src/components/layouts/left-sidebar/content.tsx +62 -0
- package/src/components/layouts/left-sidebar/context.tsx +54 -0
- package/src/components/layouts/left-sidebar/expand.tsx +22 -0
- package/src/components/layouts/left-sidebar/footer.tsx +105 -0
- package/src/components/layouts/left-sidebar/index.ts +28 -0
- package/src/components/layouts/left-sidebar/items.tsx +102 -0
- package/src/components/layouts/left-sidebar/search.tsx +74 -0
- package/src/components/layouts/left-sidebar/sidebar.tsx +188 -0
- package/src/components/layouts/left-sidebar/tree.tsx +156 -0
- package/src/components/layouts/right-sidebar.tsx +95 -0
- package/src/components/layouts/tree-context.tsx +41 -0
- package/src/components/mdx/accordion.tsx +184 -0
- package/src/components/mdx/banner.tsx +154 -0
- package/src/components/mdx/callout.tsx +96 -0
- package/src/components/mdx/card.tsx +49 -0
- package/src/components/mdx/codeblock.tsx +249 -0
- package/src/components/mdx/collapsible.tsx +32 -0
- package/src/components/mdx/files.tsx +62 -0
- package/src/components/mdx/glow-header.tsx +40 -0
- package/src/components/mdx/gradient-text.tsx +27 -0
- package/src/components/mdx/image-zoom.tsx +314 -0
- package/src/components/mdx/mermaid.tsx +16 -0
- package/src/components/mdx/multiblock.tsx +18 -0
- package/src/components/mdx/preview.tsx +100 -0
- package/src/components/mdx/steps.tsx +9 -0
- package/src/components/mdx/table.tsx +13 -0
- package/src/components/mdx/tabs.tsx +353 -0
- package/src/components/mdx/type-table.tsx +170 -0
- package/src/components/ui/accordion.tsx +71 -0
- package/src/components/ui/alert-dialog.tsx +187 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/attachment.tsx +207 -0
- package/src/components/ui/avatar.tsx +108 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +124 -0
- package/src/components/ui/bubble.tsx +127 -0
- package/src/components/ui/button-group.tsx +87 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/calendar.tsx +221 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +242 -0
- package/src/components/ui/chart.tsx +371 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/collapsible.tsx +21 -0
- package/src/components/ui/combobox.tsx +297 -0
- package/src/components/ui/command.tsx +198 -0
- package/src/components/ui/context-menu.tsx +270 -0
- package/src/components/ui/dialog.tsx +160 -0
- package/src/components/ui/direction.tsx +6 -0
- package/src/components/ui/drawer.tsx +227 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +103 -0
- package/src/components/ui/field.tsx +238 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +158 -0
- package/src/components/ui/input-otp.tsx +86 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +201 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/marker.tsx +70 -0
- package/src/components/ui/menubar.tsx +280 -0
- package/src/components/ui/message-scroller.tsx +131 -0
- package/src/components/ui/message.tsx +91 -0
- package/src/components/ui/native-select.tsx +60 -0
- package/src/components/ui/navigation-menu.tsx +167 -0
- package/src/components/ui/pagination.tsx +130 -0
- package/src/components/ui/popover.tsx +91 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/questionnaire.tsx +324 -0
- package/src/components/ui/radio-group.tsx +37 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +54 -0
- package/src/components/ui/select.tsx +200 -0
- package/src/components/ui/separator.tsx +24 -0
- package/src/components/ui/sheet.tsx +138 -0
- package/src/components/ui/sidebar.tsx +730 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/switch.tsx +31 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +81 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toast.tsx +234 -0
- package/src/components/ui/toggle-group.tsx +89 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +65 -0
- package/src/hooks/canvas/use-flow-hover.ts +18 -0
- package/src/hooks/canvas/use-flow-viewport-persist.ts +33 -0
- package/src/hooks/lang.ts +8 -0
- package/src/hooks/layout.ts +18 -0
- package/src/hooks/page/use-fit-pages.ts +91 -0
- package/src/hooks/page/use-location-search.ts +25 -0
- package/src/hooks/page/use-page-preview.ts +40 -0
- package/src/hooks/page/use-paged-list.ts +20 -0
- package/src/hooks/readability/provider.ts +86 -0
- package/src/hooks/search/dialog.ts +41 -0
- package/src/hooks/search/provider.ts +25 -0
- package/src/hooks/search/use-highlight-query.ts +51 -0
- package/src/hooks/sidebar.ts +63 -0
- package/src/hooks/use-async-value.ts +57 -0
- package/src/hooks/use-close-on-scroll.ts +23 -0
- package/src/hooks/use-copy-button.ts +46 -0
- package/src/hooks/use-cycle-index.ts +75 -0
- package/src/hooks/use-document-title.ts +9 -0
- package/src/hooks/use-element-size.ts +35 -0
- package/src/hooks/use-external-meta.ts +132 -0
- package/src/hooks/use-hot-key.ts +33 -0
- package/src/hooks/use-hover-follow.ts +54 -0
- package/src/hooks/use-in-view.ts +30 -0
- package/src/hooks/use-last-value.ts +15 -0
- package/src/hooks/use-marquee.ts +51 -0
- package/src/hooks/use-media-query.ts +14 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-modifier-keys.ts +31 -0
- package/src/hooks/use-on-change.ts +35 -0
- package/src/hooks/use-pane-keys.ts +28 -0
- package/src/hooks/use-swipe.ts +26 -0
- package/src/hooks/use-tree.ts +102 -0
- package/src/hooks/viewer/use-in-float-bar.ts +6 -0
- package/src/hooks/viewer/use-viewer-prefs.ts +77 -0
- package/src/lib/canvas/edge.ts +173 -0
- package/src/lib/canvas/geometry.ts +53 -0
- package/src/lib/canvas/state.ts +47 -0
- package/src/lib/canvas/viewport.ts +37 -0
- package/src/lib/canvas/xyflow.ts +1 -0
- package/src/lib/config.ts +81 -0
- package/src/lib/mdx/callout.ts +20 -0
- package/src/lib/mdx/gradient.ts +15 -0
- package/src/lib/mdx/mermaid.ts +14 -0
- package/src/lib/media/crop-opaque.ts +76 -0
- package/src/lib/media/nearby-indexes.ts +6 -0
- package/src/lib/media/trim-transparent.ts +117 -0
- package/src/lib/readability/config.ts +10 -0
- package/src/lib/readability/spotlight.ts +186 -0
- package/src/lib/readability/store.ts +146 -0
- package/src/lib/tree.ts +92 -0
- package/src/lib/utils/async-cache.ts +32 -0
- package/src/lib/utils/cn.ts +1 -0
- package/src/lib/utils/format.ts +22 -0
- package/src/lib/utils/history.ts +9 -0
- package/src/lib/utils/merge-refs.ts +13 -0
- package/src/lib/utils/nav-active.ts +58 -0
- package/src/lib/utils/stored-value.ts +136 -0
- package/src/lib/utils/urls.ts +17 -0
- package/src/locales/en_us.json +119 -0
- package/src/locales/pl_pl.json +35 -0
- package/src/locales/ru_ru.json +119 -0
- package/src/locales/uk_ua.json +35 -0
- package/src/locales/zh_cn.json +17 -0
- package/src/locales/zh_tw.json +17 -0
- package/src/locales.ts +5 -0
- package/src/provider.tsx +141 -0
- package/src/types/canvas.ts +49 -0
- package/src/types/glb.ts +25 -0
- package/src/types/nav.ts +95 -0
- package/src/types/preview.ts +9 -0
- package/src/types/readability.ts +28 -0
- package/src/types/search.ts +56 -0
- package/src/types/tree.ts +18 -0
- package/src/types/viewer.ts +53 -0
- package/styles/content/base.css +194 -0
- package/styles/content/default-colors.css +51 -0
- package/styles/content/shiki.css +108 -0
- package/styles/content/typography.mjs +3941 -0
- package/styles/content.css +7 -0
- package/styles/image-zoom.css +83 -0
- package/styles/layout.css +28 -0
- package/styles/left-sidebar.css +140 -0
- package/styles/readability.css +50 -0
- package/styles/right-sidebar.css +6 -0
- package/styles/workspace.css +26 -0
- package/styles.css +413 -0
- package/README.md +0 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
type ComponentType,
|
|
4
|
+
type ReactNode,
|
|
5
|
+
Suspense,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
useSyncExternalStore,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { useHotKey } from '@terrafirmagreg-team/ui/hooks/use-hot-key';
|
|
11
|
+
import {
|
|
12
|
+
dialogHandle,
|
|
13
|
+
SearchContext,
|
|
14
|
+
useSearchContext,
|
|
15
|
+
} from '@terrafirmagreg-team/ui/hooks/search/provider';
|
|
16
|
+
import type { SharedProps } from '@terrafirmagreg-team/ui/types/search';
|
|
17
|
+
export type { SharedProps } from '@terrafirmagreg-team/ui/types/search';
|
|
18
|
+
|
|
19
|
+
interface HotKey {
|
|
20
|
+
display: ReactNode;
|
|
21
|
+
|
|
22
|
+
key: string | ((e: KeyboardEvent) => boolean);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type SearchLink = [name: string, href: string];
|
|
26
|
+
|
|
27
|
+
export interface TagItem {
|
|
28
|
+
name: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SearchProviderProps<DialogProps extends SharedProps = SharedProps> {
|
|
33
|
+
|
|
34
|
+
links?: SearchLink[];
|
|
35
|
+
|
|
36
|
+
hotKey?: HotKey[];
|
|
37
|
+
|
|
38
|
+
SearchDialog: ComponentType<DialogProps>;
|
|
39
|
+
|
|
40
|
+
options?: Partial<DialogProps>;
|
|
41
|
+
|
|
42
|
+
children?: ReactNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const noop = () => () => {};
|
|
46
|
+
|
|
47
|
+
function MetaOrControl() {
|
|
48
|
+
|
|
49
|
+
const isClient = useSyncExternalStore(
|
|
50
|
+
noop,
|
|
51
|
+
() => true,
|
|
52
|
+
() => false,
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return isClient && /Windows|Linux/i.test(navigator.userAgent) ? 'Ctrl' : '⌘';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const DEFAULT_HOT_KEYS: HotKey[] = [
|
|
59
|
+
{
|
|
60
|
+
key: (e) => e.metaKey || e.ctrlKey,
|
|
61
|
+
display: <MetaOrControl />,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: 'k',
|
|
65
|
+
display: 'K',
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
export function SearchProvider<DialogProps extends SharedProps = SharedProps>({
|
|
70
|
+
SearchDialog,
|
|
71
|
+
children,
|
|
72
|
+
options,
|
|
73
|
+
hotKey = DEFAULT_HOT_KEYS,
|
|
74
|
+
links,
|
|
75
|
+
}: SearchProviderProps<DialogProps>) {
|
|
76
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
77
|
+
useHotKey((e) => {
|
|
78
|
+
if (hotKey.every((v) => (typeof v.key === 'string' ? e.key === v.key : v.key(e)))) {
|
|
79
|
+
setIsOpen((open) => !open);
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<SearchContext
|
|
86
|
+
value={useMemo(
|
|
87
|
+
() => ({
|
|
88
|
+
enabled: true,
|
|
89
|
+
open: isOpen,
|
|
90
|
+
hotKey,
|
|
91
|
+
dialogHandle,
|
|
92
|
+
setOpenSearch: setIsOpen,
|
|
93
|
+
}),
|
|
94
|
+
[isOpen, hotKey],
|
|
95
|
+
)}
|
|
96
|
+
>
|
|
97
|
+
<Suspense fallback={null}>
|
|
98
|
+
{/* @ts-expect-error -- assume all required props are filled */}
|
|
99
|
+
<SearchDialog
|
|
100
|
+
open={isOpen}
|
|
101
|
+
onOpenChange={setIsOpen}
|
|
102
|
+
links={links}
|
|
103
|
+
dialogHandle={dialogHandle}
|
|
104
|
+
{...options}
|
|
105
|
+
/>
|
|
106
|
+
</Suspense>
|
|
107
|
+
|
|
108
|
+
{children}
|
|
109
|
+
</SearchContext>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function SearchOnly({ children }: { children: ReactNode }) {
|
|
114
|
+
const search = useSearchContext();
|
|
115
|
+
|
|
116
|
+
if (search.enabled) return children;
|
|
117
|
+
}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { usePathname } from 'next/navigation';
|
|
3
|
+
import {
|
|
4
|
+
use,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type ComponentProps,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
type RefObject,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import ReactDOM from 'react-dom';
|
|
13
|
+
import { ScrollArea } from '@base-ui/react/scroll-area';
|
|
14
|
+
import { ChevronDown, ExternalLink } from 'lucide-react';
|
|
15
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
16
|
+
import { useHotKey } from '@terrafirmagreg-team/ui/hooks/use-hot-key';
|
|
17
|
+
import { useMediaQuery } from '@terrafirmagreg-team/ui/hooks/use-media-query';
|
|
18
|
+
import { useOnChange } from '@terrafirmagreg-team/ui/hooks/use-on-change';
|
|
19
|
+
import {
|
|
20
|
+
FolderContext,
|
|
21
|
+
SidebarContext,
|
|
22
|
+
useAutoScroll,
|
|
23
|
+
useFolderDepth,
|
|
24
|
+
useSidebar,
|
|
25
|
+
} from '@terrafirmagreg-team/ui/hooks/sidebar';
|
|
26
|
+
import { Link } from '@terrafirmagreg-team/ui/components/blocks/nav/link';
|
|
27
|
+
import {
|
|
28
|
+
Collapsible,
|
|
29
|
+
CollapsibleContent,
|
|
30
|
+
CollapsibleTrigger,
|
|
31
|
+
} from '@terrafirmagreg-team/ui/components/ui/collapsible';
|
|
32
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
33
|
+
|
|
34
|
+
export type { SidebarContextValue } from '@terrafirmagreg-team/ui/hooks/sidebar';
|
|
35
|
+
|
|
36
|
+
export function SidebarProvider({
|
|
37
|
+
defaultOpenLevel = 0,
|
|
38
|
+
prefetch,
|
|
39
|
+
collapsible = true,
|
|
40
|
+
children,
|
|
41
|
+
}: {
|
|
42
|
+
defaultOpenLevel?: number;
|
|
43
|
+
prefetch?: boolean;
|
|
44
|
+
collapsible?: boolean;
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
}) {
|
|
47
|
+
const closeOnRedirect = useRef(true);
|
|
48
|
+
const [open, setOpen] = useState(false);
|
|
49
|
+
const [collapsed, setCollapsed] = useState(false);
|
|
50
|
+
const pathname = usePathname();
|
|
51
|
+
const mode = useMediaQuery('(width < 768px)') ? 'drawer' : 'full';
|
|
52
|
+
|
|
53
|
+
useOnChange(pathname, () => {
|
|
54
|
+
if (closeOnRedirect.current) setOpen(false);
|
|
55
|
+
closeOnRedirect.current = true;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
useHotKey(
|
|
59
|
+
(e) => {
|
|
60
|
+
if (!(e.metaKey || e.ctrlKey) || e.shiftKey || e.altKey || e.key !== 'b')
|
|
61
|
+
return;
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
setCollapsed((prev) => !prev);
|
|
64
|
+
},
|
|
65
|
+
{ enabled: collapsible && mode === 'full', ignoreTyping: true },
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<SidebarContext
|
|
70
|
+
value={useMemo(
|
|
71
|
+
() => ({
|
|
72
|
+
open,
|
|
73
|
+
setOpen,
|
|
74
|
+
collapsed,
|
|
75
|
+
setCollapsed,
|
|
76
|
+
closeOnRedirect,
|
|
77
|
+
defaultOpenLevel,
|
|
78
|
+
prefetch,
|
|
79
|
+
mode,
|
|
80
|
+
}),
|
|
81
|
+
[open, collapsed, defaultOpenLevel, prefetch, mode],
|
|
82
|
+
)}
|
|
83
|
+
>
|
|
84
|
+
{children}
|
|
85
|
+
</SidebarContext>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function SidebarContent({
|
|
90
|
+
children,
|
|
91
|
+
}: {
|
|
92
|
+
children: (props: {
|
|
93
|
+
ref: RefObject<HTMLElement | null>;
|
|
94
|
+
collapsed: boolean;
|
|
95
|
+
hovered: boolean;
|
|
96
|
+
onPointerEnter: (e: React.PointerEvent<HTMLElement>) => void;
|
|
97
|
+
onPointerLeave: (e: React.PointerEvent<HTMLElement>) => void;
|
|
98
|
+
}) => ReactNode;
|
|
99
|
+
}) {
|
|
100
|
+
const { collapsed, mode } = useSidebar();
|
|
101
|
+
const [hover, setHover] = useState(false);
|
|
102
|
+
const ref = useRef<HTMLElement>(null);
|
|
103
|
+
const timerRef = useRef(0);
|
|
104
|
+
|
|
105
|
+
useOnChange(collapsed, () => {
|
|
106
|
+
if (collapsed) setHover(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (mode !== 'full') return null;
|
|
110
|
+
|
|
111
|
+
function shouldIgnoreHover(e: React.PointerEvent<HTMLElement>) {
|
|
112
|
+
const element = ref.current;
|
|
113
|
+
if (!element) return true;
|
|
114
|
+
return (
|
|
115
|
+
!collapsed || e.pointerType === 'touch' || element.getAnimations().length > 0
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// eslint-disable-next-line react-hooks/refs -- render-prop contract: the ref object is handed to the caller, never read here
|
|
120
|
+
return children({
|
|
121
|
+
ref,
|
|
122
|
+
collapsed,
|
|
123
|
+
hovered: hover,
|
|
124
|
+
onPointerEnter(e) {
|
|
125
|
+
if (shouldIgnoreHover(e)) return;
|
|
126
|
+
window.clearTimeout(timerRef.current);
|
|
127
|
+
setHover(true);
|
|
128
|
+
},
|
|
129
|
+
onPointerLeave(e) {
|
|
130
|
+
if (shouldIgnoreHover(e)) return;
|
|
131
|
+
window.clearTimeout(timerRef.current);
|
|
132
|
+
timerRef.current = window.setTimeout(
|
|
133
|
+
() => setHover(false),
|
|
134
|
+
Math.min(e.clientX, document.body.clientWidth - e.clientX) > 100
|
|
135
|
+
? 0
|
|
136
|
+
: 500,
|
|
137
|
+
);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function SidebarDrawerOverlay(props: ComponentProps<'div'>) {
|
|
143
|
+
const { open, setOpen, mode } = useSidebar();
|
|
144
|
+
const [hidden, setHidden] = useState(!open);
|
|
145
|
+
|
|
146
|
+
if (open && hidden) setHidden(false);
|
|
147
|
+
if (mode !== 'drawer' || hidden) return null;
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
data-state={open ? 'open' : 'closed'}
|
|
152
|
+
onClick={() => setOpen(false)}
|
|
153
|
+
onAnimationEnd={() => {
|
|
154
|
+
if (!open) ReactDOM.flushSync(() => setHidden(true));
|
|
155
|
+
}}
|
|
156
|
+
{...props}
|
|
157
|
+
/>
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function SidebarDrawerContent({
|
|
162
|
+
className,
|
|
163
|
+
children,
|
|
164
|
+
...props
|
|
165
|
+
}: ComponentProps<'aside'>) {
|
|
166
|
+
const { open, mode } = useSidebar();
|
|
167
|
+
const [hidden, setHidden] = useState(!open);
|
|
168
|
+
|
|
169
|
+
if (open && hidden) setHidden(false);
|
|
170
|
+
if (mode !== 'drawer') return null;
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<aside
|
|
174
|
+
id="sidebar-mobile"
|
|
175
|
+
data-state={open ? 'open' : 'closed'}
|
|
176
|
+
className={cn(hidden && 'invisible', className)}
|
|
177
|
+
onAnimationEnd={() => {
|
|
178
|
+
if (!open) ReactDOM.flushSync(() => setHidden(true));
|
|
179
|
+
}}
|
|
180
|
+
{...props}
|
|
181
|
+
>
|
|
182
|
+
{children}
|
|
183
|
+
</aside>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function SidebarViewport({
|
|
188
|
+
className,
|
|
189
|
+
...props
|
|
190
|
+
}: ComponentProps<typeof ScrollArea.Root>) {
|
|
191
|
+
return (
|
|
192
|
+
<ScrollArea.Root
|
|
193
|
+
className={(s) =>
|
|
194
|
+
cn('min-h-0 flex-1', typeof className === 'function' ? className(s) : className)
|
|
195
|
+
}
|
|
196
|
+
{...props}
|
|
197
|
+
>
|
|
198
|
+
<ScrollArea.Viewport className="size-full rounded-[inherit] p-4 overscroll-contain mask-[linear-gradient(to_bottom,transparent,white_12px,white_calc(100%-12px),transparent)]">
|
|
199
|
+
{props.children}
|
|
200
|
+
</ScrollArea.Viewport>
|
|
201
|
+
<ScrollArea.Corner />
|
|
202
|
+
<ScrollArea.Scrollbar
|
|
203
|
+
className={(s) =>
|
|
204
|
+
cn(
|
|
205
|
+
'flex h-full w-1.5 select-none transition-opacity',
|
|
206
|
+
!s.hovering && 'opacity-0',
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
>
|
|
210
|
+
<ScrollArea.Thumb className="relative flex-1 rounded-full bg-border" />
|
|
211
|
+
</ScrollArea.Scrollbar>
|
|
212
|
+
</ScrollArea.Root>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function SidebarSeparator(props: ComponentProps<'p'>) {
|
|
217
|
+
const depth = useFolderDepth();
|
|
218
|
+
return (
|
|
219
|
+
<p
|
|
220
|
+
{...props}
|
|
221
|
+
className={cn(
|
|
222
|
+
'inline-flex items-center gap-2 mb-1.5 px-2 mt-6 empty:mb-0',
|
|
223
|
+
depth === 0 && 'first:mt-0',
|
|
224
|
+
props.className,
|
|
225
|
+
)}
|
|
226
|
+
>
|
|
227
|
+
{props.children}
|
|
228
|
+
</p>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function SidebarItem({
|
|
233
|
+
icon,
|
|
234
|
+
active = false,
|
|
235
|
+
children,
|
|
236
|
+
...props
|
|
237
|
+
}: ComponentProps<typeof Link> & {
|
|
238
|
+
icon?: ReactNode;
|
|
239
|
+
active?: boolean;
|
|
240
|
+
}) {
|
|
241
|
+
const ref = useRef<HTMLAnchorElement>(null);
|
|
242
|
+
const { prefetch } = useSidebar();
|
|
243
|
+
useAutoScroll(active, ref);
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<Link ref={ref} data-active={active} prefetch={prefetch} {...props}>
|
|
247
|
+
{icon ?? (props.external ? <ExternalLink /> : null)}
|
|
248
|
+
{children}
|
|
249
|
+
</Link>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function SidebarFolder({
|
|
254
|
+
defaultOpen: defaultOpenProp,
|
|
255
|
+
collapsible = true,
|
|
256
|
+
active = false,
|
|
257
|
+
children,
|
|
258
|
+
...props
|
|
259
|
+
}: ComponentProps<'div'> & {
|
|
260
|
+
defaultOpen?: boolean;
|
|
261
|
+
collapsible?: boolean;
|
|
262
|
+
active?: boolean;
|
|
263
|
+
}) {
|
|
264
|
+
const { defaultOpenLevel } = useSidebar();
|
|
265
|
+
const depth = useFolderDepth() + 1;
|
|
266
|
+
const defaultOpen =
|
|
267
|
+
collapsible === false || active || (defaultOpenProp ?? defaultOpenLevel >= depth);
|
|
268
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
269
|
+
|
|
270
|
+
useOnChange(defaultOpen, (v) => {
|
|
271
|
+
if (v) setOpen(v);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<Collapsible open={open} onOpenChange={setOpen} disabled={!collapsible} {...props}>
|
|
276
|
+
<FolderContext
|
|
277
|
+
value={useMemo(
|
|
278
|
+
() => ({ open, setOpen, depth, collapsible }),
|
|
279
|
+
[collapsible, depth, open],
|
|
280
|
+
)}
|
|
281
|
+
>
|
|
282
|
+
{children}
|
|
283
|
+
</FolderContext>
|
|
284
|
+
</Collapsible>
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function SidebarFolderTrigger({
|
|
289
|
+
children,
|
|
290
|
+
...props
|
|
291
|
+
}: ComponentProps<'button'>) {
|
|
292
|
+
const folder = use(FolderContext);
|
|
293
|
+
if (folder?.collapsible)
|
|
294
|
+
return (
|
|
295
|
+
<CollapsibleTrigger {...props}>
|
|
296
|
+
{children}
|
|
297
|
+
<ChevronDown
|
|
298
|
+
data-icon
|
|
299
|
+
className={cn(
|
|
300
|
+
'ms-auto transition-transform',
|
|
301
|
+
!folder.open && '-rotate-90 rtl:rotate-90',
|
|
302
|
+
)}
|
|
303
|
+
/>
|
|
304
|
+
</CollapsibleTrigger>
|
|
305
|
+
);
|
|
306
|
+
return <div {...(props as ComponentProps<'div'>)}>{children}</div>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function SidebarFolderLink({
|
|
310
|
+
children,
|
|
311
|
+
active = false,
|
|
312
|
+
...props
|
|
313
|
+
}: ComponentProps<typeof Link> & { active?: boolean }) {
|
|
314
|
+
const ref = useRef<HTMLAnchorElement>(null);
|
|
315
|
+
const folder = use(FolderContext);
|
|
316
|
+
const { prefetch } = useSidebar();
|
|
317
|
+
useAutoScroll(active, ref);
|
|
318
|
+
|
|
319
|
+
return (
|
|
320
|
+
<Link
|
|
321
|
+
ref={ref}
|
|
322
|
+
data-active={active}
|
|
323
|
+
onClick={(e) => {
|
|
324
|
+
if (!folder?.collapsible) return;
|
|
325
|
+
if (
|
|
326
|
+
e.target instanceof Element &&
|
|
327
|
+
e.target.matches('[data-icon], [data-icon] *')
|
|
328
|
+
) {
|
|
329
|
+
folder.setOpen(!folder.open);
|
|
330
|
+
e.preventDefault();
|
|
331
|
+
} else folder.setOpen(active ? !folder.open : true);
|
|
332
|
+
}}
|
|
333
|
+
prefetch={prefetch}
|
|
334
|
+
{...props}
|
|
335
|
+
>
|
|
336
|
+
{children}
|
|
337
|
+
{folder?.collapsible && (
|
|
338
|
+
<ChevronDown
|
|
339
|
+
data-icon
|
|
340
|
+
className={cn(
|
|
341
|
+
'ms-auto transition-transform',
|
|
342
|
+
!folder.open && '-rotate-90 rtl:rotate-90',
|
|
343
|
+
)}
|
|
344
|
+
/>
|
|
345
|
+
)}
|
|
346
|
+
</Link>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function SidebarFolderContent(props: ComponentProps<'div'>) {
|
|
351
|
+
return <CollapsibleContent {...props}>{props.children}</CollapsibleContent>;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function SidebarTrigger({
|
|
355
|
+
children,
|
|
356
|
+
...props
|
|
357
|
+
}: ComponentProps<'button'>) {
|
|
358
|
+
const { open, setOpen } = useSidebar();
|
|
359
|
+
const t = useTranslations();
|
|
360
|
+
|
|
361
|
+
return (
|
|
362
|
+
<button
|
|
363
|
+
type="button"
|
|
364
|
+
aria-label={
|
|
365
|
+
open
|
|
366
|
+
? t('ui.sidebar_close', )
|
|
367
|
+
: t('ui.sidebar_open', )
|
|
368
|
+
}
|
|
369
|
+
aria-expanded={open}
|
|
370
|
+
aria-controls="sidebar-mobile"
|
|
371
|
+
onClick={() => setOpen(!open)}
|
|
372
|
+
{...props}
|
|
373
|
+
>
|
|
374
|
+
{children}
|
|
375
|
+
</button>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function SidebarCollapseTrigger(props: ComponentProps<'button'>) {
|
|
380
|
+
const { collapsed, setCollapsed } = useSidebar();
|
|
381
|
+
const t = useTranslations();
|
|
382
|
+
|
|
383
|
+
return (
|
|
384
|
+
<button
|
|
385
|
+
type="button"
|
|
386
|
+
aria-label={t('ui.sidebar_collapse', )}
|
|
387
|
+
aria-controls="sidebar"
|
|
388
|
+
aria-expanded={!collapsed}
|
|
389
|
+
data-collapsed={collapsed}
|
|
390
|
+
onClick={(e) => {
|
|
391
|
+
const button = e.currentTarget;
|
|
392
|
+
ReactDOM.flushSync(() => setCollapsed((prev) => !prev));
|
|
393
|
+
if (button.matches('[inert] *'))
|
|
394
|
+
document
|
|
395
|
+
.querySelector<HTMLElement>(
|
|
396
|
+
'[aria-controls="sidebar"]:not([inert] *)',
|
|
397
|
+
)
|
|
398
|
+
?.focus();
|
|
399
|
+
}}
|
|
400
|
+
{...props}
|
|
401
|
+
>
|
|
402
|
+
{props.children}
|
|
403
|
+
</button>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import { flushSync } from 'react-dom';
|
|
5
|
+
import { Airplay, Moon, Sun } from 'lucide-react';
|
|
6
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
7
|
+
import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
|
|
8
|
+
|
|
9
|
+
const noop = () => () => {};
|
|
10
|
+
|
|
11
|
+
const icons = { light: Sun, dark: Moon, system: Airplay } as const;
|
|
12
|
+
export type ThemeToggleMode = keyof typeof icons;
|
|
13
|
+
|
|
14
|
+
export function ThemeToggle({
|
|
15
|
+
value,
|
|
16
|
+
onValueChange,
|
|
17
|
+
modes = ['light', 'dark', 'system'],
|
|
18
|
+
labels,
|
|
19
|
+
className,
|
|
20
|
+
...props
|
|
21
|
+
}: ComponentProps<'div'> & {
|
|
22
|
+
value?: string;
|
|
23
|
+
onValueChange?: (mode: ThemeToggleMode) => void;
|
|
24
|
+
modes?: readonly ThemeToggleMode[];
|
|
25
|
+
labels?: Partial<Record<ThemeToggleMode, string>>;
|
|
26
|
+
}) {
|
|
27
|
+
const mounted = useSyncExternalStore(
|
|
28
|
+
noop,
|
|
29
|
+
() => true,
|
|
30
|
+
() => false,
|
|
31
|
+
);
|
|
32
|
+
const current = mounted ? value : undefined;
|
|
33
|
+
const select = (mode: ThemeToggleMode) => {
|
|
34
|
+
if (document?.startViewTransition) {
|
|
35
|
+
document.startViewTransition(() => flushSync(() => onValueChange?.(mode)));
|
|
36
|
+
} else {
|
|
37
|
+
onValueChange?.(mode);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return (
|
|
41
|
+
<div
|
|
42
|
+
data-theme-toggle
|
|
43
|
+
className={cn(
|
|
44
|
+
'inline-flex items-center rounded-full p-1 overflow-hidden *:rounded-full',
|
|
45
|
+
className,
|
|
46
|
+
)}
|
|
47
|
+
{...props}
|
|
48
|
+
>
|
|
49
|
+
{modes.map((mode) => {
|
|
50
|
+
const ModeIcon = icons[mode];
|
|
51
|
+
const active = current === mode;
|
|
52
|
+
return (
|
|
53
|
+
<Hint key={mode} label={labels?.[mode] ?? mode}>
|
|
54
|
+
<button
|
|
55
|
+
type="button"
|
|
56
|
+
aria-label={labels?.[mode] ?? mode}
|
|
57
|
+
aria-pressed={active}
|
|
58
|
+
className={cn(
|
|
59
|
+
'size-6.5 p-1.5 text-muted-foreground',
|
|
60
|
+
active && 'bg-accent text-accent-foreground',
|
|
61
|
+
)}
|
|
62
|
+
onClick={() => select(mode)}
|
|
63
|
+
>
|
|
64
|
+
<ModeIcon className="size-full" fill="currentColor" aria-hidden />
|
|
65
|
+
</button>
|
|
66
|
+
</Hint>
|
|
67
|
+
);
|
|
68
|
+
})}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import type { ComponentProps, ReactElement, ReactNode } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
Tooltip,
|
|
5
|
+
TooltipContent,
|
|
6
|
+
TooltipTrigger,
|
|
7
|
+
} from '@terrafirmagreg-team/ui/components/ui/tooltip';
|
|
8
|
+
|
|
9
|
+
export function Hint({
|
|
10
|
+
label,
|
|
11
|
+
children,
|
|
12
|
+
...props
|
|
13
|
+
}: {
|
|
14
|
+
label: ReactNode;
|
|
15
|
+
children: ReactElement;
|
|
16
|
+
} & Pick<
|
|
17
|
+
ComponentProps<typeof TooltipContent>,
|
|
18
|
+
'side' | 'align' | 'sideOffset'
|
|
19
|
+
>) {
|
|
20
|
+
if (label == null || label === '') return children;
|
|
21
|
+
return (
|
|
22
|
+
<Tooltip>
|
|
23
|
+
<TooltipTrigger render={children} />
|
|
24
|
+
<TooltipContent {...props}>{label}</TooltipContent>
|
|
25
|
+
</Tooltip>
|
|
26
|
+
);
|
|
27
|
+
}
|