@agilant/toga-blox 1.0.17 → 1.0.19
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/README.md
CHANGED
|
@@ -33,6 +33,10 @@ To stop the services: docker-compose down
|
|
|
33
33
|
|
|
34
34
|
To run tests: docker-compose run --rm test
|
|
35
35
|
|
|
36
|
+
Running App outside of Docker
|
|
37
|
+
|
|
38
|
+
To run test coverage report: npx vitest run src/components/{COMPONENT NAME HERE} --coverage
|
|
39
|
+
|
|
36
40
|
📚 Dependencies
|
|
37
41
|
Toga-Blox is built using:
|
|
38
42
|
|
|
@@ -4,6 +4,6 @@ const Badge = ({ borderColor, borderWidth, borderRadius, backgroundColor, hasMob
|
|
|
4
4
|
const badgeBackgroundClasses = `${backgroundColor}`;
|
|
5
5
|
const badgeBorderClasses = `${borderWidth} ${borderColor} ${borderRadius}`;
|
|
6
6
|
const badgeClasses = `inline-flex items-center ${badgeBorderClasses} ${badgeBackgroundClasses} ${badgeContainerClasses}`;
|
|
7
|
-
return (_jsxs("span", { className: badgeClasses, children: [image && _jsx("span", { className: "mr-2", children: image }), icon && hasLeftIcon && (_jsx("span", { className: `${iconClasses} max-md:hidden mr-2`, children: icon })), mobileIcon && hasMobileStyle && (_jsx("span", { className: `${iconClasses} hidden max-md:flex max-md:p-0 mr-2`, "aria-hidden": "false", "aria-label": mobileIconLabel, children: mobileIcon })), _jsx("div", { className: `${hasMobileStyle ? "max-md:hidden" : ""}`, children: text }), icon && hasRightIcon && (_jsx("span", { className: `${iconClasses} max-md:hidden ml-2`, children: icon }))] }));
|
|
7
|
+
return (_jsxs("span", { "data-testid": "badge-test-id", className: badgeClasses, children: [image && _jsx("span", { className: "mr-2", children: image }), icon && hasLeftIcon && (_jsx("span", { className: `${iconClasses} max-md:hidden mr-2`, children: icon })), mobileIcon && hasMobileStyle && (_jsx("span", { className: `${iconClasses} hidden max-md:flex max-md:p-0 mr-2`, "aria-hidden": "false", "aria-label": mobileIconLabel, children: mobileIcon })), _jsx("div", { className: `${hasMobileStyle ? "max-md:hidden" : ""}`, children: text }), icon && hasRightIcon && (_jsx("span", { className: `${iconClasses} max-md:hidden ml-2`, children: icon }))] }));
|
|
8
8
|
};
|
|
9
9
|
export default Badge;
|
|
@@ -115,7 +115,8 @@ export default {
|
|
|
115
115
|
description: "Additional Tailwind CSS classes for the badge. Example: `mb-2`.",
|
|
116
116
|
},
|
|
117
117
|
fontColor: {
|
|
118
|
-
control: "none",
|
|
118
|
+
control: "none",
|
|
119
|
+
description: "Sets the text color of the badge using Tailwind CSS classes. Example: `text-gray-800`.",
|
|
119
120
|
},
|
|
120
121
|
},
|
|
121
122
|
tags: ["autodocs"],
|
|
@@ -194,3 +195,34 @@ CommerceBadge.parameters = {
|
|
|
194
195
|
},
|
|
195
196
|
},
|
|
196
197
|
};
|
|
198
|
+
export const DeskBadge = Template.bind({});
|
|
199
|
+
DeskBadge.args = {
|
|
200
|
+
backgroundColor: "bg-black",
|
|
201
|
+
borderRadius: "rounded-full",
|
|
202
|
+
badgeContainerClasses: "px-3 py-1",
|
|
203
|
+
text: (_jsx(Text, { color: "text-white", fontFamily: "font-serif", text: "Closed", tag: "span", size: "text-sm" })),
|
|
204
|
+
};
|
|
205
|
+
DeskBadge.parameters = {
|
|
206
|
+
docs: {
|
|
207
|
+
description: {
|
|
208
|
+
story: "The badges used in the table for desk",
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
export const SupplyBadge = Template.bind({});
|
|
213
|
+
SupplyBadge.args = {
|
|
214
|
+
backgroundColor: "bg-gray-300",
|
|
215
|
+
borderRadius: "rounded-full",
|
|
216
|
+
badgeContainerClasses: "px-3 py-1",
|
|
217
|
+
mobileIcon: getFontAwesomeIcon("calculator"),
|
|
218
|
+
icon: getFontAwesomeIcon("calculator"),
|
|
219
|
+
hasLeftIcon: true,
|
|
220
|
+
text: (_jsx(Text, { color: "text-black", fontFamily: "font-serif", text: "Closed", tag: "span", size: "text-sm" })),
|
|
221
|
+
};
|
|
222
|
+
SupplyBadge.parameters = {
|
|
223
|
+
docs: {
|
|
224
|
+
description: {
|
|
225
|
+
story: "The badges used in Supply",
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
};
|
|
@@ -4,77 +4,100 @@ import { describe, expect, beforeEach, test } from "vitest";
|
|
|
4
4
|
import Badge from "./Badge";
|
|
5
5
|
import Text from "../Text/Text";
|
|
6
6
|
import { getFontAwesomeIcon } from "../../utils/getFontAwesomeIcon";
|
|
7
|
-
describe("FontAwesome Icon Rendering", () => {
|
|
8
|
-
test("renders exclamation-circle icon", () => {
|
|
9
|
-
render(getFontAwesomeIcon("exclamationCircle"));
|
|
10
|
-
const icon = screen.getByTestId("icon");
|
|
11
|
-
expect(icon).toBeInTheDocument();
|
|
12
|
-
});
|
|
13
|
-
test("renders check icon", () => {
|
|
14
|
-
render(getFontAwesomeIcon("check"));
|
|
15
|
-
const icon = screen.getByTestId("icon");
|
|
16
|
-
expect(icon).toBeInTheDocument();
|
|
17
|
-
});
|
|
18
|
-
test("renders xmark icon", () => {
|
|
19
|
-
render(getFontAwesomeIcon("xmark"));
|
|
20
|
-
const icon = screen.getByTestId("icon");
|
|
21
|
-
expect(icon).toBeInTheDocument();
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
7
|
describe("<Badge />", () => {
|
|
25
8
|
beforeEach(() => {
|
|
26
9
|
render(_jsx(Badge, { type: "span", borderColor: "border-red-500", hoverColor: "hover:bg-none", testId: "priority-badge", mobileIcon: getFontAwesomeIcon("exclamationCircle"), mobileIconLabel: "Priority", text: _jsx(Text, { size: "text-md", color: "text-black", text: "Priority", fontFamily: "font-serif", tag: "h2", additionalClasses: "font-bold" }) }));
|
|
27
10
|
});
|
|
28
11
|
test("renders badge", () => {
|
|
29
|
-
const badge = screen.getByTestId("
|
|
12
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
30
13
|
expect(badge).toBeInTheDocument();
|
|
31
14
|
});
|
|
32
15
|
test("has correct text", () => {
|
|
33
|
-
expect(screen.getByTestId("badge-
|
|
16
|
+
expect(screen.getByTestId("badge-test-id")).toHaveTextContent("Priority");
|
|
34
17
|
});
|
|
35
18
|
test("has correct border color", () => {
|
|
36
|
-
const badge = screen.getByTestId("
|
|
19
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
37
20
|
expect(badge).toHaveClass("border-red-500");
|
|
38
21
|
});
|
|
39
22
|
});
|
|
40
23
|
describe("<Badge /> with icon", () => {
|
|
41
24
|
beforeEach(() => {
|
|
42
|
-
render(_jsx(Badge, { type: "span", borderColor: "border-green-500", hoverColor: "hover:bg-none", testId: "icon-badge", cursorPointer: false, icon: getFontAwesomeIcon("
|
|
25
|
+
render(_jsx(Badge, { type: "span", borderColor: "border-green-500", hoverColor: "hover:bg-none", testId: "icon-badge", cursorPointer: false, icon: getFontAwesomeIcon("xmark"), mobileIcon: getFontAwesomeIcon("xmark"), mobileIconLabel: "Complete", hasLeftIcon: true, text: _jsx(Text, { size: "text-md", color: "text-black", text: "Complete", fontFamily: "font-serif", tag: "h2", additionalClasses: "font-bold" }) }));
|
|
43
26
|
});
|
|
44
27
|
test("renders badge with icon", () => {
|
|
45
|
-
const badge = screen.getByTestId("
|
|
28
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
46
29
|
expect(badge).toBeInTheDocument();
|
|
47
30
|
});
|
|
48
|
-
test("
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(
|
|
54
|
-
});
|
|
55
|
-
test("has correct icon", () => {
|
|
56
|
-
const icon = screen.getByTestId("icon");
|
|
57
|
-
expect(icon).toBeInTheDocument();
|
|
31
|
+
test("renders badge with icon", () => {
|
|
32
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
33
|
+
expect(badge).toBeInTheDocument();
|
|
34
|
+
const icon = badge.querySelector('svg[data-icon="xmark"][data-prefix="fas"]');
|
|
35
|
+
expect(icon).not.toBeNull();
|
|
36
|
+
expect(icon).toBeInstanceOf(SVGElement);
|
|
58
37
|
});
|
|
59
38
|
});
|
|
60
|
-
describe("<Badge /> with
|
|
39
|
+
describe("<Badge /> with Image", () => {
|
|
61
40
|
beforeEach(() => {
|
|
62
|
-
render(_jsx(Badge, { type: "href", href: "#", borderColor: "border-none", hoverColor: "hover:bg-blue-500",
|
|
63
|
-
});
|
|
64
|
-
test("renders badge with pill style", () => {
|
|
65
|
-
const pill = screen.getByTestId("pill-badge");
|
|
66
|
-
expect(pill).toBeInTheDocument();
|
|
41
|
+
render(_jsx(Badge, { type: "href", href: "#", borderColor: "border-none", hoverColor: "hover:bg-blue-500", cursorPointer: false, icon: getFontAwesomeIcon("check"), mobileIcon: getFontAwesomeIcon("check"), mobileIconLabel: "Complete", text: _jsxs(_Fragment, { children: [_jsx(Text, { size: "text-md", color: "text-black", fontFamily: "font-serif", text: "Contact Us", tag: "h2", additionalClasses: "pl-2 pb-0 font-bold" }), _jsx(Text, { size: "text-md", color: "text-black", fontFamily: "font-serif", text: "1-800-800-8000", tag: "p", additionalClasses: "pl-2 pt-0" })] }), image: _jsx("img", { src: "../../../assets/contact-image.png", alt: "test alt text", className: "flex justify-center w-12 h-12 max-md:hidden" }) }));
|
|
67
42
|
});
|
|
68
43
|
test("has correct text", () => {
|
|
69
|
-
expect(screen.getByTestId("badge-
|
|
70
|
-
expect(screen.getByTestId("badge-
|
|
44
|
+
expect(screen.getByTestId("badge-test-id")).toHaveTextContent("Contact Us");
|
|
45
|
+
expect(screen.getByTestId("badge-test-id")).toHaveTextContent("1-800-800-8000");
|
|
71
46
|
});
|
|
72
47
|
test("has correct background color", () => {
|
|
73
|
-
const
|
|
74
|
-
expect(
|
|
48
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
49
|
+
expect(badge).toHaveClass("border-none");
|
|
75
50
|
});
|
|
76
51
|
test("has correct image", () => {
|
|
77
|
-
const
|
|
78
|
-
expect(
|
|
52
|
+
const badgeImage = screen.getByAltText("test alt text");
|
|
53
|
+
expect(badgeImage).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe("<Badge /> Tests for icons and images", () => {
|
|
57
|
+
test("renders with left icon only", () => {
|
|
58
|
+
render(_jsx(Badge, { icon: getFontAwesomeIcon("xmark"), hasLeftIcon: true, text: _jsx(Text, { text: "With Icon" }), type: "to" }));
|
|
59
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
60
|
+
expect(badge).toBeInTheDocument();
|
|
61
|
+
const icon = badge.querySelector('svg[data-icon="xmark"]');
|
|
62
|
+
expect(icon).not.toBeNull();
|
|
63
|
+
});
|
|
64
|
+
test("renders with image", () => {
|
|
65
|
+
render(_jsx(Badge, { image: _jsx("img", { src: "image.png", alt: "Test Image" }), text: _jsx(Text, { text: "With Image" }), type: "to" }));
|
|
66
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
67
|
+
expect(badge).toBeInTheDocument();
|
|
68
|
+
const image = screen.getByAltText("Test Image");
|
|
69
|
+
expect(image).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe("<Badge /> tests for right badges", () => {
|
|
73
|
+
test("renders with left icon only", () => {
|
|
74
|
+
render(_jsx(Badge, { icon: getFontAwesomeIcon("xmark"), hasRightIcon: true, text: _jsx(Text, { text: "With Icon" }), type: "to" }));
|
|
75
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
76
|
+
expect(badge).toBeInTheDocument();
|
|
77
|
+
const icon = badge.querySelector('svg[data-icon="xmark"]');
|
|
78
|
+
expect(icon).not.toBeNull();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("<Badge /> - Mobile Icon Tests", () => {
|
|
82
|
+
test("renders mobile icon when hasMobileStyle is true", () => {
|
|
83
|
+
render(_jsx(Badge, { mobileIcon: getFontAwesomeIcon("check"), hasMobileStyle: true, mobileIconLabel: "Mobile Icon Label", text: "Mobile Icon Badge", type: "span" }));
|
|
84
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
85
|
+
expect(badge).toBeInTheDocument();
|
|
86
|
+
const mobileIcon = screen.getByLabelText("Mobile Icon Label");
|
|
87
|
+
expect(mobileIcon).toBeInTheDocument();
|
|
88
|
+
expect(mobileIcon).toHaveClass("hidden max-md:flex max-md:p-0 mr-2");
|
|
89
|
+
});
|
|
90
|
+
test("does not render mobile icon when hasMobileStyle is false", () => {
|
|
91
|
+
render(_jsx(Badge, { mobileIcon: getFontAwesomeIcon("check"), hasMobileStyle: false, mobileIconLabel: "Mobile Icon Label", text: "No Mobile Style", type: "to" }));
|
|
92
|
+
const badge = screen.getByTestId("badge-test-id");
|
|
93
|
+
expect(badge).toBeInTheDocument();
|
|
94
|
+
const mobileIcon = screen.queryByLabelText("Mobile Icon Label");
|
|
95
|
+
expect(mobileIcon).not.toBeInTheDocument();
|
|
96
|
+
});
|
|
97
|
+
test("mobile icon has correct aria attributes", () => {
|
|
98
|
+
render(_jsx(Badge, { mobileIcon: getFontAwesomeIcon("check"), hasMobileStyle: true, mobileIconLabel: "Mobile Icon Accessibility Label", text: "Accessible Mobile Icon Badge", type: "to" }));
|
|
99
|
+
const mobileIcon = screen.getByLabelText("Mobile Icon Accessibility Label");
|
|
100
|
+
expect(mobileIcon).toBeInTheDocument();
|
|
101
|
+
expect(mobileIcon).toHaveAttribute("aria-hidden", "false");
|
|
79
102
|
});
|
|
80
103
|
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agilant/toga-blox",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.19",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "vitest run",
|
|
10
|
-
"test:coverage": "vitest run --coverage
|
|
10
|
+
"test:coverage": "vitest run src/**/*.test.tsx --coverage",
|
|
11
11
|
"blox": "storybook dev -p 6006",
|
|
12
12
|
"build-storybook": "storybook build",
|
|
13
13
|
"build-css": "tailwindcss -i ./src/main.css -o ./dist/main.css --minify",
|