@jgb-solutions/kit 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +163 -2
- package/dist/admin/blocks/ActivityFeed.d.ts +20 -0
- package/dist/admin/blocks/BarChart.d.ts +26 -0
- package/dist/admin/blocks/ChartPoints.d.ts +24 -0
- package/dist/admin/blocks/DataTable.d.ts +58 -0
- package/dist/admin/blocks/Filters.d.ts +12 -0
- package/dist/admin/blocks/Hero.d.ts +22 -0
- package/dist/admin/blocks/LineChart.d.ts +24 -0
- package/dist/admin/blocks/Pagination.d.ts +30 -0
- package/dist/admin/blocks/Segmented.d.ts +15 -0
- package/dist/admin/blocks/Stat.d.ts +35 -0
- package/dist/admin/blocks/Status.d.ts +22 -0
- package/dist/admin/blocks/Tile.d.ts +20 -0
- package/dist/admin/blocks/sorting.d.ts +29 -0
- package/dist/admin/contrast.d.ts +12 -0
- package/dist/admin/forms/ConfirmDialog.d.ts +25 -0
- package/dist/admin/forms/Field.d.ts +48 -0
- package/dist/admin/forms/People.d.ts +28 -0
- package/dist/admin/forms/Toast.d.ts +17 -0
- package/dist/admin/icons.d.ts +31 -0
- package/dist/admin/index.d.ts +33 -0
- package/dist/admin/shell/AdminShell.d.ts +31 -0
- package/dist/admin/shell/Dock.d.ts +8 -0
- package/dist/admin/shell/PageHeader.d.ts +19 -0
- package/dist/admin/shell/Sidebar.d.ts +27 -0
- package/dist/admin/shell/ThemeToggle.d.ts +10 -0
- package/dist/admin/shell/nav.d.ts +33 -0
- package/dist/admin/styles.css +1677 -0
- package/dist/admin/theme.d.ts +30 -0
- package/dist/admin/ui/Avatar.d.ts +14 -0
- package/dist/admin/ui/Button.d.ts +19 -0
- package/dist/admin.d.ts +2 -0
- package/dist/admin.js +2168 -0
- package/dist/i18n.d.ts +104 -0
- package/dist/i18n.js +218 -0
- package/package.json +40 -7
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type InputHTMLAttributes, type ReactNode, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react';
|
|
2
|
+
/** The ids a control needs to be tied to its label, hint and error. */
|
|
3
|
+
export type FieldIds = {
|
|
4
|
+
id: string;
|
|
5
|
+
'aria-describedby': string | undefined;
|
|
6
|
+
'aria-invalid': true | undefined;
|
|
7
|
+
};
|
|
8
|
+
export type FieldProps = {
|
|
9
|
+
label: ReactNode;
|
|
10
|
+
/** Help under the label: what to enter. */
|
|
11
|
+
hint?: ReactNode;
|
|
12
|
+
/** What's wrong and how to fix it ("Use at least 12 characters."). Shown in place of nothing, never as colour alone. */
|
|
13
|
+
error?: ReactNode;
|
|
14
|
+
/** Any control, given the ids that tie it to the label, hint and error. */
|
|
15
|
+
children: (ids: FieldIds) => ReactNode;
|
|
16
|
+
};
|
|
17
|
+
/** A label, the control, a hint and an error, tied together for screen readers. */
|
|
18
|
+
export declare function Field({ label, hint, error, children }: FieldProps): import("react").JSX.Element;
|
|
19
|
+
type Labelled = {
|
|
20
|
+
label: ReactNode;
|
|
21
|
+
hint?: ReactNode;
|
|
22
|
+
error?: ReactNode;
|
|
23
|
+
};
|
|
24
|
+
/** A text input with its label (any `type`: text, email, number, password…). */
|
|
25
|
+
export declare function TextInput({ label, hint, error, className, ...input }: Labelled & InputHTMLAttributes<HTMLInputElement>): import("react").JSX.Element;
|
|
26
|
+
export declare function TextArea({ label, hint, error, className, ...input }: Labelled & TextareaHTMLAttributes<HTMLTextAreaElement>): import("react").JSX.Element;
|
|
27
|
+
export type SelectOption = {
|
|
28
|
+
value: string;
|
|
29
|
+
label: string;
|
|
30
|
+
};
|
|
31
|
+
/** A native select (the phone's own picker), styled. */
|
|
32
|
+
export declare function Select({ label, hint, error, options, className, ...select }: Labelled & SelectHTMLAttributes<HTMLSelectElement> & {
|
|
33
|
+
options: readonly SelectOption[];
|
|
34
|
+
}): import("react").JSX.Element;
|
|
35
|
+
/** A checkbox with its label to the right, and an optional hint under it. */
|
|
36
|
+
export declare function Checkbox({ label, hint, className, ...input }: {
|
|
37
|
+
label: ReactNode;
|
|
38
|
+
hint?: ReactNode;
|
|
39
|
+
} & Omit<InputHTMLAttributes<HTMLInputElement>, 'type'>): import("react").JSX.Element;
|
|
40
|
+
/** An on/off setting that applies at once (role="switch"); its label says what it turns on. */
|
|
41
|
+
export declare function Switch({ label, hint, checked, onChange, disabled, }: {
|
|
42
|
+
label: ReactNode;
|
|
43
|
+
hint?: ReactNode;
|
|
44
|
+
checked: boolean;
|
|
45
|
+
onChange: (checked: boolean) => void;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
}): import("react").JSX.Element;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type RoleOption<R extends string> = {
|
|
2
|
+
value: R;
|
|
3
|
+
label: string;
|
|
4
|
+
};
|
|
5
|
+
export type RolePickerProps<R extends string> = {
|
|
6
|
+
/** Whose role it is: names the control ("Role for Priya Nair"). */
|
|
7
|
+
name: string;
|
|
8
|
+
roles: readonly RoleOption<R>[];
|
|
9
|
+
value: R;
|
|
10
|
+
/** Applies the new role (the app calls its server); the picker waits for it. */
|
|
11
|
+
onChange: (role: R) => Promise<void> | void;
|
|
12
|
+
/** Roles that need a confirmation first (making someone an admin), with what it means. */
|
|
13
|
+
confirm?: Partial<Record<R, string>> | undefined;
|
|
14
|
+
disabled?: boolean | undefined;
|
|
15
|
+
};
|
|
16
|
+
/** An inline role select for a table row. Risky roles ask first. */
|
|
17
|
+
export declare function RolePicker<R extends string>({ name, roles, value, onChange, confirm, disabled }: RolePickerProps<R>): import("react").JSX.Element;
|
|
18
|
+
/** "an Admin", "an Editor", "a Member". */
|
|
19
|
+
export declare function articleFor(word: string): 'a' | 'an';
|
|
20
|
+
export type BanControlProps = {
|
|
21
|
+
name: string;
|
|
22
|
+
suspended: boolean;
|
|
23
|
+
/** Suspends, with the reason the admin gave (optional). */
|
|
24
|
+
onSuspend: (reason: string) => Promise<void> | void;
|
|
25
|
+
onRestore: () => Promise<void> | void;
|
|
26
|
+
};
|
|
27
|
+
/** Suspend (with a reason, after a confirmation) or restore a person, from their row. */
|
|
28
|
+
export declare function BanControl({ name, suspended, onSuspend, onRestore }: BanControlProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
type ToastApi = {
|
|
3
|
+
/** A short confirmation with the button's verb ("Suspended Leo Martin.", "Priya Nair is now an Editor."). */
|
|
4
|
+
done: (message: ReactNode) => void;
|
|
5
|
+
/** Something failed: what, and what to do. Stays until dismissed. */
|
|
6
|
+
error: (message: ReactNode) => void;
|
|
7
|
+
};
|
|
8
|
+
/** Toasts for the admin (AdminShell provides them): `const toast = useToast(); toast.done('Saved.')`. */
|
|
9
|
+
export declare function useToast(): ToastApi;
|
|
10
|
+
/**
|
|
11
|
+
* Holds the toasts and shows them: dark, short, with the sun tick; bottom right on desktop, above the
|
|
12
|
+
* dock on phones. Announced politely to screen readers. A done toast leaves after 4 seconds.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ToastProvider({ children }: {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SVGProps } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A small set of line icons (24×24, currentColor, 1.9 stroke) for the shell and for apps' navigation.
|
|
4
|
+
* Decorative by default (aria-hidden): the link or button around one names it. Apps may pass any
|
|
5
|
+
* other icon as a ReactNode instead.
|
|
6
|
+
*/
|
|
7
|
+
type IconProps = SVGProps<SVGSVGElement>;
|
|
8
|
+
export declare const icons: {
|
|
9
|
+
readonly home: (props: IconProps) => import("react").JSX.Element;
|
|
10
|
+
readonly users: (props: IconProps) => import("react").JSX.Element;
|
|
11
|
+
readonly box: (props: IconProps) => import("react").JSX.Element;
|
|
12
|
+
readonly chart: (props: IconProps) => import("react").JSX.Element;
|
|
13
|
+
readonly flag: (props: IconProps) => import("react").JSX.Element;
|
|
14
|
+
readonly gear: (props: IconProps) => import("react").JSX.Element;
|
|
15
|
+
readonly search: (props: IconProps) => import("react").JSX.Element;
|
|
16
|
+
readonly bell: (props: IconProps) => import("react").JSX.Element;
|
|
17
|
+
readonly screen: (props: IconProps) => import("react").JSX.Element;
|
|
18
|
+
readonly moon: (props: IconProps) => import("react").JSX.Element;
|
|
19
|
+
readonly sun: (props: IconProps) => import("react").JSX.Element;
|
|
20
|
+
readonly sidebar: (props: IconProps) => import("react").JSX.Element;
|
|
21
|
+
readonly doc: (props: IconProps) => import("react").JSX.Element;
|
|
22
|
+
readonly plus: (props: IconProps) => import("react").JSX.Element;
|
|
23
|
+
readonly check: (props: IconProps) => import("react").JSX.Element;
|
|
24
|
+
readonly block: (props: IconProps) => import("react").JSX.Element;
|
|
25
|
+
readonly chevronDown: (props: IconProps) => import("react").JSX.Element;
|
|
26
|
+
readonly chevronRight: (props: IconProps) => import("react").JSX.Element;
|
|
27
|
+
readonly chevronLeft: (props: IconProps) => import("react").JSX.Element;
|
|
28
|
+
readonly close: (props: IconProps) => import("react").JSX.Element;
|
|
29
|
+
};
|
|
30
|
+
export type IconName = keyof typeof icons;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jgb-solutions/admin: the admin panel kit for JGB Solutions apps. Import the stylesheet once
|
|
3
|
+
* (`import '@jgb-solutions/admin/styles.css'`), wrap the admin in <AdminShell>, and build pages from
|
|
4
|
+
* the blocks. Components take data and callbacks; the app fetches, checks permissions on the server
|
|
5
|
+
* and decides what happens.
|
|
6
|
+
*/
|
|
7
|
+
export { AdminShell, type AdminShellProps } from './shell/AdminShell';
|
|
8
|
+
export { Sidebar, type SidebarProps, type AppIdentity } from './shell/Sidebar';
|
|
9
|
+
export { Dock, type DockProps } from './shell/Dock';
|
|
10
|
+
export { PageHeader, TopSearch, type PageHeaderProps, type TopSearchProps } from './shell/PageHeader';
|
|
11
|
+
export { ThemeToggle } from './shell/ThemeToggle';
|
|
12
|
+
export { plainLink, type NavItem, type NavSection, type LinkProps, type RenderLink } from './shell/nav';
|
|
13
|
+
export { useAdminTheme, type Theme, type ThemeChoice } from './theme';
|
|
14
|
+
export { Button, IconButton, type ButtonProps, type IconButtonProps } from './ui/Button';
|
|
15
|
+
export { Avatar, initials, type AvatarProps } from './ui/Avatar';
|
|
16
|
+
export { icons, type IconName } from './icons';
|
|
17
|
+
export { contrastRatio, inkOn } from './contrast';
|
|
18
|
+
export { Bento, Tile, type TileProps } from './blocks/Tile';
|
|
19
|
+
export { StatTile, Meter, AvatarStack, DeltaText, type StatTileProps, type Delta } from './blocks/Stat';
|
|
20
|
+
export { HeroChartTile, type HeroChartTileProps } from './blocks/Hero';
|
|
21
|
+
export { LineChart, type LineChartProps, type ChartPoint } from './blocks/LineChart';
|
|
22
|
+
export { SegmentedControl, type SegmentedOption } from './blocks/Segmented';
|
|
23
|
+
export { DataTable, PersonCell, RowAction, type Column, type DataTableProps } from './blocks/DataTable';
|
|
24
|
+
export { byNumber, byText, nextSort, sortRows, type ColumnSort, type SortDirection, type TableSort } from './blocks/sorting';
|
|
25
|
+
export { FilterTabs, type FilterOption } from './blocks/Filters';
|
|
26
|
+
export { PAGE_SIZES, PageSize, Pagination, type PageSizeProps, type PaginationProps } from './blocks/Pagination';
|
|
27
|
+
export { StatusBadge, PEOPLE_STATUS, type StatusTone } from './blocks/Status';
|
|
28
|
+
export { ActivityFeed, type Activity, type ActivityFeedProps } from './blocks/ActivityFeed';
|
|
29
|
+
export { Field, TextInput, TextArea, Select, Checkbox, Switch, type FieldProps, type FieldIds, type SelectOption } from './forms/Field';
|
|
30
|
+
export { ConfirmDialog, type ConfirmDialogProps } from './forms/ConfirmDialog';
|
|
31
|
+
export { useToast } from './forms/Toast';
|
|
32
|
+
export { RolePicker, BanControl, type RolePickerProps, type RoleOption, type BanControlProps } from './forms/People';
|
|
33
|
+
export { BarChart, type BarChartProps, type BarSeries } from './blocks/BarChart';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ThemeChoice } from '../theme';
|
|
3
|
+
import type { NavSection, RenderLink } from './nav';
|
|
4
|
+
import { type AppIdentity, type SidebarProps } from './Sidebar';
|
|
5
|
+
export type AdminShellProps = {
|
|
6
|
+
app: AppIdentity;
|
|
7
|
+
/** The app's colour (hex): active navigation, primary buttons, meters, links. Text on it is white or ink, whichever reads better. */
|
|
8
|
+
brand?: string | undefined;
|
|
9
|
+
nav: NavSection[];
|
|
10
|
+
/** Which nav items the phone's dock shows, by key (at most 5). Default: the first 5. */
|
|
11
|
+
dockItems?: string[] | undefined;
|
|
12
|
+
user?: SidebarProps['user'];
|
|
13
|
+
/** Renders a navigation link with the app's router (TanStack Router's Link, Next's Link…). Default: <a href>. */
|
|
14
|
+
renderLink?: RenderLink | undefined;
|
|
15
|
+
/** Buttons in the phone's top bar, after the theme switch (notifications). */
|
|
16
|
+
mobileActions?: ReactNode;
|
|
17
|
+
/** Extra things at the bottom of the sidebar, above the person. */
|
|
18
|
+
sidebarFooter?: ReactNode;
|
|
19
|
+
/** The theme, when the app keeps it (controlled). */
|
|
20
|
+
theme?: ThemeChoice | undefined;
|
|
21
|
+
/** The theme before the stored one is read: what server rendering shows. Default "system". */
|
|
22
|
+
defaultTheme?: ThemeChoice | undefined;
|
|
23
|
+
onThemeChange?: ((choice: ThemeChoice) => void) | undefined;
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The admin's frame: the floating dark sidebar on desktop; on phones a top bar and the floating dock.
|
|
28
|
+
* Holds the theme (light, dark, system) and the app's brand colour. Every other part of the kit goes
|
|
29
|
+
* inside it, and its styles stay inside it (`.ja-root`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function AdminShell({ app, brand, nav, dockItems, user, renderLink, mobileActions, sidebarFooter, theme, defaultTheme, onThemeChange, children, }: AdminShellProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type NavItem, type RenderLink } from './nav';
|
|
2
|
+
export type DockProps = {
|
|
3
|
+
/** Up to 5 items (more are not shown): icon over label, the current one filled with the brand colour. */
|
|
4
|
+
items: NavItem[];
|
|
5
|
+
renderLink?: RenderLink | undefined;
|
|
6
|
+
};
|
|
7
|
+
/** The phone's navigation: a floating dark dock at the bottom (760 px and below). */
|
|
8
|
+
export declare function Dock({ items, renderLink }: DockProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InputHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export type PageHeaderProps = {
|
|
3
|
+
/** The page's one h1. */
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
/** One line of context under it. */
|
|
6
|
+
description?: ReactNode;
|
|
7
|
+
/** Desktop-only tools: search, theme, notifications. On phones they live in the top bar or the page. */
|
|
8
|
+
tools?: ReactNode;
|
|
9
|
+
/** The page's actions, shown on every screen size; one primary at most. */
|
|
10
|
+
actions?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/** The top of a page: its title and context, then search, tools and the main action. */
|
|
13
|
+
export declare function PageHeader({ title, description, tools, actions }: PageHeaderProps): import("react").JSX.Element;
|
|
14
|
+
export type TopSearchProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> & {
|
|
15
|
+
/** The accessible name, also the placeholder unless one is given ("Search anything"). */
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
/** The page's search field: a pill with the search icon. The app handles what it searches. */
|
|
19
|
+
export declare function TopSearch({ label, placeholder, className, ...input }: TopSearchProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type NavSection, type RenderLink } from './nav';
|
|
3
|
+
/** The app's name and mark (a letter, or its logo), shown in the sidebar and the phone's top bar. */
|
|
4
|
+
export type AppIdentity = {
|
|
5
|
+
name: string;
|
|
6
|
+
mark: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export type SidebarProps = {
|
|
9
|
+
app: AppIdentity;
|
|
10
|
+
sections: NavSection[];
|
|
11
|
+
/** The signed-in person, at the bottom. */
|
|
12
|
+
user?: {
|
|
13
|
+
name: string;
|
|
14
|
+
role?: string | undefined;
|
|
15
|
+
image?: string | null | undefined;
|
|
16
|
+
} | undefined;
|
|
17
|
+
renderLink?: RenderLink | undefined;
|
|
18
|
+
/** Where the collapsed state is remembered in this browser. */
|
|
19
|
+
storageKey?: string | undefined;
|
|
20
|
+
/** Extra things above the person (a sign-out link). */
|
|
21
|
+
footer?: ReactNode;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The desktop navigation: Bento's floating dark panel with Daylight's labelled sections, collapsible
|
|
25
|
+
* to an icon rail (remembered in this browser). Hidden at 760 px and below, where the Dock takes over.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Sidebar({ app, sections, user, renderLink, storageKey, footer }: SidebarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Where an arrow, Home or End key moves in the group (the radio pattern), or null for another key. */
|
|
2
|
+
export declare function nextIndex(key: string, current: number, count: number): number | null;
|
|
3
|
+
/**
|
|
4
|
+
* The theme switch: light, dark, or the system's (the default). A radio group of three; in the
|
|
5
|
+
* dark sidebar it shows the names too, and in a collapsed sidebar it's one button that goes to the
|
|
6
|
+
* next choice. The choice is remembered (AdminShell keeps it).
|
|
7
|
+
*/
|
|
8
|
+
export declare function ThemeToggle({ tone }: {
|
|
9
|
+
tone?: 'tile' | 'night';
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/** One place in the admin. `current` marks the page being shown. */
|
|
3
|
+
export type NavItem = {
|
|
4
|
+
/** Stable and unique: the React key, and how `dockItems` picks items. */
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
href: string;
|
|
8
|
+
icon: ReactNode;
|
|
9
|
+
/** A number to show next to it (people waiting, open reports). */
|
|
10
|
+
count?: number | string | undefined;
|
|
11
|
+
current?: boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
/** A labelled group in the sidebar ("Manage"). `end` groups sit at the bottom (Settings). */
|
|
14
|
+
export type NavSection = {
|
|
15
|
+
label?: string | undefined;
|
|
16
|
+
items: NavItem[];
|
|
17
|
+
placement?: 'start' | 'end' | undefined;
|
|
18
|
+
};
|
|
19
|
+
/** What a link needs; apps with a router pass `renderLink` to render their own link component. */
|
|
20
|
+
export type LinkProps = {
|
|
21
|
+
item: NavItem;
|
|
22
|
+
className: string;
|
|
23
|
+
'aria-current': 'page' | undefined;
|
|
24
|
+
title: string | undefined;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
export type RenderLink = (props: LinkProps) => ReactNode;
|
|
28
|
+
/** A plain link: the default when the app passes no `renderLink`. */
|
|
29
|
+
export declare const plainLink: RenderLink;
|
|
30
|
+
/** "2481" → "2,481"; strings as given. */
|
|
31
|
+
export declare const formatCount: (count: number | string) => string;
|
|
32
|
+
/** A count for the icon rail's small badge: 99 at most ("99+"); strings as given. */
|
|
33
|
+
export declare const formatBadge: (count: number | string) => string;
|