@djangocfg/ui-core 2.1.635 → 2.1.637
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 +7 -7
- package/src/components/forms/button/index.tsx +16 -2
- package/src/components/index.ts +2 -1
- package/src/components/navigation/sidebar/sidebar.tsx +14 -23
- package/src/components/overlay/side-panel/index.tsx +28 -4
- package/src/components/overlay/tooltip/index.tsx +56 -6
- package/src/components/specialized/copy/index.tsx +3 -0
- package/src/hooks/media/index.ts +1 -0
- package/src/hooks/media/useCanHover.ts +14 -0
- package/src/styles/css/base.css +2 -1
- package/src/styles/css/presets/notion.css +8 -1
- package/src/styles/css/utilities/touch-safe.css +17 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/ui-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.637",
|
|
4
4
|
"description": "Pure React UI component library without Next.js dependencies - for Electron, Vite, CRA apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui-components",
|
|
@@ -139,8 +139,8 @@
|
|
|
139
139
|
"check:docs": "node scripts/check-docs.mjs"
|
|
140
140
|
},
|
|
141
141
|
"peerDependencies": {
|
|
142
|
-
"@djangocfg/api": "^2.1.
|
|
143
|
-
"@djangocfg/i18n": "^2.1.
|
|
142
|
+
"@djangocfg/api": "^2.1.637",
|
|
143
|
+
"@djangocfg/i18n": "^2.1.637",
|
|
144
144
|
"consola": "^3.4.2",
|
|
145
145
|
"lucide-react": "^1.68.0",
|
|
146
146
|
"moment": "^2.30.1",
|
|
@@ -215,10 +215,10 @@
|
|
|
215
215
|
"vaul": "1.1.2"
|
|
216
216
|
},
|
|
217
217
|
"devDependencies": {
|
|
218
|
-
"@djangocfg/api": "^2.1.
|
|
219
|
-
"@djangocfg/eslint-config": "^2.1.
|
|
220
|
-
"@djangocfg/i18n": "^2.1.
|
|
221
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
218
|
+
"@djangocfg/api": "^2.1.637",
|
|
219
|
+
"@djangocfg/eslint-config": "^2.1.637",
|
|
220
|
+
"@djangocfg/i18n": "^2.1.637",
|
|
221
|
+
"@djangocfg/typescript-config": "^2.1.637",
|
|
222
222
|
"@storybook/react-vite": "^10.6.5",
|
|
223
223
|
"@types/node": "^24.13.3",
|
|
224
224
|
"@types/react": "19.3.0",
|
|
@@ -8,6 +8,7 @@ import { Slot } from '@radix-ui/react-slot';
|
|
|
8
8
|
|
|
9
9
|
import { cn } from '../../../lib/utils';
|
|
10
10
|
import { Link } from '../../navigation/link';
|
|
11
|
+
import { TooltipHint, type TooltipProp } from '../../overlay/tooltip';
|
|
11
12
|
import { buttonSizeClass, CONTROL_SIZE } from '../control-size';
|
|
12
13
|
|
|
13
14
|
const buttonVariants = cva(
|
|
@@ -65,6 +66,11 @@ export interface ButtonProps
|
|
|
65
66
|
VariantProps<typeof buttonVariants> {
|
|
66
67
|
asChild?: boolean
|
|
67
68
|
loading?: boolean
|
|
69
|
+
/**
|
|
70
|
+
* The control's hover hint: a text, or `{ content, hotkey?, side?, delay?, hoverable? }` (`TooltipConfig`). Replaces the `Tooltip` / `TooltipTrigger` / `TooltipContent` wrapper.
|
|
71
|
+
* Drawn only where the device can hover (`useCanHover`), so a phone gets none; a disabled button is wrapped in a span so it can still be hovered.
|
|
72
|
+
*/
|
|
73
|
+
tooltip?: TooltipProp
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
// Filter out SVG icons from children when loading
|
|
@@ -83,7 +89,7 @@ function filterIcons(children: React.ReactNode): React.ReactNode {
|
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
86
|
-
({ className, variant, size, elevated, asChild = false, loading = false, onClick, children, disabled, ...props }, ref) => {
|
|
92
|
+
({ className, variant, size, elevated, asChild = false, loading = false, onClick, children, disabled, tooltip, ...props }, ref) => {
|
|
87
93
|
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
88
94
|
if (!loading) {
|
|
89
95
|
onClick?.(e);
|
|
@@ -94,6 +100,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
94
100
|
// Don't render loading spinner with asChild to avoid "Children.only" error
|
|
95
101
|
if (asChild) {
|
|
96
102
|
return (
|
|
103
|
+
<TooltipHint tooltip={tooltip}>
|
|
97
104
|
<Slot
|
|
98
105
|
className={cn(buttonVariants({ variant, size, elevated, className }))}
|
|
99
106
|
ref={ref}
|
|
@@ -102,10 +109,12 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
102
109
|
>
|
|
103
110
|
{children}
|
|
104
111
|
</Slot>
|
|
112
|
+
</TooltipHint>
|
|
105
113
|
)
|
|
106
114
|
}
|
|
107
115
|
|
|
108
116
|
return (
|
|
117
|
+
<TooltipHint tooltip={tooltip} disabled={disabled || loading}>
|
|
109
118
|
<button
|
|
110
119
|
className={cn(buttonVariants({ variant, size, elevated, className }))}
|
|
111
120
|
ref={ref}
|
|
@@ -116,6 +125,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
116
125
|
{loading && <Loader2 className="size-4 animate-spin" />}
|
|
117
126
|
{loading ? filterIcons(children) : children}
|
|
118
127
|
</button>
|
|
128
|
+
</TooltipHint>
|
|
119
129
|
)
|
|
120
130
|
}
|
|
121
131
|
)
|
|
@@ -150,11 +160,13 @@ export interface ButtonLinkProps
|
|
|
150
160
|
disabled?: boolean
|
|
151
161
|
/** Inert + dimmed + spinner (e.g. while an action resolves). */
|
|
152
162
|
loading?: boolean
|
|
163
|
+
/** The hover hint (see `ButtonProps.tooltip`). */
|
|
164
|
+
tooltip?: TooltipProp
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
|
|
156
168
|
(
|
|
157
|
-
{ className, variant, size, elevated, href, replace, scroll, prefetch, disabled = false, loading = false, onClick, children, ...props },
|
|
169
|
+
{ className, variant, size, elevated, href, replace, scroll, prefetch, disabled = false, loading = false, onClick, children, tooltip, ...props },
|
|
158
170
|
ref,
|
|
159
171
|
) => {
|
|
160
172
|
// `<a>` can't be natively disabled — emulate it (aria + tab-order + no
|
|
@@ -169,6 +181,7 @@ const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
|
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
return (
|
|
184
|
+
<TooltipHint tooltip={tooltip}>
|
|
172
185
|
<Link
|
|
173
186
|
href={href}
|
|
174
187
|
replace={replace}
|
|
@@ -187,6 +200,7 @@ const ButtonLink = React.forwardRef<HTMLAnchorElement, ButtonLinkProps>(
|
|
|
187
200
|
{loading && <Loader2 className="size-4 animate-spin" />}
|
|
188
201
|
{loading ? filterIcons(children) : children}
|
|
189
202
|
</Link>
|
|
203
|
+
</TooltipHint>
|
|
190
204
|
)
|
|
191
205
|
}
|
|
192
206
|
)
|
package/src/components/index.ts
CHANGED
|
@@ -105,7 +105,8 @@ export { ResponsiveSheet, ResponsiveSheetContent, ResponsiveSheetHeader, Respons
|
|
|
105
105
|
export { SidePanel, SidePanelContent, SidePanelHeader, SidePanelTitle, SidePanelDescription, SidePanelBody, SidePanelFooter, SidePanelClose } from './overlay/side-panel';
|
|
106
106
|
export type { SidePanelProps, SidePanelContentProps, SidePanelCloseProps } from './overlay/side-panel';
|
|
107
107
|
export { HoverCard, HoverCardContent, HoverCardTrigger } from './overlay/hover-card';
|
|
108
|
-
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './overlay/tooltip';
|
|
108
|
+
export { Tooltip, TooltipContent, TooltipHint, TooltipProvider, TooltipTrigger } from './overlay/tooltip';
|
|
109
|
+
export type { TooltipConfig, TooltipProp } from './overlay/tooltip';
|
|
109
110
|
|
|
110
111
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
111
112
|
// Navigation
|
|
@@ -6,7 +6,6 @@ import * as React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { cn } from '../../../lib';
|
|
8
8
|
import { useIsMobile } from '../../../hooks/media';
|
|
9
|
-
import { useShortcutModLabel } from '../../../hooks/device';
|
|
10
9
|
import { Slot } from '@radix-ui/react-slot';
|
|
11
10
|
|
|
12
11
|
import { Button } from '../../forms/button';
|
|
@@ -308,10 +307,8 @@ const SidebarTrigger = React.forwardRef<
|
|
|
308
307
|
React.ElementRef<typeof Button>,
|
|
309
308
|
React.ComponentProps<typeof Button>
|
|
310
309
|
>(({ className, onClick, ...props }, ref) => {
|
|
311
|
-
const { toggleSidebar, openMobile } = useSidebar()
|
|
312
|
-
const mod = useShortcutModLabel()
|
|
310
|
+
const { toggleSidebar, openMobile, open: isOpenDesktop } = useSidebar()
|
|
313
311
|
const isMobile = useIsMobile()
|
|
314
|
-
const desktopHint = `Toggle sidebar (${mod}+B)`
|
|
315
312
|
|
|
316
313
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
317
314
|
onClick?.(event)
|
|
@@ -338,25 +335,19 @@ const SidebarTrigger = React.forwardRef<
|
|
|
338
335
|
}
|
|
339
336
|
|
|
340
337
|
return (
|
|
341
|
-
<
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
</Button>
|
|
355
|
-
</TooltipTrigger>
|
|
356
|
-
<TooltipContent side="right" align="center" sideOffset={8} className="max-w-[16rem]">
|
|
357
|
-
{desktopHint}
|
|
358
|
-
</TooltipContent>
|
|
359
|
-
</Tooltip>
|
|
338
|
+
<Button
|
|
339
|
+
ref={ref}
|
|
340
|
+
data-sidebar="trigger"
|
|
341
|
+
variant="ghost"
|
|
342
|
+
size="icon"
|
|
343
|
+
className={buttonClass}
|
|
344
|
+
tooltip={{ content: openMobile || isOpenDesktop ? "Close sidebar" : "Open sidebar", hotkey: `mod+${SIDEBAR_KEYBOARD_SHORTCUT}`, side: "right", sideOffset: 8 }}
|
|
345
|
+
onClick={handleClick}
|
|
346
|
+
{...props}
|
|
347
|
+
>
|
|
348
|
+
<PanelLeft className="h-4 w-4" />
|
|
349
|
+
<span className="sr-only">Toggle sidebar</span>
|
|
350
|
+
</Button>
|
|
360
351
|
)
|
|
361
352
|
})
|
|
362
353
|
SidebarTrigger.displayName = "SidebarTrigger"
|
|
@@ -33,6 +33,17 @@ import { cn } from '../../../lib/utils';
|
|
|
33
33
|
|
|
34
34
|
// ─── Root ─────────────────────────────────────────────────────────────────────
|
|
35
35
|
|
|
36
|
+
// A menu, popover or listbox opened from inside the panel is portalled to <body>, so it is "outside" the panel in the DOM. While one is
|
|
37
|
+
// open, a press or Esc belongs to that layer (it closes itself); the panel must not also go. Without this, closing a "..." menu by
|
|
38
|
+
// clicking away or pressing Esc took the whole panel with it. A closing layer keeps `data-state="closed"` for its exit animation.
|
|
39
|
+
const NESTED_LAYER =
|
|
40
|
+
'[data-slot="popover-content"],[role="menu"],[role="listbox"],[data-radix-popper-content-wrapper]';
|
|
41
|
+
function nestedLayerOpen(): boolean {
|
|
42
|
+
return Array.from(document.querySelectorAll(NESTED_LAYER)).some(
|
|
43
|
+
(el) => el.getAttribute('data-state') !== 'closed' && !el.closest('[data-state="closed"]'),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
export interface SidePanelProps {
|
|
37
48
|
open: boolean;
|
|
38
49
|
onOpenChange: (open: boolean) => void;
|
|
@@ -56,6 +67,15 @@ export interface SidePanelProps {
|
|
|
56
67
|
* must not dismiss the thing they are reading from.
|
|
57
68
|
*/
|
|
58
69
|
closeOnOutsideClick?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Dim the page behind the panel. Default ``false`` (the page stays legible and live).
|
|
72
|
+
*
|
|
73
|
+
* For a panel that covers content the reader is not meant to work in while it is open (a chat that
|
|
74
|
+
* slides over the page because the window has no room for a column): the dimming says the page is
|
|
75
|
+
* behind it. It is a plain layer, not a modal: no focus trap, no scroll lock; a press on it closes
|
|
76
|
+
* the panel through ``closeOnOutsideClick``.
|
|
77
|
+
*/
|
|
78
|
+
backdrop?: boolean;
|
|
59
79
|
}
|
|
60
80
|
|
|
61
81
|
const SidePanel: React.FC<SidePanelProps> & {
|
|
@@ -66,7 +86,7 @@ const SidePanel: React.FC<SidePanelProps> & {
|
|
|
66
86
|
Body: typeof SidePanelBody;
|
|
67
87
|
Footer: typeof SidePanelFooter;
|
|
68
88
|
Close: typeof SidePanelClose;
|
|
69
|
-
} = ({ open, onOpenChange, children, side = 'right', closeOnEsc = true, closeOnOutsideClick = true }) => {
|
|
89
|
+
} = ({ open, onOpenChange, children, side = 'right', closeOnEsc = true, closeOnOutsideClick = true, backdrop = false }) => {
|
|
70
90
|
// The panel element, so the outside-click listener can ask "was this click
|
|
71
91
|
// inside?" — there is no backdrop to catch it for us.
|
|
72
92
|
const contentRef = React.useRef<HTMLDivElement | null>(null);
|
|
@@ -77,7 +97,8 @@ const SidePanel: React.FC<SidePanelProps> & {
|
|
|
77
97
|
React.useEffect(() => {
|
|
78
98
|
if (!open || !closeOnEsc) return;
|
|
79
99
|
const handler = (e: KeyboardEvent) => {
|
|
80
|
-
|
|
100
|
+
// Radix layers handle Esc first (capture phase) and mark it handled.
|
|
101
|
+
if (e.key === 'Escape' && !e.defaultPrevented && !nestedLayerOpen()) onOpenChange(false);
|
|
81
102
|
};
|
|
82
103
|
window.addEventListener('keydown', handler);
|
|
83
104
|
return () => window.removeEventListener('keydown', handler);
|
|
@@ -99,6 +120,7 @@ const SidePanel: React.FC<SidePanelProps> & {
|
|
|
99
120
|
|
|
100
121
|
const handler = (event: PointerEvent) => {
|
|
101
122
|
if (!armed) return;
|
|
123
|
+
if (nestedLayerOpen()) return;
|
|
102
124
|
const target = event.target as Node | null;
|
|
103
125
|
if (!target || contentRef.current?.contains(target)) return;
|
|
104
126
|
// A click inside any overlay the panel itself opened — a Select's
|
|
@@ -121,7 +143,7 @@ const SidePanel: React.FC<SidePanelProps> & {
|
|
|
121
143
|
};
|
|
122
144
|
}, [open, closeOnOutsideClick, onOpenChange]);
|
|
123
145
|
|
|
124
|
-
const contextValue = React.useMemo(() => ({ side, contentRef }), [side]);
|
|
146
|
+
const contextValue = React.useMemo(() => ({ side, contentRef, backdrop }), [side, backdrop]);
|
|
125
147
|
|
|
126
148
|
return (
|
|
127
149
|
<DrawerPrimitive.Root
|
|
@@ -152,6 +174,7 @@ SidePanel.displayName = 'SidePanel';
|
|
|
152
174
|
const SidePanelSideContext = React.createContext<{
|
|
153
175
|
side: 'right' | 'left';
|
|
154
176
|
contentRef?: React.MutableRefObject<HTMLDivElement | null>;
|
|
177
|
+
backdrop?: boolean;
|
|
155
178
|
}>({ side: 'right' });
|
|
156
179
|
|
|
157
180
|
// ─── Content ──────────────────────────────────────────────────────────────────
|
|
@@ -167,7 +190,7 @@ const SidePanelContent = React.forwardRef<
|
|
|
167
190
|
React.ElementRef<typeof DrawerPrimitive.Content>,
|
|
168
191
|
SidePanelContentProps
|
|
169
192
|
>(({ className, children, width = '440px', style, ...props }, ref) => {
|
|
170
|
-
const { side, contentRef } = React.useContext(SidePanelSideContext);
|
|
193
|
+
const { side, contentRef, backdrop } = React.useContext(SidePanelSideContext);
|
|
171
194
|
// Both refs always compose: the caller's, and the panel's own, which the
|
|
172
195
|
// outside-click listener measures against.
|
|
173
196
|
const composedRef = useComposedRefs(ref, contentRef ?? null);
|
|
@@ -176,6 +199,7 @@ const SidePanelContent = React.forwardRef<
|
|
|
176
199
|
|
|
177
200
|
return (
|
|
178
201
|
<DrawerPrimitive.Portal>
|
|
202
|
+
{backdrop ? <div aria-hidden="true" data-slot="side-panel-backdrop" className="fixed inset-0 z-499 bg-overlay animate-in fade-in-0" /> : null}
|
|
179
203
|
<DrawerPrimitive.Content
|
|
180
204
|
ref={composedRef}
|
|
181
205
|
aria-describedby={undefined}
|
|
@@ -4,11 +4,16 @@ import * as React from 'react';
|
|
|
4
4
|
|
|
5
5
|
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
6
6
|
|
|
7
|
+
import { formatHotkey } from '../../../hooks/hotkey/formatHotkey';
|
|
8
|
+
import { useCanHover } from '../../../hooks/media/useCanHover';
|
|
7
9
|
import { cn } from '../../../lib/utils';
|
|
8
10
|
|
|
9
11
|
const TooltipProvider = TooltipPrimitive.Provider
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
/** A tooltip names a control; it is not a surface to reach into, so it closes the moment the pointer leaves the trigger (no hoverable content, as in Notion). Pass `disableHoverableContent={false}` for one with a link inside. */
|
|
14
|
+
const Tooltip = ({ disableHoverableContent = true, ...props }: React.ComponentProps<typeof TooltipPrimitive.Root>) => (
|
|
15
|
+
<TooltipPrimitive.Root disableHoverableContent={disableHoverableContent} {...props} />
|
|
16
|
+
)
|
|
12
17
|
|
|
13
18
|
const TooltipTrigger = TooltipPrimitive.Trigger
|
|
14
19
|
|
|
@@ -22,10 +27,9 @@ const TooltipContent = React.forwardRef<
|
|
|
22
27
|
aria-describedby={undefined}
|
|
23
28
|
sideOffset={sideOffset}
|
|
24
29
|
className={cn(
|
|
25
|
-
// INVERSE
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
"z-[1400] overflow-hidden rounded-[var(--radius-tooltip)] bg-foreground px-3 py-1.5 text-xs font-medium text-background shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
30
|
+
// Surface from tokens: by default INVERSE (foreground bg + background text, high contrast on any panel);
|
|
31
|
+
// a preset (Notion) points --tooltip-bg/-fg/-border at the popover surface instead.
|
|
32
|
+
"pointer-events-none z-[1400] overflow-hidden rounded-[var(--radius-tooltip)] border border-[var(--tooltip-border,transparent)] bg-[var(--tooltip-bg,var(--foreground))] px-3 py-1.5 text-xs font-medium text-[var(--tooltip-fg,var(--background))] shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
29
33
|
className
|
|
30
34
|
)}
|
|
31
35
|
{...props}
|
|
@@ -34,4 +38,50 @@ const TooltipContent = React.forwardRef<
|
|
|
34
38
|
))
|
|
35
39
|
TooltipContent.displayName = TooltipPrimitive.Content.displayName
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
/** What a control says about itself on hover: a text (or node), or this config. One shape for every control that takes a `tooltip` prop. */
|
|
42
|
+
export interface TooltipConfig {
|
|
43
|
+
/** The name of the action. */
|
|
44
|
+
content: React.ReactNode
|
|
45
|
+
/** A `useHotkey` string (`mod+j`), shown after the content in a muted tone, written for the viewer's system (⌘J on a Mac, Ctrl+J elsewhere). */
|
|
46
|
+
hotkey?: string
|
|
47
|
+
side?: 'top' | 'right' | 'bottom' | 'left'
|
|
48
|
+
align?: 'start' | 'center' | 'end'
|
|
49
|
+
sideOffset?: number
|
|
50
|
+
/** Hover delay in ms. Default 400. */
|
|
51
|
+
delay?: number
|
|
52
|
+
/** Keep it open while the pointer is over it (a tooltip with a link). Default false. */
|
|
53
|
+
hoverable?: boolean
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type TooltipProp = React.ReactNode | TooltipConfig
|
|
57
|
+
|
|
58
|
+
function isConfig(value: TooltipProp): value is TooltipConfig {
|
|
59
|
+
return typeof value === 'object' && value !== null && !React.isValidElement(value) && 'content' in value
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Wraps one trigger element in the standard tooltip. This is what a `tooltip` prop on `Button` / `ButtonLink` calls; reach for it directly only around something that is not a button.
|
|
64
|
+
* It does not mount a `TooltipProvider` (the host's `UiProviders` does, once). Nothing is drawn (and no wrapper is added) when `tooltip` is empty or the device cannot hover (`useCanHover`: a phone or tablet). A disabled button gets no pointer events, so its trigger is a `span`.
|
|
65
|
+
*/
|
|
66
|
+
function TooltipHint({ tooltip, children, disabled = false }: { tooltip: TooltipProp; children: React.ReactElement; disabled?: boolean }) {
|
|
67
|
+
const canHover = useCanHover()
|
|
68
|
+
if (tooltip === undefined || tooltip === null || tooltip === false || tooltip === '' || !canHover) return children
|
|
69
|
+
const config: TooltipConfig = isConfig(tooltip) ? tooltip : { content: tooltip }
|
|
70
|
+
const trigger = disabled ? <span className="inline-flex cursor-not-allowed">{children}</span> : children
|
|
71
|
+
return (
|
|
72
|
+
<TooltipPrimitive.Root delayDuration={config.delay ?? 400} disableHoverableContent={!config.hoverable}>
|
|
73
|
+
<TooltipTrigger asChild>{trigger}</TooltipTrigger>
|
|
74
|
+
<TooltipContent
|
|
75
|
+
side={config.side}
|
|
76
|
+
align={config.align}
|
|
77
|
+
sideOffset={config.sideOffset}
|
|
78
|
+
className={cn('flex items-center gap-3', config.hotkey ? 'whitespace-nowrap' : undefined, config.hoverable && 'pointer-events-auto')}
|
|
79
|
+
>
|
|
80
|
+
<span>{config.content}</span>
|
|
81
|
+
{config.hotkey ? <span className="opacity-60">{formatHotkey(config.hotkey)}</span> : null}
|
|
82
|
+
</TooltipContent>
|
|
83
|
+
</TooltipPrimitive.Root>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider, TooltipHint }
|
|
@@ -7,6 +7,7 @@ import { useAppT } from '@djangocfg/i18n';
|
|
|
7
7
|
import { copyText } from '../../../lib/clipboard';
|
|
8
8
|
import { cn } from '../../../lib/utils';
|
|
9
9
|
import { Button } from '../../forms/button';
|
|
10
|
+
import type { TooltipProp } from '../../overlay/tooltip';
|
|
10
11
|
|
|
11
12
|
// =============================================================================
|
|
12
13
|
// CopyButton - Copy button with icon feedback
|
|
@@ -27,6 +28,8 @@ export interface CopyButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLBut
|
|
|
27
28
|
children?: React.ReactNode
|
|
28
29
|
/** Icon size class (default: "h-4 w-4") */
|
|
29
30
|
iconClassName?: string
|
|
31
|
+
/** Hover name (standard tooltip, hover devices only). Forwarded to the inner Button. */
|
|
32
|
+
tooltip?: TooltipProp
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
const CopyButton = React.forwardRef<HTMLButtonElement, CopyButtonProps>(
|
package/src/hooks/media/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { useMediaQuery, BREAKPOINTS as MEDIA_BREAKPOINTS } from './useMediaQuery
|
|
|
4
4
|
export { useIsMobile, useIsPhone, useIsTabletOrBelow, BREAKPOINTS } from './useMobile';
|
|
5
5
|
export type { Breakpoint } from './useMobile';
|
|
6
6
|
export { useIsTouch } from './useIsTouch';
|
|
7
|
+
export { useCanHover } from './useCanHover';
|
|
7
8
|
export { useDisplayMode, useIsPwa } from './useDisplayMode';
|
|
8
9
|
export { detectDisplayMode, syncDisplayModeAttribute } from './displayMode';
|
|
9
10
|
export type { DisplayMode } from './displayMode';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useMediaQuery } from './useMediaQuery';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Can the primary input hover (a mouse or trackpad), as opposed to a finger or a pen-less tablet?
|
|
7
|
+
*
|
|
8
|
+
* Reads `(hover: hover) and (pointer: fine)` via `matchMedia`, not the userAgent, so a touch laptop with a trackpad counts, an iPad does not, and DevTools device
|
|
9
|
+
* emulation updates live. SSR-safe (false until mounted). The tooltip of `Button` / `ButtonLink` is drawn only when this is true: there is nothing to hover on a phone,
|
|
10
|
+
* and a hint that needs a long press is noise. Hover hints are also the ones that name a keyboard shortcut, which a phone has none of.
|
|
11
|
+
*/
|
|
12
|
+
export function useCanHover(): boolean {
|
|
13
|
+
return useMediaQuery('(hover: hover) and (pointer: fine)');
|
|
14
|
+
}
|
package/src/styles/css/base.css
CHANGED
|
@@ -91,7 +91,8 @@
|
|
|
91
91
|
--control-h-huge: 3.5rem;
|
|
92
92
|
--button-weight: 600;
|
|
93
93
|
/* PrivateLayout sidebar rows (desktop). */
|
|
94
|
-
--sidebar-item-h:
|
|
94
|
+
--sidebar-item-h: 2rem;
|
|
95
|
+
--sidebar-item-gap: 0.125rem;
|
|
95
96
|
--sidebar-item-font: var(--font-size-sm);
|
|
96
97
|
--sidebar-item-radius: 0.5rem;
|
|
97
98
|
--sidebar-divider-h: 1px;
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
--button-weight: 500;
|
|
98
98
|
/* Notion's sidebar row: 30px, 14px type, 6px corner. */
|
|
99
99
|
--sidebar-item-h: 1.875rem;
|
|
100
|
+
--sidebar-item-gap: 0.0625rem;
|
|
100
101
|
--sidebar-item-font: var(--font-size-base);
|
|
101
102
|
--sidebar-item-radius: 0.375rem;
|
|
102
103
|
/* Notion separates sidebar groups by space, not by a rule. */
|
|
@@ -128,7 +129,13 @@
|
|
|
128
129
|
--menu-label-weight: 500;
|
|
129
130
|
--menu-label-color: var(--muted-foreground);
|
|
130
131
|
--radius-popover: 0.625rem;
|
|
131
|
-
|
|
132
|
+
/* Tooltips are the popover surface with a hairline, not inverted (Notion: "Chat ^2" on the same grey as the menus). */
|
|
133
|
+
--tooltip-bg: var(--popover);
|
|
134
|
+
--tooltip-fg: var(--popover-foreground);
|
|
135
|
+
--tooltip-border: var(--border);
|
|
136
|
+
--radius-tooltip: 0.375rem;
|
|
137
|
+
/* The popover already has a hairline border, so no ring here; a short, soft lift (the earlier 0.2 / 24px blur read as a heavy cloud on white). */
|
|
138
|
+
--popup-shadow: 0 2px 4px rgb(15 15 15 / 0.05), 0 8px 20px -6px rgb(15 15 15 / 0.12);
|
|
132
139
|
--menu-item-px: 0.5rem;
|
|
133
140
|
--menu-item-py: 0.25rem;
|
|
134
141
|
--menu-padding: 0.25rem;
|
|
@@ -146,17 +146,31 @@
|
|
|
146
146
|
|
|
147
147
|
@media (max-width: 768px) {
|
|
148
148
|
/* Enforce on mobile for buttons, links with onClick, form controls */
|
|
149
|
-
button,
|
|
149
|
+
button:not([role="checkbox"], [role="switch"], [role="radio"], [role="combobox"], [role="tab"]),
|
|
150
150
|
[role="button"],
|
|
151
151
|
a[onClick],
|
|
152
152
|
input[type="submit"],
|
|
153
153
|
input[type="button"],
|
|
154
|
-
input[type="reset"]
|
|
155
|
-
select {
|
|
154
|
+
input[type="reset"] {
|
|
156
155
|
min-height: 44px;
|
|
157
156
|
min-width: 44px;
|
|
158
157
|
}
|
|
159
158
|
|
|
159
|
+
/* Field controls keep their own size (--control-h-*, 16px box, switch track): inflating them made the checkbox a
|
|
160
|
+
* 44px square, squashed the switch and left Select taller than Input. The 44px hit area is an invisible ::after. */
|
|
161
|
+
:where(button)[role="checkbox"],
|
|
162
|
+
:where(button)[role="switch"],
|
|
163
|
+
:where(button)[role="radio"] {
|
|
164
|
+
position: relative;
|
|
165
|
+
}
|
|
166
|
+
:where(button)[role="checkbox"]::after,
|
|
167
|
+
:where(button)[role="switch"]::after,
|
|
168
|
+
:where(button)[role="radio"]::after {
|
|
169
|
+
content: "";
|
|
170
|
+
position: absolute;
|
|
171
|
+
inset: -14px;
|
|
172
|
+
}
|
|
173
|
+
|
|
160
174
|
/* Special case: Icon-only buttons */
|
|
161
175
|
button[aria-label]:not(:has(*)),
|
|
162
176
|
[role="button"][aria-label]:not(:has(*)) {
|