@agilant/toga-blox 1.0.5 → 1.0.6
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 +42 -41
- 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/FormButton/FormButton.stories.tsx +282 -67
- package/src/components/FormButton/FormButton.tsx +46 -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
|
@@ -2,62 +2,36 @@ import React from "react";
|
|
|
2
2
|
import { Link } from "react-router-dom";
|
|
3
3
|
import { BadgeTypes } from "./Badge.types";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
getHoverClasses,
|
|
7
|
-
getIconClasses,
|
|
8
|
-
getColorClassNames,
|
|
9
|
-
getBadgeClasses,
|
|
10
|
-
getPillStyleClasses,
|
|
11
|
-
getBadgeSizeClasses,
|
|
12
|
-
getTagClasses,
|
|
13
|
-
} from "./badgeClassNames";
|
|
14
|
-
|
|
15
5
|
const Badge: React.FC<BadgeTypes> = ({
|
|
16
6
|
onClick,
|
|
17
|
-
color = "blue",
|
|
18
|
-
badgeSize,
|
|
19
7
|
cursorPointer = true,
|
|
20
8
|
type = "span",
|
|
21
9
|
to,
|
|
22
10
|
href,
|
|
23
11
|
testId,
|
|
24
|
-
hoverColor
|
|
12
|
+
hoverColor,
|
|
25
13
|
borderColor,
|
|
26
|
-
|
|
14
|
+
borderHoverColor,
|
|
15
|
+
borderWidth,
|
|
16
|
+
borderRadius,
|
|
17
|
+
backgroundColor,
|
|
27
18
|
hasMobileStyle,
|
|
28
19
|
mobileIcon,
|
|
29
20
|
mobileIconLabel,
|
|
30
|
-
|
|
21
|
+
iconSize,
|
|
22
|
+
hasLeftIcon,
|
|
23
|
+
hasRightIcon,
|
|
31
24
|
icon,
|
|
32
|
-
iconOrder = "first",
|
|
33
25
|
image,
|
|
34
|
-
tagStyle,
|
|
35
|
-
tagStyleIconColor,
|
|
36
26
|
text,
|
|
27
|
+
badgeContainerClasses,
|
|
37
28
|
}) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
badgeColorClasses,
|
|
45
|
-
hoverClasses,
|
|
46
|
-
badgeSizeClasses,
|
|
47
|
-
additionalClasses,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
let pillClasses = getPillStyleClasses({
|
|
51
|
-
badgeColorClasses,
|
|
52
|
-
hoverClasses,
|
|
53
|
-
additionalClasses,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
let tagClasses = getTagClasses({
|
|
57
|
-
badgeColorClasses,
|
|
58
|
-
hoverClasses,
|
|
59
|
-
additionalClasses,
|
|
60
|
-
});
|
|
29
|
+
const baseBadgeContainerClasses = "flex items-center justify-center px-[10px] py-[3px] rounded gap-[4px]";
|
|
30
|
+
const iconClasses = `${iconSize}`;
|
|
31
|
+
const badgeBackgroundClasses = `${backgroundColor} hover:${hoverColor}`;
|
|
32
|
+
const badgeBorderClasses = `${borderWidth} ${borderColor} ${borderRadius} hover:${borderHoverColor}`;
|
|
33
|
+
const cursorClasses = cursorPointer ? "cursor-pointer" : "";
|
|
34
|
+
const badgeClasses = `${cursorClasses} ${baseBadgeContainerClasses} ${badgeBorderClasses} ${badgeContainerClasses} ${badgeBackgroundClasses}`;
|
|
61
35
|
|
|
62
36
|
const handleClick = (
|
|
63
37
|
e: React.MouseEvent<HTMLAnchorElement | HTMLButtonElement>
|
|
@@ -67,11 +41,6 @@ const Badge: React.FC<BadgeTypes> = ({
|
|
|
67
41
|
};
|
|
68
42
|
|
|
69
43
|
const baseProps = {
|
|
70
|
-
className: image
|
|
71
|
-
? pillClasses.trim()
|
|
72
|
-
: tagStyle
|
|
73
|
-
? tagClasses.trim()
|
|
74
|
-
: badgeClasses.trim(),
|
|
75
44
|
onClick: handleClick,
|
|
76
45
|
type: type,
|
|
77
46
|
"data-testid": testId,
|
|
@@ -80,21 +49,33 @@ const Badge: React.FC<BadgeTypes> = ({
|
|
|
80
49
|
switch (type) {
|
|
81
50
|
case "href":
|
|
82
51
|
return (
|
|
83
|
-
|
|
84
|
-
{
|
|
85
|
-
|
|
52
|
+
<>
|
|
53
|
+
<a {...baseProps} href={href} className={`${badgeClasses}`}>
|
|
54
|
+
{renderContent()}
|
|
55
|
+
</a>
|
|
56
|
+
</>
|
|
86
57
|
);
|
|
87
58
|
case "to":
|
|
88
59
|
if (to) {
|
|
89
60
|
return (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
61
|
+
<>
|
|
62
|
+
<Link
|
|
63
|
+
{...baseProps}
|
|
64
|
+
to={to}
|
|
65
|
+
className={`${badgeClasses}`}
|
|
66
|
+
>
|
|
67
|
+
{renderContent()}
|
|
68
|
+
</Link>
|
|
69
|
+
</>
|
|
93
70
|
);
|
|
94
71
|
}
|
|
95
72
|
break;
|
|
96
73
|
case "span":
|
|
97
|
-
return
|
|
74
|
+
return (
|
|
75
|
+
<>
|
|
76
|
+
<span className={`${badgeClasses}`}>{renderContent()}</span>
|
|
77
|
+
</>
|
|
78
|
+
);
|
|
98
79
|
default:
|
|
99
80
|
return null;
|
|
100
81
|
}
|
|
@@ -103,7 +84,7 @@ const Badge: React.FC<BadgeTypes> = ({
|
|
|
103
84
|
return (
|
|
104
85
|
<>
|
|
105
86
|
{image && <span>{image}</span>}
|
|
106
|
-
{icon && (
|
|
87
|
+
{icon && hasLeftIcon && (
|
|
107
88
|
<span
|
|
108
89
|
className={`${iconClasses} max-md:hidden`}
|
|
109
90
|
data-testid="badge-icon"
|
|
@@ -122,13 +103,19 @@ const Badge: React.FC<BadgeTypes> = ({
|
|
|
122
103
|
</span>
|
|
123
104
|
)}
|
|
124
105
|
<div
|
|
125
|
-
className={` ${hasMobileStyle ? "max-md:hidden" : ""}
|
|
126
|
-
tagStyle ? "px-3" : ""
|
|
127
|
-
}`}
|
|
106
|
+
className={` ${hasMobileStyle ? "max-md:hidden" : ""} `}
|
|
128
107
|
data-testid="badge-text"
|
|
129
108
|
>
|
|
130
109
|
{text}
|
|
131
110
|
</div>
|
|
111
|
+
{icon && hasRightIcon && (
|
|
112
|
+
<span
|
|
113
|
+
className={`${iconClasses} max-md:hidden`}
|
|
114
|
+
data-testid="badge-icon"
|
|
115
|
+
>
|
|
116
|
+
<>{icon}</>
|
|
117
|
+
</span>
|
|
118
|
+
)}
|
|
132
119
|
</>
|
|
133
120
|
);
|
|
134
121
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { CSSProperties } from "react";
|
|
2
2
|
|
|
3
3
|
export interface BadgeTypes {
|
|
4
4
|
onClick?: (
|
|
@@ -7,22 +7,31 @@ export interface BadgeTypes {
|
|
|
7
7
|
text?: React.ReactNode;
|
|
8
8
|
cursorPointer?: boolean;
|
|
9
9
|
type: "href" | "to" | "span";
|
|
10
|
-
badgeSize?: string | undefined;
|
|
11
10
|
image?: React.ReactNode;
|
|
12
|
-
color?: string | undefined;
|
|
13
|
-
fontColor?: string | undefined;
|
|
14
11
|
borderColor?: string | undefined;
|
|
12
|
+
backgroundColor?: string | undefined;
|
|
13
|
+
borderWidth?: string | undefined;
|
|
14
|
+
borderRadius?: string | undefined;
|
|
15
|
+
borderHoverColor?: string | undefined;
|
|
16
|
+
hoverColor?: string;
|
|
15
17
|
to?: string;
|
|
16
18
|
href?: string;
|
|
17
|
-
hoverColor: string | undefined;
|
|
18
|
-
additionalClasses?: string;
|
|
19
19
|
hasMobileStyle?: boolean;
|
|
20
20
|
mobileIcon?: JSX.Element | Element | null;
|
|
21
21
|
mobileIconLabel?: string;
|
|
22
|
-
children?: React.ReactNode;
|
|
23
22
|
icon?: JSX.Element | Element | null;
|
|
23
|
+
hasLeftIcon?: boolean;
|
|
24
|
+
hasRightIcon?: boolean;
|
|
25
|
+
badgeContainerClasses?: string;
|
|
26
|
+
iconSize?: string | undefined;
|
|
27
|
+
|
|
28
|
+
// STORYBOOK PROP TYPES
|
|
29
|
+
color?: string | undefined;
|
|
30
|
+
badgeSize?: string | undefined;
|
|
24
31
|
iconOrder?: "first" | "last";
|
|
32
|
+
children?: React.ReactNode;
|
|
25
33
|
testId?: string;
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
textSize?: string;
|
|
35
|
+
fontColor?: string | undefined;
|
|
36
|
+
additionalClasses?: string;
|
|
28
37
|
}
|
|
@@ -12,7 +12,6 @@ export const getHoverClasses = (
|
|
|
12
12
|
"hover:bg-orange-700 hover:text-white": hoverColor === "orange",
|
|
13
13
|
"hover:bg-purple-700 hover:text-white": hoverColor === "purple",
|
|
14
14
|
"hover:bg-slate-950 hover:text-white": hoverColor === "black",
|
|
15
|
-
|
|
16
15
|
"": hoverColor === "none",
|
|
17
16
|
},
|
|
18
17
|
{
|
|
@@ -28,10 +27,8 @@ export const getIconClasses = (
|
|
|
28
27
|
tagStyleIconColor: string | undefined
|
|
29
28
|
) => {
|
|
30
29
|
return classNames({
|
|
31
|
-
"flex items-center order-first pr-2":
|
|
32
|
-
|
|
33
|
-
"flex items-center order-last pl-2":
|
|
34
|
-
iconOrder === "last" && tagStyle === false,
|
|
30
|
+
"flex items-center order-first pr-2": iconOrder === "first" && tagStyle === false,
|
|
31
|
+
"flex items-center order-last pl-2": iconOrder === "last" && tagStyle === false,
|
|
35
32
|
"text-white bg-red-500 flex justify-center items-center w-8 h-8 rounded-full max-md:text-black max-md:bg-transparent":
|
|
36
33
|
tagStyle === true && tagStyleIconColor === "red",
|
|
37
34
|
"text-white bg-blue-600 flex justify-center items-center w-8 h-8 rounded-full max-md:text-black max-md:bg-transparent":
|
|
@@ -47,18 +44,25 @@ export const getIconClasses = (
|
|
|
47
44
|
});
|
|
48
45
|
};
|
|
49
46
|
|
|
50
|
-
export const getBadgeSizeClasses = (
|
|
47
|
+
export const getBadgeSizeClasses = (
|
|
48
|
+
badgeSize: string | undefined,
|
|
49
|
+
width: number | undefined,
|
|
50
|
+
height: number | undefined
|
|
51
|
+
) => {
|
|
51
52
|
return classNames({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
53
|
+
[`w-${width}`]: width,
|
|
54
|
+
[`h-${height}`]: height,
|
|
55
|
+
"w-16 h-8 px-2 py-1 text-xs text-nowrap": badgeSize === "small",
|
|
56
|
+
"w-20 h-10 px-3 py-2 text-sm text-nowrap": badgeSize === "medium",
|
|
57
|
+
"w-24 h-12 px-4 py-3 text-base text-nowrap": badgeSize === "large",
|
|
55
58
|
});
|
|
56
59
|
};
|
|
57
60
|
|
|
58
61
|
export const getColorClassNames = (
|
|
59
62
|
color: string | undefined,
|
|
60
63
|
borderColor: string | undefined,
|
|
61
|
-
fontColor: string | undefined
|
|
64
|
+
fontColor: string | undefined,
|
|
65
|
+
backgroundColor: string | undefined
|
|
62
66
|
) => {
|
|
63
67
|
return classNames(
|
|
64
68
|
{
|
|
@@ -75,18 +79,33 @@ export const getColorClassNames = (
|
|
|
75
79
|
"border-blue-600": borderColor === "blue",
|
|
76
80
|
"border-teal-700": borderColor === "green",
|
|
77
81
|
"border-red-500": borderColor === "red",
|
|
78
|
-
"border-orange-500":
|
|
82
|
+
"border-orange-500": borderColor === "orange",
|
|
79
83
|
"border-slate-950": borderColor === "black",
|
|
80
|
-
"border-purple-500":
|
|
84
|
+
"border-purple-500": borderColor === "purple",
|
|
81
85
|
"border-transparent": borderColor === "none",
|
|
82
86
|
},
|
|
83
87
|
{
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
[`text-${fontColor}`]: fontColor,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
[`bg-${backgroundColor}`]: backgroundColor,
|
|
86
92
|
}
|
|
87
93
|
);
|
|
88
94
|
};
|
|
89
95
|
|
|
96
|
+
export const getBorderRadiusClasses = (borderRadius: string | undefined) => {
|
|
97
|
+
return classNames({
|
|
98
|
+
"rounded": borderRadius === "rounded",
|
|
99
|
+
"rounded-sm": borderRadius === "rounded-sm",
|
|
100
|
+
"rounded-md": borderRadius === "rounded-md",
|
|
101
|
+
"rounded-lg": borderRadius === "rounded-lg",
|
|
102
|
+
"rounded-xl": borderRadius === "rounded-xl",
|
|
103
|
+
"rounded-2xl": borderRadius === "rounded-2xl",
|
|
104
|
+
"rounded-3xl": borderRadius === "rounded-3xl",
|
|
105
|
+
"rounded-full": borderRadius === "rounded-full",
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
|
|
90
109
|
interface BadgeClassProps {
|
|
91
110
|
badgeColorClasses: string;
|
|
92
111
|
hoverClasses: string;
|
|
@@ -98,12 +117,14 @@ interface PillStyleClassProps {
|
|
|
98
117
|
badgeColorClasses: string;
|
|
99
118
|
hoverClasses: string;
|
|
100
119
|
additionalClasses?: string;
|
|
120
|
+
hasMobileStyle?: boolean;
|
|
101
121
|
}
|
|
102
122
|
|
|
103
123
|
interface TagProps {
|
|
104
124
|
badgeColorClasses: string;
|
|
105
125
|
hoverClasses: string;
|
|
106
126
|
additionalClasses?: string;
|
|
127
|
+
hasMobileStyle?: boolean;
|
|
107
128
|
}
|
|
108
129
|
|
|
109
130
|
export const getBadgeClasses = ({
|
|
@@ -113,7 +134,7 @@ export const getBadgeClasses = ({
|
|
|
113
134
|
badgeSizeClasses,
|
|
114
135
|
}: BadgeClassProps) => {
|
|
115
136
|
return classNames(
|
|
116
|
-
"badge border-2
|
|
137
|
+
"badge border-2 flex justify-center items-center",
|
|
117
138
|
badgeColorClasses,
|
|
118
139
|
hoverClasses,
|
|
119
140
|
additionalClasses,
|
|
@@ -126,9 +147,9 @@ export const getPillStyleClasses = ({
|
|
|
126
147
|
hoverClasses,
|
|
127
148
|
additionalClasses,
|
|
128
149
|
hasMobileStyle,
|
|
129
|
-
}: PillStyleClassProps
|
|
150
|
+
}: PillStyleClassProps) => {
|
|
130
151
|
return classNames(
|
|
131
|
-
"flex justify-center items-center w-full border-2 p-2
|
|
152
|
+
"flex justify-center items-center w-full border-2 p-2",
|
|
132
153
|
hasMobileStyle ? "max-md:w-12 max-md:h-12 max-md:p-4" : "",
|
|
133
154
|
badgeColorClasses,
|
|
134
155
|
hoverClasses,
|
|
@@ -141,9 +162,9 @@ export const getTagClasses = ({
|
|
|
141
162
|
hoverClasses,
|
|
142
163
|
additionalClasses,
|
|
143
164
|
hasMobileStyle,
|
|
144
|
-
}: TagProps
|
|
165
|
+
}: TagProps) => {
|
|
145
166
|
return classNames(
|
|
146
|
-
"flex justify-between items-center w-fit border-2
|
|
167
|
+
"flex justify-between items-center w-fit border-2",
|
|
147
168
|
hasMobileStyle ? "max-md:w-12 max-md:h-6 max-md:p-2" : "",
|
|
148
169
|
badgeColorClasses,
|
|
149
170
|
hoverClasses,
|
|
@@ -109,11 +109,11 @@ const HorizontalCardTemplate = ({ data }: { data: DataTypes }) => {
|
|
|
109
109
|
<div className="pr-2 text-xs">
|
|
110
110
|
{data.inStock === true
|
|
111
111
|
? getFontAwesomeIcon(
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
data.inStockProps.inStockIcon
|
|
113
|
+
)
|
|
114
114
|
: getFontAwesomeIcon(
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
data.inStockProps.outOfStockIcon
|
|
116
|
+
)}
|
|
117
117
|
</div>
|
|
118
118
|
<Text
|
|
119
119
|
tag={data.inStockProps.tag as TagName}
|
|
@@ -167,7 +167,7 @@ const HorizontalCardTemplate = ({ data }: { data: DataTypes }) => {
|
|
|
167
167
|
</div>
|
|
168
168
|
<FormButton
|
|
169
169
|
text={data.buttonProps.text}
|
|
170
|
-
|
|
170
|
+
backgroundColor={data.buttonProps.color}
|
|
171
171
|
fontColor={data.buttonProps.fontColor}
|
|
172
172
|
size={data.buttonProps.size}
|
|
173
173
|
shape={data.buttonProps.shape}
|
|
@@ -84,11 +84,11 @@ const VerticalCardTemplate = ({ data }: { data: DataTypes }) => {
|
|
|
84
84
|
<div className="pr-2 text-xs">
|
|
85
85
|
{data.inStock === true
|
|
86
86
|
? getFontAwesomeIcon(
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
data.inStockProps.inStockIcon
|
|
88
|
+
)
|
|
89
89
|
: getFontAwesomeIcon(
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
data.inStockProps.outOfStockIcon
|
|
91
|
+
)}
|
|
92
92
|
</div>
|
|
93
93
|
<Text
|
|
94
94
|
tag={data.inStockProps.tag as TagName}
|
|
@@ -136,7 +136,7 @@ const VerticalCardTemplate = ({ data }: { data: DataTypes }) => {
|
|
|
136
136
|
</div>
|
|
137
137
|
<FormButton
|
|
138
138
|
text={data.buttonProps.text}
|
|
139
|
-
|
|
139
|
+
backgroundColor={data.buttonProps.color}
|
|
140
140
|
fontColor={data.buttonProps.fontColor}
|
|
141
141
|
size={data.buttonProps.size}
|
|
142
142
|
shape={data.buttonProps.shape}
|