mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-03 12:55:41 -05:00
skin primitives
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
# Skin reference (data for the docs lane)
|
||||
|
||||
Source of truth: `resources/scripts/themes/primitives.ts` (`UiPrimitives`, `UI_PRIMITIVES`), the registry in
|
||||
`resources/scripts/themes/skins.ts`, classic's recipes in `resources/scripts/themes/classic/skins/*.ts`.
|
||||
|
||||
## API (`@pterodactyl/sdk/theme`)
|
||||
|
||||
- `defineTheme({ ui })`: `ui` is `ThemeSkins`, keyed by primitive name.
|
||||
- `skin(name, skin)` types a skin; `skin(name, (parent) => skin)` extends the layers below. The function form must go
|
||||
through `skin()`: a bare function is read as a replacement component.
|
||||
- Skin: `{ [part]: recipe }`. A recipe is a string, a cva recipe `{ base, variants, compoundVariants, defaultVariants }`,
|
||||
or `(state) => string`. Variant keys are state keys; booleans use `'true'`/`'false'`.
|
||||
- `parent` in the function form has every part resolved: `parent.root(state)` returns the classes below.
|
||||
- `useSkin(name, state)` returns a binding: `ui(part, className?, partState?)` gives
|
||||
`{ className, 'data-ui', 'data-part', data-* }` to spread; `ui.classes(part, className?, partState?)` gives the string.
|
||||
- Types: `ThemeSkins`, `Skin<N>`, `CompleteSkin<N>`, `CompleteSkins`, `SkinRecipe<S>`, `SkinRecipeConfig<S>`,
|
||||
`SkinCompoundVariant<S>`, `ResolvedSkin<N>`, `SkinExtension<N>`, `SkinDefinition<N>`, `SkinBinding<N>`,
|
||||
`SkinPartProps`, `SkinClassName`, `SkinPart<N>`, `PrimitiveName`, `PrimitiveState<N>`, `PrimitiveProps<N>`,
|
||||
`ReplaceableName`, `UiPrimitives`, `UiTone`, `NoState`, `SkinStateMap`, `SkinStateValue`, `PrimitiveMeta<N>`;
|
||||
value `UI_PRIMITIVES` (parts and `replaceable` per primitive).
|
||||
|
||||
## Rules
|
||||
|
||||
- Layers: classic, then the theme chain parent first. For each part the topmost recipe wins and replaces the one below
|
||||
wholesale; nothing merges. Parts a skin leaves out keep the recipe below.
|
||||
- The call-site `className` is appended with `cn()` (tailwind-merge), so it wins conflicts.
|
||||
- Every part renders `data-ui="<kebab-name>"` and `data-part="<part>"`. The root also renders a `data-<key>` per state
|
||||
value (camelCase keys become kebab case: `richLabel` → `data-rich-label`). `true` renders as an empty attribute,
|
||||
`false`/unset render nothing. A part given its own state (Dialog `icon`, Empty `media`, Pagination `page`) renders
|
||||
that state on itself.
|
||||
- Parts marked "classes only" below are passed as `className` to another primitive or element and carry no attributes.
|
||||
- Presentational primitives can be replaced by a component receiving the identical props. The topmost replacement wins;
|
||||
skins of all layers still resolve for the core components. A replacement must not render the primitive it replaces.
|
||||
- Base UI primitives (and the other skin-only ones) cannot be replaced: a component there is a type error, and at
|
||||
runtime it is ignored with a dev warning. Unknown primitive names and unknown parts are ignored with a dev warning.
|
||||
- Resolution is memoised per primitive per layer stack; a recipe or extension that throws is skipped and logged.
|
||||
|
||||
## Primitives
|
||||
|
||||
`root` gets the bound state as `data-*`. Replaceable = may be a component.
|
||||
|
||||
| Primitive | Parts | State (→ `data-*`) | Replaceable |
|
||||
|---|---|---|---|
|
||||
| Alert | root, icon, body, title, content | `type`: success, info, warning, danger | yes |
|
||||
| Avatar | root | `variant`: beam, marble, pixel, sunset, ring, bauhaus | yes |
|
||||
| Badge | root | `tone`: neutral, success, warning, danger, info, accent; `size`: sm, md; `variant`: solid, soft | yes |
|
||||
| Button | root, spinner, label | `color`: primary, grey, green, red, orange; `size`: xsmall, small, large, xlarge; `secondary`; `loading` | yes |
|
||||
| Card | root, header, title, icon, actions, body | `titled` (has a header); `actions`; `loading` | yes |
|
||||
| Checkbox | root, indicator | none (Base UI sets `data-checked`, `data-indeterminate`, `data-disabled`) | no |
|
||||
| Code | root | `dark` | no |
|
||||
| CopyOnClick | root (toast), status, message, target (classes only, added to the clicked child) | `status`: copied, failed | no |
|
||||
| Dialog | backdrop, viewport, container, root (popup), body, content, header, heading, title, description, spacer, footer, close, closeButton (classes only, on a Button), closeIcon, icon, iconGlyph | `described`; `type` on `icon`: danger, warning, success, info | no |
|
||||
| DropdownMenu | trigger, positioner, root (popup) | `context` (ContextDropdownMenu) | no |
|
||||
| DropdownMenuItem | root, icon, glyph, text, label, description | `danger`; `described` | no |
|
||||
| Empty | root, header, media, title, description, content | `size`: default, compact; `variant` on `media`: default, icon | yes (root) |
|
||||
| FileInput | root | none | no |
|
||||
| Input | root | `light`; `error` | no |
|
||||
| Label | root | `light` | no |
|
||||
| ListRow | root | `interactive` | yes |
|
||||
| NewButton | root (classes only, on the Button), content, icon | `link` (NewLinkButton) | no |
|
||||
| NumberInput | root (NumberField), input | `light`; `error` | no |
|
||||
| PageHeading | root, text, title, description, actions | none | yes |
|
||||
| Pagination | root, page (classes only, on each page Button) | `current` on `page` | no |
|
||||
| ProgressBar | root (track), indicator | `variant`: meter, page; `tone`: as Badge | yes |
|
||||
| Select | root (input group), input, trigger, positioner, popup, list, item, itemLabel, indicator, empty, group, groupLabel, summary, preview | `error`; `multiple`; `selected`; `richLabel`; `searching` | no |
|
||||
| Spinner | root, container (when centered) | `size`: small, base, large; `blue`; `centered` | yes |
|
||||
| SpinnerOverlay | root, text | `fixed` | no |
|
||||
| Switch | root, control, thumb, text, label (classes only, on the Label), description | `described`; `position`: start, end | no |
|
||||
| Table | root, empty, scroller, table, head, headerRow, headerCell, body, row, cell | `fetching` | no |
|
||||
| TextArea | root | `light`; `error` | no |
|
||||
| Tooltip | root, arrow | `side`: top, right, bottom, left; `arrow` | no |
|
||||
|
||||
## Components and props (`@pterodactyl/sdk`)
|
||||
|
||||
Button (`ButtonProps`, `ButtonColor`, `ButtonSize`; `Button.Text`, `Button.Danger`), LinkButton, RouterLinkButton,
|
||||
NewButton/NewLinkButton (`NewButtonProps`, `NewLinkButtonProps`), Input (`InputProps`), TextArea (`TextAreaProps`),
|
||||
NumberInput (`NumberInputProps`), FileInput (`FileInputProps`), Select (`SelectProps`), Checkbox (`CheckboxProps`),
|
||||
Switch (`SwitchProps`), Label (`LabelProps`), Dialog (`DialogProps`, `DialogIconProps`; `Dialog.Footer`, `Dialog.Icon`,
|
||||
`Dialog.Confirm`), Alert (`AlertProps`, `AlertType`), Tooltip (`TooltipProps`), DropdownMenu / DropdownMenuItem /
|
||||
ContextDropdownMenu (`DropdownMenuProps`, `DropdownMenuItemProps`, `ContextDropdownMenuProps`), Table (`TableProps`),
|
||||
Pagination (`PaginationProps`), Empty + EmptyHeader/EmptyMedia/EmptyTitle/EmptyDescription/EmptyContent (`EmptyProps`,
|
||||
`EmptySize`, `EmptyMediaVariant`), Spinner (`SpinnerProps`), SpinnerOverlay (`SpinnerOverlayProps`), Avatar
|
||||
(`AvatarProps`), ProgressBar (`ProgressBarProps`), Code (`CodeProps`), CopyOnClick (`CopyOnClickProps`), Card
|
||||
(`CardProps`), ListRow (`ListRowProps`), Badge (`BadgeProps`), PageHeading (`PageHeadingProps`). ContentBox and
|
||||
TitledGreyBox remain as thin wrappers over Card.
|
||||
|
||||
## Recipes
|
||||
|
||||
```tsx
|
||||
export default defineTheme({
|
||||
ui: {
|
||||
// Replaces Button's root recipe; spinner and label keep classic's.
|
||||
Button: skin('Button', {
|
||||
root: {
|
||||
base: 'inline-flex h-9 items-center rounded-full px-4 font-medium',
|
||||
variants: { color: { primary: 'bg-primary text-primary-foreground hover:bg-primary/90' } },
|
||||
compoundVariants: [{ secondary: true, color: 'primary', class: 'bg-transparent text-primary' }],
|
||||
},
|
||||
}),
|
||||
// Builds on the classes below.
|
||||
Card: skin('Card', (parent) => ({ root: (state) => `${parent.root(state)} backdrop-blur-xl bg-card/60` })),
|
||||
// Presentational primitives can be components with the same props.
|
||||
Badge: AuroraBadge,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
Classic's normalised variants: plain `hover:`/`active:` guarded with `not-disabled:` on Button
|
||||
(`hover:not-disabled:bg-primary/80`), `data-checked:`/`data-highlighted:`/`data-starting-style:` instead of
|
||||
`data-[…]:`, `z-9999`, and `(--var)` shorthands. Rendered classes are otherwise unchanged
|
||||
(`resources/scripts/themes/classicClasses.spec.tsx`).
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
export type AvatarVariant = 'beam' | 'marble' | 'pixel' | 'sunset' | 'ring' | 'bauhaus';
|
||||
export interface AvatarProps {
|
||||
/** Seeds the generated pattern; the panel uses a user's UUID. */
|
||||
name: string;
|
||||
size?: number | string;
|
||||
variant?: AvatarVariant;
|
||||
square?: boolean;
|
||||
title?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
declare const Avatar: ((props: AvatarProps) => import("react").ReactElement) & {
|
||||
User: {
|
||||
(props: Omit<AvatarProps, "name">): import("react").JSX.Element;
|
||||
displayName: string;
|
||||
};
|
||||
};
|
||||
export default Avatar;
|
||||
@@ -0,0 +1,13 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import type React from 'react';
|
||||
import { type UiTone } from "../../themes/skins.js";
|
||||
export type BadgeSize = 'sm' | 'md';
|
||||
/** `solid` fills the badge with its tone; `soft` tints it. */
|
||||
export type BadgeVariant = 'solid' | 'soft';
|
||||
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
||||
tone?: UiTone;
|
||||
size?: BadgeSize;
|
||||
variant?: BadgeVariant;
|
||||
}
|
||||
declare const Badge: (props: BadgeProps) => React.ReactElement;
|
||||
export default Badge;
|
||||
+12
-11
@@ -1,33 +1,34 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
export type ButtonColor = 'green' | 'red' | 'orange' | 'primary' | 'grey';
|
||||
export type ButtonSize = 'xsmall' | 'small' | 'large' | 'xlarge';
|
||||
interface Props {
|
||||
isLoading?: boolean;
|
||||
size?: 'xsmall' | 'small' | 'large' | 'xlarge';
|
||||
color?: 'green' | 'red' | 'orange' | 'primary' | 'grey';
|
||||
size?: ButtonSize;
|
||||
color?: ButtonColor;
|
||||
isSecondary?: boolean;
|
||||
}
|
||||
declare const buttonClassName: ({ color, size, isSecondary, className, }: Omit<Props, "isLoading"> & {
|
||||
type StyleableProps = Omit<Props, 'isLoading'>;
|
||||
/** The root classes of a button, for elements styled as one outside a component. */
|
||||
declare const buttonClassName: ({ className, ...props }: StyleableProps & {
|
||||
className?: string;
|
||||
}) => string;
|
||||
type StyleableProps = Omit<Props, 'isLoading'>;
|
||||
type ButtonStyleProps<E extends React.ElementType = 'button'> = {
|
||||
as?: E;
|
||||
ref?: React.ComponentPropsWithRef<E>['ref'];
|
||||
} & StyleableProps & Omit<React.ComponentPropsWithoutRef<E>, keyof StyleableProps | 'as'>;
|
||||
/** Any element, styled as a button. */
|
||||
declare const ButtonStyle: <E extends React.ElementType = "button">({ as, color, size, isSecondary, className, ref, ...props }: ButtonStyleProps<E>) => React.JSX.Element;
|
||||
type ComponentProps = Omit<React.ComponentPropsWithRef<'button'>, keyof Props> & Props;
|
||||
export type ButtonProps = Omit<React.ComponentPropsWithRef<'button'>, keyof Props> & Props;
|
||||
/** Defaults to `type="button"`; `isLoading` shows a spinner and disables the button. */
|
||||
declare const Button: {
|
||||
({ children, isLoading, disabled, type, ref, ...props }: ComponentProps): React.JSX.Element;
|
||||
displayName: string;
|
||||
};
|
||||
declare const Button: (props: ButtonProps) => React.ReactElement;
|
||||
declare const TextButton: {
|
||||
({ ref, ...props }: ComponentProps): React.JSX.Element;
|
||||
({ ref, ...props }: ButtonProps): React.JSX.Element;
|
||||
displayName: string;
|
||||
};
|
||||
declare const DangerButton: {
|
||||
({ ref, ...props }: ComponentProps): React.JSX.Element;
|
||||
({ ref, ...props }: ButtonProps): React.JSX.Element;
|
||||
displayName: string;
|
||||
};
|
||||
declare const ButtonWithVariants: typeof Button & {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import type React from 'react';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
export interface CardProps {
|
||||
/** A string renders as the card's heading; any other node replaces it. */
|
||||
title?: React.ReactNode;
|
||||
/** Shown before a string title. */
|
||||
icon?: LucideIcon;
|
||||
/** Controls placed at the end of the header. */
|
||||
actions?: React.ReactNode;
|
||||
/** Covers the card with a spinner. */
|
||||
loading?: boolean;
|
||||
className?: string;
|
||||
/** Classes for the body of a card with a header. */
|
||||
bodyClassName?: string;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
declare const Card: (props: CardProps) => React.ReactElement;
|
||||
export default Card;
|
||||
@@ -0,0 +1,8 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
export interface CodeProps {
|
||||
dark?: boolean | undefined;
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
export default function Code({ dark, className, children }: CodeProps): React.JSX.Element;
|
||||
@@ -5,5 +5,6 @@ type Props = Readonly<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElemen
|
||||
borderColor?: string;
|
||||
showLoadingOverlay?: boolean;
|
||||
}>;
|
||||
/** A section title above a plain `Card`. */
|
||||
declare const ContentBox: ({ title, borderColor, showLoadingOverlay, children, ...props }: Props) => React.JSX.Element;
|
||||
export default ContentBox;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
interface CopyOnClickProps {
|
||||
export interface CopyOnClickProps {
|
||||
text: string | number | null | undefined;
|
||||
showInNotification?: boolean;
|
||||
children: React.ReactNode;
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
type Props<E extends React.ElementType = 'label'> = {
|
||||
export type LabelProps<E extends React.ElementType = 'label'> = {
|
||||
as?: E;
|
||||
isLight?: boolean;
|
||||
} & Omit<React.ComponentPropsWithoutRef<E>, 'as' | 'isLight'>;
|
||||
declare const Label: <E extends React.ElementType = "label">({ as, isLight, className, ...props }: Props<E>) => React.JSX.Element;
|
||||
declare const Label: <E extends React.ElementType = "label">({ as, isLight, className, ...props }: LabelProps<E>) => React.JSX.Element;
|
||||
export default Label;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
import { type PanelDestination } from "../../sdk/navigation.js";
|
||||
export interface ListRowProps extends React.HTMLAttributes<HTMLElement> {
|
||||
as?: 'div' | 'li' | 'article';
|
||||
/** Renders the row as a link to the destination. */
|
||||
destination?: PanelDestination;
|
||||
exact?: boolean;
|
||||
/** Hover and press feedback; on for links and clickable rows unless set. */
|
||||
interactive?: boolean;
|
||||
}
|
||||
declare const ListRow: (props: ListRowProps) => React.ReactElement;
|
||||
export default ListRow;
|
||||
+7
-5
@@ -1,15 +1,17 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import type * as React from 'react';
|
||||
import { type LucideIcon } from 'lucide-react';
|
||||
import Button, { RouterLinkButton } from "./Button.js";
|
||||
import { RouterLinkButton, type ButtonProps } from "./Button.js";
|
||||
interface IconProps {
|
||||
/** Replaces the Plus for sibling toolbar actions such as Upload. */
|
||||
icon?: LucideIcon;
|
||||
}
|
||||
export type NewButtonProps = ButtonProps & IconProps;
|
||||
/** The panel's "create" action: a Plus icon and a sentence-case label such as "New node". */
|
||||
export declare function NewButton({ icon, className, children, ...props }: React.ComponentProps<typeof Button> & IconProps): React.JSX.Element;
|
||||
/** `NewButton` for actions that navigate to a create page. */
|
||||
export declare function NewLinkButton({ icon, className, children, ...props }: Omit<React.ComponentProps<typeof RouterLinkButton>, 'children'> & IconProps & {
|
||||
export declare function NewButton({ icon, className, children, ...props }: NewButtonProps): React.JSX.Element;
|
||||
export type NewLinkButtonProps = Omit<React.ComponentProps<typeof RouterLinkButton>, 'children'> & IconProps & {
|
||||
children: React.ReactNode;
|
||||
}): React.JSX.Element;
|
||||
};
|
||||
/** `NewButton` for actions that navigate to a create page. */
|
||||
export declare function NewLinkButton({ icon, className, children, ...props }: NewLinkButtonProps): React.JSX.Element;
|
||||
export {};
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
interface Props {
|
||||
import type React from 'react';
|
||||
export interface PageHeadingProps {
|
||||
title: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
actions?: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
export default function PageHeading({ title, description, actions, className }: Props): React.JSX.Element;
|
||||
export {};
|
||||
declare const PageHeading: (props: PageHeadingProps) => React.ReactElement;
|
||||
export default PageHeading;
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ interface RenderFuncProps<T> {
|
||||
isLastPage: boolean;
|
||||
isFirstPage: boolean;
|
||||
}
|
||||
interface Props<T> {
|
||||
export interface PaginationProps<T> {
|
||||
data: GeneratedPaginatedResult<T>;
|
||||
showGoToLast?: boolean;
|
||||
showGoToFirst?: boolean;
|
||||
@@ -24,5 +24,5 @@ interface GeneratedPaginatedResult<T> {
|
||||
};
|
||||
};
|
||||
}
|
||||
declare function Pagination<T>({ data, onPageSelect, children }: Props<T>): React.JSX.Element;
|
||||
declare function Pagination<T>({ data, onPageSelect, children }: PaginationProps<T>): React.JSX.Element;
|
||||
export default Pagination;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import { type UiTone } from "../../themes/skins.js";
|
||||
/** `meter` shows a value in a track; `page` is the loading bar along the top of the page. */
|
||||
export type ProgressBarVariant = 'meter' | 'page';
|
||||
export interface ProgressBarProps {
|
||||
/** Percent complete from 0 to 100; `null` shows the track alone. */
|
||||
value: number | null;
|
||||
variant?: ProgressBarVariant;
|
||||
/** Defaults to `accent` for the page bar and `neutral` otherwise. */
|
||||
tone?: UiTone;
|
||||
/** Names a meter for assistive technology. */
|
||||
label?: string;
|
||||
className?: string;
|
||||
}
|
||||
declare const ProgressBar: (props: ProgressBarProps) => import("react").ReactElement;
|
||||
export default ProgressBar;
|
||||
/** The page loading bar, driven by the panel's HTTP requests. */
|
||||
export declare function HttpProgressBar(): import("react").JSX.Element;
|
||||
+3
-3
@@ -1,16 +1,16 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
export type SpinnerSize = 'small' | 'base' | 'large';
|
||||
interface Props {
|
||||
export interface SpinnerProps {
|
||||
size?: SpinnerSize;
|
||||
centered?: boolean;
|
||||
isBlue?: boolean;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
type SpinnerComponentType = ((props: Props) => React.JSX.Element) & {
|
||||
type SpinnerComponentType = ((props: SpinnerProps) => React.JSX.Element) & {
|
||||
displayName?: string;
|
||||
Size: Record<'SMALL' | 'BASE' | 'LARGE', SpinnerSize>;
|
||||
Suspense: ((props: Props) => React.JSX.Element) & {
|
||||
Suspense: ((props: SpinnerProps) => React.JSX.Element) & {
|
||||
displayName?: string;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
import type { SpinnerSize } from "./Spinner.js";
|
||||
interface Props {
|
||||
export interface SpinnerOverlayProps {
|
||||
visible: boolean;
|
||||
fixed?: boolean;
|
||||
size?: SpinnerSize;
|
||||
backgroundOpacity?: number;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
declare const SpinnerOverlay: ({ size, fixed, visible, backgroundOpacity, children }: Props) => React.JSX.Element | null;
|
||||
declare const SpinnerOverlay: ({ size, fixed, visible, backgroundOpacity, children }: SpinnerOverlayProps) => React.JSX.Element | null;
|
||||
export default SpinnerOverlay;
|
||||
|
||||
@@ -8,5 +8,6 @@ interface Props {
|
||||
contentClassName?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
/** A `Card` with a header. */
|
||||
declare const TitledGreyBox: ({ icon, title, children, className, contentClassName }: Props) => React.JSX.Element;
|
||||
export default TitledGreyBox;
|
||||
|
||||
+3
-3
@@ -1,11 +1,11 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import React from 'react';
|
||||
export type AlertType = 'success' | 'info' | 'warning' | 'danger';
|
||||
interface AlertProps {
|
||||
export interface AlertProps {
|
||||
type: AlertType;
|
||||
title?: React.ReactNode;
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
export default function Alert({ type, title, className, children }: AlertProps): React.JSX.Element;
|
||||
export {};
|
||||
declare const Alert: (props: AlertProps) => React.ReactElement;
|
||||
export default Alert;
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
export { default as Alert } from "./Alert.js";
|
||||
export type { AlertType } from "./Alert.js";
|
||||
export type { AlertProps, AlertType } from "./Alert.js";
|
||||
|
||||
@@ -25,6 +25,8 @@ export interface RenderDialogProps extends DialogProps {
|
||||
}
|
||||
|
||||
export interface DialogContextType {
|
||||
setIcon: Callback<React.ReactNode>;
|
||||
setIcon: Callback<DialogIconProps | undefined>;
|
||||
setIconPosition: Callback<IconPosition>;
|
||||
/** The state the dialog's skin reads, for parts rendered by its children. */
|
||||
described: boolean;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import React from 'react';
|
||||
import { Menu } from '@base-ui/react/menu';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
interface DropdownMenuProps {
|
||||
export interface DropdownMenuProps {
|
||||
/** Rendered inside the trigger `<button>`. */
|
||||
triggerContent: React.ReactNode;
|
||||
triggerClassName?: string;
|
||||
@@ -11,7 +11,7 @@ interface DropdownMenuProps {
|
||||
className?: string;
|
||||
}
|
||||
declare function DropdownMenu({ triggerContent, triggerClassName, openOnHover, children, className }: DropdownMenuProps): React.JSX.Element;
|
||||
interface ContextDropdownMenuProps {
|
||||
export interface ContextDropdownMenuProps {
|
||||
className?: string;
|
||||
menuClassName?: string;
|
||||
children: React.ReactNode;
|
||||
@@ -19,13 +19,14 @@ interface ContextDropdownMenuProps {
|
||||
}
|
||||
/** Opens `items` at the cursor on right-click or long-press over `children`. */
|
||||
export declare function ContextDropdownMenu({ className, menuClassName, children, items }: ContextDropdownMenuProps): React.JSX.Element;
|
||||
interface ItemProps extends React.ComponentProps<typeof Menu.Item> {
|
||||
export interface DropdownMenuItemProps extends Omit<React.ComponentProps<typeof Menu.Item>, 'className'> {
|
||||
className?: string;
|
||||
icon?: LucideIcon;
|
||||
danger?: boolean;
|
||||
description?: React.ReactNode;
|
||||
}
|
||||
/** An item for either DropdownMenu or ContextDropdownMenu. */
|
||||
export declare function DropdownMenuItem({ icon, danger, description, className, children, ...props }: ItemProps): React.JSX.Element;
|
||||
export declare function DropdownMenuItem({ icon, danger, description, className, children, ...props }: DropdownMenuItemProps): React.JSX.Element;
|
||||
declare const DropdownMenuWithItems: typeof DropdownMenu & {
|
||||
Item: typeof DropdownMenuItem;
|
||||
};
|
||||
|
||||
+6
-4
@@ -9,10 +9,12 @@ interface ThemeProps {
|
||||
type WithStringClassName<TProps> = Omit<TProps, 'className'> & {
|
||||
className?: string;
|
||||
};
|
||||
type TextInputProps = ThemeProps & WithStringClassName<React.ComponentProps<typeof BaseInput>>;
|
||||
type NumberInputProps = ThemeProps & Pick<React.ComponentProps<typeof NumberField.Root>, 'value' | 'onValueChange' | 'min' | 'max' | 'step' | 'format' | 'disabled'> & WithStringClassName<Omit<React.ComponentProps<typeof NumberField.Input>, 'value' | 'onChange' | 'disabled'>>;
|
||||
export type TextInputProps = ThemeProps & WithStringClassName<React.ComponentProps<typeof BaseInput>>;
|
||||
export type TextAreaProps = ThemeProps & React.ComponentProps<'textarea'>;
|
||||
export type NumberInputProps = ThemeProps & Pick<React.ComponentProps<typeof NumberField.Root>, 'value' | 'onValueChange' | 'min' | 'max' | 'step' | 'format' | 'disabled'> & WithStringClassName<Omit<React.ComponentProps<typeof NumberField.Input>, 'value' | 'onChange' | 'disabled'>>;
|
||||
export type FileInputProps = Omit<React.ComponentProps<'input'>, 'type'>;
|
||||
export declare const TextInput: ({ $isLight, $hasError, className, ...props }: TextInputProps) => React.JSX.Element;
|
||||
export declare const FileInput: ({ className, ...props }: Omit<React.ComponentProps<"input">, "type">) => React.JSX.Element;
|
||||
export declare const TextArea: ({ $isLight, $hasError, className, ...props }: ThemeProps & React.ComponentProps<"textarea">) => React.JSX.Element;
|
||||
export declare const FileInput: ({ className, ...props }: FileInputProps) => React.JSX.Element;
|
||||
export declare const TextArea: ({ $isLight, $hasError, className, ...props }: TextAreaProps) => React.JSX.Element;
|
||||
export declare const NumberInput: ({ $isLight, $hasError, className, value, onValueChange, min, max, step, format, disabled, ...props }: NumberInputProps) => React.JSX.Element;
|
||||
export {};
|
||||
|
||||
+9
-3
@@ -1,10 +1,16 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import type * as React from 'react';
|
||||
declare function Empty({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
||||
import * as React from 'react';
|
||||
export type EmptySize = 'default' | 'compact';
|
||||
export type EmptyMediaVariant = 'default' | 'icon';
|
||||
export type EmptyProps = React.ComponentProps<'div'> & {
|
||||
/** `compact` tightens the spacing for an `Empty` inside a card, table or dialog. */
|
||||
size?: EmptySize;
|
||||
};
|
||||
declare const Empty: (props: EmptyProps) => React.ReactElement;
|
||||
declare function EmptyHeader({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
||||
/** `icon` frames a single icon in a tile; `default` leaves the media unframed. */
|
||||
declare function EmptyMedia({ className, variant, ...props }: React.ComponentProps<'div'> & {
|
||||
variant?: 'default' | 'icon';
|
||||
variant?: EmptyMediaVariant;
|
||||
}): React.JSX.Element;
|
||||
declare function EmptyTitle({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
||||
declare function EmptyDescription({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
||||
|
||||
Vendored
+15
-10
@@ -8,28 +8,33 @@ import type { UserData as SdkUser } from "../api/account/types.js";
|
||||
import type { SiteSettings as SdkSiteSettings } from "../api/settings/types.js";
|
||||
import type { Server as SdkServer } from "../api/server/types.js";
|
||||
import { SocketEvent } from "../components/server/events.js";
|
||||
export { default as Button } from "../components/elements/Button.js";
|
||||
export { default as Spinner } from "../components/elements/Spinner.js";
|
||||
export { default as Button, LinkButton, RouterLinkButton, type ButtonColor, type ButtonProps, type ButtonSize, } from "../components/elements/Button.js";
|
||||
export { default as Spinner, type SpinnerProps, type SpinnerSize } from "../components/elements/Spinner.js";
|
||||
export { default as Icon } from "../components/elements/Icon.js";
|
||||
export { default as NamedIcon, loadIconNames, type NamedIconProps } from "../components/elements/NamedIcon.js";
|
||||
export { default as Can } from "../components/elements/Can.js";
|
||||
export { default as Card, type CardProps } from "../components/elements/Card.js";
|
||||
export { default as ListRow, type ListRowProps } from "../components/elements/ListRow.js";
|
||||
export { default as Badge, type BadgeProps, type BadgeSize, type BadgeVariant } from "../components/elements/Badge.js";
|
||||
export { default as ProgressBar, type ProgressBarProps, type ProgressBarVariant, } from "../components/elements/ProgressBar.js";
|
||||
export { default as Code, type CodeProps } from "../components/elements/Code.js";
|
||||
export { default as ContentBox } from "../components/elements/ContentBox.js";
|
||||
export { default as PageContentBlock } from "../components/elements/PageContentBlock.js";
|
||||
export { default as ServerContentBlock } from "../components/elements/ServerContentBlock.js";
|
||||
export { default as TitledGreyBox } from "../components/elements/TitledGreyBox.js";
|
||||
export { default as CopyOnClick } from "../components/elements/CopyOnClick.js";
|
||||
export { default as CopyOnClick, type CopyOnClickProps } from "../components/elements/CopyOnClick.js";
|
||||
export { default as ScreenBlock, ServerError, NotFound } from "../components/elements/ScreenBlock.js";
|
||||
export { default as Label } from "../components/elements/Label.js";
|
||||
export { default as PageHeading } from "../components/elements/PageHeading.js";
|
||||
export { NewButton, NewLinkButton } from "../components/elements/NewButton.js";
|
||||
export { default as SpinnerOverlay } from "../components/elements/SpinnerOverlay.js";
|
||||
export { TextInput as Input, TextArea, NumberInput } from "../components/form/controls.js";
|
||||
export { default as Label, type LabelProps } from "../components/elements/Label.js";
|
||||
export { default as PageHeading, type PageHeadingProps } from "../components/elements/PageHeading.js";
|
||||
export { NewButton, NewLinkButton, type NewButtonProps, type NewLinkButtonProps, } from "../components/elements/NewButton.js";
|
||||
export { default as SpinnerOverlay, type SpinnerOverlayProps } from "../components/elements/SpinnerOverlay.js";
|
||||
export { TextInput as Input, TextArea, NumberInput, FileInput, type TextInputProps as InputProps, type TextAreaProps, type NumberInputProps, type FileInputProps, } from "../components/form/controls.js";
|
||||
export { Form, useAppForm, useFieldContext, useFormContext, type AppForm, type SelectOption } from "../components/form/index.js";
|
||||
export { default as Select, type SelectGroup, type SelectProps, type SelectValue } from "../components/ui/Select.js";
|
||||
export { default as Checkbox, type CheckboxProps } from "../components/ui/Checkbox.js";
|
||||
export { default as Switch, type SwitchProps } from "../components/ui/Switch.js";
|
||||
export { Alert } from "../components/elements/alert/index.js";
|
||||
export { Dialog } from "../components/elements/dialog/index.js";
|
||||
export { Alert, type AlertProps, type AlertType } from "../components/elements/alert/index.js";
|
||||
export { Dialog, type DialogIconProps, type RenderDialogProps as DialogProps } from "../components/elements/dialog/index.js";
|
||||
export { toast } from 'sonner';
|
||||
export * from "./ui.js";
|
||||
export { default as http, httpErrorToHuman } from "../api/http.js";
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
export { defineTheme, useTheme, useThemeSettings, type ThemeDefinition, type ThemeIcon, type ThemeIcons, type ThemeScheme, type ThemeSettings, type ThemeSettingValue, type ThemeState, } from "../views/theme.js";
|
||||
export { skin, type ThemeSkins } from "../themes/skins.js";
|
||||
export { skin, useSkin, UI_PRIMITIVES, type CompleteSkin, type CompleteSkins, type NoState, type PrimitiveMeta, type PrimitiveName, type PrimitiveProps, type PrimitiveState, type ReplaceableName, type ResolvedSkin, type Skin, type SkinBinding, type SkinClassName, type SkinCompoundVariant, type SkinDefinition, type SkinExtension, type SkinPart, type SkinPartProps, type SkinRecipe, type SkinRecipeConfig, type SkinStateMap, type SkinStateValue, type ThemeSkins, type UiPrimitives, type UiTone, } from "../themes/skins.js";
|
||||
export { View, ViewFixtureProvider, type ViewElementProps, type ViewFixtureSelection } from "../views/View.js";
|
||||
export { lazyView } from "../views/lazy.js";
|
||||
export { Main } from "../views/a11y.js";
|
||||
|
||||
Vendored
+4
-13
@@ -1,8 +1,9 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import { type DOMAttributes, type ReactElement, type ReactNode, type RefAttributes } from 'react';
|
||||
export { default as DropdownMenu, DropdownMenuItem, ContextDropdownMenu, } from "../components/elements/dropdown/DropdownMenu.js";
|
||||
export { default as Pagination } from "../components/elements/Pagination.js";
|
||||
export { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../components/ui/empty.js";
|
||||
export { default as DropdownMenu, DropdownMenuItem, ContextDropdownMenu, type ContextDropdownMenuProps, type DropdownMenuItemProps, type DropdownMenuProps, } from "../components/elements/dropdown/DropdownMenu.js";
|
||||
export { default as Pagination, type PaginationProps } from "../components/elements/Pagination.js";
|
||||
export { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, type EmptyMediaVariant, type EmptyProps, type EmptySize, } from "../components/ui/empty.js";
|
||||
export { default as Avatar, type AvatarProps, type AvatarVariant } from "../components/Avatar.js";
|
||||
export interface TableColumn<TRow> {
|
||||
id: string;
|
||||
label: ReactNode;
|
||||
@@ -28,13 +29,3 @@ export interface TooltipProps {
|
||||
placement?: 'top' | 'bottom' | 'left' | 'right';
|
||||
}
|
||||
export declare function Tooltip(props: TooltipProps): ReactElement;
|
||||
export interface AvatarProps {
|
||||
/** Seeds the generated pattern; the panel uses a user's UUID. */
|
||||
name: string;
|
||||
size?: number | string;
|
||||
variant?: 'beam' | 'marble' | 'pixel' | 'sunset' | 'ring' | 'bauhaus';
|
||||
square?: boolean;
|
||||
title?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
export declare function Avatar(props: AvatarProps): ReactElement;
|
||||
|
||||
+353
@@ -0,0 +1,353 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
import type { AlertProps, AlertType } from "../components/elements/alert/Alert.js";
|
||||
import type { AvatarProps, AvatarVariant } from "../components/Avatar.js";
|
||||
import type { BadgeProps, BadgeSize, BadgeVariant } from "../components/elements/Badge.js";
|
||||
import type { ButtonColor, ButtonProps, ButtonSize } from "../components/elements/Button.js";
|
||||
import type { CardProps } from "../components/elements/Card.js";
|
||||
import type { DialogIconProps } from "../components/elements/dialog/types.js";
|
||||
import type { EmptyMediaVariant, EmptyProps, EmptySize } from "../components/ui/empty.js";
|
||||
import type { ListRowProps } from "../components/elements/ListRow.js";
|
||||
import type { PageHeadingProps } from "../components/elements/PageHeading.js";
|
||||
import type { ProgressBarProps, ProgressBarVariant } from "../components/elements/ProgressBar.js";
|
||||
import type { SpinnerProps, SpinnerSize } from "../components/elements/Spinner.js";
|
||||
/** The colour roles shared by tone variants (Badge, ProgressBar). */
|
||||
export type UiTone = 'neutral' | 'success' | 'warning' | 'danger' | 'info' | 'accent';
|
||||
type ControlState = {
|
||||
light: boolean;
|
||||
error: boolean;
|
||||
};
|
||||
/** A primitive whose recipes read no state. */
|
||||
export type NoState = {
|
||||
readonly [key: string]: never;
|
||||
};
|
||||
/**
|
||||
* Every UI primitive: the parts a skin styles, the state its recipes read (rendered as `data-*` on
|
||||
* the root, or on a part given its own state), and for presentational primitives the props a
|
||||
* replacement component receives.
|
||||
*/
|
||||
export interface UiPrimitives {
|
||||
Alert: {
|
||||
parts: 'root' | 'icon' | 'body' | 'title' | 'content';
|
||||
state: {
|
||||
type: AlertType;
|
||||
};
|
||||
props: AlertProps;
|
||||
};
|
||||
Avatar: {
|
||||
parts: 'root';
|
||||
state: {
|
||||
variant: AvatarVariant;
|
||||
};
|
||||
props: AvatarProps;
|
||||
};
|
||||
Badge: {
|
||||
parts: 'root';
|
||||
state: {
|
||||
tone: UiTone;
|
||||
size: BadgeSize;
|
||||
variant: BadgeVariant;
|
||||
};
|
||||
props: BadgeProps;
|
||||
};
|
||||
Button: {
|
||||
parts: 'root' | 'spinner' | 'label';
|
||||
state: {
|
||||
color: ButtonColor;
|
||||
size: ButtonSize;
|
||||
secondary: boolean;
|
||||
loading: boolean;
|
||||
};
|
||||
props: ButtonProps;
|
||||
};
|
||||
Card: {
|
||||
parts: 'root' | 'header' | 'title' | 'icon' | 'actions' | 'body';
|
||||
state: {
|
||||
titled: boolean;
|
||||
actions: boolean;
|
||||
loading: boolean;
|
||||
};
|
||||
props: CardProps;
|
||||
};
|
||||
Checkbox: {
|
||||
parts: 'root' | 'indicator';
|
||||
state: NoState;
|
||||
};
|
||||
Code: {
|
||||
parts: 'root';
|
||||
state: {
|
||||
dark: boolean;
|
||||
};
|
||||
};
|
||||
/** `target` is added to the clicked child; the other parts are the status toast. */
|
||||
CopyOnClick: {
|
||||
parts: 'root' | 'status' | 'message' | 'target';
|
||||
state: {
|
||||
status?: 'copied' | 'failed';
|
||||
};
|
||||
};
|
||||
Dialog: {
|
||||
parts: 'backdrop' | 'viewport' | 'container' | 'root' | 'body' | 'content' | 'header' | 'heading' | 'title' | 'description' | 'spacer' | 'footer' | 'close' | 'closeButton' | 'closeIcon' | 'icon' | 'iconGlyph';
|
||||
/** `type` is the state of the `icon` part. */
|
||||
state: {
|
||||
described: boolean;
|
||||
type?: DialogIconProps['type'];
|
||||
};
|
||||
};
|
||||
DropdownMenu: {
|
||||
parts: 'trigger' | 'positioner' | 'root';
|
||||
state: {
|
||||
context: boolean;
|
||||
};
|
||||
};
|
||||
DropdownMenuItem: {
|
||||
parts: 'root' | 'icon' | 'glyph' | 'text' | 'label' | 'description';
|
||||
state: {
|
||||
danger: boolean;
|
||||
described: boolean;
|
||||
};
|
||||
};
|
||||
Empty: {
|
||||
parts: 'root' | 'header' | 'media' | 'title' | 'description' | 'content';
|
||||
/** `variant` is the state of the `media` part. */
|
||||
state: {
|
||||
size: EmptySize;
|
||||
variant?: EmptyMediaVariant;
|
||||
};
|
||||
props: EmptyProps;
|
||||
};
|
||||
FileInput: {
|
||||
parts: 'root';
|
||||
state: NoState;
|
||||
};
|
||||
Input: {
|
||||
parts: 'root';
|
||||
state: ControlState;
|
||||
};
|
||||
Label: {
|
||||
parts: 'root';
|
||||
state: {
|
||||
light: boolean;
|
||||
};
|
||||
};
|
||||
ListRow: {
|
||||
parts: 'root';
|
||||
state: {
|
||||
interactive: boolean;
|
||||
};
|
||||
props: ListRowProps;
|
||||
};
|
||||
/** `root` is added to the Button it renders, `content` wraps the icon and label. */
|
||||
NewButton: {
|
||||
parts: 'root' | 'content' | 'icon';
|
||||
state: {
|
||||
link: boolean;
|
||||
};
|
||||
};
|
||||
NumberInput: {
|
||||
parts: 'root' | 'input';
|
||||
state: ControlState;
|
||||
};
|
||||
PageHeading: {
|
||||
parts: 'root' | 'text' | 'title' | 'description' | 'actions';
|
||||
state: NoState;
|
||||
props: PageHeadingProps;
|
||||
};
|
||||
/** `page` is added to each page Button. */
|
||||
Pagination: {
|
||||
parts: 'root' | 'page';
|
||||
state: {
|
||||
current?: boolean;
|
||||
};
|
||||
};
|
||||
ProgressBar: {
|
||||
parts: 'root' | 'indicator';
|
||||
state: {
|
||||
variant: ProgressBarVariant;
|
||||
tone: UiTone;
|
||||
};
|
||||
props: ProgressBarProps;
|
||||
};
|
||||
Select: {
|
||||
parts: 'root' | 'input' | 'trigger' | 'positioner' | 'popup' | 'list' | 'item' | 'itemLabel' | 'indicator' | 'empty' | 'group' | 'groupLabel' | 'summary' | 'preview';
|
||||
state: {
|
||||
error: boolean;
|
||||
multiple: boolean;
|
||||
selected: boolean;
|
||||
richLabel: boolean;
|
||||
searching: boolean;
|
||||
};
|
||||
};
|
||||
Spinner: {
|
||||
parts: 'root' | 'container';
|
||||
state: {
|
||||
size: SpinnerSize;
|
||||
blue: boolean;
|
||||
centered: boolean;
|
||||
};
|
||||
props: SpinnerProps;
|
||||
};
|
||||
SpinnerOverlay: {
|
||||
parts: 'root' | 'text';
|
||||
state: {
|
||||
fixed: boolean;
|
||||
};
|
||||
};
|
||||
/** `label` is added to the Label it renders. */
|
||||
Switch: {
|
||||
parts: 'root' | 'control' | 'thumb' | 'text' | 'label' | 'description';
|
||||
state: {
|
||||
described: boolean;
|
||||
position: 'start' | 'end';
|
||||
};
|
||||
};
|
||||
Table: {
|
||||
parts: 'root' | 'empty' | 'scroller' | 'table' | 'head' | 'headerRow' | 'headerCell' | 'body' | 'row' | 'cell';
|
||||
state: {
|
||||
fetching: boolean;
|
||||
};
|
||||
};
|
||||
TextArea: {
|
||||
parts: 'root';
|
||||
state: ControlState;
|
||||
};
|
||||
Tooltip: {
|
||||
parts: 'root' | 'arrow';
|
||||
state: {
|
||||
side: 'top' | 'right' | 'bottom' | 'left';
|
||||
arrow: boolean;
|
||||
};
|
||||
};
|
||||
}
|
||||
export type PrimitiveName = keyof UiPrimitives;
|
||||
export type SkinPart<N extends PrimitiveName> = UiPrimitives[N]['parts'];
|
||||
export type PrimitiveState<N extends PrimitiveName> = UiPrimitives[N]['state'];
|
||||
/** Presentational primitives, which a theme can also replace with a component. */
|
||||
export type ReplaceableName = {
|
||||
[N in PrimitiveName]: 'props' extends keyof UiPrimitives[N] ? N : never;
|
||||
}[PrimitiveName];
|
||||
export type PrimitiveProps<N extends ReplaceableName> = UiPrimitives[N] extends {
|
||||
props: infer P extends object;
|
||||
} ? P : never;
|
||||
export interface PrimitiveMeta<N extends PrimitiveName> {
|
||||
readonly parts: readonly SkinPart<N>[];
|
||||
readonly replaceable: N extends ReplaceableName ? true : false;
|
||||
}
|
||||
/** The primitives and their parts at runtime, for the registry, the workbench and the docs. */
|
||||
export declare const UI_PRIMITIVES: {
|
||||
Alert: {
|
||||
parts: ("content" | "title" | "icon" | "root" | "body")[];
|
||||
replaceable: true;
|
||||
};
|
||||
Avatar: {
|
||||
parts: "root"[];
|
||||
replaceable: true;
|
||||
};
|
||||
Badge: {
|
||||
parts: "root"[];
|
||||
replaceable: true;
|
||||
};
|
||||
Button: {
|
||||
parts: ("root" | "label" | "spinner")[];
|
||||
replaceable: true;
|
||||
};
|
||||
Card: {
|
||||
parts: ("title" | "icon" | "root" | "body" | "header" | "actions")[];
|
||||
replaceable: true;
|
||||
};
|
||||
Checkbox: {
|
||||
parts: ("root" | "indicator")[];
|
||||
replaceable: false;
|
||||
};
|
||||
Code: {
|
||||
parts: "root"[];
|
||||
replaceable: false;
|
||||
};
|
||||
CopyOnClick: {
|
||||
parts: ("target" | "status" | "root" | "message")[];
|
||||
replaceable: false;
|
||||
};
|
||||
Dialog: {
|
||||
parts: ("container" | "content" | "title" | "icon" | "heading" | "root" | "body" | "footer" | "header" | "spacer" | "close" | "closeButton" | "description" | "viewport" | "backdrop" | "closeIcon" | "iconGlyph")[];
|
||||
replaceable: false;
|
||||
};
|
||||
DropdownMenu: {
|
||||
parts: ("root" | "trigger" | "positioner")[];
|
||||
replaceable: false;
|
||||
};
|
||||
DropdownMenuItem: {
|
||||
parts: ("text" | "icon" | "root" | "label" | "description" | "glyph")[];
|
||||
replaceable: false;
|
||||
};
|
||||
Empty: {
|
||||
parts: ("content" | "media" | "title" | "root" | "header" | "description")[];
|
||||
replaceable: true;
|
||||
};
|
||||
FileInput: {
|
||||
parts: "root"[];
|
||||
replaceable: false;
|
||||
};
|
||||
Input: {
|
||||
parts: "root"[];
|
||||
replaceable: false;
|
||||
};
|
||||
Label: {
|
||||
parts: "root"[];
|
||||
replaceable: false;
|
||||
};
|
||||
ListRow: {
|
||||
parts: "root"[];
|
||||
replaceable: true;
|
||||
};
|
||||
NewButton: {
|
||||
parts: ("content" | "icon" | "root")[];
|
||||
replaceable: false;
|
||||
};
|
||||
NumberInput: {
|
||||
parts: ("root" | "input")[];
|
||||
replaceable: false;
|
||||
};
|
||||
PageHeading: {
|
||||
parts: ("text" | "title" | "root" | "description" | "actions")[];
|
||||
replaceable: true;
|
||||
};
|
||||
Pagination: {
|
||||
parts: ("page" | "root")[];
|
||||
replaceable: false;
|
||||
};
|
||||
ProgressBar: {
|
||||
parts: ("root" | "indicator")[];
|
||||
replaceable: true;
|
||||
};
|
||||
Select: {
|
||||
parts: ("list" | "group" | "root" | "input" | "summary" | "preview" | "popup" | "indicator" | "trigger" | "positioner" | "item" | "itemLabel" | "empty" | "groupLabel")[];
|
||||
replaceable: false;
|
||||
};
|
||||
Spinner: {
|
||||
parts: ("container" | "root")[];
|
||||
replaceable: true;
|
||||
};
|
||||
SpinnerOverlay: {
|
||||
parts: ("text" | "root")[];
|
||||
replaceable: false;
|
||||
};
|
||||
Switch: {
|
||||
parts: ("text" | "root" | "label" | "description" | "control" | "thumb")[];
|
||||
replaceable: false;
|
||||
};
|
||||
Table: {
|
||||
parts: ("cell" | "row" | "table" | "root" | "body" | "head" | "empty" | "scroller" | "headerRow" | "headerCell")[];
|
||||
replaceable: false;
|
||||
};
|
||||
TextArea: {
|
||||
parts: "root"[];
|
||||
replaceable: false;
|
||||
};
|
||||
Tooltip: {
|
||||
parts: ("root" | "arrow")[];
|
||||
replaceable: false;
|
||||
};
|
||||
};
|
||||
export declare function isPrimitiveName(name: string): name is PrimitiveName;
|
||||
/** `data-ui` of a primitive: `DropdownMenuItem` → `dropdown-menu-item`. */
|
||||
export declare function primitiveAttribute(name: PrimitiveName): string;
|
||||
export {};
|
||||
Vendored
+93
-3
@@ -1,4 +1,94 @@
|
||||
// Generated by scripts/generate-sdk-types.mjs. Do not edit.
|
||||
export type ThemeSkins = Record<string, unknown>;
|
||||
export declare function registerSkins(_layerId: string, _skins: ThemeSkins): void;
|
||||
export declare function skin<T>(_name: string, def: T): T;
|
||||
import { type ComponentType, type ReactElement } from 'react';
|
||||
import { type PrimitiveName, type PrimitiveProps, type PrimitiveState, type ReplaceableName, type SkinPart } from "./primitives.js";
|
||||
export { UI_PRIMITIVES, type NoState, type PrimitiveMeta, type PrimitiveName, type PrimitiveProps, type PrimitiveState, type ReplaceableName, type SkinPart, type UiPrimitives, type UiTone, } from "./primitives.js";
|
||||
/** Classes appended at the call site. */
|
||||
export type SkinClassName = string | false | null | undefined;
|
||||
/** A value a recipe reads; booleans render as present-or-absent `data-*` attributes. */
|
||||
export type SkinStateValue = string | number | boolean | undefined;
|
||||
export type SkinStateMap = {
|
||||
readonly [key: string]: SkinStateValue;
|
||||
};
|
||||
type StateKey<S> = Extract<keyof S, string>;
|
||||
type VariantKey<T> = T extends boolean ? 'true' | 'false' : T extends string | number ? `${T}` : never;
|
||||
/** A class-variance-authority recipe over the primitive's state. */
|
||||
export interface SkinRecipeConfig<S> {
|
||||
readonly base?: string;
|
||||
readonly variants?: {
|
||||
readonly [K in StateKey<S>]?: {
|
||||
readonly [V in VariantKey<NonNullable<S[K]>>]?: string;
|
||||
};
|
||||
};
|
||||
readonly compoundVariants?: readonly SkinCompoundVariant<S>[];
|
||||
readonly defaultVariants?: {
|
||||
readonly [K in StateKey<S>]?: S[K];
|
||||
};
|
||||
}
|
||||
export type SkinCompoundVariant<S> = {
|
||||
readonly [K in StateKey<S>]?: S[K] | readonly S[K][];
|
||||
} & {
|
||||
readonly class?: string;
|
||||
readonly className?: string;
|
||||
};
|
||||
/** A part's classes: a string, a cva recipe, or a function of the primitive's state. */
|
||||
export type SkinRecipe<S> = string | SkinRecipeConfig<S> | ((state: S) => string);
|
||||
/** Recipes by part. A part a skin names replaces the recipe below it wholesale; the others keep theirs. */
|
||||
export type Skin<N extends PrimitiveName> = {
|
||||
readonly [P in SkinPart<N>]?: SkinRecipe<PrimitiveState<N>>;
|
||||
};
|
||||
/** A skin with a recipe for every part, as classic's are. */
|
||||
export type CompleteSkin<N extends PrimitiveName> = {
|
||||
readonly [P in SkinPart<N>]: SkinRecipe<PrimitiveState<N>>;
|
||||
};
|
||||
export type CompleteSkins = {
|
||||
readonly [N in PrimitiveName]: CompleteSkin<N>;
|
||||
};
|
||||
/** Each part's classes as resolved from the layers below, which an extending skin builds on. */
|
||||
export type ResolvedSkin<N extends PrimitiveName> = {
|
||||
readonly [P in SkinPart<N>]: (state: PrimitiveState<N>) => string;
|
||||
};
|
||||
/** `skin(name, (parent) => ({ ... }))`: a skin computed from the layers below it. */
|
||||
export interface SkinExtension<N extends PrimitiveName> {
|
||||
(parent: ResolvedSkin<N>): Skin<N>;
|
||||
readonly skinExtension: N;
|
||||
}
|
||||
export type SkinDefinition<N extends PrimitiveName> = Skin<N> | SkinExtension<N>;
|
||||
/**
|
||||
* A theme's `ui`: a skin per primitive. A presentational primitive can instead be replaced by a
|
||||
* component, which receives the props the primitive does.
|
||||
*/
|
||||
export type ThemeSkins = {
|
||||
readonly [N in PrimitiveName]?: N extends ReplaceableName ? SkinDefinition<N> | ComponentType<PrimitiveProps<N>> : SkinDefinition<N>;
|
||||
};
|
||||
/** What a part spreads onto its element. */
|
||||
export interface SkinPartProps {
|
||||
readonly className: string | undefined;
|
||||
readonly 'data-ui': string;
|
||||
readonly 'data-part': string;
|
||||
readonly [attribute: `data-${string}`]: string | undefined;
|
||||
}
|
||||
export interface SkinBinding<N extends PrimitiveName> {
|
||||
/**
|
||||
* A part's classes with `className` appended, `data-ui`, `data-part`, and a `data-*` attribute for
|
||||
* each state value: the bound state on `root`, and `state` on any part given one.
|
||||
*/
|
||||
(part: SkinPart<N>, className?: SkinClassName, state?: Partial<PrimitiveState<N>>): SkinPartProps;
|
||||
/** Only the classes, for a part that is another primitive or a library's className option. */
|
||||
classes(part: SkinPart<N>, className?: SkinClassName, state?: Partial<PrimitiveState<N>>): string;
|
||||
}
|
||||
/** Types a skin, or with a function `(parent) => skin` extends the skin of the layers below. */
|
||||
export declare function skin<N extends PrimitiveName>(name: N, definition: (parent: ResolvedSkin<N>) => Skin<N>): SkinExtension<N>;
|
||||
export declare function skin<N extends PrimitiveName>(name: N, definition: Skin<N>): Skin<N>;
|
||||
/**
|
||||
* Adds a skin layer. Classic is registered first, then each theme of the chain parent first; a layer
|
||||
* registered again keeps classic first and moves to the top otherwise.
|
||||
*/
|
||||
export declare function registerSkins(layerId: string, skins: ThemeSkins): void;
|
||||
/** Drops every layer but classic; used when a theme fails to boot. */
|
||||
export declare function clearThemeSkins(): void;
|
||||
/** Binds a primitive's skin to its state; re-renders when the layers change. */
|
||||
export declare function useSkin<N extends PrimitiveName>(name: N, state: PrimitiveState<N>): SkinBinding<N>;
|
||||
/** `useSkin` outside a component, read from the current layers. */
|
||||
export declare function getSkin<N extends PrimitiveName>(name: N, state: PrimitiveState<N>): SkinBinding<N>;
|
||||
/** A presentational primitive: the topmost layer's replacement component, given the same props, or `Core`. */
|
||||
export declare function replaceable<N extends ReplaceableName>(name: N, Core: ComponentType<PrimitiveProps<N>>): (props: PrimitiveProps<N>) => ReactElement;
|
||||
|
||||
@@ -1,22 +1,31 @@
|
||||
import type { AvatarProps } from 'boring-avatars';
|
||||
import BoringAvatar from 'boring-avatars';
|
||||
import { useCurrentUser } from '@/api/account/queries';
|
||||
import { replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
const palette = ['var(--chart-1)', 'var(--chart-2)', 'var(--chart-3)', 'var(--chart-4)', 'var(--chart-5)'];
|
||||
|
||||
type Props = Omit<AvatarProps, 'colors'>;
|
||||
export type AvatarVariant = 'beam' | 'marble' | 'pixel' | 'sunset' | 'ring' | 'bauhaus';
|
||||
|
||||
const _Avatar = ({ variant = 'beam', ...props }: AvatarProps) => (
|
||||
<BoringAvatar colors={palette} variant={variant} {...props} />
|
||||
);
|
||||
export interface AvatarProps {
|
||||
/** Seeds the generated pattern; the panel uses a user's UUID. */
|
||||
name: string;
|
||||
size?: number | string;
|
||||
variant?: AvatarVariant;
|
||||
square?: boolean;
|
||||
title?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const UserAvatar = ({ variant = 'beam', ...props }: Omit<Props, 'name'>) => {
|
||||
const uuid = useCurrentUser().uuid;
|
||||
function CoreAvatar({ variant = 'beam', className, ...props }: AvatarProps) {
|
||||
const ui = useSkin('Avatar', { variant });
|
||||
|
||||
return <BoringAvatar colors={palette} name={uuid} variant={variant} {...props} />;
|
||||
};
|
||||
return <BoringAvatar colors={palette} variant={variant} {...props} {...ui('root', className)} />;
|
||||
}
|
||||
|
||||
const _Avatar = replaceable('Avatar', CoreAvatar);
|
||||
|
||||
const UserAvatar = (props: Omit<AvatarProps, 'name'>) => <_Avatar name={useCurrentUser().uuid} {...props} />;
|
||||
|
||||
_Avatar.displayName = 'Avatar';
|
||||
UserAvatar.displayName = 'Avatar.User';
|
||||
|
||||
const Avatar = Object.assign(_Avatar, {
|
||||
|
||||
@@ -2,7 +2,6 @@ import type * as React from 'react';
|
||||
import { X, type LucideIcon } from 'lucide-react';
|
||||
import { NewButton } from '@/components/elements/NewButton';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
interface Props {
|
||||
icon: LucideIcon;
|
||||
@@ -32,7 +31,7 @@ export default function AdminListEmpty({
|
||||
);
|
||||
|
||||
return (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<ResourceIcon />
|
||||
|
||||
@@ -31,7 +31,6 @@ import DataTable from '@/components/elements/table/DataTable';
|
||||
import DataTablePagination from '@/components/elements/table/DataTablePagination';
|
||||
import { Dialog } from '@/components/elements/dialog';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { ServerError } from '@/components/elements/ScreenBlock';
|
||||
import { getPageSearch, usePageSearch } from '@/router/search';
|
||||
import { databaseHostDetailRoute } from '@/router/routeTree';
|
||||
@@ -263,7 +262,7 @@ function DatabaseHostDatabases({ hostId }: { hostId: number }) {
|
||||
table={table}
|
||||
isFetching={isFetching}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Database />
|
||||
|
||||
@@ -10,7 +10,6 @@ import { httpErrorToHuman } from '@/api/http';
|
||||
import { Alert } from '@/components/elements/alert';
|
||||
import Button from '@/components/elements/Button';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
export default function EggVariablesTab() {
|
||||
const egg = useEggDetail();
|
||||
@@ -35,7 +34,7 @@ export default function EggVariablesTab() {
|
||||
if (variables.data.length === 0) {
|
||||
return (
|
||||
<TitledGreyBox title='Egg Variables'>
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Variable />
|
||||
|
||||
@@ -14,7 +14,6 @@ import DataTable from '@/components/elements/table/DataTable';
|
||||
import { actionsColumn, EditLinkAction, RowActions } from '@/components/elements/table/RowActions';
|
||||
import { Alert } from '@/components/elements/alert';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
const eggColumns = [
|
||||
{
|
||||
@@ -102,7 +101,7 @@ export default function EggsContainer() {
|
||||
table={table}
|
||||
tableClassName='table-fixed'
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Egg />
|
||||
|
||||
@@ -45,7 +45,6 @@ import Checkbox from '@/components/ui/Checkbox';
|
||||
import Switch from '@/components/ui/Switch';
|
||||
import { FileInput } from '@/components/form/controls';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
type ExtensionState = NonNullable<AdminExtension['state']>;
|
||||
|
||||
@@ -340,7 +339,7 @@ const buildSettingsPayload = (
|
||||
|
||||
function SettingsEmptyState({ extensionEnabled }: { extensionEnabled: boolean | undefined }) {
|
||||
return (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Settings2 />
|
||||
|
||||
@@ -27,7 +27,6 @@ import DataTable from '@/components/elements/table/DataTable';
|
||||
import { actionsColumn, EditLinkAction, RowActions } from '@/components/elements/table/RowActions';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { cardTitleClass } from '@/components/ui/typography';
|
||||
|
||||
const locationToValues = (location: AdminLocation): LocationValues => ({
|
||||
@@ -203,7 +202,7 @@ function LocationDetailForm({ location }: { location: AdminLocation }) {
|
||||
<DataTable
|
||||
table={nodeTable}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<HardDrive />
|
||||
|
||||
@@ -13,7 +13,6 @@ import Label from '@/components/elements/Label';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
import { cn } from '@/lib/cn';
|
||||
|
||||
@@ -65,7 +64,7 @@ export default function AttachEggsModal({ mount, open, onClose, onAttached }: Pr
|
||||
) : (
|
||||
<>
|
||||
{availableEggs.length === 0 ? (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Egg />
|
||||
|
||||
@@ -13,7 +13,6 @@ import Select from '@/components/ui/Select';
|
||||
import Label from '@/components/elements/Label';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
import { cn } from '@/lib/cn';
|
||||
|
||||
@@ -82,7 +81,7 @@ export default function AttachNodesModal({ mount, open, onClose, onAttached }: P
|
||||
) : (
|
||||
<>
|
||||
{groups.length === 0 ? (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<HardDrive />
|
||||
|
||||
@@ -40,7 +40,6 @@ import { actionsColumn, DeleteAction, EditLinkAction, RowActions } from '@/compo
|
||||
import ListToolbar from '@/components/elements/ListToolbar';
|
||||
import { NewButton } from '@/components/elements/NewButton';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
|
||||
type MountForm = AppForm<MountValues>;
|
||||
@@ -259,7 +258,7 @@ const AttachedEggsCard = ({
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Egg />
|
||||
@@ -352,7 +351,7 @@ const AttachedNodesCard = ({
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<HardDrive />
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { bytesRatioToString, mbToBytes } from '@/lib/formatters';
|
||||
import { useNavigate } from '@tanstack/react-router';
|
||||
import { deleteAdminNodeInput, type NodeUtilization } from '@/api/admin/nodes/queries';
|
||||
@@ -8,24 +7,26 @@ import { useAdminNodeSystemInformation, useAdminNodeUtilization, useDeleteAdminN
|
||||
import { useNodeDetail } from '@/components/admin/nodes/useNodeDetail';
|
||||
import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
||||
import Code from '@/components/elements/Code';
|
||||
import ProgressBar from '@/components/elements/ProgressBar';
|
||||
import type { UiTone } from '@/themes/skins';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import Button from '@/components/elements/Button';
|
||||
import { Dialog } from '@/components/elements/dialog';
|
||||
|
||||
const usageColour = (metric: NodeUtilization['memory'] | undefined): string => {
|
||||
const usageTone = (metric: NodeUtilization['memory'] | undefined): UiTone => {
|
||||
if (!metric) {
|
||||
return 'bg-popover';
|
||||
return 'neutral';
|
||||
}
|
||||
|
||||
if (metric.css === 'red') {
|
||||
return 'bg-destructive';
|
||||
return 'danger';
|
||||
}
|
||||
|
||||
if (metric.css === 'yellow') {
|
||||
return 'bg-warning';
|
||||
return 'warning';
|
||||
}
|
||||
|
||||
return 'bg-success';
|
||||
return 'success';
|
||||
};
|
||||
|
||||
type SystemInformation = NonNullable<ReturnType<typeof useAdminNodeSystemInformation>['data']>;
|
||||
@@ -52,7 +53,6 @@ const megabytes = (formatted: string): number => Number(formatted.replaceAll(','
|
||||
|
||||
const UsageBox = ({ title, metric }: { title: string; metric: NodeUtilization['memory'] | undefined }) => {
|
||||
const percent = metric ? Math.min(metric.percent, 100) : 0;
|
||||
const colour = usageColour(metric);
|
||||
|
||||
return (
|
||||
<TitledGreyBox title={title}>
|
||||
@@ -63,12 +63,7 @@ const UsageBox = ({ title, metric }: { title: string; metric: NodeUtilization['m
|
||||
<Spinner size='small' />
|
||||
)}
|
||||
</p>
|
||||
<div className='mt-2 h-2 w-full rounded-sm bg-sunken overflow-hidden'>
|
||||
<div
|
||||
className={cn('h-2 rounded-sm transition-[width,background-color] duration-150', colour)}
|
||||
style={{ width: `${percent}%` }}
|
||||
/>
|
||||
</div>
|
||||
<ProgressBar value={percent} tone={usageTone(metric)} label={`${title} usage`} className='mt-2' />
|
||||
</TitledGreyBox>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -31,7 +31,6 @@ import { actionsColumn, DeleteAction, RowActions } from '@/components/elements/t
|
||||
import { Dialog } from '@/components/elements/dialog';
|
||||
import { Alert } from '@/components/elements/alert';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { cardTitleClass } from '@/components/ui/typography';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
import { cn } from '@/lib/cn';
|
||||
@@ -372,7 +371,7 @@ const AllocationList = ({ query, paginationTable, showPagination, onBlockDelete
|
||||
return (
|
||||
<>
|
||||
{grouped.length === 0 ? (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Network />
|
||||
|
||||
@@ -16,7 +16,6 @@ import DataTablePagination from '@/components/elements/table/DataTablePagination
|
||||
import { Alert } from '@/components/elements/alert';
|
||||
import Button from '@/components/elements/Button';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { httpErrorToHuman } from '@/api/http';
|
||||
import { relationshipAttributes } from '@/api/relationships';
|
||||
|
||||
@@ -138,7 +137,7 @@ const NodeServerList = ({ query, table }: NodeServerListProps) => {
|
||||
table={table}
|
||||
isFetching={loading}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Server />
|
||||
|
||||
@@ -15,7 +15,6 @@ import CopyOnClick from '@/components/elements/CopyOnClick';
|
||||
import ListToolbar from '@/components/elements/ListToolbar';
|
||||
import { NewLinkButton } from '@/components/elements/NewButton';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
function ServerDatabaseContent({ server }: { server: AdminServer }) {
|
||||
const { attributes } = server;
|
||||
@@ -106,7 +105,7 @@ function ServerDatabaseContent({ server }: { server: AdminServer }) {
|
||||
table={table}
|
||||
isFetching={isFetching}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Database />
|
||||
|
||||
@@ -17,7 +17,6 @@ import TitledGreyBox from '@/components/elements/TitledGreyBox';
|
||||
import Code from '@/components/elements/Code';
|
||||
import { NewLinkButton } from '@/components/elements/NewButton';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import Button from '@/components/elements/Button';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { ServerError } from '@/components/elements/ScreenBlock';
|
||||
@@ -142,7 +141,7 @@ function ServerMountsContent({ server }: Props) {
|
||||
table={table}
|
||||
isFetching={isFetching}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<FolderInput />
|
||||
|
||||
@@ -23,7 +23,6 @@ import Code from '@/components/elements/Code';
|
||||
import { TextInput } from '@/components/form/controls';
|
||||
import { ServerError } from '@/components/elements/ScreenBlock';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
|
||||
interface Props {
|
||||
@@ -66,7 +65,7 @@ const EnvironmentVariables = ({ form, egg }: { form: AppForm<Values, TagCheckMet
|
||||
if (variables.length === 0) {
|
||||
return (
|
||||
<TitledGreyBox title='Service Variables'>
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Variable />
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import { Tags } from 'lucide-react';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
export default function NoTagsYet() {
|
||||
return (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Tags />
|
||||
|
||||
@@ -48,7 +48,6 @@ import DataTable from '@/components/elements/table/DataTable';
|
||||
import { actionsColumn, RowActions } from '@/components/elements/table/RowActions';
|
||||
import ServerEditAction from '@/components/admin/servers/ServerEditAction';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
|
||||
type UserForm = AppForm<UserValues>;
|
||||
@@ -237,7 +236,7 @@ const OwnedServersCard = ({ servers }: { servers: AdminUserServer[] }) => {
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Server />
|
||||
|
||||
@@ -7,7 +7,6 @@ import CreateApiKeyForm from '@/components/dashboard/forms/CreateApiKeyForm';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import PageContentBlock from '@/components/elements/PageContentBlock';
|
||||
import { Dialog } from '@/components/elements/dialog';
|
||||
import Code from '@/components/elements/Code';
|
||||
@@ -62,7 +61,7 @@ export default function AccountApiContainer() {
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<KeyRound />
|
||||
|
||||
@@ -14,8 +14,6 @@ import { useCurrentUser } from '@/api/account/queries';
|
||||
import { useDebouncedValue } from '@/plugins/useDebouncedValue';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { cn } from '@/lib/cn';
|
||||
|
||||
type Props = DialogProps;
|
||||
|
||||
@@ -66,7 +64,7 @@ export default function SearchModal({ ...props }: Props) {
|
||||
</div>
|
||||
)}
|
||||
{canSearch && servers && !isFetching && !error && serverList.length === 0 && (
|
||||
<Empty className={cn(emptyCompactClass, 'mt-6')}>
|
||||
<Empty size='compact' className='mt-6'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<SearchX />
|
||||
|
||||
@@ -11,7 +11,6 @@ import { ServerError } from '@/components/elements/ScreenBlock';
|
||||
import DataTable from '@/components/elements/table/DataTable';
|
||||
import { accountSshColumns } from '@/components/dashboard/ssh/AccountSSHTable';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
export default function AccountSSHContainer() {
|
||||
const { data, error, refetch } = useSSHKeys();
|
||||
@@ -39,7 +38,7 @@ export default function AccountSSHContainer() {
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<KeySquare />
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import type React from 'react';
|
||||
import { replaceable, useSkin, type UiTone } from '@/themes/skins';
|
||||
|
||||
export type BadgeSize = 'sm' | 'md';
|
||||
/** `solid` fills the badge with its tone; `soft` tints it. */
|
||||
export type BadgeVariant = 'solid' | 'soft';
|
||||
|
||||
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
||||
tone?: UiTone;
|
||||
size?: BadgeSize;
|
||||
variant?: BadgeVariant;
|
||||
}
|
||||
|
||||
/** A short status or count label. */
|
||||
function CoreBadge({ tone = 'neutral', size = 'md', variant = 'solid', className, ...props }: BadgeProps) {
|
||||
const ui = useSkin('Badge', { tone, size, variant });
|
||||
|
||||
return <span {...ui('root', className)} {...props} />;
|
||||
}
|
||||
|
||||
const Badge = replaceable('Badge', CoreBadge);
|
||||
|
||||
export default Badge;
|
||||
@@ -1,115 +1,38 @@
|
||||
import React from 'react';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { Link } from '@tanstack/react-router';
|
||||
import { cn } from '@/lib/cn';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { getSkin, replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
export type ButtonColor = 'green' | 'red' | 'orange' | 'primary' | 'grey';
|
||||
export type ButtonSize = 'xsmall' | 'small' | 'large' | 'xlarge';
|
||||
|
||||
interface Props {
|
||||
isLoading?: boolean;
|
||||
size?: 'xsmall' | 'small' | 'large' | 'xlarge';
|
||||
color?: 'green' | 'red' | 'orange' | 'primary' | 'grey';
|
||||
size?: ButtonSize;
|
||||
color?: ButtonColor;
|
||||
isSecondary?: boolean;
|
||||
}
|
||||
|
||||
const buttonStyle = cva(
|
||||
'relative inline-block rounded-sm border p-2 text-sm uppercase tracking-wide transition-colors duration-150 disabled:cursor-default disabled:opacity-50',
|
||||
{
|
||||
variants: {
|
||||
color: {
|
||||
primary:
|
||||
'bg-primary border-primary text-primary-foreground [&:hover:not(:disabled)]:bg-primary/80 [&:hover:not(:disabled)]:border-primary',
|
||||
grey: 'border-border bg-popover text-foreground [&:hover:not(:disabled)]:bg-secondary [&:hover:not(:disabled)]:border-secondary',
|
||||
green: 'border-success bg-success text-success-foreground [&:hover:not(:disabled)]:bg-success/80 [&:hover:not(:disabled)]:border-success',
|
||||
red: 'border-destructive bg-destructive text-destructive-foreground [&:hover:not(:disabled)]:bg-destructive/80 [&:hover:not(:disabled)]:border-destructive',
|
||||
orange: 'border-caution bg-caution text-caution-foreground [&:hover:not(:disabled)]:bg-caution/80 [&:hover:not(:disabled)]:border-caution',
|
||||
},
|
||||
size: {
|
||||
xsmall: 'px-2 py-1 text-xs',
|
||||
small: 'px-4 py-2',
|
||||
large: 'p-4 text-sm',
|
||||
xlarge: 'p-4 w-full',
|
||||
},
|
||||
isSecondary: {
|
||||
true: 'border-border bg-transparent text-foreground [&:hover:not(:disabled)]:border-popover [&:hover:not(:disabled)]:bg-popover [&:hover:not(:disabled)]:text-foreground',
|
||||
false: '',
|
||||
},
|
||||
},
|
||||
compoundVariants: [
|
||||
{
|
||||
isSecondary: true,
|
||||
color: 'primary',
|
||||
class: '[&:hover:not(:disabled)]:bg-primary [&:hover:not(:disabled)]:border-primary [&:hover:not(:disabled)]:text-primary-foreground',
|
||||
},
|
||||
{
|
||||
isSecondary: true,
|
||||
color: 'red',
|
||||
class: '[&:hover:not(:disabled)]:bg-destructive [&:hover:not(:disabled)]:border-destructive [&:hover:not(:disabled)]:text-destructive-foreground',
|
||||
},
|
||||
{
|
||||
isSecondary: true,
|
||||
color: 'green',
|
||||
class: '[&:hover:not(:disabled)]:bg-success [&:hover:not(:disabled)]:border-success [&:hover:not(:disabled)]:text-success-foreground',
|
||||
},
|
||||
{
|
||||
isSecondary: true,
|
||||
color: 'orange',
|
||||
class: '[&:hover:not(:disabled)]:bg-caution [&:hover:not(:disabled)]:border-caution [&:hover:not(:disabled)]:text-caution-foreground',
|
||||
},
|
||||
{
|
||||
isSecondary: false,
|
||||
color: 'primary',
|
||||
class: '[&:active:not(:disabled)]:bg-primary/70 [&:active:not(:disabled)]:border-primary/70',
|
||||
},
|
||||
{
|
||||
isSecondary: false,
|
||||
color: 'green',
|
||||
class: '[&:active:not(:disabled)]:bg-success/70 [&:active:not(:disabled)]:border-success',
|
||||
},
|
||||
{
|
||||
isSecondary: false,
|
||||
color: 'red',
|
||||
class: '[&:active:not(:disabled)]:bg-destructive/70 [&:active:not(:disabled)]:border-destructive',
|
||||
},
|
||||
{
|
||||
isSecondary: false,
|
||||
color: 'orange',
|
||||
class: '[&:active:not(:disabled)]:bg-caution/70 [&:active:not(:disabled)]:border-caution',
|
||||
},
|
||||
],
|
||||
defaultVariants: {
|
||||
color: 'primary',
|
||||
size: 'small',
|
||||
isSecondary: false,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
type StyleProps = VariantProps<typeof buttonStyle>;
|
||||
|
||||
const buttonClassName = ({
|
||||
color,
|
||||
size,
|
||||
isSecondary,
|
||||
className,
|
||||
}: Omit<Props, 'isLoading'> & { className?: string }): string =>
|
||||
cn(
|
||||
buttonStyle({
|
||||
// A secondary button without a colour skips the default primary fill.
|
||||
color: isSecondary && !color ? undefined : (color as StyleProps['color']),
|
||||
size: (size as StyleProps['size']) ?? 'small',
|
||||
isSecondary: !!isSecondary,
|
||||
}),
|
||||
className
|
||||
);
|
||||
|
||||
type StyleableProps = Omit<Props, 'isLoading'>;
|
||||
|
||||
const buttonState = ({ color, size, isSecondary }: StyleableProps, loading = false) => ({
|
||||
color: color ?? 'primary',
|
||||
size: size ?? 'small',
|
||||
secondary: !!isSecondary,
|
||||
loading,
|
||||
});
|
||||
|
||||
/** The root classes of a button, for elements styled as one outside a component. */
|
||||
const buttonClassName = ({ className, ...props }: StyleableProps & { className?: string }): string =>
|
||||
getSkin('Button', buttonState(props)).classes('root', className);
|
||||
|
||||
type ButtonStyleProps<E extends React.ElementType = 'button'> = {
|
||||
as?: E;
|
||||
ref?: React.ComponentPropsWithRef<E>['ref'];
|
||||
} & StyleableProps &
|
||||
Omit<React.ComponentPropsWithoutRef<E>, keyof StyleableProps | 'as'>;
|
||||
|
||||
/** Any element, styled as a button. */
|
||||
const ButtonStyle = <E extends React.ElementType = 'button'>({
|
||||
as,
|
||||
color,
|
||||
@@ -120,31 +43,54 @@ const ButtonStyle = <E extends React.ElementType = 'button'>({
|
||||
...props
|
||||
}: ButtonStyleProps<E>) => {
|
||||
const Component = (as || 'button') as React.ElementType;
|
||||
const ui = useSkin('Button', buttonState({ color, size, isSecondary }));
|
||||
|
||||
return <Component ref={ref} className={buttonClassName({ color, size, isSecondary, className })} {...props} />;
|
||||
return <Component ref={ref} {...ui('root', className)} {...props} />;
|
||||
};
|
||||
|
||||
type ComponentProps = Omit<React.ComponentPropsWithRef<'button'>, keyof Props> & Props;
|
||||
export type ButtonProps = Omit<React.ComponentPropsWithRef<'button'>, keyof Props> & Props;
|
||||
|
||||
function CoreButton({
|
||||
children,
|
||||
isLoading,
|
||||
disabled,
|
||||
type = 'button',
|
||||
color,
|
||||
size,
|
||||
isSecondary,
|
||||
className,
|
||||
ref,
|
||||
...props
|
||||
}: ButtonProps) {
|
||||
const ui = useSkin('Button', buttonState({ color, size, isSecondary }, !!isLoading));
|
||||
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
{...ui('root', className)}
|
||||
type={type}
|
||||
disabled={disabled || isLoading}
|
||||
aria-busy={isLoading || undefined}
|
||||
{...props}
|
||||
>
|
||||
{isLoading && (
|
||||
<span {...ui('spinner')}>
|
||||
<Spinner size='small' />
|
||||
</span>
|
||||
)}
|
||||
<span {...ui('label')}>{children}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
/** Defaults to `type="button"`; `isLoading` shows a spinner and disables the button. */
|
||||
const Button = ({ children, isLoading, disabled, type = 'button', ref, ...props }: ComponentProps) => (
|
||||
<ButtonStyle ref={ref} type={type} disabled={disabled || isLoading} aria-busy={isLoading || undefined} {...props}>
|
||||
{isLoading && (
|
||||
<span className='flex absolute justify-center items-center w-full h-full left-0 top-0'>
|
||||
<Spinner size='small' />
|
||||
</span>
|
||||
)}
|
||||
<span className={isLoading ? 'text-transparent' : undefined}>{children}</span>
|
||||
</ButtonStyle>
|
||||
);
|
||||
const Button = replaceable('Button', CoreButton);
|
||||
|
||||
Button.displayName = 'Button';
|
||||
|
||||
const TextButton = ({ ref, ...props }: ComponentProps) => <Button ref={ref} color='grey' {...props} />;
|
||||
const TextButton = ({ ref, ...props }: ButtonProps) => <Button ref={ref} color='grey' {...props} />;
|
||||
|
||||
TextButton.displayName = 'Button.Text';
|
||||
|
||||
const DangerButton = ({ ref, ...props }: ComponentProps) => <Button ref={ref} color='red' {...props} />;
|
||||
const DangerButton = ({ ref, ...props }: ButtonProps) => <Button ref={ref} color='red' {...props} />;
|
||||
|
||||
DangerButton.displayName = 'Button.Danger';
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import type React from 'react';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import Icon from '@/components/elements/Icon';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import { isString } from '@/lib/objects';
|
||||
import { replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
export interface CardProps {
|
||||
/** A string renders as the card's heading; any other node replaces it. */
|
||||
title?: React.ReactNode;
|
||||
/** Shown before a string title. */
|
||||
icon?: LucideIcon;
|
||||
/** Controls placed at the end of the header. */
|
||||
actions?: React.ReactNode;
|
||||
/** Covers the card with a spinner. */
|
||||
loading?: boolean;
|
||||
className?: string;
|
||||
/** Classes for the body of a card with a header. */
|
||||
bodyClassName?: string;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
/** A surface for a section of content; with a title or actions it has a header above its body. */
|
||||
function CoreCard({ title, icon, actions, loading = false, className, bodyClassName, children }: CardProps) {
|
||||
const titled = !!title || !!actions;
|
||||
const ui = useSkin('Card', { titled, actions: !!actions, loading });
|
||||
|
||||
return (
|
||||
<div {...ui('root', className)}>
|
||||
{loading && <SpinnerOverlay visible />}
|
||||
{titled ? (
|
||||
<>
|
||||
<div {...ui('header')}>
|
||||
{isString(title) ? (
|
||||
<h2 {...ui('title')}>
|
||||
{icon && <Icon icon={icon} {...ui('icon')} />}
|
||||
{title}
|
||||
</h2>
|
||||
) : (
|
||||
title
|
||||
)}
|
||||
{!!actions && <div {...ui('actions')}>{actions}</div>}
|
||||
</div>
|
||||
<div {...ui('body', bodyClassName)}>{children}</div>
|
||||
</>
|
||||
) : (
|
||||
children
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const Card = replaceable('Card', CoreCard);
|
||||
|
||||
export default Card;
|
||||
@@ -1,21 +1,14 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
interface CodeProps {
|
||||
export interface CodeProps {
|
||||
dark?: boolean | undefined;
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export default function Code({ dark, className, children }: CodeProps) {
|
||||
return (
|
||||
<code
|
||||
className={cn('font-mono px-1.5 py-0.5 inline-block rounded-sm', className, {
|
||||
'bg-sunken': !dark,
|
||||
'bg-muted text-foreground': dark,
|
||||
})}
|
||||
>
|
||||
{children}
|
||||
</code>
|
||||
);
|
||||
const ui = useSkin('Code', { dark: !!dark });
|
||||
|
||||
return <code {...ui('root', className)}>{children}</code>;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
|
||||
import Card from '@/components/elements/Card';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { sectionTitleClass } from '@/components/ui/typography';
|
||||
|
||||
@@ -11,13 +11,13 @@ type Props = Readonly<
|
||||
}
|
||||
>;
|
||||
|
||||
/** A section title above a plain `Card`. */
|
||||
const ContentBox = ({ title, borderColor, showLoadingOverlay, children, ...props }: Props) => (
|
||||
<div {...props}>
|
||||
{title && <h2 className={cn(sectionTitleClass, 'mb-4 px-4')}>{title}</h2>}
|
||||
<div className={cn('bg-card p-4 rounded-sm shadow-lg relative', !!borderColor && 'border-t-4')}>
|
||||
<SpinnerOverlay visible={showLoadingOverlay || false} />
|
||||
<Card loading={showLoadingOverlay} className={borderColor ? 'border-t-4' : undefined}>
|
||||
{children}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ import Button from '@/components/elements/Button';
|
||||
import { TextArea, TextInput } from '@/components/form/controls';
|
||||
import copyToClipboard from '@/lib/clipboard';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
interface CopyOnClickProps {
|
||||
export interface CopyOnClickProps {
|
||||
text: string | number | null | undefined;
|
||||
showInNotification?: boolean;
|
||||
children: React.ReactNode;
|
||||
@@ -45,6 +46,7 @@ const copyStatusMessage = (status: CopyStatus, text: CopyOnClickProps['text'], s
|
||||
/** Copies `text` when its single child is clicked; a non-interactive child becomes a focusable button. */
|
||||
const CopyOnClick = ({ text, showInNotification = false, children }: CopyOnClickProps) => {
|
||||
const [status, setStatus] = useState<CopyStatus | null>(null);
|
||||
const ui = useSkin('CopyOnClick', { status: status ?? undefined });
|
||||
|
||||
useEffect(() => {
|
||||
if (!status) {
|
||||
@@ -85,7 +87,7 @@ const CopyOnClick = ({ text, showInNotification = false, children }: CopyOnClick
|
||||
role: interactive ? element.props.role : (element.props.role ?? 'button'),
|
||||
tabIndex: interactive ? element.props.tabIndex : (element.props.tabIndex ?? 0),
|
||||
onKeyDown: interactive ? element.props.onKeyDown : onKeyDown,
|
||||
className: cn(element.props.className || '', 'cursor-pointer'),
|
||||
className: cn(element.props.className, ui.classes('target')),
|
||||
onClick: (e: React.MouseEvent<HTMLElement>) => {
|
||||
copy();
|
||||
element.props.onClick?.(e);
|
||||
@@ -97,9 +99,9 @@ const CopyOnClick = ({ text, showInNotification = false, children }: CopyOnClick
|
||||
<>
|
||||
{status && (
|
||||
<Portal>
|
||||
<div className='fixed z-50 bottom-0 right-0 m-4'>
|
||||
<div role='status' className='rounded-md py-3 px-4 text-foreground bg-popover/95 shadow-sm'>
|
||||
<p>{copyStatusMessage(status, text, showInNotification)}</p>
|
||||
<div {...ui('root')}>
|
||||
<div role='status' {...ui('status')}>
|
||||
<p {...ui('message')}>{copyStatusMessage(status, text, showInNotification)}</p>
|
||||
</div>
|
||||
</div>
|
||||
</Portal>
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { interactiveSurfaceClass } from '@/components/ui/styles';
|
||||
|
||||
type Props<E extends React.ElementType = 'div'> = {
|
||||
as?: E;
|
||||
$hoverable?: boolean;
|
||||
} & Omit<React.ComponentPropsWithoutRef<E>, 'as' | '$hoverable'>;
|
||||
|
||||
const GreyRowBox = <E extends React.ElementType = 'div'>({ as, $hoverable, className, ...props }: Props<E>) => {
|
||||
const Component = (as || 'div') as React.ElementType;
|
||||
|
||||
return (
|
||||
<Component
|
||||
className={cn(
|
||||
'flex rounded-sm no-underline text-foreground items-center bg-card p-4 border border-transparent overflow-hidden',
|
||||
'[&_.icon]:flex [&_.icon]:w-16 [&_.icon]:items-center [&_.icon]:justify-center [&_.icon]:rounded-full [&_.icon]:bg-popover [&_.icon]:p-3',
|
||||
$hoverable !== false && interactiveSurfaceClass,
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default GreyRowBox;
|
||||
@@ -1,24 +1,16 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
type Props<E extends React.ElementType = 'label'> = {
|
||||
export type LabelProps<E extends React.ElementType = 'label'> = {
|
||||
as?: E;
|
||||
isLight?: boolean;
|
||||
} & Omit<React.ComponentPropsWithoutRef<E>, 'as' | 'isLight'>;
|
||||
|
||||
const Label = <E extends React.ElementType = 'label'>({ as, isLight, className, ...props }: Props<E>) => {
|
||||
const Label = <E extends React.ElementType = 'label'>({ as, isLight, className, ...props }: LabelProps<E>) => {
|
||||
const Component = (as || 'label') as React.ElementType;
|
||||
const ui = useSkin('Label', { light: !!isLight });
|
||||
|
||||
return (
|
||||
<Component
|
||||
className={cn(
|
||||
'block text-sm font-medium uppercase text-foreground mb-1',
|
||||
isLight && 'text-muted-foreground',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
return <Component {...ui('root', className)} {...props} />;
|
||||
};
|
||||
|
||||
export default Label;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import { PanelLink, type PanelDestination } from '@/sdk/navigation';
|
||||
import { replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
export interface ListRowProps extends React.HTMLAttributes<HTMLElement> {
|
||||
as?: 'div' | 'li' | 'article';
|
||||
/** Renders the row as a link to the destination. */
|
||||
destination?: PanelDestination;
|
||||
exact?: boolean;
|
||||
/** Hover and press feedback; on for links and clickable rows unless set. */
|
||||
interactive?: boolean;
|
||||
}
|
||||
|
||||
/** A row of a list, such as a server on the dashboard. */
|
||||
function CoreListRow({ as: Element = 'div', destination, exact, interactive, className, ...props }: ListRowProps) {
|
||||
const ui = useSkin('ListRow', {
|
||||
interactive: interactive ?? (destination !== undefined || props.onClick !== undefined),
|
||||
});
|
||||
|
||||
if (destination) {
|
||||
return <PanelLink destination={destination} exact={exact} {...ui('root', className)} {...props} />;
|
||||
}
|
||||
|
||||
return <Element {...ui('root', className)} {...props} />;
|
||||
}
|
||||
|
||||
const ListRow = replaceable('ListRow', CoreListRow);
|
||||
|
||||
export default ListRow;
|
||||
@@ -1,44 +1,40 @@
|
||||
import type * as React from 'react';
|
||||
import { Plus, type LucideIcon } from 'lucide-react';
|
||||
import Button, { RouterLinkButton } from '@/components/elements/Button';
|
||||
import Button, { RouterLinkButton, type ButtonProps } from '@/components/elements/Button';
|
||||
import Icon from '@/components/elements/Icon';
|
||||
import { cn } from '@/lib/cn';
|
||||
|
||||
const newButtonClass =
|
||||
'inline-flex h-9 shrink-0 items-center justify-center gap-2 px-3 normal-case font-medium tracking-normal';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
interface IconProps {
|
||||
/** Replaces the Plus for sibling toolbar actions such as Upload. */
|
||||
icon?: LucideIcon;
|
||||
}
|
||||
|
||||
export type NewButtonProps = ButtonProps & IconProps;
|
||||
|
||||
/** The panel's "create" action: a Plus icon and a sentence-case label such as "New node". */
|
||||
export function NewButton({
|
||||
icon = Plus,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Button> & IconProps) {
|
||||
export function NewButton({ icon = Plus, className, children, ...props }: NewButtonProps) {
|
||||
const ui = useSkin('NewButton', { link: false });
|
||||
|
||||
return (
|
||||
<Button className={cn(newButtonClass, className)} {...props}>
|
||||
<span className='inline-flex items-center gap-2'>
|
||||
<Icon icon={icon} aria-hidden className='h-4 w-4' />
|
||||
<Button className={ui.classes('root', className)} {...props}>
|
||||
<span {...ui('content')}>
|
||||
<Icon icon={icon} aria-hidden {...ui('icon')} />
|
||||
{children}
|
||||
</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export type NewLinkButtonProps = Omit<React.ComponentProps<typeof RouterLinkButton>, 'children'> &
|
||||
IconProps & { children: React.ReactNode };
|
||||
|
||||
/** `NewButton` for actions that navigate to a create page. */
|
||||
export function NewLinkButton({
|
||||
icon = Plus,
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: Omit<React.ComponentProps<typeof RouterLinkButton>, 'children'> & IconProps & { children: React.ReactNode }) {
|
||||
export function NewLinkButton({ icon = Plus, className, children, ...props }: NewLinkButtonProps) {
|
||||
const ui = useSkin('NewButton', { link: true });
|
||||
|
||||
return (
|
||||
<RouterLinkButton className={cn(newButtonClass, className)} {...props}>
|
||||
<Icon icon={icon} aria-hidden className='h-4 w-4' />
|
||||
<RouterLinkButton className={ui.classes('root', className)} {...props}>
|
||||
<Icon icon={icon} aria-hidden {...ui('icon')} />
|
||||
{children}
|
||||
</RouterLinkButton>
|
||||
);
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { pageTitleClass } from '@/components/ui/typography';
|
||||
import type React from 'react';
|
||||
import { replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
interface Props {
|
||||
export interface PageHeadingProps {
|
||||
title: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
actions?: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function PageHeading({ title, description, actions, className }: Props) {
|
||||
function CorePageHeading({ title, description, actions, className }: PageHeadingProps) {
|
||||
const ui = useSkin('PageHeading', {});
|
||||
|
||||
return (
|
||||
<header className={cn('mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between', className)}>
|
||||
<div className='min-w-0'>
|
||||
<h1 className={pageTitleClass}>{title}</h1>
|
||||
{description && <p className='mt-1 text-sm leading-relaxed text-foreground/70'>{description}</p>}
|
||||
<header {...ui('root', className)}>
|
||||
<div {...ui('text')}>
|
||||
<h1 {...ui('title')}>{title}</h1>
|
||||
{description && <p {...ui('description')}>{description}</p>}
|
||||
</div>
|
||||
{actions && <div className='shrink-0'>{actions}</div>}
|
||||
{actions && <div {...ui('actions')}>{actions}</div>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
const PageHeading = replaceable('PageHeading', CorePageHeading);
|
||||
|
||||
export default PageHeading;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import Button from '@/components/elements/Button';
|
||||
import { ChevronsLeft, ChevronsRight } from 'lucide-react';
|
||||
import Icon from '@/components/elements/Icon';
|
||||
import { useSkin, type SkinBinding } from '@/themes/skins';
|
||||
|
||||
interface RenderFuncProps<T> {
|
||||
items: T[];
|
||||
@@ -10,7 +10,7 @@ interface RenderFuncProps<T> {
|
||||
isFirstPage: boolean;
|
||||
}
|
||||
|
||||
interface Props<T> {
|
||||
export interface PaginationProps<T> {
|
||||
data: GeneratedPaginatedResult<T>;
|
||||
showGoToLast?: boolean;
|
||||
showGoToFirst?: boolean;
|
||||
@@ -39,8 +39,18 @@ interface PaginationDataSet {
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
const Block = ({ className, ...props }: React.ComponentProps<typeof Button>) => (
|
||||
<Button type='button' className={cn('p-0 w-10 h-10 not-last-of-type:mr-2', className)} {...props} />
|
||||
const PageButton = ({
|
||||
ui,
|
||||
current,
|
||||
...props
|
||||
}: { ui: SkinBinding<'Pagination'>; current: boolean } & React.ComponentProps<typeof Button>) => (
|
||||
<Button
|
||||
type='button'
|
||||
className={ui.classes('page', undefined, { current })}
|
||||
isSecondary={!current}
|
||||
color='primary'
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
const normalizeGeneratedPagination = (
|
||||
@@ -53,7 +63,8 @@ const normalizeGeneratedPagination = (
|
||||
totalPages: pagination.total_pages,
|
||||
});
|
||||
|
||||
function Pagination<T>({ data, onPageSelect, children }: Props<T>) {
|
||||
function Pagination<T>({ data, onPageSelect, children }: PaginationProps<T>) {
|
||||
const ui = useSkin('Pagination', {});
|
||||
const items = data.data;
|
||||
const pagination = normalizeGeneratedPagination(data.meta.pagination);
|
||||
const isFirstPage = pagination.currentPage === 1;
|
||||
@@ -72,26 +83,26 @@ function Pagination<T>({ data, onPageSelect, children }: Props<T>) {
|
||||
<>
|
||||
{children({ items, isFirstPage, isLastPage })}
|
||||
{pages.length > 1 && (
|
||||
<div className='mt-4 flex justify-center'>
|
||||
<div {...ui('root')}>
|
||||
{pages[0] > 1 && !isFirstPage && (
|
||||
<Block isSecondary color='primary' onClick={() => onPageSelect(1)}>
|
||||
<PageButton ui={ui} current={false} onClick={() => onPageSelect(1)}>
|
||||
<Icon icon={ChevronsLeft} />
|
||||
</Block>
|
||||
</PageButton>
|
||||
)}
|
||||
{pages.map((page) => (
|
||||
<Block
|
||||
isSecondary={pagination.currentPage !== page}
|
||||
color='primary'
|
||||
<PageButton
|
||||
key={`block_page_${page}`}
|
||||
ui={ui}
|
||||
current={pagination.currentPage === page}
|
||||
onClick={() => onPageSelect(page)}
|
||||
>
|
||||
{page}
|
||||
</Block>
|
||||
</PageButton>
|
||||
))}
|
||||
{pages[4] < pagination.totalPages && !isLastPage && (
|
||||
<Block isSecondary color='primary' onClick={() => onPageSelect(pagination.totalPages)}>
|
||||
<PageButton ui={ui} current={false} onClick={() => onPageSelect(pagination.totalPages)}>
|
||||
<Icon icon={ChevronsRight} />
|
||||
</Block>
|
||||
</PageButton>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,8 +1,46 @@
|
||||
import { useEffect } from 'react';
|
||||
import { setHttpProgress, useHttpProgress } from '@/state/httpProgress';
|
||||
import { randomInt } from '@/helpers';
|
||||
import { replaceable, useSkin, type UiTone } from '@/themes/skins';
|
||||
|
||||
export default function ProgressBar() {
|
||||
/** `meter` shows a value in a track; `page` is the loading bar along the top of the page. */
|
||||
export type ProgressBarVariant = 'meter' | 'page';
|
||||
|
||||
export interface ProgressBarProps {
|
||||
/** Percent complete from 0 to 100; `null` shows the track alone. */
|
||||
value: number | null;
|
||||
variant?: ProgressBarVariant;
|
||||
/** Defaults to `accent` for the page bar and `neutral` otherwise. */
|
||||
tone?: UiTone;
|
||||
/** Names a meter for assistive technology. */
|
||||
label?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function CoreProgressBar({ value, variant = 'meter', tone, label, className }: ProgressBarProps) {
|
||||
const meter = variant === 'meter';
|
||||
const ui = useSkin('ProgressBar', { variant, tone: tone ?? (meter ? 'neutral' : 'accent') });
|
||||
|
||||
return (
|
||||
<div
|
||||
{...ui('root', className)}
|
||||
role={meter ? 'progressbar' : undefined}
|
||||
aria-label={meter ? label : undefined}
|
||||
aria-valuemin={meter ? 0 : undefined}
|
||||
aria-valuemax={meter ? 100 : undefined}
|
||||
aria-valuenow={meter ? (value ?? undefined) : undefined}
|
||||
>
|
||||
{value !== null && <div {...ui('indicator')} style={{ width: `${value}%` }} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const ProgressBar = replaceable('ProgressBar', CoreProgressBar);
|
||||
|
||||
export default ProgressBar;
|
||||
|
||||
/** The page loading bar, driven by the panel's HTTP requests. */
|
||||
export function HttpProgressBar() {
|
||||
const { progress, continuous } = useHttpProgress();
|
||||
const visible = (progress || 0) > 0;
|
||||
|
||||
@@ -38,14 +76,5 @@ export default function ProgressBar() {
|
||||
return () => clearTimeout(timeout);
|
||||
}, [continuous, progress]);
|
||||
|
||||
return (
|
||||
<div className='fixed h-0.5 w-full'>
|
||||
{visible && (
|
||||
<div
|
||||
className='h-full bg-accent shadow-progress transition-[width] duration-300 ease-in-out'
|
||||
style={{ width: progress === undefined ? '100%' : `${progress}%` }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
return <ProgressBar variant='page' value={visible ? (progress ?? 100) : null} />;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,31 @@
|
||||
import React, { Suspense } from 'react';
|
||||
import { cva } from 'class-variance-authority';
|
||||
import { useLocation, useRouter } from '@tanstack/react-router';
|
||||
import { cn } from '@/lib/cn';
|
||||
import ErrorBoundary from '@/components/elements/ErrorBoundary';
|
||||
import { replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
export type SpinnerSize = 'small' | 'base' | 'large';
|
||||
|
||||
interface Props {
|
||||
export interface SpinnerProps {
|
||||
size?: SpinnerSize;
|
||||
centered?: boolean;
|
||||
isBlue?: boolean;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
type SpinnerComponentType = ((props: Props) => React.JSX.Element) & {
|
||||
type SpinnerComponentType = ((props: SpinnerProps) => React.JSX.Element) & {
|
||||
displayName?: string;
|
||||
Size: Record<'SMALL' | 'BASE' | 'LARGE', SpinnerSize>;
|
||||
Suspense: ((props: Props) => React.JSX.Element) & { displayName?: string };
|
||||
Suspense: ((props: SpinnerProps) => React.JSX.Element) & { displayName?: string };
|
||||
};
|
||||
|
||||
const spinnerSize = cva('', {
|
||||
variants: {
|
||||
size: {
|
||||
small: 'w-4 h-4 border-2',
|
||||
base: 'w-8 h-8 border-[3px]',
|
||||
large: 'w-16 h-16 border-[6px]',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: 'base',
|
||||
},
|
||||
});
|
||||
function CoreSpinner({ size = 'base', centered = false, isBlue = false }: SpinnerProps) {
|
||||
const ui = useSkin('Spinner', { size, blue: isBlue, centered });
|
||||
const spinner = <span {...ui('root')} />;
|
||||
|
||||
const SpinnerComponent = ({ size, isBlue }: Props) => (
|
||||
<span
|
||||
className={cn(
|
||||
'block rounded-full animate-[spin_1s_cubic-bezier(0.55,0.25,0.25,0.7)_infinite] border-muted border-t-foreground',
|
||||
isBlue && 'border-ring border-t-primary',
|
||||
spinnerSize({ size: size ?? 'base' })
|
||||
)}
|
||||
/>
|
||||
);
|
||||
return centered ? <div {...ui('container')}>{spinner}</div> : spinner;
|
||||
}
|
||||
|
||||
const Spinner = (({ centered, ...props }: Props) =>
|
||||
centered ? (
|
||||
<div className={cn('flex justify-center items-center', props.size === 'large' ? 'm-20' : 'm-6')}>
|
||||
<SpinnerComponent {...props} />
|
||||
</div>
|
||||
) : (
|
||||
<SpinnerComponent {...props} />
|
||||
)) as SpinnerComponentType;
|
||||
|
||||
Spinner.displayName = 'Spinner';
|
||||
const Spinner = replaceable('Spinner', CoreSpinner) as SpinnerComponentType;
|
||||
|
||||
Spinner.Size = {
|
||||
SMALL: 'small',
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import type { SpinnerSize } from '@/components/elements/Spinner';
|
||||
import Spinner from '@/components/elements/Spinner';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
interface Props {
|
||||
export interface SpinnerOverlayProps {
|
||||
visible: boolean;
|
||||
fixed?: boolean;
|
||||
size?: SpinnerSize;
|
||||
@@ -12,18 +12,16 @@ interface Props {
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
const SpinnerOverlay = ({ size, fixed, visible, backgroundOpacity, children }: Props) => {
|
||||
const SpinnerOverlay = ({ size, fixed, visible, backgroundOpacity, children }: SpinnerOverlayProps) => {
|
||||
const ui = useSkin('SpinnerOverlay', { fixed: !!fixed });
|
||||
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'top-0 left-0 flex items-center justify-center w-full h-full rounded-sm flex-col z-40',
|
||||
'bg-background/(--spinner-overlay-opacity)',
|
||||
fixed ? 'fixed' : 'absolute'
|
||||
)}
|
||||
{...ui('root')}
|
||||
style={
|
||||
backgroundOpacity === undefined
|
||||
? undefined
|
||||
@@ -31,7 +29,7 @@ const SpinnerOverlay = ({ size, fixed, visible, backgroundOpacity, children }: P
|
||||
}
|
||||
>
|
||||
<Spinner size={size} />
|
||||
{children && <p className='mt-4 text-muted-foreground'>{children}</p>}
|
||||
{children && <p {...ui('text')}>{children}</p>}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import type React from 'react';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import Icon from '@/components/elements/Icon';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { cardTitleClass } from '@/components/ui/typography';
|
||||
import { isString } from '@/lib/objects';
|
||||
import Card from '@/components/elements/Card';
|
||||
|
||||
interface Props {
|
||||
icon?: LucideIcon;
|
||||
@@ -13,20 +10,11 @@ interface Props {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
/** A `Card` with a header. */
|
||||
const TitledGreyBox = ({ icon, title, children, className, contentClassName }: Props) => (
|
||||
<div className={cn('rounded-sm shadow-md bg-card', className)}>
|
||||
<div className='bg-muted rounded-t-sm p-3 border-b border-border'>
|
||||
{isString(title) ? (
|
||||
<h2 className={cardTitleClass}>
|
||||
{icon && <Icon icon={icon} className='mr-2 text-muted-foreground' />}
|
||||
{title}
|
||||
</h2>
|
||||
) : (
|
||||
title
|
||||
)}
|
||||
</div>
|
||||
<div className={cn('p-3', contentClassName)}>{children}</div>
|
||||
</div>
|
||||
<Card title={title} icon={icon} className={className} bodyClassName={contentClassName}>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
|
||||
export default TitledGreyBox;
|
||||
|
||||
@@ -1,57 +1,38 @@
|
||||
import { CheckCircle2, Info, ShieldAlert, TriangleAlert, type LucideIcon } from 'lucide-react';
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
export type AlertType = 'success' | 'info' | 'warning' | 'danger';
|
||||
|
||||
interface AlertProps {
|
||||
export interface AlertProps {
|
||||
type: AlertType;
|
||||
title?: React.ReactNode;
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const alertConfig = {
|
||||
success: {
|
||||
icon: CheckCircle2,
|
||||
className: 'border-success bg-success/15',
|
||||
iconClassName: 'text-success',
|
||||
},
|
||||
info: {
|
||||
icon: Info,
|
||||
className: 'border-accent bg-accent/10',
|
||||
iconClassName: 'text-accent',
|
||||
},
|
||||
warning: {
|
||||
icon: TriangleAlert,
|
||||
className: 'border-warning bg-warning/15',
|
||||
iconClassName: 'text-warning',
|
||||
},
|
||||
danger: {
|
||||
icon: ShieldAlert,
|
||||
className: 'border-destructive bg-destructive/15',
|
||||
iconClassName: 'text-destructive',
|
||||
},
|
||||
} satisfies Record<AlertType, { icon: LucideIcon; className: string; iconClassName: string }>;
|
||||
const icons = {
|
||||
success: CheckCircle2,
|
||||
info: Info,
|
||||
warning: TriangleAlert,
|
||||
danger: ShieldAlert,
|
||||
} satisfies Record<AlertType, LucideIcon>;
|
||||
|
||||
export default function Alert({ type, title, className, children }: AlertProps) {
|
||||
const config = alertConfig[type];
|
||||
const AlertIcon = config.icon;
|
||||
function CoreAlert({ type, title, className, children }: AlertProps) {
|
||||
const ui = useSkin('Alert', { type });
|
||||
const AlertIcon = icons[type];
|
||||
|
||||
return (
|
||||
<div
|
||||
role='alert'
|
||||
className={cn(
|
||||
'flex items-start rounded-sm border border-l-4 px-4 py-3 text-foreground shadow-sm',
|
||||
config.className,
|
||||
className
|
||||
)}
|
||||
>
|
||||
<AlertIcon aria-hidden className={cn('mr-3 mt-0.5 h-5 w-5 shrink-0', config.iconClassName)} />
|
||||
<div className='min-w-0 flex-1 text-sm leading-relaxed'>
|
||||
{title && <p className='mb-1 font-semibold text-foreground'>{title}</p>}
|
||||
<div>{children}</div>
|
||||
<div role='alert' {...ui('root', className)}>
|
||||
<AlertIcon aria-hidden {...ui('icon')} />
|
||||
<div {...ui('body')}>
|
||||
{title && <p {...ui('title')}>{title}</p>}
|
||||
<div {...ui('content')}>{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const Alert = replaceable('Alert', CoreAlert);
|
||||
|
||||
export default Alert;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export { default as Alert } from './Alert';
|
||||
export type { AlertType } from './Alert';
|
||||
export type { AlertProps, AlertType } from './Alert';
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { Dialog as BaseDialog } from '@base-ui/react/dialog';
|
||||
import Button from '@/components/elements/Button';
|
||||
import { X } from 'lucide-react';
|
||||
import { Check, Info, ShieldAlert, TriangleAlert, X } from 'lucide-react';
|
||||
import { useSkin, type SkinBinding } from '@/themes/skins';
|
||||
import { DialogContext } from './context';
|
||||
import DialogFooter from './DialogFooter';
|
||||
import type { IconPosition, RenderDialogProps } from './types';
|
||||
import { dialogTitleClass } from '@/components/ui/typography';
|
||||
import { cn } from '@/lib/cn';
|
||||
import type { DialogIconProps, IconPosition, RenderDialogProps } from './types';
|
||||
|
||||
const focusableSelector =
|
||||
':is(input, select, textarea, button, a[href], [tabindex]):not([disabled]):not([tabindex="-1"])';
|
||||
const dialogContainerClass = 'flex min-h-full items-center justify-center p-4 text-center';
|
||||
const closeIconClass = 'w-5 h-5 group-hover:rotate-90 transition-transform duration-100';
|
||||
const backdropClass = [
|
||||
'fixed inset-0 bg-background/50 z-40 transition-opacity duration-150 ease-out',
|
||||
'data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 data-[ending-style]:ease-in',
|
||||
].join(' ');
|
||||
const panelClass = [
|
||||
'relative flex flex-col overflow-hidden bg-card rounded-sm max-w-xl w-full mx-auto shadow-lg text-left',
|
||||
'max-h-[calc(100dvh-2rem)] ring-4 ring-border/80 transition duration-150 ease-out',
|
||||
'data-[starting-style]:opacity-0 data-[starting-style]:scale-75',
|
||||
'data-[ending-style]:opacity-0 data-[ending-style]:scale-75 data-[ending-style]:ease-in',
|
||||
].join(' ');
|
||||
|
||||
const icons = {
|
||||
danger: ShieldAlert,
|
||||
warning: TriangleAlert,
|
||||
success: Check,
|
||||
info: Info,
|
||||
};
|
||||
|
||||
function TypeIcon({ ui, icon }: { ui: SkinBinding<'Dialog'>; icon: DialogIconProps }) {
|
||||
const Glyph = icons[icon.type];
|
||||
|
||||
return (
|
||||
<div {...ui('icon', icon.className, { type: icon.type })}>
|
||||
<Glyph {...ui('iconGlyph')} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function DialogComponent({
|
||||
open,
|
||||
@@ -32,9 +36,11 @@ export default function DialogComponent({
|
||||
preventExternalClose,
|
||||
children,
|
||||
}: RenderDialogProps) {
|
||||
const [icon, setIcon] = useState<React.ReactNode>();
|
||||
const [icon, setIcon] = useState<DialogIconProps>();
|
||||
const [iconPosition, setIconPosition] = useState<IconPosition>('title');
|
||||
const popupRef = React.useRef<HTMLDivElement>(null);
|
||||
const described = !!description;
|
||||
const ui = useSkin('Dialog', { described });
|
||||
|
||||
const initialFocus = (interactionType: string) => {
|
||||
if (interactionType === 'touch') {
|
||||
@@ -55,61 +61,52 @@ export default function DialogComponent({
|
||||
onClose();
|
||||
};
|
||||
|
||||
const context = useMemo(() => ({ setIcon, setIconPosition }), [setIcon, setIconPosition]);
|
||||
const context = useMemo(() => ({ setIcon, setIconPosition, described }), [setIcon, setIconPosition, described]);
|
||||
|
||||
const items = React.Children.toArray(children);
|
||||
const isFooter = (child: React.ReactNode) => React.isValidElement(child) && child.type === DialogFooter;
|
||||
const footer = items.filter(isFooter);
|
||||
const content = items.filter((child) => !isFooter(child));
|
||||
const typeIcon = icon && <TypeIcon ui={ui} icon={icon} />;
|
||||
|
||||
return (
|
||||
<DialogContext.Provider value={context}>
|
||||
{/* Base UI unmounts the popup after its data-ending-style transition finishes. */}
|
||||
<BaseDialog.Root open={open} onOpenChange={onOpenChange}>
|
||||
<BaseDialog.Portal>
|
||||
<BaseDialog.Backdrop className={backdropClass} />
|
||||
<div className='fixed inset-0 overflow-y-auto z-50'>
|
||||
<div className={dialogContainerClass}>
|
||||
<BaseDialog.Popup ref={popupRef} className={panelClass} initialFocus={initialFocus}>
|
||||
<div className='flex min-h-0 flex-1 overflow-y-auto p-6 pb-0'>
|
||||
{iconPosition === 'container' && icon}
|
||||
<div className='flex-1 min-w-0'>
|
||||
<div className='flex items-center'>
|
||||
{iconPosition !== 'container' && icon}
|
||||
<div>
|
||||
{title && (
|
||||
<BaseDialog.Title
|
||||
className={cn(
|
||||
dialogTitleClass,
|
||||
description ? 'mb-2' : 'mb-5',
|
||||
'pr-4'
|
||||
)}
|
||||
>
|
||||
{title}
|
||||
</BaseDialog.Title>
|
||||
)}
|
||||
<BaseDialog.Backdrop {...ui('backdrop')} />
|
||||
<div {...ui('viewport')}>
|
||||
<div {...ui('container')}>
|
||||
<BaseDialog.Popup ref={popupRef} {...ui('root')} initialFocus={initialFocus}>
|
||||
<div {...ui('body')}>
|
||||
{iconPosition === 'container' && typeIcon}
|
||||
<div {...ui('content')}>
|
||||
<div {...ui('header')}>
|
||||
{iconPosition !== 'container' && typeIcon}
|
||||
<div {...ui('heading')}>
|
||||
{title && <BaseDialog.Title {...ui('title')}>{title}</BaseDialog.Title>}
|
||||
{description && (
|
||||
<BaseDialog.Description className='mb-5 text-sm leading-relaxed text-muted-foreground'>
|
||||
<BaseDialog.Description {...ui('description')}>
|
||||
{description}
|
||||
</BaseDialog.Description>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{content}
|
||||
<div className='invisible h-6' />
|
||||
<div {...ui('spacer')} />
|
||||
</div>
|
||||
</div>
|
||||
{footer}
|
||||
{/* Rendered after the other buttons so it is not the default focus. */}
|
||||
{!hideCloseIcon && (
|
||||
<div className='absolute right-0 top-0 m-4'>
|
||||
<div {...ui('close')}>
|
||||
<Button.Text
|
||||
type='button'
|
||||
size='xsmall'
|
||||
onClick={onClose}
|
||||
className='group w-8 h-8 p-0 inline-flex items-center justify-center'
|
||||
className={ui.classes('closeButton')}
|
||||
>
|
||||
<X className={closeIconClass} />
|
||||
<X {...ui('closeIcon')} />
|
||||
</Button.Text>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import React from 'react';
|
||||
import React, { use } from 'react';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
import { DialogContext } from './context';
|
||||
|
||||
const DialogFooter = ({ children }: { children: React.ReactNode }) => (
|
||||
<div className='px-6 py-3 bg-card flex items-center justify-end space-x-3 rounded-b-sm'>{children}</div>
|
||||
);
|
||||
const DialogFooter = ({ children }: { children: React.ReactNode }) => {
|
||||
const ui = useSkin('Dialog', { described: use(DialogContext).described });
|
||||
|
||||
return <div {...ui('footer')}>{children}</div>;
|
||||
};
|
||||
|
||||
export default DialogFooter;
|
||||
|
||||
@@ -1,35 +1,13 @@
|
||||
import { use, useEffect } from 'react';
|
||||
import { Check, TriangleAlert, Info, ShieldAlert } from 'lucide-react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { DialogContext } from './context';
|
||||
import type { DialogIconProps } from './types';
|
||||
|
||||
const icons = {
|
||||
danger: ShieldAlert,
|
||||
warning: TriangleAlert,
|
||||
success: Check,
|
||||
info: Info,
|
||||
};
|
||||
|
||||
const iconClass = 'flex items-center justify-center w-10 h-10 rounded-full mr-4';
|
||||
const iconTypeClass = {
|
||||
danger: 'bg-destructive text-destructive-foreground',
|
||||
warning: 'bg-warning text-warning-foreground',
|
||||
success: 'bg-success text-success-foreground',
|
||||
info: 'bg-primary text-primary-foreground',
|
||||
};
|
||||
|
||||
/** Places a type icon beside the dialog title, or beside the whole content with `position="container"`. */
|
||||
const DialogIcon = ({ type, position, className }: DialogIconProps) => {
|
||||
const { setIcon, setIconPosition } = use(DialogContext);
|
||||
|
||||
useEffect(() => {
|
||||
const Icon = icons[type];
|
||||
|
||||
setIcon(
|
||||
<div className={cn(iconClass, iconTypeClass[type], className)}>
|
||||
<Icon className='w-6 h-6' />
|
||||
</div>
|
||||
);
|
||||
setIcon({ type, className });
|
||||
|
||||
return () => setIcon(undefined);
|
||||
}, [className, setIcon, type]);
|
||||
|
||||
@@ -4,4 +4,5 @@ import type { DialogContextType } from './types';
|
||||
export const DialogContext = React.createContext<DialogContextType>({
|
||||
setIcon: () => null,
|
||||
setIconPosition: () => null,
|
||||
described: false,
|
||||
});
|
||||
|
||||
+3
-1
@@ -24,6 +24,8 @@ export interface RenderDialogProps extends DialogProps {
|
||||
}
|
||||
|
||||
export interface DialogContextType {
|
||||
setIcon: Callback<React.ReactNode>;
|
||||
setIcon: Callback<DialogIconProps | undefined>;
|
||||
setIconPosition: Callback<IconPosition>;
|
||||
/** The state the dialog's skin reads, for parts rendered by its children. */
|
||||
described: boolean;
|
||||
}
|
||||
|
||||
@@ -2,22 +2,14 @@ import React, { use } from 'react';
|
||||
import { Menu } from '@base-ui/react/menu';
|
||||
import { ContextMenu } from '@base-ui/react/context-menu';
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import Icon from '@/components/elements/Icon';
|
||||
|
||||
const positionerClass = 'z-[9999] outline-hidden';
|
||||
|
||||
const popupClass =
|
||||
'min-w-56 bg-popover border border-border rounded-sm shadow-xl p-1.5 text-sm text-popover-foreground ' +
|
||||
'outline-hidden origin-[var(--transform-origin)] transition duration-100 ' +
|
||||
'data-[starting-style]:opacity-0 data-[starting-style]:scale-95 ' +
|
||||
'data-[ending-style]:opacity-0 data-[ending-style]:scale-95';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
type MenuItemComponent = React.ComponentType<React.ComponentProps<typeof Menu.Item>>;
|
||||
const MenuItemContext = React.createContext<MenuItemComponent>(Menu.Item as MenuItemComponent);
|
||||
const ContextMenuItem = (props: React.ComponentProps<typeof Menu.Item>) => <ContextMenu.Item {...props} />;
|
||||
|
||||
interface DropdownMenuProps {
|
||||
export interface DropdownMenuProps {
|
||||
/** Rendered inside the trigger `<button>`. */
|
||||
triggerContent: React.ReactNode;
|
||||
triggerClassName?: string;
|
||||
@@ -27,14 +19,20 @@ interface DropdownMenuProps {
|
||||
}
|
||||
|
||||
function DropdownMenu({ triggerContent, triggerClassName, openOnHover, children, className }: DropdownMenuProps) {
|
||||
const ui = useSkin('DropdownMenu', { context: false });
|
||||
|
||||
return (
|
||||
<Menu.Root>
|
||||
<Menu.Trigger className={triggerClassName} openOnHover={openOnHover} closeDelay={openOnHover ? 150 : 0}>
|
||||
<Menu.Trigger
|
||||
{...ui('trigger', triggerClassName)}
|
||||
openOnHover={openOnHover}
|
||||
closeDelay={openOnHover ? 150 : 0}
|
||||
>
|
||||
{triggerContent}
|
||||
</Menu.Trigger>
|
||||
<Menu.Portal>
|
||||
<Menu.Positioner className={positionerClass} sideOffset={4} align='end'>
|
||||
<Menu.Popup className={cn(popupClass, className)}>
|
||||
<Menu.Positioner {...ui('positioner')} sideOffset={4} align='end'>
|
||||
<Menu.Popup {...ui('root', className)}>
|
||||
<MenuItemContext.Provider value={Menu.Item as MenuItemComponent}>
|
||||
{children}
|
||||
</MenuItemContext.Provider>
|
||||
@@ -45,7 +43,7 @@ function DropdownMenu({ triggerContent, triggerClassName, openOnHover, children,
|
||||
);
|
||||
}
|
||||
|
||||
interface ContextDropdownMenuProps {
|
||||
export interface ContextDropdownMenuProps {
|
||||
className?: string;
|
||||
menuClassName?: string;
|
||||
children: React.ReactNode;
|
||||
@@ -54,12 +52,14 @@ interface ContextDropdownMenuProps {
|
||||
|
||||
/** Opens `items` at the cursor on right-click or long-press over `children`. */
|
||||
export function ContextDropdownMenu({ className, menuClassName, children, items }: ContextDropdownMenuProps) {
|
||||
const ui = useSkin('DropdownMenu', { context: true });
|
||||
|
||||
return (
|
||||
<ContextMenu.Root>
|
||||
<ContextMenu.Trigger className={className}>{children}</ContextMenu.Trigger>
|
||||
<ContextMenu.Trigger {...ui('trigger', className)}>{children}</ContextMenu.Trigger>
|
||||
<ContextMenu.Portal>
|
||||
<ContextMenu.Positioner className={positionerClass}>
|
||||
<ContextMenu.Popup className={cn(popupClass, menuClassName)}>
|
||||
<ContextMenu.Positioner {...ui('positioner')}>
|
||||
<ContextMenu.Popup {...ui('root', menuClassName)}>
|
||||
<MenuItemContext.Provider value={ContextMenuItem}>{items}</MenuItemContext.Provider>
|
||||
</ContextMenu.Popup>
|
||||
</ContextMenu.Positioner>
|
||||
@@ -68,53 +68,28 @@ export function ContextDropdownMenu({ className, menuClassName, children, items
|
||||
);
|
||||
}
|
||||
|
||||
interface ItemProps extends React.ComponentProps<typeof Menu.Item> {
|
||||
export interface DropdownMenuItemProps extends Omit<React.ComponentProps<typeof Menu.Item>, 'className'> {
|
||||
className?: string;
|
||||
icon?: LucideIcon;
|
||||
danger?: boolean;
|
||||
description?: React.ReactNode;
|
||||
}
|
||||
|
||||
/** An item for either DropdownMenu or ContextDropdownMenu. */
|
||||
export function DropdownMenuItem({ icon, danger, description, className, children, ...props }: ItemProps) {
|
||||
export function DropdownMenuItem({ icon, danger, description, className, children, ...props }: DropdownMenuItemProps) {
|
||||
const Item = use(MenuItemContext);
|
||||
const ui = useSkin('DropdownMenuItem', { danger: !!danger, described: !!description });
|
||||
|
||||
return (
|
||||
<Item
|
||||
className={cn(
|
||||
'group flex w-full gap-3 px-2.5 py-2.5 rounded-sm cursor-pointer select-none outline-hidden',
|
||||
description ? 'items-start' : 'items-center',
|
||||
'text-foreground transition-colors data-[highlighted]:bg-muted data-[highlighted]:text-foreground',
|
||||
danger && 'text-destructive data-[highlighted]:bg-destructive/10 data-[highlighted]:text-destructive',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<Item {...ui('root', className)} {...props}>
|
||||
{icon && (
|
||||
<span
|
||||
className={cn(
|
||||
'flex h-7 w-7 shrink-0 items-center justify-center rounded-sm border border-border bg-muted text-muted-foreground transition-colors',
|
||||
description && 'mt-0.5',
|
||||
'group-data-[highlighted]:border-border group-data-[highlighted]:bg-background group-data-[highlighted]:text-foreground',
|
||||
danger &&
|
||||
'border-destructive/30 bg-destructive/10 text-destructive group-data-[highlighted]:border-destructive/40 group-data-[highlighted]:bg-destructive/15 group-data-[highlighted]:text-destructive'
|
||||
)}
|
||||
>
|
||||
<Icon icon={icon} className='h-4 w-4' />
|
||||
<span {...ui('icon')}>
|
||||
<Icon icon={icon} {...ui('glyph')} />
|
||||
</span>
|
||||
)}
|
||||
<span className='flex min-w-0 flex-1 flex-col'>
|
||||
<span className='truncate text-sm font-medium leading-5'>{children}</span>
|
||||
{description && (
|
||||
<span
|
||||
className={cn(
|
||||
'mt-0.5 text-xs leading-4 text-muted-foreground',
|
||||
'group-data-[highlighted]:text-muted-foreground',
|
||||
danger && 'group-data-[highlighted]:text-destructive/80'
|
||||
)}
|
||||
>
|
||||
{description}
|
||||
</span>
|
||||
)}
|
||||
<span {...ui('text')}>
|
||||
<span {...ui('label')}>{children}</span>
|
||||
{description && <span {...ui('description')}>{description}</span>}
|
||||
</span>
|
||||
</Item>
|
||||
);
|
||||
|
||||
@@ -131,7 +131,11 @@ describe('DataTable', () => {
|
||||
|
||||
render(<StringTable />);
|
||||
|
||||
expect(screen.getByText('No rows')).toHaveAttribute('data-slot', 'empty-description');
|
||||
const description = screen.getByText('No rows');
|
||||
|
||||
expect(description).toHaveAttribute('data-ui', 'empty');
|
||||
expect(description).toHaveAttribute('data-part', 'description');
|
||||
expect(description.parentElement).toHaveAttribute('data-size', 'compact');
|
||||
});
|
||||
|
||||
it('reports the sort state of hidden sort columns on the header that controls them', () => {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import React from 'react';
|
||||
import { flexRender, type Column, type RowData, type Table as TanStackTable } from '@tanstack/react-table';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { isString } from '@/lib/objects';
|
||||
import { Empty, EmptyDescription } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
declare module '@tanstack/react-table' {
|
||||
interface ColumnMeta<TData extends RowData, TValue> {
|
||||
@@ -14,7 +13,7 @@ declare module '@tanstack/react-table' {
|
||||
}
|
||||
}
|
||||
|
||||
interface Props<TData extends RowData> {
|
||||
export interface DataTableProps<TData extends RowData> {
|
||||
table: TanStackTable<TData>;
|
||||
/** Replaces the table when there are no rows; a string renders as a compact `Empty` description. */
|
||||
emptyState: React.ReactNode;
|
||||
@@ -49,18 +48,16 @@ export default function DataTable<TData extends RowData>({
|
||||
className,
|
||||
tableClassName,
|
||||
isFetching = false,
|
||||
}: Props<TData>) {
|
||||
}: DataTableProps<TData>) {
|
||||
const rows = table.getRowModel().rows;
|
||||
const ui = useSkin('Table', { fetching: isFetching });
|
||||
|
||||
return (
|
||||
<div
|
||||
aria-busy={isFetching}
|
||||
className={cn('@container overflow-hidden rounded-sm border border-border bg-card', className)}
|
||||
>
|
||||
<div aria-busy={isFetching} {...ui('root', className)}>
|
||||
{rows.length === 0 ? (
|
||||
<div className={cn('flex transition-opacity', isFetching && 'opacity-55')}>
|
||||
<div {...ui('empty')}>
|
||||
{isString(emptyState) ? (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyDescription>{emptyState}</EmptyDescription>
|
||||
</Empty>
|
||||
) : (
|
||||
@@ -68,20 +65,17 @@ export default function DataTable<TData extends RowData>({
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className='overflow-x-auto scrollbar-thin scrollbar-thumb-(--scrollbar-thumb)'>
|
||||
<table className={cn('w-full border-collapse text-left text-sm', tableClassName)}>
|
||||
<thead className='border-b border-border bg-muted/70'>
|
||||
<div {...ui('scroller')}>
|
||||
<table {...ui('table', tableClassName)}>
|
||||
<thead {...ui('head')}>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<tr key={headerGroup.id}>
|
||||
<tr key={headerGroup.id} {...ui('headerRow')}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<th
|
||||
key={header.id}
|
||||
scope='col'
|
||||
aria-sort={ariaSort(table, header.column)}
|
||||
className={cn(
|
||||
'h-10 whitespace-nowrap px-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground',
|
||||
header.column.columnDef.meta?.headerClassName
|
||||
)}
|
||||
{...ui('headerCell', header.column.columnDef.meta?.headerClassName)}
|
||||
>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
@@ -91,17 +85,11 @@ export default function DataTable<TData extends RowData>({
|
||||
</tr>
|
||||
))}
|
||||
</thead>
|
||||
<tbody className={cn('divide-y divide-border transition-opacity', isFetching && 'opacity-55')}>
|
||||
<tbody {...ui('body')}>
|
||||
{rows.map((row) => (
|
||||
<tr key={row.id} className='transition-colors hover:bg-muted/35'>
|
||||
<tr key={row.id} {...ui('row')}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<td
|
||||
key={cell.id}
|
||||
className={cn(
|
||||
'px-3 py-2.5 align-middle text-foreground',
|
||||
cell.column.columnDef.meta?.cellClassName
|
||||
)}
|
||||
>
|
||||
<td key={cell.id} {...ui('cell', cell.column.columnDef.meta?.cellClassName)}>
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
</td>
|
||||
))}
|
||||
|
||||
@@ -2,13 +2,15 @@ import type { ComponentProps, ReactElement, ReactNode } from 'react';
|
||||
import type { ColumnDef } from '@tanstack/react-table';
|
||||
import { Link, type AnyRouter, type LinkComponentProps, type RegisteredRouter } from '@tanstack/react-router';
|
||||
import { MoreHorizontal, Pencil, Trash2, type LucideIcon } from 'lucide-react';
|
||||
import Button, { buttonClassName } from '@/components/elements/Button';
|
||||
import Button from '@/components/elements/Button';
|
||||
import DropdownMenu from '@/components/elements/dropdown/DropdownMenu';
|
||||
import Icon from '@/components/elements/Icon';
|
||||
import Tooltip from '@/components/elements/tooltip/Tooltip';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
const iconClassName = 'h-3.5 w-3.5';
|
||||
const actionClassName = buttonClassName({ color: 'grey', size: 'xsmall', isSecondary: true });
|
||||
/** Links and menu triggers look like the row's icon buttons. */
|
||||
const useActionButton = () => useSkin('Button', { color: 'grey', size: 'xsmall', secondary: true, loading: false });
|
||||
|
||||
type RowActionCount = 1 | 2 | 3;
|
||||
|
||||
@@ -84,9 +86,11 @@ export function EditLinkAction<
|
||||
const TMaskFrom extends string = TFrom,
|
||||
const TMaskTo extends string = '',
|
||||
>(props: LinkComponentProps<'a', TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & { 'aria-label': string }) {
|
||||
const button = useActionButton();
|
||||
|
||||
return (
|
||||
<ActionTooltip content='Edit'>
|
||||
<Link {...props} className={actionClassName}>
|
||||
<Link {...props} {...button('root')}>
|
||||
<Icon icon={Pencil} className={iconClassName} />
|
||||
</Link>
|
||||
</ActionTooltip>
|
||||
@@ -95,9 +99,11 @@ export function EditLinkAction<
|
||||
|
||||
/** The "…" menu for actions other than edit and delete. */
|
||||
export function RowActionsMenu({ label, children }: { label: string; children: ReactNode }) {
|
||||
const button = useActionButton();
|
||||
|
||||
return (
|
||||
<DropdownMenu
|
||||
triggerClassName={actionClassName}
|
||||
triggerClassName={button.classes('root')}
|
||||
triggerContent={
|
||||
<>
|
||||
<Icon icon={MoreHorizontal} className={iconClassName} />
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
useMergeRefs,
|
||||
useTransitionStyles,
|
||||
} from '@floating-ui/react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { useSkin, type SkinBinding } from '@/themes/skins';
|
||||
|
||||
type Interaction = 'hover' | 'click' | 'focus';
|
||||
type TooltipChildProps = React.DOMAttributes<Element> &
|
||||
@@ -25,7 +25,7 @@ type TooltipChildProps = React.DOMAttributes<Element> &
|
||||
className?: string;
|
||||
};
|
||||
|
||||
interface Props {
|
||||
export interface TooltipProps {
|
||||
rest?: number;
|
||||
delay?: number | Partial<{ open: number; close: number }>;
|
||||
content: string | React.ReactNode;
|
||||
@@ -37,14 +37,7 @@ interface Props {
|
||||
children: React.ReactElement<TooltipChildProps>;
|
||||
}
|
||||
|
||||
const arrowSides = {
|
||||
top: 'bottom-[-6px] left-0',
|
||||
bottom: 'top-[-6px] left-0',
|
||||
right: 'top-0 left-[-6px]',
|
||||
left: 'top-0 right-[-6px]',
|
||||
} satisfies Record<Side, string>;
|
||||
|
||||
type TooltipInteractionOptions = Pick<Props, 'interactions' | 'rest' | 'delay'>;
|
||||
type TooltipInteractionOptions = Pick<TooltipProps, 'interactions' | 'rest' | 'delay'>;
|
||||
|
||||
function useTooltipInteractions(
|
||||
context: FloatingContext,
|
||||
@@ -67,25 +60,18 @@ function useTooltipInteractions(
|
||||
|
||||
type TooltipArrowProps = {
|
||||
ref: React.Ref<HTMLDivElement>;
|
||||
placement: Placement;
|
||||
ui: SkinBinding<'Tooltip'>;
|
||||
position?: { x?: number; y?: number };
|
||||
};
|
||||
|
||||
function TooltipArrow({ ref, placement, position }: TooltipArrowProps) {
|
||||
const side = arrowSides[placement.split('-')[0] as Side];
|
||||
function TooltipArrow({ ref, ui, position }: TooltipArrowProps) {
|
||||
const x = Math.round(position?.x || 0);
|
||||
const y = Math.round(position?.y || 0);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
style={{ transform: `translate(${x}px, ${y}px) rotate(45deg)` }}
|
||||
className={cn('absolute bg-popover w-3 h-3', side)}
|
||||
/>
|
||||
);
|
||||
return <div ref={ref} style={{ transform: `translate(${x}px, ${y}px) rotate(45deg)` }} {...ui('arrow')} />;
|
||||
}
|
||||
|
||||
export default function Tooltip({ children, ...props }: Props) {
|
||||
export default function Tooltip({ children, ...props }: TooltipProps) {
|
||||
const arrowEl = useRef<HTMLDivElement>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const enabled = !props.disabled;
|
||||
@@ -120,6 +106,7 @@ export default function Tooltip({ children, ...props }: Props) {
|
||||
});
|
||||
|
||||
const referenceRef = useMergeRefs([refs.setReference, children.props.ref]);
|
||||
const ui = useSkin('Tooltip', { side: placement.split('-')[0] as Side, arrow: !!props.arrow });
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -129,17 +116,12 @@ export default function Tooltip({ children, ...props }: Props) {
|
||||
<div
|
||||
{...getFloatingProps({
|
||||
ref: refs.setFloating,
|
||||
className: cn(
|
||||
'bg-popover text-sm text-popover-foreground px-3 py-2 rounded-sm pointer-events-none max-w-[24rem] z-9999',
|
||||
props.className
|
||||
),
|
||||
...ui('root', props.className),
|
||||
style: { ...floatingStyles, ...transitionStyles },
|
||||
})}
|
||||
>
|
||||
{props.content}
|
||||
{props.arrow && (
|
||||
<TooltipArrow ref={arrowEl} placement={placement} position={middlewareData.arrow} />
|
||||
)}
|
||||
{props.arrow && <TooltipArrow ref={arrowEl} ui={ui} position={middlewareData.arrow} />}
|
||||
</div>
|
||||
</FloatingPortal>
|
||||
)}
|
||||
|
||||
@@ -1,69 +1,44 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { Input as BaseInput } from '@base-ui/react/input';
|
||||
import { NumberField } from '@base-ui/react/number-field';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
interface ThemeProps {
|
||||
$isLight?: boolean;
|
||||
$hasError?: boolean;
|
||||
}
|
||||
|
||||
const controlBaseClass = [
|
||||
'resize-none appearance-none outline-hidden w-full min-w-0',
|
||||
'p-3 border-2 rounded-sm text-sm transition-[background-color,border-color,color,box-shadow] duration-150',
|
||||
'bg-input border-input hover:border-input text-foreground shadow-none focus:ring-0',
|
||||
'focus:shadow-md focus:border-primary focus:ring-2 focus:ring-ring/50',
|
||||
'disabled:opacity-75 read-only:cursor-text read-only:bg-muted/40',
|
||||
'required:shadow-none invalid:shadow-none',
|
||||
].join(' ');
|
||||
|
||||
const lightClass =
|
||||
'bg-background border-border text-foreground focus:border-primary disabled:bg-muted disabled:border-border';
|
||||
const errorClass = [
|
||||
'text-destructive border-destructive hover:border-destructive',
|
||||
'focus:border-destructive focus:ring-destructive',
|
||||
].join(' ');
|
||||
|
||||
const controlClass = ({ $isLight, $hasError }: ThemeProps, className?: string): string =>
|
||||
cn(controlBaseClass, $isLight && lightClass, $hasError && errorClass, className);
|
||||
const controlState = ({ $isLight, $hasError }: ThemeProps) => ({ light: !!$isLight, error: !!$hasError });
|
||||
|
||||
type WithStringClassName<TProps> = Omit<TProps, 'className'> & { className?: string };
|
||||
|
||||
type TextInputProps = ThemeProps & WithStringClassName<React.ComponentProps<typeof BaseInput>>;
|
||||
type NumberInputProps = ThemeProps &
|
||||
export type TextInputProps = ThemeProps & WithStringClassName<React.ComponentProps<typeof BaseInput>>;
|
||||
export type TextAreaProps = ThemeProps & React.ComponentProps<'textarea'>;
|
||||
export type NumberInputProps = ThemeProps &
|
||||
Pick<
|
||||
React.ComponentProps<typeof NumberField.Root>,
|
||||
'value' | 'onValueChange' | 'min' | 'max' | 'step' | 'format' | 'disabled'
|
||||
> &
|
||||
WithStringClassName<Omit<React.ComponentProps<typeof NumberField.Input>, 'value' | 'onChange' | 'disabled'>>;
|
||||
export type FileInputProps = Omit<React.ComponentProps<'input'>, 'type'>;
|
||||
|
||||
export const TextInput = ({ $isLight, $hasError, className, ...props }: TextInputProps) => (
|
||||
<BaseInput className={controlClass({ $isLight, $hasError }, className)} {...props} />
|
||||
);
|
||||
export const TextInput = ({ $isLight, $hasError, className, ...props }: TextInputProps) => {
|
||||
const ui = useSkin('Input', controlState({ $isLight, $hasError }));
|
||||
|
||||
export const FileInput = ({ className, ...props }: Omit<React.ComponentProps<'input'>, 'type'>) => (
|
||||
<input
|
||||
{...props}
|
||||
type='file'
|
||||
className={cn(
|
||||
'block w-full min-w-0 rounded-sm text-sm text-foreground',
|
||||
'file:mr-3 file:rounded-sm file:border file:border-border file:bg-popover file:px-4 file:py-2 file:text-sm file:font-medium file:text-foreground',
|
||||
'enabled:cursor-pointer enabled:file:cursor-pointer enabled:hover:file:bg-secondary',
|
||||
'focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card',
|
||||
'disabled:cursor-default disabled:opacity-50',
|
||||
className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
return <BaseInput {...ui('root', className)} {...props} />;
|
||||
};
|
||||
|
||||
export const TextArea = ({
|
||||
$isLight,
|
||||
$hasError,
|
||||
className,
|
||||
...props
|
||||
}: ThemeProps & React.ComponentProps<'textarea'>) => (
|
||||
<textarea className={controlClass({ $isLight, $hasError }, className)} {...props} />
|
||||
);
|
||||
export const FileInput = ({ className, ...props }: FileInputProps) => {
|
||||
const ui = useSkin('FileInput', {});
|
||||
|
||||
return <input {...props} type='file' {...ui('root', className)} />;
|
||||
};
|
||||
|
||||
export const TextArea = ({ $isLight, $hasError, className, ...props }: TextAreaProps) => {
|
||||
const ui = useSkin('TextArea', controlState({ $isLight, $hasError }));
|
||||
|
||||
return <textarea {...ui('root', className)} {...props} />;
|
||||
};
|
||||
|
||||
export const NumberInput = ({
|
||||
$isLight,
|
||||
@@ -77,16 +52,21 @@ export const NumberInput = ({
|
||||
format,
|
||||
disabled,
|
||||
...props
|
||||
}: NumberInputProps) => (
|
||||
<NumberField.Root
|
||||
value={value}
|
||||
onValueChange={onValueChange}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
format={{ useGrouping: false, ...format }}
|
||||
disabled={disabled}
|
||||
>
|
||||
<NumberField.Input className={controlClass({ $isLight, $hasError }, className)} {...props} />
|
||||
</NumberField.Root>
|
||||
);
|
||||
}: NumberInputProps) => {
|
||||
const ui = useSkin('NumberInput', controlState({ $isLight, $hasError }));
|
||||
|
||||
return (
|
||||
<NumberField.Root
|
||||
{...ui('root')}
|
||||
value={value}
|
||||
onValueChange={onValueChange}
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
format={{ useGrouping: false, ...format }}
|
||||
disabled={disabled}
|
||||
>
|
||||
<NumberField.Input {...ui('input', className)} {...props} />
|
||||
</NumberField.Root>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -21,7 +21,6 @@ import { SocketEvent } from '@/components/server/events';
|
||||
import useWebsocketEvent from '@/plugins/useWebsocketEvent';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
|
||||
const backupUsage = (limit: number, count: number, hasBackups: boolean, canCreate: boolean): string | null => {
|
||||
if (limit === 0 && hasBackups) {
|
||||
@@ -37,7 +36,7 @@ const backupUsage = (limit: number, count: number, hasBackups: boolean, canCreat
|
||||
|
||||
function PastEndEmptyState({ onFirstPage }: { onFirstPage: () => void }) {
|
||||
return (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Archive />
|
||||
@@ -67,7 +66,7 @@ function BackupsEmptyState({ page, backupLimit, canAddBackup, onFirstPage }: Bac
|
||||
}
|
||||
|
||||
return (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Archive />
|
||||
|
||||
@@ -12,7 +12,6 @@ import { ServerError } from '@/components/elements/ScreenBlock';
|
||||
import DataTable from '@/components/elements/table/DataTable';
|
||||
import { databaseColumns } from '@/components/server/databases/DatabaseTable';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
|
||||
const databaseUsage = (canCreate: boolean, limit: number, count: number): string | null => {
|
||||
@@ -24,7 +23,7 @@ const databaseUsage = (canCreate: boolean, limit: number, count: number): string
|
||||
};
|
||||
|
||||
const DatabasesEmptyState = ({ databaseLimit, canAddDatabase }: { databaseLimit: number; canAddDatabase: boolean }) => (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Database />
|
||||
|
||||
@@ -17,7 +17,6 @@ import { ServerError } from '@/components/elements/ScreenBlock';
|
||||
import DataTable from '@/components/elements/table/DataTable';
|
||||
import { allocationColumns } from '@/components/server/network/AllocationTable';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
|
||||
const NetworkContainer = () => {
|
||||
@@ -64,7 +63,7 @@ const NetworkContainer = () => {
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Network />
|
||||
|
||||
@@ -14,7 +14,6 @@ import { Dialog } from '@/components/elements/dialog';
|
||||
import DataTable from '@/components/elements/table/DataTable';
|
||||
import { scheduleColumns } from '@/components/server/schedules/ScheduleTable';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
|
||||
const CreateScheduleButton = () => (
|
||||
@@ -58,7 +57,7 @@ const ScheduleContainer = () => {
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<CalendarClock />
|
||||
|
||||
@@ -22,7 +22,6 @@ import DataTable from '@/components/elements/table/DataTable';
|
||||
import { scheduleTaskColumns } from '@/components/server/schedules/ScheduleTaskTable';
|
||||
import { relationshipData } from '@/api/relationships';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
|
||||
const CronBox = ({ title, value }: { title: string; value: string }) => (
|
||||
@@ -123,7 +122,7 @@ const ScheduleDetails = ({ schedule }: { schedule: Schedule }) => {
|
||||
<DataTable
|
||||
table={table}
|
||||
emptyState={
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<ListTodo />
|
||||
|
||||
@@ -13,8 +13,6 @@ import { useServerStartup, useSetSelectedDockerImage } from '@/api/server/startu
|
||||
import Slot from '@/extensions/Slot';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { cn } from '@/lib/cn';
|
||||
|
||||
const StartupContainer = () => {
|
||||
const server = useCurrentServer()!;
|
||||
@@ -111,7 +109,7 @@ const StartupContainer = () => {
|
||||
</div>
|
||||
<h3 className='mt-8 mb-2 text-2xl'>Variables</h3>
|
||||
{data.data.length === 0 ? (
|
||||
<Empty className={cn(emptyCompactClass, 'border')}>
|
||||
<Empty size='compact' className='border'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Variable />
|
||||
|
||||
@@ -6,7 +6,6 @@ import Spinner from '@/components/elements/Spinner';
|
||||
import AddSubuserButton from '@/components/server/users/AddSubuserButton';
|
||||
import ListToolbar from '@/components/elements/ListToolbar';
|
||||
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
import { emptyCompactClass } from '@/components/ui/styles';
|
||||
import { usePermissions } from '@/plugins/usePermissions';
|
||||
import ServerContentBlock from '@/components/elements/ServerContentBlock';
|
||||
import { useServerSubusers } from '@/api/server/users/queries';
|
||||
@@ -25,7 +24,7 @@ const hasPermissionGroups = <T extends object>(permissions: T | undefined): bool
|
||||
};
|
||||
|
||||
const UsersEmptyState = ({ canCreate }: { canCreate: boolean }) => (
|
||||
<Empty className={emptyCompactClass}>
|
||||
<Empty size='compact'>
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant='icon'>
|
||||
<Users />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Checkbox as BaseCheckbox } from '@base-ui/react/checkbox';
|
||||
import { Check, Minus } from 'lucide-react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
export type CheckboxProps = Omit<
|
||||
React.ComponentProps<typeof BaseCheckbox.Root>,
|
||||
@@ -12,25 +12,18 @@ export type CheckboxProps = Omit<
|
||||
className?: string;
|
||||
};
|
||||
|
||||
const rootClass = [
|
||||
'flex items-center justify-center shrink-0 w-4 h-4 rounded-xs cursor-pointer',
|
||||
'bg-input border border-input text-primary-foreground transition-colors duration-75 hover:border-primary/70',
|
||||
'data-[checked]:bg-primary data-[checked]:border-transparent',
|
||||
'data-[indeterminate]:bg-primary data-[indeterminate]:border-transparent',
|
||||
'data-[disabled]:opacity-60 data-[disabled]:cursor-default',
|
||||
'[&_svg]:size-3.5',
|
||||
].join(' ');
|
||||
|
||||
export default function Checkbox({ checked, onChange, indeterminate, className, ...props }: CheckboxProps) {
|
||||
const ui = useSkin('Checkbox', {});
|
||||
|
||||
return (
|
||||
<BaseCheckbox.Root
|
||||
{...props}
|
||||
checked={checked}
|
||||
indeterminate={indeterminate}
|
||||
onCheckedChange={onChange}
|
||||
className={cn(rootClass, className)}
|
||||
{...ui('root', className)}
|
||||
>
|
||||
<BaseCheckbox.Indicator>
|
||||
<BaseCheckbox.Indicator {...ui('indicator')}>
|
||||
{indeterminate ? (
|
||||
<Minus size={14} strokeWidth={2.5} aria-hidden />
|
||||
) : (
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
import { Combobox } from '@base-ui/react/combobox';
|
||||
import { Check, ChevronDown } from 'lucide-react';
|
||||
import { cn } from '@/lib/cn';
|
||||
import { isNumber, isString } from '@/lib/objects';
|
||||
import { useSkin, type SkinBinding } from '@/themes/skins';
|
||||
|
||||
export type SelectValue = string | number;
|
||||
|
||||
@@ -57,34 +57,7 @@ type ComboboxGroupItem = {
|
||||
items: SelectOption[];
|
||||
};
|
||||
|
||||
type WithStringClassName<TProps> = Omit<TProps, 'className'> & { className?: string };
|
||||
|
||||
const inputGroupClass = [
|
||||
'relative flex items-center w-full rounded-sm border text-sm transition-colors duration-150',
|
||||
'bg-input border-input text-foreground hover:border-input data-[popup-open]:border-input',
|
||||
'focus-within:shadow-md focus-within:border-primary focus-within:ring-2 focus-within:ring-ring/50',
|
||||
'data-[disabled]:opacity-75 data-[disabled]:cursor-default',
|
||||
].join(' ');
|
||||
const inputErrorClass =
|
||||
'border-destructive text-destructive focus-within:border-destructive focus-within:ring-destructive';
|
||||
const inputClass = [
|
||||
'w-full min-w-0 appearance-none border-0 bg-transparent p-3 pr-10 text-sm text-foreground outline-hidden',
|
||||
'placeholder:text-muted-foreground focus:ring-0 focus:outline-hidden disabled:cursor-default',
|
||||
].join(' ');
|
||||
const triggerClass =
|
||||
'absolute right-0 top-0 flex h-full w-10 items-center justify-center border-0 bg-transparent p-0 text-muted-foreground [&_svg]:h-4 [&_svg]:w-4 [&_svg]:shrink-0';
|
||||
const positionerClass = 'z-[99999] min-w-[var(--anchor-width)] outline-none';
|
||||
const popupClass = [
|
||||
'bg-card border border-border rounded-sm shadow-lg py-1 text-sm text-foreground',
|
||||
'w-[var(--anchor-width)] max-w-[var(--available-width)] max-h-[min(18rem,var(--available-height))]',
|
||||
].join(' ');
|
||||
const listClass = 'max-h-72 overflow-y-auto overscroll-contain outline-none';
|
||||
const itemClass =
|
||||
'flex items-center justify-between px-3 py-2 cursor-pointer select-none outline-hidden data-[highlighted]:bg-popover data-[highlighted]:text-foreground data-[selected]:text-accent data-[disabled]:opacity-50 data-[disabled]:cursor-default';
|
||||
const emptyClass = 'px-3 py-2 text-sm text-muted-foreground empty:p-0';
|
||||
const groupLabelClass = 'px-3 pt-2 pb-1 text-xs uppercase text-muted-foreground empty:hidden';
|
||||
const selectionSummaryClass = 'pointer-events-none whitespace-nowrap px-3 py-3 text-sm text-foreground';
|
||||
const selectionPreviewClass = 'pointer-events-none flex min-w-0 flex-1 items-center px-3 py-2 pr-10 text-sm';
|
||||
type SelectSkin = SkinBinding<'Select'>;
|
||||
|
||||
const optionLabel = (option: SelectOption | null | undefined): string => {
|
||||
if (!option) {
|
||||
@@ -133,118 +106,82 @@ const getGroups = (groups: SelectGroup[] | undefined): ComboboxGroupItem[] | und
|
||||
items: group.options,
|
||||
}));
|
||||
|
||||
const ComboboxInputGroup = ({
|
||||
$hasError,
|
||||
className,
|
||||
...props
|
||||
}: { $hasError?: boolean } & WithStringClassName<React.ComponentProps<typeof Combobox.InputGroup>>) => (
|
||||
<Combobox.InputGroup className={cn(inputGroupClass, $hasError && inputErrorClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxInput = ({ className, ...props }: WithStringClassName<React.ComponentProps<typeof Combobox.Input>>) => (
|
||||
<Combobox.Input className={cn(inputClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxTrigger = ({
|
||||
className,
|
||||
...props
|
||||
}: WithStringClassName<React.ComponentProps<typeof Combobox.Trigger>>) => (
|
||||
<Combobox.Trigger className={cn(triggerClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxPositioner = ({
|
||||
className,
|
||||
...props
|
||||
}: WithStringClassName<React.ComponentProps<typeof Combobox.Positioner>>) => (
|
||||
<Combobox.Positioner className={cn(positionerClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxPopup = ({ className, ...props }: WithStringClassName<React.ComponentProps<typeof Combobox.Popup>>) => (
|
||||
<Combobox.Popup className={cn(popupClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxList = ({ className, ...props }: WithStringClassName<React.ComponentProps<typeof Combobox.List>>) => (
|
||||
<Combobox.List className={cn(listClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxItem = ({ className, ...props }: WithStringClassName<React.ComponentProps<typeof Combobox.Item>>) => (
|
||||
<Combobox.Item className={cn(itemClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxEmpty = ({ className, ...props }: WithStringClassName<React.ComponentProps<typeof Combobox.Empty>>) => (
|
||||
<Combobox.Empty className={cn(emptyClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxGroupLabel = ({
|
||||
className,
|
||||
...props
|
||||
}: WithStringClassName<React.ComponentProps<typeof Combobox.GroupLabel>>) => (
|
||||
<Combobox.GroupLabel className={cn(groupLabelClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const ComboboxSelectionSummary = ({ className, ...props }: React.ComponentProps<'span'>) => (
|
||||
<span className={cn(selectionSummaryClass, className)} {...props} />
|
||||
);
|
||||
|
||||
const CheckIcon = () => <Check size={14} strokeWidth={2.5} aria-hidden />;
|
||||
|
||||
const ChevronIcon = () => <ChevronDown size={16} aria-hidden />;
|
||||
|
||||
const ComboboxOptionItem = ({ option, showIndicator }: { option: SelectOption; showIndicator: boolean }) => (
|
||||
<ComboboxItem value={option} disabled={option.disabled}>
|
||||
<span className='min-w-0'>{option.label}</span>
|
||||
const ComboboxOptionItem = ({
|
||||
ui,
|
||||
option,
|
||||
showIndicator,
|
||||
}: {
|
||||
ui: SelectSkin;
|
||||
option: SelectOption;
|
||||
showIndicator: boolean;
|
||||
}) => (
|
||||
<Combobox.Item {...ui('item')} value={option} disabled={option.disabled}>
|
||||
<span {...ui('itemLabel')}>{option.label}</span>
|
||||
{showIndicator && (
|
||||
<Combobox.ItemIndicator>
|
||||
<Combobox.ItemIndicator {...ui('indicator')}>
|
||||
<CheckIcon />
|
||||
</Combobox.ItemIndicator>
|
||||
)}
|
||||
</ComboboxItem>
|
||||
</Combobox.Item>
|
||||
);
|
||||
|
||||
const ComboboxOptionsList = ({
|
||||
ui,
|
||||
groups,
|
||||
showIndicator,
|
||||
}: {
|
||||
ui: SelectSkin;
|
||||
groups: ComboboxGroupItem[] | undefined;
|
||||
showIndicator: boolean;
|
||||
}) =>
|
||||
groups ? (
|
||||
<ComboboxList>
|
||||
<Combobox.List {...ui('list')}>
|
||||
{(group: ComboboxGroupItem) => (
|
||||
<Combobox.Group key={group.value} items={group.items}>
|
||||
<ComboboxGroupLabel>{group.label}</ComboboxGroupLabel>
|
||||
<Combobox.Group key={group.value} items={group.items} {...ui('group')}>
|
||||
<Combobox.GroupLabel {...ui('groupLabel')}>{group.label}</Combobox.GroupLabel>
|
||||
<Combobox.Collection>
|
||||
{(option: SelectOption) => (
|
||||
<ComboboxOptionItem key={optionKey(option)} option={option} showIndicator={showIndicator} />
|
||||
<ComboboxOptionItem
|
||||
key={optionKey(option)}
|
||||
ui={ui}
|
||||
option={option}
|
||||
showIndicator={showIndicator}
|
||||
/>
|
||||
)}
|
||||
</Combobox.Collection>
|
||||
</Combobox.Group>
|
||||
)}
|
||||
</ComboboxList>
|
||||
</Combobox.List>
|
||||
) : (
|
||||
<ComboboxList>
|
||||
<Combobox.List {...ui('list')}>
|
||||
{(option: SelectOption) => (
|
||||
<ComboboxOptionItem key={optionKey(option)} option={option} showIndicator={showIndicator} />
|
||||
<ComboboxOptionItem key={optionKey(option)} ui={ui} option={option} showIndicator={showIndicator} />
|
||||
)}
|
||||
</ComboboxList>
|
||||
</Combobox.List>
|
||||
);
|
||||
|
||||
const ComboboxPopupContent = ({
|
||||
ui,
|
||||
groupedItems,
|
||||
emptyMessage,
|
||||
showIndicator,
|
||||
}: {
|
||||
ui: SelectSkin;
|
||||
groupedItems: ComboboxGroupItem[] | undefined;
|
||||
emptyMessage: string;
|
||||
showIndicator: boolean;
|
||||
}) => (
|
||||
<Combobox.Portal>
|
||||
<ComboboxPositioner sideOffset={4}>
|
||||
<ComboboxPopup>
|
||||
<ComboboxEmpty>{emptyMessage}</ComboboxEmpty>
|
||||
<ComboboxOptionsList groups={groupedItems} showIndicator={showIndicator} />
|
||||
</ComboboxPopup>
|
||||
</ComboboxPositioner>
|
||||
<Combobox.Positioner {...ui('positioner')} sideOffset={4}>
|
||||
<Combobox.Popup {...ui('popup')}>
|
||||
<Combobox.Empty {...ui('empty')}>{emptyMessage}</Combobox.Empty>
|
||||
<ComboboxOptionsList ui={ui} groups={groupedItems} showIndicator={showIndicator} />
|
||||
</Combobox.Popup>
|
||||
</Combobox.Positioner>
|
||||
</Combobox.Portal>
|
||||
);
|
||||
|
||||
@@ -342,11 +279,11 @@ type SelectSearch = ReturnType<typeof useSelectSearch>;
|
||||
type InputAriaProps = Pick<React.ComponentProps<'input'>, 'aria-describedby' | 'aria-invalid'>;
|
||||
|
||||
function MultiSelectCombobox({
|
||||
ui,
|
||||
id,
|
||||
placeholder,
|
||||
searchPlaceholder,
|
||||
emptyMessage,
|
||||
hasError,
|
||||
disabled,
|
||||
items,
|
||||
groupedItems,
|
||||
@@ -357,11 +294,11 @@ function MultiSelectCombobox({
|
||||
onChange,
|
||||
onCreate,
|
||||
}: {
|
||||
ui: SelectSkin;
|
||||
id: string | undefined;
|
||||
placeholder: string | undefined;
|
||||
searchPlaceholder: string;
|
||||
emptyMessage: string;
|
||||
hasError: boolean | undefined;
|
||||
disabled: boolean | undefined;
|
||||
items: SelectOption[] | ComboboxGroupItem[];
|
||||
groupedItems: ComboboxGroupItem[] | undefined;
|
||||
@@ -402,17 +339,15 @@ function MultiSelectCombobox({
|
||||
isItemEqualToValue={isSameOption}
|
||||
autoHighlight
|
||||
>
|
||||
<ComboboxInputGroup $hasError={hasError}>
|
||||
<Combobox.InputGroup {...ui('root')}>
|
||||
<Combobox.Value>
|
||||
{(value: SelectOption[]) => (
|
||||
<>
|
||||
{value.length > 0 && (
|
||||
<ComboboxSelectionSummary>{`${value.length} selected`}</ComboboxSelectionSummary>
|
||||
)}
|
||||
<ComboboxInput
|
||||
{value.length > 0 && <span {...ui('summary')}>{`${value.length} selected`}</span>}
|
||||
<Combobox.Input
|
||||
{...ui('input')}
|
||||
{...inputAria}
|
||||
id={id}
|
||||
className={value.length > 0 ? 'pl-0' : undefined}
|
||||
placeholder={value.length > 0 ? searchPlaceholder : placeholder}
|
||||
onFocus={search.handleFocus}
|
||||
onBlur={search.handleBlur}
|
||||
@@ -420,43 +355,41 @@ function MultiSelectCombobox({
|
||||
</>
|
||||
)}
|
||||
</Combobox.Value>
|
||||
<ComboboxTrigger aria-label='Open popup'>
|
||||
<Combobox.Trigger {...ui('trigger')} aria-label='Open popup'>
|
||||
<ChevronIcon />
|
||||
</ComboboxTrigger>
|
||||
</ComboboxInputGroup>
|
||||
<ComboboxPopupContent groupedItems={groupedItems} emptyMessage={emptyMessage} showIndicator />
|
||||
</Combobox.Trigger>
|
||||
</Combobox.InputGroup>
|
||||
<ComboboxPopupContent ui={ui} groupedItems={groupedItems} emptyMessage={emptyMessage} showIndicator />
|
||||
</Combobox.Root>
|
||||
);
|
||||
}
|
||||
|
||||
function SingleSelectCombobox({
|
||||
ui,
|
||||
id,
|
||||
placeholder,
|
||||
emptyMessage,
|
||||
hasError,
|
||||
disabled,
|
||||
items,
|
||||
groupedItems,
|
||||
selectedOption,
|
||||
inputValue,
|
||||
richSelection,
|
||||
inputFocused,
|
||||
inputAria,
|
||||
search,
|
||||
onChange,
|
||||
onSelectLabel,
|
||||
}: {
|
||||
ui: SelectSkin;
|
||||
id: string | undefined;
|
||||
placeholder: string | undefined;
|
||||
emptyMessage: string;
|
||||
hasError: boolean | undefined;
|
||||
disabled: boolean | undefined;
|
||||
items: SelectOption[] | ComboboxGroupItem[];
|
||||
groupedItems: ComboboxGroupItem[] | undefined;
|
||||
selectedOption: SelectOption | null;
|
||||
inputValue: string;
|
||||
richSelection: React.ReactNode | null;
|
||||
inputFocused: boolean;
|
||||
inputAria: InputAriaProps;
|
||||
search: SelectSearch;
|
||||
onChange: (value: SelectValue) => void;
|
||||
@@ -486,26 +419,26 @@ function SingleSelectCombobox({
|
||||
isItemEqualToValue={isSameOption}
|
||||
autoHighlight
|
||||
>
|
||||
<ComboboxInputGroup $hasError={hasError}>
|
||||
{richSelection && (
|
||||
<span className={cn(selectionPreviewClass, inputFocused && 'invisible')}>{richSelection}</span>
|
||||
)}
|
||||
<ComboboxInput
|
||||
<Combobox.InputGroup {...ui('root')}>
|
||||
{richSelection && <span {...ui('preview')}>{richSelection}</span>}
|
||||
<Combobox.Input
|
||||
{...ui('input')}
|
||||
{...inputAria}
|
||||
id={id}
|
||||
className={cn(
|
||||
richSelection && 'absolute inset-0 h-full',
|
||||
richSelection && !inputFocused && 'text-transparent'
|
||||
)}
|
||||
placeholder={placeholder}
|
||||
onFocus={search.handleFocus}
|
||||
onBlur={search.handleBlur}
|
||||
/>
|
||||
<ComboboxTrigger aria-label='Open popup'>
|
||||
<Combobox.Trigger {...ui('trigger')} aria-label='Open popup'>
|
||||
<ChevronIcon />
|
||||
</ComboboxTrigger>
|
||||
</ComboboxInputGroup>
|
||||
<ComboboxPopupContent groupedItems={groupedItems} emptyMessage={emptyMessage} showIndicator={false} />
|
||||
</Combobox.Trigger>
|
||||
</Combobox.InputGroup>
|
||||
<ComboboxPopupContent
|
||||
ui={ui}
|
||||
groupedItems={groupedItems}
|
||||
emptyMessage={emptyMessage}
|
||||
showIndicator={false}
|
||||
/>
|
||||
</Combobox.Root>
|
||||
);
|
||||
}
|
||||
@@ -533,6 +466,14 @@ export default function Select(props: SelectProps) {
|
||||
'aria-describedby': props['aria-describedby'],
|
||||
'aria-invalid': props['aria-invalid'],
|
||||
};
|
||||
const richSelection = props.multiple ? null : resolveRichSelection(selectedOptions[0] ?? null);
|
||||
const ui = useSkin('Select', {
|
||||
error: !!hasError,
|
||||
multiple: !!props.multiple,
|
||||
selected: selectedOptions.length > 0,
|
||||
richLabel: !!richSelection,
|
||||
searching: search.inputFocused,
|
||||
});
|
||||
|
||||
if (props.multiple) {
|
||||
const inputValue = search.inputFocused ? search.searchValue : '';
|
||||
@@ -540,11 +481,11 @@ export default function Select(props: SelectProps) {
|
||||
|
||||
return (
|
||||
<MultiSelectCombobox
|
||||
ui={ui}
|
||||
id={id}
|
||||
placeholder={placeholder}
|
||||
searchPlaceholder={searchPlaceholder}
|
||||
emptyMessage={emptyMessage}
|
||||
hasError={hasError}
|
||||
disabled={disabled}
|
||||
items={creatable ? [...flatOptions, creatable] : items}
|
||||
groupedItems={groupedItems}
|
||||
@@ -560,22 +501,20 @@ export default function Select(props: SelectProps) {
|
||||
|
||||
const selectedOption = selectedOptions[0] ?? null;
|
||||
const selectedLabel = optionLabel(selectedOption);
|
||||
const richSelection = resolveRichSelection(selectedOption);
|
||||
const inputValue = search.inputFocused ? search.searchValue : selectedLabel;
|
||||
|
||||
return (
|
||||
<SingleSelectCombobox
|
||||
ui={ui}
|
||||
id={id}
|
||||
placeholder={placeholder}
|
||||
emptyMessage={emptyMessage}
|
||||
hasError={hasError}
|
||||
disabled={disabled}
|
||||
items={items}
|
||||
groupedItems={groupedItems}
|
||||
selectedOption={selectedOption}
|
||||
inputValue={inputValue}
|
||||
richSelection={richSelection}
|
||||
inputFocused={search.inputFocused}
|
||||
inputAria={inputAria}
|
||||
search={search}
|
||||
onChange={props.onChange}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useId } from 'react';
|
||||
import { Switch as BaseSwitch } from '@base-ui/react/switch';
|
||||
import { cn } from '@/lib/cn';
|
||||
import Label from '@/components/elements/Label';
|
||||
import { useSkin } from '@/themes/skins';
|
||||
|
||||
export interface SwitchProps {
|
||||
checked: boolean;
|
||||
@@ -18,19 +18,6 @@ export interface SwitchProps {
|
||||
'aria-labelledby'?: string;
|
||||
}
|
||||
|
||||
const rootClass = [
|
||||
'group relative inline-block shrink-0 w-12 h-6 rounded-full border cursor-pointer select-none p-0',
|
||||
'bg-input border-input transition-colors duration-75',
|
||||
'hover:border-primary/70 active:bg-popover data-[checked]:bg-primary data-[checked]:border-primary',
|
||||
'data-[disabled]:opacity-60 data-[disabled]:cursor-default',
|
||||
].join(' ');
|
||||
const thumbClass = [
|
||||
'block absolute top-1/2 left-0.5 size-4.5 -translate-y-1/2 rounded-full border bg-background',
|
||||
'transition-[left] duration-75 ease-in',
|
||||
'group-data-[checked]:left-[calc(100%_-_1.125rem_-_0.125rem)]',
|
||||
'group-data-[checked]:bg-primary-foreground group-data-[checked]:border-primary-foreground',
|
||||
].join(' ');
|
||||
|
||||
export default function Switch({
|
||||
checked,
|
||||
onChange,
|
||||
@@ -50,6 +37,7 @@ export default function Switch({
|
||||
const labelId = `${generatedId}-label`;
|
||||
const descriptionId = `${generatedId}-description`;
|
||||
const hasText = !!label || !!description;
|
||||
const ui = useSkin('Switch', { described: !!description, position: controlPosition });
|
||||
const control = (
|
||||
<BaseSwitch.Root
|
||||
id={fieldId}
|
||||
@@ -61,20 +49,20 @@ export default function Switch({
|
||||
aria-label={ariaLabel}
|
||||
aria-labelledby={ariaLabelledBy ?? (label ? labelId : undefined)}
|
||||
aria-describedby={description ? descriptionId : undefined}
|
||||
className={rootClass}
|
||||
{...ui('control')}
|
||||
>
|
||||
<BaseSwitch.Thumb className={thumbClass} />
|
||||
<BaseSwitch.Thumb {...ui('thumb')} />
|
||||
</BaseSwitch.Root>
|
||||
);
|
||||
const text = hasText ? (
|
||||
<div className='min-w-0 flex-1'>
|
||||
<div {...ui('text')}>
|
||||
{label && (
|
||||
<Label id={labelId} htmlFor={fieldId} className='cursor-pointer mb-0'>
|
||||
<Label id={labelId} htmlFor={fieldId} className={ui.classes('label')}>
|
||||
{label}
|
||||
</Label>
|
||||
)}
|
||||
{description && (
|
||||
<p id={descriptionId} className='input-help'>
|
||||
<p id={descriptionId} {...ui('description')}>
|
||||
{description}
|
||||
</p>
|
||||
)}
|
||||
@@ -82,7 +70,7 @@ export default function Switch({
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<div className={cn('flex gap-4', description ? 'items-start' : 'items-center', className)}>
|
||||
<div {...ui('root', className)}>
|
||||
{controlPosition === 'end' ? (
|
||||
<>
|
||||
{text}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTi
|
||||
afterEach(cleanup);
|
||||
|
||||
describe('Empty', () => {
|
||||
it('renders each part with its slot and merges class names', () => {
|
||||
it('renders each part with its skin attributes and merges class names', () => {
|
||||
const { container } = render(
|
||||
<Empty className='border md:p-8' data-testid='empty'>
|
||||
<EmptyHeader>
|
||||
@@ -27,13 +27,14 @@ describe('Empty', () => {
|
||||
|
||||
const root = screen.getByTestId('empty');
|
||||
|
||||
expect(root).toHaveAttribute('data-slot', 'empty');
|
||||
expect(root).toHaveAttribute('data-ui', 'empty');
|
||||
expect(root).toHaveAttribute('data-size', 'default');
|
||||
expect(root).toHaveClass('border', 'md:p-8', 'p-6');
|
||||
expect(root).not.toHaveClass('md:p-12');
|
||||
expect(
|
||||
[...container.querySelectorAll('[data-slot]')].map((element) => element.getAttribute('data-slot'))
|
||||
).toEqual(['empty', 'empty-header', 'empty-icon', 'empty-title', 'empty-description', 'empty-content']);
|
||||
expect(screen.getByText('No databases')).toHaveAttribute('data-slot', 'empty-title');
|
||||
[...container.querySelectorAll('[data-ui="empty"]')].map((element) => element.getAttribute('data-part'))
|
||||
).toEqual(['root', 'header', 'media', 'title', 'description', 'content']);
|
||||
expect(screen.getByText('No databases')).toHaveAttribute('data-part', 'title');
|
||||
expect(screen.getByRole('link', { name: 'the panel' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Create database' })).toBeInTheDocument();
|
||||
});
|
||||
@@ -53,9 +54,11 @@ describe('Empty', () => {
|
||||
expect(screen.getByTestId('icon')).not.toHaveClass('size-10');
|
||||
});
|
||||
|
||||
it('lets callers override the slot attribute', () => {
|
||||
render(<EmptyTitle data-slot='custom-title'>Title</EmptyTitle>);
|
||||
it('tightens a compact empty state', () => {
|
||||
render(<Empty size='compact' data-testid='empty' />);
|
||||
|
||||
expect(screen.getByText('Title')).toHaveAttribute('data-slot', 'custom-title');
|
||||
expect(screen.getByTestId('empty')).toHaveClass('gap-4', 'md:p-8');
|
||||
expect(screen.getByTestId('empty')).not.toHaveClass('gap-6', 'md:p-12');
|
||||
expect(screen.getByTestId('empty')).toHaveAttribute('data-size', 'compact');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,90 +1,53 @@
|
||||
import type * as React from 'react';
|
||||
import { cva } from 'class-variance-authority';
|
||||
import { cn } from '@/lib/cn';
|
||||
import * as React from 'react';
|
||||
import { replaceable, useSkin } from '@/themes/skins';
|
||||
|
||||
export type EmptySize = 'default' | 'compact';
|
||||
export type EmptyMediaVariant = 'default' | 'icon';
|
||||
|
||||
export type EmptyProps = React.ComponentProps<'div'> & {
|
||||
/** `compact` tightens the spacing for an `Empty` inside a card, table or dialog. */
|
||||
size?: EmptySize;
|
||||
};
|
||||
|
||||
const EmptySizeContext = React.createContext<EmptySize>('default');
|
||||
|
||||
const usePartSkin = () => useSkin('Empty', { size: React.use(EmptySizeContext) });
|
||||
|
||||
function CoreEmpty({ className, size = 'default', ...props }: EmptyProps) {
|
||||
const ui = useSkin('Empty', { size });
|
||||
|
||||
function Empty({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot='empty'
|
||||
className={cn(
|
||||
'flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-sm border-dashed p-6 text-center text-balance md:p-12',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
<EmptySizeContext.Provider value={size}>
|
||||
<div {...ui('root', className)} {...props} />
|
||||
</EmptySizeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
const Empty = replaceable('Empty', CoreEmpty);
|
||||
|
||||
function EmptyHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot='empty-header'
|
||||
className={cn('flex max-w-sm flex-col items-center gap-2 text-center', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
return <div {...usePartSkin()('header', className)} {...props} />;
|
||||
}
|
||||
|
||||
const emptyMediaVariants = cva(
|
||||
'mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-transparent',
|
||||
icon: "flex size-10 shrink-0 items-center justify-center rounded-sm bg-secondary text-secondary-foreground [&_svg:not([class*='size-'])]:size-6",
|
||||
},
|
||||
},
|
||||
defaultVariants: { variant: 'default' },
|
||||
}
|
||||
);
|
||||
|
||||
/** `icon` frames a single icon in a tile; `default` leaves the media unframed. */
|
||||
function EmptyMedia({
|
||||
className,
|
||||
variant = 'default',
|
||||
...props
|
||||
}: React.ComponentProps<'div'> & { variant?: 'default' | 'icon' }) {
|
||||
return (
|
||||
<div
|
||||
data-slot='empty-icon'
|
||||
data-variant={variant}
|
||||
className={cn(emptyMediaVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}: React.ComponentProps<'div'> & { variant?: EmptyMediaVariant }) {
|
||||
return <div {...usePartSkin()('media', className, { variant })} {...props} />;
|
||||
}
|
||||
|
||||
function EmptyTitle({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot='empty-title'
|
||||
className={cn('font-header text-lg font-medium tracking-tight text-foreground', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
return <div {...usePartSkin()('title', className)} {...props} />;
|
||||
}
|
||||
|
||||
function EmptyDescription({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot='empty-description'
|
||||
className={cn(
|
||||
'text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-accent',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
return <div {...usePartSkin()('description', className)} {...props} />;
|
||||
}
|
||||
|
||||
function EmptyContent({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot='empty-content'
|
||||
className={cn('flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance', className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
return <div {...usePartSkin()('content', className)} {...props} />;
|
||||
}
|
||||
|
||||
export { Empty, EmptyHeader, EmptyMedia, EmptyTitle, EmptyDescription, EmptyContent };
|
||||
|
||||
@@ -1,5 +1,2 @@
|
||||
export const interactiveSurfaceClass =
|
||||
'transition-[background-color,border-color,color,box-shadow] duration-150 hover:bg-popover hover:border-border active:bg-popover/80';
|
||||
|
||||
/** Tighter spacing for an `Empty` that sits inside a card, table or dialog. */
|
||||
export const emptyCompactClass = 'gap-4 md:p-8';
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
export const pageTitleClass = 'font-header text-2xl font-semibold tracking-normal text-foreground';
|
||||
export const sectionTitleClass = 'font-header text-lg font-semibold tracking-normal text-foreground';
|
||||
export const cardTitleClass = 'font-header text-sm font-semibold uppercase tracking-wide text-foreground';
|
||||
export const dialogTitleClass = 'font-header text-xl font-semibold tracking-normal text-foreground';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Outlet } from '@tanstack/react-router';
|
||||
import ProgressBar from '@/components/elements/ProgressBar';
|
||||
import { HttpProgressBar } from '@/components/elements/ProgressBar';
|
||||
import { RouteAnnouncer, SkipLink } from '@/views/a11y';
|
||||
|
||||
export default function RootLayout() {
|
||||
return (
|
||||
<>
|
||||
<SkipLink />
|
||||
<ProgressBar />
|
||||
<HttpProgressBar />
|
||||
<div className='mx-auto w-auto'>
|
||||
<Outlet />
|
||||
</div>
|
||||
|
||||
@@ -31,28 +31,58 @@ import { SocketEvent } from '@/components/server/events';
|
||||
import { hasPermission } from '@/plugins/usePermissions';
|
||||
import { cn as mergeClasses } from '@/lib/cn';
|
||||
|
||||
export { default as Button } from '@/components/elements/Button';
|
||||
export { default as Spinner } from '@/components/elements/Spinner';
|
||||
export {
|
||||
default as Button,
|
||||
LinkButton,
|
||||
RouterLinkButton,
|
||||
type ButtonColor,
|
||||
type ButtonProps,
|
||||
type ButtonSize,
|
||||
} from '@/components/elements/Button';
|
||||
export { default as Spinner, type SpinnerProps, type SpinnerSize } from '@/components/elements/Spinner';
|
||||
export { default as Icon } from '@/components/elements/Icon';
|
||||
export { default as NamedIcon, loadIconNames, type NamedIconProps } from '@/components/elements/NamedIcon';
|
||||
export { default as Can } from '@/components/elements/Can';
|
||||
export { default as Card, type CardProps } from '@/components/elements/Card';
|
||||
export { default as ListRow, type ListRowProps } from '@/components/elements/ListRow';
|
||||
export { default as Badge, type BadgeProps, type BadgeSize, type BadgeVariant } from '@/components/elements/Badge';
|
||||
export {
|
||||
default as ProgressBar,
|
||||
type ProgressBarProps,
|
||||
type ProgressBarVariant,
|
||||
} from '@/components/elements/ProgressBar';
|
||||
export { default as Code, type CodeProps } from '@/components/elements/Code';
|
||||
export { default as ContentBox } from '@/components/elements/ContentBox';
|
||||
export { default as PageContentBlock } from '@/components/elements/PageContentBlock';
|
||||
export { default as ServerContentBlock } from '@/components/elements/ServerContentBlock';
|
||||
export { default as TitledGreyBox } from '@/components/elements/TitledGreyBox';
|
||||
export { default as CopyOnClick } from '@/components/elements/CopyOnClick';
|
||||
export { default as CopyOnClick, type CopyOnClickProps } from '@/components/elements/CopyOnClick';
|
||||
export { default as ScreenBlock, ServerError, NotFound } from '@/components/elements/ScreenBlock';
|
||||
export { default as Label } from '@/components/elements/Label';
|
||||
export { default as PageHeading } from '@/components/elements/PageHeading';
|
||||
export { NewButton, NewLinkButton } from '@/components/elements/NewButton';
|
||||
export { default as SpinnerOverlay } from '@/components/elements/SpinnerOverlay';
|
||||
export { TextInput as Input, TextArea, NumberInput } from '@/components/form/controls';
|
||||
export { default as Label, type LabelProps } from '@/components/elements/Label';
|
||||
export { default as PageHeading, type PageHeadingProps } from '@/components/elements/PageHeading';
|
||||
export {
|
||||
NewButton,
|
||||
NewLinkButton,
|
||||
type NewButtonProps,
|
||||
type NewLinkButtonProps,
|
||||
} from '@/components/elements/NewButton';
|
||||
export { default as SpinnerOverlay, type SpinnerOverlayProps } from '@/components/elements/SpinnerOverlay';
|
||||
export {
|
||||
TextInput as Input,
|
||||
TextArea,
|
||||
NumberInput,
|
||||
FileInput,
|
||||
type TextInputProps as InputProps,
|
||||
type TextAreaProps,
|
||||
type NumberInputProps,
|
||||
type FileInputProps,
|
||||
} from '@/components/form/controls';
|
||||
export { Form, useAppForm, useFieldContext, useFormContext, type AppForm, type SelectOption } from '@/components/form';
|
||||
export { default as Select, type SelectGroup, type SelectProps, type SelectValue } from '@/components/ui/Select';
|
||||
export { default as Checkbox, type CheckboxProps } from '@/components/ui/Checkbox';
|
||||
export { default as Switch, type SwitchProps } from '@/components/ui/Switch';
|
||||
export { Alert } from '@/components/elements/alert';
|
||||
export { Dialog } from '@/components/elements/dialog';
|
||||
export { Alert, type AlertProps, type AlertType } from '@/components/elements/alert';
|
||||
export { Dialog, type DialogIconProps, type RenderDialogProps as DialogProps } from '@/components/elements/dialog';
|
||||
export { toast } from 'sonner';
|
||||
export * from './ui';
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
type ViewProps,
|
||||
} from '@/views/registry';
|
||||
import { registerThemeIcons, type ThemeDefinition } from '@/views/theme';
|
||||
import { registerSkins } from '@/themes/skins';
|
||||
import { clearThemeSkins, registerSkins } from '@/themes/skins';
|
||||
import classic from '@/themes/classic';
|
||||
import { createViewHarness, LooseView, preloadView, ViewFixtureProvider } from '@/views/View';
|
||||
import { act, createContext, useContext, useLayoutEffect, useMemo, type ComponentType, type ReactNode } from 'react';
|
||||
@@ -413,6 +413,7 @@ let rendered: RenderedView | undefined;
|
||||
export function renderView<N extends ViewName>(name: N, options: RenderViewOptions<N> = {}): RenderedView {
|
||||
rendered?.unmount();
|
||||
clearThemeLayers();
|
||||
clearThemeSkins();
|
||||
if (options.theme) {
|
||||
registerSkins('theme', options.theme.ui ?? {});
|
||||
registerViewLayer('theme', 'theme', options.theme.views ?? {});
|
||||
|
||||
@@ -13,7 +13,35 @@ export {
|
||||
type ThemeSettingValue,
|
||||
type ThemeState,
|
||||
} from '@/views/theme';
|
||||
export { skin, type ThemeSkins } from '@/themes/skins';
|
||||
export {
|
||||
skin,
|
||||
useSkin,
|
||||
UI_PRIMITIVES,
|
||||
type CompleteSkin,
|
||||
type CompleteSkins,
|
||||
type NoState,
|
||||
type PrimitiveMeta,
|
||||
type PrimitiveName,
|
||||
type PrimitiveProps,
|
||||
type PrimitiveState,
|
||||
type ReplaceableName,
|
||||
type ResolvedSkin,
|
||||
type Skin,
|
||||
type SkinBinding,
|
||||
type SkinClassName,
|
||||
type SkinCompoundVariant,
|
||||
type SkinDefinition,
|
||||
type SkinExtension,
|
||||
type SkinPart,
|
||||
type SkinPartProps,
|
||||
type SkinRecipe,
|
||||
type SkinRecipeConfig,
|
||||
type SkinStateMap,
|
||||
type SkinStateValue,
|
||||
type ThemeSkins,
|
||||
type UiPrimitives,
|
||||
type UiTone,
|
||||
} from '@/themes/skins';
|
||||
export { View, ViewFixtureProvider, type ViewElementProps, type ViewFixtureSelection } from '@/views/View';
|
||||
export { lazyView } from '@/views/lazy';
|
||||
export { Main } from '@/views/a11y';
|
||||
|
||||
@@ -2,15 +2,28 @@ import { useMemo, type DOMAttributes, type ReactElement, type ReactNode, type Re
|
||||
import { getCoreRowModel, useReactTable, type ColumnDef } from '@tanstack/react-table';
|
||||
import PanelDataTable from '@/components/elements/table/DataTable';
|
||||
import PanelTooltip from '@/components/elements/tooltip/Tooltip';
|
||||
import PanelAvatar from '@/components/Avatar';
|
||||
|
||||
export {
|
||||
default as DropdownMenu,
|
||||
DropdownMenuItem,
|
||||
ContextDropdownMenu,
|
||||
type ContextDropdownMenuProps,
|
||||
type DropdownMenuItemProps,
|
||||
type DropdownMenuProps,
|
||||
} from '@/components/elements/dropdown/DropdownMenu';
|
||||
export { default as Pagination } from '@/components/elements/Pagination';
|
||||
export { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '@/components/ui/empty';
|
||||
export { default as Pagination, type PaginationProps } from '@/components/elements/Pagination';
|
||||
export {
|
||||
Empty,
|
||||
EmptyContent,
|
||||
EmptyDescription,
|
||||
EmptyHeader,
|
||||
EmptyMedia,
|
||||
EmptyTitle,
|
||||
type EmptyMediaVariant,
|
||||
type EmptyProps,
|
||||
type EmptySize,
|
||||
} from '@/components/ui/empty';
|
||||
export { default as Avatar, type AvatarProps, type AvatarVariant } from '@/components/Avatar';
|
||||
|
||||
export interface TableColumn<TRow> {
|
||||
id: string;
|
||||
@@ -52,16 +65,3 @@ export interface TooltipProps {
|
||||
export function Tooltip(props: TooltipProps): ReactElement {
|
||||
return <PanelTooltip {...props} />;
|
||||
}
|
||||
|
||||
export interface AvatarProps {
|
||||
/** Seeds the generated pattern; the panel uses a user's UUID. */
|
||||
name: string;
|
||||
size?: number | string;
|
||||
variant?: 'beam' | 'marble' | 'pixel' | 'sunset' | 'ring' | 'bauhaus';
|
||||
square?: boolean;
|
||||
title?: boolean;
|
||||
className?: string;
|
||||
}
|
||||
export function Avatar(props: AvatarProps): ReactElement {
|
||||
return <PanelAvatar {...props} />;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
import { classicSkins } from '@/themes/classic/skins';
|
||||
import { registerSkins } from '@/themes/skins';
|
||||
|
||||
// jsdom lacks PointerEvent, which Base UI dispatches.
|
||||
if (globalThis.window?.PointerEvent === undefined && globalThis.window?.MouseEvent) {
|
||||
@@ -8,3 +10,6 @@ if (globalThis.window?.PointerEvent === undefined && globalThis.window?.MouseEve
|
||||
if (globalThis.window?.navigator.userAgent.includes('jsdom')) {
|
||||
globalThis.window.scrollTo = () => {};
|
||||
}
|
||||
|
||||
// The panel registers classic before its first render; components under test render without booting.
|
||||
registerSkins('classic', classicSkins);
|
||||
|
||||
@@ -333,12 +333,8 @@
|
||||
"span: active:bg-popover bg-input border border-input cursor-pointer data-[checked]:bg-primary data-[checked]:border-primary data-[disabled]:cursor-default data-[disabled]:opacity-60 duration-75 group h-6 hover:border-primary/70 inline-block p-0 relative rounded-full select-none shrink-0 transition-colors w-12",
|
||||
"span: -translate-y-1/2 absolute bg-background block border duration-75 ease-in group-data-[checked]:bg-primary-foreground group-data-[checked]:border-primary-foreground group-data-[checked]:left-[calc(100%_-_1.125rem_-_0.125rem)] left-0.5 rounded-full size-4.5 top-1/2 transition-[left]"
|
||||
],
|
||||
"Label": [
|
||||
"label: block font-medium mb-1 text-foreground text-sm uppercase"
|
||||
],
|
||||
"Label light span": [
|
||||
"span: block font-medium mb-0 text-muted-foreground text-sm uppercase"
|
||||
],
|
||||
"Label": ["label: block font-medium mb-1 text-foreground text-sm uppercase"],
|
||||
"Label light span": ["span: block font-medium mb-0 text-muted-foreground text-sm uppercase"],
|
||||
"Dialog": [
|
||||
"div: bg-background/50 data-[ending-style]:ease-in data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 duration-150 ease-out fixed inset-0 transition-opacity z-40",
|
||||
"div: fixed inset-0 overflow-y-auto z-50",
|
||||
@@ -504,9 +500,7 @@
|
||||
"div: bg-popover max-w-[24rem] pointer-events-none px-3 py-2 rounded-sm text-popover-foreground text-sm z-9999",
|
||||
"div: absolute bg-popover h-3 left-0 top-[-6px] w-3"
|
||||
],
|
||||
"DropdownMenu closed": [
|
||||
"button: p-2"
|
||||
],
|
||||
"DropdownMenu closed": ["button: p-2"],
|
||||
"DropdownMenu open": [
|
||||
"div: outline-hidden z-[9999]",
|
||||
"div: bg-popover border border-border data-[ending-style]:opacity-0 data-[ending-style]:scale-95 data-[starting-style]:opacity-0 data-[starting-style]:scale-95 duration-100 min-w-64 origin-[var(--transform-origin)] outline-hidden p-1.5 rounded-sm shadow-xl text-popover-foreground text-sm transition",
|
||||
@@ -637,18 +631,10 @@
|
||||
"div: fixed h-0.5 w-full",
|
||||
"div: bg-accent duration-300 ease-in-out h-full shadow-progress transition-[width]"
|
||||
],
|
||||
"ProgressBar idle": [
|
||||
"div: fixed h-0.5 w-full"
|
||||
],
|
||||
"Code": [
|
||||
"code: bg-sunken font-mono inline-block px-1.5 py-0.5 rounded-sm"
|
||||
],
|
||||
"Code dark className": [
|
||||
"code: bg-muted font-mono inline-block px-1.5 py-0.5 rounded-sm text-foreground text-xs"
|
||||
],
|
||||
"CopyOnClick": [
|
||||
"span: cursor-pointer font-mono"
|
||||
],
|
||||
"ProgressBar idle": ["div: fixed h-0.5 w-full"],
|
||||
"Code": ["code: bg-sunken font-mono inline-block px-1.5 py-0.5 rounded-sm"],
|
||||
"Code dark className": ["code: bg-muted font-mono inline-block px-1.5 py-0.5 rounded-sm text-foreground text-xs"],
|
||||
"CopyOnClick": ["span: cursor-pointer font-mono"],
|
||||
"CopyOnClick status": [
|
||||
"div: bottom-0 fixed m-4 right-0 z-50",
|
||||
"div: bg-popover/95 px-4 py-3 rounded-md shadow-sm text-foreground",
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import type { CompleteSkin } from '@/sdk/theme';
|
||||
|
||||
export const button = {
|
||||
root: {
|
||||
base: 'relative inline-block rounded-sm border p-2 text-sm uppercase tracking-wide transition-colors duration-150 disabled:cursor-default disabled:opacity-50',
|
||||
variants: {
|
||||
color: {
|
||||
primary:
|
||||
'bg-primary border-primary text-primary-foreground hover:not-disabled:bg-primary/80 hover:not-disabled:border-primary',
|
||||
grey: 'border-border bg-popover text-foreground hover:not-disabled:bg-secondary hover:not-disabled:border-secondary',
|
||||
green: 'border-success bg-success text-success-foreground hover:not-disabled:bg-success/80 hover:not-disabled:border-success',
|
||||
red: 'border-destructive bg-destructive text-destructive-foreground hover:not-disabled:bg-destructive/80 hover:not-disabled:border-destructive',
|
||||
orange: 'border-caution bg-caution text-caution-foreground hover:not-disabled:bg-caution/80 hover:not-disabled:border-caution',
|
||||
},
|
||||
size: {
|
||||
xsmall: 'px-2 py-1 text-xs',
|
||||
small: 'px-4 py-2',
|
||||
large: 'p-4 text-sm',
|
||||
xlarge: 'p-4 w-full',
|
||||
},
|
||||
secondary: {
|
||||
true: 'border-border bg-transparent text-foreground hover:not-disabled:border-popover hover:not-disabled:bg-popover hover:not-disabled:text-foreground',
|
||||
},
|
||||
},
|
||||
compoundVariants: [
|
||||
{
|
||||
secondary: true,
|
||||
color: 'primary',
|
||||
class: 'hover:not-disabled:bg-primary hover:not-disabled:border-primary hover:not-disabled:text-primary-foreground',
|
||||
},
|
||||
{
|
||||
secondary: true,
|
||||
color: 'red',
|
||||
class: 'hover:not-disabled:bg-destructive hover:not-disabled:border-destructive hover:not-disabled:text-destructive-foreground',
|
||||
},
|
||||
{
|
||||
secondary: true,
|
||||
color: 'green',
|
||||
class: 'hover:not-disabled:bg-success hover:not-disabled:border-success hover:not-disabled:text-success-foreground',
|
||||
},
|
||||
{
|
||||
secondary: true,
|
||||
color: 'orange',
|
||||
class: 'hover:not-disabled:bg-caution hover:not-disabled:border-caution hover:not-disabled:text-caution-foreground',
|
||||
},
|
||||
{
|
||||
secondary: false,
|
||||
color: 'primary',
|
||||
class: 'active:not-disabled:bg-primary/70 active:not-disabled:border-primary/70',
|
||||
},
|
||||
{
|
||||
secondary: false,
|
||||
color: 'green',
|
||||
class: 'active:not-disabled:bg-success/70 active:not-disabled:border-success',
|
||||
},
|
||||
{
|
||||
secondary: false,
|
||||
color: 'red',
|
||||
class: 'active:not-disabled:bg-destructive/70 active:not-disabled:border-destructive',
|
||||
},
|
||||
{
|
||||
secondary: false,
|
||||
color: 'orange',
|
||||
class: 'active:not-disabled:bg-caution/70 active:not-disabled:border-caution',
|
||||
},
|
||||
],
|
||||
},
|
||||
spinner: 'flex absolute justify-center items-center w-full h-full left-0 top-0',
|
||||
label: { variants: { loading: { true: 'text-transparent' } } },
|
||||
} satisfies CompleteSkin<'Button'>;
|
||||
|
||||
export const newButton = {
|
||||
root: 'inline-flex h-9 shrink-0 items-center justify-center gap-2 px-3 normal-case font-medium tracking-normal',
|
||||
content: 'inline-flex items-center gap-2',
|
||||
icon: 'h-4 w-4',
|
||||
} satisfies CompleteSkin<'NewButton'>;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user