@commercetools/nimbus 0.0.1 → 0.0.3-alpha.2
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/index.d.ts +1412 -0
- package/dist/index.js +22451 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +27 -0
- package/dist/index.umd.cjs.map +1 -0
- package/package.json +74 -40
- package/.storybook/apca-check/index.ts +0 -150
- package/.storybook/main.ts +0 -64
- package/.storybook/preview.tsx +0 -92
- package/.storybook/vitest.setup.ts +0 -13
- package/docs/architecture-decisions/adr-0001-consumer-component-apis.md +0 -177
- package/docs/architecture-decisions/adr-0002-compound-component-extraction.md +0 -82
- package/src/components/accordion/accordion-context.tsx +0 -17
- package/src/components/accordion/accordion.mdx +0 -172
- package/src/components/accordion/accordion.recipe.tsx +0 -98
- package/src/components/accordion/accordion.slots.tsx +0 -39
- package/src/components/accordion/accordion.stories.tsx +0 -188
- package/src/components/accordion/accordion.tsx +0 -16
- package/src/components/accordion/accordion.types.tsx +0 -54
- package/src/components/accordion/components/accordion-content.tsx +0 -28
- package/src/components/accordion/components/accordion-group.tsx +0 -27
- package/src/components/accordion/components/accordion-header.tsx +0 -63
- package/src/components/accordion/components/accordion-item.tsx +0 -87
- package/src/components/accordion/index.ts +0 -2
- package/src/components/alert/alert.mdx +0 -92
- package/src/components/alert/alert.recipe.tsx +0 -65
- package/src/components/alert/alert.slots.tsx +0 -46
- package/src/components/alert/alert.stories.tsx +0 -308
- package/src/components/alert/alert.tsx +0 -18
- package/src/components/alert/alert.types.tsx +0 -70
- package/src/components/alert/components/alert.actions.tsx +0 -27
- package/src/components/alert/components/alert.description.tsx +0 -27
- package/src/components/alert/components/alert.dismiss-button.tsx +0 -41
- package/src/components/alert/components/alert.root.tsx +0 -92
- package/src/components/alert/components/alert.title.tsx +0 -29
- package/src/components/alert/index.ts +0 -2
- package/src/components/avatar/avatar.mdx +0 -80
- package/src/components/avatar/avatar.recipe.tsx +0 -36
- package/src/components/avatar/avatar.slots.tsx +0 -16
- package/src/components/avatar/avatar.stories.tsx +0 -136
- package/src/components/avatar/avatar.tsx +0 -34
- package/src/components/avatar/avatar.types.ts +0 -33
- package/src/components/avatar/index.ts +0 -2
- package/src/components/badge/badge.mdx +0 -91
- package/src/components/badge/badge.recipe.tsx +0 -72
- package/src/components/badge/badge.slots.tsx +0 -8
- package/src/components/badge/badge.stories.tsx +0 -124
- package/src/components/badge/badge.tsx +0 -35
- package/src/components/badge/badge.types.tsx +0 -40
- package/src/components/badge/index.ts +0 -2
- package/src/components/bleed/bleed.tsx +0 -1
- package/src/components/bleed/index.ts +0 -1
- package/src/components/box/box.mdx +0 -115
- package/src/components/box/box.stories.tsx +0 -71
- package/src/components/box/box.tsx +0 -11
- package/src/components/box/index.ts +0 -1
- package/src/components/button/button.mdx +0 -169
- package/src/components/button/button.recipe.ts +0 -185
- package/src/components/button/button.slots.tsx +0 -45
- package/src/components/button/button.stories.tsx +0 -369
- package/src/components/button/button.tsx +0 -37
- package/src/components/button/button.types.ts +0 -14
- package/src/components/button/index.ts +0 -2
- package/src/components/card/card.mdx +0 -92
- package/src/components/card/card.recipe.tsx +0 -71
- package/src/components/card/card.slots.tsx +0 -50
- package/src/components/card/card.stories.tsx +0 -175
- package/src/components/card/card.tsx +0 -9
- package/src/components/card/card.types.ts +0 -22
- package/src/components/card/components/card.content.tsx +0 -29
- package/src/components/card/components/card.header.tsx +0 -28
- package/src/components/card/components/card.root.tsx +0 -62
- package/src/components/card/index.ts +0 -2
- package/src/components/checkbox/checkbox.mdx +0 -78
- package/src/components/checkbox/checkbox.recipe.tsx +0 -116
- package/src/components/checkbox/checkbox.slots.tsx +0 -33
- package/src/components/checkbox/checkbox.stories.tsx +0 -200
- package/src/components/checkbox/checkbox.tsx +0 -77
- package/src/components/checkbox/checkbox.types.tsx +0 -22
- package/src/components/checkbox/index.ts +0 -2
- package/src/components/code/code.mdx +0 -17
- package/src/components/code/code.recipe.ts +0 -63
- package/src/components/code/code.tsx +0 -1
- package/src/components/code/index.ts +0 -1
- package/src/components/dialog/dialog.mdx +0 -20
- package/src/components/dialog/dialog.recipe.ts +0 -254
- package/src/components/dialog/dialog.tsx +0 -61
- package/src/components/dialog/index.ts +0 -1
- package/src/components/em/em.mdx +0 -17
- package/src/components/em/em.tsx +0 -1
- package/src/components/em/index.ts +0 -1
- package/src/components/flex/flex.mdx +0 -41
- package/src/components/flex/flex.tsx +0 -1
- package/src/components/flex/index.ts +0 -1
- package/src/components/grid/grid.mdx +0 -156
- package/src/components/grid/grid.stories.tsx +0 -151
- package/src/components/grid/grid.tsx +0 -29
- package/src/components/grid/index.ts +0 -1
- package/src/components/heading/heading.mdx +0 -23
- package/src/components/heading/heading.recipe.ts +0 -49
- package/src/components/heading/heading.tsx +0 -1
- package/src/components/heading/index.ts +0 -1
- package/src/components/highlight/highlight.mdx +0 -18
- package/src/components/highlight/highlight.tsx +0 -1
- package/src/components/highlight/index.ts +0 -1
- package/src/components/icon-button/icon-button.mdx +0 -98
- package/src/components/icon-button/icon-button.stories.tsx +0 -188
- package/src/components/icon-button/icon-button.tsx +0 -21
- package/src/components/icon-button/icon-button.types.tsx +0 -10
- package/src/components/icon-button/index.ts +0 -2
- package/src/components/index.ts +0 -33
- package/src/components/input/index.ts +0 -1
- package/src/components/input/input.mdx +0 -20
- package/src/components/input/input.recipe.ts +0 -95
- package/src/components/input/input.tsx +0 -1
- package/src/components/input-group/index.ts +0 -1
- package/src/components/input-group/input-group.mdx +0 -20
- package/src/components/input-group/input-group.tsx +0 -44
- package/src/components/kbd/index.ts +0 -1
- package/src/components/kbd/kbd.mdx +0 -18
- package/src/components/kbd/kbd.recipe.ts +0 -57
- package/src/components/kbd/kbd.tsx +0 -1
- package/src/components/link/index.ts +0 -2
- package/src/components/link/link.mdx +0 -77
- package/src/components/link/link.recipe.ts +0 -52
- package/src/components/link/link.slots.tsx +0 -29
- package/src/components/link/link.stories.tsx +0 -204
- package/src/components/link/link.tsx +0 -38
- package/src/components/link/link.types.tsx +0 -26
- package/src/components/list/index.ts +0 -1
- package/src/components/list/list.mdx +0 -18
- package/src/components/list/list.recipe.ts +0 -68
- package/src/components/list/list.tsx +0 -9
- package/src/components/loading-spinner/index.ts +0 -2
- package/src/components/loading-spinner/loading-spinner.mdx +0 -92
- package/src/components/loading-spinner/loading-spinner.recipe.tsx +0 -70
- package/src/components/loading-spinner/loading-spinner.slots.tsx +0 -38
- package/src/components/loading-spinner/loading-spinner.stories.tsx +0 -97
- package/src/components/loading-spinner/loading-spinner.tsx +0 -50
- package/src/components/loading-spinner/loading-spinner.types.tsx +0 -21
- package/src/components/nimbus-provider/color-mode.tsx +0 -32
- package/src/components/nimbus-provider/index.ts +0 -2
- package/src/components/nimbus-provider/nimbus-provider.mdx +0 -21
- package/src/components/nimbus-provider/nimbus-provider.tsx +0 -51
- package/src/components/select/components/select.clear-button.tsx +0 -31
- package/src/components/select/components/select.option-group.tsx +0 -48
- package/src/components/select/components/select.option.tsx +0 -21
- package/src/components/select/components/select.options.tsx +0 -23
- package/src/components/select/components/select.root.tsx +0 -81
- package/src/components/select/index.ts +0 -2
- package/src/components/select/select.mdx +0 -170
- package/src/components/select/select.recipe.tsx +0 -216
- package/src/components/select/select.slots.tsx +0 -58
- package/src/components/select/select.stories.tsx +0 -841
- package/src/components/select/select.tsx +0 -18
- package/src/components/select/select.types.tsx +0 -37
- package/src/components/simple-grid/index.ts +0 -1
- package/src/components/simple-grid/simple-grid.mdx +0 -133
- package/src/components/simple-grid/simple-grid.stories.tsx +0 -143
- package/src/components/simple-grid/simple-grid.tsx +0 -31
- package/src/components/stack/index.ts +0 -1
- package/src/components/stack/stack.mdx +0 -88
- package/src/components/stack/stack.stories.tsx +0 -82
- package/src/components/stack/stack.tsx +0 -15
- package/src/components/table/index.ts +0 -1
- package/src/components/table/table.mdx +0 -23
- package/src/components/table/table.recipe.ts +0 -170
- package/src/components/table/table.tsx +0 -43
- package/src/components/text/index.ts +0 -1
- package/src/components/text/text.mdx +0 -244
- package/src/components/text/text.tsx +0 -23
- package/src/components/text-input/index.ts +0 -2
- package/src/components/text-input/text-input.mdx +0 -118
- package/src/components/text-input/text-input.recipe.tsx +0 -68
- package/src/components/text-input/text-input.slots.tsx +0 -24
- package/src/components/text-input/text-input.stories.tsx +0 -282
- package/src/components/text-input/text-input.tsx +0 -39
- package/src/components/text-input/text-input.types.ts +0 -7
- package/src/components/toggle-button-group/components/toggle-button-group.button.tsx +0 -14
- package/src/components/toggle-button-group/components/toggle-button-group.root.tsx +0 -15
- package/src/components/toggle-button-group/index.ts +0 -2
- package/src/components/toggle-button-group/toggle-button-group.mdx +0 -94
- package/src/components/toggle-button-group/toggle-button-group.recipe.tsx +0 -64
- package/src/components/toggle-button-group/toggle-button-group.slots.tsx +0 -26
- package/src/components/toggle-button-group/toggle-button-group.stories.tsx +0 -311
- package/src/components/toggle-button-group/toggle-button-group.tsx +0 -12
- package/src/components/toggle-button-group/toggle-button-group.types.tsx +0 -62
- package/src/components/tooltip/index.ts +0 -4
- package/src/components/tooltip/make-element-focusable.stories.tsx +0 -56
- package/src/components/tooltip/make-element-focusable.tsx +0 -57
- package/src/components/tooltip/tooltip-trigger.stories.tsx +0 -157
- package/src/components/tooltip/tooltip-trigger.tsx +0 -15
- package/src/components/tooltip/tooltip.mdx +0 -48
- package/src/components/tooltip/tooltip.recipe.ts +0 -26
- package/src/components/tooltip/tooltip.slots.ts +0 -35
- package/src/components/tooltip/tooltip.stories.tsx +0 -139
- package/src/components/tooltip/tooltip.tsx +0 -31
- package/src/components/tooltip/tooltip.types.ts +0 -44
- package/src/components/visually-hidden/index.ts +0 -1
- package/src/components/visually-hidden/visually-hidden.mdx +0 -61
- package/src/components/visually-hidden/visually-hidden.stories.tsx +0 -124
- package/src/components/visually-hidden/visually-hidden.tsx +0 -18
- package/src/docs/accessibility.mdx +0 -21
- package/src/docs/background.mdx +0 -154
- package/src/docs/border.mdx +0 -226
- package/src/docs/changelog.mdx +0 -17
- package/src/docs/components-layout.mdx +0 -22
- package/src/docs/components.mdx +0 -17
- package/src/docs/data-display.mdx +0 -23
- package/src/docs/display.mdx +0 -55
- package/src/docs/effects.mdx +0 -73
- package/src/docs/feedback.mdx +0 -22
- package/src/docs/filters.mdx +0 -268
- package/src/docs/flex-and-grid.mdx +0 -445
- package/src/docs/forms.mdx +0 -22
- package/src/docs/generated/index.mdx +0 -16
- package/src/docs/getting-started.mdx +0 -17
- package/src/docs/home.mdx +0 -56
- package/src/docs/hooks.mdx +0 -16
- package/src/docs/inputs.mdx +0 -21
- package/src/docs/installation.mdx +0 -60
- package/src/docs/interactivity.mdx +0 -278
- package/src/docs/known-issues.mdx +0 -19
- package/src/docs/layout.mdx +0 -301
- package/src/docs/list.mdx +0 -82
- package/src/docs/markdown.mdx +0 -234
- package/src/docs/media.mdx +0 -22
- package/src/docs/naivgation.mdx +0 -22
- package/src/docs/playground.mdx +0 -16
- package/src/docs/rfcs-component-structure-rfcs.mdx +0 -17
- package/src/docs/rfcs-component-structure.mdx +0 -74
- package/src/docs/rfcs-hook-structure.mdx +0 -59
- package/src/docs/sizing.mdx +0 -210
- package/src/docs/spacing.mdx +0 -193
- package/src/docs/style-props-typography.mdx +0 -373
- package/src/docs/style-props.mdx +0 -15
- package/src/docs/svg.mdx +0 -58
- package/src/docs/tables.mdx +0 -95
- package/src/docs/toc.mdx +0 -39
- package/src/docs/tokens/animations.mdx +0 -68
- package/src/docs/tokens/aspect-ratios.mdx +0 -21
- package/src/docs/tokens/blurs.mdx +0 -20
- package/src/docs/tokens/borders.mdx +0 -25
- package/src/docs/tokens/breakpoints.mdx +0 -35
- package/src/docs/tokens/colors.mdx +0 -86
- package/src/docs/tokens/cursors.mdx +0 -21
- package/src/docs/tokens/radii.mdx +0 -23
- package/src/docs/tokens/shadows.mdx +0 -21
- package/src/docs/tokens/sizes.mdx +0 -54
- package/src/docs/tokens/spacing.mdx +0 -35
- package/src/docs/tokens/typography.mdx +0 -61
- package/src/docs/tokens/z-indices.mdx +0 -23
- package/src/docs/tokens-other.mdx +0 -17
- package/src/docs/tokens.mdx +0 -16
- package/src/docs/transforms.mdx +0 -150
- package/src/docs/transitions.mdx +0 -164
- package/src/docs/typography.mdx +0 -17
- package/src/docs/utilities.mdx +0 -17
- package/src/hooks/index.ts +0 -2
- package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.mdx +0 -54
- package/src/hooks/use-copy-to-clipboard/use-copy-to-clipboard.ts +0 -1
- package/src/hooks/use-hotkeys/use-hotkeys.mdx +0 -48
- package/src/hooks/use-hotkeys/use-hotkeys.stories.tsx +0 -69
- package/src/hooks/use-hotkeys/use-hotkeys.ts +0 -1
- package/src/index.ts +0 -3
- package/src/test/utils.tsx +0 -20
- package/src/theme/animation-styles.ts +0 -52
- package/src/theme/breakpoints.ts +0 -32
- package/src/theme/global-css.ts +0 -53
- package/src/theme/index.ts +0 -35
- package/src/theme/keyframes.ts +0 -192
- package/src/theme/layer-styles.ts +0 -12
- package/src/theme/recipes/index.ts +0 -21
- package/src/theme/semantic-tokens/colors.ts +0 -55
- package/src/theme/semantic-tokens/index.ts +0 -9
- package/src/theme/semantic-tokens/radii.ts +0 -3
- package/src/theme/semantic-tokens/shadows.ts +0 -4
- package/src/theme/slot-recipes/index.ts +0 -15
- package/src/theme/text-styles.ts +0 -8
- package/src/theme/tokens/animations.ts +0 -4
- package/src/theme/tokens/aspect-ratios.ts +0 -5
- package/src/theme/tokens/blurs.ts +0 -5
- package/src/theme/tokens/borders.ts +0 -4
- package/src/theme/tokens/colors.ts +0 -8
- package/src/theme/tokens/cursor.ts +0 -4
- package/src/theme/tokens/durations.ts +0 -4
- package/src/theme/tokens/easings.ts +0 -4
- package/src/theme/tokens/font-sizes.ts +0 -4
- package/src/theme/tokens/font-weights.ts +0 -4
- package/src/theme/tokens/fonts.ts +0 -4
- package/src/theme/tokens/index.ts +0 -57
- package/src/theme/tokens/letter-spacings.ts +0 -24
- package/src/theme/tokens/line-heights.ts +0 -4
- package/src/theme/tokens/radii.ts +0 -4
- package/src/theme/tokens/sizes.ts +0 -120
- package/src/theme/tokens/spacing.ts +0 -4
- package/src/theme/tokens/z-index.ts +0 -4
- package/src/utils/extractStyleProps.ts +0 -26
- package/src/utils/fixedForwardRef.ts +0 -17
- package/tsconfig.json +0 -38
- package/vite.config.ts +0 -54
- package/vitest.config.ts +0 -50
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import type { Meta, StoryObj } from "@storybook/react";
|
|
3
|
-
import { TextInput } from "./text-input";
|
|
4
|
-
import type { TextInputProps } from "./text-input.types";
|
|
5
|
-
import { userEvent, within, expect, fn } from "@storybook/test";
|
|
6
|
-
import { Box, Stack, Text } from "@/components";
|
|
7
|
-
|
|
8
|
-
const meta: Meta<typeof TextInput> = {
|
|
9
|
-
title: "components/TextInput",
|
|
10
|
-
component: TextInput,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default meta;
|
|
14
|
-
|
|
15
|
-
type Story = StoryObj<typeof TextInput>;
|
|
16
|
-
|
|
17
|
-
const inputVariants: TextInputProps["variant"][] = ["solid", "ghost"];
|
|
18
|
-
const inputSize: TextInputProps["size"][] = ["md", "sm"];
|
|
19
|
-
|
|
20
|
-
export const Base: Story = {
|
|
21
|
-
args: {
|
|
22
|
-
placeholder: "base text input",
|
|
23
|
-
["aria-label"]: "test-input",
|
|
24
|
-
},
|
|
25
|
-
play: async ({ canvasElement, step }) => {
|
|
26
|
-
const canvas = within(canvasElement);
|
|
27
|
-
const input = canvas.getByLabelText("test-input");
|
|
28
|
-
|
|
29
|
-
await step("Uses an <input> element by default", async () => {
|
|
30
|
-
await expect(input.tagName).toBe("INPUT");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
await step("Forwards data- & aria-attributes", async () => {
|
|
34
|
-
await expect(input).toHaveAttribute("aria-label", "test-input");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
await step("Is focusable with <tab> key", async () => {
|
|
38
|
-
await userEvent.tab();
|
|
39
|
-
await expect(input).toHaveFocus();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
await step("Can type text", async () => {
|
|
43
|
-
await userEvent.type(input, "Base text input");
|
|
44
|
-
await expect(input).toHaveValue("Base text input");
|
|
45
|
-
await userEvent.clear(input);
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const Sizes: Story = {
|
|
51
|
-
args: {
|
|
52
|
-
"aria-label": "test-input",
|
|
53
|
-
},
|
|
54
|
-
render: (args) => {
|
|
55
|
-
return (
|
|
56
|
-
<Stack direction="row" gap="400" alignItems="center">
|
|
57
|
-
{inputSize.map((size) => (
|
|
58
|
-
<TextInput
|
|
59
|
-
key={size as string}
|
|
60
|
-
{...args}
|
|
61
|
-
size={size}
|
|
62
|
-
placeholder={size as string}
|
|
63
|
-
/>
|
|
64
|
-
))}
|
|
65
|
-
</Stack>
|
|
66
|
-
);
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const Variants: Story = {
|
|
71
|
-
args: {
|
|
72
|
-
placeholder: "text input",
|
|
73
|
-
["aria-label"]: "test-input",
|
|
74
|
-
},
|
|
75
|
-
render: (args) => {
|
|
76
|
-
return (
|
|
77
|
-
<Stack direction="row" gap="400" alignItems="center">
|
|
78
|
-
{inputVariants.map((variant) => (
|
|
79
|
-
<TextInput
|
|
80
|
-
key={variant as string}
|
|
81
|
-
{...args}
|
|
82
|
-
variant={variant}
|
|
83
|
-
placeholder={variant as string}
|
|
84
|
-
/>
|
|
85
|
-
))}
|
|
86
|
-
</Stack>
|
|
87
|
-
);
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const Disabled: Story = {
|
|
92
|
-
args: {
|
|
93
|
-
isDisabled: true,
|
|
94
|
-
},
|
|
95
|
-
render: (args) => {
|
|
96
|
-
return (
|
|
97
|
-
<Stack direction="row" gap="400" alignItems="center">
|
|
98
|
-
{inputVariants.map((variant) => (
|
|
99
|
-
<TextInput
|
|
100
|
-
key={variant as string}
|
|
101
|
-
{...args}
|
|
102
|
-
variant={variant}
|
|
103
|
-
placeholder={variant as string}
|
|
104
|
-
aria-label={`${variant as string}-disabled`}
|
|
105
|
-
/>
|
|
106
|
-
))}
|
|
107
|
-
</Stack>
|
|
108
|
-
);
|
|
109
|
-
},
|
|
110
|
-
play: async ({ canvasElement, step }) => {
|
|
111
|
-
const canvas = within(canvasElement);
|
|
112
|
-
const input = canvas.getByLabelText("solid-disabled");
|
|
113
|
-
|
|
114
|
-
await step("Has disabled attribute", async () => {
|
|
115
|
-
await expect(input).toBeDisabled();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
await step("Cannot be focused", async () => {
|
|
119
|
-
await userEvent.tab();
|
|
120
|
-
await expect(input).not.toHaveFocus();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
await step("Cannot type text when disabled", async () => {
|
|
124
|
-
await userEvent.type(input, "Test");
|
|
125
|
-
await expect(input).toHaveValue("");
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const Invalid: Story = {
|
|
131
|
-
args: {
|
|
132
|
-
isInvalid: true,
|
|
133
|
-
},
|
|
134
|
-
render: (args) => {
|
|
135
|
-
return (
|
|
136
|
-
<Stack direction="row" gap="400" alignItems="center">
|
|
137
|
-
{inputVariants.map((variant) => (
|
|
138
|
-
<TextInput
|
|
139
|
-
key={variant as string}
|
|
140
|
-
{...args}
|
|
141
|
-
variant={variant}
|
|
142
|
-
placeholder={variant as string}
|
|
143
|
-
aria-label={`${variant as string}-invalid`}
|
|
144
|
-
/>
|
|
145
|
-
))}
|
|
146
|
-
</Stack>
|
|
147
|
-
);
|
|
148
|
-
},
|
|
149
|
-
play: async ({ canvasElement, step }) => {
|
|
150
|
-
const canvas = within(canvasElement);
|
|
151
|
-
const input = canvas.getByLabelText("solid-invalid");
|
|
152
|
-
|
|
153
|
-
await step("Has invalid state", async () => {
|
|
154
|
-
await expect(input).toHaveAttribute("data-invalid", "true");
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
await step("Is still focusable when invalid", async () => {
|
|
158
|
-
await userEvent.tab();
|
|
159
|
-
await expect(input).toHaveFocus();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
await step("Can still type when invalid", async () => {
|
|
163
|
-
await userEvent.type(input, "Test Input");
|
|
164
|
-
await expect(input).toHaveValue("Test Input");
|
|
165
|
-
await userEvent.clear(input);
|
|
166
|
-
});
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export const SmokeTest: Story = {
|
|
171
|
-
args: {
|
|
172
|
-
onChange: fn(),
|
|
173
|
-
["aria-label"]: "test-input",
|
|
174
|
-
},
|
|
175
|
-
render: (args) => {
|
|
176
|
-
const states = [
|
|
177
|
-
{ label: "Default", props: {} },
|
|
178
|
-
{ label: "Disabled", props: { isDisabled: true } },
|
|
179
|
-
{ label: "Invalid", props: { isInvalid: true } },
|
|
180
|
-
{
|
|
181
|
-
label: "Invalid & Disabled",
|
|
182
|
-
props: { isInvalid: true, isDisabled: true },
|
|
183
|
-
},
|
|
184
|
-
];
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
<Stack gap="600">
|
|
188
|
-
{states.map((state) => (
|
|
189
|
-
<Stack key={state.label} direction="column" gap="400">
|
|
190
|
-
{inputSize.map((size) => (
|
|
191
|
-
<Stack
|
|
192
|
-
direction="row"
|
|
193
|
-
key={size as string}
|
|
194
|
-
gap="400"
|
|
195
|
-
alignItems="center"
|
|
196
|
-
>
|
|
197
|
-
{inputVariants.map((variant) => (
|
|
198
|
-
<Box key={variant as string}>
|
|
199
|
-
<TextInput
|
|
200
|
-
{...args}
|
|
201
|
-
{...state.props}
|
|
202
|
-
variant={variant}
|
|
203
|
-
size={size}
|
|
204
|
-
placeholder={`${variant as string} ${size as string} ${state.label}`}
|
|
205
|
-
/>
|
|
206
|
-
</Box>
|
|
207
|
-
))}
|
|
208
|
-
</Stack>
|
|
209
|
-
))}
|
|
210
|
-
</Stack>
|
|
211
|
-
))}
|
|
212
|
-
</Stack>
|
|
213
|
-
);
|
|
214
|
-
},
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export const Controlled: Story = {
|
|
218
|
-
render: () => {
|
|
219
|
-
const [value, setValue] = useState("");
|
|
220
|
-
const onChangeRequest = (e: string) => {
|
|
221
|
-
setValue(e);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
return (
|
|
225
|
-
<Stack gap="400">
|
|
226
|
-
<TextInput
|
|
227
|
-
value={value}
|
|
228
|
-
onChange={onChangeRequest}
|
|
229
|
-
placeholder="Type something..."
|
|
230
|
-
aria-label="controlled-input"
|
|
231
|
-
/>
|
|
232
|
-
<Text data-testid="value-display">Current value: {value}</Text>
|
|
233
|
-
</Stack>
|
|
234
|
-
);
|
|
235
|
-
},
|
|
236
|
-
play: async ({ canvasElement, step }) => {
|
|
237
|
-
const canvas = within(canvasElement);
|
|
238
|
-
const input = canvas.getByLabelText("controlled-input");
|
|
239
|
-
const valueDisplay = canvas.getByTestId("value-display");
|
|
240
|
-
|
|
241
|
-
await step("Updates controlled value", async () => {
|
|
242
|
-
await userEvent.type(input, "Hello");
|
|
243
|
-
await expect(input).toHaveValue("Hello");
|
|
244
|
-
await expect(valueDisplay).toHaveTextContent("Current value: Hello");
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
await step("Clears controlled value", async () => {
|
|
248
|
-
await userEvent.clear(input);
|
|
249
|
-
await expect(input).toHaveValue("");
|
|
250
|
-
await expect(valueDisplay).toHaveTextContent("Current value:");
|
|
251
|
-
});
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
export const InputTypes: Story = {
|
|
256
|
-
args: {
|
|
257
|
-
["aria-label"]: "test-input",
|
|
258
|
-
},
|
|
259
|
-
render: (args) => {
|
|
260
|
-
const inputTypes = [
|
|
261
|
-
"date",
|
|
262
|
-
"datetime-local",
|
|
263
|
-
"email",
|
|
264
|
-
"month",
|
|
265
|
-
"number",
|
|
266
|
-
"password",
|
|
267
|
-
"search",
|
|
268
|
-
"tel",
|
|
269
|
-
"text",
|
|
270
|
-
"time",
|
|
271
|
-
"url",
|
|
272
|
-
"week",
|
|
273
|
-
] as const;
|
|
274
|
-
return (
|
|
275
|
-
<Stack direction="column" gap="400">
|
|
276
|
-
{inputTypes.map((type) => (
|
|
277
|
-
<TextInput key={type} {...args} placeholder={type} type={type} />
|
|
278
|
-
))}
|
|
279
|
-
</Stack>
|
|
280
|
-
);
|
|
281
|
-
},
|
|
282
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useRef } from "react";
|
|
2
|
-
import { TextInputRoot } from "./text-input.slots";
|
|
3
|
-
import type { TextInputProps } from "./text-input.types";
|
|
4
|
-
import { useObjectRef } from "react-aria";
|
|
5
|
-
import { mergeRefs, useRecipe } from "@chakra-ui/react";
|
|
6
|
-
import { textInputRecipe } from "./text-input.recipe";
|
|
7
|
-
import { TextField, Input } from "react-aria-components";
|
|
8
|
-
import { extractStyleProps } from "@/utils/extractStyleProps";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* TextInput
|
|
12
|
-
* ============================================================
|
|
13
|
-
* An input component that takes in a text as input
|
|
14
|
-
*
|
|
15
|
-
* Features:
|
|
16
|
-
*
|
|
17
|
-
* - allows forwarding refs to the underlying DOM element
|
|
18
|
-
* - accepts all native html 'HTMLInputElement' attributes (including aria- & data-attributes)
|
|
19
|
-
* - supports 'variants', 'sizes', etc. configured in the recipe
|
|
20
|
-
* - allows overriding styles by using style-props
|
|
21
|
-
*/
|
|
22
|
-
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
|
|
23
|
-
(props, forwardedRef) => {
|
|
24
|
-
const localRef = useRef<HTMLInputElement>(null);
|
|
25
|
-
const ref = useObjectRef(mergeRefs(localRef, forwardedRef));
|
|
26
|
-
const recipe = useRecipe({ recipe: textInputRecipe });
|
|
27
|
-
const [recipeProps, leftOverProps] = recipe.splitVariantProps(props);
|
|
28
|
-
const [styleProps, textfieldProps] = extractStyleProps(leftOverProps);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<TextField {...textfieldProps}>
|
|
32
|
-
<TextInputRoot ref={ref} {...recipeProps} {...styleProps} asChild>
|
|
33
|
-
<Input />
|
|
34
|
-
</TextInputRoot>
|
|
35
|
-
</TextField>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
TextInput.displayName = "TextInput";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { TextInputRootProps } from "./text-input.slots";
|
|
2
|
-
import type { TextFieldProps } from "react-aria-components";
|
|
3
|
-
|
|
4
|
-
// Helper type to merge props and resolve conflicts
|
|
5
|
-
export interface TextInputProps
|
|
6
|
-
extends TextFieldProps,
|
|
7
|
-
Omit<TextInputRootProps, keyof TextFieldProps | "as" | "asChild"> {}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { forwardRef } from "react";
|
|
2
|
-
import { ToggleButtonGroupButton as ToggleButtonGroupButtonSlot } from "../toggle-button-group.slots";
|
|
3
|
-
import type { ToggleButtonGroupButtonComponent } from "../toggle-button-group.types";
|
|
4
|
-
|
|
5
|
-
export const ToggleButtonGroupButton: ToggleButtonGroupButtonComponent =
|
|
6
|
-
forwardRef(({ children, ...rest }, ref) => {
|
|
7
|
-
return (
|
|
8
|
-
<ToggleButtonGroupButtonSlot {...rest} ref={ref}>
|
|
9
|
-
{children}
|
|
10
|
-
</ToggleButtonGroupButtonSlot>
|
|
11
|
-
);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
ToggleButtonGroupButton.displayName = "ToggleButtonGroup.Button";
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { forwardRef } from "react";
|
|
2
|
-
import { ToggleButtonGroupRoot as ToggleButtonGroupRootSlot } from "../toggle-button-group.slots";
|
|
3
|
-
import type { ToggleButtonGroupRootComponent } from "../toggle-button-group.types";
|
|
4
|
-
|
|
5
|
-
export const ToggleButtonGroupRoot: ToggleButtonGroupRootComponent = forwardRef(
|
|
6
|
-
({ children, ...rest }, ref) => {
|
|
7
|
-
return (
|
|
8
|
-
<ToggleButtonGroupRootSlot ref={ref} {...rest}>
|
|
9
|
-
{children}
|
|
10
|
-
</ToggleButtonGroupRootSlot>
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
ToggleButtonGroupRoot.displayName = "ToggleButtonGroup.Root";
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: Components-ToggleButtonGroup
|
|
3
|
-
title: ToggleButtonGroup
|
|
4
|
-
description:
|
|
5
|
-
To group multiple `Button` or `IconButton` components together, visually and
|
|
6
|
-
logically, representing a set of related actions.
|
|
7
|
-
documentState: InitialDraft
|
|
8
|
-
order: 999
|
|
9
|
-
menu:
|
|
10
|
-
- Components
|
|
11
|
-
- ToggleButtonGroup
|
|
12
|
-
tags:
|
|
13
|
-
- component
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
# ToggleButtonGroup
|
|
17
|
-
|
|
18
|
-
To group multiple `Button` or `IconButton` components together, visually and
|
|
19
|
-
logically, representing a set of related actions.
|
|
20
|
-
|
|
21
|
-
## Basic Usage
|
|
22
|
-
|
|
23
|
-
[Explain the basic usage / usecase of the component].
|
|
24
|
-
|
|
25
|
-
```jsx-live
|
|
26
|
-
const App = () => <ToggleButtonGroup>I am ToggleButtonGroup!</ToggleButtonGroup>
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Sizes
|
|
30
|
-
|
|
31
|
-
Available sizes.
|
|
32
|
-
|
|
33
|
-
```jsx-live
|
|
34
|
-
const App = () => {
|
|
35
|
-
|
|
36
|
-
const sizes = ['2xl', 'xl', 'lg', 'md', 'sm', 'xs', '2xs'];
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<Stack direction="horizontal" alignItems="center">
|
|
40
|
-
{sizes.map(size => (
|
|
41
|
-
<ToggleButtonGroup key={size} size={size}>'{size}' ToggleButtonGroup</ToggleButtonGroup>
|
|
42
|
-
))}
|
|
43
|
-
</Stack>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Variants
|
|
49
|
-
|
|
50
|
-
Available variants.
|
|
51
|
-
|
|
52
|
-
```jsx-live
|
|
53
|
-
const App = () => {
|
|
54
|
-
|
|
55
|
-
const variants = ['solid', 'subtle', 'outline', 'ghost', 'plain'];
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<Stack direction="horizontal">
|
|
59
|
-
{variants.map(variant => (
|
|
60
|
-
<ToggleButtonGroup key={variant} variant={variant}>'{variant}' ToggleButtonGroup</ToggleButtonGroup>
|
|
61
|
-
))}
|
|
62
|
-
</Stack>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Colors
|
|
68
|
-
|
|
69
|
-
[Explain usage with different colors/semantics.]
|
|
70
|
-
|
|
71
|
-
```jsx-live
|
|
72
|
-
const App = () => {
|
|
73
|
-
const variants = ["solid", "subtle", "outline", "ghost", "link", "plain"];
|
|
74
|
-
const colors = ["neutral", "primary", "info", "success", "danger", "error"];
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<Stack>
|
|
78
|
-
{colors.map((color) => (
|
|
79
|
-
<Stack key={color} direction="horizontal">
|
|
80
|
-
{variants.map((variant) => (
|
|
81
|
-
<ToggleButtonGroup colorPalette={color} key={variant} variant={variant}>
|
|
82
|
-
'{variant}' ToggleButtonGroup
|
|
83
|
-
</ToggleButtonGroup>
|
|
84
|
-
))}
|
|
85
|
-
</Stack>
|
|
86
|
-
))}
|
|
87
|
-
</Stack>
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## Props
|
|
93
|
-
|
|
94
|
-
<PropTable id="ToggleButtonGroup" />
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { defineSlotRecipe } from "@chakra-ui/react";
|
|
2
|
-
import { buttonRecipe } from "../button/button.recipe";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Recipe configuration for the ToggleButtonGroup component.
|
|
6
|
-
* Defines the styling variants and base styles using Chakra UI's recipe system.
|
|
7
|
-
*/
|
|
8
|
-
export const buttonGroupRecipe = defineSlotRecipe({
|
|
9
|
-
slots: ["root", "button"],
|
|
10
|
-
// Unique class name prefix for the component
|
|
11
|
-
className: "nimbus-toggle-button-group",
|
|
12
|
-
|
|
13
|
-
// Base styles applied to all instances of the component
|
|
14
|
-
base: {
|
|
15
|
-
root: {
|
|
16
|
-
display: "inline-flex",
|
|
17
|
-
},
|
|
18
|
-
button: {
|
|
19
|
-
// Base style is the same as our Button
|
|
20
|
-
...buttonRecipe.base,
|
|
21
|
-
// Default style is outlined
|
|
22
|
-
...buttonRecipe.variants?.variant.outline,
|
|
23
|
-
// Create overrides for custom ToggleButtonGroup styles
|
|
24
|
-
borderRadius: "0",
|
|
25
|
-
borderRightWidth: "0",
|
|
26
|
-
"&:first-of-type": {
|
|
27
|
-
borderLeftRadius: "200",
|
|
28
|
-
},
|
|
29
|
-
"&:last-of-type": {
|
|
30
|
-
borderRightWidth: "1px",
|
|
31
|
-
borderRightRadius: "200",
|
|
32
|
-
},
|
|
33
|
-
// When selected, the button is styled like a solid button
|
|
34
|
-
"&[data-selected=true]": buttonRecipe.variants?.variant.solid,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
variants: {
|
|
39
|
-
size: {
|
|
40
|
-
xs: {
|
|
41
|
-
button: buttonRecipe.variants?.size.xs,
|
|
42
|
-
},
|
|
43
|
-
md: {
|
|
44
|
-
button: buttonRecipe.variants?.size.md,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
tone: {
|
|
49
|
-
primary: {
|
|
50
|
-
button: { colorPalette: "primary" },
|
|
51
|
-
},
|
|
52
|
-
critical: {
|
|
53
|
-
button: { colorPalette: "error" },
|
|
54
|
-
},
|
|
55
|
-
neutral: {
|
|
56
|
-
button: { colorPalette: "neutral" },
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
defaultVariants: {
|
|
62
|
-
size: "md",
|
|
63
|
-
},
|
|
64
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createSlotRecipeContext } from "@chakra-ui/react";
|
|
2
|
-
import { buttonGroupRecipe } from "./toggle-button-group.recipe";
|
|
3
|
-
import type {
|
|
4
|
-
ToggleButtonGroupButtonProps,
|
|
5
|
-
ToggleButtonGroupProps,
|
|
6
|
-
ToggleButtonGroupButtonComponent,
|
|
7
|
-
} from "./toggle-button-group.types";
|
|
8
|
-
import {
|
|
9
|
-
ToggleButton as RacToggleButton,
|
|
10
|
-
ToggleButtonGroup as RacToggleButtonGroup,
|
|
11
|
-
} from "react-aria-components";
|
|
12
|
-
|
|
13
|
-
const { withContext, withProvider } = createSlotRecipeContext({
|
|
14
|
-
recipe: buttonGroupRecipe,
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export const ToggleButtonGroupRoot = withProvider<
|
|
18
|
-
typeof RacToggleButtonGroup,
|
|
19
|
-
ToggleButtonGroupProps
|
|
20
|
-
>(RacToggleButtonGroup, "root");
|
|
21
|
-
|
|
22
|
-
export const ToggleButtonGroupButton: ToggleButtonGroupButtonComponent =
|
|
23
|
-
withContext<typeof RacToggleButton, ToggleButtonGroupButtonProps>(
|
|
24
|
-
RacToggleButton,
|
|
25
|
-
"button"
|
|
26
|
-
);
|