@agilant/toga-blox 1.0.5
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/Dockerfile +9 -0
- package/README.md +69 -0
- package/assets/Logo.png +0 -0
- package/assets/compass-card-image-2.png +0 -0
- package/assets/compass-card-image-3.png +0 -0
- package/assets/compass-card-image-4.png +0 -0
- package/assets/compass-card-image.png +0 -0
- package/assets/compass-logo.png +0 -0
- package/assets/compass-tech-hero-bg.png +0 -0
- package/assets/contact-image.png +0 -0
- package/assets/green-laptop.png +0 -0
- package/assets/heroImage.png +0 -0
- package/assets/placeholder-no-image-available.png +0 -0
- package/assets/team.png +0 -0
- package/declarations.d.ts +4 -0
- package/docker-compose.yml +22 -0
- package/global.css +4 -0
- package/index.js +4 -0
- package/nodemon.json +5 -0
- package/package.json +70 -0
- package/postcss.config.js +6 -0
- package/src/components/Badge/Badge.stories.tsx +284 -0
- package/src/components/Badge/Badge.test.tsx +185 -0
- package/src/components/Badge/Badge.tsx +137 -0
- package/src/components/Badge/Badge.types.tsx +28 -0
- package/src/components/Badge/badgeClassNames.tsx +152 -0
- package/src/components/Badge/index.ts +2 -0
- package/src/components/Card/Card.stories.tsx +91 -0
- package/src/components/Card/Card.test.tsx +53 -0
- package/src/components/Card/Card.tsx +30 -0
- package/src/components/Card/Card.types.ts +11 -0
- package/src/components/Card/DUMMYPRODUCTDATA.json +670 -0
- package/src/components/Card/cardClassNames.ts +49 -0
- package/src/components/Card/index.ts +3 -0
- package/src/components/Card/templates/CompassCardTemplate.tsx +58 -0
- package/src/components/Card/templates/HorizontalCardTemplate.tsx +184 -0
- package/src/components/Card/templates/VerticalCardTemplate.tsx +154 -0
- package/src/components/Footer/ContactInfoItem.tsx +20 -0
- package/src/components/Footer/DUMMYFOOTERDATA.json +132 -0
- package/src/components/Footer/Footer.stories.tsx +292 -0
- package/src/components/Footer/Footer.test.tsx +90 -0
- package/src/components/Footer/Footer.tsx +159 -0
- package/src/components/Footer/Footer.types.tsx +61 -0
- package/src/components/Footer/footerClassNames.tsx +57 -0
- package/src/components/FormButton/FormButton.stories.tsx +199 -0
- package/src/components/FormButton/FormButton.test.tsx +73 -0
- package/src/components/FormButton/FormButton.tsx +116 -0
- package/src/components/FormButton/FormButton.types.ts +32 -0
- package/src/components/FormButton/formButtonClassNames.tsx +153 -0
- package/src/components/FormButton/index.ts +2 -0
- package/src/components/GenericList/DUMMYLISTDATA.json +560 -0
- package/src/components/GenericList/GenericList.stories.tsx +104 -0
- package/src/components/GenericList/GenericList.test.tsx +29 -0
- package/src/components/GenericList/GenericList.tsx +146 -0
- package/src/components/GenericList/genericListClassNames.tsx +8 -0
- package/src/components/GenericList/templates/DummyDataList.tsx +23 -0
- package/src/components/GenericList/templates/DynamicIconList.tsx +74 -0
- package/src/components/HamburgerButton/HamburgerButton.tsx +68 -0
- package/src/components/HamburgerButton/HamburgerButton.types.tsx +6 -0
- package/src/components/HamburgerButton/index.ts +2 -0
- package/src/components/Header/DUMMYICONDATA.json +136 -0
- package/src/components/Header/Header.stories.tsx +521 -0
- package/src/components/Header/Header.test.tsx +323 -0
- package/src/components/Header/Header.tsx +289 -0
- package/src/components/Header/Header.types.ts +52 -0
- package/src/components/Header/headerClassNames.tsx +50 -0
- package/src/components/Header/headerContext.tsx +125 -0
- package/src/components/Header/index.ts +2 -0
- package/src/components/Hero/Hero.stories.tsx +69 -0
- package/src/components/Hero/Hero.test.tsx +109 -0
- package/src/components/Hero/Hero.tsx +58 -0
- package/src/components/Hero/Hero.types.ts +9 -0
- package/src/components/Hero/index.ts +2 -0
- package/src/components/Icon/Icon.stories.tsx +227 -0
- package/src/components/Icon/Icon.test.tsx +53 -0
- package/src/components/Icon/Icon.tsx +208 -0
- package/src/components/Icon/Icon.types.ts +24 -0
- package/src/components/Icon/iconClassNames.ts +79 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/Image/Image.stories.tsx +79 -0
- package/src/components/Image/Image.test.tsx +87 -0
- package/src/components/Image/Image.tsx +49 -0
- package/src/components/Image/Image.types.ts +11 -0
- package/src/components/Image/index.ts +2 -0
- package/src/components/Input/Input.stories.tsx +651 -0
- package/src/components/Input/Input.test.tsx +90 -0
- package/src/components/Input/Input.tsx +226 -0
- package/src/components/Input/Input.types.ts +52 -0
- package/src/components/Input/InputMemoTypes.tsx +32 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/Input/inputClassNames.tsx +169 -0
- package/src/components/MobileMenu/MobileMenu.tsx +41 -0
- package/src/components/MobileMenu/MobileMenu.types.tsx +30 -0
- package/src/components/MobileMenu/index.ts +2 -0
- package/src/components/Nav/DUMMYNAVDATA.json +234 -0
- package/src/components/Nav/Nav.stories.tsx +181 -0
- package/src/components/Nav/Nav.test.tsx +89 -0
- package/src/components/Nav/Nav.tsx +242 -0
- package/src/components/Nav/Nav.types.tsx +35 -0
- package/src/components/Nav/index.ts +2 -0
- package/src/components/Nav/navClassNames.tsx +192 -0
- package/src/components/Page/TableDataDummy.tsx +216 -0
- package/src/components/Page/ViewPageTemplate.stories.tsx +546 -0
- package/src/components/Page/ViewPageTemplate.test.tsx +361 -0
- package/src/components/Page/ViewPageTemplate.tsx +10 -0
- package/src/components/Page/ViewPageTemplate.types.ts +6 -0
- package/src/components/Page/index.ts +2 -0
- package/src/components/PageSection/PageSection.stories.tsx +114 -0
- package/src/components/PageSection/PageSection.tsx +12 -0
- package/src/components/PageSection/PageSection.types.ts +6 -0
- package/src/components/PageSection/PageSections.test.tsx +88 -0
- package/src/components/PageSection/index.ts +2 -0
- package/src/components/Text/Text.stories.tsx +60 -0
- package/src/components/Text/Text.test.tsx +52 -0
- package/src/components/Text/Text.tsx +80 -0
- package/src/components/Text/Text.types.ts +12 -0
- package/src/components/Text/index.ts +2 -0
- package/src/components/Toaster/Toaster.stories.tsx +122 -0
- package/src/components/Toaster/Toaster.test.tsx +61 -0
- package/src/components/Toaster/Toaster.tsx +80 -0
- package/src/components/Toaster/Toaster.types.ts +12 -0
- package/src/components/Toaster/index.ts +2 -0
- package/src/hoc/index.ts +2 -0
- package/src/hoc/styling/withStoryBook.tsx +19 -0
- package/src/main.css +3 -0
- package/src/setupTests.ts +1 -0
- package/src/userHoc/index.ts +1 -0
- package/src/userHoc/withMemo.tsx +20 -0
- package/src/utils/assertTagName.tsx +7 -0
- package/src/utils/generateAccordionItem.tsx +102 -0
- package/src/utils/generateFooterContacts.tsx +75 -0
- package/src/utils/generateNavMenu.tsx +54 -0
- package/src/utils/generateSocialList.tsx +34 -0
- package/src/utils/getFontAwesomeIcon.tsx +25 -0
- package/src/utils/inputValidation.tsx +26 -0
- package/tailwind.config.js +32 -0
- package/tsconfig.json +25 -0
- package/vite.config.ts +33 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { Meta, StoryFn } from "@storybook/react";
|
|
2
|
+
import FormButton from ".";
|
|
3
|
+
import type { ButtonTypes } from "./FormButton.types";
|
|
4
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
5
|
+
import { faCoffee } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import Text from "../Text/Text";
|
|
7
|
+
|
|
8
|
+
export default {
|
|
9
|
+
title: "Components/FormButton",
|
|
10
|
+
component: FormButton,
|
|
11
|
+
argTypes: {
|
|
12
|
+
onClick: {
|
|
13
|
+
table: {
|
|
14
|
+
disable: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
text: {
|
|
18
|
+
control: "text",
|
|
19
|
+
description: "The main text displayed on the component",
|
|
20
|
+
},
|
|
21
|
+
textStyle: {
|
|
22
|
+
control: "select",
|
|
23
|
+
options: ["normal", "bold"],
|
|
24
|
+
description: "Whether the button text is bold or normal.",
|
|
25
|
+
},
|
|
26
|
+
fontFamily: {
|
|
27
|
+
control: "select",
|
|
28
|
+
options: ["sans", "serif", "mono"],
|
|
29
|
+
description: "The font family of the button text.",
|
|
30
|
+
},
|
|
31
|
+
color: {
|
|
32
|
+
control: "select",
|
|
33
|
+
options: ["blue", "green", "grey", "clear"],
|
|
34
|
+
description: "The color for the button background.",
|
|
35
|
+
},
|
|
36
|
+
fontColor: {
|
|
37
|
+
control: "select",
|
|
38
|
+
options: ["white", "black"],
|
|
39
|
+
description: "The text color on the button.",
|
|
40
|
+
},
|
|
41
|
+
size: {
|
|
42
|
+
control: "select",
|
|
43
|
+
options: ["xs", "sm", "md", "lg", "xl"],
|
|
44
|
+
description: "The size of the text and button.",
|
|
45
|
+
},
|
|
46
|
+
borderColor: {
|
|
47
|
+
control: "select",
|
|
48
|
+
options: ["blue", "green", "grey", "none"],
|
|
49
|
+
description: "The color of the border.",
|
|
50
|
+
},
|
|
51
|
+
shape: {
|
|
52
|
+
control: "select",
|
|
53
|
+
options: ["cornered", "semiRounded", "rounded", "underline"],
|
|
54
|
+
description: "The shape of the button",
|
|
55
|
+
},
|
|
56
|
+
buttonWide: {
|
|
57
|
+
control: "boolean",
|
|
58
|
+
description: "Whether the button is wide or not.",
|
|
59
|
+
},
|
|
60
|
+
hoverBackground: {
|
|
61
|
+
control: "select",
|
|
62
|
+
options: ["blue", "green", "grey", "none"],
|
|
63
|
+
description: "The background color on hover.",
|
|
64
|
+
},
|
|
65
|
+
hoverBorderColor: {
|
|
66
|
+
control: "select",
|
|
67
|
+
options: ["blue", "green", "grey", "black", "none"],
|
|
68
|
+
description: "The border color on hover.",
|
|
69
|
+
},
|
|
70
|
+
hoverFontColor: {
|
|
71
|
+
control: "select",
|
|
72
|
+
options: ["blue", "green", "grey", "black"],
|
|
73
|
+
description: "The font color on hover.",
|
|
74
|
+
},
|
|
75
|
+
hoverUnderline: {
|
|
76
|
+
control: "boolean",
|
|
77
|
+
description: "Whether the text is underlined on hover.",
|
|
78
|
+
},
|
|
79
|
+
hoverBorder: {
|
|
80
|
+
control: "boolean",
|
|
81
|
+
description: "If there is a border on hover",
|
|
82
|
+
},
|
|
83
|
+
icon: {
|
|
84
|
+
table: {
|
|
85
|
+
disable: true,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
as: {
|
|
89
|
+
table: {
|
|
90
|
+
disable: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
iconOrder: {
|
|
94
|
+
control: "select",
|
|
95
|
+
options: ["first", "last"],
|
|
96
|
+
},
|
|
97
|
+
type: {
|
|
98
|
+
table: {
|
|
99
|
+
disable: true,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
to: {
|
|
103
|
+
table: {
|
|
104
|
+
disable: true,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
href: {
|
|
108
|
+
table: {
|
|
109
|
+
disable: true,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
tooltip: {
|
|
113
|
+
table: {
|
|
114
|
+
disable: true,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
additionalClasses: {
|
|
118
|
+
table: {
|
|
119
|
+
disable: true,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
isDisabled: {
|
|
123
|
+
control: "boolean",
|
|
124
|
+
description: "Toggle the buttons ability to be clicked.",
|
|
125
|
+
},
|
|
126
|
+
hasShadow: {
|
|
127
|
+
control: "boolean",
|
|
128
|
+
description: "Toggle the buttons shadow.",
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
tags: ["autodocs"],
|
|
132
|
+
parameters: {
|
|
133
|
+
layout: "centered",
|
|
134
|
+
},
|
|
135
|
+
} as Meta;
|
|
136
|
+
|
|
137
|
+
const Template: StoryFn<ButtonTypes> = (args) => <FormButton {...args} />;
|
|
138
|
+
|
|
139
|
+
export const Default = Template.bind({});
|
|
140
|
+
Default.args = {
|
|
141
|
+
text: "Default Button",
|
|
142
|
+
color: "blue",
|
|
143
|
+
fontColor: "white",
|
|
144
|
+
size: "md",
|
|
145
|
+
borderColor: "none",
|
|
146
|
+
shape: "rounded",
|
|
147
|
+
hoverBackground: "blue",
|
|
148
|
+
hoverFontColor: "black",
|
|
149
|
+
hoverBorderColor: "blue",
|
|
150
|
+
hoverUnderline: false,
|
|
151
|
+
onClick: () => alert("Button clicked!"),
|
|
152
|
+
additionalClasses: "p-2",
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const Compass = Template.bind({});
|
|
156
|
+
Compass.args = {
|
|
157
|
+
text: <Text size={""} color={""} text={"Compass Button"} fontFamily={""} />,
|
|
158
|
+
color: "green",
|
|
159
|
+
fontColor: "white",
|
|
160
|
+
size: "xl",
|
|
161
|
+
shape: "semiRounded",
|
|
162
|
+
borderColor: "none",
|
|
163
|
+
hoverBackground: "green",
|
|
164
|
+
hoverFontColor: "green",
|
|
165
|
+
hoverBorderColor: "green",
|
|
166
|
+
hoverUnderline: false,
|
|
167
|
+
onClick: () => alert("Button clicked!"),
|
|
168
|
+
as: "a",
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Story for a Disabled Button
|
|
172
|
+
export const Disabled = Template.bind({});
|
|
173
|
+
Disabled.args = {
|
|
174
|
+
...Default.args,
|
|
175
|
+
text: (
|
|
176
|
+
<Text size={""} color={""} text={"Disabled Button"} fontFamily={""} />
|
|
177
|
+
),
|
|
178
|
+
isDisabled: true,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const WithIcon = Template.bind({});
|
|
182
|
+
WithIcon.args = {
|
|
183
|
+
...Default.args,
|
|
184
|
+
text: (
|
|
185
|
+
<Text
|
|
186
|
+
size={""}
|
|
187
|
+
color={""}
|
|
188
|
+
text={"Button with icon"}
|
|
189
|
+
fontFamily={""}
|
|
190
|
+
additionalClasses="pl-2"
|
|
191
|
+
/>
|
|
192
|
+
),
|
|
193
|
+
icon: <FontAwesomeIcon icon={faCoffee} />,
|
|
194
|
+
shape: "cornered",
|
|
195
|
+
buttonWide: true,
|
|
196
|
+
hoverUnderline: false,
|
|
197
|
+
onClick: () => alert("Button clicked!"),
|
|
198
|
+
// additionalClasses: "flex items-center justify-between p-2",
|
|
199
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, beforeEach, test, vi } from "vitest";
|
|
3
|
+
import Button from "./FormButton";
|
|
4
|
+
import { MemoryRouter } from "react-router-dom";
|
|
5
|
+
|
|
6
|
+
describe("Button", () => {
|
|
7
|
+
test("renders correctly", () => {
|
|
8
|
+
render(
|
|
9
|
+
<MemoryRouter>
|
|
10
|
+
<Button
|
|
11
|
+
text="Default Button"
|
|
12
|
+
color="green"
|
|
13
|
+
size="md"
|
|
14
|
+
shape="outline"
|
|
15
|
+
/>
|
|
16
|
+
</MemoryRouter>
|
|
17
|
+
);
|
|
18
|
+
expect(screen.getByText("Default Button")).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("is clickable", () => {
|
|
22
|
+
const mockOnClick = vi.fn();
|
|
23
|
+
render(
|
|
24
|
+
<MemoryRouter>
|
|
25
|
+
<Button
|
|
26
|
+
text="Clickable Button"
|
|
27
|
+
color="green"
|
|
28
|
+
size="md"
|
|
29
|
+
shape="outline"
|
|
30
|
+
onClick={mockOnClick}
|
|
31
|
+
/>
|
|
32
|
+
</MemoryRouter>
|
|
33
|
+
);
|
|
34
|
+
fireEvent.click(screen.getByText("Clickable Button"));
|
|
35
|
+
expect(mockOnClick).toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("has correct text", () => {
|
|
39
|
+
render(
|
|
40
|
+
<MemoryRouter>
|
|
41
|
+
<Button
|
|
42
|
+
text="Default Button"
|
|
43
|
+
color="green"
|
|
44
|
+
size="md"
|
|
45
|
+
shape="outline"
|
|
46
|
+
/>
|
|
47
|
+
</MemoryRouter>
|
|
48
|
+
);
|
|
49
|
+
expect(screen.getByText("Default Button")).toHaveTextContent(
|
|
50
|
+
"Default Button"
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe("Disabled Button", () => {
|
|
56
|
+
test("is disabled", () => {
|
|
57
|
+
render(
|
|
58
|
+
<MemoryRouter>
|
|
59
|
+
<Button
|
|
60
|
+
text="Disabled Button"
|
|
61
|
+
color="green"
|
|
62
|
+
size="md"
|
|
63
|
+
shape="outline"
|
|
64
|
+
isDisabled
|
|
65
|
+
/>
|
|
66
|
+
</MemoryRouter>
|
|
67
|
+
);
|
|
68
|
+
expect(screen.getByText("Disabled Button")).toHaveAttribute(
|
|
69
|
+
"aria-disabled",
|
|
70
|
+
"true"
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { ElementType } from "react";
|
|
2
|
+
import { Link } from "react-router-dom";
|
|
3
|
+
import type { ButtonTypes } from ".";
|
|
4
|
+
import {
|
|
5
|
+
getHoverClassNames,
|
|
6
|
+
getColorClassNames,
|
|
7
|
+
getIconClasses,
|
|
8
|
+
getSizeClasses,
|
|
9
|
+
getTextClasses,
|
|
10
|
+
getButtonClasses,
|
|
11
|
+
} from "./formButtonClassNames";
|
|
12
|
+
|
|
13
|
+
const Button: React.FC<ButtonTypes> = ({
|
|
14
|
+
onClick,
|
|
15
|
+
text,
|
|
16
|
+
textStyle = "regular",
|
|
17
|
+
fontFamily = "sans",
|
|
18
|
+
color,
|
|
19
|
+
fontColor,
|
|
20
|
+
size = "md",
|
|
21
|
+
customWidth,
|
|
22
|
+
customHeight,
|
|
23
|
+
shape = "cornered",
|
|
24
|
+
buttonWide = false,
|
|
25
|
+
borderColor,
|
|
26
|
+
icon,
|
|
27
|
+
iconOrder = "first",
|
|
28
|
+
additionalClasses = "",
|
|
29
|
+
type = "button",
|
|
30
|
+
to,
|
|
31
|
+
href,
|
|
32
|
+
tooltip,
|
|
33
|
+
isDisabled = false,
|
|
34
|
+
hasShadow = false,
|
|
35
|
+
as: Element = "a",
|
|
36
|
+
hoverBackground,
|
|
37
|
+
hoverFontColor,
|
|
38
|
+
hoverUnderline,
|
|
39
|
+
hoverBorderColor,
|
|
40
|
+
...props
|
|
41
|
+
}) => {
|
|
42
|
+
let hoverClasses = getHoverClassNames(
|
|
43
|
+
hoverBackground,
|
|
44
|
+
hoverFontColor,
|
|
45
|
+
hoverUnderline,
|
|
46
|
+
hoverBorderColor,
|
|
47
|
+
isDisabled
|
|
48
|
+
);
|
|
49
|
+
let buttonColorClasses = getColorClassNames(color, fontColor, borderColor);
|
|
50
|
+
let buttonSizeClasses = getSizeClasses(buttonWide, size);
|
|
51
|
+
let textStyleClasses = getTextClasses(textStyle, fontFamily);
|
|
52
|
+
|
|
53
|
+
const shapeClassesMap: { [key: string]: string } = {
|
|
54
|
+
cornered: "rounded-none",
|
|
55
|
+
semiRounded: "rounded-md",
|
|
56
|
+
rounded: "rounded-full",
|
|
57
|
+
underline: "rounded-none border-b-6 border-b-black",
|
|
58
|
+
none: "border-none rounded-none",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
let iconClasses = getIconClasses(iconOrder);
|
|
62
|
+
|
|
63
|
+
const buttonShapeClasses = shapeClassesMap[shape];
|
|
64
|
+
|
|
65
|
+
let buttonClasses = getButtonClasses({
|
|
66
|
+
buttonColorClasses,
|
|
67
|
+
buttonSizeClasses,
|
|
68
|
+
buttonShapeClasses,
|
|
69
|
+
textStyleClasses,
|
|
70
|
+
hoverClasses,
|
|
71
|
+
hasShadow,
|
|
72
|
+
customWidth,
|
|
73
|
+
customHeight,
|
|
74
|
+
additionalClasses,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const handleClick = (
|
|
78
|
+
e: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>
|
|
79
|
+
) => {
|
|
80
|
+
if (isDisabled) {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
onClick?.(e);
|
|
85
|
+
};
|
|
86
|
+
// Base props common to all elements
|
|
87
|
+
const baseProps = {
|
|
88
|
+
className: buttonClasses.trim(),
|
|
89
|
+
onClick: handleClick,
|
|
90
|
+
type: type,
|
|
91
|
+
"aria-disabled": isDisabled ? "true" : "false",
|
|
92
|
+
"data-tooltip": tooltip,
|
|
93
|
+
};
|
|
94
|
+
// Extend baseProps based on Element type
|
|
95
|
+
if (Element === "a") {
|
|
96
|
+
props = { ...baseProps, href: href };
|
|
97
|
+
} else if (Element === "link") {
|
|
98
|
+
props = { ...baseProps, to: to };
|
|
99
|
+
} else if (Element === "button") {
|
|
100
|
+
// For 'button', the baseProps already contain all necessary properties
|
|
101
|
+
props = { ...baseProps };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<Element {...props}>
|
|
106
|
+
{icon && (
|
|
107
|
+
<span className={`${iconClasses} ${additionalClasses}`}>
|
|
108
|
+
{icon}
|
|
109
|
+
</span>
|
|
110
|
+
)}
|
|
111
|
+
{text}
|
|
112
|
+
</Element>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default Button;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { ElementType } from "react";
|
|
2
|
+
|
|
3
|
+
export interface ButtonTypes {
|
|
4
|
+
onClick?: (
|
|
5
|
+
e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>
|
|
6
|
+
) => void;
|
|
7
|
+
text?: string | JSX.Element;
|
|
8
|
+
color?: string;
|
|
9
|
+
fontColor?: string;
|
|
10
|
+
borderColor?: string;
|
|
11
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | string;
|
|
12
|
+
textStyle?: "thin" | "light" | "normal" | "semibold" | "bold";
|
|
13
|
+
fontFamily?: "sans" | "mono" | "serif" | string;
|
|
14
|
+
customWidth?: string;
|
|
15
|
+
customHeight?: string;
|
|
16
|
+
shape?: "cornered" | "semiRounded" | "rounded" | "underline" | string;
|
|
17
|
+
icon?: JSX.Element | null;
|
|
18
|
+
iconOrder?: "first" | "last";
|
|
19
|
+
type?: "submit" | "reset" | "button";
|
|
20
|
+
to?: string;
|
|
21
|
+
href?: string;
|
|
22
|
+
tooltip?: string;
|
|
23
|
+
additionalClasses?: string;
|
|
24
|
+
isDisabled?: boolean;
|
|
25
|
+
hasShadow?: boolean;
|
|
26
|
+
as?: ElementType;
|
|
27
|
+
hoverBackground?: string;
|
|
28
|
+
hoverFontColor?: string;
|
|
29
|
+
hoverUnderline?: boolean;
|
|
30
|
+
hoverBorderColor?: string;
|
|
31
|
+
buttonWide?: boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import classNames from "classNames";
|
|
2
|
+
|
|
3
|
+
export const getHoverClassNames = (
|
|
4
|
+
hoverBackground: string | undefined,
|
|
5
|
+
hoverFontColor: string | undefined,
|
|
6
|
+
hoverUnderline: boolean | undefined,
|
|
7
|
+
hoverBorderColor: string | undefined,
|
|
8
|
+
isDisabled: boolean | undefined
|
|
9
|
+
) => {
|
|
10
|
+
return classNames(
|
|
11
|
+
{
|
|
12
|
+
"hover:bg-blue-200": hoverBackground === "blue" && !isDisabled,
|
|
13
|
+
"hover:bg-teal-100": hoverBackground === "green" && !isDisabled,
|
|
14
|
+
"hover:bg-gray-200": hoverBackground === "grey" && !isDisabled,
|
|
15
|
+
"hover:bg-slate-950": hoverBackground === "black" && !isDisabled,
|
|
16
|
+
"hover:bg-transparent text-black": hoverBackground === "none" && !isDisabled,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"hover:text-blue-800": hoverFontColor === "blue" && !isDisabled,
|
|
20
|
+
"hover:text-teal-800": hoverFontColor === "green" && !isDisabled,
|
|
21
|
+
"hover:text-gray-800": hoverFontColor === "grey" && !isDisabled,
|
|
22
|
+
"hover:text-slate-50": hoverFontColor === "white" && !isDisabled,
|
|
23
|
+
"hover:text-black": hoverFontColor === "black" && !isDisabled,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"hover:border-blue-800": hoverBorderColor === "blue" && !isDisabled,
|
|
27
|
+
"hover:border-teal-800":
|
|
28
|
+
hoverBorderColor === "green" && !isDisabled,
|
|
29
|
+
"hover:border-gray-800": hoverBorderColor === "grey" && !isDisabled,
|
|
30
|
+
"hover:border-black": hoverBorderColor === "black" && !isDisabled,
|
|
31
|
+
"hover:border-transparent":
|
|
32
|
+
hoverBackground === "none" && !isDisabled,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"hover:underline hover:underline-offset-4":
|
|
36
|
+
hoverUnderline === true && !isDisabled,
|
|
37
|
+
"": hoverUnderline === false || isDisabled,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"opacity-50 cursor-not-allowed": isDisabled === true,
|
|
41
|
+
"cursor-pointer": isDisabled === false,
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const getColorClassNames = (
|
|
47
|
+
color: string | undefined,
|
|
48
|
+
fontColor: string | undefined,
|
|
49
|
+
borderColor: string | undefined
|
|
50
|
+
) => {
|
|
51
|
+
return classNames(
|
|
52
|
+
{
|
|
53
|
+
"bg-blue-600": color === "blue",
|
|
54
|
+
"bg-teal-700": color === "green",
|
|
55
|
+
"bg-gray-600": color === "grey",
|
|
56
|
+
"bg-transparent border-black": color === "clear",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"border-blue-600": borderColor === "blue",
|
|
60
|
+
"border-teal-700": borderColor === "green",
|
|
61
|
+
"border-gray-600": borderColor === "grey",
|
|
62
|
+
"border-transparent": borderColor === "none",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"text-white": fontColor === "white" && color !== "clear",
|
|
66
|
+
"text-black": fontColor === "black",
|
|
67
|
+
},
|
|
68
|
+
{}
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const getIconClasses = (iconOrder: string | undefined) => {
|
|
73
|
+
return classNames({
|
|
74
|
+
"flex items-center order-first": iconOrder === "first",
|
|
75
|
+
"flex items-center order-last pl-2": iconOrder === "last",
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const getSizeClasses = (
|
|
80
|
+
buttonWide: boolean | undefined,
|
|
81
|
+
size: string | undefined
|
|
82
|
+
) => {
|
|
83
|
+
return classNames(
|
|
84
|
+
{
|
|
85
|
+
"btn-wide": buttonWide === true,
|
|
86
|
+
"": buttonWide === false,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"text-xs": size === "xs",
|
|
90
|
+
"text-sm": size === "sm",
|
|
91
|
+
"text-md": size === "md",
|
|
92
|
+
"text-lg": size === "lg",
|
|
93
|
+
"text-xl": size === "xl",
|
|
94
|
+
[`text-${size}`]: size !== undefined,
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const getTextClasses = (
|
|
100
|
+
textStyle: string | undefined,
|
|
101
|
+
fontFamily: string | undefined
|
|
102
|
+
) => {
|
|
103
|
+
return classNames(
|
|
104
|
+
{
|
|
105
|
+
"font-normal": textStyle === "normal",
|
|
106
|
+
"font-bold": textStyle === "bold",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"font-sans": fontFamily === "sans",
|
|
110
|
+
"font-serif": fontFamily === "serif",
|
|
111
|
+
"font-mono": fontFamily === "mono",
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
interface ButtonClassProps {
|
|
117
|
+
buttonColorClasses: string;
|
|
118
|
+
buttonSizeClasses: string;
|
|
119
|
+
buttonShapeClasses: string;
|
|
120
|
+
textStyleClasses: string;
|
|
121
|
+
hoverClasses: string;
|
|
122
|
+
hasShadow: boolean;
|
|
123
|
+
customWidth?: string;
|
|
124
|
+
customHeight?: string;
|
|
125
|
+
additionalClasses?: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const getButtonClasses = ({
|
|
129
|
+
buttonColorClasses,
|
|
130
|
+
buttonSizeClasses,
|
|
131
|
+
buttonShapeClasses,
|
|
132
|
+
textStyleClasses,
|
|
133
|
+
hoverClasses,
|
|
134
|
+
hasShadow,
|
|
135
|
+
customWidth,
|
|
136
|
+
customHeight,
|
|
137
|
+
additionalClasses,
|
|
138
|
+
}: ButtonClassProps) => {
|
|
139
|
+
return classNames(
|
|
140
|
+
"border-2 p-1 rounded-full flex justify-center max-sm:text-xs",
|
|
141
|
+
buttonColorClasses,
|
|
142
|
+
buttonSizeClasses,
|
|
143
|
+
buttonShapeClasses,
|
|
144
|
+
textStyleClasses,
|
|
145
|
+
hoverClasses,
|
|
146
|
+
{
|
|
147
|
+
"shadow-md": hasShadow,
|
|
148
|
+
},
|
|
149
|
+
customWidth,
|
|
150
|
+
customHeight,
|
|
151
|
+
additionalClasses
|
|
152
|
+
);
|
|
153
|
+
};
|