@softure-ai/theme-notion 0.8.0 → 0.10.1
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/CHANGELOG.md +58 -0
- package/README.md +133 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/notion/InstallBar.d.ts +23 -0
- package/dist/notion/InstallBar.d.ts.map +1 -0
- package/dist/notion/InstallBar.js +16 -0
- package/dist/notion/InstallBar.js.map +1 -0
- package/dist/notion/MiniProgress.d.ts +13 -0
- package/dist/notion/MiniProgress.d.ts.map +1 -0
- package/dist/notion/MiniProgress.js +24 -0
- package/dist/notion/MiniProgress.js.map +1 -0
- package/dist/notion/SheetMenu.d.ts +9 -0
- package/dist/notion/SheetMenu.d.ts.map +1 -0
- package/dist/notion/SheetMenu.js +19 -0
- package/dist/notion/SheetMenu.js.map +1 -0
- package/dist/notion/Status.d.ts +2 -1
- package/dist/notion/Status.d.ts.map +1 -1
- package/dist/notion/Status.js +7 -2
- package/dist/notion/Status.js.map +1 -1
- package/dist/notion/UpdatePrompt.d.ts +13 -0
- package/dist/notion/UpdatePrompt.d.ts.map +1 -0
- package/dist/notion/UpdatePrompt.js +16 -0
- package/dist/notion/UpdatePrompt.js.map +1 -0
- package/dist/ui/accordion.d.ts +3 -1
- package/dist/ui/accordion.d.ts.map +1 -1
- package/dist/ui/accordion.js +2 -2
- package/dist/ui/accordion.js.map +1 -1
- package/dist/ui/badge.js +1 -1
- package/dist/ui/badge.js.map +1 -1
- package/dist/ui/button.d.ts +1 -1
- package/dist/ui/button.d.ts.map +1 -1
- package/dist/ui/button.js +2 -0
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/dialog.d.ts +2 -1
- package/dist/ui/dialog.d.ts.map +1 -1
- package/dist/ui/dialog.js +3 -2
- package/dist/ui/dialog.js.map +1 -1
- package/dist/ui/dropdown-menu.d.ts +14 -5
- package/dist/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/ui/dropdown-menu.js +21 -10
- package/dist/ui/dropdown-menu.js.map +1 -1
- package/dist/ui/select.d.ts +8 -3
- package/dist/ui/select.d.ts.map +1 -1
- package/dist/ui/select.js +10 -5
- package/dist/ui/select.js.map +1 -1
- package/dist/ui/tabs.d.ts +6 -2
- package/dist/ui/tabs.d.ts.map +1 -1
- package/dist/ui/tabs.js +13 -4
- package/dist/ui/tabs.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/notion/InstallBar.tsx +75 -0
- package/src/notion/MiniProgress.tsx +67 -0
- package/src/notion/SheetMenu.tsx +41 -0
- package/src/notion/Status.tsx +14 -3
- package/src/notion/UpdatePrompt.tsx +47 -0
- package/src/ui/accordion.tsx +5 -1
- package/src/ui/badge.tsx +1 -1
- package/src/ui/button.tsx +3 -0
- package/src/ui/dialog.tsx +8 -1
- package/src/ui/dropdown-menu.tsx +55 -16
- package/src/ui/select.tsx +23 -5
- package/src/ui/tabs.tsx +27 -7
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Progress as ProgressPrimitive } from "radix-ui";
|
|
4
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils.js";
|
|
7
|
+
|
|
8
|
+
import { TONE_FILL, type Tone } from "./tones.js";
|
|
9
|
+
|
|
10
|
+
export type MiniProgressProps = Omit<ComponentProps<typeof ProgressPrimitive.Root>, "children" | "max" | "value"> & {
|
|
11
|
+
/** 0–100, clamped; non-finite values read as 0. */
|
|
12
|
+
readonly value: number;
|
|
13
|
+
/** Text inside the bar, e.g. a formatted amount; defaults to the rounded percent. */
|
|
14
|
+
readonly label?: ReactNode;
|
|
15
|
+
/** Fill colour by meaning (the theme's tones); defaults to primary. */
|
|
16
|
+
readonly tone?: Tone;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function clampShare(value: number): number {
|
|
20
|
+
if (!Number.isFinite(value)) return 0;
|
|
21
|
+
return Math.min(100, Math.max(0, value));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const LABEL_CLASS = "absolute inset-0 flex items-center px-2 text-xs font-medium tabular-nums whitespace-nowrap";
|
|
25
|
+
|
|
26
|
+
// A share with its figure inside the bar, for a table cell or a tile: a 20 px track that takes the cell's width and
|
|
27
|
+
// carries the label, so a figure and a bar never collide in a narrow column. The label is drawn twice: in the text
|
|
28
|
+
// colour on the track, and in the page background clipped to the fill, so it reads at any value, also where the
|
|
29
|
+
// fill's edge crosses a letter. Both copies are hidden: the progress bar itself reports the value (and a string label
|
|
30
|
+
// as its value text). A label wider than the cell ends in an ellipsis.
|
|
31
|
+
export function MiniProgress({ value, label, tone, className, ...props }: MiniProgressProps) {
|
|
32
|
+
const share = clampShare(value);
|
|
33
|
+
const text = label ?? `${Math.round(share)}%`;
|
|
34
|
+
return (
|
|
35
|
+
<ProgressPrimitive.Root
|
|
36
|
+
data-slot="mini-progress"
|
|
37
|
+
data-tone={tone ?? "default"}
|
|
38
|
+
value={share}
|
|
39
|
+
max={100}
|
|
40
|
+
getValueLabel={typeof text === "string" ? () => text : undefined}
|
|
41
|
+
className={cn("relative h-5 w-full min-w-16 overflow-hidden rounded-sm bg-primary/12", className)}
|
|
42
|
+
{...props}
|
|
43
|
+
>
|
|
44
|
+
<ProgressPrimitive.Indicator
|
|
45
|
+
data-slot="mini-progress-indicator"
|
|
46
|
+
className={cn(
|
|
47
|
+
"absolute inset-y-0 left-0 transition-[width]",
|
|
48
|
+
// In dark the default fill is the lighter link blue, as in `Progress`.
|
|
49
|
+
tone === undefined ? "bg-primary dark:bg-link" : TONE_FILL[tone],
|
|
50
|
+
)}
|
|
51
|
+
style={{ width: `${share}%` }}
|
|
52
|
+
/>
|
|
53
|
+
<span aria-hidden="true" data-slot="mini-progress-label" className={cn(LABEL_CLASS, "text-foreground")}>
|
|
54
|
+
<span className="truncate">{text}</span>
|
|
55
|
+
</span>
|
|
56
|
+
{/* The page background, not `primary-foreground`: white on the dark fills stays under 4.5:1. */}
|
|
57
|
+
<span
|
|
58
|
+
aria-hidden="true"
|
|
59
|
+
data-slot="mini-progress-label"
|
|
60
|
+
className={cn(LABEL_CLASS, "text-background")}
|
|
61
|
+
style={{ clipPath: `inset(0 ${100 - share}% 0 0)` }}
|
|
62
|
+
>
|
|
63
|
+
<span className="truncate">{text}</span>
|
|
64
|
+
</span>
|
|
65
|
+
</ProgressPrimitive.Root>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Slot } from "radix-ui";
|
|
4
|
+
import type { ComponentProps } from "react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils.js";
|
|
7
|
+
|
|
8
|
+
// Navigation rows inside a `Sheet` (a phone's navigation drawer), shaped like the sidebar's menu but with no
|
|
9
|
+
// `SidebarProvider`: a list of items, each holding one full-width row.
|
|
10
|
+
export function SheetMenu({ className, ...props }: ComponentProps<"ul">) {
|
|
11
|
+
return <ul data-slot="sheet-menu" className={cn("flex w-full min-w-0 flex-col gap-1", className)} {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function SheetMenuItem({ className, ...props }: ComponentProps<"li">) {
|
|
15
|
+
return <li data-slot="sheet-menu-item" className={cn("relative", className)} {...props} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SheetMenuButtonProps extends ComponentProps<"button"> {
|
|
19
|
+
// Renders the child (a link) with the row's look instead of a button.
|
|
20
|
+
readonly asChild?: boolean;
|
|
21
|
+
// The row of the screen being shown; the caller adds `aria-current="page"` on a link.
|
|
22
|
+
readonly isActive?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// One row: icon and label left-aligned in the foreground colour, a touch target tall on a phone and a list row
|
|
26
|
+
// from `md`, hovered and focused like the sidebar's rows on the sheet's `background`.
|
|
27
|
+
export function SheetMenuButton({ asChild = false, isActive = false, className, type, ...props }: SheetMenuButtonProps) {
|
|
28
|
+
const Comp = asChild ? Slot.Root : "button";
|
|
29
|
+
return (
|
|
30
|
+
<Comp
|
|
31
|
+
data-slot="sheet-menu-button"
|
|
32
|
+
data-active={isActive}
|
|
33
|
+
type={asChild ? type : (type ?? "button")}
|
|
34
|
+
className={cn(
|
|
35
|
+
"flex min-h-touch-target w-full items-center gap-2 overflow-hidden rounded-md px-2 text-left text-ui text-foreground outline-hidden transition-colors duration-120 hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring active:bg-accent disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-accent data-[active=true]:font-medium md:min-h-row-height [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
|
36
|
+
className,
|
|
37
|
+
)}
|
|
38
|
+
{...props}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
package/src/notion/Status.tsx
CHANGED
|
@@ -25,20 +25,31 @@ export interface StatusProps {
|
|
|
25
25
|
icon: LucideIcon;
|
|
26
26
|
// The word: a status always carries one, so states read apart without telling colours apart.
|
|
27
27
|
children: ReactNode;
|
|
28
|
+
// The full word on hover; defaults to the word itself when it is a string or a number, since a long one is cut.
|
|
29
|
+
title?: string;
|
|
28
30
|
className?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
/** The word as plain text, or undefined when it is any other node. */
|
|
34
|
+
function getPlainText(children: ReactNode): string | undefined {
|
|
35
|
+
return typeof children === "string" || typeof children === "number" ? String(children) : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
// A state of something (booked, to pay, overdue): a ghost badge with a line icon and a word in a palette colour.
|
|
32
|
-
|
|
39
|
+
// In a narrow container the word, not the icon, shrinks and ends in an ellipsis.
|
|
40
|
+
export function Status({ color, icon: Icon, children, title, className }: StatusProps) {
|
|
33
41
|
return (
|
|
34
42
|
<Badge
|
|
35
43
|
variant="ghost"
|
|
36
44
|
data-slot="status"
|
|
37
45
|
data-color={color}
|
|
38
|
-
|
|
46
|
+
title={title ?? getPlainText(children)}
|
|
47
|
+
className={cn("gap-1.5 px-0 text-sm font-normal [&>svg]:size-4 [&>svg]:shrink-0", TEXT_COLOR[color], className)}
|
|
39
48
|
>
|
|
40
49
|
<Icon aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
|
|
41
|
-
|
|
50
|
+
<span data-slot="status-label" className="min-w-0 truncate">
|
|
51
|
+
{children}
|
|
52
|
+
</span>
|
|
42
53
|
</Badge>
|
|
43
54
|
);
|
|
44
55
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { RefreshCw } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "../lib/utils.js";
|
|
4
|
+
import { Alert, AlertDescription, AlertTitle } from "../ui/alert.js";
|
|
5
|
+
import { Button } from "../ui/button.js";
|
|
6
|
+
|
|
7
|
+
import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
|
|
8
|
+
|
|
9
|
+
export interface UpdatePromptProps {
|
|
10
|
+
/** A new build waits (`isUpdateReady` from `useServiceWorkerUpdate` in `@softure-ai/pwa/react`). */
|
|
11
|
+
readonly open: boolean;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly description: string;
|
|
14
|
+
/** The button's text. */
|
|
15
|
+
readonly reload: string;
|
|
16
|
+
/** The button's action (`activate` from `useServiceWorkerUpdate`): the new build takes over and the page reloads. */
|
|
17
|
+
readonly onReload: () => void;
|
|
18
|
+
readonly className?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The offer to reload into a new build: a floating alert at the bottom of the screen, above the home indicator and
|
|
22
|
+
// beside a notch (the safe-area insets), with a reload button at the touch height on a phone. It is a polite status,
|
|
23
|
+
// not an alert: the offer never interrupts what a screen reader is reading. The copy is the app's
|
|
24
|
+
// (`pwaMessages.en.update` in `@softure-ai/pwa` has the English text, keyed like these props).
|
|
25
|
+
export function UpdatePrompt({ open, title, description, reload, onReload, className }: UpdatePromptProps) {
|
|
26
|
+
if (!open) return null;
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
data-slot="update-prompt"
|
|
30
|
+
className={cn(
|
|
31
|
+
"pointer-events-none fixed inset-x-0 bottom-0 z-50 flex justify-center pt-4 pr-[calc(--spacing(4)+env(safe-area-inset-right))] pb-[calc(--spacing(4)+env(safe-area-inset-bottom))] pl-[calc(--spacing(4)+env(safe-area-inset-left))]",
|
|
32
|
+
className,
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
<Alert role="status" aria-live="polite" className="pointer-events-auto max-w-md shadow-menu">
|
|
36
|
+
<RefreshCw strokeWidth={ICON_STROKE_WIDTH} />
|
|
37
|
+
<AlertTitle>{title}</AlertTitle>
|
|
38
|
+
<AlertDescription>
|
|
39
|
+
<p>{description}</p>
|
|
40
|
+
<Button size="touch" className="mt-1 md:h-7" onClick={onReload}>
|
|
41
|
+
{reload}
|
|
42
|
+
</Button>
|
|
43
|
+
</AlertDescription>
|
|
44
|
+
</Alert>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
package/src/ui/accordion.tsx
CHANGED
|
@@ -27,14 +27,18 @@ function AccordionItem({
|
|
|
27
27
|
function AccordionTrigger({
|
|
28
28
|
className,
|
|
29
29
|
children,
|
|
30
|
+
size = "default",
|
|
30
31
|
...props
|
|
31
|
-
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>
|
|
32
|
+
}: React.ComponentProps<typeof AccordionPrimitive.Trigger> & {
|
|
33
|
+
size?: "default" | "touch"
|
|
34
|
+
}) {
|
|
32
35
|
return (
|
|
33
36
|
<AccordionPrimitive.Header className="flex">
|
|
34
37
|
<AccordionPrimitive.Trigger
|
|
35
38
|
data-slot="accordion-trigger"
|
|
36
39
|
className={cn(
|
|
37
40
|
"flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180",
|
|
41
|
+
size === "touch" && "min-h-touch-target",
|
|
38
42
|
className
|
|
39
43
|
)}
|
|
40
44
|
{...props}
|
package/src/ui/badge.tsx
CHANGED
|
@@ -20,7 +20,7 @@ const TAG_COLORS = {
|
|
|
20
20
|
const COLORED_VARIANTS = ["default", "secondary", "outline", "ghost", "link", "tag"] as const
|
|
21
21
|
|
|
22
22
|
const badgeVariants = cva(
|
|
23
|
-
"inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3",
|
|
23
|
+
"inline-flex w-fit max-w-full shrink-0 items-center justify-center-safe gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3",
|
|
24
24
|
{
|
|
25
25
|
variants: {
|
|
26
26
|
variant: {
|
package/src/ui/button.tsx
CHANGED
|
@@ -29,6 +29,9 @@ const buttonVariants = cva(
|
|
|
29
29
|
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
30
30
|
"icon-sm": "size-6",
|
|
31
31
|
"icon-lg": "size-8",
|
|
32
|
+
touch:
|
|
33
|
+
"h-touch-target px-3 has-[>svg:first-child]:pl-2.5 has-[>svg:last-child]:pr-2.5",
|
|
34
|
+
"icon-touch": "size-touch-target",
|
|
32
35
|
},
|
|
33
36
|
},
|
|
34
37
|
defaultVariants: {
|
package/src/ui/dialog.tsx
CHANGED
|
@@ -53,11 +53,14 @@ function DialogContent({
|
|
|
53
53
|
children,
|
|
54
54
|
showCloseButton = true,
|
|
55
55
|
closeLabel = messages.dialog.close,
|
|
56
|
+
closeButtonSize = "default",
|
|
56
57
|
...props
|
|
57
58
|
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
|
58
59
|
showCloseButton?: boolean
|
|
59
60
|
// The close button's hidden text, from the app's message layer.
|
|
60
61
|
closeLabel?: string
|
|
62
|
+
// `touch` draws the close button 44 x 44, centred on the same icon.
|
|
63
|
+
closeButtonSize?: "default" | "touch"
|
|
61
64
|
}) {
|
|
62
65
|
return (
|
|
63
66
|
<DialogPortal data-slot="dialog-portal">
|
|
@@ -74,7 +77,11 @@ function DialogContent({
|
|
|
74
77
|
{showCloseButton && (
|
|
75
78
|
<DialogPrimitive.Close
|
|
76
79
|
data-slot="dialog-close"
|
|
77
|
-
className=
|
|
80
|
+
className={cn(
|
|
81
|
+
"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
82
|
+
closeButtonSize === "touch" &&
|
|
83
|
+
"top-0.5 right-0.5 inline-flex size-touch-target items-center justify-center rounded-md"
|
|
84
|
+
)}
|
|
78
85
|
>
|
|
79
86
|
<XIcon />
|
|
80
87
|
<span className="sr-only">{closeLabel}</span>
|
package/src/ui/dropdown-menu.tsx
CHANGED
|
@@ -5,6 +5,18 @@ import { cn } from "../lib/utils.js"
|
|
|
5
5
|
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
|
6
6
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
|
|
7
7
|
|
|
8
|
+
type DropdownMenuItemSize = "default" | "touch"
|
|
9
|
+
|
|
10
|
+
// The items render in a portal, so a menu's size reaches them through context, not the DOM.
|
|
11
|
+
const DropdownMenuItemSizeContext =
|
|
12
|
+
React.createContext<DropdownMenuItemSize>("default")
|
|
13
|
+
|
|
14
|
+
// One height or the other: `cn` does not merge `min-h-7` with the theme's `touch-target` spacing.
|
|
15
|
+
function useItemHeight(size: DropdownMenuItemSize | undefined) {
|
|
16
|
+
const menuSize = React.useContext(DropdownMenuItemSizeContext)
|
|
17
|
+
return (size ?? menuSize) === "touch" ? "min-h-touch-target" : "min-h-7"
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
function DropdownMenu({
|
|
9
21
|
...props
|
|
10
22
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
|
@@ -33,19 +45,24 @@ function DropdownMenuTrigger({
|
|
|
33
45
|
function DropdownMenuContent({
|
|
34
46
|
className,
|
|
35
47
|
sideOffset = 4,
|
|
48
|
+
size = "default",
|
|
36
49
|
...props
|
|
37
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>
|
|
50
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content> & {
|
|
51
|
+
size?: DropdownMenuItemSize
|
|
52
|
+
}) {
|
|
38
53
|
return (
|
|
39
54
|
<DropdownMenuPrimitive.Portal>
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
<DropdownMenuItemSizeContext.Provider value={size}>
|
|
56
|
+
<DropdownMenuPrimitive.Content
|
|
57
|
+
data-slot="dropdown-menu-content"
|
|
58
|
+
sideOffset={sideOffset}
|
|
59
|
+
className={cn(
|
|
60
|
+
"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-xl bg-popover p-1 text-popover-foreground shadow-menu 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 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
61
|
+
className
|
|
62
|
+
)}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
</DropdownMenuItemSizeContext.Provider>
|
|
49
66
|
</DropdownMenuPrimitive.Portal>
|
|
50
67
|
)
|
|
51
68
|
}
|
|
@@ -62,18 +79,23 @@ function DropdownMenuItem({
|
|
|
62
79
|
className,
|
|
63
80
|
inset,
|
|
64
81
|
variant = "default",
|
|
82
|
+
size,
|
|
65
83
|
...props
|
|
66
84
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
|
67
85
|
inset?: boolean
|
|
68
86
|
variant?: "default" | "destructive"
|
|
87
|
+
size?: DropdownMenuItemSize
|
|
69
88
|
}) {
|
|
89
|
+
const height = useItemHeight(size)
|
|
90
|
+
|
|
70
91
|
return (
|
|
71
92
|
<DropdownMenuPrimitive.Item
|
|
72
93
|
data-slot="dropdown-menu-item"
|
|
73
94
|
data-inset={inset}
|
|
74
95
|
data-variant={variant}
|
|
75
96
|
className={cn(
|
|
76
|
-
"relative flex cursor-default items-center gap-2 rounded-md
|
|
97
|
+
"relative flex cursor-default items-center gap-2 rounded-md px-2 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/10 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",
|
|
98
|
+
height,
|
|
77
99
|
className
|
|
78
100
|
)}
|
|
79
101
|
{...props}
|
|
@@ -85,13 +107,19 @@ function DropdownMenuCheckboxItem({
|
|
|
85
107
|
className,
|
|
86
108
|
children,
|
|
87
109
|
checked,
|
|
110
|
+
size,
|
|
88
111
|
...props
|
|
89
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>
|
|
112
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem> & {
|
|
113
|
+
size?: DropdownMenuItemSize
|
|
114
|
+
}) {
|
|
115
|
+
const height = useItemHeight(size)
|
|
116
|
+
|
|
90
117
|
return (
|
|
91
118
|
<DropdownMenuPrimitive.CheckboxItem
|
|
92
119
|
data-slot="dropdown-menu-checkbox-item"
|
|
93
120
|
className={cn(
|
|
94
|
-
"relative flex cursor-default items-center gap-2 rounded-md
|
|
121
|
+
"relative flex cursor-default items-center gap-2 rounded-md py-1 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
122
|
+
height,
|
|
95
123
|
className
|
|
96
124
|
)}
|
|
97
125
|
checked={checked}
|
|
@@ -121,13 +149,19 @@ function DropdownMenuRadioGroup({
|
|
|
121
149
|
function DropdownMenuRadioItem({
|
|
122
150
|
className,
|
|
123
151
|
children,
|
|
152
|
+
size,
|
|
124
153
|
...props
|
|
125
|
-
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>
|
|
154
|
+
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem> & {
|
|
155
|
+
size?: DropdownMenuItemSize
|
|
156
|
+
}) {
|
|
157
|
+
const height = useItemHeight(size)
|
|
158
|
+
|
|
126
159
|
return (
|
|
127
160
|
<DropdownMenuPrimitive.RadioItem
|
|
128
161
|
data-slot="dropdown-menu-radio-item"
|
|
129
162
|
className={cn(
|
|
130
|
-
"relative flex cursor-default items-center gap-2 rounded-md
|
|
163
|
+
"relative flex cursor-default items-center gap-2 rounded-md py-1 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
164
|
+
height,
|
|
131
165
|
className
|
|
132
166
|
)}
|
|
133
167
|
{...props}
|
|
@@ -201,16 +235,21 @@ function DropdownMenuSubTrigger({
|
|
|
201
235
|
className,
|
|
202
236
|
inset,
|
|
203
237
|
children,
|
|
238
|
+
size,
|
|
204
239
|
...props
|
|
205
240
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
|
206
241
|
inset?: boolean
|
|
242
|
+
size?: DropdownMenuItemSize
|
|
207
243
|
}) {
|
|
244
|
+
const height = useItemHeight(size)
|
|
245
|
+
|
|
208
246
|
return (
|
|
209
247
|
<DropdownMenuPrimitive.SubTrigger
|
|
210
248
|
data-slot="dropdown-menu-sub-trigger"
|
|
211
249
|
data-inset={inset}
|
|
212
250
|
className={cn(
|
|
213
|
-
"flex cursor-default items-center gap-2 rounded-md
|
|
251
|
+
"flex cursor-default items-center gap-2 rounded-md px-2 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
|
252
|
+
height,
|
|
214
253
|
className
|
|
215
254
|
)}
|
|
216
255
|
{...props}
|
package/src/ui/select.tsx
CHANGED
|
@@ -5,6 +5,11 @@ import { cn } from "../lib/utils.js"
|
|
|
5
5
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
|
6
6
|
import { Select as SelectPrimitive } from "radix-ui"
|
|
7
7
|
|
|
8
|
+
type SelectItemSize = "default" | "touch"
|
|
9
|
+
|
|
10
|
+
// The items render in a portal, so a list's size reaches them through context, not the DOM.
|
|
11
|
+
const SelectItemSizeContext = React.createContext<SelectItemSize>("default")
|
|
12
|
+
|
|
8
13
|
function Select({
|
|
9
14
|
...props
|
|
10
15
|
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
|
@@ -29,7 +34,7 @@ function SelectTrigger({
|
|
|
29
34
|
children,
|
|
30
35
|
...props
|
|
31
36
|
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
|
32
|
-
size?: "sm" | "default"
|
|
37
|
+
size?: "sm" | "default" | "touch"
|
|
33
38
|
}) {
|
|
34
39
|
return (
|
|
35
40
|
<SelectPrimitive.Trigger
|
|
@@ -37,6 +42,7 @@ function SelectTrigger({
|
|
|
37
42
|
data-size={size}
|
|
38
43
|
className={cn(
|
|
39
44
|
"flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-field px-2.5 py-1 text-sm whitespace-nowrap transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-7 data-[size=sm]:h-6 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
|
45
|
+
size === "touch" && "h-touch-target",
|
|
40
46
|
className
|
|
41
47
|
)}
|
|
42
48
|
{...props}
|
|
@@ -54,8 +60,11 @@ function SelectContent({
|
|
|
54
60
|
children,
|
|
55
61
|
position = "item-aligned",
|
|
56
62
|
align = "center",
|
|
63
|
+
size = "default",
|
|
57
64
|
...props
|
|
58
|
-
}: React.ComponentProps<typeof SelectPrimitive.Content>
|
|
65
|
+
}: React.ComponentProps<typeof SelectPrimitive.Content> & {
|
|
66
|
+
size?: SelectItemSize
|
|
67
|
+
}) {
|
|
59
68
|
return (
|
|
60
69
|
<SelectPrimitive.Portal>
|
|
61
70
|
<SelectPrimitive.Content
|
|
@@ -78,7 +87,9 @@ function SelectContent({
|
|
|
78
87
|
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
|
79
88
|
)}
|
|
80
89
|
>
|
|
81
|
-
{
|
|
90
|
+
<SelectItemSizeContext.Provider value={size}>
|
|
91
|
+
{children}
|
|
92
|
+
</SelectItemSizeContext.Provider>
|
|
82
93
|
</SelectPrimitive.Viewport>
|
|
83
94
|
<SelectScrollDownButton />
|
|
84
95
|
</SelectPrimitive.Content>
|
|
@@ -102,13 +113,20 @@ function SelectLabel({
|
|
|
102
113
|
function SelectItem({
|
|
103
114
|
className,
|
|
104
115
|
children,
|
|
116
|
+
size,
|
|
105
117
|
...props
|
|
106
|
-
}: React.ComponentProps<typeof SelectPrimitive.Item>
|
|
118
|
+
}: React.ComponentProps<typeof SelectPrimitive.Item> & {
|
|
119
|
+
size?: SelectItemSize
|
|
120
|
+
}) {
|
|
121
|
+
const listSize = React.useContext(SelectItemSizeContext)
|
|
122
|
+
|
|
107
123
|
return (
|
|
108
124
|
<SelectPrimitive.Item
|
|
109
125
|
data-slot="select-item"
|
|
110
126
|
className={cn(
|
|
111
|
-
"relative flex w-full cursor-default items-center gap-2 rounded-md py-1
|
|
127
|
+
"relative flex w-full cursor-default items-center gap-2 rounded-md py-1 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
|
128
|
+
// One height or the other: `cn` does not merge `min-h-7` with the theme's `touch-target` spacing.
|
|
129
|
+
(size ?? listSize) === "touch" ? "min-h-touch-target" : "min-h-7",
|
|
112
130
|
className
|
|
113
131
|
)}
|
|
114
132
|
{...props}
|
package/src/ui/tabs.tsx
CHANGED
|
@@ -5,6 +5,11 @@ import { cva, type VariantProps } from "class-variance-authority"
|
|
|
5
5
|
import { cn } from "../lib/utils.js"
|
|
6
6
|
import { Tabs as TabsPrimitive } from "radix-ui"
|
|
7
7
|
|
|
8
|
+
type TabsTriggerSize = "default" | "touch"
|
|
9
|
+
|
|
10
|
+
// A list's size reaches its triggers through context, so a trigger's own size can win over it.
|
|
11
|
+
const TabsTriggerSizeContext = React.createContext<TabsTriggerSize>("default")
|
|
12
|
+
|
|
8
13
|
function Tabs({
|
|
9
14
|
className,
|
|
10
15
|
orientation = "horizontal",
|
|
@@ -32,9 +37,15 @@ const tabsListVariants = cva(
|
|
|
32
37
|
default: "bg-muted",
|
|
33
38
|
line: "gap-1 bg-transparent",
|
|
34
39
|
},
|
|
40
|
+
size: {
|
|
41
|
+
default: "",
|
|
42
|
+
// The triggers set the height: a fixed one would cap them at 35 px.
|
|
43
|
+
touch: "group-data-[orientation=horizontal]/tabs:h-auto",
|
|
44
|
+
},
|
|
35
45
|
},
|
|
36
46
|
defaultVariants: {
|
|
37
47
|
variant: "line",
|
|
48
|
+
size: "default",
|
|
38
49
|
},
|
|
39
50
|
}
|
|
40
51
|
)
|
|
@@ -42,23 +53,31 @@ const tabsListVariants = cva(
|
|
|
42
53
|
function TabsList({
|
|
43
54
|
className,
|
|
44
55
|
variant = "line",
|
|
56
|
+
size = "default",
|
|
45
57
|
...props
|
|
46
58
|
}: React.ComponentProps<typeof TabsPrimitive.List> &
|
|
47
59
|
VariantProps<typeof tabsListVariants>) {
|
|
48
60
|
return (
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
<TabsTriggerSizeContext.Provider value={size ?? "default"}>
|
|
62
|
+
<TabsPrimitive.List
|
|
63
|
+
data-slot="tabs-list"
|
|
64
|
+
data-variant={variant}
|
|
65
|
+
className={cn(tabsListVariants({ variant, size }), className)}
|
|
66
|
+
{...props}
|
|
67
|
+
/>
|
|
68
|
+
</TabsTriggerSizeContext.Provider>
|
|
55
69
|
)
|
|
56
70
|
}
|
|
57
71
|
|
|
58
72
|
function TabsTrigger({
|
|
59
73
|
className,
|
|
74
|
+
size,
|
|
60
75
|
...props
|
|
61
|
-
}: React.ComponentProps<typeof TabsPrimitive.Trigger>
|
|
76
|
+
}: React.ComponentProps<typeof TabsPrimitive.Trigger> & {
|
|
77
|
+
size?: TabsTriggerSize
|
|
78
|
+
}) {
|
|
79
|
+
const listSize = React.useContext(TabsTriggerSizeContext)
|
|
80
|
+
|
|
62
81
|
return (
|
|
63
82
|
<TabsPrimitive.Trigger
|
|
64
83
|
data-slot="tabs-trigger"
|
|
@@ -67,6 +86,7 @@ function TabsTrigger({
|
|
|
67
86
|
"group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent",
|
|
68
87
|
"bg-clip-padding data-[state=active]:border-input data-[state=active]:bg-background data-[state=active]:text-foreground focus-visible:data-[state=active]:border-ring dark:data-[state=active]:bg-accent/40 dark:data-[state=active]:text-foreground",
|
|
69
88
|
"after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100",
|
|
89
|
+
(size ?? listSize) === "touch" && "min-h-touch-target min-w-touch-target",
|
|
70
90
|
className
|
|
71
91
|
)}
|
|
72
92
|
{...props}
|