@nicolassancho/storybook-core 3.3.0 → 4.0.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 +7 -7
- package/dist/components/Atoms/Chip/Chip.d.ts +6 -27
- package/dist/components/Atoms/Chip/Chip.js +6 -24
- package/dist/components/Atoms/Chip/chipStyles.d.ts +25 -0
- package/dist/components/Atoms/Chip/chipStyles.js +18 -0
- package/dist/components/Atoms/ChipLink/ChipLink.d.ts +25 -0
- package/dist/components/Atoms/ChipLink/ChipLink.js +7 -0
- package/dist/components/Atoms/Icon/iconsMap.d.ts +2 -0
- package/dist/components/Atoms/Icon/iconsMap.js +3 -1
- package/dist/components/Molecules/ProductCard/ProductCard.d.ts +11 -13
- package/dist/components/Molecules/ProductCard/ProductCard.js +2 -10
- package/dist/components/Organisms/Footer/Footer.d.ts +41 -0
- package/dist/components/Organisms/Footer/Footer.js +24 -0
- package/dist/components/Organisms/Header/Header.d.ts +41 -11
- package/dist/components/Organisms/Header/Header.js +17 -20
- package/dist/components/Organisms/ProductGrid/ProductGrid.d.ts +0 -5
- package/dist/components/Organisms/ProductGrid/ProductGrid.js +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +15 -11
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ documented in Storybook. It is published to npm as `@nicolassancho/storybook-cor
|
|
|
31
31
|
|
|
32
32
|
## Components
|
|
33
33
|
|
|
34
|
-
| Layer | Components
|
|
35
|
-
| --------- |
|
|
36
|
-
| Atoms | Button, Icon, Image, Label, RadioButton, SearchInput, Spinner, Text |
|
|
37
|
-
| Molecules | Breadcrumbs, CartIcon, ProductCard, ProductDetails, RadioGroup
|
|
38
|
-
| Organisms | Header, ProductGrid
|
|
39
|
-
| Layouts | Grid
|
|
34
|
+
| Layer | Components |
|
|
35
|
+
| --------- | ----------------------------------------------------------------------------------- |
|
|
36
|
+
| Atoms | Button, Chip, ChipLink, Icon, Image, Label, RadioButton, SearchInput, Spinner, Text |
|
|
37
|
+
| Molecules | Breadcrumbs, CartIcon, ProductCard, ProductDetails, RadioGroup |
|
|
38
|
+
| Organisms | Footer, Header, ProductGrid |
|
|
39
|
+
| Layouts | Grid |
|
|
40
40
|
|
|
41
41
|
The palette and the contrast of each text color are documented under **Foundations / Colors** in
|
|
42
42
|
Storybook.
|
|
@@ -61,7 +61,7 @@ npm install @nicolassancho/storybook-core
|
|
|
61
61
|
|
|
62
62
|
The library ships its design tokens (colors, font sizes, breakpoints), not compiled CSS: your app's
|
|
63
63
|
Tailwind generates the classes, and `@source` is what makes it scan the library. `react`, `react-dom`
|
|
64
|
-
(
|
|
64
|
+
(19), `tailwindcss` (v4), `tailwind-variants` (v3) and `tailwind-merge` (v3) are
|
|
65
65
|
peer dependencies.
|
|
66
66
|
|
|
67
67
|
```tsx
|
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
export interface ChipProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "children" | "className"
|
|
2
|
+
export interface ChipProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "children" | "className"> {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
/**
|
|
5
|
-
* Whether the chip is the active choice.
|
|
6
|
-
*
|
|
7
|
-
* Leave it out for a button that is not a toggle, such as a submit button.
|
|
5
|
+
* Whether the chip is the active choice. It sets `aria-pressed`, which makes the chip a toggle
|
|
6
|
+
* button. Leave it out for a button that is not a toggle, such as a submit button.
|
|
8
7
|
*/
|
|
9
8
|
selected?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Makes the chip a link, for filters that live in the URL (for example `?category=shirts`).
|
|
12
|
-
* It needs no JavaScript. Without `href` the chip is a `<button>`.
|
|
13
|
-
*/
|
|
14
|
-
href?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Component used to render the link when `href` is set. Receives `href`, `onClick`,
|
|
17
|
-
* `className`, `children` and `aria-current`, so a framework link (e.g. `next/link`) can be
|
|
18
|
-
* passed directly. Defaults to a plain `<a>`. Define it outside the render function: an inline
|
|
19
|
-
* definition remounts the link.
|
|
20
|
-
*/
|
|
21
|
-
LinkComponent?: React.ElementType<{
|
|
22
|
-
href: string;
|
|
23
|
-
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
24
|
-
children: React.ReactNode;
|
|
25
|
-
className?: string;
|
|
26
|
-
"aria-current"?: "true";
|
|
27
|
-
}>;
|
|
28
|
-
/** Click handler. Optional: a link or a submit button needs none. */
|
|
29
|
-
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
30
9
|
className?: string;
|
|
31
10
|
}
|
|
32
11
|
/**
|
|
33
|
-
* A pill for choosing a filter or
|
|
34
|
-
*
|
|
35
|
-
*
|
|
12
|
+
* A pill button for choosing a filter or an option. It works without JavaScript inside a native
|
|
13
|
+
* form: a `type="submit"` chip with a `name` and `value` submits that value. For a filter that
|
|
14
|
+
* lives in the URL, use `ChipLink`.
|
|
36
15
|
*/
|
|
37
16
|
export declare const Chip: React.FC<ChipProps>;
|
|
@@ -10,31 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import {
|
|
14
|
-
const chipStyles = tv({
|
|
15
|
-
base: "inline-flex items-center rounded-full border px-4 py-2 text-sm font-medium no-underline transition-colors focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
|
|
16
|
-
variants: {
|
|
17
|
-
selected: {
|
|
18
|
-
true: "border-primary bg-primary text-on-primary hover:bg-primary-darker",
|
|
19
|
-
false: "border-neutral-400 bg-surface text-neutral-900 hover:border-neutral-900",
|
|
20
|
-
},
|
|
21
|
-
disabled: {
|
|
22
|
-
true: "pointer-events-none cursor-not-allowed opacity-50",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
defaultVariants: {
|
|
26
|
-
selected: false,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
13
|
+
import { chipStyles } from "./chipStyles";
|
|
29
14
|
/**
|
|
30
|
-
* A pill for choosing a filter or
|
|
31
|
-
*
|
|
32
|
-
*
|
|
15
|
+
* A pill button for choosing a filter or an option. It works without JavaScript inside a native
|
|
16
|
+
* form: a `type="submit"` chip with a `name` and `value` submits that value. For a filter that
|
|
17
|
+
* lives in the URL, use `ChipLink`.
|
|
33
18
|
*/
|
|
34
19
|
export const Chip = (_a) => {
|
|
35
|
-
var { children, selected,
|
|
36
|
-
|
|
37
|
-
return (_jsx(LinkComponent, { href: href, onClick: onClick, className: chipStyles({ selected: Boolean(selected), className }), "aria-current": selected ? "true" : undefined, children: children }));
|
|
38
|
-
}
|
|
39
|
-
return (_jsx("button", Object.assign({ type: type, onClick: onClick, disabled: disabled, "aria-pressed": selected, className: chipStyles({ selected: Boolean(selected), disabled, className }) }, props, { children: children })));
|
|
20
|
+
var { children, selected, className, type = "button", disabled = false } = _a, props = __rest(_a, ["children", "selected", "className", "type", "disabled"]);
|
|
21
|
+
return (_jsx("button", Object.assign({ type: type, disabled: disabled, "aria-pressed": selected, className: chipStyles({ selected: Boolean(selected), disabled, className }) }, props, { children: children })));
|
|
40
22
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const chipStyles: import("tailwind-variants").TVReturnType<{
|
|
2
|
+
selected: {
|
|
3
|
+
true: "border-primary bg-primary text-on-primary hover:bg-primary-darker";
|
|
4
|
+
false: "border-neutral-400 bg-surface text-neutral-900 hover:border-neutral-900";
|
|
5
|
+
};
|
|
6
|
+
disabled: {
|
|
7
|
+
true: "pointer-events-none cursor-not-allowed opacity-50";
|
|
8
|
+
};
|
|
9
|
+
}, undefined, "inline-flex items-center rounded-full border px-4 py-2 text-sm font-medium no-underline transition-colors focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface", {
|
|
10
|
+
selected: {
|
|
11
|
+
true: "border-primary bg-primary text-on-primary hover:bg-primary-darker";
|
|
12
|
+
false: "border-neutral-400 bg-surface text-neutral-900 hover:border-neutral-900";
|
|
13
|
+
};
|
|
14
|
+
disabled: {
|
|
15
|
+
true: "pointer-events-none cursor-not-allowed opacity-50";
|
|
16
|
+
};
|
|
17
|
+
}, undefined, import("tailwind-variants").TVReturnTypeLike<{
|
|
18
|
+
selected: {
|
|
19
|
+
true: "border-primary bg-primary text-on-primary hover:bg-primary-darker";
|
|
20
|
+
false: "border-neutral-400 bg-surface text-neutral-900 hover:border-neutral-900";
|
|
21
|
+
};
|
|
22
|
+
disabled: {
|
|
23
|
+
true: "pointer-events-none cursor-not-allowed opacity-50";
|
|
24
|
+
};
|
|
25
|
+
}, undefined>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { tv } from "tailwind-variants";
|
|
2
|
+
// Shared by Chip (a button) and ChipLink (a link) so the two look the same. It is not exported
|
|
3
|
+
// from `src/index.js`: it is an implementation detail, not public API.
|
|
4
|
+
export const chipStyles = tv({
|
|
5
|
+
base: "inline-flex items-center rounded-full border px-4 py-2 text-sm font-medium no-underline transition-colors focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
|
|
6
|
+
variants: {
|
|
7
|
+
selected: {
|
|
8
|
+
true: "border-primary bg-primary text-on-primary hover:bg-primary-darker",
|
|
9
|
+
false: "border-neutral-400 bg-surface text-neutral-900 hover:border-neutral-900",
|
|
10
|
+
},
|
|
11
|
+
disabled: {
|
|
12
|
+
true: "pointer-events-none cursor-not-allowed opacity-50",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
defaultVariants: {
|
|
16
|
+
selected: false,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ChipLinkProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
/** Where the chip goes, for example `/products?category=shirts`. It needs no JavaScript. */
|
|
5
|
+
href: string;
|
|
6
|
+
/** Whether the chip is the current choice. It sets `aria-current="true"` on the link. */
|
|
7
|
+
selected?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Component used to render the link. Receives `href`, `className`, `children` and
|
|
10
|
+
* `aria-current`, so a framework link (e.g. `next/link`) can be passed directly. Defaults to a
|
|
11
|
+
* plain `<a>`. Define it outside the render function: an inline definition remounts the link.
|
|
12
|
+
*/
|
|
13
|
+
LinkComponent?: React.ElementType<{
|
|
14
|
+
href: string;
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
"aria-current"?: "true";
|
|
18
|
+
}>;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A pill link for filters that live in the URL, such as a category. Put the chips in a `<nav>` or
|
|
23
|
+
* a list and mark the current one with `selected`. For a toggle or a form control, use `Chip`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const ChipLink: React.FC<ChipLinkProps>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { chipStyles } from "../Chip/chipStyles";
|
|
3
|
+
/**
|
|
4
|
+
* A pill link for filters that live in the URL, such as a category. Put the chips in a `<nav>` or
|
|
5
|
+
* a list and mark the current one with `selected`. For a toggle or a form control, use `Chip`.
|
|
6
|
+
*/
|
|
7
|
+
export const ChipLink = ({ children, href, selected, LinkComponent = "a", className, }) => (_jsx(LinkComponent, { href: href, className: chipStyles({ selected: Boolean(selected), className }), "aria-current": selected ? "true" : undefined, children: children }));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Home, ShoppingCart, ArrowDown, ArrowLeft, AlertOctagon, AlertTriangle,
|
|
1
|
+
import { Home, ShoppingCart, ArrowDown, ArrowLeft, AlertOctagon, AlertTriangle, Sun, Moon,
|
|
2
2
|
// Import other icons as needed
|
|
3
3
|
} from "react-feather";
|
|
4
4
|
export const IconsMap = {
|
|
@@ -8,5 +8,7 @@ export const IconsMap = {
|
|
|
8
8
|
ArrowLeft,
|
|
9
9
|
AlertOctagon,
|
|
10
10
|
AlertTriangle,
|
|
11
|
+
Sun,
|
|
12
|
+
Moon,
|
|
11
13
|
// Add other icons here
|
|
12
14
|
};
|
|
@@ -8,27 +8,19 @@ export interface ProductCardProps {
|
|
|
8
8
|
brand: string;
|
|
9
9
|
price: string;
|
|
10
10
|
tag?: string;
|
|
11
|
-
buttonLabel?: string;
|
|
12
|
-
onClick?: () => void;
|
|
13
|
-
/**
|
|
14
|
-
* Handler for opening the product. Without `href` the title renders as a stretched button.
|
|
15
|
-
* With `href` it is passed to the link as `onClick`.
|
|
16
|
-
*/
|
|
17
|
-
onProductClick?: () => void;
|
|
18
11
|
/**
|
|
19
12
|
* Product URL. The title renders as a real link stretched over the whole card, so
|
|
20
|
-
* middle-click, new tab and crawlable links work.
|
|
13
|
+
* middle-click, new tab and crawlable links work. Without it the card is display-only and the
|
|
14
|
+
* title is plain text.
|
|
21
15
|
*/
|
|
22
16
|
href?: string;
|
|
23
17
|
/**
|
|
24
|
-
* Component used to render the link when `href` is set. Receives `href`, `
|
|
25
|
-
* `
|
|
26
|
-
*
|
|
27
|
-
* definition remounts the link.
|
|
18
|
+
* Component used to render the link when `href` is set. Receives `href`, `className` and
|
|
19
|
+
* `children`, so a framework link (e.g. `next/link`) can be passed directly. Defaults to a
|
|
20
|
+
* plain `<a>`. Define it outside the render function: an inline definition remounts the link.
|
|
28
21
|
*/
|
|
29
22
|
LinkComponent?: React.ElementType<{
|
|
30
23
|
href: string;
|
|
31
|
-
onClick?: () => void;
|
|
32
24
|
children: React.ReactNode;
|
|
33
25
|
className?: string;
|
|
34
26
|
}>;
|
|
@@ -44,6 +36,12 @@ export interface ProductCardProps {
|
|
|
44
36
|
* `height` or `loading`. The image is decorative (`alt=""`): the title already names the card.
|
|
45
37
|
*/
|
|
46
38
|
imageProps?: Omit<ImageProps, "src" | "alt" | "className" | "ImageComponent">;
|
|
39
|
+
/**
|
|
40
|
+
* Controls shown under the product info, such as an add-to-cart `<form>` with a submit
|
|
41
|
+
* `Button`. They sit above the stretched link, so pressing one does its own action and does
|
|
42
|
+
* not open the product, while pressing anywhere else on the card does.
|
|
43
|
+
*/
|
|
44
|
+
actions?: React.ReactNode;
|
|
47
45
|
className?: string;
|
|
48
46
|
}
|
|
49
47
|
export declare const ProductCard: React.FC<ProductCardProps>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { tv } from "tailwind-variants";
|
|
3
|
-
import { Button } from "../../Atoms/Button/Button";
|
|
4
3
|
import { Image } from "../../Atoms/Image/Image";
|
|
5
4
|
import { Text } from "../../Atoms/Text/Text";
|
|
6
5
|
const productCardStyles = tv({
|
|
@@ -18,14 +17,7 @@ const productCardStyles = tv({
|
|
|
18
17
|
action: "relative z-10 mt-2",
|
|
19
18
|
},
|
|
20
19
|
});
|
|
21
|
-
export const ProductCard = ({ imageUrl, title, brand, price, tag,
|
|
20
|
+
export const ProductCard = ({ imageUrl, title, brand, price, tag, href, LinkComponent = "a", ImageComponent, imageProps, actions, className, }) => {
|
|
22
21
|
const styles = productCardStyles();
|
|
23
|
-
|
|
24
|
-
if (href) {
|
|
25
|
-
titleContent = (_jsx(LinkComponent, { href: href, onClick: onProductClick, className: styles.titleAction(), children: title }));
|
|
26
|
-
}
|
|
27
|
-
else if (onProductClick) {
|
|
28
|
-
titleContent = (_jsx("button", { type: "button", onClick: onProductClick, className: styles.titleAction(), children: title }));
|
|
29
|
-
}
|
|
30
|
-
return (_jsx("div", { className: styles.base({ className }), children: _jsxs("div", { className: styles.body(), children: [_jsxs("div", { className: styles.imageWrapper(), children: [_jsx(Image, Object.assign({ src: imageUrl, alt: "", ImageComponent: ImageComponent, className: styles.image() }, imageProps)), tag && _jsx("span", { className: styles.tag(), children: tag })] }), _jsxs("div", { className: styles.productInfo(), children: [_jsx(Text, { as: "h3", size: "small", weight: "semibold", className: styles.title(), children: titleContent }), _jsx(Text, { as: "p", size: "small", color: "base", className: styles.subTitle(), children: brand }), _jsx(Text, { as: "p", size: "small", color: "base", className: styles.price(), children: price })] }), onClick && (_jsx(Button, { variant: "primary", onClick: onClick, className: styles.action(), children: buttonLabel }))] }) }));
|
|
22
|
+
return (_jsx("div", { className: styles.base({ className }), children: _jsxs("div", { className: styles.body(), children: [_jsxs("div", { className: styles.imageWrapper(), children: [_jsx(Image, Object.assign({ src: imageUrl, alt: "", ImageComponent: ImageComponent, className: styles.image() }, imageProps)), tag && _jsx("span", { className: styles.tag(), children: tag })] }), _jsxs("div", { className: styles.productInfo(), children: [_jsx(Text, { as: "h3", size: "small", weight: "semibold", className: styles.title(), children: href ? (_jsx(LinkComponent, { href: href, className: styles.titleAction(), children: title })) : (title) }), _jsx(Text, { as: "p", size: "small", color: "base", className: styles.subTitle(), children: brand }), _jsx(Text, { as: "p", size: "small", color: "base", className: styles.price(), children: price })] }), actions && _jsx("div", { className: styles.action(), children: actions })] }) }));
|
|
31
23
|
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface FooterColumn {
|
|
3
|
+
/** Column heading, rendered as an `<h2>`. */
|
|
4
|
+
title: string;
|
|
5
|
+
links: {
|
|
6
|
+
label: string;
|
|
7
|
+
href: string;
|
|
8
|
+
}[];
|
|
9
|
+
}
|
|
10
|
+
export interface FooterProps {
|
|
11
|
+
/**
|
|
12
|
+
* Groups of links. They all sit inside one `<nav>` landmark (see `navLabel`), each under its
|
|
13
|
+
* own heading. Without columns no navigation is rendered.
|
|
14
|
+
*/
|
|
15
|
+
columns?: FooterColumn[];
|
|
16
|
+
/** Brand block shown before the columns, such as a logo and a short description. */
|
|
17
|
+
brand?: React.ReactNode;
|
|
18
|
+
/** Legal line shown under a divider, such as the copyright. */
|
|
19
|
+
legal?: React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Component used to render each link. Receives `href`, `className` and `children`, so a
|
|
22
|
+
* framework link (e.g. `next/link`) can be passed directly. Defaults to a plain `<a>`.
|
|
23
|
+
* Define it outside the render function: an inline definition remounts the links.
|
|
24
|
+
*/
|
|
25
|
+
LinkComponent?: React.ElementType<{
|
|
26
|
+
href: string;
|
|
27
|
+
children: React.ReactNode;
|
|
28
|
+
className?: string;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Accessible name of the navigation landmark. Change it when the page has another navigation
|
|
32
|
+
* with the same name, or to translate it.
|
|
33
|
+
*/
|
|
34
|
+
navLabel?: string;
|
|
35
|
+
className?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Page footer: a `contentinfo` landmark with an optional brand block, link columns and a legal
|
|
39
|
+
* line. It holds no state, so it renders from a Server Component.
|
|
40
|
+
*/
|
|
41
|
+
export declare const Footer: React.FC<FooterProps>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { tv } from "tailwind-variants";
|
|
3
|
+
import { Text } from "../../Atoms/Text/Text";
|
|
4
|
+
const footerStyles = tv({
|
|
5
|
+
base: "w-full border-t border-neutral-200 bg-surface",
|
|
6
|
+
slots: {
|
|
7
|
+
inner: "flex flex-col gap-8 px-4 py-10",
|
|
8
|
+
top: "flex flex-col gap-8 md:flex-row md:justify-between",
|
|
9
|
+
brand: "md:max-w-xs",
|
|
10
|
+
columns: "flex flex-wrap gap-x-12 gap-y-8",
|
|
11
|
+
list: "mt-3 flex flex-col gap-2",
|
|
12
|
+
link: "rounded-sm text-sm text-neutral-600 underline-offset-4 hover:text-neutral-900 hover:underline focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
|
|
13
|
+
legal: "border-t border-neutral-200 pt-6 text-sm text-neutral-600",
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Page footer: a `contentinfo` landmark with an optional brand block, link columns and a legal
|
|
18
|
+
* line. It holds no state, so it renders from a Server Component.
|
|
19
|
+
*/
|
|
20
|
+
export const Footer = ({ columns = [], brand, legal, LinkComponent = "a", navLabel = "Footer", className, }) => {
|
|
21
|
+
const styles = footerStyles();
|
|
22
|
+
const hasColumns = columns.length > 0;
|
|
23
|
+
return (_jsx("footer", { className: styles.base({ className }), children: _jsxs("div", { className: styles.inner(), children: [(brand || hasColumns) && (_jsxs("div", { className: styles.top(), children: [brand && _jsx("div", { className: styles.brand(), children: brand }), hasColumns && (_jsx("nav", { "aria-label": navLabel, className: styles.columns(), children: columns.map(({ title, links }) => (_jsxs("div", { children: [_jsx(Text, { as: "h2", size: "small", weight: "semibold", color: "darker", children: title }), _jsx("ul", { className: styles.list(), children: links.map(({ label, href }) => (_jsx("li", { children: _jsx(LinkComponent, { href: href, className: styles.link(), children: label }) }, `${label}-${href}`))) })] }, title))) }))] })), legal && _jsx("div", { className: styles.legal(), children: legal })] }) }));
|
|
24
|
+
};
|
|
@@ -1,15 +1,45 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
export interface
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export interface HeaderNavItem {
|
|
3
|
+
label: string;
|
|
4
|
+
href: string;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
7
|
-
|
|
6
|
+
export interface HeaderProps {
|
|
7
|
+
/**
|
|
8
|
+
* Brand shown first, such as a logo or a name. Render it as a link yourself (for example to
|
|
9
|
+
* the home page), so the component never guesses where "home" is.
|
|
10
|
+
*/
|
|
11
|
+
brand: React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Controls shown at the end, such as a search form, a cart link or a theme toggle. They stay
|
|
14
|
+
* together, and drop below the brand when there is no room beside it.
|
|
15
|
+
*/
|
|
16
|
+
actions?: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Links of the main navigation. They sit in one `<nav>` landmark (see `navLabel`): between the
|
|
19
|
+
* brand and the actions from the `md` breakpoint up, and on a row of their own below it.
|
|
20
|
+
* Without items no navigation is rendered.
|
|
21
|
+
*/
|
|
22
|
+
navItems?: HeaderNavItem[];
|
|
23
|
+
/**
|
|
24
|
+
* Accessible name of the navigation landmark. Change it when the page has another navigation
|
|
25
|
+
* with the same name, or to translate it.
|
|
26
|
+
*/
|
|
27
|
+
navLabel?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Component used to render each navigation link. Receives `href`, `className` and `children`,
|
|
30
|
+
* so a framework link (e.g. `next/link`) can be passed directly. Defaults to a plain `<a>`.
|
|
31
|
+
* Define it outside the render function: an inline definition remounts the links.
|
|
32
|
+
*/
|
|
33
|
+
LinkComponent?: React.ElementType<{
|
|
34
|
+
href: string;
|
|
35
|
+
children: React.ReactNode;
|
|
36
|
+
className?: string;
|
|
37
|
+
}>;
|
|
8
38
|
className?: string;
|
|
9
|
-
position: "left" | "center" | "right";
|
|
10
39
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Page header: a `banner` landmark with a brand, an optional main navigation and a group of
|
|
42
|
+
* actions. It grows with its content instead of overflowing on a phone, and it holds no state, so
|
|
43
|
+
* it renders from a Server Component.
|
|
44
|
+
*/
|
|
45
|
+
export declare const Header: React.FC<HeaderProps>;
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { tv } from "tailwind-variants";
|
|
3
3
|
const headerStyles = tv({
|
|
4
|
-
base: "w-full
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
right: "flex-1 justify-end",
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
defaultVariants: {
|
|
16
|
-
position: "left",
|
|
4
|
+
base: "w-full bg-surface shadow-sm",
|
|
5
|
+
slots: {
|
|
6
|
+
inner: "flex min-h-16 flex-wrap items-center gap-x-6 gap-y-2 px-4 py-3",
|
|
7
|
+
brand: "order-1",
|
|
8
|
+
actions: "order-2 ml-auto flex items-center gap-2 md:order-3",
|
|
9
|
+
nav: "order-3 w-full md:order-2 md:w-auto md:flex-1",
|
|
10
|
+
list: "flex flex-wrap items-center gap-x-4 gap-y-1",
|
|
11
|
+
link: "rounded-sm text-sm text-neutral-600 underline-offset-4 hover:text-neutral-900 hover:underline focus:outline-hidden focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-surface",
|
|
17
12
|
},
|
|
18
13
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Page header: a `banner` landmark with a brand, an optional main navigation and a group of
|
|
16
|
+
* actions. It grows with its content instead of overflowing on a phone, and it holds no state, so
|
|
17
|
+
* it renders from a Server Component.
|
|
18
|
+
*/
|
|
19
|
+
export const Header = ({ brand, actions, navItems = [], navLabel = "Main", LinkComponent = "a", className, }) => {
|
|
20
|
+
const styles = headerStyles();
|
|
21
|
+
return (_jsx("header", { className: styles.base({ className }), children: _jsxs("div", { className: styles.inner(), children: [_jsx("div", { className: styles.brand(), children: brand }), actions && _jsx("div", { className: styles.actions(), children: actions }), navItems.length > 0 && (_jsx("nav", { "aria-label": navLabel, className: styles.nav(), children: _jsx("ul", { className: styles.list(), children: navItems.map(({ label, href }) => (_jsx("li", { children: _jsx(LinkComponent, { href: href, className: styles.link(), children: label }) }, `${label}-${href}`))) }) }))] }) }));
|
|
22
22
|
};
|
|
23
|
-
Header.Left = ({ children, className }) => (_jsx(Slot, { position: "left", className: className, children: children }));
|
|
24
|
-
Header.Center = ({ children, className }) => (_jsx(Slot, { position: "center", className: className, children: children }));
|
|
25
|
-
Header.Right = ({ children, className }) => (_jsx(Slot, { position: "right", className: className, children: children }));
|
|
@@ -15,10 +15,5 @@ export interface ProductGridProps {
|
|
|
15
15
|
* `ImageComponent`. See `ProductCard`.
|
|
16
16
|
*/
|
|
17
17
|
ImageComponent?: ProductCardProps["ImageComponent"];
|
|
18
|
-
/**
|
|
19
|
-
* Returns the click handler for a product, called with the product and its index. It is
|
|
20
|
-
* the fallback: a product that sets its own `onProductClick` keeps it. See `ProductCard`.
|
|
21
|
-
*/
|
|
22
|
-
getOnProductClick?: (product: ProductCardProps, index: number) => () => void;
|
|
23
18
|
}
|
|
24
19
|
export declare const ProductGrid: React.FC<ProductGridProps>;
|
|
@@ -5,9 +5,9 @@ import { ProductCard } from "../../Molecules/ProductCard/ProductCard";
|
|
|
5
5
|
const productGridStyles = tv({
|
|
6
6
|
base: "xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4",
|
|
7
7
|
});
|
|
8
|
-
export const ProductGrid = ({ products, columns = 3, gap = "medium", className, LinkComponent, ImageComponent,
|
|
9
|
-
return (_jsx(Grid, { columns: columns, gap: gap, className: productGridStyles({ className }), children: products.map((product
|
|
10
|
-
var _a
|
|
11
|
-
return (_jsx(ProductCard, Object.assign({ LinkComponent: LinkComponent, ImageComponent: ImageComponent }, product,
|
|
8
|
+
export const ProductGrid = ({ products, columns = 3, gap = "medium", className, LinkComponent, ImageComponent, }) => {
|
|
9
|
+
return (_jsx(Grid, { columns: columns, gap: gap, className: productGridStyles({ className }), children: products.map((product) => {
|
|
10
|
+
var _a;
|
|
11
|
+
return (_jsx(ProductCard, Object.assign({ LinkComponent: LinkComponent, ImageComponent: ImageComponent }, product), (_a = product.id) !== null && _a !== void 0 ? _a : product.title));
|
|
12
12
|
}) }));
|
|
13
13
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./components/Atoms/Button/Button";
|
|
2
2
|
export * from "./components/Atoms/Chip/Chip";
|
|
3
|
+
export * from "./components/Atoms/ChipLink/ChipLink";
|
|
3
4
|
export * from "./components/Atoms/Spinner/Spinner";
|
|
4
5
|
export * from "./components/Atoms/Text/Text";
|
|
5
6
|
export * from "./components/Atoms/Icon/Icon";
|
|
@@ -13,5 +14,6 @@ export * from "./components/Molecules/CartIcon/CartIcon";
|
|
|
13
14
|
export * from "./components/Molecules/ProductCard/ProductCard";
|
|
14
15
|
export * from "./components/Molecules/ProductDetails/ProductDetails";
|
|
15
16
|
export * from "./components/Molecules/RadioGroup/RadioGroup";
|
|
17
|
+
export * from "./components/Organisms/Footer/Footer";
|
|
16
18
|
export * from "./components/Organisms/Header/Header";
|
|
17
19
|
export * from "./components/Organisms/ProductGrid/ProductGrid";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Atoms
|
|
2
2
|
export * from "./components/Atoms/Button/Button";
|
|
3
3
|
export * from "./components/Atoms/Chip/Chip";
|
|
4
|
+
export * from "./components/Atoms/ChipLink/ChipLink";
|
|
4
5
|
export * from "./components/Atoms/Spinner/Spinner";
|
|
5
6
|
export * from "./components/Atoms/Text/Text";
|
|
6
7
|
export * from "./components/Atoms/Icon/Icon";
|
|
@@ -17,5 +18,6 @@ export * from "./components/Molecules/ProductCard/ProductCard";
|
|
|
17
18
|
export * from "./components/Molecules/ProductDetails/ProductDetails";
|
|
18
19
|
export * from "./components/Molecules/RadioGroup/RadioGroup";
|
|
19
20
|
// Organisms
|
|
21
|
+
export * from "./components/Organisms/Footer/Footer";
|
|
20
22
|
export * from "./components/Organisms/Header/Header";
|
|
21
23
|
export * from "./components/Organisms/ProductGrid/ProductGrid";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nicolassancho/storybook-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.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",
|
|
@@ -53,13 +53,15 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@eslint/js": "^9.39.5",
|
|
56
|
-
"@storybook/addon-a11y": "^10.6.
|
|
57
|
-
"@storybook/addon-docs": "^10.6.
|
|
58
|
-
"@storybook/addon-links": "^10.6.
|
|
59
|
-
"@storybook/addon-vitest": "^10.6.
|
|
60
|
-
"@storybook/react": "^10.6.
|
|
61
|
-
"@storybook/react-vite": "^10.6.
|
|
56
|
+
"@storybook/addon-a11y": "^10.6.2",
|
|
57
|
+
"@storybook/addon-docs": "^10.6.2",
|
|
58
|
+
"@storybook/addon-links": "^10.6.2",
|
|
59
|
+
"@storybook/addon-vitest": "^10.6.2",
|
|
60
|
+
"@storybook/react": "^10.6.2",
|
|
61
|
+
"@storybook/react-vite": "^10.6.2",
|
|
62
62
|
"@tailwindcss/postcss": "^4.3.3",
|
|
63
|
+
"@types/react": "^19",
|
|
64
|
+
"@types/react-dom": "^19",
|
|
63
65
|
"@typescript-eslint/eslint-plugin": "^8.71.1",
|
|
64
66
|
"@typescript-eslint/parser": "^8.71.1",
|
|
65
67
|
"@vitest/browser-playwright": "^5.0.3",
|
|
@@ -67,11 +69,13 @@
|
|
|
67
69
|
"eslint-config-prettier": "^10.1.8",
|
|
68
70
|
"eslint-plugin-react": "^7.37.5",
|
|
69
71
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
70
|
-
"eslint-plugin-storybook": "^10.6.
|
|
72
|
+
"eslint-plugin-storybook": "^10.6.2",
|
|
71
73
|
"playwright": "^1.64.0",
|
|
72
74
|
"postcss": "^8.4.41",
|
|
73
75
|
"prettier": "^3.9.10",
|
|
74
|
-
"
|
|
76
|
+
"react": "^19.3.0",
|
|
77
|
+
"react-dom": "^19.3.0",
|
|
78
|
+
"storybook": "^10.6.2",
|
|
75
79
|
"tailwind-merge": "^3.7.0",
|
|
76
80
|
"tailwind-variants": "^3.3.1",
|
|
77
81
|
"tailwindcss": "^4.3.3",
|
|
@@ -82,8 +86,8 @@
|
|
|
82
86
|
"react-feather": "^2.0.10"
|
|
83
87
|
},
|
|
84
88
|
"peerDependencies": {
|
|
85
|
-
"react": "
|
|
86
|
-
"react-dom": "
|
|
89
|
+
"react": "^19.0.0",
|
|
90
|
+
"react-dom": "^19.0.0",
|
|
87
91
|
"tailwind-merge": "^3.7.0",
|
|
88
92
|
"tailwind-variants": "^3.3.1",
|
|
89
93
|
"tailwindcss": "^4.3.3"
|