@nicolassancho/storybook-core 3.2.0 → 3.4.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 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, 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.
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ export interface ChipProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "children" | "className" | "onClick"> {
3
+ children: React.ReactNode;
4
+ /**
5
+ * Whether the chip is the active choice. With `href` it sets `aria-current="true"` on the
6
+ * link; without it sets `aria-pressed` on the button, which turns the button into a toggle.
7
+ * Leave it out for a button that is not a toggle, such as a submit button.
8
+ */
9
+ 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
+ className?: string;
31
+ }
32
+ /**
33
+ * A pill for choosing a filter or category. A link when `href` is set, a button otherwise.
34
+ * Both work without JavaScript: the link navigates, and a `type="submit"` button with a `name`
35
+ * and `value` submits a native form.
36
+ */
37
+ export declare const Chip: React.FC<ChipProps>;
@@ -0,0 +1,40 @@
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 } from "react/jsx-runtime";
13
+ import { tv } from "tailwind-variants";
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
+ });
29
+ /**
30
+ * A pill for choosing a filter or category. A link when `href` is set, a button otherwise.
31
+ * Both work without JavaScript: the link navigates, and a `type="submit"` button with a `name`
32
+ * and `value` submits a native form.
33
+ */
34
+ export const Chip = (_a) => {
35
+ var { children, selected, href, LinkComponent = "a", onClick, className, type = "button", disabled = false } = _a, props = __rest(_a, ["children", "selected", "href", "LinkComponent", "onClick", "className", "type", "disabled"]);
36
+ if (href) {
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 })));
40
+ };
@@ -5,4 +5,6 @@ export declare const IconsMap: {
5
5
  ArrowLeft: import("react-feather").Icon;
6
6
  AlertOctagon: import("react-feather").Icon;
7
7
  AlertTriangle: import("react-feather").Icon;
8
+ Sun: import("react-feather").Icon;
9
+ Moon: import("react-feather").Icon;
8
10
  };
@@ -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
  };
@@ -2,8 +2,15 @@ import React from "react";
2
2
  export interface RadioButtonProps {
3
3
  label: string;
4
4
  value: string | number;
5
- checked: boolean;
6
- onChange: (value: string | number) => void;
5
+ /**
6
+ * Makes the radio controlled. Leave it out for an uncontrolled radio (see `defaultChecked`),
7
+ * which a native form can submit without any handler.
8
+ */
9
+ checked?: boolean;
10
+ /** Initial state of an uncontrolled radio. Ignored when `checked` is set. */
11
+ defaultChecked?: boolean;
12
+ /** Called with the radio's `value` when it is selected. Optional, so it renders on the server. */
13
+ onChange?: (value: string | number) => void;
7
14
  name: string;
8
15
  className?: string;
9
16
  }
@@ -7,7 +7,7 @@ const radioButtonStyles = tv({
7
7
  input: "text-primary",
8
8
  },
9
9
  });
10
- export const RadioButton = ({ label, value, checked, onChange, name, className, }) => {
10
+ export const RadioButton = ({ label, value, checked, defaultChecked, onChange, name, className, }) => {
11
11
  const styles = radioButtonStyles();
12
- return (_jsxs("label", { className: styles.base({ className }), children: [_jsx("input", { type: "radio", name: name, value: value, checked: checked, onChange: () => onChange(value), className: styles.input() }), _jsx(Text, { as: "span", size: "small", color: "dark", children: label })] }));
12
+ return (_jsxs("label", { className: styles.base({ className }), children: [_jsx("input", { type: "radio", name: name, value: value, checked: checked, defaultChecked: checked === undefined ? defaultChecked : undefined, onChange: onChange && (() => onChange(value)), className: styles.input() }), _jsx(Text, { as: "span", size: "small", color: "dark", children: label })] }));
13
13
  };
@@ -1,9 +1,15 @@
1
1
  import React from "react";
2
2
  export interface SearchInputProps extends React.InputHTMLAttributes<HTMLInputElement> {
3
3
  placeholder?: string;
4
- value: string;
4
+ /**
5
+ * Current text. Setting it makes the input controlled: pair it with `onChange`. Leave it out
6
+ * for an uncontrolled input (set the initial text with `defaultValue`), which a native `<form>`
7
+ * can submit without any handler, for example a `GET` search form rendered on the server.
8
+ */
9
+ value?: string;
5
10
  isInvalid?: boolean;
6
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
11
+ /** Called on every change. Optional, so the input renders from a Server Component. */
12
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
7
13
  className?: string;
8
14
  /**
9
15
  * Custom visual size of the input.
@@ -16,8 +16,20 @@ export interface RadioGroupProps {
16
16
  */
17
17
  name?: string;
18
18
  options: RadioGroupOption[];
19
- value: string | number;
20
- onChange: (value: string | number) => void;
19
+ /**
20
+ * Selected option. Setting it makes the group controlled: pair it with `onChange`. Leave it
21
+ * out for an uncontrolled group (see `defaultValue`). Pick one mode and keep it: React warns
22
+ * when a group switches between them.
23
+ */
24
+ value?: string | number;
25
+ /**
26
+ * Initially selected option of an uncontrolled group, which a native `<form>` can submit
27
+ * without any handler (the Server Action receives the option's `value` as a string).
28
+ * Ignored when `value` is set.
29
+ */
30
+ defaultValue?: string | number;
31
+ /** Called with the selected option's value. Optional, so the group renders on the server. */
32
+ onChange?: (value: string | number) => void;
21
33
  columns?: 1 | 2 | 3 | 4 | 6 | 8 | 12;
22
34
  gap?: "none" | "small" | "medium" | "large" | "xl";
23
35
  className?: string;
@@ -3,8 +3,8 @@ import { useId } from "react";
3
3
  import { RadioButton } from "../../Atoms/RadioButton/RadioButton";
4
4
  import { Text } from "../../Atoms/Text/Text";
5
5
  import { Grid } from "../../Layouts/Grid/Grid";
6
- export const RadioGroup = ({ label, name, options, value, onChange, columns = 1, gap = "small", className, }) => {
6
+ export const RadioGroup = ({ label, name, options, value, defaultValue, onChange, columns = 1, gap = "small", className, }) => {
7
7
  const generatedName = useId();
8
8
  const groupName = name !== null && name !== void 0 ? name : generatedName;
9
- return (_jsxs("fieldset", { children: [label && (_jsx("legend", { className: "mb-2 font-medium", children: _jsx(Text, { as: "span", size: "small", children: label }) })), _jsx(Grid, { columns: columns, gap: gap, className: className, children: options.map((option) => (_jsx(RadioButton, { name: groupName, label: option.label, value: option.value, checked: value === option.value, onChange: onChange }, option.value))) })] }));
9
+ return (_jsxs("fieldset", { children: [label && (_jsx("legend", { className: "mb-2 font-medium", children: _jsx(Text, { as: "span", size: "small", children: label }) })), _jsx(Grid, { columns: columns, gap: gap, className: className, children: options.map((option) => (_jsx(RadioButton, { name: groupName, label: option.label, value: option.value, checked: value === undefined ? undefined : value === option.value, defaultChecked: value === undefined ? defaultValue === option.value : undefined, onChange: onChange }, option.value))) })] }));
10
10
  };
@@ -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
+ };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./components/Atoms/Button/Button";
2
+ export * from "./components/Atoms/Chip/Chip";
2
3
  export * from "./components/Atoms/Spinner/Spinner";
3
4
  export * from "./components/Atoms/Text/Text";
4
5
  export * from "./components/Atoms/Icon/Icon";
@@ -12,5 +13,6 @@ export * from "./components/Molecules/CartIcon/CartIcon";
12
13
  export * from "./components/Molecules/ProductCard/ProductCard";
13
14
  export * from "./components/Molecules/ProductDetails/ProductDetails";
14
15
  export * from "./components/Molecules/RadioGroup/RadioGroup";
16
+ export * from "./components/Organisms/Footer/Footer";
15
17
  export * from "./components/Organisms/Header/Header";
16
18
  export * from "./components/Organisms/ProductGrid/ProductGrid";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // Atoms
2
2
  export * from "./components/Atoms/Button/Button";
3
+ export * from "./components/Atoms/Chip/Chip";
3
4
  export * from "./components/Atoms/Spinner/Spinner";
4
5
  export * from "./components/Atoms/Text/Text";
5
6
  export * from "./components/Atoms/Icon/Icon";
@@ -16,5 +17,6 @@ export * from "./components/Molecules/ProductCard/ProductCard";
16
17
  export * from "./components/Molecules/ProductDetails/ProductDetails";
17
18
  export * from "./components/Molecules/RadioGroup/RadioGroup";
18
19
  // Organisms
20
+ export * from "./components/Organisms/Footer/Footer";
19
21
  export * from "./components/Organisms/Header/Header";
20
22
  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.2.0",
3
+ "version": "3.4.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",