@nazuraki/ui-react 0.2.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/dist/Button.d.ts +6 -0
- package/dist/Button.js +9 -0
- package/dist/Card.d.ts +3 -0
- package/dist/Card.js +4 -0
- package/dist/Dialog.d.ts +10 -0
- package/dist/Dialog.js +17 -0
- package/dist/NavLink.d.ts +4 -0
- package/dist/NavLink.js +5 -0
- package/dist/Tabs.d.ts +14 -0
- package/dist/Tabs.js +13 -0
- package/dist/cx.d.ts +1 -0
- package/dist/cx.js +3 -0
- package/dist/feedback.d.ts +18 -0
- package/dist/feedback.js +15 -0
- package/dist/form.d.ts +23 -0
- package/dist/form.js +31 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/package.json +35 -0
package/dist/Button.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes } from "react";
|
|
2
|
+
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
3
|
+
/** Visual emphasis. Maps to .nb-btn--{variant}. */
|
|
4
|
+
variant?: "default" | "primary" | "accent" | "danger";
|
|
5
|
+
}
|
|
6
|
+
export declare function Button({ variant, className, ...rest }: ButtonProps): import("react").JSX.Element;
|
package/dist/Button.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function Button({ variant = "default", className, ...rest }) {
|
|
3
|
+
const classes = ["nb-btn"];
|
|
4
|
+
if (variant !== "default")
|
|
5
|
+
classes.push(`nb-btn--${variant}`);
|
|
6
|
+
if (className)
|
|
7
|
+
classes.push(className);
|
|
8
|
+
return _jsx("button", { className: classes.join(" "), ...rest });
|
|
9
|
+
}
|
package/dist/Card.d.ts
ADDED
package/dist/Card.js
ADDED
package/dist/Dialog.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DialogHTMLAttributes, ReactNode } from "react";
|
|
2
|
+
export interface DialogProps extends Omit<DialogHTMLAttributes<HTMLDialogElement>, "open" | "title"> {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onClose?: () => void;
|
|
5
|
+
title?: ReactNode;
|
|
6
|
+
/** Rendered in a right-aligned action row below the content. */
|
|
7
|
+
actions?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/** Modal dialog on the native <dialog> element (showModal + ::backdrop). */
|
|
10
|
+
export declare function Dialog({ open, onClose, title, actions, className, children, ...rest }: DialogProps): import("react").JSX.Element;
|
package/dist/Dialog.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
/** Modal dialog on the native <dialog> element (showModal + ::backdrop). */
|
|
5
|
+
export function Dialog({ open, onClose, title, actions, className, children, ...rest }) {
|
|
6
|
+
const ref = useRef(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const el = ref.current;
|
|
9
|
+
if (!el)
|
|
10
|
+
return;
|
|
11
|
+
if (open && !el.open)
|
|
12
|
+
el.showModal();
|
|
13
|
+
else if (!open && el.open)
|
|
14
|
+
el.close();
|
|
15
|
+
}, [open]);
|
|
16
|
+
return (_jsxs("dialog", { ref: ref, className: cx("nb-dialog", className), onClose: onClose, ...rest, children: [title !== undefined && _jsx("h2", { className: "nb-dialog__title", children: title }), children, actions !== undefined && _jsx("div", { className: "nb-dialog__actions", children: actions })] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AnchorHTMLAttributes } from "react";
|
|
2
|
+
export type NavLinkProps = AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
3
|
+
/** The switchboard-style uppercase link with chevron and glow hover. */
|
|
4
|
+
export declare function NavLink({ className, ...rest }: NavLinkProps): import("react").JSX.Element;
|
package/dist/NavLink.js
ADDED
package/dist/Tabs.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface TabItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
content: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export interface TabsProps {
|
|
8
|
+
items: TabItem[];
|
|
9
|
+
/** Controlled active tab id; omit for uncontrolled. */
|
|
10
|
+
active?: string;
|
|
11
|
+
defaultActive?: string;
|
|
12
|
+
onChange?: (id: string) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function Tabs({ items, active, defaultActive, onChange }: TabsProps): import("react").JSX.Element;
|
package/dist/Tabs.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
export function Tabs({ items, active, defaultActive, onChange }) {
|
|
5
|
+
const [internal, setInternal] = useState(defaultActive ?? items[0]?.id);
|
|
6
|
+
const current = active ?? internal;
|
|
7
|
+
const select = (id) => {
|
|
8
|
+
setInternal(id);
|
|
9
|
+
onChange?.(id);
|
|
10
|
+
};
|
|
11
|
+
const activeItem = items.find((t) => t.id === current);
|
|
12
|
+
return (_jsxs("div", { children: [_jsx("div", { role: "tablist", className: "nb-tabs", children: items.map((t) => (_jsx("button", { role: "tab", type: "button", "aria-selected": t.id === current, className: cx("nb-tab", t.id === current && "nb-tab--active"), onClick: () => select(t.id), children: t.label }, t.id))) }), _jsx("div", { role: "tabpanel", className: "nb-tabpanel", children: activeItem?.content })] }));
|
|
13
|
+
}
|
package/dist/cx.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function cx(...parts: Array<string | false | null | undefined>): string;
|
package/dist/cx.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from "react";
|
|
2
|
+
export type SemanticVariant = "info" | "success" | "warning" | "danger";
|
|
3
|
+
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
4
|
+
variant?: SemanticVariant | "primary";
|
|
5
|
+
}
|
|
6
|
+
export declare function Badge({ variant, className, ...rest }: BadgeProps): import("react").JSX.Element;
|
|
7
|
+
export interface AlertProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
|
|
8
|
+
variant?: SemanticVariant;
|
|
9
|
+
title?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export declare function Alert({ variant, title, className, children, ...rest }: AlertProps): import("react").JSX.Element;
|
|
12
|
+
export interface ProgressProps extends HTMLAttributes<HTMLDivElement> {
|
|
13
|
+
/** 0–100 */
|
|
14
|
+
value: number;
|
|
15
|
+
accent?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function Progress({ value, accent, className, ...rest }: ProgressProps): import("react").JSX.Element;
|
|
18
|
+
export declare function Spinner({ className, ...rest }: HTMLAttributes<HTMLSpanElement>): import("react").JSX.Element;
|
package/dist/feedback.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
export function Badge({ variant, className, ...rest }) {
|
|
4
|
+
return _jsx("span", { className: cx("nb-badge", variant && `nb-badge--${variant}`, className), ...rest });
|
|
5
|
+
}
|
|
6
|
+
export function Alert({ variant = "info", title, className, children, ...rest }) {
|
|
7
|
+
return (_jsxs("div", { role: "alert", className: cx("nb-alert", `nb-alert--${variant}`, className), ...rest, children: [title !== undefined && _jsx("span", { className: "nb-alert__title", children: title }), children] }));
|
|
8
|
+
}
|
|
9
|
+
export function Progress({ value, accent, className, ...rest }) {
|
|
10
|
+
const clamped = Math.max(0, Math.min(100, value));
|
|
11
|
+
return (_jsx("div", { role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": clamped, className: cx("nb-progress", className), ...rest, children: _jsx("div", { className: cx("nb-progress__bar", accent && "nb-progress__bar--accent"), style: { width: `${clamped}%` } }) }));
|
|
12
|
+
}
|
|
13
|
+
export function Spinner({ className, ...rest }) {
|
|
14
|
+
return _jsx("span", { role: "status", "aria-label": "loading", className: cx("nb-spinner", className), ...rest });
|
|
15
|
+
}
|
package/dist/form.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { InputHTMLAttributes, LabelHTMLAttributes, ReactNode, SelectHTMLAttributes, TextareaHTMLAttributes } from "react";
|
|
2
|
+
export type InputProps = InputHTMLAttributes<HTMLInputElement>;
|
|
3
|
+
export declare function Input({ className, ...rest }: InputProps): import("react").JSX.Element;
|
|
4
|
+
export type TextareaProps = TextareaHTMLAttributes<HTMLTextAreaElement>;
|
|
5
|
+
export declare function Textarea({ className, ...rest }: TextareaProps): import("react").JSX.Element;
|
|
6
|
+
export type SelectProps = SelectHTMLAttributes<HTMLSelectElement>;
|
|
7
|
+
export declare function Select({ className, ...rest }: SelectProps): import("react").JSX.Element;
|
|
8
|
+
export interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
|
|
9
|
+
}
|
|
10
|
+
export declare function Label({ className, ...rest }: LabelProps): import("react").JSX.Element;
|
|
11
|
+
/** Label + control wrapper with standard field spacing. */
|
|
12
|
+
export declare function Field({ label, htmlFor, children }: {
|
|
13
|
+
label: ReactNode;
|
|
14
|
+
htmlFor?: string;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}): import("react").JSX.Element;
|
|
17
|
+
type ChoiceProps = InputHTMLAttributes<HTMLInputElement> & {
|
|
18
|
+
label?: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
export declare const Checkbox: ({ label, className, ...rest }: ChoiceProps) => import("react").JSX.Element;
|
|
21
|
+
export declare const Radio: ({ label, className, ...rest }: ChoiceProps) => import("react").JSX.Element;
|
|
22
|
+
export declare const Switch: ({ label, className, ...rest }: ChoiceProps) => import("react").JSX.Element;
|
|
23
|
+
export {};
|
package/dist/form.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
export function Input({ className, ...rest }) {
|
|
4
|
+
return _jsx("input", { className: cx("nb-input", className), ...rest });
|
|
5
|
+
}
|
|
6
|
+
export function Textarea({ className, ...rest }) {
|
|
7
|
+
return _jsx("textarea", { className: cx("nb-textarea", className), ...rest });
|
|
8
|
+
}
|
|
9
|
+
export function Select({ className, ...rest }) {
|
|
10
|
+
return _jsx("select", { className: cx("nb-select", className), ...rest });
|
|
11
|
+
}
|
|
12
|
+
export function Label({ className, ...rest }) {
|
|
13
|
+
return _jsx("label", { className: cx("nb-label", className), ...rest });
|
|
14
|
+
}
|
|
15
|
+
/** Label + control wrapper with standard field spacing. */
|
|
16
|
+
export function Field({ label, htmlFor, children }) {
|
|
17
|
+
return (_jsxs("div", { className: "nb-field", children: [_jsx(Label, { htmlFor: htmlFor, children: label }), children] }));
|
|
18
|
+
}
|
|
19
|
+
function choice(kind) {
|
|
20
|
+
const inputClass = `nb-${kind}`;
|
|
21
|
+
const type = kind === "switch" ? "checkbox" : kind;
|
|
22
|
+
return function Choice({ label, className, ...rest }) {
|
|
23
|
+
const input = _jsx("input", { type: type, role: kind === "switch" ? "switch" : undefined, className: cx(inputClass, className), ...rest });
|
|
24
|
+
if (label === undefined)
|
|
25
|
+
return input;
|
|
26
|
+
return (_jsxs("label", { className: "nb-choice", children: [input, label] }));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export const Checkbox = choice("checkbox");
|
|
30
|
+
export const Radio = choice("radio");
|
|
31
|
+
export const Switch = choice("switch");
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Button, type ButtonProps } from "./Button.js";
|
|
2
|
+
export { Card, type CardProps } from "./Card.js";
|
|
3
|
+
export { NavLink, type NavLinkProps } from "./NavLink.js";
|
|
4
|
+
export { Input, Textarea, Select, Label, Field, Checkbox, Radio, Switch, type InputProps, type TextareaProps, type SelectProps, type LabelProps, } from "./form.js";
|
|
5
|
+
export { Badge, Alert, Progress, Spinner, type BadgeProps, type AlertProps, type ProgressProps, type SemanticVariant, } from "./feedback.js";
|
|
6
|
+
export { Dialog, type DialogProps } from "./Dialog.js";
|
|
7
|
+
export { Tabs, type TabsProps, type TabItem } from "./Tabs.js";
|
|
8
|
+
export { cx } from "./cx.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Button } from "./Button.js";
|
|
2
|
+
export { Card } from "./Card.js";
|
|
3
|
+
export { NavLink } from "./NavLink.js";
|
|
4
|
+
export { Input, Textarea, Select, Label, Field, Checkbox, Radio, Switch, } from "./form.js";
|
|
5
|
+
export { Badge, Alert, Progress, Spinner, } from "./feedback.js";
|
|
6
|
+
export { Dialog } from "./Dialog.js";
|
|
7
|
+
export { Tabs } from "./Tabs.js";
|
|
8
|
+
export { cx } from "./cx.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nazuraki/ui-react",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Shared React components styled by @nazuraki/styles themes.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/nazuraki/ui-std-lib.git",
|
|
9
|
+
"directory": "components/react"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "^19.0.0",
|
|
32
|
+
"react": "^19.0.0",
|
|
33
|
+
"typescript": "^5.7.0"
|
|
34
|
+
}
|
|
35
|
+
}
|