@nicolassancho/storybook-core 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/components/Atoms/Badge/Badge.d.ts +11 -0
- package/dist/components/Atoms/Badge/Badge.js +14 -0
- package/dist/components/Atoms/TableSkeleton/TableSkeleton.d.ts +13 -0
- package/dist/components/Atoms/TableSkeleton/TableSkeleton.js +16 -0
- package/dist/components/Molecules/EmptyState/EmptyState.d.ts +13 -0
- package/dist/components/Molecules/EmptyState/EmptyState.js +15 -0
- package/dist/components/Molecules/Input/Input.js +3 -10
- package/dist/components/Molecules/Input/fieldStyles.d.ts +17 -0
- package/dist/components/Molecules/Input/fieldStyles.js +12 -0
- package/dist/components/Molecules/Pagination/Pagination.d.ts +33 -0
- package/dist/components/Molecules/Pagination/Pagination.js +17 -0
- package/dist/components/Molecules/Select/Select.d.ts +29 -0
- package/dist/components/Molecules/Select/Select.js +24 -0
- package/dist/components/Molecules/Table/Table.d.ts +64 -0
- package/dist/components/Molecules/Table/Table.js +81 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,8 +35,8 @@ documented in Storybook. It is published to npm as `@nicolassancho/storybook-cor
|
|
|
35
35
|
|
|
36
36
|
| Layer | Components |
|
|
37
37
|
| --------- | ----------------------------------------------------------------------------------- |
|
|
38
|
-
| Atoms | Button, ButtonLink, Card, Chip, ChipLink, Icon, Image, Label, RadioButton, SearchInput (deprecated), Spinner, Text |
|
|
39
|
-
| Molecules | Alert, Breadcrumbs, CartIcon, Input, Popover, ProductCard, ProductDetails, RadioGroup, SidebarNav |
|
|
38
|
+
| Atoms | Badge, Button, ButtonLink, Card, Chip, ChipLink, Icon, Image, Label, RadioButton, SearchInput (deprecated), Spinner, TableSkeleton, Text |
|
|
39
|
+
| Molecules | Alert, Breadcrumbs, CartIcon, EmptyState, Input, Pagination, Popover, ProductCard, ProductDetails, RadioGroup, Select, SidebarNav, Table |
|
|
40
40
|
| Organisms | Footer, Header, ProductGrid |
|
|
41
41
|
| Layouts | Container, Grid |
|
|
42
42
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface BadgeProps {
|
|
3
|
+
/** The text. It is always visible, so meaning never depends on color alone. */
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
/** `success` for a good state, such as Active. `neutral` for everything else. */
|
|
6
|
+
variant?: "neutral" | "success";
|
|
7
|
+
/** Additional classes for custom styling */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
/** A small label for a status. */
|
|
11
|
+
export declare const Badge: React.FC<BadgeProps>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
const badgeStyles = tv({
|
|
4
|
+
base: "inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",
|
|
5
|
+
variants: {
|
|
6
|
+
variant: {
|
|
7
|
+
neutral: "border border-neutral-200 bg-neutral-50 text-neutral-700",
|
|
8
|
+
success: "bg-success-subtle text-success",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
defaultVariants: { variant: "neutral" },
|
|
12
|
+
});
|
|
13
|
+
/** A small label for a status. */
|
|
14
|
+
export const Badge = ({ children, variant, className }) => (_jsx("span", { className: badgeStyles({ variant, className }), children: children }));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface TableSkeletonProps {
|
|
3
|
+
/** Text for screen readers while the content loads, for example "Loading products". */
|
|
4
|
+
label: string;
|
|
5
|
+
/** Rows under the header row. */
|
|
6
|
+
rows?: number;
|
|
7
|
+
/** Bars in each row. */
|
|
8
|
+
columns?: number;
|
|
9
|
+
/** Additional classes for custom styling */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/** A placeholder for tabular content on first load. The bars are hidden from screen readers. */
|
|
13
|
+
export declare const TableSkeleton: React.FC<TableSkeletonProps>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
const tableSkeletonStyles = tv({
|
|
4
|
+
slots: {
|
|
5
|
+
bars: "animate-pulse motion-reduce:animate-none",
|
|
6
|
+
row: "flex h-10 items-center gap-6 border-b border-neutral-200 px-4 last:border-b-0",
|
|
7
|
+
header: "bg-neutral-50",
|
|
8
|
+
bar: "h-3 flex-1 rounded-sm bg-neutral-200",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
/** A placeholder for tabular content on first load. The bars are hidden from screen readers. */
|
|
12
|
+
export const TableSkeleton = ({ label, rows = 6, columns = 3, className, }) => {
|
|
13
|
+
const styles = tableSkeletonStyles();
|
|
14
|
+
const bars = Array.from({ length: columns }, (_, column) => (_jsx("span", { className: styles.bar() }, column)));
|
|
15
|
+
return (_jsxs("div", { className: className, children: [_jsx("p", { role: "status", className: "sr-only", children: label }), _jsxs("div", { "aria-hidden": "true", className: styles.bars(), children: [_jsx("div", { className: styles.row({ className: styles.header() }), children: bars }), Array.from({ length: rows }, (_, row) => (_jsx("div", { className: styles.row(), children: bars }, row)))] })] }));
|
|
16
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface EmptyStateProps {
|
|
3
|
+
/** What is empty, for example "No products yet." */
|
|
4
|
+
title: string;
|
|
5
|
+
/** What to do next. */
|
|
6
|
+
description?: string;
|
|
7
|
+
/** Slot under the text, usually a `ButtonLink`. */
|
|
8
|
+
action?: React.ReactNode;
|
|
9
|
+
/** Additional classes for custom styling */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
/** The message shown in place of a list that has nothing to show. */
|
|
13
|
+
export declare const EmptyState: React.FC<EmptyStateProps>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
const emptyStateStyles = tv({
|
|
4
|
+
slots: {
|
|
5
|
+
base: "px-4 py-12 text-center",
|
|
6
|
+
title: "font-medium text-neutral-900",
|
|
7
|
+
description: "mt-1 text-sm text-neutral-600",
|
|
8
|
+
action: "mt-4",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
/** The message shown in place of a list that has nothing to show. */
|
|
12
|
+
export const EmptyState = ({ title, description, action, className, }) => {
|
|
13
|
+
const styles = emptyStateStyles();
|
|
14
|
+
return (_jsxs("div", { className: styles.base({ className }), children: [_jsx("p", { className: styles.title(), children: title }), description && _jsx("p", { className: styles.description(), children: description }), action && _jsx("div", { className: styles.action(), children: action })] }));
|
|
15
|
+
};
|
|
@@ -13,20 +13,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
import { useId } from "react";
|
|
14
14
|
import { tv } from "tailwind-variants";
|
|
15
15
|
import { Label } from "../../Atoms/Label/Label.js";
|
|
16
|
+
import { fieldStyles } from "./fieldStyles.js";
|
|
16
17
|
const inputStyles = tv({
|
|
17
18
|
slots: {
|
|
18
19
|
root: "flex flex-col gap-1",
|
|
19
|
-
field: "w-full rounded-sm border bg-surface px-3 py-2 text-sm text-neutral-900 placeholder:text-neutral-500 focus:outline-hidden focus:ring-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
|
|
20
20
|
description: "text-sm text-neutral-500",
|
|
21
21
|
error: "text-sm text-danger",
|
|
22
22
|
},
|
|
23
|
-
variants: {
|
|
24
|
-
invalid: {
|
|
25
|
-
true: { field: "border-danger focus:border-danger focus:ring-danger" },
|
|
26
|
-
false: { field: "border-neutral-400 focus:border-primary focus:ring-primary" },
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
defaultVariants: { invalid: false },
|
|
30
23
|
});
|
|
31
24
|
/**
|
|
32
25
|
* A text field with its label, optional help text and optional error message. It needs no
|
|
@@ -40,6 +33,6 @@ export const Input = (_a) => {
|
|
|
40
33
|
const descriptionId = `${inputId}-description`;
|
|
41
34
|
const errorId = `${inputId}-error`;
|
|
42
35
|
const ids = [describedBy, description && descriptionId, error && errorId].filter(Boolean);
|
|
43
|
-
const styles = inputStyles(
|
|
44
|
-
return (_jsxs("div", { className: styles.root(), children: [_jsx(Label, { htmlFor: inputId, color: "darker", className: hideLabel ? "sr-only" : undefined, children: label }), _jsx("input", Object.assign({}, props, { id: inputId, type: type, "aria-invalid": error ? true : undefined, "aria-describedby": ids.length > 0 ? ids.join(" ") : undefined, className:
|
|
36
|
+
const styles = inputStyles();
|
|
37
|
+
return (_jsxs("div", { className: styles.root(), children: [_jsx(Label, { htmlFor: inputId, color: "darker", className: hideLabel ? "sr-only" : undefined, children: label }), _jsx("input", Object.assign({}, props, { id: inputId, type: type, "aria-invalid": error ? true : undefined, "aria-describedby": ids.length > 0 ? ids.join(" ") : undefined, className: fieldStyles({ invalid: Boolean(error), className }) })), description && (_jsx("p", { id: descriptionId, className: styles.description(), children: description })), error && (_jsx("p", { id: errorId, className: styles.error(), children: error }))] }));
|
|
45
38
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The look shared by form fields, so `Input` and `Select` stay the same. */
|
|
2
|
+
export declare const fieldStyles: import("tailwind-variants").TVReturnType<{
|
|
3
|
+
invalid: {
|
|
4
|
+
true: "border-danger focus:border-danger focus:ring-danger";
|
|
5
|
+
false: "border-neutral-400 focus:border-primary focus:ring-primary";
|
|
6
|
+
};
|
|
7
|
+
}, undefined, "w-full rounded-sm border bg-surface px-3 py-2 text-sm text-neutral-900 placeholder:text-neutral-500 focus:outline-hidden focus:ring-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed", {
|
|
8
|
+
invalid: {
|
|
9
|
+
true: "border-danger focus:border-danger focus:ring-danger";
|
|
10
|
+
false: "border-neutral-400 focus:border-primary focus:ring-primary";
|
|
11
|
+
};
|
|
12
|
+
}, undefined, import("tailwind-variants").TVReturnTypeLike<{
|
|
13
|
+
invalid: {
|
|
14
|
+
true: "border-danger focus:border-danger focus:ring-danger";
|
|
15
|
+
false: "border-neutral-400 focus:border-primary focus:ring-primary";
|
|
16
|
+
};
|
|
17
|
+
}, undefined>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { tv } from "tailwind-variants";
|
|
2
|
+
/** The look shared by form fields, so `Input` and `Select` stay the same. */
|
|
3
|
+
export const fieldStyles = tv({
|
|
4
|
+
base: "w-full rounded-sm border bg-surface px-3 py-2 text-sm text-neutral-900 placeholder:text-neutral-500 focus:outline-hidden focus:ring-2 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
|
|
5
|
+
variants: {
|
|
6
|
+
invalid: {
|
|
7
|
+
true: "border-danger focus:border-danger focus:ring-danger",
|
|
8
|
+
false: "border-neutral-400 focus:border-primary focus:ring-primary",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
defaultVariants: { invalid: false },
|
|
12
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface PaginationProps {
|
|
3
|
+
/**
|
|
4
|
+
* Current page, from 1 to the last page. The app handles a page outside that range and shows an
|
|
5
|
+
* empty state instead of this component when there are no items.
|
|
6
|
+
*/
|
|
7
|
+
page: number;
|
|
8
|
+
/** Number of items across all pages. */
|
|
9
|
+
totalItems: number;
|
|
10
|
+
/** Items per page. */
|
|
11
|
+
pageSize: number;
|
|
12
|
+
/**
|
|
13
|
+
* URL of the previous page. Without it the link is left out, as on the first page. Plain strings
|
|
14
|
+
* rather than a function, so a Server Component can pass them through a client component.
|
|
15
|
+
*/
|
|
16
|
+
previousHref?: string;
|
|
17
|
+
/** URL of the next page. Without it the link is left out, as on the last page. */
|
|
18
|
+
nextHref?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Component used to render the links. Receives `href`, `className` and `children`, so a
|
|
21
|
+
* framework link (e.g. `next/link`) can be passed directly. Defaults to a plain `<a>`. Define it
|
|
22
|
+
* outside the render function: an inline definition remounts the link.
|
|
23
|
+
*/
|
|
24
|
+
LinkComponent?: React.ElementType<{
|
|
25
|
+
href: string;
|
|
26
|
+
children: React.ReactNode;
|
|
27
|
+
className?: string;
|
|
28
|
+
}>;
|
|
29
|
+
/** Additional classes for custom styling */
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Links to the previous and next page, with the range shown. It needs no JavaScript. */
|
|
33
|
+
export declare const Pagination: React.FC<PaginationProps>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
const paginationStyles = tv({
|
|
4
|
+
slots: {
|
|
5
|
+
base: "flex flex-wrap items-center justify-between gap-3 text-sm text-neutral-600",
|
|
6
|
+
nav: "flex items-center gap-3",
|
|
7
|
+
link: "rounded-sm text-neutral-900 underline underline-offset-2 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
/** Links to the previous and next page, with the range shown. It needs no JavaScript. */
|
|
11
|
+
export const Pagination = ({ page, totalItems, pageSize, previousHref, nextHref, LinkComponent = "a", className, }) => {
|
|
12
|
+
const styles = paginationStyles();
|
|
13
|
+
const first = (page - 1) * pageSize + 1;
|
|
14
|
+
const last = Math.min(page * pageSize, totalItems);
|
|
15
|
+
const totalPages = Math.ceil(totalItems / pageSize);
|
|
16
|
+
return (_jsxs("div", { className: styles.base({ className }), children: [_jsxs("p", { children: [first, "\u2013", last, " of ", totalItems] }), (previousHref || nextHref) && (_jsxs("nav", { "aria-label": "Pagination", className: styles.nav(), children: [previousHref && (_jsxs(LinkComponent, { href: previousHref, className: styles.link(), children: ["Previous", _jsx("span", { className: "sr-only", children: " page" })] })), _jsxs("span", { children: ["Page ", page, " of ", totalPages] }), nextHref && (_jsxs(LinkComponent, { href: nextHref, className: styles.link(), children: ["Next", _jsx("span", { className: "sr-only", children: " page" })] }))] }))] }));
|
|
17
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SelectProps extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, "children" | "multiple" | "size"> {
|
|
7
|
+
/** The field's name, always rendered as a real `<label>`. */
|
|
8
|
+
label: string;
|
|
9
|
+
/** Hides the label visually (`sr-only`) and keeps it for screen readers. */
|
|
10
|
+
hideLabel?: boolean;
|
|
11
|
+
/** The choices, in display order. */
|
|
12
|
+
options: SelectOption[];
|
|
13
|
+
/** Name submitted with a native `<form>`. */
|
|
14
|
+
name?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Current value. Setting it makes the select controlled: pair it with `onChange`. Leave it out
|
|
17
|
+
* for an uncontrolled select (set the initial choice with `defaultValue`), which a native
|
|
18
|
+
* `<form>` can submit without any handler.
|
|
19
|
+
*/
|
|
20
|
+
value?: string;
|
|
21
|
+
/** Initial choice of an uncontrolled select. */
|
|
22
|
+
defaultValue?: string;
|
|
23
|
+
/** Called when the choice changes. Optional, so the select renders from a Server Component. */
|
|
24
|
+
onChange?: (e: React.ChangeEvent<HTMLSelectElement>) => void;
|
|
25
|
+
/** Additional classes for the `<select>` element */
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/** A native `<select>` with its label, styled like `Input`. It needs no JavaScript of its own. */
|
|
29
|
+
export declare const Select: React.FC<SelectProps>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useId } from "react";
|
|
14
|
+
import { tv } from "tailwind-variants";
|
|
15
|
+
import { Label } from "../../Atoms/Label/Label.js";
|
|
16
|
+
import { fieldStyles } from "../Input/fieldStyles.js";
|
|
17
|
+
const selectStyles = tv({ base: "flex flex-col gap-1" });
|
|
18
|
+
/** A native `<select>` with its label, styled like `Input`. It needs no JavaScript of its own. */
|
|
19
|
+
export const Select = (_a) => {
|
|
20
|
+
var { label, hideLabel = false, options, id, className } = _a, props = __rest(_a, ["label", "hideLabel", "options", "id", "className"]);
|
|
21
|
+
const generatedId = useId();
|
|
22
|
+
const selectId = id !== null && id !== void 0 ? id : generatedId;
|
|
23
|
+
return (_jsxs("div", { className: selectStyles(), children: [_jsx(Label, { htmlFor: selectId, color: "darker", className: hideLabel ? "sr-only" : undefined, children: label }), _jsx("select", Object.assign({}, props, { id: selectId, className: fieldStyles({ className }), children: options.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value))) }))] }));
|
|
24
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface TableProps {
|
|
3
|
+
/** Accessible name of the scroll region, for example "Products table". */
|
|
4
|
+
label: string;
|
|
5
|
+
/**
|
|
6
|
+
* The table's name, hidden visually. Say how the rows are ordered and which columns sort, because
|
|
7
|
+
* a screen reader announces `aria-sort` only on the sorted column.
|
|
8
|
+
*/
|
|
9
|
+
caption: string;
|
|
10
|
+
/** `TableHead` and `TableBody`. */
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
/** Additional classes for the `<table>` element */
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface TableSectionProps {
|
|
16
|
+
/** `TableRow` elements. */
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export type TableRowProps = React.HTMLAttributes<HTMLTableRowElement>;
|
|
20
|
+
export interface TableHeaderCellProps extends React.ThHTMLAttributes<HTMLTableCellElement> {
|
|
21
|
+
/** Column name. */
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
/** Where the header link goes. Setting it makes the column sortable. */
|
|
24
|
+
href?: string;
|
|
25
|
+
/** Set on the sorted column only. It sets `aria-sort` and shows the direction. */
|
|
26
|
+
sort?: "ascending" | "descending";
|
|
27
|
+
/** Text alignment. Use `right` for numbers. */
|
|
28
|
+
align?: "left" | "right";
|
|
29
|
+
/**
|
|
30
|
+
* Component used to render the header link. Receives `href`, `className` and `children`, so a
|
|
31
|
+
* framework link (e.g. `next/link`) can be passed directly. Defaults to a plain `<a>`. Define it
|
|
32
|
+
* outside the render function: an inline definition remounts the link.
|
|
33
|
+
*/
|
|
34
|
+
LinkComponent?: React.ElementType<{
|
|
35
|
+
href: string;
|
|
36
|
+
children: React.ReactNode;
|
|
37
|
+
className?: string;
|
|
38
|
+
}>;
|
|
39
|
+
/** Additional classes for custom styling */
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface TableCellProps extends React.TdHTMLAttributes<HTMLTableCellElement> {
|
|
43
|
+
/** Text alignment. `right` also lines digits up, for numbers. */
|
|
44
|
+
align?: "left" | "right";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A data table in a labelled scroll region that the keyboard can reach. Build it from `TableHead`,
|
|
48
|
+
* `TableBody`, `TableRow`, `TableHeaderCell` and `TableCell`. Set a minimum width with `className`
|
|
49
|
+
* when the columns need one: below it the table scrolls.
|
|
50
|
+
*/
|
|
51
|
+
export declare const Table: React.FC<TableProps>;
|
|
52
|
+
/** The header section of a `Table`. */
|
|
53
|
+
export declare const TableHead: React.FC<TableSectionProps>;
|
|
54
|
+
/** The body section of a `Table`. */
|
|
55
|
+
export declare const TableBody: React.FC<TableSectionProps>;
|
|
56
|
+
/** A row of a `Table`. */
|
|
57
|
+
export declare const TableRow: React.FC<TableRowProps>;
|
|
58
|
+
/**
|
|
59
|
+
* A column header. With `href` it is a sort link, which needs no JavaScript: the app works out the
|
|
60
|
+
* URL and passes `sort` on the sorted column.
|
|
61
|
+
*/
|
|
62
|
+
export declare const TableHeaderCell: React.FC<TableHeaderCellProps>;
|
|
63
|
+
/** A data cell of a `Table`. */
|
|
64
|
+
export declare const TableCell: React.FC<TableCellProps>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { tv } from "tailwind-variants";
|
|
14
|
+
import { Icon } from "../../Atoms/Icon/Icon.js";
|
|
15
|
+
const tableStyles = tv({
|
|
16
|
+
slots: {
|
|
17
|
+
region: "overflow-x-auto focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary",
|
|
18
|
+
table: "w-full text-sm",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const headStyles = tv({ base: "border-b border-neutral-200 text-left text-neutral-700" });
|
|
22
|
+
const rowStyles = tv({ base: "h-10 border-b border-neutral-200 last:border-b-0" });
|
|
23
|
+
const headerCellStyles = tv({
|
|
24
|
+
slots: {
|
|
25
|
+
cell: "h-10 whitespace-nowrap bg-neutral-50 px-4 font-medium",
|
|
26
|
+
label: "inline-flex items-center gap-1",
|
|
27
|
+
link: "inline-flex items-center gap-1 rounded-sm hover:text-neutral-900 focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary",
|
|
28
|
+
},
|
|
29
|
+
variants: {
|
|
30
|
+
align: {
|
|
31
|
+
left: { cell: "text-left" },
|
|
32
|
+
right: { cell: "text-right" },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
defaultVariants: { align: "left" },
|
|
36
|
+
});
|
|
37
|
+
const cellStyles = tv({
|
|
38
|
+
base: "whitespace-nowrap px-4 text-neutral-900",
|
|
39
|
+
variants: {
|
|
40
|
+
align: {
|
|
41
|
+
left: "text-left",
|
|
42
|
+
right: "text-right tabular-nums",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
defaultVariants: { align: "left" },
|
|
46
|
+
});
|
|
47
|
+
/** Up and down chevrons: the column can sort but is not sorted now. */
|
|
48
|
+
const SortableIcon = () => (_jsxs("svg", { "aria-hidden": "true", focusable: "false", className: "h-3.5 w-3.5", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("path", { d: "M8 9l4-4 4 4" }), _jsx("path", { d: "M16 15l-4 4-4-4" })] }));
|
|
49
|
+
/**
|
|
50
|
+
* A data table in a labelled scroll region that the keyboard can reach. Build it from `TableHead`,
|
|
51
|
+
* `TableBody`, `TableRow`, `TableHeaderCell` and `TableCell`. Set a minimum width with `className`
|
|
52
|
+
* when the columns need one: below it the table scrolls.
|
|
53
|
+
*/
|
|
54
|
+
export const Table = ({ label, caption, children, className }) => {
|
|
55
|
+
const styles = tableStyles();
|
|
56
|
+
return (_jsx("div", { role: "region", "aria-label": label, tabIndex: 0, className: styles.region(), children: _jsxs("table", { className: styles.table({ className }), children: [_jsx("caption", { className: "sr-only", children: caption }), children] }) }));
|
|
57
|
+
};
|
|
58
|
+
/** The header section of a `Table`. */
|
|
59
|
+
export const TableHead = ({ children }) => (_jsx("thead", { className: headStyles(), children: children }));
|
|
60
|
+
/** The body section of a `Table`. */
|
|
61
|
+
export const TableBody = ({ children }) => _jsx("tbody", { children: children });
|
|
62
|
+
/** A row of a `Table`. */
|
|
63
|
+
export const TableRow = (_a) => {
|
|
64
|
+
var { className } = _a, props = __rest(_a, ["className"]);
|
|
65
|
+
return (_jsx("tr", Object.assign({}, props, { className: rowStyles({ className }) })));
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* A column header. With `href` it is a sort link, which needs no JavaScript: the app works out the
|
|
69
|
+
* URL and passes `sort` on the sorted column.
|
|
70
|
+
*/
|
|
71
|
+
export const TableHeaderCell = (_a) => {
|
|
72
|
+
var { children, href, sort, align, LinkComponent = "a", className, scope = "col" } = _a, props = __rest(_a, ["children", "href", "sort", "align", "LinkComponent", "className", "scope"]);
|
|
73
|
+
const styles = headerCellStyles({ align });
|
|
74
|
+
const sortIcon = sort && (_jsx("span", { className: sort === "ascending" ? "rotate-180" : undefined, children: _jsx(Icon, { name: "ArrowDown", size: "small" }) }));
|
|
75
|
+
return (_jsx("th", Object.assign({}, props, { scope: scope, "aria-sort": sort, className: styles.cell({ className }), children: href ? (_jsxs(LinkComponent, { href: href, className: styles.link(), children: [children, sortIcon !== null && sortIcon !== void 0 ? sortIcon : _jsx(SortableIcon, {})] })) : (_jsxs("span", { className: styles.label(), children: [children, sortIcon] })) })));
|
|
76
|
+
};
|
|
77
|
+
/** A data cell of a `Table`. */
|
|
78
|
+
export const TableCell = (_a) => {
|
|
79
|
+
var { align, className } = _a, props = __rest(_a, ["align", "className"]);
|
|
80
|
+
return (_jsx("td", Object.assign({}, props, { className: cellStyles({ align, className }) })));
|
|
81
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export * from "./components/Atoms/Badge/Badge.js";
|
|
1
2
|
export * from "./components/Atoms/Button/Button.js";
|
|
2
3
|
export * from "./components/Atoms/ButtonLink/ButtonLink.js";
|
|
3
4
|
export * from "./components/Atoms/Card/Card.js";
|
|
4
5
|
export * from "./components/Atoms/Chip/Chip.js";
|
|
5
6
|
export * from "./components/Atoms/ChipLink/ChipLink.js";
|
|
6
7
|
export * from "./components/Atoms/Spinner/Spinner.js";
|
|
8
|
+
export * from "./components/Atoms/TableSkeleton/TableSkeleton.js";
|
|
7
9
|
export * from "./components/Atoms/Text/Text.js";
|
|
8
10
|
export * from "./components/Atoms/Icon/Icon.js";
|
|
9
11
|
export * from "./components/Atoms/Image/Image.js";
|
|
@@ -15,12 +17,16 @@ export * from "./components/Layouts/Grid/Grid.js";
|
|
|
15
17
|
export * from "./components/Molecules/Alert/Alert.js";
|
|
16
18
|
export * from "./components/Molecules/Breadcrumbs/Breadcrumbs.js";
|
|
17
19
|
export * from "./components/Molecules/CartIcon/CartIcon.js";
|
|
20
|
+
export * from "./components/Molecules/EmptyState/EmptyState.js";
|
|
18
21
|
export * from "./components/Molecules/Input/Input.js";
|
|
22
|
+
export * from "./components/Molecules/Pagination/Pagination.js";
|
|
19
23
|
export * from "./components/Molecules/Popover/Popover.js";
|
|
20
24
|
export * from "./components/Molecules/ProductCard/ProductCard.js";
|
|
21
25
|
export * from "./components/Molecules/ProductDetails/ProductDetails.js";
|
|
22
26
|
export * from "./components/Molecules/RadioGroup/RadioGroup.js";
|
|
27
|
+
export * from "./components/Molecules/Select/Select.js";
|
|
23
28
|
export * from "./components/Molecules/SidebarNav/SidebarNav.js";
|
|
29
|
+
export * from "./components/Molecules/Table/Table.js";
|
|
24
30
|
export * from "./components/Organisms/Footer/Footer.js";
|
|
25
31
|
export * from "./components/Organisms/Header/Header.js";
|
|
26
32
|
export * from "./components/Organisms/ProductGrid/ProductGrid.js";
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Atoms
|
|
2
|
+
export * from "./components/Atoms/Badge/Badge.js";
|
|
2
3
|
export * from "./components/Atoms/Button/Button.js";
|
|
3
4
|
export * from "./components/Atoms/ButtonLink/ButtonLink.js";
|
|
4
5
|
export * from "./components/Atoms/Card/Card.js";
|
|
5
6
|
export * from "./components/Atoms/Chip/Chip.js";
|
|
6
7
|
export * from "./components/Atoms/ChipLink/ChipLink.js";
|
|
7
8
|
export * from "./components/Atoms/Spinner/Spinner.js";
|
|
9
|
+
export * from "./components/Atoms/TableSkeleton/TableSkeleton.js";
|
|
8
10
|
export * from "./components/Atoms/Text/Text.js";
|
|
9
11
|
export * from "./components/Atoms/Icon/Icon.js";
|
|
10
12
|
export * from "./components/Atoms/Image/Image.js";
|
|
@@ -18,12 +20,16 @@ export * from "./components/Layouts/Grid/Grid.js";
|
|
|
18
20
|
export * from "./components/Molecules/Alert/Alert.js";
|
|
19
21
|
export * from "./components/Molecules/Breadcrumbs/Breadcrumbs.js";
|
|
20
22
|
export * from "./components/Molecules/CartIcon/CartIcon.js";
|
|
23
|
+
export * from "./components/Molecules/EmptyState/EmptyState.js";
|
|
21
24
|
export * from "./components/Molecules/Input/Input.js";
|
|
25
|
+
export * from "./components/Molecules/Pagination/Pagination.js";
|
|
22
26
|
export * from "./components/Molecules/Popover/Popover.js";
|
|
23
27
|
export * from "./components/Molecules/ProductCard/ProductCard.js";
|
|
24
28
|
export * from "./components/Molecules/ProductDetails/ProductDetails.js";
|
|
25
29
|
export * from "./components/Molecules/RadioGroup/RadioGroup.js";
|
|
30
|
+
export * from "./components/Molecules/Select/Select.js";
|
|
26
31
|
export * from "./components/Molecules/SidebarNav/SidebarNav.js";
|
|
32
|
+
export * from "./components/Molecules/Table/Table.js";
|
|
27
33
|
// Organisms
|
|
28
34
|
export * from "./components/Organisms/Footer/Footer.js";
|
|
29
35
|
export * from "./components/Organisms/Header/Header.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nicolassancho/storybook-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.0",
|
|
4
4
|
"description": "Accessible React + Tailwind component library built with tailwind-variants and documented in Storybook.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|