@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,168 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import ReactModal from "react-modal";
|
|
3
|
+
import { Transition } from "react-transition-group";
|
|
4
|
+
|
|
5
|
+
import { MaterialIcon } from "../material-icon";
|
|
6
|
+
import { cx } from "../../utils";
|
|
7
|
+
import useBodyScrollLock from "../../hooks/use-body-scroll-lock";
|
|
8
|
+
|
|
9
|
+
import { ModalProps, Size, Shape, Animation } from "./types";
|
|
10
|
+
import { Button } from "../button";
|
|
11
|
+
|
|
12
|
+
const Modal: React.FC<ModalProps> = ({
|
|
13
|
+
size = "md",
|
|
14
|
+
shape = "default",
|
|
15
|
+
animation = "popper",
|
|
16
|
+
centered,
|
|
17
|
+
title,
|
|
18
|
+
isOpen,
|
|
19
|
+
children,
|
|
20
|
+
bodyStyle,
|
|
21
|
+
className,
|
|
22
|
+
bodyClassName,
|
|
23
|
+
portalClassName,
|
|
24
|
+
overlayClassName,
|
|
25
|
+
closeButtonClassName,
|
|
26
|
+
closeWrapperClassName,
|
|
27
|
+
onRequestClose,
|
|
28
|
+
parentSelector,
|
|
29
|
+
hideScrollOnIsOpenFalse = true,
|
|
30
|
+
hideCloseButton = false,
|
|
31
|
+
...modalProps
|
|
32
|
+
}: ModalProps) => {
|
|
33
|
+
// Use the custom hook to lock/unlock the body scroll when the modal is open/closed.
|
|
34
|
+
useBodyScrollLock(isOpen, hideScrollOnIsOpenFalse);
|
|
35
|
+
|
|
36
|
+
// Animation cannot run at the same time as the modal opening
|
|
37
|
+
const [isTransitioning, setIsTransitioning] = useState(false);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
// Run animation one frame after rendering the modal
|
|
41
|
+
setIsTransitioning(isOpen);
|
|
42
|
+
}, [isOpen]);
|
|
43
|
+
|
|
44
|
+
const parent = useMemo(() => {
|
|
45
|
+
/* istanbul ignore next */ if (typeof document === "undefined") return null;
|
|
46
|
+
let parent = document.querySelector("main") || document.body;
|
|
47
|
+
if (parentSelector)
|
|
48
|
+
parent = document.querySelector(parentSelector) || document.body;
|
|
49
|
+
|
|
50
|
+
return parent;
|
|
51
|
+
}, [parentSelector]);
|
|
52
|
+
|
|
53
|
+
if (!parent) return null;
|
|
54
|
+
|
|
55
|
+
// Don't render anything when modal is closed
|
|
56
|
+
if (!isOpen) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const getSizeClasses = (size: Size) => {
|
|
61
|
+
const sizeMap = {
|
|
62
|
+
xl: "inset-[5%] min-h-fit",
|
|
63
|
+
lg: "inset-[10%] min-h-fit",
|
|
64
|
+
md: "inset-[15%] min-h-fit",
|
|
65
|
+
sm: "top-[18%] w-[640px]",
|
|
66
|
+
xs: "w-[calc(100%-30px)]",
|
|
67
|
+
};
|
|
68
|
+
return sizeMap[size];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getAnimationClasses = (animation: Animation, state: string) => {
|
|
72
|
+
if (animation === "popper") {
|
|
73
|
+
const baseClasses = "transition-transform duration-300";
|
|
74
|
+
if (state === "entering" || state === "entered") {
|
|
75
|
+
return `${baseClasses} opacity-100 ${state === "entered" ? "translate-y-0 pointer-events-auto" : ""}`;
|
|
76
|
+
}
|
|
77
|
+
if (state === "exiting" || state === "exited") {
|
|
78
|
+
return `${baseClasses} opacity-0 translate-y-[-18px] duration-[180ms]`;
|
|
79
|
+
}
|
|
80
|
+
return `${baseClasses} opacity-0 translate-y-[-18px]`;
|
|
81
|
+
}
|
|
82
|
+
if (animation === "bottomSheet") {
|
|
83
|
+
const baseClasses = "transition-transform duration-200 ease-in-out";
|
|
84
|
+
if (state === "entering" || state === "entered") {
|
|
85
|
+
return `${baseClasses} opacity-100 ${state === "entered" ? "translate-y-0 pointer-events-auto" : ""}`;
|
|
86
|
+
}
|
|
87
|
+
if (state === "exiting" || state === "exited") {
|
|
88
|
+
return `${baseClasses} opacity-0 translate-y-full duration-[180ms]`;
|
|
89
|
+
}
|
|
90
|
+
return `${baseClasses} opacity-0 translate-y-full`;
|
|
91
|
+
}
|
|
92
|
+
return "";
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<Transition enter exit in={isTransitioning} timeout={0}>
|
|
97
|
+
{(state: string) => (
|
|
98
|
+
<ReactModal
|
|
99
|
+
ariaHideApp={false}
|
|
100
|
+
isOpen={isOpen}
|
|
101
|
+
onRequestClose={onRequestClose}
|
|
102
|
+
closeTimeoutMS={0}
|
|
103
|
+
parentSelector={() => parent}
|
|
104
|
+
className={cx(
|
|
105
|
+
"absolute bg-white overflow-auto outline-none min-w-[150px] rounded-lg max-w-[calc(100vw-30px)]",
|
|
106
|
+
getSizeClasses(size),
|
|
107
|
+
shape === "rounded" && "rounded-3xl",
|
|
108
|
+
centered && "top-0 translate-y-[calc(50vh-50%)]",
|
|
109
|
+
getAnimationClasses(animation, state),
|
|
110
|
+
className
|
|
111
|
+
)}
|
|
112
|
+
portalClassName={cx("z-80", portalClassName)}
|
|
113
|
+
overlayClassName={cx(
|
|
114
|
+
"z-80 fixed inset-0 bg-black/50 flex items-center justify-center pb-[300px]",
|
|
115
|
+
overlayClassName
|
|
116
|
+
)}
|
|
117
|
+
{...modalProps}
|
|
118
|
+
>
|
|
119
|
+
{!hideCloseButton && (
|
|
120
|
+
<div className={cx(closeWrapperClassName)}>
|
|
121
|
+
<Button
|
|
122
|
+
className={cx(
|
|
123
|
+
"absolute right-0 top-0 float-right h-6 cursor-pointer p-5 text-text",
|
|
124
|
+
closeButtonClassName
|
|
125
|
+
)}
|
|
126
|
+
onClick={onRequestClose as () => void}
|
|
127
|
+
data-testid="close-button"
|
|
128
|
+
data-track-element-name="modal_close_button"
|
|
129
|
+
data-track-click-text="Close Modal"
|
|
130
|
+
data-track-element-clicked="modal"
|
|
131
|
+
>
|
|
132
|
+
<MaterialIcon
|
|
133
|
+
name="close"
|
|
134
|
+
size={24}
|
|
135
|
+
/>
|
|
136
|
+
</Button>
|
|
137
|
+
</div>
|
|
138
|
+
)}
|
|
139
|
+
|
|
140
|
+
{title ? (
|
|
141
|
+
<div
|
|
142
|
+
className={cx(
|
|
143
|
+
"px-[7px] py-[7px] border-b border-border-secondary-on-bg-fill text-text",
|
|
144
|
+
)}
|
|
145
|
+
>
|
|
146
|
+
{title}
|
|
147
|
+
</div>
|
|
148
|
+
) : null}
|
|
149
|
+
<div
|
|
150
|
+
className={cx("p-5", bodyClassName)}
|
|
151
|
+
style={bodyStyle}
|
|
152
|
+
data-testid={modalProps["data-testid"]}
|
|
153
|
+
data-cy={modalProps["data-cy"]}
|
|
154
|
+
>
|
|
155
|
+
{children}
|
|
156
|
+
</div>
|
|
157
|
+
</ReactModal>
|
|
158
|
+
)}
|
|
159
|
+
</Transition>
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export { Modal };
|
|
164
|
+
|
|
165
|
+
Modal.displayName = "Modal";
|
|
166
|
+
|
|
167
|
+
export type { ModalProps, Size, Shape, Animation };
|
|
168
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Props as RModalProps } from "react-modal";
|
|
2
|
+
|
|
3
|
+
export type Size = "xl" | "lg" | "md" | "sm" | "xs";
|
|
4
|
+
export type Shape = "rounded" | "default";
|
|
5
|
+
export type Animation = "popper" | "bottomSheet";
|
|
6
|
+
|
|
7
|
+
type OwnProps = {
|
|
8
|
+
size?: Size;
|
|
9
|
+
shape?: Shape;
|
|
10
|
+
title?: string;
|
|
11
|
+
bodyClassName?: string | null | undefined;
|
|
12
|
+
closeWrapperClassName?: string | null | undefined;
|
|
13
|
+
closeButtonClassName?: string | null | undefined;
|
|
14
|
+
bodyStyle?: React.CSSProperties;
|
|
15
|
+
centered?: boolean;
|
|
16
|
+
hideScrollOnIsOpenFalse?: boolean;
|
|
17
|
+
parentSelector?: string;
|
|
18
|
+
animation?: Animation;
|
|
19
|
+
hideCloseButton?: boolean;
|
|
20
|
+
["data-testid"]?: string;
|
|
21
|
+
["data-cy"]?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ModalProps = OwnProps & RModalProps;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { RadioButton } from "./index";
|
|
2
|
+
import { DocsPage } from "@shared/stories/DocsTemplate";
|
|
3
|
+
|
|
4
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
|
|
7
|
+
const meta: Meta<typeof RadioButton> = {
|
|
8
|
+
title: "Components/RadioButton",
|
|
9
|
+
component: RadioButton,
|
|
10
|
+
tags: ["autodocs"],
|
|
11
|
+
parameters: {
|
|
12
|
+
layout: "centered",
|
|
13
|
+
docs: {
|
|
14
|
+
page: DocsPage,
|
|
15
|
+
description: {
|
|
16
|
+
component:
|
|
17
|
+
"A radio button component with support for labels, subtext, error states, and custom variants.",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
argTypes: {
|
|
22
|
+
name: {
|
|
23
|
+
control: { type: "text" },
|
|
24
|
+
description: "Radio button group name",
|
|
25
|
+
},
|
|
26
|
+
value: {
|
|
27
|
+
control: { type: "text" },
|
|
28
|
+
description: "Radio button value",
|
|
29
|
+
},
|
|
30
|
+
checked: {
|
|
31
|
+
control: { type: "boolean" },
|
|
32
|
+
description: "Whether the radio button is checked",
|
|
33
|
+
},
|
|
34
|
+
label: {
|
|
35
|
+
control: { type: "text" },
|
|
36
|
+
description: "Label text",
|
|
37
|
+
},
|
|
38
|
+
subText: {
|
|
39
|
+
control: { type: "text" },
|
|
40
|
+
description: "Subtext displayed below the label",
|
|
41
|
+
},
|
|
42
|
+
variant: {
|
|
43
|
+
control: { type: "select" },
|
|
44
|
+
options: ["circle"],
|
|
45
|
+
description: "Radio button variant",
|
|
46
|
+
},
|
|
47
|
+
hasError: {
|
|
48
|
+
control: { type: "boolean" },
|
|
49
|
+
description: "Show error state",
|
|
50
|
+
},
|
|
51
|
+
disabled: {
|
|
52
|
+
control: { type: "boolean" },
|
|
53
|
+
description: "Disable the radio button",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
args: {
|
|
57
|
+
name: "radio-group",
|
|
58
|
+
value: "option1",
|
|
59
|
+
checked: false,
|
|
60
|
+
label: "Radio Button Label",
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default meta;
|
|
65
|
+
type Story = StoryObj<typeof meta>;
|
|
66
|
+
|
|
67
|
+
// Default radio button
|
|
68
|
+
export const Default: Story = {
|
|
69
|
+
args: {},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Checked radio button
|
|
73
|
+
export const Checked: Story = {
|
|
74
|
+
args: {
|
|
75
|
+
checked: true,
|
|
76
|
+
label: "Checked Radio Button",
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Unchecked radio button
|
|
81
|
+
export const Unchecked: Story = {
|
|
82
|
+
args: {
|
|
83
|
+
checked: false,
|
|
84
|
+
label: "Unchecked Radio Button",
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// With label
|
|
89
|
+
export const WithLabel: Story = {
|
|
90
|
+
args: {
|
|
91
|
+
label: "Option with Label",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// With subtext
|
|
96
|
+
export const WithSubtext: Story = {
|
|
97
|
+
args: {
|
|
98
|
+
label: "Premium Plan",
|
|
99
|
+
subText: "$29.99/month - Best value",
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Error state
|
|
104
|
+
export const Error: Story = {
|
|
105
|
+
args: {
|
|
106
|
+
label: "Radio Button with Error",
|
|
107
|
+
hasError: true,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// Disabled state
|
|
112
|
+
export const Disabled: Story = {
|
|
113
|
+
args: {
|
|
114
|
+
label: "Disabled Radio Button",
|
|
115
|
+
disabled: true,
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Disabled checked
|
|
120
|
+
export const DisabledChecked: Story = {
|
|
121
|
+
args: {
|
|
122
|
+
checked: true,
|
|
123
|
+
label: "Disabled Checked Radio Button",
|
|
124
|
+
disabled: true,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// Radio group
|
|
129
|
+
export const RadioGroup: Story = {
|
|
130
|
+
render: () => {
|
|
131
|
+
const [selected, setSelected] = useState("option1");
|
|
132
|
+
return (
|
|
133
|
+
<div className="space-y-3">
|
|
134
|
+
<RadioButton
|
|
135
|
+
name="plan"
|
|
136
|
+
value="option1"
|
|
137
|
+
checked={selected === "option1"}
|
|
138
|
+
onChange={() => setSelected("option1")}
|
|
139
|
+
label="Basic Plan"
|
|
140
|
+
subText="$9.99/month"
|
|
141
|
+
/>
|
|
142
|
+
<RadioButton
|
|
143
|
+
name="plan"
|
|
144
|
+
value="option2"
|
|
145
|
+
checked={selected === "option2"}
|
|
146
|
+
onChange={() => setSelected("option2")}
|
|
147
|
+
label="Standard Plan"
|
|
148
|
+
subText="$19.99/month"
|
|
149
|
+
/>
|
|
150
|
+
<RadioButton
|
|
151
|
+
name="plan"
|
|
152
|
+
value="option3"
|
|
153
|
+
checked={selected === "option3"}
|
|
154
|
+
onChange={() => setSelected("option3")}
|
|
155
|
+
label="Premium Plan"
|
|
156
|
+
subText="$29.99/month"
|
|
157
|
+
/>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
parameters: {
|
|
162
|
+
docs: {
|
|
163
|
+
description: {
|
|
164
|
+
story: "Radio button group where only one option can be selected.",
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// With error in group
|
|
171
|
+
export const GroupWithError: Story = {
|
|
172
|
+
render: () => {
|
|
173
|
+
const [selected, setSelected] = useState<string | undefined>();
|
|
174
|
+
return (
|
|
175
|
+
<div className="space-y-3">
|
|
176
|
+
<RadioButton
|
|
177
|
+
name="payment"
|
|
178
|
+
value="credit"
|
|
179
|
+
checked={selected === "credit"}
|
|
180
|
+
onChange={(val) =>
|
|
181
|
+
setSelected(
|
|
182
|
+
typeof val === "string" || typeof val === "number"
|
|
183
|
+
? String(val)
|
|
184
|
+
: undefined
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
label="Credit Card"
|
|
188
|
+
hasError={!selected}
|
|
189
|
+
/>
|
|
190
|
+
<RadioButton
|
|
191
|
+
name="payment"
|
|
192
|
+
value="debit"
|
|
193
|
+
checked={selected === "debit"}
|
|
194
|
+
onChange={(val) =>
|
|
195
|
+
setSelected(
|
|
196
|
+
typeof val === "string" || typeof val === "number"
|
|
197
|
+
? String(val)
|
|
198
|
+
: undefined
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
label="Debit Card"
|
|
202
|
+
hasError={!selected}
|
|
203
|
+
/>
|
|
204
|
+
<RadioButton
|
|
205
|
+
name="payment"
|
|
206
|
+
value="paypal"
|
|
207
|
+
checked={selected === "paypal"}
|
|
208
|
+
onChange={(val) =>
|
|
209
|
+
setSelected(
|
|
210
|
+
typeof val === "string" || typeof val === "number"
|
|
211
|
+
? String(val)
|
|
212
|
+
: undefined
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
label="PayPal"
|
|
216
|
+
hasError={!selected}
|
|
217
|
+
/>
|
|
218
|
+
{!selected && (
|
|
219
|
+
<p className="text-sm text-red-600">Please select a payment method</p>
|
|
220
|
+
)}
|
|
221
|
+
</div>
|
|
222
|
+
);
|
|
223
|
+
},
|
|
224
|
+
parameters: {
|
|
225
|
+
docs: {
|
|
226
|
+
description: {
|
|
227
|
+
story: "Radio button group with error state when no option is selected.",
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// All variants showcase
|
|
234
|
+
export const AllVariants: Story = {
|
|
235
|
+
render: () => (
|
|
236
|
+
<div className="space-y-6">
|
|
237
|
+
<div>
|
|
238
|
+
<h3 className="mb-3 text-lg font-semibold">States</h3>
|
|
239
|
+
<div className="space-y-3">
|
|
240
|
+
<RadioButton
|
|
241
|
+
name="demo1"
|
|
242
|
+
value="unchecked"
|
|
243
|
+
checked={false}
|
|
244
|
+
label="Unchecked"
|
|
245
|
+
/>
|
|
246
|
+
<RadioButton
|
|
247
|
+
name="demo2"
|
|
248
|
+
value="checked"
|
|
249
|
+
checked={true}
|
|
250
|
+
label="Checked"
|
|
251
|
+
/>
|
|
252
|
+
<RadioButton
|
|
253
|
+
name="demo3"
|
|
254
|
+
value="disabled"
|
|
255
|
+
checked={false}
|
|
256
|
+
label="Disabled"
|
|
257
|
+
disabled
|
|
258
|
+
/>
|
|
259
|
+
<RadioButton
|
|
260
|
+
name="demo4"
|
|
261
|
+
value="disabled-checked"
|
|
262
|
+
checked={true}
|
|
263
|
+
label="Disabled Checked"
|
|
264
|
+
disabled
|
|
265
|
+
/>
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
<div>
|
|
269
|
+
<h3 className="mb-3 text-lg font-semibold">With Subtext</h3>
|
|
270
|
+
<div className="space-y-3">
|
|
271
|
+
<RadioButton
|
|
272
|
+
name="demo5"
|
|
273
|
+
value="plan1"
|
|
274
|
+
checked={true}
|
|
275
|
+
label="Basic Plan"
|
|
276
|
+
subText="$9.99/month"
|
|
277
|
+
/>
|
|
278
|
+
<RadioButton
|
|
279
|
+
name="demo6"
|
|
280
|
+
value="plan2"
|
|
281
|
+
checked={false}
|
|
282
|
+
label="Premium Plan"
|
|
283
|
+
subText="$29.99/month - Best value"
|
|
284
|
+
/>
|
|
285
|
+
</div>
|
|
286
|
+
</div>
|
|
287
|
+
<div>
|
|
288
|
+
<h3 className="mb-3 text-lg font-semibold">Error State</h3>
|
|
289
|
+
<RadioButton
|
|
290
|
+
name="demo7"
|
|
291
|
+
value="error"
|
|
292
|
+
checked={false}
|
|
293
|
+
label="Radio Button with Error"
|
|
294
|
+
hasError
|
|
295
|
+
/>
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
),
|
|
299
|
+
parameters: {
|
|
300
|
+
docs: {
|
|
301
|
+
description: {
|
|
302
|
+
story: "Showcase of all radio button variants and states.",
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { cx } from "@shared/utils";
|
|
4
|
+
|
|
5
|
+
import { RadioButtonProps } from "./types";
|
|
6
|
+
import { Button } from "@shared/components/button";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const RadioButton: React.FC<RadioButtonProps> = props => {
|
|
10
|
+
const {
|
|
11
|
+
name,
|
|
12
|
+
value,
|
|
13
|
+
label,
|
|
14
|
+
subText,
|
|
15
|
+
checked,
|
|
16
|
+
onChange,
|
|
17
|
+
className,
|
|
18
|
+
variant = "circle",
|
|
19
|
+
hasError = false,
|
|
20
|
+
labelProps = {},
|
|
21
|
+
"data-cy": dataCy,
|
|
22
|
+
labelClassName = "",
|
|
23
|
+
disabled,
|
|
24
|
+
...rest
|
|
25
|
+
} = props;
|
|
26
|
+
|
|
27
|
+
const handleChange = () => onChange?.(value || name);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<label
|
|
31
|
+
htmlFor={name}
|
|
32
|
+
className={cx("flex items-center", className)}
|
|
33
|
+
data-cy={dataCy}
|
|
34
|
+
{...labelProps}
|
|
35
|
+
>
|
|
36
|
+
<input
|
|
37
|
+
className="hidden"
|
|
38
|
+
type="radio"
|
|
39
|
+
name={name}
|
|
40
|
+
value={value}
|
|
41
|
+
checked={checked}
|
|
42
|
+
readOnly
|
|
43
|
+
disabled={disabled}
|
|
44
|
+
{...rest}
|
|
45
|
+
/>
|
|
46
|
+
<Button
|
|
47
|
+
type="button"
|
|
48
|
+
onClick={handleChange}
|
|
49
|
+
disabled={disabled}
|
|
50
|
+
className={cx(
|
|
51
|
+
"border-border-secondary-on-bg-fill bg-bg mr-3 flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full border-[1px] border-solid outline-offset-4",
|
|
52
|
+
checked && "border-border-brand border-[1px] border-solid",
|
|
53
|
+
disabled && "opacity-50"
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
{checked && <div className="bg-bg-fill-brand h-[0.875rem] w-[0.875rem] rounded-full" />}
|
|
57
|
+
</Button>
|
|
58
|
+
<Button
|
|
59
|
+
type="button"
|
|
60
|
+
onClick={handleChange}
|
|
61
|
+
disabled={disabled}
|
|
62
|
+
tabIndex={label ? 0 : -1}
|
|
63
|
+
>
|
|
64
|
+
<div className={cx("text-body2 font-normal", labelClassName)}>{label}</div>
|
|
65
|
+
<div className="text-text-info text-body1">{subText}</div>
|
|
66
|
+
</Button>
|
|
67
|
+
</label>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
RadioButton.displayName = "RadioButton";
|
|
72
|
+
|
|
73
|
+
export type { RadioButtonProps };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InputHTMLAttributes, LabelHTMLAttributes, ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
type OwnProps = {
|
|
4
|
+
name: string;
|
|
5
|
+
value?: string | number;
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
onChange?: (newVal?: string | number) => void;
|
|
8
|
+
label?: string | ReactNode;
|
|
9
|
+
subText?: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
labelProps?: LabelHTMLAttributes<HTMLLabelElement>;
|
|
12
|
+
variant?: "circle";
|
|
13
|
+
hasError?: boolean;
|
|
14
|
+
"data-cy"?: string;
|
|
15
|
+
labelClassName?: string;
|
|
16
|
+
};
|
|
17
|
+
export type RadioButtonProps = OwnProps &
|
|
18
|
+
Omit<
|
|
19
|
+
InputHTMLAttributes<HTMLInputElement>,
|
|
20
|
+
"onChange" | "value" | "name" | "checked"
|
|
21
|
+
>;
|
|
22
|
+
|