@agilant/toga-blox 1.0.6 → 1.0.8
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/package.json +39 -38
- package/src/components/Badge/Badge.tsx +3 -3
- 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.test.tsx +4 -4
- package/src/components/FormButton/FormButton.tsx +3 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agilant/toga-blox",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -17,55 +17,56 @@
|
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@emotion/is-prop-valid": "^1.3
|
|
21
|
-
"@storybook/addon-docs": "^
|
|
22
|
-
"@storybook/addon-viewport": "^
|
|
23
|
-
"@tanstack/react-virtual": "^3.
|
|
24
|
-
"@tanstack/virtual-core": "^3.
|
|
20
|
+
"@emotion/is-prop-valid": "^1.1.3",
|
|
21
|
+
"@storybook/addon-docs": "^7.6.6",
|
|
22
|
+
"@storybook/addon-viewport": "^7.6.10",
|
|
23
|
+
"@tanstack/react-virtual": "^3.1.3",
|
|
24
|
+
"@tanstack/virtual-core": "^3.1.3",
|
|
25
25
|
"classnames": "^2.5.1",
|
|
26
|
-
"
|
|
26
|
+
"react-router-dom": "^6.16.0",
|
|
27
|
+
"daisyui": "^3",
|
|
27
28
|
"esbuild-wasm": "^0.23.0",
|
|
28
|
-
"framer-motion": "^11.
|
|
29
|
-
"react": "^18.
|
|
30
|
-
"react-dom": "^18.
|
|
31
|
-
"tslib": "^2.
|
|
29
|
+
"framer-motion": "^11.0.8",
|
|
30
|
+
"react": "^18.2.0",
|
|
31
|
+
"react-dom": "^18.2.0",
|
|
32
|
+
"tslib": "^2.3.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@fortawesome/fontawesome-svg-core": "^6.
|
|
35
|
-
"@fortawesome/free-solid-svg-icons": "^6.
|
|
35
|
+
"@fortawesome/fontawesome-svg-core": "^6.5.1",
|
|
36
|
+
"@fortawesome/free-solid-svg-icons": "^6.5.2",
|
|
36
37
|
"@fortawesome/react-fontawesome": "^0.2.2",
|
|
37
|
-
"@storybook/addon-a11y": "^
|
|
38
|
-
"@storybook/addon-essentials": "^
|
|
39
|
-
"@storybook/addon-interactions": "^
|
|
40
|
-
"@storybook/addon-links": "^
|
|
41
|
-
"@storybook/addon-onboarding": "^
|
|
42
|
-
"@storybook/blocks": "^
|
|
43
|
-
"@storybook/react": "^
|
|
44
|
-
"@storybook/react-vite": "^
|
|
45
|
-
"@storybook/test": "^
|
|
38
|
+
"@storybook/addon-a11y": "^7.6.8",
|
|
39
|
+
"@storybook/addon-essentials": "^7.6.6",
|
|
40
|
+
"@storybook/addon-interactions": "^7.6.6",
|
|
41
|
+
"@storybook/addon-links": "^7.6.6",
|
|
42
|
+
"@storybook/addon-onboarding": "^1.0.10",
|
|
43
|
+
"@storybook/blocks": "^7.6.6",
|
|
44
|
+
"@storybook/react": "^7.6.6",
|
|
45
|
+
"@storybook/react-vite": "^7.6.6",
|
|
46
|
+
"@storybook/test": "^7.6.6",
|
|
46
47
|
"@testing-library/jest-dom": "^6.4.6",
|
|
47
|
-
"@testing-library/react": "^
|
|
48
|
+
"@testing-library/react": "^14.3.1",
|
|
48
49
|
"@testing-library/user-event": "^14.5.2",
|
|
49
50
|
"@types/react-router-dom": "^5.3.3",
|
|
50
|
-
"@vitejs/plugin-react": "^4.
|
|
51
|
-
"@vitest/coverage-istanbul": "^2.
|
|
52
|
-
"@vitest/coverage-v8": "^2.
|
|
53
|
-
"autoprefixer": "^10.4.
|
|
54
|
-
"jsdom": "^
|
|
55
|
-
"nodemon": "^3.
|
|
56
|
-
"postcss": "^8.4.
|
|
57
|
-
"react-router-dom": "^6.
|
|
58
|
-
"storybook": "^
|
|
59
|
-
"tailwindcss": "^3.4.
|
|
60
|
-
"typescript": "^5.
|
|
61
|
-
"vite": "^5.
|
|
62
|
-
"vite-tsconfig-paths": "^4.
|
|
63
|
-
"vitest": "^
|
|
51
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
52
|
+
"@vitest/coverage-istanbul": "^1.2.1",
|
|
53
|
+
"@vitest/coverage-v8": "^1.2.1",
|
|
54
|
+
"autoprefixer": "^10.4.16",
|
|
55
|
+
"jsdom": "^23.2.0",
|
|
56
|
+
"nodemon": "^3.0.2",
|
|
57
|
+
"postcss": "^8.4.32",
|
|
58
|
+
"react-router-dom": "^6.16.0",
|
|
59
|
+
"storybook": "^7.6.6",
|
|
60
|
+
"tailwindcss": "^3.4.0",
|
|
61
|
+
"typescript": "^5.3.3",
|
|
62
|
+
"vite": "^4.5.1",
|
|
63
|
+
"vite-tsconfig-paths": "^4.2.2",
|
|
64
|
+
"vitest": "^1.6.0"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
67
|
"@fortawesome/fontawesome-svg-core": "^1.2.35",
|
|
67
68
|
"@fortawesome/free-solid-svg-icons": "^6.5.2",
|
|
68
69
|
"@fortawesome/react-fontawesome": "^0.2.2",
|
|
69
|
-
"react-router-dom": "^
|
|
70
|
+
"react-router-dom": "^6.16.0"
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -50,7 +50,7 @@ const Badge: React.FC<BadgeTypes> = ({
|
|
|
50
50
|
case "href":
|
|
51
51
|
return (
|
|
52
52
|
<>
|
|
53
|
-
<a {...baseProps} href={href} className={
|
|
53
|
+
<a {...baseProps} href={href} className={badgeClasses}>
|
|
54
54
|
{renderContent()}
|
|
55
55
|
</a>
|
|
56
56
|
</>
|
|
@@ -62,7 +62,7 @@ const Badge: React.FC<BadgeTypes> = ({
|
|
|
62
62
|
<Link
|
|
63
63
|
{...baseProps}
|
|
64
64
|
to={to}
|
|
65
|
-
className={
|
|
65
|
+
className={badgeClasses}
|
|
66
66
|
>
|
|
67
67
|
{renderContent()}
|
|
68
68
|
</Link>
|
|
@@ -73,7 +73,7 @@ const Badge: React.FC<BadgeTypes> = ({
|
|
|
73
73
|
case "span":
|
|
74
74
|
return (
|
|
75
75
|
<>
|
|
76
|
-
<span className={
|
|
76
|
+
<span className={badgeClasses}>{renderContent()}</span>
|
|
77
77
|
</>
|
|
78
78
|
);
|
|
79
79
|
default:
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { ChangeEvent, useState } from "react";
|
|
2
|
+
import { Meta, StoryFn } from "@storybook/react";
|
|
3
|
+
import CounterButton from "../CounterButton/CounterButton";
|
|
4
|
+
import { CounterButtonTypes } from "../CounterButton/CounterButton.types";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: "Components/CounterButton",
|
|
8
|
+
component: CounterButton,
|
|
9
|
+
argTypes: {
|
|
10
|
+
count: {
|
|
11
|
+
control: "none",
|
|
12
|
+
description:
|
|
13
|
+
"The initial count value to be displayed in the input field.",
|
|
14
|
+
},
|
|
15
|
+
containerClassName: {
|
|
16
|
+
control: "none",
|
|
17
|
+
description:
|
|
18
|
+
"Additional classes for styling the outer container of the counter.",
|
|
19
|
+
},
|
|
20
|
+
inputClassName: {
|
|
21
|
+
control: "none",
|
|
22
|
+
description: "Additional classes for styling the input field.",
|
|
23
|
+
},
|
|
24
|
+
buttonClassName: {
|
|
25
|
+
control: "none",
|
|
26
|
+
description:
|
|
27
|
+
"Additional classes for styling the increment and decrement buttons.",
|
|
28
|
+
},
|
|
29
|
+
iconClasses: {
|
|
30
|
+
control: "none",
|
|
31
|
+
description: "Additional classes for styling the icons.",
|
|
32
|
+
},
|
|
33
|
+
onIncrementClick: {
|
|
34
|
+
table: { disable: true },
|
|
35
|
+
control: "none",
|
|
36
|
+
description: "Function to handle increment button click.",
|
|
37
|
+
},
|
|
38
|
+
onDecrementClick: {
|
|
39
|
+
table: { disable: true },
|
|
40
|
+
control: "none",
|
|
41
|
+
description: "Function to handle decrement button click.",
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
tags: ["autodocs"],
|
|
45
|
+
parameters: {
|
|
46
|
+
layout: "centered",
|
|
47
|
+
},
|
|
48
|
+
} as Meta;
|
|
49
|
+
|
|
50
|
+
const Template: StoryFn<CounterButtonTypes> = (args) => {
|
|
51
|
+
const [count, setCount] = useState(args.count);
|
|
52
|
+
|
|
53
|
+
const handleIncrement = () => {
|
|
54
|
+
setCount((prevCount) => prevCount + 1);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleDecrement = () => {
|
|
58
|
+
setCount((prevCount) => prevCount - 1);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
62
|
+
const newCount =
|
|
63
|
+
e.target.value === "" || e.target.value === null
|
|
64
|
+
? 0
|
|
65
|
+
: parseInt(e.target.value, 10);
|
|
66
|
+
if (!isNaN(newCount) && newCount >= 0) {
|
|
67
|
+
setCount(newCount);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<CounterButton
|
|
73
|
+
{...args}
|
|
74
|
+
count={count}
|
|
75
|
+
onIncrementClick={handleIncrement}
|
|
76
|
+
onDecrementClick={handleDecrement}
|
|
77
|
+
onInputChange={handleInputChange}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export const Default = Template.bind({});
|
|
83
|
+
Default.args = {
|
|
84
|
+
count: 1,
|
|
85
|
+
containerClassName:
|
|
86
|
+
"flex items-center border border-gray-300 rounded-lg overflow-hidden ",
|
|
87
|
+
inputClassName:
|
|
88
|
+
"w-full h-full text-center text-xl border-none outline-none m-0 p-0 bg-white",
|
|
89
|
+
buttonClassName: "w-12 h-12 flex items-center justify-center",
|
|
90
|
+
iconClasses: "fill-current text-blue-600",
|
|
91
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import FormButton from "../FormButton/FormButton";
|
|
3
|
+
import { CounterButtonTypes } from "./CounterButton.types";
|
|
4
|
+
import Text from "../Text/Text";
|
|
5
|
+
|
|
6
|
+
const CounterButton: React.FC<CounterButtonTypes> = ({
|
|
7
|
+
count,
|
|
8
|
+
containerClassName,
|
|
9
|
+
inputClassName,
|
|
10
|
+
buttonClassName,
|
|
11
|
+
iconClasses,
|
|
12
|
+
onIncrementClick,
|
|
13
|
+
onDecrementClick,
|
|
14
|
+
onInputChange,
|
|
15
|
+
}) => {
|
|
16
|
+
return (
|
|
17
|
+
<div className={containerClassName}>
|
|
18
|
+
<FormButton
|
|
19
|
+
icon={
|
|
20
|
+
<svg
|
|
21
|
+
width={12}
|
|
22
|
+
height={12}
|
|
23
|
+
viewBox="0 0 12 12"
|
|
24
|
+
fill="none"
|
|
25
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
26
|
+
className={iconClasses}
|
|
27
|
+
>
|
|
28
|
+
<path d="M11.0626 6.43135H0.937598C0.712598 6.43135 0.506348 6.24385 0.506348 6.0001C0.506348 5.7751 0.693848 5.56885 0.937598 5.56885H11.0626C11.2876 5.56885 11.4938 5.75635 11.4938 6.0001C11.4938 6.2251 11.2876 6.43135 11.0626 6.43135Z" />
|
|
29
|
+
</svg>
|
|
30
|
+
}
|
|
31
|
+
text={
|
|
32
|
+
<Text
|
|
33
|
+
size={""}
|
|
34
|
+
color={""}
|
|
35
|
+
text={"Decrement"}
|
|
36
|
+
fontFamily={""}
|
|
37
|
+
additionalClasses="sr-only"
|
|
38
|
+
/>
|
|
39
|
+
}
|
|
40
|
+
backgroundColor="clear"
|
|
41
|
+
fontColor="black"
|
|
42
|
+
size="md"
|
|
43
|
+
borderColor="none"
|
|
44
|
+
shape="cornered"
|
|
45
|
+
additionalClasses={buttonClassName}
|
|
46
|
+
onClick={onDecrementClick}
|
|
47
|
+
/>
|
|
48
|
+
<div
|
|
49
|
+
className={`w-16 h-12 flex justify-center items-center border-x border-gray-300`}
|
|
50
|
+
>
|
|
51
|
+
<input
|
|
52
|
+
type="text"
|
|
53
|
+
value={count}
|
|
54
|
+
className={inputClassName}
|
|
55
|
+
onChange={onInputChange}
|
|
56
|
+
onFocus={(e) => e.target.select()}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
<FormButton
|
|
60
|
+
icon={
|
|
61
|
+
<svg
|
|
62
|
+
width={12}
|
|
63
|
+
height={12}
|
|
64
|
+
viewBox="0 0 12 12"
|
|
65
|
+
fill="none"
|
|
66
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
67
|
+
className={iconClasses}
|
|
68
|
+
>
|
|
69
|
+
<g clipPath="url(#clip0_1032_24236)">
|
|
70
|
+
<path d="M11.2501 5.5876H6.43135V0.750098C6.43135 0.525098 6.24385 0.318848 6.0001 0.318848C5.7751 0.318848 5.56885 0.506348 5.56885 0.750098V5.5876H0.750098C0.525098 5.5876 0.318848 5.7751 0.318848 6.01885C0.318848 6.24385 0.506348 6.4501 0.750098 6.4501H5.5876V11.2501C5.5876 11.4751 5.7751 11.6813 6.01885 11.6813C6.24385 11.6813 6.4501 11.4938 6.4501 11.2501V6.43135H11.2501C11.4751 6.43135 11.6813 6.24385 11.6813 6.0001C11.6813 5.7751 11.4751 5.5876 11.2501 5.5876Z" />
|
|
71
|
+
</g>
|
|
72
|
+
<defs>
|
|
73
|
+
<clipPath id="clip0_1032_24236">
|
|
74
|
+
<rect width={12} height={12} fill="white" />
|
|
75
|
+
</clipPath>
|
|
76
|
+
</defs>
|
|
77
|
+
</svg>
|
|
78
|
+
}
|
|
79
|
+
text={
|
|
80
|
+
<Text
|
|
81
|
+
size={""}
|
|
82
|
+
color={""}
|
|
83
|
+
text={"Increment"}
|
|
84
|
+
fontFamily={""}
|
|
85
|
+
additionalClasses="sr-only"
|
|
86
|
+
/>
|
|
87
|
+
}
|
|
88
|
+
backgroundColor="clear"
|
|
89
|
+
fontColor="black"
|
|
90
|
+
size="md"
|
|
91
|
+
borderColor="none"
|
|
92
|
+
shape="cornered"
|
|
93
|
+
additionalClasses={buttonClassName}
|
|
94
|
+
onClick={onIncrementClick}
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default CounterButton;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChangeEvent, MouseEvent } from "react";
|
|
2
|
+
|
|
3
|
+
export interface CounterButtonTypes {
|
|
4
|
+
count: number;
|
|
5
|
+
containerClassName?: string;
|
|
6
|
+
inputClassName?: string;
|
|
7
|
+
buttonClassName?: string;
|
|
8
|
+
iconClasses?: string;
|
|
9
|
+
onIncrementClick: () => void;
|
|
10
|
+
onDecrementClick: () => void;
|
|
11
|
+
onInputChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
12
|
+
}
|
|
@@ -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
|
|
@@ -32,9 +32,8 @@ const FormButton: React.FC<ButtonTypes> = ({
|
|
|
32
32
|
}) => {
|
|
33
33
|
const baseFormButtonClasses = "flex items-center justify-center";
|
|
34
34
|
const hoverClasses = !isDisabled
|
|
35
|
-
? `hover:${hoverBackground} hover:${hoverFontColor} ${
|
|
36
|
-
|
|
37
|
-
} hover:${hoverBorderColor}`
|
|
35
|
+
? `hover:${hoverBackground} hover:${hoverFontColor} ${hoverUnderline ? "hover:underline hover:underline-offset-4" : ""
|
|
36
|
+
} hover:${hoverBorderColor}`
|
|
38
37
|
: "";
|
|
39
38
|
const buttonColorClasses = `${backgroundColor} ${fontColor} ${borderColor}`;
|
|
40
39
|
const cursorClasses = isDisabled
|
|
@@ -86,7 +85,7 @@ const FormButton: React.FC<ButtonTypes> = ({
|
|
|
86
85
|
|
|
87
86
|
return (
|
|
88
87
|
<Element {...props}>
|
|
89
|
-
{icon && <span className={
|
|
88
|
+
{icon && <span className={iconClasses}>{icon}</span>}
|
|
90
89
|
{text}
|
|
91
90
|
</Element>
|
|
92
91
|
);
|