@nicolassancho/storybook-core 3.1.0 → 3.3.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.
@@ -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
+ };
@@ -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.
@@ -5,8 +5,17 @@ export interface TextProps {
5
5
  * Text color. Every option reaches the 4.5:1 text contrast on white.
6
6
  */
7
7
  color?: "base" | "dark" | "darker" | "primary" | "secondary";
8
- size?: "small" | "medium" | "large";
9
- weight?: "normal" | "bold" | "semibold";
8
+ /**
9
+ * Text size: 14px, 16px and 20px for body copy, 32px for headings and a fluid 36 to 64px for
10
+ * hero text. Each size sets its own line-height, and `display` also tightens the tracking.
11
+ */
12
+ size?: "small" | "medium" | "large" | "heading" | "display";
13
+ /**
14
+ * Font family: `body` is `font-sans`, `display` is `font-display` (the heading font the
15
+ * consumer sets with `--font-display`, the body font when none is set).
16
+ */
17
+ font?: "body" | "display";
18
+ weight?: "normal" | "medium" | "semibold" | "bold";
10
19
  underline?: boolean;
11
20
  children: React.ReactNode;
12
21
  className?: string;
@@ -1,8 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { tv } from "tailwind-variants";
3
3
  const textStyles = tv({
4
- base: "font-sans",
5
4
  variants: {
5
+ font: {
6
+ body: "font-sans",
7
+ display: "font-display",
8
+ },
6
9
  color: {
7
10
  base: "text-neutral-500",
8
11
  dark: "text-neutral-700",
@@ -14,11 +17,14 @@ const textStyles = tv({
14
17
  small: "text-sm",
15
18
  medium: "text-base",
16
19
  large: "text-lg",
20
+ heading: "text-2xl",
21
+ display: "text-4xl",
17
22
  },
18
23
  weight: {
19
24
  normal: "font-normal",
20
- bold: "font-bold",
25
+ medium: "font-medium",
21
26
  semibold: "font-semibold",
27
+ bold: "font-bold",
22
28
  },
23
29
  underline: {
24
30
  true: "underline",
@@ -26,12 +32,13 @@ const textStyles = tv({
26
32
  },
27
33
  },
28
34
  defaultVariants: {
35
+ font: "body",
29
36
  color: "dark",
30
37
  size: "medium",
31
38
  weight: "normal",
32
39
  underline: false,
33
40
  },
34
41
  });
35
- export const Text = ({ as: Component = "div", color = "dark", size = "medium", weight = "normal", underline = false, children, className = "", }) => {
36
- return (_jsx(Component, { className: textStyles({ color, size, weight, underline, className }), children: children }));
42
+ export const Text = ({ as: Component = "div", font = "body", color = "dark", size = "medium", weight = "normal", underline = false, children, className = "", }) => {
43
+ return (_jsx(Component, { className: textStyles({ font, color, size, weight, underline, className }), children: children }));
37
44
  };
@@ -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
  };
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";
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";
@@ -3,14 +3,37 @@
3
3
  `@import "tailwindcss"`. The Colors story reads these values, so it needs no edit when they change.
4
4
  */
5
5
  @theme {
6
- /* Closed type scale: these are the only text sizes that exist. */
6
+ /*
7
+ Closed type scale: these are the only text sizes that exist. Sizes are in rem, so they follow
8
+ the browser's font-size setting, and each size carries its line-height (`text-sm` sets both).
9
+ 4xl is the fluid display size (36px on phones, 64px from about 1200px wide). The names are
10
+ Tailwind's t-shirt sizes on purpose: tailwind-merge reads `text-display` as a color and
11
+ would drop one of `text-display` and `text-neutral-900` when they meet in a tv() call.
12
+ */
7
13
  --text-*: initial;
8
- --text-xs: 12px;
9
- --text-sm: 14px;
10
- --text-base: 16px;
11
- --text-lg: 20px;
12
- --text-xl: 24px;
13
- --text-2xl: 32px;
14
+ --text-xs: 0.75rem;
15
+ --text-xs--line-height: 1rem;
16
+ --text-sm: 0.875rem;
17
+ --text-sm--line-height: 1.25rem;
18
+ --text-base: 1rem;
19
+ --text-base--line-height: 1.5rem;
20
+ --text-lg: 1.25rem;
21
+ --text-lg--line-height: 1.75rem;
22
+ --text-xl: 1.5rem;
23
+ --text-xl--line-height: 2rem;
24
+ --text-2xl: 2rem;
25
+ --text-2xl--line-height: 2.5rem;
26
+ --text-3xl: 2.5rem;
27
+ --text-3xl--line-height: 3rem;
28
+ --text-4xl: clamp(2.25rem, 5.4vw, 4rem);
29
+ --text-4xl--line-height: 1.04;
30
+ --text-4xl--letter-spacing: -0.03em;
31
+
32
+ /*
33
+ Font families. The library loads no fonts: a consumer sets --font-sans (body) and optionally
34
+ --font-display (headings). Without one, headings use the body font.
35
+ */
36
+ --font-display: var(--font-sans);
14
37
 
15
38
  --color-primary-50: light-dark(#f9fbfc, #12191d);
16
39
  --color-primary-100: light-dark(#f1f7fa, #121e23);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicolassancho/storybook-core",
3
- "version": "3.1.0",
3
+ "version": "3.3.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",