@windstream/react-shared-components 0.0.1
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/LICENSE +21 -0
- package/README.md +360 -0
- package/dist/core.d.ts +389 -0
- package/dist/index.d.ts +389 -0
- package/dist/index.esm.js +35 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +3 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.esm.js +2 -0
- package/dist/utils/index.esm.js.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +151 -0
- package/src/components/accordion/Accordion.stories.tsx +225 -0
- package/src/components/accordion/index.tsx +36 -0
- package/src/components/accordion/types.ts +10 -0
- package/src/components/alert-card/AlertCard.stories.tsx +172 -0
- package/src/components/alert-card/index.tsx +35 -0
- package/src/components/alert-card/types.ts +9 -0
- package/src/components/brand-button/BrandButton.stories.tsx +221 -0
- package/src/components/brand-button/helpers.ts +35 -0
- package/src/components/brand-button/index.tsx +90 -0
- package/src/components/brand-button/types.ts +27 -0
- package/src/components/button/Button.stories.tsx +108 -0
- package/src/components/button/index.tsx +23 -0
- package/src/components/button/types.ts +14 -0
- package/src/components/call-button/CallButton.stories.tsx +324 -0
- package/src/components/call-button/index.tsx +80 -0
- package/src/components/call-button/types.ts +9 -0
- package/src/components/checkbox/Checkbox.stories.tsx +248 -0
- package/src/components/checkbox/index.tsx +185 -0
- package/src/components/checkbox/types.ts +24 -0
- package/src/components/checklist/Checklist.stories.tsx +151 -0
- package/src/components/checklist/index.tsx +33 -0
- package/src/components/checklist/types.ts +6 -0
- package/src/components/collapse/Collapse.stories.tsx +256 -0
- package/src/components/collapse/index.tsx +44 -0
- package/src/components/collapse/types.ts +6 -0
- package/src/components/divider/Divider.stories.tsx +206 -0
- package/src/components/divider/index.tsx +23 -0
- package/src/components/divider/type.ts +3 -0
- package/src/components/input/Input.stories.tsx +358 -0
- package/src/components/input/index.tsx +174 -0
- package/src/components/input/types.ts +37 -0
- package/src/components/link/Link.stories.tsx +163 -0
- package/src/components/link/index.tsx +96 -0
- package/src/components/link/types.ts +25 -0
- package/src/components/list/List.stories.tsx +272 -0
- package/src/components/list/index.tsx +86 -0
- package/src/components/list/list-item/index.tsx +36 -0
- package/src/components/list/list-item/types.ts +13 -0
- package/src/components/list/types.ts +29 -0
- package/src/components/material-icon/MaterialIcon.stories.tsx +330 -0
- package/src/components/material-icon/constants.ts +95 -0
- package/src/components/material-icon/index.tsx +44 -0
- package/src/components/material-icon/types.ts +31 -0
- package/src/components/modal/Modal.stories.tsx +171 -0
- package/src/components/modal/index.tsx +168 -0
- package/src/components/modal/types.ts +24 -0
- package/src/components/radio-button/RadioButton.stories.tsx +307 -0
- package/src/components/radio-button/index.tsx +73 -0
- package/src/components/radio-button/types.ts +22 -0
- package/src/components/see-more/SeeMore.stories.tsx +182 -0
- package/src/components/see-more/index.tsx +38 -0
- package/src/components/see-more/types.ts +4 -0
- package/src/components/select/Select.stories.tsx +410 -0
- package/src/components/select/index.tsx +150 -0
- package/src/components/select/types.ts +34 -0
- package/src/components/select-plan-button/SelectPlanButton.stories.tsx +160 -0
- package/src/components/select-plan-button/index.tsx +21 -0
- package/src/components/select-plan-button/types.ts +4 -0
- package/src/components/skeleton/Skeleton.stories.tsx +180 -0
- package/src/components/skeleton/index.tsx +61 -0
- package/src/components/skeleton/types.ts +4 -0
- package/src/components/spinner/Spinner.stories.tsx +335 -0
- package/src/components/spinner/index.tsx +44 -0
- package/src/components/spinner/types.ts +5 -0
- package/src/components/text/Text.stories.tsx +302 -0
- package/src/components/text/index.tsx +26 -0
- package/src/components/text/types.ts +45 -0
- package/src/components/tooltip/Tooltip.stories.tsx +220 -0
- package/src/components/tooltip/index.tsx +78 -0
- package/src/components/tooltip/types.ts +7 -0
- package/src/components/view-cart-button/ViewCartButton.stories.tsx +241 -0
- package/src/components/view-cart-button/index.tsx +39 -0
- package/src/components/view-cart-button/types.ts +5 -0
- package/src/hooks/use-body-scroll-lock.ts +31 -0
- package/src/index.ts +81 -0
- package/src/setupTests.ts +46 -0
- package/src/stories/DocsTemplate.tsx +26 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +1 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +1 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +1 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +1 -0
- package/src/stories/assets/youtube.svg +1 -0
- package/src/styles/globals.css +50 -0
- package/src/types/global.d.ts +9 -0
- package/src/utils/index.ts +49 -0
- package/tailwind.config.cjs +524 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { AlertCard } from "./index";
|
|
2
|
+
import { DocsPage } from "@shared/stories/DocsTemplate";
|
|
3
|
+
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof AlertCard> = {
|
|
7
|
+
title: "Components/AlertCard",
|
|
8
|
+
component: AlertCard,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: "centered",
|
|
12
|
+
docs: {
|
|
13
|
+
page: DocsPage,
|
|
14
|
+
description: {
|
|
15
|
+
component:
|
|
16
|
+
"An alert card component for displaying error messages and critical information with an icon and responsive layout.",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
argTypes: {
|
|
21
|
+
errorMessage: {
|
|
22
|
+
control: { type: "text" },
|
|
23
|
+
description: "Error message or content to display",
|
|
24
|
+
},
|
|
25
|
+
className: {
|
|
26
|
+
control: { type: "text" },
|
|
27
|
+
description: "Additional CSS classes",
|
|
28
|
+
},
|
|
29
|
+
textVariant: {
|
|
30
|
+
control: { type: "text" },
|
|
31
|
+
description: "Text variant class name",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
errorMessage: "This is an error message that needs your attention.",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default meta;
|
|
40
|
+
type Story = StoryObj<typeof meta>;
|
|
41
|
+
|
|
42
|
+
// Default alert card
|
|
43
|
+
export const Default: Story = {
|
|
44
|
+
args: {},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Short error message
|
|
48
|
+
export const ShortMessage: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
errorMessage: "Error occurred",
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Long error message
|
|
55
|
+
export const LongMessage: Story = {
|
|
56
|
+
args: {
|
|
57
|
+
errorMessage:
|
|
58
|
+
"This is a longer error message that demonstrates how the alert card handles extended text content. The layout will adapt responsively to accommodate the message length.",
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Custom text variant
|
|
63
|
+
export const CustomTextVariant: Story = {
|
|
64
|
+
args: {
|
|
65
|
+
errorMessage: "Error with custom text styling",
|
|
66
|
+
textVariant: "body1",
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// With React node content
|
|
71
|
+
export const WithReactNode: Story = {
|
|
72
|
+
args: {
|
|
73
|
+
errorMessage: (
|
|
74
|
+
<div>
|
|
75
|
+
<p className="body2">Error occurred while processing your request.</p>
|
|
76
|
+
<p className="body3 mt-1 text-text-secondary">
|
|
77
|
+
Please try again or contact support if the issue persists.
|
|
78
|
+
</p>
|
|
79
|
+
</div>
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Responsive layout
|
|
85
|
+
export const Responsive: Story = {
|
|
86
|
+
render: () => (
|
|
87
|
+
<div className="w-full max-w-4xl space-y-4">
|
|
88
|
+
<div>
|
|
89
|
+
<h3 className="mb-2 text-sm font-medium text-gray-600">
|
|
90
|
+
Mobile Layout (flex-col)
|
|
91
|
+
</h3>
|
|
92
|
+
<div className="w-64 border border-gray-200 p-2">
|
|
93
|
+
<AlertCard errorMessage="This alert card stacks vertically on mobile devices with the icon on top." />
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
<div>
|
|
97
|
+
<h3 className="mb-2 text-sm font-medium text-gray-600">
|
|
98
|
+
Desktop Layout (flex-row)
|
|
99
|
+
</h3>
|
|
100
|
+
<div className="w-full border border-gray-200 p-2">
|
|
101
|
+
<AlertCard errorMessage="This alert card displays horizontally on desktop with the icon on the left." />
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
),
|
|
106
|
+
parameters: {
|
|
107
|
+
docs: {
|
|
108
|
+
description: {
|
|
109
|
+
story:
|
|
110
|
+
"Alert card adapts its layout responsively - vertical on mobile, horizontal on desktop.",
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Custom styling
|
|
117
|
+
export const CustomStyling: Story = {
|
|
118
|
+
args: {
|
|
119
|
+
errorMessage: "Alert card with custom styling",
|
|
120
|
+
className: "rounded-lg shadow-lg",
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Multiple alert cards
|
|
125
|
+
export const Multiple: Story = {
|
|
126
|
+
render: () => (
|
|
127
|
+
<div className="w-full max-w-2xl space-y-4">
|
|
128
|
+
<AlertCard errorMessage="First error message" />
|
|
129
|
+
<AlertCard errorMessage="Second error message with more details about what went wrong" />
|
|
130
|
+
<AlertCard errorMessage="Third error message" />
|
|
131
|
+
</div>
|
|
132
|
+
),
|
|
133
|
+
parameters: {
|
|
134
|
+
docs: {
|
|
135
|
+
description: {
|
|
136
|
+
story: "Multiple alert cards displayed together.",
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// All variants showcase
|
|
143
|
+
export const AllVariants: Story = {
|
|
144
|
+
render: () => (
|
|
145
|
+
<div className="w-full max-w-2xl space-y-6">
|
|
146
|
+
<div>
|
|
147
|
+
<h3 className="mb-3 text-lg font-semibold">Default Alert Card</h3>
|
|
148
|
+
<AlertCard errorMessage="Default error message" />
|
|
149
|
+
</div>
|
|
150
|
+
<div>
|
|
151
|
+
<h3 className="mb-3 text-lg font-semibold">Long Message</h3>
|
|
152
|
+
<AlertCard errorMessage="This is a longer error message that demonstrates how the alert card handles extended text content while maintaining proper spacing and readability." />
|
|
153
|
+
</div>
|
|
154
|
+
<div>
|
|
155
|
+
<h3 className="mb-3 text-lg font-semibold">Custom Styled</h3>
|
|
156
|
+
<AlertCard
|
|
157
|
+
errorMessage="Custom styled alert card"
|
|
158
|
+
className="rounded-lg"
|
|
159
|
+
textVariant="body1"
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
),
|
|
164
|
+
parameters: {
|
|
165
|
+
docs: {
|
|
166
|
+
description: {
|
|
167
|
+
story: "Showcase of all alert card variants and states.",
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { AlertCardProps } from "./types";
|
|
4
|
+
import { cx } from "@shared/utils";
|
|
5
|
+
import { Text } from "@shared/components/text";
|
|
6
|
+
import { MaterialIcon } from "@shared/components/material-icon";
|
|
7
|
+
|
|
8
|
+
export const AlertCard: React.FC<AlertCardProps> = ({
|
|
9
|
+
errorMessage,
|
|
10
|
+
className,
|
|
11
|
+
textVariant,
|
|
12
|
+
}) => {
|
|
13
|
+
|
|
14
|
+
if (!errorMessage) return null;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
className={cx(
|
|
19
|
+
"bg-bg-fill-critical-secondary border-border-critical-secondary flex flex-col md:flex-row items-center gap-5 justify-center rounded-none border-2 px-4 py-6 md:py-4",
|
|
20
|
+
className
|
|
21
|
+
)}
|
|
22
|
+
data-testid="alert-card"
|
|
23
|
+
>
|
|
24
|
+
<MaterialIcon name="dangerous" size={52} className="text-icon-critical" />
|
|
25
|
+
|
|
26
|
+
<Text className={cx("body2 text-text", textVariant)}>
|
|
27
|
+
{errorMessage}
|
|
28
|
+
</Text>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
AlertCard.displayName = "AlertCard";
|
|
34
|
+
|
|
35
|
+
export type { AlertCardProps };
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { BrandButton } from "./index";
|
|
2
|
+
import { DocsPage } from "@shared/stories/DocsTemplate";
|
|
3
|
+
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof BrandButton> = {
|
|
7
|
+
title: "Components/BrandButton",
|
|
8
|
+
component: BrandButton,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: "centered",
|
|
12
|
+
docs: {
|
|
13
|
+
page: DocsPage,
|
|
14
|
+
description: {
|
|
15
|
+
component:
|
|
16
|
+
"A branded button component with predefined variants, responsive sizing, and loading states. Designed for consistent brand styling across the application.",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
argTypes: {
|
|
21
|
+
variant: {
|
|
22
|
+
control: { type: "select" },
|
|
23
|
+
options: ["primary_brand", "primary_inverse", "secondary"],
|
|
24
|
+
description: "Button styling variant",
|
|
25
|
+
},
|
|
26
|
+
isLoading: {
|
|
27
|
+
control: { type: "boolean" },
|
|
28
|
+
description: "Show loading spinner",
|
|
29
|
+
},
|
|
30
|
+
disabled: {
|
|
31
|
+
control: { type: "boolean" },
|
|
32
|
+
description: "Disable the button",
|
|
33
|
+
},
|
|
34
|
+
text: {
|
|
35
|
+
control: { type: "text" },
|
|
36
|
+
description: "Button text content",
|
|
37
|
+
},
|
|
38
|
+
label: {
|
|
39
|
+
control: { type: "text" },
|
|
40
|
+
description: "Button label (displayed above text)",
|
|
41
|
+
},
|
|
42
|
+
fullWidth: {
|
|
43
|
+
control: { type: "boolean" },
|
|
44
|
+
description: "Make button full width",
|
|
45
|
+
},
|
|
46
|
+
size: {
|
|
47
|
+
control: { type: "object" },
|
|
48
|
+
description: "Responsive size configuration",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
args: {
|
|
52
|
+
text: "Button",
|
|
53
|
+
variant: "primary_brand",
|
|
54
|
+
isLoading: false,
|
|
55
|
+
disabled: false,
|
|
56
|
+
fullWidth: false,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default meta;
|
|
61
|
+
type Story = StoryObj<typeof meta>;
|
|
62
|
+
|
|
63
|
+
// Default button
|
|
64
|
+
export const Default: Story = {
|
|
65
|
+
args: {},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Primary brand variant
|
|
69
|
+
export const PrimaryBrand: Story = {
|
|
70
|
+
args: {
|
|
71
|
+
variant: "primary_brand",
|
|
72
|
+
text: "Primary Brand Button",
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Primary inverse variant
|
|
77
|
+
export const PrimaryInverse: Story = {
|
|
78
|
+
args: {
|
|
79
|
+
variant: "primary_inverse",
|
|
80
|
+
text: "Primary Inverse Button",
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Secondary variant
|
|
85
|
+
export const Secondary: Story = {
|
|
86
|
+
args: {
|
|
87
|
+
variant: "secondary",
|
|
88
|
+
text: "Secondary Button",
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// With label
|
|
93
|
+
export const WithLabel: Story = {
|
|
94
|
+
args: {
|
|
95
|
+
variant: "primary_brand",
|
|
96
|
+
label: "Label",
|
|
97
|
+
text: "Button Text",
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Loading state
|
|
102
|
+
export const Loading: Story = {
|
|
103
|
+
args: {
|
|
104
|
+
variant: "primary_brand",
|
|
105
|
+
text: "Loading...",
|
|
106
|
+
isLoading: true,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Disabled state
|
|
111
|
+
export const Disabled: Story = {
|
|
112
|
+
args: {
|
|
113
|
+
variant: "primary_brand",
|
|
114
|
+
text: "Disabled Button",
|
|
115
|
+
disabled: true,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Full width
|
|
120
|
+
export const FullWidth: Story = {
|
|
121
|
+
args: {
|
|
122
|
+
variant: "primary_brand",
|
|
123
|
+
text: "Full Width Button",
|
|
124
|
+
fullWidth: true,
|
|
125
|
+
},
|
|
126
|
+
render: (args) => (
|
|
127
|
+
<div className="w-64">
|
|
128
|
+
<BrandButton {...args} />
|
|
129
|
+
</div>
|
|
130
|
+
),
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Responsive sizes
|
|
134
|
+
export const ResponsiveSizes: Story = {
|
|
135
|
+
render: () => (
|
|
136
|
+
<div className="space-y-4">
|
|
137
|
+
<div>
|
|
138
|
+
<h4 className="mb-2 text-sm font-medium">Base: small, MD: medium, LG: large</h4>
|
|
139
|
+
<BrandButton
|
|
140
|
+
variant="primary_brand"
|
|
141
|
+
text="Responsive Button"
|
|
142
|
+
size={{ base: "small", md: "medium", lg: "large" }}
|
|
143
|
+
/>
|
|
144
|
+
</div>
|
|
145
|
+
<div>
|
|
146
|
+
<h4 className="mb-2 text-sm font-medium">Base: medium, MD: large</h4>
|
|
147
|
+
<BrandButton
|
|
148
|
+
variant="primary_brand"
|
|
149
|
+
text="Responsive Button"
|
|
150
|
+
size={{ base: "medium", md: "large" }}
|
|
151
|
+
/>
|
|
152
|
+
</div>
|
|
153
|
+
<div>
|
|
154
|
+
<h4 className="mb-2 text-sm font-medium">Base only</h4>
|
|
155
|
+
<BrandButton
|
|
156
|
+
variant="primary_brand"
|
|
157
|
+
text="Responsive Button"
|
|
158
|
+
size={{ base: "medium" }}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
),
|
|
163
|
+
parameters: {
|
|
164
|
+
docs: {
|
|
165
|
+
description: {
|
|
166
|
+
story:
|
|
167
|
+
"BrandButton supports responsive sizing that adapts to different screen sizes.",
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// All variants showcase
|
|
174
|
+
export const AllVariants: Story = {
|
|
175
|
+
render: () => (
|
|
176
|
+
<div className="space-y-6">
|
|
177
|
+
<div>
|
|
178
|
+
<h3 className="mb-4 text-lg font-semibold">Variants</h3>
|
|
179
|
+
<div className="flex flex-col gap-3">
|
|
180
|
+
<BrandButton variant="primary_brand" text="Primary Brand" />
|
|
181
|
+
<BrandButton variant="primary_inverse" text="Primary Inverse" />
|
|
182
|
+
<BrandButton variant="secondary" text="Secondary" />
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
<div>
|
|
186
|
+
<h3 className="mb-4 text-lg font-semibold">States</h3>
|
|
187
|
+
<div className="flex flex-col gap-3">
|
|
188
|
+
<BrandButton variant="primary_brand" text="Normal" />
|
|
189
|
+
<BrandButton variant="primary_brand" text="Loading" isLoading />
|
|
190
|
+
<BrandButton variant="primary_brand" text="Disabled" disabled />
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
<div>
|
|
194
|
+
<h3 className="mb-4 text-lg font-semibold">With Label</h3>
|
|
195
|
+
<BrandButton
|
|
196
|
+
variant="primary_brand"
|
|
197
|
+
label="Label"
|
|
198
|
+
text="Button Text"
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
<div>
|
|
202
|
+
<h3 className="mb-4 text-lg font-semibold">Full Width</h3>
|
|
203
|
+
<div className="w-64">
|
|
204
|
+
<BrandButton
|
|
205
|
+
variant="primary_brand"
|
|
206
|
+
text="Full Width Button"
|
|
207
|
+
fullWidth
|
|
208
|
+
/>
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
),
|
|
213
|
+
parameters: {
|
|
214
|
+
docs: {
|
|
215
|
+
description: {
|
|
216
|
+
story: "Complete showcase of all BrandButton variants, sizes, and states.",
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ResponsiveSize } from "./types";
|
|
2
|
+
|
|
3
|
+
// Using a simple, intentional workaround to handle the Tailwind scan issue.
|
|
4
|
+
const getClassNames = (size:string) =>{
|
|
5
|
+
switch (size) {
|
|
6
|
+
case "small":
|
|
7
|
+
return "md:btn-small"
|
|
8
|
+
case "medium":
|
|
9
|
+
return "md:btn-medium"
|
|
10
|
+
case "large":
|
|
11
|
+
return "md:btn-large"
|
|
12
|
+
case "x-large":
|
|
13
|
+
return "md:btn-x-large"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const sizeToClassNames = (size: ResponsiveSize) => {
|
|
18
|
+
let classes = "";
|
|
19
|
+
|
|
20
|
+
if (size.base) classes = `btn-${size.base} `;
|
|
21
|
+
if (size.md) classes += `${getClassNames(size.md)} `;
|
|
22
|
+
if (size.lg) classes += `lg:btn-${size.lg} `;
|
|
23
|
+
|
|
24
|
+
return classes.trim();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const getLabelSizeBasedOnButtonSize = (size: ResponsiveSize) => {
|
|
28
|
+
let classes = "";
|
|
29
|
+
|
|
30
|
+
if (size.base) classes = size.base === "x-large" ? `label3 ` : "label4 ";
|
|
31
|
+
if (size.md) classes += size.md === "x-large" ? `md:label3 ` : "md:label4 ";
|
|
32
|
+
if (size.lg) classes += size.lg === "x-large" ? `lg:label3 ` : "lg:label4 ";
|
|
33
|
+
|
|
34
|
+
return classes.trim();
|
|
35
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
import { cx } from "@shared/utils";
|
|
3
|
+
import { ButtonProps, ButtonVariantsT } from "@shared/components/brand-button/types";
|
|
4
|
+
import { MaterialIcon } from "@shared/components/material-icon";
|
|
5
|
+
import { getLabelSizeBasedOnButtonSize, sizeToClassNames } from "./helpers";
|
|
6
|
+
|
|
7
|
+
// BrandButton is intentionally limited to prevent over-configuration, restricting className and children props.
|
|
8
|
+
export const BrandButton = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
9
|
+
(
|
|
10
|
+
{
|
|
11
|
+
variant = "primary_brand",
|
|
12
|
+
isLoading = false,
|
|
13
|
+
text,
|
|
14
|
+
label,
|
|
15
|
+
disabled,
|
|
16
|
+
fullWidth,
|
|
17
|
+
size = { base: "medium" },
|
|
18
|
+
...props
|
|
19
|
+
},
|
|
20
|
+
ref
|
|
21
|
+
) => {
|
|
22
|
+
const getVariantClasses = () => {
|
|
23
|
+
const baseClasses =
|
|
24
|
+
cx(
|
|
25
|
+
sizeToClassNames(size),
|
|
26
|
+
'rounded-2xl pl-15 pr-15 inline-flex gap-2 items-center justify-center outline-none focus:ring-2 focus:ring-offset-2 cursor-pointer transition-colors duration-200 align-top',
|
|
27
|
+
fullWidth && "w-full"
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const variantClasses: Record<ButtonVariantsT, string> = {
|
|
31
|
+
primary_brand:
|
|
32
|
+
"bg-bg-fill-brand text-text-brand-on-bg-fill enabled:hover:bg-bg-fill-brand-hover focus:ring-bg-fill-brand",
|
|
33
|
+
primary_inverse:
|
|
34
|
+
"bg-bg-surface-inverse text-text-inverse enabled:hover:bg-bg-fill-inverse-hover focus:ring-bg-surface-inverse",
|
|
35
|
+
secondary:
|
|
36
|
+
"border-2 border-border-secondary-on-bg-fill bg-bg text-text focus:ring-bg-surface-inverse",
|
|
37
|
+
};
|
|
38
|
+
const stateClasses = cx(
|
|
39
|
+
(disabled || isLoading) && "cursor-not-allowed",
|
|
40
|
+
(isLoading) && "pl-7",
|
|
41
|
+
disabled && "bg-bg-fill-brand-disabled"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return cx(
|
|
45
|
+
baseClasses,
|
|
46
|
+
variantClasses[variant] || "",
|
|
47
|
+
stateClasses
|
|
48
|
+
)
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const variantClasses = getVariantClasses();
|
|
52
|
+
|
|
53
|
+
let infoClassNames = `button--${variant}`
|
|
54
|
+
if (isLoading) infoClassNames += " button--loading";
|
|
55
|
+
if (disabled) infoClassNames += " button--disabled";
|
|
56
|
+
|
|
57
|
+
const combinedClassName =
|
|
58
|
+
`${infoClassNames} ${variantClasses}`;
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<button
|
|
62
|
+
ref={ref}
|
|
63
|
+
className={cx(combinedClassName)}
|
|
64
|
+
disabled={disabled || isLoading}
|
|
65
|
+
{...props}
|
|
66
|
+
>
|
|
67
|
+
{isLoading ? (
|
|
68
|
+
<MaterialIcon name="progress_activity" className="animate-spin" />
|
|
69
|
+
) : null}
|
|
70
|
+
|
|
71
|
+
{label ? (
|
|
72
|
+
<span className="flex flex-col">
|
|
73
|
+
<span className={cx(getLabelSizeBasedOnButtonSize(size))}>
|
|
74
|
+
{label}
|
|
75
|
+
</span>
|
|
76
|
+
{text}
|
|
77
|
+
</span>
|
|
78
|
+
): (
|
|
79
|
+
text
|
|
80
|
+
)}
|
|
81
|
+
</button>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
BrandButton.displayName = "BrandButton";
|
|
87
|
+
|
|
88
|
+
export type { ButtonProps, ButtonVariantsT, ButtonSizeT, ResponsiveSize } from "./types";
|
|
89
|
+
|
|
90
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ButtonHTMLAttributes,
|
|
3
|
+
} from "react";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type ButtonVariantsT = "primary_brand" | "primary_inverse" | "secondary"
|
|
7
|
+
|
|
8
|
+
export type ButtonSizeT = "small" | "medium" | "large" | "x-large";
|
|
9
|
+
|
|
10
|
+
export type ResponsiveSize = {
|
|
11
|
+
base?: ButtonSizeT;
|
|
12
|
+
md?: ButtonSizeT;
|
|
13
|
+
lg?: ButtonSizeT;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ButtonCustomProps = {
|
|
17
|
+
/** Button styling variant */
|
|
18
|
+
variant?: ButtonVariantsT;
|
|
19
|
+
/** Loading state - shows spinner and disables button */
|
|
20
|
+
isLoading?: boolean;
|
|
21
|
+
label?: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
fullWidth?: boolean;
|
|
24
|
+
size?: ResponsiveSize;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type ButtonProps = ButtonCustomProps & Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"| "className">;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Button } from "./index";
|
|
2
|
+
import { DocsPage } from "@shared/stories/DocsTemplate";
|
|
3
|
+
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof Button> = {
|
|
7
|
+
title: "Components/Button",
|
|
8
|
+
component: Button,
|
|
9
|
+
tags: ["autodocs"],
|
|
10
|
+
parameters: {
|
|
11
|
+
layout: "centered",
|
|
12
|
+
docs: {
|
|
13
|
+
page: DocsPage,
|
|
14
|
+
description: {
|
|
15
|
+
component:
|
|
16
|
+
"A base button component for functional actions. Its appearance and behavior can be customized based on the parent component's context using className. This component provides loading and disabled states, but styling is left to the consumer.",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
argTypes: {
|
|
21
|
+
disabled: {
|
|
22
|
+
control: { type: "boolean" },
|
|
23
|
+
description: "Disable the button",
|
|
24
|
+
},
|
|
25
|
+
children: {
|
|
26
|
+
control: { type: "text" },
|
|
27
|
+
description: "Button content",
|
|
28
|
+
},
|
|
29
|
+
className: {
|
|
30
|
+
control: { type: "text" },
|
|
31
|
+
description: "Additional CSS classes for custom styling",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
args: {
|
|
35
|
+
children: "Button",
|
|
36
|
+
disabled: false,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default meta;
|
|
41
|
+
type Story = StoryObj<typeof meta>;
|
|
42
|
+
|
|
43
|
+
// Default button
|
|
44
|
+
export const Default: Story = {
|
|
45
|
+
args: {},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Disabled button
|
|
49
|
+
export const Disabled: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
disabled: true,
|
|
52
|
+
children: "Disabled Button",
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// With custom styling
|
|
57
|
+
export const WithCustomStyling: Story = {
|
|
58
|
+
args: {
|
|
59
|
+
className: "btn-medium bg-fill-brand text-inverse rounded px-4 py-2",
|
|
60
|
+
children: "Custom Styled Button",
|
|
61
|
+
},
|
|
62
|
+
parameters: {
|
|
63
|
+
docs: {
|
|
64
|
+
description: {
|
|
65
|
+
story:
|
|
66
|
+
"The Button component accepts className for custom styling. Use Tailwind classes or your own CSS to style the button as needed.",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Styling examples
|
|
73
|
+
export const StylingExamples: Story = {
|
|
74
|
+
render: () => (
|
|
75
|
+
<div className="space-y-4">
|
|
76
|
+
<div>
|
|
77
|
+
<p className="mb-2 text-sm text-gray-600">
|
|
78
|
+
Examples of how you can style the Button component using className:
|
|
79
|
+
</p>
|
|
80
|
+
<div className="flex flex-wrap gap-2">
|
|
81
|
+
<Button className="btn-medium bg-fill-brand text-inverse">
|
|
82
|
+
Brand Button
|
|
83
|
+
</Button>
|
|
84
|
+
<Button className="btn-medium bg-surface-secondary text-default">
|
|
85
|
+
Secondary Button
|
|
86
|
+
</Button>
|
|
87
|
+
<Button className="btn-medium border border-border-default text-default">
|
|
88
|
+
Outline Button
|
|
89
|
+
</Button>
|
|
90
|
+
<Button className="btn-small bg-fill-brand text-inverse">
|
|
91
|
+
Small Button
|
|
92
|
+
</Button>
|
|
93
|
+
<Button className="btn-large bg-fill-brand text-inverse">
|
|
94
|
+
Large Button
|
|
95
|
+
</Button>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
),
|
|
100
|
+
parameters: {
|
|
101
|
+
docs: {
|
|
102
|
+
description: {
|
|
103
|
+
story:
|
|
104
|
+
"Styling examples showing how to use className to customize the button appearance. These are examples only - the component itself doesn't provide built-in variants.",
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|