@agilant/toga-blox 1.0.5 → 1.0.7
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/.gitattributes +5 -0
- package/README.md +3 -1
- package/package.json +15 -14
- package/src/components/Badge/Badge.stories.tsx +175 -126
- package/src/components/Badge/Badge.test.tsx +20 -29
- package/src/components/Badge/Badge.tsx +44 -57
- package/src/components/Badge/Badge.types.tsx +18 -9
- package/src/components/Badge/badgeClassNames.tsx +40 -19
- package/src/components/Card/templates/HorizontalCardTemplate.tsx +5 -5
- package/src/components/Card/templates/VerticalCardTemplate.tsx +5 -5
- package/src/components/CounterButton/CounterButton.stories.tsx +91 -0
- package/src/components/CounterButton/CounterButton.tsx +100 -0
- package/src/components/CounterButton/CounterButton.types.ts +12 -0
- package/src/components/FormButton/FormButton.stories.tsx +282 -67
- package/src/components/FormButton/FormButton.test.tsx +4 -4
- package/src/components/FormButton/FormButton.tsx +45 -67
- package/src/components/FormButton/FormButton.types.ts +8 -7
- package/src/components/Header/Header.stories.tsx +20 -23
- package/src/components/Header/Header.test.tsx +0 -1
- package/src/components/Hero/Hero.tsx +3 -3
- package/src/components/Icon/Icon.stories.tsx +12 -12
- package/src/components/Icon/Icon.test.tsx +3 -3
- package/src/components/Icon/Icon.tsx +9 -9
- package/src/components/Image/Image.tsx +10 -12
- package/src/components/Image/declarations.d.ts +24 -0
- package/src/components/Input/Input.stories.tsx +116 -253
- package/src/components/Input/Input.test.tsx +4 -4
- package/src/components/Input/Input.tsx +5 -7
- package/src/components/Nav/DUMMYNAVDATA.json +1 -1
- package/src/components/Page/ViewPageTemplate.stories.tsx +77 -80
- package/src/components/Text/Text.stories.tsx +21 -31
- package/src/components/Text/Text.tsx +12 -63
- package/src/components/Text/Text.types.ts +4 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Meta, StoryFn } from "@storybook/react";
|
|
2
|
-
import FormButton from "
|
|
2
|
+
import FormButton from "./FormButton";
|
|
3
3
|
import type { ButtonTypes } from "./FormButton.types";
|
|
4
4
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
5
|
-
import { faCoffee } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
+
import { faBoxes, faClipboardList, faTags, faPlusSquare, faCoffee, faTrash, faArrowRight } from "@fortawesome/free-solid-svg-icons";
|
|
6
6
|
import Text from "../Text/Text";
|
|
7
7
|
|
|
8
8
|
export default {
|
|
@@ -15,84 +15,148 @@ export default {
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
text: {
|
|
18
|
-
control: "
|
|
19
|
-
description:
|
|
18
|
+
control: "none",
|
|
19
|
+
description:
|
|
20
|
+
"The main text displayed on the button. Passed through the Text component. Text component controls styles of text",
|
|
20
21
|
},
|
|
21
22
|
textStyle: {
|
|
22
|
-
control: "
|
|
23
|
-
options: ["normal", "bold"],
|
|
24
|
-
|
|
23
|
+
control: "none",
|
|
24
|
+
options: ["font-normal", "font-bold"],
|
|
25
|
+
table: {
|
|
26
|
+
disable: true,
|
|
27
|
+
},
|
|
28
|
+
description:
|
|
29
|
+
"The font weight of the button text. *Storybook prop only.",
|
|
25
30
|
},
|
|
26
31
|
fontFamily: {
|
|
27
|
-
control: "
|
|
28
|
-
options: ["sans", "serif", "mono"],
|
|
29
|
-
|
|
32
|
+
control: "none",
|
|
33
|
+
options: ["font-sans", "font-serif", "font-mono"],
|
|
34
|
+
table: {
|
|
35
|
+
disable: true,
|
|
36
|
+
},
|
|
37
|
+
description:
|
|
38
|
+
"The font family of the button text. *Storybook prop only.",
|
|
30
39
|
},
|
|
31
|
-
|
|
32
|
-
control: "
|
|
33
|
-
options: [
|
|
34
|
-
|
|
40
|
+
backgroundColor: {
|
|
41
|
+
control: "none",
|
|
42
|
+
options: [
|
|
43
|
+
"bg-blue-600",
|
|
44
|
+
"bg-green-600",
|
|
45
|
+
"bg-gray-600",
|
|
46
|
+
"bg-transparent",
|
|
47
|
+
],
|
|
48
|
+
description:
|
|
49
|
+
"The background color of the button. Use Tailwind CSS color classes.",
|
|
35
50
|
},
|
|
36
51
|
fontColor: {
|
|
37
|
-
control: "
|
|
38
|
-
options: ["white", "black"],
|
|
39
|
-
|
|
52
|
+
control: "none",
|
|
53
|
+
options: ["text-white", "text-black"],
|
|
54
|
+
table: {
|
|
55
|
+
disable: true,
|
|
56
|
+
},
|
|
57
|
+
description:
|
|
58
|
+
"The text color of the button. Use Tailwind CSS color classes. *Storybook prop only.",
|
|
40
59
|
},
|
|
41
60
|
size: {
|
|
42
|
-
control: "
|
|
43
|
-
options: ["xs", "sm", "md", "lg", "xl"],
|
|
44
|
-
|
|
61
|
+
control: "none",
|
|
62
|
+
options: ["text-xs", "text-sm", "text-md", "text-lg", "text-xl"],
|
|
63
|
+
table: {
|
|
64
|
+
disable: true,
|
|
65
|
+
},
|
|
66
|
+
description:
|
|
67
|
+
"The size of the text on the button. Use Tailwind CSS text size classes. *Storybook prop only.",
|
|
45
68
|
},
|
|
46
69
|
borderColor: {
|
|
47
|
-
control: "
|
|
48
|
-
options: [
|
|
49
|
-
|
|
70
|
+
control: "none",
|
|
71
|
+
options: [
|
|
72
|
+
"border-blue-600",
|
|
73
|
+
"border-green-600",
|
|
74
|
+
"border-gray-600",
|
|
75
|
+
"border-none",
|
|
76
|
+
],
|
|
77
|
+
description:
|
|
78
|
+
"The color of the border of the button. Use Tailwind CSS border color classes.",
|
|
50
79
|
},
|
|
51
80
|
shape: {
|
|
52
|
-
control: "
|
|
53
|
-
options: [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
control: "none",
|
|
82
|
+
options: [
|
|
83
|
+
"rounded-none",
|
|
84
|
+
"rounded-md",
|
|
85
|
+
"rounded-full",
|
|
86
|
+
"border-b-6 border-b-black",
|
|
87
|
+
],
|
|
88
|
+
description:
|
|
89
|
+
"The shape of the button. Use Tailwind CSS border radius classes.",
|
|
59
90
|
},
|
|
60
91
|
hoverBackground: {
|
|
61
|
-
control: "
|
|
62
|
-
options: [
|
|
63
|
-
|
|
92
|
+
control: "none",
|
|
93
|
+
options: [
|
|
94
|
+
"hover:bg-blue-700",
|
|
95
|
+
"hover:bg-green-700",
|
|
96
|
+
"hover:bg-gray-700",
|
|
97
|
+
"hover:bg-transparent",
|
|
98
|
+
],
|
|
99
|
+
description:
|
|
100
|
+
"The background color of the button on hover. Use Tailwind CSS color classes.",
|
|
64
101
|
},
|
|
65
102
|
hoverBorderColor: {
|
|
66
|
-
control: "
|
|
67
|
-
options: [
|
|
68
|
-
|
|
103
|
+
control: "none",
|
|
104
|
+
options: [
|
|
105
|
+
"hover:border-blue-700",
|
|
106
|
+
"hover:border-green-700",
|
|
107
|
+
"hover:border-gray-700",
|
|
108
|
+
"hover:border-transparent",
|
|
109
|
+
],
|
|
110
|
+
description:
|
|
111
|
+
"The border color of the button on hover. Use Tailwind CSS border color classes.",
|
|
69
112
|
},
|
|
70
113
|
hoverFontColor: {
|
|
71
|
-
control: "
|
|
72
|
-
options: [
|
|
73
|
-
|
|
114
|
+
control: "none",
|
|
115
|
+
options: [
|
|
116
|
+
"hover:text-blue-700",
|
|
117
|
+
"hover:text-green-700",
|
|
118
|
+
"hover:text-gray-700",
|
|
119
|
+
"hover:text-black",
|
|
120
|
+
],
|
|
121
|
+
description:
|
|
122
|
+
"The text color of the button on hover. Use Tailwind CSS color classes.",
|
|
74
123
|
},
|
|
75
124
|
hoverUnderline: {
|
|
76
|
-
control: "
|
|
125
|
+
control: "none",
|
|
77
126
|
description: "Whether the text is underlined on hover.",
|
|
78
127
|
},
|
|
79
128
|
hoverBorder: {
|
|
80
|
-
control: "
|
|
81
|
-
description: "
|
|
129
|
+
control: "none",
|
|
130
|
+
description: "Whether there is a border on hover.",
|
|
82
131
|
},
|
|
83
132
|
icon: {
|
|
84
133
|
table: {
|
|
85
134
|
disable: true,
|
|
86
135
|
},
|
|
87
136
|
},
|
|
137
|
+
color: {
|
|
138
|
+
table: {
|
|
139
|
+
disable: true,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
88
142
|
as: {
|
|
89
143
|
table: {
|
|
90
144
|
disable: true,
|
|
91
145
|
},
|
|
92
146
|
},
|
|
147
|
+
buttonWide: {
|
|
148
|
+
table: {
|
|
149
|
+
disable: true,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
93
152
|
iconOrder: {
|
|
94
|
-
control: "
|
|
153
|
+
control: "none",
|
|
95
154
|
options: ["first", "last"],
|
|
155
|
+
table: {
|
|
156
|
+
disable: true,
|
|
157
|
+
},
|
|
158
|
+
description:
|
|
159
|
+
"The order of the icon in the button. *Storybook prop only.",
|
|
96
160
|
},
|
|
97
161
|
type: {
|
|
98
162
|
table: {
|
|
@@ -120,12 +184,21 @@ export default {
|
|
|
120
184
|
},
|
|
121
185
|
},
|
|
122
186
|
isDisabled: {
|
|
123
|
-
control: "
|
|
124
|
-
description:
|
|
187
|
+
control: "none",
|
|
188
|
+
description:
|
|
189
|
+
"Whether the button is disabled and cannot be clicked.",
|
|
125
190
|
},
|
|
126
191
|
hasShadow: {
|
|
127
|
-
control: "
|
|
128
|
-
description: "
|
|
192
|
+
control: "none",
|
|
193
|
+
description: "Whether the button has a shadow.",
|
|
194
|
+
},
|
|
195
|
+
customWidth: {
|
|
196
|
+
control: "none",
|
|
197
|
+
description: "The custom width of the button.",
|
|
198
|
+
},
|
|
199
|
+
customHeight: {
|
|
200
|
+
control: "none",
|
|
201
|
+
description: "The custom height of the button.",
|
|
129
202
|
},
|
|
130
203
|
},
|
|
131
204
|
tags: ["autodocs"],
|
|
@@ -139,14 +212,13 @@ const Template: StoryFn<ButtonTypes> = (args) => <FormButton {...args} />;
|
|
|
139
212
|
export const Default = Template.bind({});
|
|
140
213
|
Default.args = {
|
|
141
214
|
text: "Default Button",
|
|
142
|
-
|
|
143
|
-
fontColor: "white",
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
hoverBorderColor: "blue",
|
|
215
|
+
backgroundColor: "bg-blue-600",
|
|
216
|
+
fontColor: "text-white",
|
|
217
|
+
borderColor: "border-none",
|
|
218
|
+
shape: "rounded-md",
|
|
219
|
+
hoverBackground: "bg-blue-700",
|
|
220
|
+
hoverFontColor: "text-black",
|
|
221
|
+
hoverBorderColor: "border-blue-700",
|
|
150
222
|
hoverUnderline: false,
|
|
151
223
|
onClick: () => alert("Button clicked!"),
|
|
152
224
|
additionalClasses: "p-2",
|
|
@@ -155,20 +227,19 @@ Default.args = {
|
|
|
155
227
|
export const Compass = Template.bind({});
|
|
156
228
|
Compass.args = {
|
|
157
229
|
text: <Text size={""} color={""} text={"Compass Button"} fontFamily={""} />,
|
|
158
|
-
|
|
159
|
-
fontColor: "
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
hoverBorderColor: "green",
|
|
230
|
+
backgroundColor: "bg-green-400",
|
|
231
|
+
fontColor: "text-black",
|
|
232
|
+
shape: "rounded-md",
|
|
233
|
+
borderColor: "border-none",
|
|
234
|
+
hoverBackground: "bg-green-700",
|
|
235
|
+
hoverFontColor: "text-white",
|
|
236
|
+
hoverBorderColor: "border-green-900",
|
|
166
237
|
hoverUnderline: false,
|
|
167
238
|
onClick: () => alert("Button clicked!"),
|
|
168
239
|
as: "a",
|
|
240
|
+
additionalClasses: "p-2",
|
|
169
241
|
};
|
|
170
242
|
|
|
171
|
-
// Story for a Disabled Button
|
|
172
243
|
export const Disabled = Template.bind({});
|
|
173
244
|
Disabled.args = {
|
|
174
245
|
...Default.args,
|
|
@@ -191,9 +262,153 @@ WithIcon.args = {
|
|
|
191
262
|
/>
|
|
192
263
|
),
|
|
193
264
|
icon: <FontAwesomeIcon icon={faCoffee} />,
|
|
194
|
-
shape: "
|
|
195
|
-
buttonWide: true,
|
|
265
|
+
shape: "rounded-none",
|
|
196
266
|
hoverUnderline: false,
|
|
197
267
|
onClick: () => alert("Button clicked!"),
|
|
198
|
-
// additionalClasses: "flex items-center justify-between p-2",
|
|
199
268
|
};
|
|
269
|
+
|
|
270
|
+
export const IconOnly = Template.bind({});
|
|
271
|
+
IconOnly.args = {
|
|
272
|
+
fontColor: "text-red-600",
|
|
273
|
+
shape: "rounded",
|
|
274
|
+
hoverBackground: "bg-blue-700",
|
|
275
|
+
hoverFontColor: "text-white",
|
|
276
|
+
hoverBorderColor: "border-blue-700",
|
|
277
|
+
hoverUnderline: false,
|
|
278
|
+
icon: <FontAwesomeIcon icon={faTrash} />,
|
|
279
|
+
additionalClasses: "px-4 py-3 bg-gray-50",
|
|
280
|
+
onClick: () => alert("Icon button clicked!"),
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export const ClearCartButton = Template.bind({});
|
|
284
|
+
ClearCartButton.args = {
|
|
285
|
+
text: <Text size={""} color={""} text={"Clear Cart"} fontFamily={""} />,
|
|
286
|
+
fontColor: "text-red-600",
|
|
287
|
+
size: "text-md",
|
|
288
|
+
shape: "rounded-md",
|
|
289
|
+
hoverBackground: "bg-blue-700",
|
|
290
|
+
hoverFontColor: "text-white",
|
|
291
|
+
hoverBorderColor: "border-red-700",
|
|
292
|
+
hoverUnderline: false,
|
|
293
|
+
icon: <FontAwesomeIcon icon={faTrash} />,
|
|
294
|
+
iconOrder: "first",
|
|
295
|
+
additionalClasses:
|
|
296
|
+
"px-5 py-6 bg-gray-50 border-red-500 gap-2",
|
|
297
|
+
onClick: () => alert("Cart Cleared!"),
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export const RightIconButton = Template.bind({});
|
|
301
|
+
RightIconButton.args = {
|
|
302
|
+
text: (
|
|
303
|
+
<Text size={""} color={"text-blue-600"} text={"Next"} fontFamily={""} />
|
|
304
|
+
),
|
|
305
|
+
backgroundColor: "bg-gray-700",
|
|
306
|
+
shape: "rounded-md",
|
|
307
|
+
hoverBackground: "bg-blue-700",
|
|
308
|
+
hoverFontColor: "text-white",
|
|
309
|
+
hoverBorderColor: "border-blue-700",
|
|
310
|
+
hoverUnderline: false,
|
|
311
|
+
icon: <FontAwesomeIcon icon={faArrowRight} />,
|
|
312
|
+
additionalClasses:
|
|
313
|
+
"px-6 py-3 bg-gray-50 border-red-500 gap-2 flex-row-reverse",
|
|
314
|
+
onClick: () => alert("Cart Cleared!"),
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export const ConfirmRequestButton = Template.bind({});
|
|
318
|
+
ConfirmRequestButton.args = {
|
|
319
|
+
text: (
|
|
320
|
+
<Text size={""} color={""} text={"CONFIRM REQUEST"} fontFamily={""} />
|
|
321
|
+
),
|
|
322
|
+
backgroundColor: "bg-[#9ca3af]",
|
|
323
|
+
fontColor: "text-white",
|
|
324
|
+
size: "text-md",
|
|
325
|
+
borderColor: "border-none",
|
|
326
|
+
shape: "rounded-md",
|
|
327
|
+
hoverUnderline: false,
|
|
328
|
+
isDisabled: true,
|
|
329
|
+
additionalClasses: "py-3 px-6",
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export const FourButtonsRow = Template.bind({});
|
|
333
|
+
FourButtonsRow.args = {};
|
|
334
|
+
FourButtonsRow.decorators = [
|
|
335
|
+
(Story) => (
|
|
336
|
+
<div className="flex divide-x divide-gray-200 rounded-md overflow-hidden border border-gray-200">
|
|
337
|
+
<FormButton
|
|
338
|
+
text="All"
|
|
339
|
+
backgroundColor="bg-teal-600"
|
|
340
|
+
fontColor="text-white"
|
|
341
|
+
size="text-md"
|
|
342
|
+
borderColor="border-gray-200"
|
|
343
|
+
shape="rounded-none"
|
|
344
|
+
hoverBackground="bg-teal-600"
|
|
345
|
+
hoverFontColor="text-black"
|
|
346
|
+
hoverBorderColor="border-none"
|
|
347
|
+
hoverUnderline={false}
|
|
348
|
+
additionalClasses="py-2 px-4"
|
|
349
|
+
onClick={() => alert("All clicked!")}
|
|
350
|
+
/>
|
|
351
|
+
|
|
352
|
+
<FormButton
|
|
353
|
+
text={
|
|
354
|
+
<>
|
|
355
|
+
<FontAwesomeIcon icon={faBoxes} className="mr-2" />{" "}
|
|
356
|
+
Bundles
|
|
357
|
+
</>
|
|
358
|
+
}
|
|
359
|
+
backgroundColor="bg-white"
|
|
360
|
+
fontColor="text-teal-600"
|
|
361
|
+
size="text-md"
|
|
362
|
+
borderColor="border-gray-200"
|
|
363
|
+
shape="rounded-none"
|
|
364
|
+
hoverBackground="bg-teal-600"
|
|
365
|
+
hoverFontColor="text-black"
|
|
366
|
+
hoverBorderColor="border-none"
|
|
367
|
+
hoverUnderline={false}
|
|
368
|
+
additionalClasses="py-2 px-4"
|
|
369
|
+
onClick={() => alert("Bundles clicked!")}
|
|
370
|
+
/>
|
|
371
|
+
<FormButton
|
|
372
|
+
text={
|
|
373
|
+
<>
|
|
374
|
+
<FontAwesomeIcon
|
|
375
|
+
icon={faClipboardList}
|
|
376
|
+
className="mr-2"
|
|
377
|
+
/>{" "}
|
|
378
|
+
Categories
|
|
379
|
+
</>
|
|
380
|
+
}
|
|
381
|
+
backgroundColor="bg-white"
|
|
382
|
+
fontColor="text-teal-600"
|
|
383
|
+
size="text-md"
|
|
384
|
+
borderColor="border-gray-200"
|
|
385
|
+
shape="rounded-none"
|
|
386
|
+
hoverBackground="bg-teal-600"
|
|
387
|
+
hoverFontColor="text-black"
|
|
388
|
+
hoverBorderColor="border-none"
|
|
389
|
+
hoverUnderline={false}
|
|
390
|
+
additionalClasses="py-2 px-4"
|
|
391
|
+
onClick={() => alert("Categories clicked!")}
|
|
392
|
+
/>
|
|
393
|
+
<FormButton
|
|
394
|
+
text={
|
|
395
|
+
<>
|
|
396
|
+
<FontAwesomeIcon icon={faPlusSquare} className="mr-2" />{" "}
|
|
397
|
+
Custom Categories
|
|
398
|
+
</>
|
|
399
|
+
}
|
|
400
|
+
backgroundColor="bg-white"
|
|
401
|
+
fontColor="text-teal-600"
|
|
402
|
+
size="text-md"
|
|
403
|
+
borderColor="border-gray-200"
|
|
404
|
+
shape="rounded-none"
|
|
405
|
+
hoverBackground="bg-teal-600"
|
|
406
|
+
hoverFontColor="text-black"
|
|
407
|
+
hoverBorderColor="border-none"
|
|
408
|
+
hoverUnderline={false}
|
|
409
|
+
additionalClasses="py-2 px-4"
|
|
410
|
+
onClick={() => alert("Custom Categories clicked!")}
|
|
411
|
+
/>
|
|
412
|
+
</div>
|
|
413
|
+
),
|
|
414
|
+
];
|
|
@@ -9,7 +9,7 @@ describe("Button", () => {
|
|
|
9
9
|
<MemoryRouter>
|
|
10
10
|
<Button
|
|
11
11
|
text="Default Button"
|
|
12
|
-
|
|
12
|
+
backgroundColor="green"
|
|
13
13
|
size="md"
|
|
14
14
|
shape="outline"
|
|
15
15
|
/>
|
|
@@ -24,7 +24,7 @@ describe("Button", () => {
|
|
|
24
24
|
<MemoryRouter>
|
|
25
25
|
<Button
|
|
26
26
|
text="Clickable Button"
|
|
27
|
-
|
|
27
|
+
backgroundColor="green"
|
|
28
28
|
size="md"
|
|
29
29
|
shape="outline"
|
|
30
30
|
onClick={mockOnClick}
|
|
@@ -40,7 +40,7 @@ describe("Button", () => {
|
|
|
40
40
|
<MemoryRouter>
|
|
41
41
|
<Button
|
|
42
42
|
text="Default Button"
|
|
43
|
-
|
|
43
|
+
backgroundColor="green"
|
|
44
44
|
size="md"
|
|
45
45
|
shape="outline"
|
|
46
46
|
/>
|
|
@@ -58,7 +58,7 @@ describe("Disabled Button", () => {
|
|
|
58
58
|
<MemoryRouter>
|
|
59
59
|
<Button
|
|
60
60
|
text="Disabled Button"
|
|
61
|
-
|
|
61
|
+
backgroundColor="green"
|
|
62
62
|
size="md"
|
|
63
63
|
shape="outline"
|
|
64
64
|
isDisabled
|
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
import React, { ElementType } from "react";
|
|
2
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";
|
|
3
|
+
import type { ButtonTypes } from "./FormButton.types";
|
|
12
4
|
|
|
13
|
-
const
|
|
5
|
+
const FormButton: React.FC<ButtonTypes> = ({
|
|
14
6
|
onClick,
|
|
15
7
|
text,
|
|
16
|
-
textStyle = "
|
|
17
|
-
fontFamily = "sans",
|
|
18
|
-
|
|
19
|
-
fontColor,
|
|
20
|
-
size = "md",
|
|
8
|
+
textStyle = "font-normal",
|
|
9
|
+
fontFamily = "font-sans",
|
|
10
|
+
backgroundColor = "bg-blue-600",
|
|
11
|
+
fontColor = "text-white",
|
|
12
|
+
size = "text-md",
|
|
21
13
|
customWidth,
|
|
22
14
|
customHeight,
|
|
23
|
-
shape = "
|
|
24
|
-
|
|
25
|
-
borderColor,
|
|
15
|
+
shape = "rounded-md",
|
|
16
|
+
borderColor = "border-transparent",
|
|
26
17
|
icon,
|
|
27
18
|
iconOrder = "first",
|
|
28
19
|
additionalClasses = "",
|
|
@@ -31,48 +22,40 @@ const Button: React.FC<ButtonTypes> = ({
|
|
|
31
22
|
href,
|
|
32
23
|
tooltip,
|
|
33
24
|
isDisabled = false,
|
|
34
|
-
hasShadow
|
|
35
|
-
as: Element = "
|
|
36
|
-
hoverBackground,
|
|
37
|
-
hoverFontColor,
|
|
38
|
-
hoverUnderline,
|
|
39
|
-
hoverBorderColor,
|
|
25
|
+
hasShadow,
|
|
26
|
+
as: Element = "button",
|
|
27
|
+
hoverBackground = "",
|
|
28
|
+
hoverFontColor = "",
|
|
29
|
+
hoverUnderline = false,
|
|
30
|
+
hoverBorderColor = "",
|
|
40
31
|
...props
|
|
41
32
|
}) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
hoverFontColor
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
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);
|
|
33
|
+
const baseFormButtonClasses = "flex items-center justify-center";
|
|
34
|
+
const hoverClasses = !isDisabled
|
|
35
|
+
? `hover:${hoverBackground} hover:${hoverFontColor} ${hoverUnderline ? "hover:underline hover:underline-offset-4" : ""
|
|
36
|
+
} hover:${hoverBorderColor}`
|
|
37
|
+
: "";
|
|
38
|
+
const buttonColorClasses = `${backgroundColor} ${fontColor} ${borderColor}`;
|
|
39
|
+
const cursorClasses = isDisabled
|
|
40
|
+
? "cursor-not-allowed opacity-50"
|
|
41
|
+
: "cursor-pointer";
|
|
42
|
+
const textStyleClasses = `${textStyle} ${fontFamily}`;
|
|
43
|
+
const buttonShapeClasses = shape;
|
|
44
|
+
const iconClasses =
|
|
45
|
+
iconOrder === "first" ? "order-first" : "order-last pl-2";
|
|
62
46
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
47
|
+
const buttonClasses = `
|
|
48
|
+
${baseFormButtonClasses}
|
|
49
|
+
${buttonColorClasses}
|
|
50
|
+
${buttonShapeClasses}
|
|
51
|
+
${textStyleClasses}
|
|
52
|
+
${hoverClasses}
|
|
53
|
+
${cursorClasses}
|
|
54
|
+
${hasShadow ? hasShadow : ""}
|
|
55
|
+
${customWidth}
|
|
56
|
+
${customHeight}
|
|
57
|
+
${additionalClasses}
|
|
58
|
+
`.trim();
|
|
76
59
|
|
|
77
60
|
const handleClick = (
|
|
78
61
|
e: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>
|
|
@@ -83,34 +66,29 @@ const Button: React.FC<ButtonTypes> = ({
|
|
|
83
66
|
}
|
|
84
67
|
onClick?.(e);
|
|
85
68
|
};
|
|
86
|
-
|
|
69
|
+
|
|
87
70
|
const baseProps = {
|
|
88
|
-
className: buttonClasses
|
|
71
|
+
className: buttonClasses,
|
|
89
72
|
onClick: handleClick,
|
|
90
73
|
type: type,
|
|
91
74
|
"aria-disabled": isDisabled ? "true" : "false",
|
|
92
75
|
"data-tooltip": tooltip,
|
|
93
76
|
};
|
|
94
|
-
|
|
77
|
+
|
|
95
78
|
if (Element === "a") {
|
|
96
79
|
props = { ...baseProps, href: href };
|
|
97
80
|
} else if (Element === "link") {
|
|
98
81
|
props = { ...baseProps, to: to };
|
|
99
82
|
} else if (Element === "button") {
|
|
100
|
-
// For 'button', the baseProps already contain all necessary properties
|
|
101
83
|
props = { ...baseProps };
|
|
102
84
|
}
|
|
103
85
|
|
|
104
86
|
return (
|
|
105
87
|
<Element {...props}>
|
|
106
|
-
{icon &&
|
|
107
|
-
<span className={`${iconClasses} ${additionalClasses}`}>
|
|
108
|
-
{icon}
|
|
109
|
-
</span>
|
|
110
|
-
)}
|
|
88
|
+
{icon && <span className={iconClasses}>{icon}</span>}
|
|
111
89
|
{text}
|
|
112
90
|
</Element>
|
|
113
91
|
);
|
|
114
92
|
};
|
|
115
93
|
|
|
116
|
-
export default
|
|
94
|
+
export default FormButton;
|
|
@@ -5,28 +5,29 @@ export interface ButtonTypes {
|
|
|
5
5
|
e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>
|
|
6
6
|
) => void;
|
|
7
7
|
text?: string | JSX.Element;
|
|
8
|
-
|
|
9
|
-
fontColor?: string;
|
|
8
|
+
backgroundColor?: string;
|
|
10
9
|
borderColor?: string;
|
|
11
|
-
size?: "xs" | "sm" | "md" | "lg" | "xl" | string;
|
|
12
|
-
textStyle?: "thin" | "light" | "normal" | "semibold" | "bold";
|
|
13
10
|
fontFamily?: "sans" | "mono" | "serif" | string;
|
|
14
11
|
customWidth?: string;
|
|
15
12
|
customHeight?: string;
|
|
16
13
|
shape?: "cornered" | "semiRounded" | "rounded" | "underline" | string;
|
|
17
14
|
icon?: JSX.Element | null;
|
|
18
|
-
iconOrder?: "first" | "last";
|
|
19
15
|
type?: "submit" | "reset" | "button";
|
|
20
16
|
to?: string;
|
|
21
17
|
href?: string;
|
|
22
18
|
tooltip?: string;
|
|
23
19
|
additionalClasses?: string;
|
|
24
20
|
isDisabled?: boolean;
|
|
25
|
-
hasShadow?:
|
|
21
|
+
hasShadow?: string;
|
|
26
22
|
as?: ElementType;
|
|
27
23
|
hoverBackground?: string;
|
|
28
24
|
hoverFontColor?: string;
|
|
29
25
|
hoverUnderline?: boolean;
|
|
30
26
|
hoverBorderColor?: string;
|
|
31
|
-
|
|
27
|
+
|
|
28
|
+
// STORYBOOK PROPS
|
|
29
|
+
size?: "xs" | "sm" | "md" | "lg" | "xl" | string;
|
|
30
|
+
textStyle?: "thin" | "light" | "normal" | "semibold" | "bold";
|
|
31
|
+
iconOrder?: "first" | "last";
|
|
32
|
+
fontColor?: string;
|
|
32
33
|
}
|