@nicolassancho/storybook-core 3.2.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.
- package/dist/components/Atoms/Chip/Chip.d.ts +37 -0
- package/dist/components/Atoms/Chip/Chip.js +40 -0
- package/dist/components/Atoms/RadioButton/RadioButton.d.ts +9 -2
- package/dist/components/Atoms/RadioButton/RadioButton.js +2 -2
- package/dist/components/Atoms/SearchInput/SearchInput.d.ts +8 -2
- package/dist/components/Molecules/RadioGroup/RadioGroup.d.ts +14 -2
- package/dist/components/Molecules/RadioGroup/RadioGroup.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
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
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nicolassancho/storybook-core",
|
|
3
|
-
"version": "3.
|
|
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",
|