knowidea-ui 0.0.0-stage → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/Accordion.d.ts +21 -0
- package/dist/Accordion.js +8 -0
- package/dist/Alert.d.ts +17 -0
- package/dist/Alert.js +9 -0
- package/dist/AppBar.d.ts +18 -0
- package/dist/AppBar.js +7 -0
- package/dist/Avatar.d.ts +11 -0
- package/dist/Avatar.js +17 -0
- package/dist/Badge.d.ts +10 -0
- package/dist/Badge.js +5 -0
- package/dist/BottomNavigation.d.ts +13 -0
- package/dist/BottomNavigation.js +7 -0
- package/dist/Breadcrumbs.d.ts +14 -0
- package/dist/Breadcrumbs.js +9 -0
- package/dist/Button.d.ts +14 -0
- package/dist/Button.js +13 -0
- package/dist/Calendar.d.ts +28 -0
- package/dist/Calendar.js +131 -0
- package/dist/Card.d.ts +34 -0
- package/dist/Card.js +13 -0
- package/dist/Chart.d.ts +41 -0
- package/dist/Chart.js +93 -0
- package/dist/Chip.d.ts +19 -0
- package/dist/Chip.js +19 -0
- package/dist/Choice.d.ts +49 -0
- package/dist/Choice.js +20 -0
- package/dist/CodeBlock.d.ts +12 -0
- package/dist/CodeBlock.js +25 -0
- package/dist/Combobox.d.ts +30 -0
- package/dist/Combobox.js +21 -0
- package/dist/DatePicker.d.ts +19 -0
- package/dist/DatePicker.js +29 -0
- package/dist/Dialog.d.ts +35 -0
- package/dist/Dialog.js +19 -0
- package/dist/Divider.d.ts +8 -0
- package/dist/Divider.js +8 -0
- package/dist/Drawer.d.ts +33 -0
- package/dist/Drawer.js +19 -0
- package/dist/EmptyState.d.ts +12 -0
- package/dist/EmptyState.js +5 -0
- package/dist/Field.d.ts +14 -0
- package/dist/Field.js +7 -0
- package/dist/FileUpload.d.ts +23 -0
- package/dist/FileUpload.js +116 -0
- package/dist/Icon.d.ts +9 -0
- package/dist/Icon.js +7 -0
- package/dist/IconButton.d.ts +8 -0
- package/dist/IconButton.js +13 -0
- package/dist/Input.d.ts +14 -0
- package/dist/Input.js +14 -0
- package/dist/Kbd.d.ts +7 -0
- package/dist/Kbd.js +13 -0
- package/dist/Layout.d.ts +39 -0
- package/dist/Layout.js +24 -0
- package/dist/Link.d.ts +11 -0
- package/dist/Link.js +5 -0
- package/dist/List.d.ts +45 -0
- package/dist/List.js +28 -0
- package/dist/Menu.d.ts +22 -0
- package/dist/Menu.js +16 -0
- package/dist/NavItems.d.ts +10 -0
- package/dist/NavItems.js +1 -0
- package/dist/Pagination.d.ts +16 -0
- package/dist/Pagination.js +32 -0
- package/dist/Popover.d.ts +22 -0
- package/dist/Popover.js +10 -0
- package/dist/Progress.d.ts +16 -0
- package/dist/Progress.js +9 -0
- package/dist/Quote.d.ts +8 -0
- package/dist/Quote.js +5 -0
- package/dist/SegmentedControl.d.ts +24 -0
- package/dist/SegmentedControl.js +8 -0
- package/dist/Select.d.ts +20 -0
- package/dist/Select.js +10 -0
- package/dist/SelectionBar.d.ts +27 -0
- package/dist/SelectionBar.js +12 -0
- package/dist/Sheet.d.ts +22 -0
- package/dist/Sheet.js +16 -0
- package/dist/Skeleton.d.ts +13 -0
- package/dist/Skeleton.js +9 -0
- package/dist/Slider.d.ts +27 -0
- package/dist/Slider.js +10 -0
- package/dist/Spinner.d.ts +6 -0
- package/dist/Spinner.js +5 -0
- package/dist/Stat.d.ts +44 -0
- package/dist/Stat.js +21 -0
- package/dist/Status.d.ts +26 -0
- package/dist/Status.js +21 -0
- package/dist/Stepper.d.ts +23 -0
- package/dist/Stepper.js +8 -0
- package/dist/Table.d.ts +45 -0
- package/dist/Table.js +177 -0
- package/dist/Tabs.d.ts +17 -0
- package/dist/Tabs.js +6 -0
- package/dist/TextField.d.ts +20 -0
- package/dist/TextField.js +7 -0
- package/dist/ThemeProvider.d.ts +18 -0
- package/dist/ThemeProvider.js +26 -0
- package/dist/ThemeScope.d.ts +11 -0
- package/dist/ThemeScope.js +13 -0
- package/dist/Timeline.d.ts +28 -0
- package/dist/Timeline.js +16 -0
- package/dist/Toast.d.ts +21 -0
- package/dist/Toast.js +29 -0
- package/dist/Tooltip.d.ts +9 -0
- package/dist/Tooltip.js +7 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +52 -0
- package/dist/motion.d.ts +6 -0
- package/dist/motion.js +39 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +11 -0
- package/package.json +53 -3
package/dist/Select.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface SelectOption {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface SelectProps {
|
|
7
|
+
options: SelectOption[];
|
|
8
|
+
value?: string | null;
|
|
9
|
+
defaultValue?: string | null;
|
|
10
|
+
onValueChange?: (value: string | null) => void;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
invalid?: boolean;
|
|
14
|
+
/** 読み込み中。開けなくなり、回転と文を出す */
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
name?: string;
|
|
17
|
+
className?: string;
|
|
18
|
+
"aria-label"?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function Select({ options, value, defaultValue, onValueChange, placeholder, disabled, invalid, loading, name, className, ...rest }: SelectProps): import("react").JSX.Element;
|
package/dist/Select.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Select as BaseSelect } from "@base-ui/react/select";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { Spinner } from "./Spinner.js";
|
|
5
|
+
import { cx } from "./utils.js";
|
|
6
|
+
import { useThemeScope } from "./ThemeScope.js";
|
|
7
|
+
export function Select({ options, value, defaultValue, onValueChange, placeholder = "選択", disabled, invalid, loading, name, className, ...rest }) {
|
|
8
|
+
const scope = useThemeScope();
|
|
9
|
+
return (_jsxs(BaseSelect.Root, { items: options, value: value, defaultValue: defaultValue, onValueChange: (v) => onValueChange?.(v), disabled: disabled || loading, name: name, children: [_jsxs(BaseSelect.Trigger, { className: cx("ki-select", className), "aria-invalid": invalid || undefined, "aria-busy": loading || undefined, ...rest, children: [loading ? (_jsxs("span", { style: { display: "inline-flex", alignItems: "center", gap: "var(--space-2)" }, children: [_jsx(Spinner, {}), "\u8AAD\u307F\u8FBC\u307F\u4E2D"] })) : (_jsx(BaseSelect.Value, { placeholder: placeholder })), _jsx(BaseSelect.Icon, { className: "ki-select__icon", children: _jsx(Icon, { name: "chevron-down" }) })] }), _jsx(BaseSelect.Portal, { children: _jsx(BaseSelect.Positioner, { className: "ki-select__positioner", sideOffset: 4, alignItemWithTrigger: false, ...scope, children: _jsx(BaseSelect.Popup, { className: "ki-select__popup", children: _jsx(BaseSelect.List, { children: options.map((o) => (_jsxs(BaseSelect.Item, { value: o.value, disabled: o.disabled, className: "ki-select__item", children: [_jsx("span", { className: "ki-select__item-mark", children: _jsx(Icon, { name: "check" }) }), _jsx(BaseSelect.ItemText, { children: o.label })] }, o.value))) }) }) }) })] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface SelectionBarProps {
|
|
3
|
+
/** 選んだ数 */
|
|
4
|
+
count: number;
|
|
5
|
+
/** 件数の文。{count} が数になる。既定「{count} 件を選択中」 */
|
|
6
|
+
countLabel?: string;
|
|
7
|
+
/** 件数の下の 1 行(進み方、注意)。state が error なら失敗の理由 */
|
|
8
|
+
note?: ReactNode;
|
|
9
|
+
/** 一括の操作。Button を並べる */
|
|
10
|
+
actions?: ReactNode;
|
|
11
|
+
/** 選択を解除。渡すと「選択を解除」ボタンが出る */
|
|
12
|
+
onClear?: () => void;
|
|
13
|
+
clearLabel?: string;
|
|
14
|
+
/** 画面の下に貼り付く */
|
|
15
|
+
sticky?: boolean;
|
|
16
|
+
/** 0 件のとき消すか、案内を出すか。既定は案内を出す(hide で何も描かない) */
|
|
17
|
+
whenEmpty?: "hint" | "hide";
|
|
18
|
+
emptyHint?: string;
|
|
19
|
+
/** state が loading のときの文言。既定は「処理中」 */
|
|
20
|
+
loadingText?: string;
|
|
21
|
+
state?: "ready" | "loading" | "error";
|
|
22
|
+
/** 読み上げの名前 */
|
|
23
|
+
label?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
/** 選んだ物への一括の操作の帯。件数、操作、選択の解除。 */
|
|
27
|
+
export declare function SelectionBar({ count, countLabel, note, actions, onClear, clearLabel, sticky, whenEmpty, emptyHint, loadingText, state, label, className, }: SelectionBarProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "./Button.js";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { Spinner } from "./Spinner.js";
|
|
5
|
+
import { cx } from "./utils.js";
|
|
6
|
+
/** 選んだ物への一括の操作の帯。件数、操作、選択の解除。 */
|
|
7
|
+
export function SelectionBar({ count, countLabel = "{count} 件を選択中", note, actions, onClear, clearLabel = "選択を解除", sticky, whenEmpty = "hint", emptyHint = "項目を選択すると、ここに操作が表示される。", loadingText = "処理中", state = "ready", label = "選択した項目への操作", className, }) {
|
|
8
|
+
if (count === 0 && whenEmpty === "hide" && state === "ready")
|
|
9
|
+
return null;
|
|
10
|
+
const [before, after] = countLabel.split("{count}");
|
|
11
|
+
return (_jsx("section", { className: cx("ki-selbar", className), "aria-label": label, "data-sticky": sticky ? "" : undefined, "data-state": state === "ready" ? undefined : state, children: _jsxs("div", { className: "ki-selbar__head", children: [_jsxs("div", { className: "ki-selbar__summary", children: [_jsxs("p", { className: "ki-selbar__count", children: [before, _jsx("b", { children: count }), after] }), _jsx("p", { className: "ki-selbar__note", role: "status", children: state === "loading" ? _jsxs(_Fragment, { children: [_jsx(Spinner, {}), loadingText] }) : state === "error" ? _jsxs(_Fragment, { children: [_jsx(Icon, { name: "error" }), note ?? "処理できなかった。選択はそのまま残っている。"] }) : count === 0 ? emptyHint : note })] }), _jsxs("div", { className: "ki-selbar__actions", children: [onClear ? _jsx(Button, { variant: "quiet", disabled: count === 0 || state === "loading", onClick: onClear, children: clearLabel }) : null, actions] })] }) }));
|
|
12
|
+
}
|
package/dist/Sheet.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { type ButtonProps } from "./Button.js";
|
|
3
|
+
export interface SheetProps {
|
|
4
|
+
/** 開くボタン。1 つの要素 */
|
|
5
|
+
trigger?: ReactElement;
|
|
6
|
+
title: ReactNode;
|
|
7
|
+
description?: ReactNode;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
/** 下の操作。SheetClose を使うと閉じる */
|
|
10
|
+
actions?: ReactNode;
|
|
11
|
+
open?: boolean;
|
|
12
|
+
defaultOpen?: boolean;
|
|
13
|
+
onOpenChange?: (open: boolean) => void;
|
|
14
|
+
/** 中身を読み込み中。本文の形をまねた Skeleton を出す */
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
/** 右上の閉じるボタンの名前 */
|
|
17
|
+
closeLabel?: string;
|
|
18
|
+
}
|
|
19
|
+
/** 閉じるボタン。Sheet の actions の中で使う */
|
|
20
|
+
export declare function SheetClose(props: ButtonProps): import("react").JSX.Element;
|
|
21
|
+
/** 下から出る面。指で下へ引くか、Esc か、外を押すと閉じる。 */
|
|
22
|
+
export declare function Sheet({ trigger, title, description, children, actions, open, defaultOpen, onOpenChange, loading, closeLabel }: SheetProps): import("react").JSX.Element;
|
package/dist/Sheet.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useThemeScope } from "./ThemeScope.js";
|
|
3
|
+
import { Drawer as BaseDrawer } from "@base-ui/react/drawer";
|
|
4
|
+
import { Button } from "./Button.js";
|
|
5
|
+
import { Icon } from "./Icon.js";
|
|
6
|
+
import { IconButton } from "./IconButton.js";
|
|
7
|
+
import { SkeletonText } from "./Skeleton.js";
|
|
8
|
+
/** 閉じるボタン。Sheet の actions の中で使う */
|
|
9
|
+
export function SheetClose(props) {
|
|
10
|
+
return _jsx(BaseDrawer.Close, { render: _jsx(Button, { variant: "secondary", ...props }) });
|
|
11
|
+
}
|
|
12
|
+
/** 下から出る面。指で下へ引くか、Esc か、外を押すと閉じる。 */
|
|
13
|
+
export function Sheet({ trigger, title, description, children, actions, open, defaultOpen, onOpenChange, loading, closeLabel = "閉じる" }) {
|
|
14
|
+
const scope = useThemeScope();
|
|
15
|
+
return (_jsxs(BaseDrawer.Root, { swipeDirection: "down", open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange ? (o) => onOpenChange(o) : undefined, children: [trigger ? _jsx(BaseDrawer.Trigger, { render: trigger }) : null, _jsxs(BaseDrawer.Portal, { children: [_jsx(BaseDrawer.Backdrop, { className: "ki-sheet__backdrop", ...scope }), _jsx(BaseDrawer.Viewport, { className: "ki-sheet__viewport", ...scope, children: _jsxs(BaseDrawer.Popup, { className: "ki-sheet", children: [_jsx("span", { className: "ki-sheet__handle", "aria-hidden": "true" }), _jsxs("div", { className: "ki-sheet__head", children: [_jsx(BaseDrawer.Title, { className: "ki-sheet__title", children: title }), _jsx(BaseDrawer.Close, { render: _jsx(IconButton, { variant: "quiet", label: closeLabel, icon: _jsx(Icon, { name: "close" }) }) })] }), description ? _jsx(BaseDrawer.Description, { className: "ki-sheet__description", children: description }) : null, loading ? (_jsx("div", { className: "ki-sheet__loading", children: _jsx(SkeletonText, {}) })) : children ? _jsx(BaseDrawer.Content, { className: "ki-sheet__body", children: children }) : null, actions ? _jsx("div", { className: "ki-sheet__actions", children: actions }) : null] }) })] })] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface SkeletonProps {
|
|
2
|
+
size?: "short" | "medium" | "long";
|
|
3
|
+
shape?: "text" | "block";
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
/** 読み込みの仮の形。動かさない */
|
|
7
|
+
export declare function Skeleton({ size, shape, className }: SkeletonProps): import("react").JSX.Element;
|
|
8
|
+
export interface SkeletonTextProps {
|
|
9
|
+
lines?: number;
|
|
10
|
+
/** 読み上げる文 */
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function SkeletonText({ lines, label }: SkeletonTextProps): import("react").JSX.Element;
|
package/dist/Skeleton.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./utils.js";
|
|
3
|
+
/** 読み込みの仮の形。動かさない */
|
|
4
|
+
export function Skeleton({ size = "long", shape = "text", className }) {
|
|
5
|
+
return _jsx("span", { className: cx("ki-skeleton", className), "data-size": size, "data-shape": shape === "block" ? "block" : undefined, "aria-hidden": "true" });
|
|
6
|
+
}
|
|
7
|
+
export function SkeletonText({ lines = 3, label = "読み込み中" }) {
|
|
8
|
+
return (_jsxs("div", { className: "ki-skeleton-stack", "aria-busy": "true", children: [_jsx("span", { className: "ki-sr-only", role: "status", children: label }), Array.from({ length: lines }).map((_, i) => (_jsx(Skeleton, { size: i === lines - 1 ? "medium" : "long" }, i)))] }));
|
|
9
|
+
}
|
package/dist/Slider.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface SliderProps {
|
|
2
|
+
/** 何の量か。上に出し、読み上げの名前にもなる */
|
|
3
|
+
label: string;
|
|
4
|
+
/** 1 つの値。範囲を選ぶ時は [下限, 上限] */
|
|
5
|
+
value?: number | number[];
|
|
6
|
+
defaultValue?: number | number[];
|
|
7
|
+
/** 動かしている間ずっと呼ぶ */
|
|
8
|
+
onValueChange?: (value: number | number[]) => void;
|
|
9
|
+
/** 指を離した時、キーで変えた時に 1 度呼ぶ。保存はこちらで */
|
|
10
|
+
onValueCommitted?: (value: number | number[]) => void;
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
step?: number;
|
|
14
|
+
/** PageUp と PageDown、Shift と矢印で動く幅。既定は 10 */
|
|
15
|
+
largeStep?: number;
|
|
16
|
+
/** 値の見せ方。読み上げにも使う(例: (v) => `${v}%`) */
|
|
17
|
+
formatValue?: (value: number) => string;
|
|
18
|
+
/** 範囲の時の、つまみの名前。全体の名前は label が持つので、ここには付けない */
|
|
19
|
+
thumbLabels?: [string, string];
|
|
20
|
+
/** 上の値を出さない(すぐ近くに値を出している時) */
|
|
21
|
+
hideValue?: boolean;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
name?: string;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
/** 量を指で選ぶ。つまみは 44px 四方で押せる。矢印キーで step、PageUp と PageDown で largeStep ずつ動く。 */
|
|
27
|
+
export declare function Slider({ label, value, defaultValue, onValueChange, onValueCommitted, min, max, step, largeStep, formatValue, thumbLabels, hideValue, disabled, name, className, }: SliderProps): import("react").JSX.Element;
|
package/dist/Slider.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Slider as BaseSlider } from "@base-ui/react/slider";
|
|
3
|
+
import { cx } from "./utils.js";
|
|
4
|
+
/** 量を指で選ぶ。つまみは 44px 四方で押せる。矢印キーで step、PageUp と PageDown で largeStep ずつ動く。 */
|
|
5
|
+
export function Slider({ label, value, defaultValue, onValueChange, onValueCommitted, min = 0, max = 100, step = 1, largeStep, formatValue, thumbLabels = ["下限", "上限"], hideValue, disabled, name, className, }) {
|
|
6
|
+
const current = value ?? defaultValue ?? min;
|
|
7
|
+
const count = Array.isArray(current) ? current.length : 1;
|
|
8
|
+
const show = (v) => (formatValue ? formatValue(v) : String(v));
|
|
9
|
+
return (_jsxs(BaseSlider.Root, { className: cx("ki-slider", className), value: value, defaultValue: value === undefined ? (defaultValue ?? min) : undefined, onValueChange: onValueChange ? (v) => onValueChange(v) : undefined, onValueCommitted: onValueCommitted ? (v) => onValueCommitted(v) : undefined, min: min, max: max, step: step, largeStep: largeStep, disabled: disabled, name: name, thumbAlignment: "edge", children: [_jsxs("div", { className: "ki-slider__head", children: [_jsx(BaseSlider.Label, { className: "ki-slider__label", children: label }), hideValue ? null : (_jsx(BaseSlider.Value, { className: "ki-slider__value", children: (_, values) => values.map(show).join(" 〜 ") }))] }), _jsx(BaseSlider.Control, { className: "ki-slider__control", children: _jsxs(BaseSlider.Track, { className: "ki-slider__track", children: [_jsx(BaseSlider.Indicator, { className: "ki-slider__indicator" }), Array.from({ length: count }, (_, i) => (_jsx(BaseSlider.Thumb, { index: i, className: "ki-slider__thumb", getAriaLabel: count > 1 ? (n) => thumbLabels[n] ?? String(n + 1) : undefined, getAriaValueText: (_, v) => show(v) }, i)))] }) })] }));
|
|
10
|
+
}
|
package/dist/Spinner.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./utils.js";
|
|
3
|
+
export function Spinner({ label, className }) {
|
|
4
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { className: cx("ki-spinner", className), "aria-hidden": "true" }), label ? _jsx("span", { className: "ki-sr-only", role: "status", children: label }) : null] }));
|
|
5
|
+
}
|
package/dist/Stat.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type IconName } from "./Icon.js";
|
|
2
|
+
export interface SparklineProps {
|
|
3
|
+
data: number[];
|
|
4
|
+
width?: number;
|
|
5
|
+
height?: number;
|
|
6
|
+
/** 読み上げる文(例: 直近 7 日の推移) */
|
|
7
|
+
label: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/** 小さな推移の線。線と最後の点だけ。値は Stat の数が伝える。 */
|
|
11
|
+
export declare function Sparkline({ data, width, height, label, className }: SparklineProps): import("react").JSX.Element | null;
|
|
12
|
+
export interface StatDelta {
|
|
13
|
+
/** up、down は矢印と符号。flat は同じ。none は前の数が無い */
|
|
14
|
+
dir: "up" | "down" | "flat" | "none";
|
|
15
|
+
/** 差の文(例: +12%、-3 件) */
|
|
16
|
+
text?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface StatProps {
|
|
19
|
+
label: string;
|
|
20
|
+
icon?: IconName;
|
|
21
|
+
value: number | string | null;
|
|
22
|
+
unit?: string;
|
|
23
|
+
delta?: StatDelta;
|
|
24
|
+
/** 差の前に付ける語。既定は「前回比」 */
|
|
25
|
+
deltaLabel?: string;
|
|
26
|
+
/** 数の下の補足(例: 全体 12) */
|
|
27
|
+
sub?: string;
|
|
28
|
+
spark?: number[];
|
|
29
|
+
sparkLabel?: string;
|
|
30
|
+
/** いつ時点の値か(例: 10/13 09:28)。時刻は等幅で出る */
|
|
31
|
+
asOf?: string;
|
|
32
|
+
/** asOf の前後の文。{time} が asOf に変わる。既定は「{time} 時点」 */
|
|
33
|
+
asOfFormat?: string;
|
|
34
|
+
/** 数が取れなかった・無いときに出す語 */
|
|
35
|
+
fallback?: string;
|
|
36
|
+
/** 数が古い。印を付ける */
|
|
37
|
+
stale?: boolean;
|
|
38
|
+
staleLabel?: string;
|
|
39
|
+
state?: "ready" | "loading" | "error";
|
|
40
|
+
/** state が error のときの理由 */
|
|
41
|
+
error?: string;
|
|
42
|
+
className?: string;
|
|
43
|
+
}
|
|
44
|
+
export declare function Stat({ label, icon, value, unit, delta, deltaLabel, sub, spark, sparkLabel, asOf, asOfFormat, fallback, stale, staleLabel, state, error, className, }: StatProps): import("react").JSX.Element;
|
package/dist/Stat.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from "./Icon.js";
|
|
3
|
+
import { Skeleton } from "./Skeleton.js";
|
|
4
|
+
import { cx, formatNumber } from "./utils.js";
|
|
5
|
+
/** 小さな推移の線。線と最後の点だけ。値は Stat の数が伝える。 */
|
|
6
|
+
export function Sparkline({ data, width = 96, height = 28, label, className }) {
|
|
7
|
+
if (data.length < 2)
|
|
8
|
+
return null;
|
|
9
|
+
const pad = 3;
|
|
10
|
+
const min = Math.min(...data), max = Math.max(...data);
|
|
11
|
+
const span = max - min || 1;
|
|
12
|
+
const pts = data.map((v, i) => [pad + (i * (width - pad * 2)) / (data.length - 1), height - pad - ((v - min) / span) * (height - pad * 2)]);
|
|
13
|
+
const last = pts[pts.length - 1];
|
|
14
|
+
return (_jsxs("svg", { className: cx("ki-spark", className), width: width, height: height, viewBox: `0 0 ${width} ${height}`, role: "img", "aria-label": label, children: [_jsx("polyline", { className: "ki-spark__line", points: pts.map((p) => p.join(",")).join(" ") }), _jsx("circle", { className: "ki-spark__dot", cx: last[0], cy: last[1], r: 2.5 })] }));
|
|
15
|
+
}
|
|
16
|
+
export function Stat({ label, icon, value, unit, delta, deltaLabel = "前回比", sub, spark, sparkLabel, asOf, asOfFormat = "{time} 時点", fallback = "不明", stale, staleLabel = "古い値", state = "ready", error, className, }) {
|
|
17
|
+
const loading = state === "loading";
|
|
18
|
+
const failed = state === "error";
|
|
19
|
+
const shown = failed || value == null ? fallback : typeof value === "number" ? formatNumber(value) : value;
|
|
20
|
+
return (_jsxs("div", { className: cx("ki-stat", className), role: "group", "aria-label": label, "data-state": state === "ready" ? undefined : state, "aria-busy": loading || undefined, children: [_jsxs("p", { className: "ki-stat__head", children: [icon ? _jsx(Icon, { name: icon }) : null, label] }), loading ? (_jsxs("div", { style: { display: "grid", gap: "var(--space-2)" }, children: [_jsx(Skeleton, { size: "medium" }), _jsx(Skeleton, { size: "short" })] })) : (_jsxs(_Fragment, { children: [_jsxs("p", { className: "ki-stat__value", children: [_jsx("span", { className: "ki-stat__num", children: shown }), !failed && value != null && unit ? _jsx("span", { className: "ki-stat__unit", children: unit }) : null] }), failed ? _jsxs("p", { className: "ki-stat__error", children: [_jsx(Icon, { name: "warning" }), error ?? "取れなかった"] }) : null, !failed && sub ? _jsx("p", { className: "ki-stat__sub", children: sub }) : null, !failed ? (_jsxs("div", { className: "ki-stat__foot", children: [delta ? (_jsxs("p", { className: "ki-stat__delta", "data-dir": delta.dir, children: [delta.dir === "up" ? _jsx(Icon, { name: "arrow-up" }) : delta.dir === "down" ? _jsx(Icon, { name: "arrow-down" }) : null, _jsxs("span", { children: [deltaLabel, " ", delta.dir === "none" ? "なし" : delta.dir === "flat" ? "変わらず" : delta.text] })] })) : _jsx("span", {}), spark ? _jsx("span", { className: "ki-stat__spark", children: _jsx(Sparkline, { data: spark, label: sparkLabel ?? `${label}の推移` }) }) : null] })) : null] })), asOf || stale ? (_jsxs("p", { className: "ki-stat__asof", children: [asOf ? _jsx("span", { children: asOfFormat.split("{time}").map((part, i, a) => _jsxs("span", { children: [part, i < a.length - 1 ? _jsx("time", { children: asOf }) : null] }, i)) }) : null, stale ? _jsxs("span", { className: "ki-status", "data-tone": "warn", children: [_jsx(Icon, { name: "stale" }), staleLabel] }) : null] })) : null] }));
|
|
21
|
+
}
|
package/dist/Status.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type IconName } from "./Icon.js";
|
|
2
|
+
export type StatusTone = "neutral" | "info" | "success" | "warn" | "error";
|
|
3
|
+
/** 既定の種類。色だけでなく、形(アイコン)と字で伝える */
|
|
4
|
+
export type StatusKind = "neutral" | "info" | "success" | "warn" | "error" | "working" | "paused" | "pending" | "stopped";
|
|
5
|
+
interface Def {
|
|
6
|
+
icon: IconName;
|
|
7
|
+
tone: StatusTone;
|
|
8
|
+
}
|
|
9
|
+
/** 種類ごとの既定のアイコンと色。tone と icon を props で渡せば上書きできる */
|
|
10
|
+
export declare const statusKinds: Record<StatusKind, Def>;
|
|
11
|
+
export interface StatusProps {
|
|
12
|
+
/** 状態の種類。既定は neutral */
|
|
13
|
+
kind?: StatusKind;
|
|
14
|
+
/** 字。必須。色だけに頼らない */
|
|
15
|
+
label: string;
|
|
16
|
+
/** 種類の既定の色を変える */
|
|
17
|
+
tone?: StatusTone;
|
|
18
|
+
/** 種類の既定のアイコンを変える */
|
|
19
|
+
icon?: IconName;
|
|
20
|
+
/** lg は一目で分かる大きさ */
|
|
21
|
+
size?: "md" | "lg";
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
/** 状態の印。状態の種類は kind で渡し、字は label に書く。 */
|
|
25
|
+
export declare function Status({ kind, label, tone, icon, size, className }: StatusProps): import("react").JSX.Element;
|
|
26
|
+
export {};
|
package/dist/Status.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from "./Icon.js";
|
|
3
|
+
import { cx } from "./utils.js";
|
|
4
|
+
/** 種類ごとの既定のアイコンと色。tone と icon を props で渡せば上書きできる */
|
|
5
|
+
export const statusKinds = {
|
|
6
|
+
neutral: { icon: "info", tone: "neutral" },
|
|
7
|
+
info: { icon: "info", tone: "info" },
|
|
8
|
+
success: { icon: "success", tone: "success" },
|
|
9
|
+
warn: { icon: "warning", tone: "warn" },
|
|
10
|
+
error: { icon: "error", tone: "error" },
|
|
11
|
+
working: { icon: "working", tone: "info" },
|
|
12
|
+
paused: { icon: "paused", tone: "warn" },
|
|
13
|
+
pending: { icon: "clock", tone: "neutral" },
|
|
14
|
+
stopped: { icon: "stopped", tone: "neutral" },
|
|
15
|
+
};
|
|
16
|
+
/** 状態の印。状態の種類は kind で渡し、字は label に書く。 */
|
|
17
|
+
export function Status({ kind = "neutral", label, tone, icon, size = "md", className }) {
|
|
18
|
+
const def = statusKinds[kind];
|
|
19
|
+
const t = tone ?? def.tone;
|
|
20
|
+
return (_jsxs("span", { className: cx("ki-status", className), "data-tone": t === "neutral" ? undefined : t, "data-size": size === "lg" ? "lg" : undefined, children: [_jsx(Icon, { name: icon ?? def.icon }), label] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface StepperProps {
|
|
2
|
+
value?: number | null;
|
|
3
|
+
defaultValue?: number;
|
|
4
|
+
onValueChange?: (value: number | null) => void;
|
|
5
|
+
min?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
step?: number;
|
|
8
|
+
/** PageUp と PageDown、Shift と矢印で動く幅 */
|
|
9
|
+
largeStep?: number;
|
|
10
|
+
/** 数の見せ方(例: { style: "unit", unit: "minute" } で「5 分」) */
|
|
11
|
+
format?: Intl.NumberFormatOptions;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
invalid?: boolean;
|
|
14
|
+
name?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
/** 欄の名前(読み上げ)。Field の中では要らない */
|
|
17
|
+
"aria-label"?: string;
|
|
18
|
+
decrementLabel?: string;
|
|
19
|
+
incrementLabel?: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
/** 段のある数を、− と + で 1 つずつ変える。欄に打っても入れられる。上下の矢印キーでも変わる。 */
|
|
23
|
+
export declare function Stepper({ value, defaultValue, onValueChange, min, max, step, largeStep, format, disabled, invalid, name, id, className, decrementLabel, incrementLabel, ...rest }: StepperProps): import("react").JSX.Element;
|
package/dist/Stepper.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { NumberField as BaseNumberField } from "@base-ui/react/number-field";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { cx } from "./utils.js";
|
|
5
|
+
/** 段のある数を、− と + で 1 つずつ変える。欄に打っても入れられる。上下の矢印キーでも変わる。 */
|
|
6
|
+
export function Stepper({ value, defaultValue, onValueChange, min, max, step = 1, largeStep, format, disabled, invalid, name, id, className, decrementLabel = "減らす", incrementLabel = "増やす", ...rest }) {
|
|
7
|
+
return (_jsx(BaseNumberField.Root, { className: cx("ki-stepper", className), value: value, defaultValue: defaultValue, onValueChange: onValueChange ? (v) => onValueChange(v) : undefined, min: min, max: max, step: step, largeStep: largeStep ?? step * 10, format: format, disabled: disabled, name: name, id: id, locale: "ja-JP", children: _jsxs(BaseNumberField.Group, { className: "ki-stepper__group", ...(invalid ? { "data-invalid": "" } : null), children: [_jsx(BaseNumberField.Decrement, { className: "ki-stepper__button", "aria-label": decrementLabel, children: _jsx(Icon, { name: "remove" }) }), _jsx(BaseNumberField.Input, { className: "ki-stepper__input", "aria-label": rest["aria-label"], "aria-roledescription": "\u6570\u306E\u5165\u529B", ...(invalid ? { "aria-invalid": true } : null) }), _jsx(BaseNumberField.Increment, { className: "ki-stepper__button", "aria-label": incrementLabel, children: _jsx(Icon, { name: "add" }) })] }) }));
|
|
8
|
+
}
|
package/dist/Table.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type SortDirection = "ascending" | "descending";
|
|
3
|
+
export interface SortState {
|
|
4
|
+
key: string;
|
|
5
|
+
direction: SortDirection;
|
|
6
|
+
}
|
|
7
|
+
export interface Column<T> {
|
|
8
|
+
key: string;
|
|
9
|
+
header: ReactNode;
|
|
10
|
+
/** 数字の列。右寄せ、等幅 */
|
|
11
|
+
numeric?: boolean;
|
|
12
|
+
sortable?: boolean;
|
|
13
|
+
/** 長い文を折り返す列 */
|
|
14
|
+
wrap?: boolean;
|
|
15
|
+
/** 行ごとの表示。無ければ row[key] */
|
|
16
|
+
render?: (row: T) => ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export interface TableProps<T> {
|
|
19
|
+
/** 表の名前。読み上げる。必須 */
|
|
20
|
+
label: string;
|
|
21
|
+
columns: Column<T>[];
|
|
22
|
+
rows: T[];
|
|
23
|
+
rowKey: (row: T) => string;
|
|
24
|
+
/** 見える表題 */
|
|
25
|
+
caption?: ReactNode;
|
|
26
|
+
sort?: SortState | null;
|
|
27
|
+
onSortChange?: (sort: SortState | null) => void;
|
|
28
|
+
selectable?: boolean;
|
|
29
|
+
selected?: string[];
|
|
30
|
+
onSelectedChange?: (keys: string[]) => void;
|
|
31
|
+
/** 行を選択するチェックボックスの名前 */
|
|
32
|
+
rowLabel?: (row: T) => string;
|
|
33
|
+
loading?: boolean;
|
|
34
|
+
/** 失敗の文。あると表の代わりに帯を出す */
|
|
35
|
+
error?: ReactNode;
|
|
36
|
+
onRetry?: () => void;
|
|
37
|
+
emptyTitle?: string;
|
|
38
|
+
emptyText?: string;
|
|
39
|
+
emptyAction?: ReactNode;
|
|
40
|
+
/** 行の先頭に掴む所を出し、ドラッグかキーボードで行を並べ替えられるようにする。onReorder が必要 */
|
|
41
|
+
reorderable?: boolean;
|
|
42
|
+
/** 並べ替えを確定したとき。fromIndex と toIndex は、渡した rows の中の位置(0 から) */
|
|
43
|
+
onReorder?: (fromIndex: number, toIndex: number) => void;
|
|
44
|
+
}
|
|
45
|
+
export declare function Table<T extends Record<string, unknown>>({ label, columns, rows, rowKey, caption, sort, onSortChange, selectable, selected, onSelectedChange, rowLabel, loading, error, onRetry, emptyTitle, emptyText, emptyAction, reorderable, onReorder, }: TableProps<T>): import("react").JSX.Element;
|
package/dist/Table.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
import { Checkbox } from "./Choice.js";
|
|
5
|
+
import { Alert } from "./Alert.js";
|
|
6
|
+
import { Button } from "./Button.js";
|
|
7
|
+
import { EmptyState } from "./EmptyState.js";
|
|
8
|
+
import { Skeleton } from "./Skeleton.js";
|
|
9
|
+
import { Spinner } from "./Spinner.js";
|
|
10
|
+
const move = (list, from, to) => {
|
|
11
|
+
const next = list.slice();
|
|
12
|
+
const [x] = next.splice(from, 1);
|
|
13
|
+
next.splice(to, 0, x);
|
|
14
|
+
return next;
|
|
15
|
+
};
|
|
16
|
+
export function Table({ label, columns, rows, rowKey, caption, sort, onSortChange, selectable, selected = [], onSelectedChange, rowLabel, loading, error, onRetry, emptyTitle = "行がない", emptyText, emptyAction, reorderable, onReorder, }) {
|
|
17
|
+
const canReorder = !!reorderable && !!onReorder;
|
|
18
|
+
const span = columns.length + (selectable ? 1 : 0) + (canReorder ? 1 : 0);
|
|
19
|
+
const keys = rows.map(rowKey);
|
|
20
|
+
// 行の並べ替え
|
|
21
|
+
const hintId = useId();
|
|
22
|
+
const bodyRef = useRef(null);
|
|
23
|
+
const handles = useRef(new Map());
|
|
24
|
+
const focusKey = useRef(null);
|
|
25
|
+
const origin = useRef({ y: 0, h: 0, mids: [] });
|
|
26
|
+
const [drag, setDrag] = useState(null);
|
|
27
|
+
const [liveText, setLiveText] = useState("");
|
|
28
|
+
const liveN = useRef(0);
|
|
29
|
+
// 同じ文が続いても読み上げられるよう、文の終わりを入れ替える(見た目は変わらない)
|
|
30
|
+
const setLive = (t) => { liveN.current += 1; setLiveText(t + (liveN.current % 2 ? "" : "\u00a0")); };
|
|
31
|
+
const dragRef = useRef(null);
|
|
32
|
+
dragRef.current = drag;
|
|
33
|
+
const enabled = canReorder && !loading && !error && rows.length > 1;
|
|
34
|
+
const nameOf = (row) => (rowLabel ? rowLabel(row) : "この行");
|
|
35
|
+
const place = (from, to) => `${from + 1} 行目から ${to + 1} 行目へ`;
|
|
36
|
+
const finish = useCallback((d, commit) => {
|
|
37
|
+
setDrag(null);
|
|
38
|
+
if (!commit || d.to === d.from) {
|
|
39
|
+
setLive(commit ? "動かさなかった" : `元の位置(${d.from + 1} 行目)に戻した`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
focusKey.current = keys[d.from] ?? null;
|
|
43
|
+
setLive(`${place(d.from, d.to)}移した`);
|
|
44
|
+
onReorder?.(d.from, d.to);
|
|
45
|
+
}, [keys, onReorder]);
|
|
46
|
+
// 並べ替えたあと、行が差し替わっても掴む所へ focus を戻す
|
|
47
|
+
useLayoutEffect(() => {
|
|
48
|
+
if (focusKey.current) {
|
|
49
|
+
handles.current.get(focusKey.current)?.focus();
|
|
50
|
+
}
|
|
51
|
+
if (!drag)
|
|
52
|
+
focusKey.current = null;
|
|
53
|
+
});
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (drag?.mode !== "pointer")
|
|
56
|
+
return;
|
|
57
|
+
const onKey = (e) => { if (e.key === "Escape" && dragRef.current)
|
|
58
|
+
finish(dragRef.current, false); };
|
|
59
|
+
window.addEventListener("keydown", onKey);
|
|
60
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
61
|
+
}, [drag?.mode, finish]);
|
|
62
|
+
const onHandleDown = (e, index) => {
|
|
63
|
+
if (!enabled || (e.pointerType === "mouse" && e.button !== 0))
|
|
64
|
+
return;
|
|
65
|
+
const trs = [...(bodyRef.current?.querySelectorAll(":scope > tr") ?? [])];
|
|
66
|
+
origin.current = { y: e.clientY, h: trs[index]?.getBoundingClientRect().height ?? 0, mids: trs.map((tr) => { const r = tr.getBoundingClientRect(); return r.top + r.height / 2; }) };
|
|
67
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
68
|
+
setDrag({ mode: "pointer", from: index, to: index, slot: index, dy: 0 });
|
|
69
|
+
setLive(`${nameOf(rows[index])} を掴んだ。${index + 1} 行目`);
|
|
70
|
+
};
|
|
71
|
+
const onHandleMove = (e) => {
|
|
72
|
+
const d = dragRef.current;
|
|
73
|
+
if (!d || d.mode !== "pointer")
|
|
74
|
+
return;
|
|
75
|
+
const mids = origin.current.mids;
|
|
76
|
+
const slot = mids.filter((m) => m < e.clientY).length;
|
|
77
|
+
const to = slot > d.from ? slot - 1 : slot;
|
|
78
|
+
if (to !== d.to)
|
|
79
|
+
setLive(`${to + 1} 行目の位置`);
|
|
80
|
+
setDrag({ mode: "pointer", from: d.from, to, slot, dy: e.clientY - origin.current.y });
|
|
81
|
+
};
|
|
82
|
+
const onHandleUp = (e, commit) => {
|
|
83
|
+
const d = dragRef.current;
|
|
84
|
+
if (!d || d.mode !== "pointer")
|
|
85
|
+
return;
|
|
86
|
+
if (e.currentTarget.hasPointerCapture(e.pointerId))
|
|
87
|
+
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
88
|
+
finish(d, commit);
|
|
89
|
+
};
|
|
90
|
+
const onHandleKey = (e, index) => {
|
|
91
|
+
if (!enabled)
|
|
92
|
+
return;
|
|
93
|
+
const d = dragRef.current;
|
|
94
|
+
const lifted = d?.mode === "key" ? d : null;
|
|
95
|
+
if (e.key === " " || e.key === "Spacebar") {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
if (!lifted) {
|
|
98
|
+
if (dragRef.current)
|
|
99
|
+
return;
|
|
100
|
+
focusKey.current = keys[index] ?? null;
|
|
101
|
+
setDrag({ mode: "key", from: index, to: index });
|
|
102
|
+
setLive(`${nameOf(rows[index])} を持ち上げた。${index + 1} 行目。上下の矢印で動かし、Space で置く`);
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
finish(lifted, true);
|
|
106
|
+
}
|
|
107
|
+
else if (e.key === "Enter") {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
if (lifted)
|
|
110
|
+
finish(lifted, true);
|
|
111
|
+
}
|
|
112
|
+
else if (lifted && (e.key === "ArrowUp" || e.key === "ArrowDown")) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
const to = Math.min(rows.length - 1, Math.max(0, lifted.to + (e.key === "ArrowUp" ? -1 : 1)));
|
|
115
|
+
if (to === lifted.to) {
|
|
116
|
+
setLive(to === 0 ? "いちばん上" : "いちばん下");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
setDrag({ mode: "key", from: lifted.from, to });
|
|
120
|
+
setLive(`${to + 1} 行目`);
|
|
121
|
+
}
|
|
122
|
+
else if (lifted && e.key === "Escape") {
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
finish(lifted, false);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// 持ち上げたまま Tab などで離れたら、元に戻す
|
|
129
|
+
// 行が入れ替わる間は一瞬 focus が外れるので、少し待ってから確かめる
|
|
130
|
+
const onHandleBlur = () => {
|
|
131
|
+
setTimeout(() => {
|
|
132
|
+
const d = dragRef.current;
|
|
133
|
+
if (d?.mode !== "key")
|
|
134
|
+
return;
|
|
135
|
+
const el = handles.current.get(keys[d.from] ?? "");
|
|
136
|
+
if (el !== document.activeElement)
|
|
137
|
+
finish(d, false);
|
|
138
|
+
}, 0);
|
|
139
|
+
};
|
|
140
|
+
// 描く順。キーボードで持ち上げている間は、動かした先の並びを見せる
|
|
141
|
+
const order = rows.map((_, i) => i);
|
|
142
|
+
const view = drag?.mode === "key" ? move(order, drag.from, drag.to) : order;
|
|
143
|
+
const allSelected = keys.length > 0 && keys.every((k) => selected.includes(k));
|
|
144
|
+
const someSelected = keys.some((k) => selected.includes(k));
|
|
145
|
+
const nextSort = (col) => {
|
|
146
|
+
if (!onSortChange)
|
|
147
|
+
return;
|
|
148
|
+
if (!sort || sort.key !== col.key)
|
|
149
|
+
onSortChange({ key: col.key, direction: "ascending" });
|
|
150
|
+
else if (sort.direction === "ascending")
|
|
151
|
+
onSortChange({ key: col.key, direction: "descending" });
|
|
152
|
+
else
|
|
153
|
+
onSortChange(null);
|
|
154
|
+
};
|
|
155
|
+
return (_jsxs("div", { className: "ki-table-wrap", role: "region", "aria-label": label, tabIndex: 0, children: [_jsxs("table", { className: "ki-table", "aria-busy": loading || undefined, children: [caption ? _jsx("caption", { children: caption }) : null, _jsx("thead", { children: _jsxs("tr", { children: [canReorder ? _jsx("th", { scope: "col", "data-handle": "", children: _jsx("span", { className: "ki-sr-only", children: "\u4E26\u3079\u66FF\u3048" }) }) : null, selectable ? (_jsx("th", { scope: "col", "data-select": "", children: _jsx(Checkbox, { "aria-label": "\u3059\u3079\u3066\u306E\u884C\u3092\u9078\u629E", checked: allSelected, indeterminate: !allSelected && someSelected, disabled: loading || rows.length === 0, onCheckedChange: (c) => onSelectedChange?.(c ? keys : []) }) })) : null, columns.map((col) => {
|
|
156
|
+
const dir = sort && sort.key === col.key ? sort.direction : undefined;
|
|
157
|
+
return (_jsx("th", { scope: "col", "data-numeric": col.numeric ? "" : undefined, "aria-sort": col.sortable ? dir ?? "none" : undefined, children: col.sortable ? (_jsxs("button", { type: "button", className: "ki-table__sort", onClick: () => nextSort(col), children: [col.header, _jsx(Icon, { name: dir === "ascending" ? "chevron-up" : dir === "descending" ? "chevron-down" : "sort" })] })) : col.header }, col.key));
|
|
158
|
+
})] }) }), _jsx("tbody", { ref: bodyRef, children: error ? (_jsx("tr", { children: _jsx("td", { colSpan: span, className: "ki-table__state", children: _jsx(Alert, { tone: "error", action: onRetry ? _jsx(Button, { variant: "secondary", onClick: onRetry, children: "\u518D\u8A66\u884C" }) : undefined, children: error }) }) })) : loading ? ([0, 1, 2].map((i) => (_jsx("tr", { children: Array.from({ length: span }).map((_, j) => (_jsx("td", { children: _jsx(Skeleton, { size: "long" }) }, j))) }, i)))) : rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: span, className: "ki-table__state", children: _jsx(EmptyState, { title: emptyTitle, action: emptyAction, children: emptyText }) }) })) : (view.map((i, pos) => {
|
|
159
|
+
const row = rows[i];
|
|
160
|
+
const k = rowKey(row);
|
|
161
|
+
const isSel = selected.includes(k);
|
|
162
|
+
const picked = !!drag && i === drag.from;
|
|
163
|
+
// 指やマウスで動かす間は、間の行を 1 行ぶんずらして、落とす所に空きを作る
|
|
164
|
+
let shift = 0;
|
|
165
|
+
if (drag?.mode === "pointer") {
|
|
166
|
+
if (drag.to > drag.from && i > drag.from && i <= drag.to)
|
|
167
|
+
shift = -origin.current.h;
|
|
168
|
+
else if (drag.to < drag.from && i >= drag.to && i < drag.from)
|
|
169
|
+
shift = origin.current.h;
|
|
170
|
+
}
|
|
171
|
+
const lifted = drag?.mode === "key" && picked;
|
|
172
|
+
return (_jsxs("tr", { "aria-selected": selectable ? isSel : undefined, "data-dragging": picked ? "" : undefined, "data-shift": shift ? "" : undefined, style: drag?.mode === "pointer" ? (picked ? { transform: `translateY(${drag.dy}px)` } : shift ? { transform: `translateY(${shift}px)` } : undefined) : undefined, children: [canReorder ? (_jsx("td", { "data-handle": "", children: _jsx("button", { type: "button", className: "ki-table__handle", ref: (el) => { if (el)
|
|
173
|
+
handles.current.set(k, el);
|
|
174
|
+
else
|
|
175
|
+
handles.current.delete(k); }, "aria-label": `${nameOf(row)} を並べ替える(${(drag?.mode === "pointer" && picked ? drag.to : pos) + 1} 行目)`, "aria-describedby": hintId, "aria-pressed": lifted ? true : undefined, disabled: !enabled, "data-active": picked ? "" : undefined, onPointerDown: (e) => onHandleDown(e, i), onPointerMove: onHandleMove, onPointerUp: (e) => onHandleUp(e, true), onPointerCancel: (e) => onHandleUp(e, false), onKeyDown: (e) => onHandleKey(e, i), onBlur: onHandleBlur, onContextMenu: (e) => e.preventDefault(), children: _jsx(Icon, { name: "drag" }) }) })) : null, selectable ? (_jsx("td", { "data-select": "", children: _jsx(Checkbox, { "aria-label": rowLabel ? rowLabel(row) + " を選択" : "この行を選択", checked: isSel, onCheckedChange: (c) => onSelectedChange?.(c ? [...selected, k] : selected.filter((x) => x !== k)) }) })) : null, columns.map((col) => (_jsx("td", { "data-numeric": col.numeric ? "" : undefined, "data-wrap": col.wrap ? "" : undefined, children: col.render ? col.render(row) : row[col.key] }, col.key)))] }, k));
|
|
176
|
+
})) })] }), canReorder ? (_jsxs(_Fragment, { children: [_jsx("span", { id: hintId, className: "ki-sr-only", children: "Space \u3067\u6301\u3061\u4E0A\u3052\u3001\u4E0A\u4E0B\u306E\u77E2\u5370\u3067\u52D5\u304B\u3057\u3001Space \u304B Enter \u3067\u7F6E\u304F\u3002Esc \u3067\u623B\u3059\u3002\u30DE\u30A6\u30B9\u3084\u6307\u3067\u306F\u3001\u62BC\u3057\u305F\u307E\u307E\u52D5\u304B\u3059" }), _jsx("span", { className: "ki-sr-only", role: "status", "aria-live": "polite", children: liveText })] })) : null, loading ? _jsxs("span", { className: "ki-sr-only", role: "status", children: [_jsx(Spinner, {}), "\u8AAD\u307F\u8FBC\u307F\u4E2D"] }) : null] }));
|
|
177
|
+
}
|
package/dist/Tabs.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface TabItem {
|
|
3
|
+
value: string;
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
content: ReactNode;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface TabsProps {
|
|
9
|
+
items: TabItem[];
|
|
10
|
+
value?: string;
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
onValueChange?: (value: string) => void;
|
|
13
|
+
/** タブ一覧の名前 */
|
|
14
|
+
label: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function Tabs({ items, value, defaultValue, onValueChange, label, className }: TabsProps): import("react").JSX.Element;
|
package/dist/Tabs.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Tabs as BaseTabs } from "@base-ui/react/tabs";
|
|
3
|
+
import { cx } from "./utils.js";
|
|
4
|
+
export function Tabs({ items, value, defaultValue, onValueChange, label, className }) {
|
|
5
|
+
return (_jsxs(BaseTabs.Root, { className: cx("ki-tabs", className), value: value, defaultValue: defaultValue ?? items[0]?.value, onValueChange: onValueChange ? (v) => onValueChange(v) : undefined, children: [_jsx(BaseTabs.List, { className: "ki-tabs__list", "aria-label": label, children: items.map((t) => (_jsx(BaseTabs.Tab, { value: t.value, disabled: t.disabled, className: "ki-tabs__tab", children: t.label }, t.value))) }), items.map((t) => (_jsx(BaseTabs.Panel, { value: t.value, className: "ki-tabs__panel", children: t.content }, t.value)))] }));
|
|
6
|
+
}
|