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.
Files changed (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -2
  3. package/dist/Accordion.d.ts +21 -0
  4. package/dist/Accordion.js +8 -0
  5. package/dist/Alert.d.ts +17 -0
  6. package/dist/Alert.js +9 -0
  7. package/dist/AppBar.d.ts +18 -0
  8. package/dist/AppBar.js +7 -0
  9. package/dist/Avatar.d.ts +11 -0
  10. package/dist/Avatar.js +17 -0
  11. package/dist/Badge.d.ts +10 -0
  12. package/dist/Badge.js +5 -0
  13. package/dist/BottomNavigation.d.ts +13 -0
  14. package/dist/BottomNavigation.js +7 -0
  15. package/dist/Breadcrumbs.d.ts +14 -0
  16. package/dist/Breadcrumbs.js +9 -0
  17. package/dist/Button.d.ts +14 -0
  18. package/dist/Button.js +13 -0
  19. package/dist/Calendar.d.ts +28 -0
  20. package/dist/Calendar.js +131 -0
  21. package/dist/Card.d.ts +34 -0
  22. package/dist/Card.js +13 -0
  23. package/dist/Chart.d.ts +41 -0
  24. package/dist/Chart.js +93 -0
  25. package/dist/Chip.d.ts +19 -0
  26. package/dist/Chip.js +19 -0
  27. package/dist/Choice.d.ts +49 -0
  28. package/dist/Choice.js +20 -0
  29. package/dist/CodeBlock.d.ts +12 -0
  30. package/dist/CodeBlock.js +25 -0
  31. package/dist/Combobox.d.ts +30 -0
  32. package/dist/Combobox.js +21 -0
  33. package/dist/DatePicker.d.ts +19 -0
  34. package/dist/DatePicker.js +29 -0
  35. package/dist/Dialog.d.ts +35 -0
  36. package/dist/Dialog.js +19 -0
  37. package/dist/Divider.d.ts +8 -0
  38. package/dist/Divider.js +8 -0
  39. package/dist/Drawer.d.ts +33 -0
  40. package/dist/Drawer.js +19 -0
  41. package/dist/EmptyState.d.ts +12 -0
  42. package/dist/EmptyState.js +5 -0
  43. package/dist/Field.d.ts +14 -0
  44. package/dist/Field.js +7 -0
  45. package/dist/FileUpload.d.ts +23 -0
  46. package/dist/FileUpload.js +116 -0
  47. package/dist/Icon.d.ts +9 -0
  48. package/dist/Icon.js +7 -0
  49. package/dist/IconButton.d.ts +8 -0
  50. package/dist/IconButton.js +13 -0
  51. package/dist/Input.d.ts +14 -0
  52. package/dist/Input.js +14 -0
  53. package/dist/Kbd.d.ts +7 -0
  54. package/dist/Kbd.js +13 -0
  55. package/dist/Layout.d.ts +39 -0
  56. package/dist/Layout.js +24 -0
  57. package/dist/Link.d.ts +11 -0
  58. package/dist/Link.js +5 -0
  59. package/dist/List.d.ts +45 -0
  60. package/dist/List.js +28 -0
  61. package/dist/Menu.d.ts +22 -0
  62. package/dist/Menu.js +16 -0
  63. package/dist/NavItems.d.ts +10 -0
  64. package/dist/NavItems.js +1 -0
  65. package/dist/Pagination.d.ts +16 -0
  66. package/dist/Pagination.js +32 -0
  67. package/dist/Popover.d.ts +22 -0
  68. package/dist/Popover.js +10 -0
  69. package/dist/Progress.d.ts +16 -0
  70. package/dist/Progress.js +9 -0
  71. package/dist/Quote.d.ts +8 -0
  72. package/dist/Quote.js +5 -0
  73. package/dist/SegmentedControl.d.ts +24 -0
  74. package/dist/SegmentedControl.js +8 -0
  75. package/dist/Select.d.ts +20 -0
  76. package/dist/Select.js +10 -0
  77. package/dist/SelectionBar.d.ts +27 -0
  78. package/dist/SelectionBar.js +12 -0
  79. package/dist/Sheet.d.ts +22 -0
  80. package/dist/Sheet.js +16 -0
  81. package/dist/Skeleton.d.ts +13 -0
  82. package/dist/Skeleton.js +9 -0
  83. package/dist/Slider.d.ts +27 -0
  84. package/dist/Slider.js +10 -0
  85. package/dist/Spinner.d.ts +6 -0
  86. package/dist/Spinner.js +5 -0
  87. package/dist/Stat.d.ts +44 -0
  88. package/dist/Stat.js +21 -0
  89. package/dist/Status.d.ts +26 -0
  90. package/dist/Status.js +21 -0
  91. package/dist/Stepper.d.ts +23 -0
  92. package/dist/Stepper.js +8 -0
  93. package/dist/Table.d.ts +45 -0
  94. package/dist/Table.js +177 -0
  95. package/dist/Tabs.d.ts +17 -0
  96. package/dist/Tabs.js +6 -0
  97. package/dist/TextField.d.ts +20 -0
  98. package/dist/TextField.js +7 -0
  99. package/dist/ThemeProvider.d.ts +18 -0
  100. package/dist/ThemeProvider.js +26 -0
  101. package/dist/ThemeScope.d.ts +11 -0
  102. package/dist/ThemeScope.js +13 -0
  103. package/dist/Timeline.d.ts +28 -0
  104. package/dist/Timeline.js +16 -0
  105. package/dist/Toast.d.ts +21 -0
  106. package/dist/Toast.js +29 -0
  107. package/dist/Tooltip.d.ts +9 -0
  108. package/dist/Tooltip.js +7 -0
  109. package/dist/index.d.ts +53 -0
  110. package/dist/index.js +52 -0
  111. package/dist/motion.d.ts +6 -0
  112. package/dist/motion.js +39 -0
  113. package/dist/utils.d.ts +5 -0
  114. package/dist/utils.js +11 -0
  115. package/package.json +53 -3
@@ -0,0 +1,116 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState } from "react";
3
+ import { Icon } from "./Icon.js";
4
+ import { IconButton } from "./IconButton.js";
5
+ import { cx } from "./utils.js";
6
+ /** バイトを「1.2 MB」のように */
7
+ export function formatBytes(n) {
8
+ if (n < 1024)
9
+ return `${n} B`;
10
+ const units = ["KB", "MB", "GB"];
11
+ let v = n / 1024;
12
+ let i = 0;
13
+ while (v >= 1024 && i < units.length - 1) {
14
+ v /= 1024;
15
+ i++;
16
+ }
17
+ return `${v < 10 ? v.toFixed(1) : Math.round(v)} ${units[i]}`;
18
+ }
19
+ /** accept("image/*,.pdf" など)に合うか。input の accept と同じ見方 */
20
+ function accepts(f, accept) {
21
+ if (!accept)
22
+ return true;
23
+ const name = f.name.toLowerCase();
24
+ const type = f.type.toLowerCase();
25
+ return accept.split(",").map((a) => a.trim().toLowerCase()).filter(Boolean).some((a) => a.startsWith(".") ? name.endsWith(a) : a.endsWith("/*") ? type.startsWith(a.slice(0, -1)) : type === a);
26
+ }
27
+ const same = (a, b) => a.name === b.name && a.size === b.size && a.lastModified === b.lastModified;
28
+ /** 行の key。File ごとに 1 度だけ番号を振り、前の行を外しても後ろの行が作り直されないようにする */
29
+ const keys = new WeakMap();
30
+ let next = 0;
31
+ const keyOf = (f) => {
32
+ if (!keys.has(f))
33
+ keys.set(f, next++);
34
+ return keys.get(f);
35
+ };
36
+ /** ファイルを選ぶ、または置く。スマホでは押すと選ぶ画面が開く。選んだ物は下に並び、1 つずつ外せる。 */
37
+ export function FileUpload({ label = "ファイルを選ぶ", accept, multiple, maxSize, hint, value, defaultValue = [], onFilesChange, disabled, invalid, name, className, }) {
38
+ const id = useId();
39
+ const input = useRef(null);
40
+ const list = useRef(null);
41
+ const [inner, setInner] = useState(defaultValue);
42
+ const [over, setOver] = useState(false);
43
+ const [error, setError] = useState("");
44
+ const files = value !== undefined ? value : inner;
45
+ const set = (next) => {
46
+ if (value === undefined)
47
+ setInner(next);
48
+ onFilesChange?.(next);
49
+ };
50
+ // フォームで送れるよう、選んだ物だけを input に入れる(加えなかった物は送らない)
51
+ const sync = (list) => {
52
+ if (!input.current || typeof DataTransfer === "undefined")
53
+ return;
54
+ const dt = new DataTransfer();
55
+ list.forEach((f) => dt.items.add(f));
56
+ input.current.files = dt.files;
57
+ };
58
+ useEffect(() => { sync(files); }, [files]);
59
+ // フォームの reset では一覧も空にする
60
+ useEffect(() => {
61
+ const form = input.current?.form;
62
+ if (!form)
63
+ return;
64
+ const reset = () => { set([]); setError(""); };
65
+ form.addEventListener("reset", reset);
66
+ return () => form.removeEventListener("reset", reset);
67
+ });
68
+ const add = (picked) => {
69
+ if (disabled)
70
+ return;
71
+ const big = [];
72
+ const wrong = [];
73
+ const ok = [];
74
+ for (const f of picked) {
75
+ if (!accepts(f, accept))
76
+ wrong.push(f.name);
77
+ else if (maxSize && f.size > maxSize)
78
+ big.push(f.name);
79
+ else if (!files.some((g) => same(f, g)) && !ok.some((g) => same(f, g)))
80
+ ok.push(f);
81
+ }
82
+ const extra = multiple ? [] : ok.splice(1).map((f) => f.name);
83
+ const why = [
84
+ wrong.length ? `形式が合わない: ${wrong.join("、")}` : "",
85
+ big.length ? `大きすぎる: ${big.join("、")}${maxSize ? `(上限 ${formatBytes(maxSize)})` : ""}` : "",
86
+ extra.length ? `1 つだけ選べる: ${extra.join("、")}` : "",
87
+ ].filter(Boolean);
88
+ // 同じ理由が続いても読み上げるよう、いったん空にしてから入れる
89
+ setError("");
90
+ if (why.length)
91
+ requestAnimationFrame(() => setError(`加えなかった物があります。${why.join("。")}`));
92
+ const nextFiles = ok.length ? (multiple ? [...files, ...ok] : ok) : files;
93
+ if (ok.length)
94
+ set(nextFiles);
95
+ sync(nextFiles);
96
+ };
97
+ const drag = (e, on) => {
98
+ e.preventDefault();
99
+ if (disabled)
100
+ return;
101
+ // 置き場の中の別の要素へ移っただけの時は、外れたことにしない
102
+ if (!on && e.currentTarget.contains(e.relatedTarget))
103
+ return;
104
+ setOver(on);
105
+ };
106
+ const remove = (i) => {
107
+ set(files.filter((_, j) => j !== i));
108
+ setError("");
109
+ // 次の行の「外す」へ。無ければ前の行、それも無ければ置き場へ
110
+ const buttons = list.current ? Array.from(list.current.querySelectorAll("button")) : [];
111
+ const target = buttons[i + 1] ?? buttons[i - 1];
112
+ requestAnimationFrame(() => (target && target.isConnected ? target : input.current)?.focus());
113
+ };
114
+ const describedBy = [hint ? `${id}-h` : "", error ? `${id}-e` : ""].filter(Boolean).join(" ") || undefined;
115
+ return (_jsxs("div", { className: cx("ki-file-upload", className), "data-disabled": disabled ? "" : undefined, "data-invalid": invalid || error ? "" : undefined, children: [_jsxs("label", { className: "ki-file-upload__zone", htmlFor: id, "data-dragging": over ? "" : undefined, onDragEnter: (e) => drag(e, true), onDragOver: (e) => drag(e, true), onDragLeave: (e) => drag(e, false), onDrop: (e) => { e.preventDefault(); setOver(false); add(Array.from(e.dataTransfer.files)); }, children: [_jsx(Icon, { name: "upload" }), _jsx("span", { className: "ki-file-upload__label", children: label }), _jsx("span", { className: "ki-file-upload__sub", "aria-hidden": "true", children: "\u62BC\u3057\u3066\u9078\u3076\u304B\u3001\u3053\u3053\u3078\u7F6E\u304F" }), hint ? _jsx("span", { className: "ki-file-upload__hint", id: `${id}-h`, "aria-hidden": "true", children: hint }) : null, _jsx("input", { ref: input, id: id, className: "ki-file-upload__input", type: "file", title: "", accept: accept, multiple: multiple, disabled: disabled, name: name, "aria-describedby": describedBy, "aria-invalid": invalid || !!error || undefined, onChange: (e) => add(Array.from(e.currentTarget.files ?? [])) })] }), _jsx("p", { className: "ki-file-upload__error", id: `${id}-e`, role: "alert", children: error }), files.length ? (_jsx("ul", { className: "ki-file-upload__list", "aria-label": "\u9078\u3093\u3060\u30D5\u30A1\u30A4\u30EB", ref: list, children: files.map((f, i) => (_jsxs("li", { className: "ki-file-upload__item", children: [_jsx(Icon, { name: "file" }), _jsx("span", { className: "ki-file-upload__name", children: f.name }), _jsx("span", { className: "ki-file-upload__size", children: formatBytes(f.size) }), _jsx(IconButton, { variant: "quiet", label: `${f.name} を外す`, icon: _jsx(Icon, { name: "close" }), disabled: disabled, onClick: () => remove(i) })] }, keyOf(f)))) })) : null] }));
116
+ }
package/dist/Icon.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { type IconName, type IconProps as BaseIconProps } from "knowidea-icons/react";
2
+ export type { IconName };
3
+ export interface IconProps extends Omit<BaseIconProps, "title"> {
4
+ name: IconName;
5
+ /** 意味を持つときだけ付ける。無ければ装飾として隠す(読み上げない) */
6
+ label?: string;
7
+ }
8
+ /** `packages/icons`(workspace の `icons`)の部品を、`ki-icon`(1.25em、currentColor)で包む。 */
9
+ export declare function Icon({ name, label, className, ...rest }: IconProps): import("react").JSX.Element;
package/dist/Icon.js ADDED
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Icon as BaseIcon } from "knowidea-icons/react";
3
+ import { cx } from "./utils.js";
4
+ /** `packages/icons`(workspace の `icons`)の部品を、`ki-icon`(1.25em、currentColor)で包む。 */
5
+ export function Icon({ name, label, className, ...rest }) {
6
+ return _jsx(BaseIcon, { name: name, title: label, className: cx("ki-icon", className), ...rest });
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from "react";
2
+ import type { ButtonProps } from "./Button.js";
3
+ export interface IconButtonProps extends Omit<ButtonProps, "icon" | "children" | "loadingLabel"> {
4
+ /** 読み上げる名前。必須 */
5
+ label: string;
6
+ icon: ReactNode;
7
+ }
8
+ export declare function IconButton({ label, icon, variant, size, loading, className, type, onClick, ...rest }: IconButtonProps): import("react").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Spinner } from "./Spinner.js";
3
+ import { cx } from "./utils.js";
4
+ export function IconButton({ label, icon, variant = "quiet", size = "md", loading = false, className, type = "button", onClick, ...rest }) {
5
+ const handle = (e) => {
6
+ if (loading) {
7
+ e.preventDefault();
8
+ return;
9
+ }
10
+ onClick?.(e);
11
+ };
12
+ return (_jsx("button", { type: type, className: cx("ki-button", "ki-icon-button", className), "data-variant": variant, "data-size": size === "lg" ? "lg" : undefined, "data-loading": loading ? "" : undefined, "aria-busy": loading || undefined, "aria-label": label, onClick: handle, ...rest, children: loading ? _jsx(Spinner, {}) : icon }));
13
+ }
@@ -0,0 +1,14 @@
1
+ import type { ComponentPropsWithoutRef, TextareaHTMLAttributes } from "react";
2
+ export interface InputProps extends ComponentPropsWithoutRef<"input"> {
3
+ /** 失敗。aria-invalid になり、枠が失敗の色になる */
4
+ invalid?: boolean;
5
+ /** 読み込み中。右端に回転を出す */
6
+ loading?: boolean;
7
+ /** 等幅で出す(数字) */
8
+ numeric?: boolean;
9
+ }
10
+ export declare function Input({ invalid, loading, numeric, className, ...rest }: InputProps): import("react").JSX.Element;
11
+ export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
12
+ invalid?: boolean;
13
+ }
14
+ export declare function Textarea({ invalid, className, rows, ...rest }: TextareaProps): import("react").JSX.Element;
package/dist/Input.js ADDED
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Input as BaseInput } from "@base-ui/react/input";
3
+ import { Field as BaseField } from "@base-ui/react/field";
4
+ import { Spinner } from "./Spinner.js";
5
+ import { cx } from "./utils.js";
6
+ export function Input({ invalid, loading, numeric, className, ...rest }) {
7
+ const input = (_jsx(BaseInput, { className: cx("ki-input", className), "aria-invalid": invalid || undefined, "data-numeric": numeric ? "" : undefined, ...rest }));
8
+ if (!loading)
9
+ return input;
10
+ return (_jsxs("span", { className: "ki-input-group", "data-loading": "", children: [input, _jsx("span", { className: "ki-input__adornment", children: _jsx(Spinner, {}) })] }));
11
+ }
12
+ export function Textarea({ invalid, className, rows = 3, ...rest }) {
13
+ return (_jsx(BaseField.Control, { render: _jsx("textarea", { rows: rows }), className: cx("ki-textarea", className), "aria-invalid": invalid || undefined, ...rest }));
14
+ }
package/dist/Kbd.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface KbdProps {
2
+ /** 1 つのキー("K")か、同時に押すキーの並び(["⌘", "K"]) */
3
+ keys: string | string[];
4
+ className?: string;
5
+ }
6
+ /** キーボードのキー。ショートカットを文の中や Menu の右に出す。同時に押すキーは + でつなぐ。 */
7
+ export declare function Kbd({ keys, className }: KbdProps): import("react").JSX.Element;
package/dist/Kbd.js ADDED
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment } from "react";
3
+ import { cx } from "./utils.js";
4
+ /** 記号のキーの読み上げ。見た目は記号、読み上げは名前 */
5
+ const spoken = {
6
+ "⌘": "Command", "⌥": "Option", "⇧": "Shift", "⌃": "Control", "↵": "Enter", "⌫": "Backspace", "⎋": "Esc",
7
+ "↑": "上", "↓": "下", "←": "左", "→": "右",
8
+ };
9
+ /** キーボードのキー。ショートカットを文の中や Menu の右に出す。同時に押すキーは + でつなぐ。 */
10
+ export function Kbd({ keys, className }) {
11
+ const list = Array.isArray(keys) ? keys : [keys];
12
+ return (_jsx("kbd", { className: cx("ki-kbd", className), children: list.map((k, i) => (_jsxs(Fragment, { children: [i > 0 ? _jsx("span", { className: "ki-kbd__plus", "aria-hidden": "true", children: "+" }) : null, _jsx("kbd", { className: "ki-kbd__key", children: spoken[k] ? _jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: k }), _jsx("span", { className: "ki-sr-only", children: spoken[k] })] }) : k })] }, i))) }));
13
+ }
@@ -0,0 +1,39 @@
1
+ import type { ElementType, HTMLAttributes, ReactNode } from "react";
2
+ /** 間隔の段。--space-1(4px)から --space-7(48px) */
3
+ export type Space = 1 | 2 | 3 | 4 | 5 | 6 | 7;
4
+ export interface StackProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
5
+ /** column は縦(既定)、row は横 */
6
+ direction?: "column" | "row";
7
+ /** 間隔の段(1〜7)。省略すると 3(12px)。CSS の --ki-gap で上書きできる(gap を渡すと、そちらが勝つ) */
8
+ gap?: Space;
9
+ align?: "start" | "center" | "end" | "stretch" | "baseline";
10
+ justify?: "start" | "center" | "end" | "between";
11
+ /** row のとき、入りきらなければ折り返す */
12
+ wrap?: boolean;
13
+ /** 描画する要素。既定は div。ul や section など */
14
+ as?: ElementType;
15
+ children?: ReactNode;
16
+ }
17
+ /** 子を 1 方向に並べ、間隔をそろえる。 */
18
+ export declare function Stack({ direction, gap, align, justify, wrap, as: Tag, className, style, children, ...rest }: StackProps): import("react").JSX.Element;
19
+ export interface GridProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
20
+ /** 列の数を固定する。狭い幅(600px 以下)では 1 列になる。無ければ minItemWidth で自動 */
21
+ columns?: number;
22
+ /** columns が無いとき、1 つの最小の幅(px)。既定 240 */
23
+ minItemWidth?: number;
24
+ /** columns を狭い幅でも保つ */
25
+ keepColumns?: boolean;
26
+ gap?: Space;
27
+ as?: ElementType;
28
+ children?: ReactNode;
29
+ }
30
+ /** 格子。列の数を決めるか、1 つの最小の幅で自動に詰める。 */
31
+ export declare function Grid({ columns, minItemWidth, keepColumns, gap, as: Tag, className, style, children, ...rest }: GridProps): import("react").JSX.Element;
32
+ export interface ContainerProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
33
+ /** sm 640px、md 960px(既定)、lg 1200px、fluid は絞らない */
34
+ size?: "sm" | "md" | "lg" | "fluid";
35
+ as?: ElementType;
36
+ children?: ReactNode;
37
+ }
38
+ /** 中身の幅を絞り、左右に余白(16px)を付けて中央に置く。 */
39
+ export declare function Container({ size, as: Tag, className, children, ...rest }: ContainerProps): import("react").JSX.Element;
package/dist/Layout.js ADDED
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./utils.js";
3
+ const gapVar = (g) => `var(--space-${g})`;
4
+ const alignMap = { start: "flex-start", center: "center", end: "flex-end", stretch: "stretch", baseline: "baseline" };
5
+ const justifyMap = { start: "flex-start", center: "center", end: "flex-end", between: "space-between" };
6
+ /** 子を 1 方向に並べ、間隔をそろえる。 */
7
+ export function Stack({ direction = "column", gap, align, justify, wrap, as: Tag = "div", className, style, children, ...rest }) {
8
+ const s = { ...(gap ? { "--ki-gap": gapVar(gap) } : null), ...(align ? { "--ki-align": alignMap[align] } : null), ...(justify ? { "--ki-justify": justifyMap[justify] } : null), ...style };
9
+ return _jsx(Tag, { className: cx("ki-stack", className), "data-direction": direction === "row" ? "row" : undefined, "data-wrap": wrap ? "" : undefined, style: s, ...rest, children: children });
10
+ }
11
+ /** 格子。列の数を決めるか、1 つの最小の幅で自動に詰める。 */
12
+ export function Grid({ columns, minItemWidth, keepColumns, gap, as: Tag = "div", className, style, children, ...rest }) {
13
+ const s = {
14
+ ...(gap ? { "--ki-gap": gapVar(gap) } : null),
15
+ ...(columns ? { "--ki-cols": columns } : null),
16
+ ...(!columns && minItemWidth ? { "--ki-min": `${minItemWidth}px` } : null),
17
+ ...style,
18
+ };
19
+ return _jsx(Tag, { className: cx("ki-grid", className), "data-columns": columns ? "" : undefined, "data-keep": columns && keepColumns ? "" : undefined, style: s, ...rest, children: children });
20
+ }
21
+ /** 中身の幅を絞り、左右に余白(16px)を付けて中央に置く。 */
22
+ export function Container({ size = "md", as: Tag = "div", className, children, ...rest }) {
23
+ return _jsx(Tag, { className: cx("ki-container", className), "data-size": size === "md" ? undefined : size, ...rest, children: children });
24
+ }
package/dist/Link.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { AnchorHTMLAttributes, ReactNode } from "react";
2
+ export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
3
+ tone?: "default" | "muted";
4
+ /** 文の外に単独で置くとき true。44px の高さにする */
5
+ standalone?: boolean;
6
+ /** 別のタブで開く。読み上げる文を足す */
7
+ external?: boolean;
8
+ disabled?: boolean;
9
+ children?: ReactNode;
10
+ }
11
+ export declare function Link({ tone, standalone, external, disabled, className, children, ...rest }: LinkProps): import("react").JSX.Element;
package/dist/Link.js ADDED
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./utils.js";
3
+ export function Link({ tone = "default", standalone, external, disabled, className, children, ...rest }) {
4
+ return (_jsxs("a", { className: cx("ki-link", className), "data-tone": tone === "muted" ? "muted" : undefined, "data-standalone": standalone ? "" : undefined, "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : rest.tabIndex, target: external ? "_blank" : rest.target, rel: external ? "noopener noreferrer" : rest.rel, ...rest, href: disabled ? undefined : rest.href, children: [children, external ? _jsx("span", { className: "ki-sr-only", children: "(\u65B0\u3057\u3044\u30BF\u30D6\u3067\u958B\u304F)" }) : null] }));
5
+ }
package/dist/List.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { type ReactNode } from "react";
2
+ export interface ListEntry {
3
+ id: string;
4
+ /** 題 */
5
+ title: ReactNode;
6
+ /** あると題がリンクになり、行全体が押せる */
7
+ href?: string;
8
+ /** 題の下の 2 行目。Status、時刻、補足を並べる */
9
+ meta?: ReactNode;
10
+ /** 末尾の操作や印。広い幅では右、狭い幅では 3 行目 */
11
+ side?: ReactNode;
12
+ /** 選べない・押せない行 */
13
+ disabled?: boolean;
14
+ }
15
+ export interface ListItemProps {
16
+ item: ListEntry;
17
+ /** 選べる一覧のとき、選んでいるか */
18
+ selected?: boolean;
19
+ /** 無ければ選べない行 */
20
+ onSelectedChange?: (selected: boolean) => void;
21
+ /** 選ぶ枠の名前。既定「{題} を選択」 */
22
+ selectLabel?: string;
23
+ }
24
+ /** 1 行。List の外では使えない(List の中に並べる)。 */
25
+ export declare function ListItem({ item, selected, onSelectedChange, selectLabel }: ListItemProps): import("react").JSX.Element;
26
+ export interface ListProps {
27
+ /** 一覧の名前。必須(読み上げる) */
28
+ label: string;
29
+ items: ListEntry[];
30
+ /** 選んだ行の id。onSelectedChange と一緒に渡すと、選べる一覧になる */
31
+ selected?: string[];
32
+ onSelectedChange?: (ids: string[]) => void;
33
+ state?: "ready" | "loading" | "empty" | "error";
34
+ /** 一覧の上に出す文(例: 8 件) */
35
+ summary?: ReactNode;
36
+ /** 「すべて選択」の文言。選んだ数があれば {count} が数になる */
37
+ selectAllLabel?: string;
38
+ selectedLabel?: string;
39
+ emptyText?: string;
40
+ errorText?: string;
41
+ loadingText?: string;
42
+ className?: string;
43
+ }
44
+ /** 行の一覧。選べる行(左のチェック)、2 行目のメタ、末尾の操作。幅で組み替える。 */
45
+ export declare function List({ label, items, selected, onSelectedChange, state, summary, selectAllLabel, selectedLabel, emptyText, errorText, loadingText, className, }: ListProps): import("react").JSX.Element;
package/dist/List.js ADDED
@@ -0,0 +1,28 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef } from "react";
3
+ import { Checkbox } from "./Choice.js";
4
+ import { EmptyState } from "./EmptyState.js";
5
+ import { Icon } from "./Icon.js";
6
+ import { useListMotion } from "./motion.js";
7
+ import { Skeleton } from "./Skeleton.js";
8
+ /** 1 行。List の外では使えない(List の中に並べる)。 */
9
+ export function ListItem({ item, selected, onSelectedChange, selectLabel }) {
10
+ const text = typeof item.title === "string" ? item.title : undefined;
11
+ return (_jsxs("li", { className: "ki-list__item", "data-id": item.id, "data-selected": selected ? "" : undefined, "data-disabled": item.disabled ? "" : undefined, children: [onSelectedChange ? (_jsx("div", { className: "ki-list__pick", children: _jsx(Checkbox, { "aria-label": selectLabel ?? `${text ?? "この行"} を選択`, checked: !!selected, disabled: item.disabled, onCheckedChange: onSelectedChange }) })) : null, _jsxs("div", { className: "ki-list__main", children: [_jsx("h3", { className: "ki-list__title", children: item.href && !item.disabled ? _jsx("a", { href: item.href, children: item.title }) : item.title }), item.meta ? _jsx("p", { className: "ki-list__meta", children: item.meta }) : null] }), item.side ? _jsx("div", { className: "ki-list__side", children: item.side }) : null] }));
12
+ }
13
+ /** 行の一覧。選べる行(左のチェック)、2 行目のメタ、末尾の操作。幅で組み替える。 */
14
+ export function List({ label, items, selected = [], onSelectedChange, state = "ready", summary, selectAllLabel = "すべて選択", selectedLabel = "{count} 件を選択中", emptyText = "一覧は空", errorText = "一覧を取れなかった。", loadingText = "読み込み中", className, }) {
15
+ const sel = new Set(selected);
16
+ const selectable = !!onSelectedChange;
17
+ const selectableItems = items.filter((i) => !i.disabled);
18
+ const all = selectableItems.length > 0 && selectableItems.every((i) => sel.has(i.id));
19
+ const some = items.some((i) => sel.has(i.id));
20
+ const box = useRef(null);
21
+ // 行を足す、消す、並べ替える時に滑らせる
22
+ useListMotion(box, state === "ready" ? items.map((i) => i.id).join("\n") : state);
23
+ return (_jsxs("div", { className: className, children: [_jsxs("ul", { ref: box, className: "ki-list", "aria-label": label, "aria-busy": state === "loading" || undefined, "data-selectable": selectable ? "" : undefined, children: [selectable && state === "ready" && items.length > 0 ? (_jsxs("li", { className: "ki-list__head", children: [_jsx(Checkbox, { label: selected.length > 0 ? selectedLabel.replace("{count}", String(selected.length)) : selectAllLabel, checked: all, indeterminate: some && !all, onCheckedChange: (c) => onSelectedChange(c ? selectableItems.map((i) => i.id) : []) }), summary ? _jsx("span", { children: summary }) : null] })) : null, state === "loading"
24
+ ? [0, 1, 2].map((i) => (_jsxs("li", { className: "ki-list__item", "data-state": "loading", children: [selectable ? _jsx("div", { className: "ki-list__pick" }) : null, _jsxs("div", { className: "ki-list__main", children: [_jsx(Skeleton, { size: "long" }), _jsx(Skeleton, { size: "medium" })] })] }, i)))
25
+ : null, state === "ready"
26
+ ? items.map((it) => (_jsx(ListItem, { item: it, selected: sel.has(it.id), onSelectedChange: selectable ? (c) => onSelectedChange(c ? [...selected, it.id] : selected.filter((x) => x !== it.id)) : undefined }, it.id)))
27
+ : null, state === "empty" ? _jsx("li", { className: "ki-list__state", children: _jsx(EmptyState, { title: emptyText, icon: _jsx(Icon, { name: "inbox" }) }) }) : null, state === "error" ? _jsx("li", { className: "ki-list__state", children: _jsx(EmptyState, { title: errorText, icon: _jsx(Icon, { name: "warning" }) }) }) : null] }), state === "loading" ? _jsx("span", { className: "ki-sr-only", role: "status", children: loadingText }) : null] }));
28
+ }
package/dist/Menu.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ export type MenuEntry = {
3
+ type?: "item";
4
+ label: string;
5
+ icon?: ReactNode;
6
+ tone?: "danger";
7
+ disabled?: boolean;
8
+ onSelect?: () => void;
9
+ href?: string;
10
+ } | {
11
+ type: "separator";
12
+ } | {
13
+ type: "label";
14
+ label: string;
15
+ };
16
+ export interface MenuProps {
17
+ /** 開くボタン。1 つの要素 */
18
+ trigger: ReactElement;
19
+ items: MenuEntry[];
20
+ align?: "start" | "center" | "end";
21
+ }
22
+ export declare function Menu({ trigger, items, align }: MenuProps): import("react").JSX.Element;
package/dist/Menu.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 { Menu as BaseMenu } from "@base-ui/react/menu";
4
+ export function Menu({ trigger, items, align = "start" }) {
5
+ const scope = useThemeScope();
6
+ return (_jsxs(BaseMenu.Root, { children: [_jsx(BaseMenu.Trigger, { render: trigger }), _jsx(BaseMenu.Portal, { children: _jsx(BaseMenu.Positioner, { className: "ki-menu__positioner", sideOffset: 4, align: align, ...scope, children: _jsx(BaseMenu.Popup, { className: "ki-menu__popup", children: items.map((it, i) => {
7
+ if (it.type === "separator")
8
+ return _jsx(BaseMenu.Separator, { className: "ki-menu__separator" }, i);
9
+ if (it.type === "label")
10
+ return _jsx("div", { className: "ki-menu__label", role: "presentation", children: it.label }, i);
11
+ if (it.href) {
12
+ return (_jsxs(BaseMenu.LinkItem, { href: it.href, className: "ki-menu__item", "data-tone": it.tone, children: [it.icon, it.label] }, i));
13
+ }
14
+ return (_jsxs(BaseMenu.Item, { className: "ki-menu__item", "data-tone": it.tone, disabled: it.disabled, onClick: it.onSelect, children: [it.icon, it.label] }, i));
15
+ }) }) }) })] }));
16
+ }
@@ -0,0 +1,10 @@
1
+ import type { IconName } from "./Icon.js";
2
+ export interface NavItem {
3
+ id: string;
4
+ label: string;
5
+ icon?: IconName;
6
+ href: string;
7
+ /** 件数の印 */
8
+ count?: number;
9
+ disabled?: boolean;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ export interface PaginationProps {
2
+ /** 今のページ(1 から) */
3
+ page: number;
4
+ pageCount: number;
5
+ onPageChange?: (page: number) => void;
6
+ /** 渡すとボタンでなくリンクにする(ページごとに URL がある場合) */
7
+ getHref?: (page: number) => string;
8
+ /** 今のページの前後に出す数 */
9
+ siblings?: number;
10
+ label?: string;
11
+ className?: string;
12
+ }
13
+ type Item = number | "gap-start" | "gap-end";
14
+ export declare function pageItems(page: number, count: number, siblings: number): Item[];
15
+ export declare function Pagination({ page, pageCount, onPageChange, getHref, siblings, label, className }: PaginationProps): import("react").JSX.Element;
16
+ export {};
@@ -0,0 +1,32 @@
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
+ export function pageItems(page, count, siblings) {
5
+ const total = siblings * 2 + 5;
6
+ if (count <= total)
7
+ return Array.from({ length: count }, (_, i) => i + 1);
8
+ const left = Math.max(page - siblings, 2);
9
+ const right = Math.min(page + siblings, count - 1);
10
+ const out = [1];
11
+ if (left > 2)
12
+ out.push("gap-start");
13
+ for (let i = left; i <= right; i++)
14
+ out.push(i);
15
+ if (right < count - 1)
16
+ out.push("gap-end");
17
+ out.push(count);
18
+ return out;
19
+ }
20
+ export function Pagination({ page, pageCount, onPageChange, getHref, siblings = 1, label = "ページ送り", className }) {
21
+ const cell = (p, content, aria, disabled = false, current = false) => {
22
+ const common = {
23
+ className: "ki-pagination__item",
24
+ "aria-label": aria,
25
+ "aria-current": current ? "page" : undefined,
26
+ };
27
+ if (getHref && !disabled)
28
+ return _jsx("a", { ...common, href: getHref(p), onClick: onPageChange ? (e) => { e.preventDefault(); onPageChange(p); } : undefined, children: content });
29
+ return (_jsx("button", { type: "button", ...common, disabled: disabled, onClick: () => onPageChange?.(p), children: content }));
30
+ };
31
+ return (_jsx("nav", { className: cx("ki-pagination", className), "aria-label": label, children: _jsxs("ul", { className: "ki-pagination__list", children: [_jsx("li", { children: cell(page - 1, _jsx(Icon, { name: "chevron-left" }), "前のページ", page <= 1) }), pageItems(page, pageCount, siblings).map((it) => (_jsx("li", { children: typeof it === "number" ? cell(it, it, `${it} ページ`, false, it === page) : _jsx("span", { className: "ki-pagination__gap", "aria-hidden": "true", children: "\u2026" }) }, String(it)))), _jsx("li", { children: cell(page + 1, _jsx(Icon, { name: "chevron-right" }), "次のページ", page >= pageCount) })] }) }));
32
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReactElement, ReactNode } from "react";
2
+ export interface PopoverProps {
3
+ /** 開くボタン。1 つの要素 */
4
+ trigger: ReactElement;
5
+ /** 見出し。読み上げの名前になる */
6
+ title?: ReactNode;
7
+ description?: ReactNode;
8
+ children?: ReactNode;
9
+ /** 開く向き */
10
+ side?: "top" | "bottom" | "left" | "right";
11
+ align?: "start" | "center" | "end";
12
+ /** 見出しが無い時の名前(読み上げ) */
13
+ "aria-label"?: string;
14
+ /** 右上に閉じるボタンを出す */
15
+ closable?: boolean;
16
+ closeLabel?: string;
17
+ open?: boolean;
18
+ defaultOpen?: boolean;
19
+ onOpenChange?: (open: boolean) => void;
20
+ }
21
+ /** ボタンの近くに出る小さな面。外を押すか Esc で閉じ、開いたボタンに focus が戻る。中の操作は Tab で移れる。 */
22
+ export declare function Popover({ trigger, title, description, children, side, align, closable, closeLabel, open, defaultOpen, onOpenChange, ...rest }: PopoverProps): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useThemeScope } from "./ThemeScope.js";
3
+ import { Popover as BasePopover } from "@base-ui/react/popover";
4
+ import { Icon } from "./Icon.js";
5
+ import { IconButton } from "./IconButton.js";
6
+ /** ボタンの近くに出る小さな面。外を押すか Esc で閉じ、開いたボタンに focus が戻る。中の操作は Tab で移れる。 */
7
+ export function Popover({ trigger, title, description, children, side = "bottom", align = "start", closable, closeLabel = "閉じる", open, defaultOpen, onOpenChange, ...rest }) {
8
+ const scope = useThemeScope();
9
+ return (_jsxs(BasePopover.Root, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange ? (o) => onOpenChange(o) : undefined, children: [_jsx(BasePopover.Trigger, { render: trigger }), _jsx(BasePopover.Portal, { children: _jsx(BasePopover.Positioner, { className: "ki-popover__positioner", side: side, align: align, sideOffset: 4, collisionPadding: 16, ...scope, children: _jsxs(BasePopover.Popup, { className: "ki-popover", "aria-label": title ? undefined : rest["aria-label"], children: [title || closable ? (_jsxs("div", { className: "ki-popover__head", children: [title ? _jsx(BasePopover.Title, { className: "ki-popover__title", children: title }) : _jsx("span", {}), closable ? _jsx(BasePopover.Close, { render: _jsx(IconButton, { variant: "quiet", label: closeLabel, icon: _jsx(Icon, { name: "close" }) }) }) : null] })) : null, description ? _jsx(BasePopover.Description, { className: "ki-popover__description", children: description }) : null, children ? _jsx("div", { className: "ki-popover__body", children: children }) : null] }) }) })] }));
10
+ }
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from "react";
2
+ export interface ProgressProps {
3
+ /** 0 から max。null は進み具合が不明(動かさず、破線の枠で示す) */
4
+ value: number | null;
5
+ max?: number;
6
+ /** 何の進み具合か。必須(読み上げの名前になる) */
7
+ label: ReactNode;
8
+ /** 値を文字でも出す(例: 40%)。既定は true */
9
+ showValue?: boolean;
10
+ tone?: "primary" | "success" | "warn" | "error";
11
+ size?: "md" | "lg";
12
+ disabled?: boolean;
13
+ className?: string;
14
+ }
15
+ /** 進み具合の線。値は文字でも出す。終わらない動きは使わない。 */
16
+ export declare function Progress({ value, max, label, showValue, tone, size, disabled, className }: ProgressProps): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Progress as BaseProgress } from "@base-ui/react/progress";
3
+ import { cx } from "./utils.js";
4
+ /** 進み具合の線。値は文字でも出す。終わらない動きは使わない。 */
5
+ export function Progress({ value, max = 100, label, showValue = true, tone = "primary", size = "md", disabled, className }) {
6
+ const known = value != null;
7
+ const pct = known ? Math.min(100, Math.max(0, (value / max) * 100)) : 0;
8
+ return (_jsxs(BaseProgress.Root, { value: value, max: max, className: cx("ki-progress", className), "data-tone": tone === "primary" ? undefined : tone, "data-size": size === "lg" ? "lg" : undefined, "data-indeterminate": known ? undefined : "", "data-disabled": disabled ? "" : undefined, getAriaValueText: (formatted) => (known ? `${Math.round(pct)}%` : "不明"), children: [_jsxs("div", { className: "ki-progress__head", children: [_jsx(BaseProgress.Label, { className: "ki-progress__label", children: label }), showValue ? _jsx("span", { className: "ki-progress__value", children: known ? `${Math.round(pct)}%` : "不明" }) : null] }), _jsx(BaseProgress.Track, { className: "ki-progress__track", children: _jsx(BaseProgress.Indicator, { className: "ki-progress__bar", style: known ? { width: `${pct}%` } : undefined }) })] }));
9
+ }
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from "react";
2
+ export interface QuoteProps {
3
+ /** 出典 */
4
+ cite?: ReactNode;
5
+ className?: string;
6
+ children: ReactNode;
7
+ }
8
+ export declare function Quote({ cite, className, children }: QuoteProps): import("react").JSX.Element;
package/dist/Quote.js ADDED
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./utils.js";
3
+ export function Quote({ cite, className, children }) {
4
+ return (_jsxs("figure", { className: cx("ki-quote", className), children: [_jsx("blockquote", { children: children }), cite ? _jsx("figcaption", { children: cite }) : null] }));
5
+ }
@@ -0,0 +1,24 @@
1
+ import type { ReactNode } from "react";
2
+ export interface SegmentedOption {
3
+ value: string;
4
+ label: ReactNode;
5
+ /** 字の前に置くアイコン */
6
+ icon?: ReactNode;
7
+ disabled?: boolean;
8
+ }
9
+ export interface SegmentedControlProps {
10
+ /** 何を切り替えるか。必須(スクリーンリーダー向けの名前) */
11
+ label: string;
12
+ /** 2 から 5 個 */
13
+ options: SegmentedOption[];
14
+ value?: string;
15
+ defaultValue?: string;
16
+ onValueChange?: (value: string) => void;
17
+ name?: string;
18
+ disabled?: boolean;
19
+ /** 親の幅いっぱいに広げる */
20
+ fullWidth?: boolean;
21
+ className?: string;
22
+ }
23
+ /** 表示の切り替え。選んだ印は、選んだ所へ滑る。矢印キーで移る(ラジオのグループ)。 */
24
+ export declare function SegmentedControl({ label, options, value, defaultValue, onValueChange, name, disabled, fullWidth, className }: SegmentedControlProps): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Radio as BaseRadio } from "@base-ui/react/radio";
3
+ import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
4
+ import { cx } from "./utils.js";
5
+ /** 表示の切り替え。選んだ印は、選んだ所へ滑る。矢印キーで移る(ラジオのグループ)。 */
6
+ export function SegmentedControl({ label, options, value, defaultValue, onValueChange, name, disabled, fullWidth, className }) {
7
+ return (_jsxs(BaseRadioGroup, { "aria-label": label, className: cx("ki-segmented", className), style: { "--ki-seg-count": options.length }, "data-full-width": fullWidth ? "" : undefined, value: value, defaultValue: defaultValue ?? (value === undefined ? options[0]?.value : undefined), onValueChange: onValueChange ? (v) => onValueChange(v) : undefined, name: name, disabled: disabled, children: [_jsx("span", { className: "ki-segmented__thumb", "aria-hidden": "true" }), options.map((o) => (_jsxs(BaseRadio.Root, { value: o.value, disabled: o.disabled, className: "ki-segmented__item", children: [o.icon, o.label] }, o.value)))] }));
8
+ }