@bloxwap/hig 0.0.0-stage → 0.2.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/LICENSE +5 -0
- package/README.md +44 -2
- package/chart/README.md +23 -0
- package/chart/dist/index.d.ts +8 -0
- package/chart/dist/index.js +12 -0
- package/contracts/README.md +3 -0
- package/contracts/dist/announcements.d.ts +12 -0
- package/contracts/dist/announcements.js +8 -0
- package/contracts/dist/feedback.d.ts +40 -0
- package/contracts/dist/feedback.js +1 -0
- package/contracts/dist/index.d.ts +41 -0
- package/contracts/dist/index.js +52 -0
- package/contracts/dist/messages.d.ts +162 -0
- package/contracts/dist/messages.js +68 -0
- package/feedback/README.md +7 -0
- package/feedback/assets/error.wav +0 -0
- package/feedback/assets/manifest.json +68 -0
- package/feedback/assets/success.wav +0 -0
- package/feedback/assets/tick.wav +0 -0
- package/feedback/assets/toggle.wav +0 -0
- package/feedback/dist/browser-haptic.d.ts +23 -0
- package/feedback/dist/browser-haptic.js +41 -0
- package/feedback/dist/contract.d.ts +96 -0
- package/feedback/dist/contract.js +58 -0
- package/feedback/dist/native.d.ts +27 -0
- package/feedback/dist/native.js +63 -0
- package/feedback/dist/preferences.d.ts +8 -0
- package/feedback/dist/preferences.js +24 -0
- package/feedback/dist/react.d.ts +19 -0
- package/feedback/dist/react.js +23 -0
- package/feedback/dist/web-haptic.d.ts +6 -0
- package/feedback/dist/web-haptic.js +6 -0
- package/feedback/dist/web-sound.d.ts +5 -0
- package/feedback/dist/web-sound.js +32 -0
- package/feedback/dist/web.d.ts +3 -0
- package/feedback/dist/web.js +4 -0
- package/native/README.md +11 -0
- package/native/android/build.gradle +28 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableView.java +173 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGAdjustableViewManager.java +23 -0
- package/native/android/src/main/java/com/bloxwap/hig/HIGPackage.java +24 -0
- package/native/dist/animated-number-model.d.ts +24 -0
- package/native/dist/animated-number-model.js +110 -0
- package/native/dist/animated-number.d.ts +9 -0
- package/native/dist/animated-number.js +93 -0
- package/native/dist/brand.d.ts +7 -0
- package/native/dist/brand.js +6 -0
- package/native/dist/button.d.ts +29 -0
- package/native/dist/button.js +34 -0
- package/native/dist/checkbox.d.ts +3 -0
- package/native/dist/checkbox.js +11 -0
- package/native/dist/data.d.ts +40 -0
- package/native/dist/data.js +27 -0
- package/native/dist/field.d.ts +15 -0
- package/native/dist/field.js +13 -0
- package/native/dist/gesture-sheet.d.ts +73 -0
- package/native/dist/gesture-sheet.js +151 -0
- package/native/dist/navigation.d.ts +47 -0
- package/native/dist/navigation.js +16 -0
- package/native/dist/overlay.d.ts +36 -0
- package/native/dist/overlay.js +65 -0
- package/native/dist/provider.d.ts +43 -0
- package/native/dist/provider.js +52 -0
- package/native/dist/radio-group.d.ts +5 -0
- package/native/dist/radio-group.js +53 -0
- package/native/dist/recipes.d.ts +42 -0
- package/native/dist/recipes.js +19 -0
- package/native/dist/roles.d.ts +6 -0
- package/native/dist/roles.js +4 -0
- package/native/dist/select.d.ts +3 -0
- package/native/dist/select.js +9 -0
- package/native/dist/selection-types.d.ts +22 -0
- package/native/dist/selection-types.js +1 -0
- package/native/dist/selection.d.ts +7 -0
- package/native/dist/selection.js +6 -0
- package/native/dist/slider.d.ts +11 -0
- package/native/dist/slider.js +41 -0
- package/native/dist/status.d.ts +75 -0
- package/native/dist/status.js +72 -0
- package/native/dist/surface.d.ts +18 -0
- package/native/dist/surface.js +41 -0
- package/native/dist/switch-row.d.ts +8 -0
- package/native/dist/switch-row.js +18 -0
- package/native/dist/switch.d.ts +10 -0
- package/native/dist/switch.js +23 -0
- package/native/dist/text-content.d.ts +5 -0
- package/native/dist/text-content.js +6 -0
- package/native-fonts/README.md +17 -0
- package/native-fonts/dist/index.d.ts +164 -0
- package/native-fonts/dist/index.js +164 -0
- package/native-fonts/fonts/BloxwapMono-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapMono.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-ExtraBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSans.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansKR.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC-SemiBold.ttf +0 -0
- package/native-fonts/fonts/BloxwapSansSC.ttf +0 -0
- package/native-fonts/fonts/OFL.txt +93 -0
- package/native-fonts/fonts/manifest.json +164 -0
- package/og-fonts/README.md +34 -0
- package/og-fonts/dist/index.d.ts +116 -0
- package/og-fonts/dist/index.js +102 -0
- package/og-fonts/dist/node.d.ts +11 -0
- package/og-fonts/dist/node.js +39 -0
- package/og-fonts/fonts/BloxwapMono-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Black.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Bold.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans-Medium.ttf +0 -0
- package/og-fonts/fonts/BloxwapSans.ttf +0 -0
- package/og-fonts/fonts/OFL.txt +93 -0
- package/og-fonts/fonts/manifest.json +65 -0
- package/package.json +358 -4
- package/react/README.md +9 -0
- package/react/dist/animated-number-model.d.ts +20 -0
- package/react/dist/animated-number-model.js +92 -0
- package/react/dist/animated-number.d.ts +8 -0
- package/react/dist/animated-number.js +71 -0
- package/react/dist/base.css +9 -0
- package/react/dist/brand.d.ts +7 -0
- package/react/dist/brand.js +4 -0
- package/react/dist/button.d.ts +14 -0
- package/react/dist/button.js +20 -0
- package/react/dist/data.d.ts +63 -0
- package/react/dist/data.js +23 -0
- package/react/dist/dialog.d.ts +29 -0
- package/react/dist/dialog.js +21 -0
- package/react/dist/field.d.ts +15 -0
- package/react/dist/field.js +19 -0
- package/react/dist/gesture-sheet.d.ts +41 -0
- package/react/dist/gesture-sheet.js +128 -0
- package/react/dist/navigation.d.ts +48 -0
- package/react/dist/navigation.js +69 -0
- package/react/dist/overlay.d.ts +17 -0
- package/react/dist/overlay.js +18 -0
- package/react/dist/provider.d.ts +25 -0
- package/react/dist/provider.js +50 -0
- package/react/dist/recipes/activity-list.d.ts +8 -0
- package/react/dist/recipes/activity-list.js +6 -0
- package/react/dist/recipes/balance-card.d.ts +6 -0
- package/react/dist/recipes/balance-card.js +5 -0
- package/react/dist/recipes/code-window.d.ts +4 -0
- package/react/dist/recipes/code-window.js +4 -0
- package/react/dist/recipes/install-command.d.ts +5 -0
- package/react/dist/recipes/install-command.js +8 -0
- package/react/dist/recipes/market-row.d.ts +25 -0
- package/react/dist/recipes/market-row.js +8 -0
- package/react/dist/recipes/marketing-hero.d.ts +7 -0
- package/react/dist/recipes/marketing-hero.js +5 -0
- package/react/dist/recipes/trade-entry.d.ts +11 -0
- package/react/dist/recipes/trade-entry.js +12 -0
- package/react/dist/recipes.d.ts +8 -0
- package/react/dist/recipes.js +9 -0
- package/react/dist/select.d.ts +4 -0
- package/react/dist/select.js +172 -0
- package/react/dist/selection.d.ts +27 -0
- package/react/dist/selection.js +16 -0
- package/react/dist/slider.d.ts +11 -0
- package/react/dist/slider.js +10 -0
- package/react/dist/status.d.ts +53 -0
- package/react/dist/status.js +43 -0
- package/react/dist/styles.css +228 -0
- package/react/dist/surface.d.ts +291 -0
- package/react/dist/surface.js +9 -0
- package/tokens/README.md +9 -0
- package/tokens/assets/bloxwap-icon.svg +1 -0
- package/tokens/dist/index.d.ts +429 -0
- package/tokens/dist/index.js +507 -0
- package/tokens/dist/manifest.json +197 -0
- package/tokens/dist/theme.d.ts +11 -0
- package/tokens/dist/theme.js +22 -0
- package/tokens/dist/tokens.css +119 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface NumberProps {
|
|
3
|
+
value: number | null | undefined;
|
|
4
|
+
options?: Intl.NumberFormatOptions;
|
|
5
|
+
stale?: boolean;
|
|
6
|
+
label?: string;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
suffix?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function NumberReadout({ value, options, stale, label, prefix, suffix }: NumberProps): React.JSX.Element;
|
|
11
|
+
export declare function Usd(props: NumberProps): React.JSX.Element;
|
|
12
|
+
/** Input is percent points: 5 means 5%, not 500%. */
|
|
13
|
+
export declare function Percent(props: NumberProps): React.JSX.Element;
|
|
14
|
+
export declare function Metric({ label, value }: {
|
|
15
|
+
label: string;
|
|
16
|
+
value: React.ReactNode;
|
|
17
|
+
}): React.JSX.Element;
|
|
18
|
+
export declare const Stat: typeof Metric;
|
|
19
|
+
export interface ListProps<T> {
|
|
20
|
+
items: readonly T[];
|
|
21
|
+
keyFor: (item: T) => string;
|
|
22
|
+
render: (item: T) => React.ReactNode;
|
|
23
|
+
empty?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
loading?: boolean;
|
|
26
|
+
error?: string;
|
|
27
|
+
onRetry?: () => void;
|
|
28
|
+
onLoadMore?: () => void;
|
|
29
|
+
}
|
|
30
|
+
export declare function List<T>({ items, keyFor, render, empty, label, loading, error, onRetry, onLoadMore }: ListProps<T>): React.JSX.Element;
|
|
31
|
+
export declare function Row({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): React.JSX.Element;
|
|
32
|
+
export interface Column<T> {
|
|
33
|
+
key: string;
|
|
34
|
+
label: string;
|
|
35
|
+
render: (row: T) => React.ReactNode; /** Logical alignment applies to both header and data cells. */
|
|
36
|
+
align?: 'start' | 'center' | 'end';
|
|
37
|
+
sort?: 'ascending' | 'descending';
|
|
38
|
+
onSort?: () => void;
|
|
39
|
+
}
|
|
40
|
+
/** Keep native table-row semantics and HIG's cells while forwarding host highlights, data/ARIA attributes and event handlers. */
|
|
41
|
+
export type TableRowProps = Omit<React.HTMLAttributes<HTMLTableRowElement>, 'children' | 'dangerouslySetInnerHTML' | 'role'> & {
|
|
42
|
+
[name: `data-${string}`]: string | number | boolean | undefined;
|
|
43
|
+
};
|
|
44
|
+
export interface TableProps<T> {
|
|
45
|
+
caption: string;
|
|
46
|
+
rows: readonly T[];
|
|
47
|
+
columns: readonly Column<T>[];
|
|
48
|
+
keyFor: (row: T) => string;
|
|
49
|
+
rowProps?: (row: T, index: number) => TableRowProps;
|
|
50
|
+
/** Host classes/style belong to the focusable scroll region; tableClassName styles the table itself. */
|
|
51
|
+
className?: string;
|
|
52
|
+
style?: React.CSSProperties;
|
|
53
|
+
tableClassName?: string;
|
|
54
|
+
/** Keep the accessible caption when a visible section heading already names this table. */
|
|
55
|
+
captionHidden?: boolean;
|
|
56
|
+
/** Set a bounded scroll-region height through style/className for vertical sticky scrolling. */
|
|
57
|
+
stickyHeader?: boolean;
|
|
58
|
+
/** Retains existing rows and suppresses an empty message while loading. */
|
|
59
|
+
loading?: boolean;
|
|
60
|
+
/** Content of one full-width state cell, such as an empty explanation, skeleton, or error/retry UI. Supply content, not tr/td elements. null hides the default state. */
|
|
61
|
+
state?: React.ReactNode;
|
|
62
|
+
}
|
|
63
|
+
export declare function Table<T>({ caption, rows, columns, keyFor, rowProps, className, style, tableClassName, captionHidden, stickyHeader, loading, state }: TableProps<T>): React.JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useHIG } from './provider.js';
|
|
7
|
+
export function NumberReadout({ value, options, stale, label, prefix = '', suffix = '' }) { const { locale, messages } = useHIG(); const known = value != null && Number.isFinite(value), formatted = formatNumber(value, locale, options), reading = known ? `${prefix}${formatted}${suffix}` : formatted; return _jsxs("span", { className: 'hig-number', "aria-label": label ? `${label}: ${reading}${stale ? ` ${messages.stale ?? en.stale}` : ''}` : undefined, children: [reading, stale && _jsxs("span", { children: [" ", messages.stale ?? en.stale] })] }); }
|
|
8
|
+
export function Usd(props) { return _jsx(NumberReadout, { ...props, options: { style: 'currency', currency: 'USD', ...props.options } }); }
|
|
9
|
+
/** Input is percent points: 5 means 5%, not 500%. */
|
|
10
|
+
export function Percent(props) { return _jsx(NumberReadout, { ...props, value: props.value == null ? props.value : props.value / 100, options: { maximumFractionDigits: Math.max(3, props.options?.minimumFractionDigits ?? 0), ...props.options, style: 'percent' } }); }
|
|
11
|
+
export function Metric({ label, value }) { return _jsxs("dl", { className: 'hig-surface', children: [_jsx("dt", { children: label }), _jsx("dd", { children: value })] }); }
|
|
12
|
+
export const Stat = Metric;
|
|
13
|
+
export function List({ items, keyFor, render, empty, label, loading = false, error, onRetry, onLoadMore }) {
|
|
14
|
+
const { messages } = useHIG();
|
|
15
|
+
return _jsxs("div", { className: 'hig-data-list', "aria-busy": loading, children: [items.length ? _jsx("ul", { className: 'hig-list', "aria-label": label, children: items.map(item => _jsx("li", { children: render(item) }, keyFor(item))) }) : !loading && !error ? _jsx("p", { className: 'hig-list-message', children: empty ?? messages.noItems ?? en.noItems }) : null, loading && _jsx("p", { className: 'hig-list-message', role: 'status', children: messages.loadingItems ?? en.loadingItems }), error && _jsxs("div", { className: 'hig-list-error', role: 'alert', children: [_jsx("p", { className: 'hig-list-message', children: error }), onRetry && _jsx("button", { className: 'hig-button', "data-intent": 'secondary', type: 'button', disabled: loading, onClick: onRetry, children: messages.retry ?? en.retry })] }), onLoadMore && _jsx("button", { className: 'hig-button', "data-intent": 'secondary', type: 'button', disabled: loading, onClick: onLoadMore, children: messages.loadMore ?? en.loadMore })] });
|
|
16
|
+
}
|
|
17
|
+
export function Row({ className, ...props }) { return _jsx("div", { ...props, className: `hig-row${className ? ` ${className}` : ''}` }); }
|
|
18
|
+
function tableRowAttributes(props) { const attributes = { ...props }; delete attributes.children; delete attributes.dangerouslySetInnerHTML; delete attributes.role; return attributes; }
|
|
19
|
+
export function Table({ caption, rows, columns, keyFor, rowProps, className, style, tableClassName, captionHidden = false, stickyHeader = false, loading = false, state }) {
|
|
20
|
+
const { messages } = useHIG();
|
|
21
|
+
const status = state !== undefined ? state : loading ? _jsx("span", { role: 'status', children: messages.loading ?? en.loading }) : !rows.length ? messages.noRows ?? en.noRows : null;
|
|
22
|
+
return _jsx("div", { className: `hig-table-scroll${className ? ` ${className}` : ''}`, style: style, tabIndex: 0, role: 'region', "aria-label": caption, "aria-busy": loading || undefined, children: _jsxs("table", { className: `hig-table${tableClassName ? ` ${tableClassName}` : ''}`, "data-sticky-header": stickyHeader || undefined, children: [_jsx("caption", { className: captionHidden ? 'hig-sr-only' : undefined, children: caption }), _jsx("thead", { children: _jsx("tr", { children: columns.map(c => _jsx("th", { scope: 'col', "aria-sort": c.sort, style: c.align ? { textAlign: c.align } : undefined, children: c.onSort ? _jsxs("button", { type: 'button', className: 'hig-table-sort', onClick: c.onSort, children: [c.label, _jsxs("svg", { className: 'hig-table-sort-icon', "aria-hidden": 'true', focusable: 'false', width: '14', height: '14', viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: '1.5', strokeLinecap: 'round', strokeLinejoin: 'round', children: [_jsx("path", { className: 'hig-table-sort-up', d: 'm4.5 6 3.5-3.5L11.5 6' }), _jsx("path", { className: 'hig-table-sort-down', d: 'm4.5 10 3.5 3.5 3.5-3.5' })] })] }) : c.label }, c.key)) }) }), _jsxs("tbody", { children: [rows.map((row, index) => _createElement("tr", { ...tableRowAttributes(rowProps?.(row, index)), key: keyFor(row) }, columns.map(c => _jsx("td", { style: c.align ? { textAlign: c.align } : undefined, children: c.render(row) }, c.key)))), status !== null && status !== false && _jsx("tr", { className: 'hig-table-state', children: _jsx("td", { colSpan: Math.max(1, columns.length), children: status }) })] })] }) });
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as Modal from '@radix-ui/react-dialog';
|
|
3
|
+
/** Layout, focus and dismissal events on the owned Radix content element. */
|
|
4
|
+
export type DialogContentProps = Omit<React.ComponentPropsWithoutRef<typeof Modal.Content>, 'children' | 'asChild' | 'forceMount' | 'role' | 'dir' | 'lang' | 'id' | 'aria-labelledby' | 'aria-describedby' | 'dangerouslySetInnerHTML'>;
|
|
5
|
+
export interface DialogProps {
|
|
6
|
+
open: boolean;
|
|
7
|
+
onOpenChange: (open: boolean) => void;
|
|
8
|
+
title: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
trigger?: React.ReactNode;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
/** Keep the required accessible title while the host supplies its visible heading. */
|
|
13
|
+
titleHidden?: boolean;
|
|
14
|
+
/** Keep supporting text available to assistive technology without rendering it visibly. */
|
|
15
|
+
descriptionHidden?: boolean;
|
|
16
|
+
contentProps?: DialogContentProps;
|
|
17
|
+
contentRef?: React.Ref<HTMLDivElement>;
|
|
18
|
+
/** Undefined keeps the standard action; null omits it. A custom ref-capable button is composed with Close. */
|
|
19
|
+
closeButton?: React.ReactElement | null;
|
|
20
|
+
/** Close button text and accessible name; defaults to HIGProvider `messages.close`. */
|
|
21
|
+
closeLabel?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AlertDialogProps extends Omit<DialogProps, 'closeLabel'> {
|
|
24
|
+
cancelLabel?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function Dialog(props: DialogProps): React.JSX.Element;
|
|
27
|
+
export declare const Sheet: typeof Dialog;
|
|
28
|
+
/** Critical confirmation stays open on outside interaction and requires an explicit decision. */
|
|
29
|
+
export declare function AlertDialog({ cancelLabel, ...props }: AlertDialogProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as Modal from '@radix-ui/react-dialog';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG, useThemeStyle } from './provider.js';
|
|
6
|
+
import { Button } from './button.js';
|
|
7
|
+
const OWNED_CONTENT_PROPS = new Set(['children', 'asChild', 'forceMount', 'role', 'dir', 'lang', 'id', 'ref', 'aria-labelledby', 'aria-describedby', 'dangerouslySetInnerHTML']);
|
|
8
|
+
function DialogFrame({ open, onOpenChange, title, description, trigger, children, closeLabel, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, alert = false }) {
|
|
9
|
+
const { messages, direction, locale, density } = useHIG();
|
|
10
|
+
const themeStyle = useThemeStyle();
|
|
11
|
+
// JavaScript callers receive the same ownership guarantees as typed callers. Copy first;
|
|
12
|
+
// a host may share or freeze its props object across several modal instances.
|
|
13
|
+
const safeContent = Object.fromEntries(Object.entries(contentProps ?? {}).filter(([key]) => !OWNED_CONTENT_PROPS.has(key)));
|
|
14
|
+
const { className, onPointerDownOutside, style, ...content } = safeContent;
|
|
15
|
+
return _jsxs(Modal.Root, { open: open, onOpenChange: onOpenChange, children: [trigger && _jsx(Modal.Trigger, { asChild: true, children: trigger }), _jsxs(Modal.Portal, { children: [_jsx(Modal.Overlay, { className: 'hig-backdrop' }), _jsxs(Modal.Content, { ...content, ...(!description ? { 'aria-describedby': undefined } : {}), ref: contentRef, role: alert ? 'alertdialog' : 'dialog', className: ['hig-dialog', className].filter(Boolean).join(' '), dir: direction, lang: locale, "data-hig-density": density, style: { ...themeStyle, ...style }, onPointerDownOutside: event => { onPointerDownOutside?.(event); if (alert)
|
|
16
|
+
event.preventDefault(); }, children: [_jsx(Modal.Title, { className: titleHidden ? 'hig-sr-only' : 'hig-dialog-title', children: title }), description && _jsx(Modal.Description, { className: descriptionHidden ? 'hig-sr-only' : 'hig-dialog-description', children: description }), children, closeButton !== null && _jsx(Modal.Close, { asChild: true, children: closeButton ?? _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: closeLabel ?? messages.close ?? en.close }) })] })] })] });
|
|
17
|
+
}
|
|
18
|
+
export function Dialog(props) { return _jsx(DialogFrame, { ...props }); }
|
|
19
|
+
export const Sheet = Dialog;
|
|
20
|
+
/** Critical confirmation stays open on outside interaction and requires an explicit decision. */
|
|
21
|
+
export function AlertDialog({ cancelLabel, ...props }) { const { messages } = useHIG(); return _jsx(DialogFrame, { ...props, alert: true, closeLabel: cancelLabel ?? messages.cancel ?? en.cancel }); }
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function Field({ id: provided, label, description, error, required, disabled, children }: React.PropsWithChildren<{
|
|
3
|
+
id?: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}>): React.JSX.Element;
|
|
10
|
+
export declare const Label: (props: React.LabelHTMLAttributes<HTMLLabelElement>) => React.JSX.Element;
|
|
11
|
+
export declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
|
|
12
|
+
export declare const TextArea: React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
13
|
+
/** Raw string and selection stay untouched; host parses/validates precision on submit. */
|
|
14
|
+
export declare const AmountInput: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & React.RefAttributes<HTMLInputElement>>;
|
|
15
|
+
export declare const SearchInput: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useId, forwardRef } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG } from './provider.js';
|
|
6
|
+
const Context = createContext({ id: '' });
|
|
7
|
+
export function Field({ id: provided, label, description, error, required, disabled, children }) {
|
|
8
|
+
const { messages } = useHIG();
|
|
9
|
+
const generated = useId();
|
|
10
|
+
const id = provided ?? generated;
|
|
11
|
+
const ids = [description && `${id}-help`, error && `${id}-error`].filter(Boolean).join(' ') || undefined;
|
|
12
|
+
return _jsx(Context.Provider, { value: { id, description: ids, invalid: !!error, disabled, required }, children: _jsxs("div", { className: 'hig-field', children: [_jsxs("label", { htmlFor: id, children: [label, required ? ` ${messages.required ?? en.required}` : ''] }), children, description && _jsx("p", { id: `${id}-help`, children: description }), error && _jsx("p", { id: `${id}-error`, role: 'alert', children: error })] }) });
|
|
13
|
+
}
|
|
14
|
+
export const Label = (props) => _jsx("label", { ...props });
|
|
15
|
+
export const Input = forwardRef(function Input(props, ref) { const field = useContext(Context); return _jsx("input", { id: field.id || undefined, "aria-describedby": field.description, "aria-invalid": field.invalid || undefined, required: field.required, ...props, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); });
|
|
16
|
+
export const TextArea = forwardRef(function TextArea(props, ref) { const field = useContext(Context); return _jsx("textarea", { id: field.id || undefined, "aria-describedby": field.description, "aria-invalid": field.invalid || undefined, required: field.required, ...props, disabled: !!field.disabled || props.disabled, ref: ref, className: `hig-input ${props.className ?? ''}` }); });
|
|
17
|
+
/** Raw string and selection stay untouched; host parses/validates precision on submit. */
|
|
18
|
+
export const AmountInput = forwardRef(function AmountInput(props, ref) { return _jsx(Input, { ...props, ref: ref, type: 'text', inputMode: props.inputMode ?? 'decimal' }); });
|
|
19
|
+
export const SearchInput = forwardRef(function SearchInput(props, ref) { return _jsx(Input, { ...props, ref: ref, type: 'search' }); });
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Drawer, type DialogProps as BackendProps } from 'vaul';
|
|
3
|
+
import type { DialogProps, DialogContentProps } from './dialog.js';
|
|
4
|
+
/** Vaul owns gestures, detents, input repositioning and background scaling. HIG owns the controlled modal root. */
|
|
5
|
+
type HostBackendProps<Props> = Props extends object ? Omit<Props, 'children' | 'open' | 'defaultOpen' | 'onOpenChange' | 'modal' | 'nested' | 'onClose'> : never;
|
|
6
|
+
export type GestureSheetBackendProps = HostBackendProps<BackendProps>;
|
|
7
|
+
type SnapPointBackendProp = 'snapPoints' | 'snapPoint' | 'activeSnapPoint' | 'setActiveSnapPoint' | 'fadeFromIndex' | 'snapToSequentialPoint';
|
|
8
|
+
export type GestureSheetDynamicBackendProps = Omit<GestureSheetBackendProps, SnapPointBackendProp> & {
|
|
9
|
+
[Key in SnapPointBackendProp]?: never;
|
|
10
|
+
};
|
|
11
|
+
export type GestureSheetContentProps = DialogContentProps & {
|
|
12
|
+
[key: `data-${string}`]: string | number | boolean | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type GestureSheetHandleProps = Omit<React.ComponentPropsWithoutRef<typeof Drawer.Handle>, 'children' | 'aria-hidden' | 'dangerouslySetInnerHTML' | 'onClick' | 'onPointerDown' | 'onPointerMove' | 'onPointerCancel'>;
|
|
15
|
+
export type GestureSheetOverlayProps = Omit<React.ComponentPropsWithoutRef<typeof Drawer.Overlay>, 'children' | 'asChild' | 'forceMount' | 'dangerouslySetInnerHTML'>;
|
|
16
|
+
interface GestureSheetCommonProps extends Omit<DialogProps, 'contentProps'> {
|
|
17
|
+
contentProps?: GestureSheetContentProps;
|
|
18
|
+
/** Default anatomy pads and scrolls the card; custom anatomy leaves layout and scrolling to the host. */
|
|
19
|
+
contentMode?: 'default' | 'custom';
|
|
20
|
+
/** The real backend drag handle is included by default. */
|
|
21
|
+
handle?: boolean;
|
|
22
|
+
handleProps?: GestureSheetHandleProps;
|
|
23
|
+
handleRef?: React.Ref<HTMLDivElement>;
|
|
24
|
+
overlayProps?: GestureSheetOverlayProps;
|
|
25
|
+
}
|
|
26
|
+
export type GestureSheetProps = GestureSheetCommonProps & (
|
|
27
|
+
/** Backend defaults are retained, including autoFocus=false and repositionInputs=true. */
|
|
28
|
+
{
|
|
29
|
+
enableDynamicSizing?: false;
|
|
30
|
+
backendProps?: GestureSheetBackendProps;
|
|
31
|
+
maxDynamicContentSize?: never;
|
|
32
|
+
}
|
|
33
|
+
/** Vertical content sizing is intrinsic and cannot be combined with Vaul detents. */
|
|
34
|
+
| {
|
|
35
|
+
enableDynamicSizing: true;
|
|
36
|
+
backendProps?: GestureSheetDynamicBackendProps; /** A finite positive content-height ceiling in CSS pixels; the viewport ceiling still applies. */
|
|
37
|
+
maxDynamicContentSize?: number;
|
|
38
|
+
});
|
|
39
|
+
/** Optional web gesture backend. Install vaul separately; the core overlay entry never imports it. */
|
|
40
|
+
export declare function GestureSheet({ open, onOpenChange, title, description, trigger, children, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, closeLabel, backendProps, contentMode, handle, handleProps, handleRef, overlayProps, enableDynamicSizing, maxDynamicContentSize }: GestureSheetProps): React.JSX.Element;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Drawer } from 'vaul';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useHIG, useThemeStyle } from './provider.js';
|
|
7
|
+
import { Button } from './button.js';
|
|
8
|
+
const OWNED_CONTENT = new Set(['children', 'asChild', 'forceMount', 'role', 'dir', 'lang', 'id', 'ref', 'aria-labelledby', 'aria-describedby', 'dangerouslySetInnerHTML']);
|
|
9
|
+
const OWNED_ROOT = new Set(['children', 'open', 'defaultOpen', 'onOpenChange', 'modal', 'nested', 'onClose']);
|
|
10
|
+
const OWNED_OVERLAY = new Set(['children', 'asChild', 'forceMount', 'ref', 'dangerouslySetInnerHTML']);
|
|
11
|
+
const OWNED_HANDLE = new Set(['children', 'aria-hidden', 'ref', 'dangerouslySetInnerHTML', 'onClick', 'onPointerDown', 'onPointerMove', 'onPointerCancel']);
|
|
12
|
+
const OWNED_BACKEND_DATA = new Set(['data-vaul-drawer', 'data-vaul-drawer-direction', 'data-vaul-delayed-snap-points', 'data-vaul-snap-points', 'data-vaul-custom-container', 'data-vaul-animate', 'data-vaul-overlay', 'data-vaul-snap-points-overlay', 'data-vaul-handle', 'data-vaul-drawer-visible', 'data-vaul-handle-hitarea']);
|
|
13
|
+
const DYNAMIC_BACKEND = new Set(['snapPoints', 'snapPoint', 'activeSnapPoint', 'setActiveSnapPoint', 'fadeFromIndex', 'snapToSequentialPoint']);
|
|
14
|
+
const safeProps = (props, owned) => Object.fromEntries(Object.entries(props ?? {}).filter(([key]) => !owned.has(key) && !OWNED_BACKEND_DATA.has(key)));
|
|
15
|
+
function useDynamicHeight(open, enabled, reducedMotion, panel, content) {
|
|
16
|
+
const animation = useRef(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!open || !enabled || !content)
|
|
19
|
+
return;
|
|
20
|
+
const card = panel.current;
|
|
21
|
+
if (!card)
|
|
22
|
+
return;
|
|
23
|
+
let previous = null;
|
|
24
|
+
const cancel = () => { const current = animation.current; animation.current = null; current?.cancel(); };
|
|
25
|
+
const measure = () => {
|
|
26
|
+
const next = content.getBoundingClientRect().height, from = animation.current ? card.getBoundingClientRect().height : previous;
|
|
27
|
+
previous = next;
|
|
28
|
+
if (from === null || Math.abs(from - next) < .5)
|
|
29
|
+
return;
|
|
30
|
+
if (reducedMotion || card.style.height || typeof card.animate !== 'function') {
|
|
31
|
+
cancel();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
cancel();
|
|
35
|
+
const current = card.animate([{ height: `${from}px` }, { height: `${next}px` }], { duration: 200, easing: 'cubic-bezier(.32,.72,0,1)' });
|
|
36
|
+
animation.current = current;
|
|
37
|
+
current.onfinish = current.oncancel = () => { if (animation.current === current)
|
|
38
|
+
animation.current = null; };
|
|
39
|
+
};
|
|
40
|
+
const resize = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(measure);
|
|
41
|
+
resize?.observe(content);
|
|
42
|
+
measure();
|
|
43
|
+
const inline = typeof MutationObserver === 'undefined' ? null : new MutationObserver(() => { if (card.style.height)
|
|
44
|
+
cancel(); });
|
|
45
|
+
inline?.observe(card, { attributes: true, attributeFilter: ['style'] });
|
|
46
|
+
return () => { resize?.disconnect(); inline?.disconnect(); cancel(); };
|
|
47
|
+
}, [open, enabled, reducedMotion, panel, content]);
|
|
48
|
+
}
|
|
49
|
+
// Vaul 1.1.2 writes motion styles before requesting a controlled close. If the host
|
|
50
|
+
// rejects that request, restore the last resting styles without remounting its card.
|
|
51
|
+
function snapshotStyles(element, properties) {
|
|
52
|
+
const values = properties.map(property => [property, element?.style.getPropertyValue(property) ?? '', element?.style.getPropertyPriority(property) ?? '']);
|
|
53
|
+
return () => { if (element?.isConnected)
|
|
54
|
+
for (const [property, value, priority] of values) {
|
|
55
|
+
if (value)
|
|
56
|
+
element.style.setProperty(property, value, priority);
|
|
57
|
+
else
|
|
58
|
+
element.style.removeProperty(property);
|
|
59
|
+
} };
|
|
60
|
+
}
|
|
61
|
+
const MOTION_PROPERTIES = ['transform', 'transition', 'transition-property', 'transition-duration', 'transition-timing-function'];
|
|
62
|
+
const BACKGROUND_PROPERTIES = [...MOTION_PROPERTIES, 'border-radius', 'overflow', 'transform-origin'];
|
|
63
|
+
const BODY_POSITION = ['position', 'top', 'left', 'right', 'height'];
|
|
64
|
+
/** Optional web gesture backend. Install vaul separately; the core overlay entry never imports it. */
|
|
65
|
+
export function GestureSheet({ open, onOpenChange, title, description, trigger, children, titleHidden, descriptionHidden, contentProps, contentRef, closeButton, closeLabel, backendProps, contentMode = 'default', handle = true, handleProps, handleRef, overlayProps, enableDynamicSizing = false, maxDynamicContentSize }) {
|
|
66
|
+
if (enableDynamicSizing && Object.entries(backendProps ?? {}).some(([key, value]) => value !== undefined && DYNAMIC_BACKEND.has(key)))
|
|
67
|
+
throw new Error('Dynamic GestureSheet does not accept Vaul snap-point props.');
|
|
68
|
+
if (maxDynamicContentSize !== undefined && (!Number.isFinite(maxDynamicContentSize) || maxDynamicContentSize <= 0))
|
|
69
|
+
throw new Error('GestureSheet maxDynamicContentSize must be finite and greater than zero.');
|
|
70
|
+
const { messages, direction, locale, reducedMotion } = useHIG();
|
|
71
|
+
const themeStyle = useThemeStyle();
|
|
72
|
+
const currentOpen = useRef(open);
|
|
73
|
+
currentOpen.current = open;
|
|
74
|
+
const panel = useRef(null), backdrop = useRef(null), motion = useRef(null), frame = useRef(null);
|
|
75
|
+
const [anatomy, setAnatomy] = useState(null);
|
|
76
|
+
const refCleanup = useRef(null), releasePosition = useRef(null);
|
|
77
|
+
// Vaul's internal ref composition predates React callback-ref cleanup returns.
|
|
78
|
+
const setPanel = useCallback((element) => { panel.current = element; if (typeof contentRef === 'function') {
|
|
79
|
+
if (!element && refCleanup.current) {
|
|
80
|
+
const cleanup = refCleanup.current;
|
|
81
|
+
refCleanup.current = null;
|
|
82
|
+
cleanup();
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const cleanup = contentRef(element);
|
|
86
|
+
refCleanup.current = typeof cleanup === 'function' ? cleanup : null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (contentRef)
|
|
90
|
+
contentRef.current = element; }, [contentRef]);
|
|
91
|
+
useEffect(() => () => { if (frame.current !== null)
|
|
92
|
+
cancelAnimationFrame(frame.current); releasePosition.current?.(); }, []);
|
|
93
|
+
useEffect(() => { if (!open) {
|
|
94
|
+
motion.current = null;
|
|
95
|
+
releasePosition.current?.();
|
|
96
|
+
releasePosition.current = null;
|
|
97
|
+
} }, [open]);
|
|
98
|
+
const { onAnimationEnd, ...backend } = safeProps(backendProps, OWNED_ROOT);
|
|
99
|
+
const dynamic = !!enableDynamicSizing && ((backend.direction ?? 'bottom') === 'top' || (backend.direction ?? 'bottom') === 'bottom');
|
|
100
|
+
useDynamicHeight(open, dynamic, reducedMotion, panel, anatomy);
|
|
101
|
+
const { className, onPointerDownCapture, onFocusOutside, onInteractOutside, style, ...content } = safeProps(contentProps, OWNED_CONTENT);
|
|
102
|
+
const { className: overlayClass, ...overlay } = safeProps(overlayProps, OWNED_OVERLAY);
|
|
103
|
+
const { className: handleClass, ...grip } = safeProps(handleProps, OWNED_HANDLE);
|
|
104
|
+
const requestOpen = (next) => {
|
|
105
|
+
if (!next && frame.current === null) {
|
|
106
|
+
const wasFixed = document.body.style.position === 'fixed';
|
|
107
|
+
const restoreBody = snapshotStyles(document.body, [...BODY_POSITION, 'pointer-events']);
|
|
108
|
+
const restoreMotion = motion.current;
|
|
109
|
+
motion.current = null;
|
|
110
|
+
frame.current = requestAnimationFrame(() => {
|
|
111
|
+
frame.current = null;
|
|
112
|
+
if (currentOpen.current) {
|
|
113
|
+
// Safari's backend clears its saved body position even for a rejected close.
|
|
114
|
+
// Retain the released position so the eventual accepted close still unlocks.
|
|
115
|
+
if (wasFixed && document.body.style.position !== 'fixed')
|
|
116
|
+
releasePosition.current ??= snapshotStyles(document.body, BODY_POSITION);
|
|
117
|
+
restoreBody();
|
|
118
|
+
restoreMotion?.();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
onOpenChange(next);
|
|
123
|
+
};
|
|
124
|
+
const body = _jsxs(_Fragment, { children: [handle && _jsx(Drawer.Handle, { ...grip, ref: handleRef, className: ['hig-gesture-handle', handleClass].filter(Boolean).join(' ') }), _jsx(Drawer.Title, { className: titleHidden ? 'hig-sr-only' : undefined, children: title }), description && _jsx(Drawer.Description, { className: descriptionHidden ? 'hig-sr-only' : undefined, children: description }), children, closeButton !== null && _jsx(Drawer.Close, { asChild: true, children: closeButton ?? _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: closeLabel ?? messages.close ?? en.close }) })] });
|
|
125
|
+
return _jsxs(Drawer.Root, { ...backend, open: open, onOpenChange: requestOpen, modal: true, onAnimationEnd: next => { if (next === currentOpen.current)
|
|
126
|
+
onAnimationEnd?.(next); }, children: [trigger && _jsx(Drawer.Trigger, { asChild: true, children: trigger }), _jsxs(Drawer.Portal, { children: [_jsx(Drawer.Overlay, { ...overlay, ref: backdrop, className: ['hig-backdrop', 'hig-gesture-backdrop', overlayClass].filter(Boolean).join(' '), "data-hig-motion": reducedMotion ? 'reduced' : 'full' }), _jsx(Drawer.Content, { ...content, ...(!description ? { 'aria-describedby': undefined } : {}), ref: setPanel, className: ['hig-gesture-sheet', className].filter(Boolean).join(' '), role: 'dialog', dir: direction, lang: locale, style: { ...themeStyle, ...style, ...(dynamic && maxDynamicContentSize !== undefined && { maxHeight: maxDynamicContentSize }) }, onPointerDownCapture: event => { const restorePanel = snapshotStyles(panel.current, MOTION_PROPERTIES), restoreOverlay = snapshotStyles(backdrop.current, ['opacity', 'transition']), restoreBackground = backend.shouldScaleBackground ? snapshotStyles(document.querySelector('[data-vaul-drawer-wrapper]'), BACKGROUND_PROPERTIES) : () => { }; motion.current = () => { restorePanel(); restoreOverlay(); restoreBackground(); }; onPointerDownCapture?.(event); }, onInteractOutside: event => { if (event.detail.originalEvent.type === 'focusin')
|
|
127
|
+
onFocusOutside?.(event); onInteractOutside?.(event); }, "data-hig-content-mode": contentMode, "data-hig-motion": reducedMotion ? 'reduced' : 'full', "data-hig-dynamic": dynamic ? 'true' : undefined, children: dynamic ? _jsx("div", { ref: setAnatomy, className: 'hig-gesture-dynamic', "data-hig-content-mode": contentMode, children: body }) : body })] })] });
|
|
128
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function Tabs({ label, items, value, defaultValue, onValueChange }: {
|
|
3
|
+
label: string;
|
|
4
|
+
items: readonly {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
content: React.ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}[];
|
|
10
|
+
value?: string;
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
onValueChange?: (v: string) => void;
|
|
13
|
+
}): React.JSX.Element;
|
|
14
|
+
export declare function Accordion({ title, children, open, onOpenChange }: React.PropsWithChildren<{
|
|
15
|
+
title: string;
|
|
16
|
+
open?: boolean;
|
|
17
|
+
onOpenChange?: (open: boolean) => void;
|
|
18
|
+
}>): React.JSX.Element;
|
|
19
|
+
export declare function Breadcrumb({ items }: {
|
|
20
|
+
items: readonly {
|
|
21
|
+
label: string;
|
|
22
|
+
href?: string;
|
|
23
|
+
}[];
|
|
24
|
+
}): React.JSX.Element;
|
|
25
|
+
export declare function Navigation({ label, items }: {
|
|
26
|
+
label: string;
|
|
27
|
+
items: readonly {
|
|
28
|
+
label: string;
|
|
29
|
+
href: string;
|
|
30
|
+
active?: boolean;
|
|
31
|
+
}[];
|
|
32
|
+
}): React.JSX.Element;
|
|
33
|
+
export declare function Pagination({ page, total, onPageChange }: {
|
|
34
|
+
page: number;
|
|
35
|
+
total: number;
|
|
36
|
+
onPageChange: (p: number) => void;
|
|
37
|
+
}): React.JSX.Element;
|
|
38
|
+
export declare function Search({ query, onQueryChange, results, loading, error }: {
|
|
39
|
+
query: string;
|
|
40
|
+
onQueryChange: (s: string) => void;
|
|
41
|
+
results: readonly {
|
|
42
|
+
id: string;
|
|
43
|
+
label: string;
|
|
44
|
+
onSelect: () => void;
|
|
45
|
+
}[];
|
|
46
|
+
loading?: boolean;
|
|
47
|
+
error?: string;
|
|
48
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useLayoutEffect, useRef } from 'react';
|
|
4
|
+
import { formatNumber } from '@bloxwap/hig/contracts';
|
|
5
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { useControllable, useHIG } from './provider.js';
|
|
7
|
+
import { Button, Link } from './button.js';
|
|
8
|
+
import { SearchInput, Field } from './field.js';
|
|
9
|
+
const focusable = 'a[href],area[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),iframe,audio[controls],video[controls],summary,[contenteditable]:not([contenteditable="false"]),[tabindex]:not([tabindex="-1"])';
|
|
10
|
+
const contentSelector = 'img,svg,canvas,video,picture,progress,meter,input,select,textarea';
|
|
11
|
+
/** True when the panel's first visible content is itself focusable (for example an InstallCommand `pre`), so the panel needs no tab stop of its own. */
|
|
12
|
+
function startsWithFocusable(panel) {
|
|
13
|
+
const walker = panel.ownerDocument.createTreeWalker(panel, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, { acceptNode: node => { const el = node; return node.nodeType === 1 && (el.hasAttribute('hidden') || el.hasAttribute('inert') || el.getAttribute('aria-hidden') === 'true') ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT; } });
|
|
14
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) {
|
|
15
|
+
if (node.nodeType === 1) {
|
|
16
|
+
const el = node;
|
|
17
|
+
if (el.matches(focusable))
|
|
18
|
+
return true;
|
|
19
|
+
if (el.matches(contentSelector))
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
else if (node.textContent?.trim())
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
/** Runs before paint on the client; on the server, where effects never run, it falls back to useEffect so React does not warn. */
|
|
28
|
+
const useIsomorphicLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;
|
|
29
|
+
/** Applies the APG panel tab stop to the DOM: `tabindex=0` unless the panel's first visible content is already focusable. */
|
|
30
|
+
function syncPanelStop(panel) { const stop = !startsWithFocusable(panel); if (stop && panel.getAttribute('tabindex') !== '0')
|
|
31
|
+
panel.tabIndex = 0;
|
|
32
|
+
else if (!stop && panel.hasAttribute('tabindex'))
|
|
33
|
+
panel.removeAttribute('tabindex'); }
|
|
34
|
+
export function Tabs({ label, items, value, defaultValue, onValueChange }) {
|
|
35
|
+
const { direction } = useHIG();
|
|
36
|
+
const id = useId();
|
|
37
|
+
const [current, set] = useControllable(value, defaultValue ?? items.find(item => !item.disabled)?.value ?? '', onValueChange);
|
|
38
|
+
const enabled = items.filter(item => !item.disabled);
|
|
39
|
+
const tabStop = (enabled.find(item => item.value === current) ?? enabled[0])?.value;
|
|
40
|
+
// APG: a panel is a tab stop only when its first content is not focusable; otherwise that control is the single stop after the tab list.
|
|
41
|
+
// Every panel renders tabIndex=0 (so server and hydration markup are unchanged); a layout effect then corrects the shown panel in the same commit, before paint and before any passive effect, so it is never a tab stop for one commit (#97).
|
|
42
|
+
const panel = useRef(null);
|
|
43
|
+
useIsomorphicLayoutEffect(() => { if (panel.current)
|
|
44
|
+
syncPanelStop(panel.current); });
|
|
45
|
+
useIsomorphicLayoutEffect(() => { const node = panel.current; if (!node)
|
|
46
|
+
return; let observer; if (typeof MutationObserver !== 'undefined') {
|
|
47
|
+
observer = new MutationObserver(() => syncPanelStop(node));
|
|
48
|
+
observer.observe(node, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['tabindex', 'hidden', 'inert', 'aria-hidden', 'disabled', 'href', 'contenteditable', 'controls'] });
|
|
49
|
+
} return () => { observer?.disconnect(); node.tabIndex = 0; }; }, [current]);
|
|
50
|
+
return _jsxs("div", { className: 'hig-tabs', children: [_jsx("div", { role: 'tablist', "aria-label": label, className: 'hig-inline hig-tab-list', onKeyDown: e => { if (!enabled.length)
|
|
51
|
+
return; const index = enabled.findIndex(item => `${id}-tab-${item.value}` === e.target.id); let next = index; if (e.key === (direction === 'rtl' ? 'ArrowLeft' : 'ArrowRight'))
|
|
52
|
+
next = (index + 1) % enabled.length;
|
|
53
|
+
else if (e.key === (direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft'))
|
|
54
|
+
next = index < 0 ? enabled.length - 1 : (index - 1 + enabled.length) % enabled.length;
|
|
55
|
+
else if (e.key === 'Home')
|
|
56
|
+
next = 0;
|
|
57
|
+
else if (e.key === 'End')
|
|
58
|
+
next = enabled.length - 1;
|
|
59
|
+
else
|
|
60
|
+
return; e.preventDefault(); if (enabled[next]) {
|
|
61
|
+
set(enabled[next].value);
|
|
62
|
+
document.getElementById(`${id}-tab-${enabled[next].value}`)?.focus();
|
|
63
|
+
} }, children: items.map(item => _jsx("button", { type: 'button', className: 'hig-button hig-tab', role: 'tab', id: `${id}-tab-${item.value}`, "aria-controls": `${id}-panel-${item.value}`, "aria-selected": current === item.value, tabIndex: tabStop === item.value ? 0 : -1, disabled: item.disabled, onClick: () => set(item.value), children: item.label }, item.value)) }), items.map(item => _jsx("div", { ref: current === item.value ? panel : undefined, hidden: current !== item.value, className: 'hig-tab-panel', role: 'tabpanel', id: `${id}-panel-${item.value}`, "aria-labelledby": `${id}-tab-${item.value}`, tabIndex: 0, children: item.content }, item.value))] });
|
|
64
|
+
}
|
|
65
|
+
export function Accordion({ title, children, open, onOpenChange }) { return _jsxs("details", { open: open, className: 'hig-surface hig-accordion', onToggle: e => onOpenChange?.(e.currentTarget.open), children: [_jsx("summary", { className: 'hig-accordion-summary', children: title }), children] }); }
|
|
66
|
+
export function Breadcrumb({ items }) { const { messages } = useHIG(); return _jsx("nav", { "aria-label": messages.breadcrumb ?? en.breadcrumb, children: _jsx("ol", { role: 'list', className: 'hig-inline hig-breadcrumb', children: items.map((item, i) => _jsxs("li", { children: [i > 0 && _jsx("span", { "aria-hidden": 'true', className: 'hig-breadcrumb-separator', children: "/" }), item.href ? _jsx(Link, { href: item.href, "aria-current": i === items.length - 1 ? 'page' : undefined, children: item.label }) : _jsx("span", { "aria-current": i === items.length - 1 ? 'page' : undefined, children: item.label })] }, i)) }) }); }
|
|
67
|
+
export function Navigation({ label, items }) { return _jsx("nav", { "aria-label": label, className: 'hig-stack hig-navigation', children: items.map(item => _jsx(Link, { href: item.href, "aria-current": item.active ? 'page' : undefined, children: item.label }, item.href)) }); }
|
|
68
|
+
export function Pagination({ page, total, onPageChange }) { const { locale, messages } = useHIG(); return _jsxs("nav", { "aria-label": messages.pagination ?? en.pagination, className: 'hig-inline hig-pagination', children: [_jsx(Button, { intent: 'secondary', disabled: page <= 1, onClick: () => onPageChange(page - 1), children: messages.previous ?? en.previous }), _jsx("span", { children: (messages.pageOf ?? en.pageOf)(formatNumber(page, locale), formatNumber(total, locale)) }), _jsx(Button, { intent: 'secondary', disabled: page >= total, onClick: () => onPageChange(page + 1), children: messages.next ?? en.next })] }); }
|
|
69
|
+
export function Search({ query, onQueryChange, results, loading, error }) { const { messages } = useHIG(); return _jsxs("section", { children: [_jsx(Field, { label: messages.search ?? en.search, children: _jsx(SearchInput, { value: query, onChange: e => onQueryChange(e.target.value) }) }), loading ? _jsx("p", { role: 'status', children: messages.searching ?? en.searching }) : error ? _jsx("p", { role: 'alert', children: error }) : results.length ? _jsx("ul", { children: results.map(r => _jsx("li", { children: _jsx(Button, { intent: 'ghost', onClick: r.onSelect, children: r.label }) }, r.id)) }) : _jsx("p", { role: 'status', children: messages.noResults ?? en.noResults })] }); }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export { Dialog, Sheet, AlertDialog, type DialogProps, type DialogContentProps, type AlertDialogProps } from './dialog.js';
|
|
3
|
+
export declare function Menu({ label, items }: {
|
|
4
|
+
label: string;
|
|
5
|
+
items: readonly {
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
onSelect: (event: Event) => void;
|
|
9
|
+
}[];
|
|
10
|
+
}): React.JSX.Element;
|
|
11
|
+
export declare function Popover({ label, children, closeLabel }: React.PropsWithChildren<{
|
|
12
|
+
label: string; /** Close button text and accessible name; defaults to HIGProvider `messages.close`. */
|
|
13
|
+
closeLabel?: string;
|
|
14
|
+
}>): React.JSX.Element;
|
|
15
|
+
export declare function Tooltip({ content, children }: React.PropsWithChildren<{
|
|
16
|
+
content: string;
|
|
17
|
+
}>): React.JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useId, useRef } from 'react';
|
|
4
|
+
import * as en from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { useHIG, useThemeStyle } from './provider.js';
|
|
6
|
+
import * as Drop from '@radix-ui/react-dropdown-menu';
|
|
7
|
+
import * as Pop from '@radix-ui/react-popover';
|
|
8
|
+
import * as Tip from '@radix-ui/react-tooltip';
|
|
9
|
+
import { Button } from './button.js';
|
|
10
|
+
export { Dialog, Sheet, AlertDialog } from './dialog.js';
|
|
11
|
+
export function Menu({ label, items }) { const { feedback, direction, locale, density } = useHIG(); const themeStyle = useThemeStyle(); const id = useId(); const sequence = useRef(0); const origin = useRef('keyboard'); return _jsxs(Drop.Root, { dir: direction, children: [_jsx(Drop.Trigger, { asChild: true, children: _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: label }) }), _jsx(Drop.Portal, { children: _jsx(Drop.Content, { className: 'hig-popover hig-menu', align: 'start', sideOffset: 6, collisionPadding: 16, style: themeStyle, lang: locale, "data-hig-density": density, children: items.map((item, i) => _jsx(Drop.Item, { disabled: item.disabled, className: 'hig-menu-item', onPointerDown: () => { origin.current = 'pointer'; }, onKeyDown: () => { origin.current = 'keyboard'; }, onSelect: event => { if (item.disabled)
|
|
12
|
+
return; item.onSelect(event); if (!event.defaultPrevented)
|
|
13
|
+
try {
|
|
14
|
+
feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent: 'selection', origin: origin.current });
|
|
15
|
+
}
|
|
16
|
+
catch { /* Optional feedback cannot alter the action. */ } }, children: item.label }, i)) }) })] }); }
|
|
17
|
+
export function Popover({ label, children, closeLabel }) { const { messages, direction, locale, density } = useHIG(); const themeStyle = useThemeStyle(); return _jsxs(Pop.Root, { children: [_jsx(Pop.Trigger, { asChild: true, children: _jsx(Button, { intent: 'secondary', suppressFeedback: true, children: label }) }), _jsx(Pop.Portal, { children: _jsxs(Pop.Content, { className: 'hig-popover', sideOffset: 6, collisionPadding: 16, style: themeStyle, dir: direction, lang: locale, "data-hig-density": density, children: [children, _jsx(Pop.Close, { asChild: true, children: _jsx(Button, { intent: 'ghost', suppressFeedback: true, children: closeLabel ?? messages.close ?? en.close }) })] }) })] }); }
|
|
18
|
+
export function Tooltip({ content, children }) { const { direction, locale, density } = useHIG(); const themeStyle = useThemeStyle(); return _jsx(Tip.Provider, { children: _jsxs(Tip.Root, { children: [_jsx(Tip.Trigger, { asChild: true, children: children }), _jsx(Tip.Portal, { children: _jsx(Tip.Content, { className: 'hig-popover hig-tooltip', sideOffset: 6, collisionPadding: 16, style: themeStyle, dir: direction, lang: locale, "data-hig-density": density, children: content }) })] }) }); }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FeedbackSink, FeedbackIntent } from '@bloxwap/hig/contracts/feedback';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { type Environment } from '@bloxwap/hig/contracts';
|
|
4
|
+
import { type HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
5
|
+
import { nativeSrgb } from '@bloxwap/hig/tokens';
|
|
6
|
+
export type { HIGMessages } from '@bloxwap/hig/contracts/messages';
|
|
7
|
+
export interface HIGContext extends Environment {
|
|
8
|
+
onAccepted?: (id: string) => void;
|
|
9
|
+
feedback?: FeedbackSink; /** Brand accent as opaque sRGB hex (#RGB or #RRGGBB). Nested providers inherit it; omitted at the root, Bloxwap green applies. */
|
|
10
|
+
primaryColor?: string; /** Host translations of built-in copy, merged through nested providers. Components fall back to the English export per key; read the full resolved catalog with `useMessages()`. */
|
|
11
|
+
messages: Readonly<Partial<HIGMessages>>;
|
|
12
|
+
}
|
|
13
|
+
export interface HIGProviderProps extends Partial<Omit<HIGContext, 'messages'>> {
|
|
14
|
+
messages?: Partial<HIGMessages>;
|
|
15
|
+
}
|
|
16
|
+
export declare function HIGProvider({ children, density, locale, direction, reducedMotion, onAccepted, feedback, primaryColor, messages }: React.PropsWithChildren<HIGProviderProps>): React.JSX.Element;
|
|
17
|
+
export declare const useHIG: () => HIGContext;
|
|
18
|
+
/** Scoped primary colour variables for host-owned portals outside the provider's DOM. */
|
|
19
|
+
export declare function useThemeStyle(): React.CSSProperties | undefined;
|
|
20
|
+
/** Resolved sRGB roles for canvas and host-drawn content. CSS retains the default wide-gamut palette. */
|
|
21
|
+
export declare function useColors(): Readonly<Record<keyof typeof nativeSrgb, string>>;
|
|
22
|
+
/** Complete built-in copy for the nearest HIGProvider: host translations over the English defaults. */
|
|
23
|
+
export declare function useMessages(): HIGMessages;
|
|
24
|
+
/** Controlled values never silently switch to internal state. */
|
|
25
|
+
export declare function useControllable<T>(value: T | undefined, initial: T, onChange?: (value: T) => void, intent?: FeedbackIntent): [T, (next: T) => void];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo, useState, useRef, useId } from 'react';
|
|
4
|
+
import { defaultEnvironment } from '@bloxwap/hig/contracts';
|
|
5
|
+
import { defaultMessages, resolveMessages } from '@bloxwap/hig/contracts/messages';
|
|
6
|
+
import { nativeSrgb, resolvePrimaryColor } from '@bloxwap/hig/tokens';
|
|
7
|
+
const Context = createContext({ ...defaultEnvironment, messages: {} });
|
|
8
|
+
export function HIGProvider({ children, density = 'comfortable', locale = 'en-US', direction = 'ltr', reducedMotion, onAccepted, feedback, primaryColor, messages }) {
|
|
9
|
+
const parent = useContext(Context);
|
|
10
|
+
const inherited = parent.messages;
|
|
11
|
+
const resolved = useMemo(() => resolveMessages(inherited, messages), [inherited, messages]);
|
|
12
|
+
const accent = primaryColor ?? parent.primaryColor;
|
|
13
|
+
const theme = useMemo(() => primaryStyle(accent), [accent]);
|
|
14
|
+
const [osReduced, setOSReduced] = useState(false);
|
|
15
|
+
useEffect(() => { const query = window.matchMedia?.('(prefers-reduced-motion: reduce)'); if (!query)
|
|
16
|
+
return; const update = () => setOSReduced(query.matches); update(); query.addEventListener('change', update); return () => query.removeEventListener('change', update); }, []);
|
|
17
|
+
return _jsx(Context.Provider, { value: { density, locale, direction, reducedMotion: reducedMotion ?? osReduced, onAccepted, feedback, primaryColor: accent, messages: resolved }, children: _jsx("div", { style: theme, "data-hig-density": density, "data-hig-motion": reducedMotion ?? osReduced ? 'reduced' : 'full', dir: direction, lang: locale, children: children }) });
|
|
18
|
+
}
|
|
19
|
+
export const useHIG = () => useContext(Context);
|
|
20
|
+
function primaryStyle(primaryColor) {
|
|
21
|
+
if (primaryColor === undefined)
|
|
22
|
+
return undefined;
|
|
23
|
+
const colors = resolvePrimaryColor(primaryColor);
|
|
24
|
+
return { '--hig-action': colors.action, '--hig-focus': colors.focus, '--hig-onAction': colors.onAction };
|
|
25
|
+
}
|
|
26
|
+
/** Scoped primary colour variables for host-owned portals outside the provider's DOM. */
|
|
27
|
+
export function useThemeStyle() { const { primaryColor } = useHIG(); return useMemo(() => primaryStyle(primaryColor), [primaryColor]); }
|
|
28
|
+
/** Resolved sRGB roles for canvas and host-drawn content. CSS retains the default wide-gamut palette. */
|
|
29
|
+
export function useColors() { const { primaryColor } = useHIG(); return useMemo(() => primaryColor === undefined ? nativeSrgb : { ...nativeSrgb, ...resolvePrimaryColor(primaryColor) }, [primaryColor]); }
|
|
30
|
+
/** Complete built-in copy for the nearest HIGProvider: host translations over the English defaults. */
|
|
31
|
+
export function useMessages() { const overrides = useContext(Context).messages; return useMemo(() => resolveMessages({ ...defaultMessages }, overrides), [overrides]); }
|
|
32
|
+
/** Controlled values never silently switch to internal state. */
|
|
33
|
+
export function useControllable(value, initial, onChange, intent = 'selection') {
|
|
34
|
+
const [internal, setInternal] = useState(initial);
|
|
35
|
+
const current = value === undefined ? internal : value;
|
|
36
|
+
const { feedback } = useHIG();
|
|
37
|
+
const id = useId();
|
|
38
|
+
const sequence = useRef(0);
|
|
39
|
+
const pending = useRef(null);
|
|
40
|
+
useEffect(() => { const request = pending.current; if (!request)
|
|
41
|
+
return; pending.current = null; if (Object.is(current, request.value)) {
|
|
42
|
+
try {
|
|
43
|
+
feedback?.emit({ id: `${id}/${++sequence.current}`, source: id, intent, origin: 'programmatic' });
|
|
44
|
+
}
|
|
45
|
+
catch { /* Effects remain optional. */ }
|
|
46
|
+
} });
|
|
47
|
+
return [current, (next) => { if (Object.is(current, next))
|
|
48
|
+
return; pending.current = { value: next }; if (value === undefined)
|
|
49
|
+
setInternal(next); onChange?.(next); }];
|
|
50
|
+
}
|