@simplybusiness/mobius 3.2.1 → 3.2.3
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/CHANGELOG.md +18 -0
- package/dist/cjs/components/Chopin/Actions/Actions.d.ts +3 -2
- package/dist/cjs/components/Chopin/Actions/Actions.js +3 -3
- package/dist/cjs/components/Chopin/Actions/Actions.js.map +1 -1
- package/dist/cjs/components/Chopin/Actions/Actions.test.js +23 -19
- package/dist/cjs/components/Chopin/Actions/Actions.test.js.map +1 -1
- package/dist/cjs/components/Chopin/Actions/LinkOrButton.d.ts +3 -0
- package/dist/cjs/components/Chopin/Actions/LinkOrButton.js +28 -0
- package/dist/cjs/components/Chopin/Actions/LinkOrButton.js.map +1 -0
- package/dist/cjs/components/Chopin/Actions/LinkOrButton.test.d.ts +1 -0
- package/dist/cjs/components/Chopin/Actions/LinkOrButton.test.js +35 -0
- package/dist/cjs/components/Chopin/Actions/LinkOrButton.test.js.map +1 -0
- package/dist/cjs/components/LinkButton/LinkButton.d.ts +2 -2
- package/dist/esm/components/Chopin/Actions/Actions.js +3 -3
- package/dist/esm/components/Chopin/Actions/Actions.js.map +1 -1
- package/dist/esm/components/Chopin/Actions/Actions.test.js +23 -19
- package/dist/esm/components/Chopin/Actions/Actions.test.js.map +1 -1
- package/dist/esm/components/Chopin/Actions/LinkOrButton.js +24 -0
- package/dist/esm/components/Chopin/Actions/LinkOrButton.js.map +1 -0
- package/dist/esm/components/Chopin/Actions/LinkOrButton.test.js +33 -0
- package/dist/esm/components/Chopin/Actions/LinkOrButton.test.js.map +1 -0
- package/dist/mobius.d.ts +4 -3
- package/package.json +1 -1
- package/src/components/Chopin/Actions/Actions.story.mdx +44 -37
- package/src/components/Chopin/Actions/Actions.test.tsx +19 -43
- package/src/components/Chopin/Actions/Actions.tsx +12 -15
- package/src/components/Chopin/Actions/LinkOrButton.test.tsx +51 -0
- package/src/components/Chopin/Actions/LinkOrButton.tsx +20 -0
- package/src/components/LinkButton/LinkButton.tsx +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file, or link in
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.2.3] - 2023-01-11
|
|
9
|
+
|
|
10
|
+
## Changed
|
|
11
|
+
|
|
12
|
+
- Change `<Chopin.Actions />` to render as buttons by default. Previously, in order to render actions as buttons we would have to provide `elementType` prop, but that still required for `href` to be present. Now, with `href` provided, a `<LinkButton>` will show, otherwise `<Button>` will show
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- Fixed `<Button />` default transition during page load by specifying only the properties that we want transitioning. This fixes an issue where conditionally added padding scales button in size in an inelegant way.
|
|
17
|
+
|
|
18
|
+
## [3.2.2] - 2023-01-06
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Fixed `onClick` type for `<LinkButton>`, so that it always expects default event
|
|
23
|
+
|
|
8
24
|
## [3.2.0] - 2023-01-04
|
|
9
25
|
|
|
10
26
|
### Changed
|
|
@@ -132,6 +148,8 @@ Additionally, mobius and themes are available on the public NPM registry and can
|
|
|
132
148
|
|
|
133
149
|
## Github Links
|
|
134
150
|
|
|
151
|
+
[3.2.3]: https://github.com/simplybusiness/mobius/releases/tag/v3.2.3
|
|
152
|
+
[3.2.2]: https://github.com/simplybusiness/mobius/releases/tag/v3.2.2
|
|
135
153
|
[3.2.1]: https://github.com/simplybusiness/mobius/releases/tag/v3.2.1
|
|
136
154
|
[3.2.0]: https://github.com/simplybusiness/mobius/releases/tag/v3.2.0
|
|
137
155
|
[3.1.3]: https://github.com/simplybusiness/mobius/releases/tag/v3.1.3
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Ref } from "react";
|
|
2
2
|
import { DOMProps } from "@react-types/shared";
|
|
3
|
+
import { ButtonProps } from "../../Button";
|
|
3
4
|
import { ForwardedRefComponent } from "../../../types/components";
|
|
4
5
|
import { type LinkButtonProps } from "../../LinkButton";
|
|
5
6
|
export type ActionsElementType = HTMLDivElement;
|
|
6
7
|
export interface ActionsProps extends DOMProps {
|
|
7
8
|
/** Custom class name for setting specific CSS */
|
|
8
9
|
className?: string;
|
|
9
|
-
backButton?: LinkButtonProps;
|
|
10
|
-
nextButton?: LinkButtonProps;
|
|
10
|
+
backButton?: LinkButtonProps | ButtonProps;
|
|
11
|
+
nextButton?: LinkButtonProps | ButtonProps;
|
|
11
12
|
backLabel?: string;
|
|
12
13
|
nextLabel?: string;
|
|
13
14
|
}
|
|
@@ -19,16 +19,16 @@ const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
|
19
19
|
const react_1 = require("react");
|
|
20
20
|
const clsx_1 = __importDefault(require("clsx"));
|
|
21
21
|
const Flex_1 = require("../../Flex");
|
|
22
|
-
const
|
|
22
|
+
const LinkOrButton_1 = require("./LinkOrButton");
|
|
23
23
|
const Actions = (0, react_1.forwardRef)((props, ref) => {
|
|
24
24
|
const { className, backButton, nextButton, backLabel, nextLabel } = props, rest = __rest(props, ["className", "backButton", "nextButton", "backLabel", "nextLabel"]);
|
|
25
25
|
const classes = (0, clsx_1.default)("chopin", "chopin/Actions", className);
|
|
26
26
|
const nextButtonClasses = (0, clsx_1.default)("chopin/ActionsNext", {
|
|
27
|
-
"--single-action": !
|
|
27
|
+
"--single-action": !backLabel,
|
|
28
28
|
});
|
|
29
29
|
const backButtonProps = Object.assign(Object.assign({}, backButton), { className: "chopin/ActionsBack", variant: "ghost", icon: "leftArrow", size: "large" });
|
|
30
30
|
const nextButtonProps = Object.assign(Object.assign({}, nextButton), { className: nextButtonClasses, size: "large" });
|
|
31
|
-
return ((0, jsx_runtime_1.jsx)(Flex_1.Flex, Object.assign({ ref: ref, className: classes, justifyContent: "center" }, rest, { children: (0, jsx_runtime_1.jsxs)(Flex_1.Flex, Object.assign({ className: "chopin/ActionsContainer", justifyContent: "space-between", alignItems: "center" }, { children: [(backButton === null || backButton === void 0 ? void 0 : backButton.href)
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(Flex_1.Flex, Object.assign({ ref: ref, className: classes, justifyContent: "center" }, rest, { children: (0, jsx_runtime_1.jsxs)(Flex_1.Flex, Object.assign({ className: "chopin/ActionsContainer", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(LinkOrButton_1.LinkOrButton, Object.assign({ href: backButton === null || backButton === void 0 ? void 0 : backButton.href }, backButtonProps, { children: backLabel })), (0, jsx_runtime_1.jsx)(LinkOrButton_1.LinkOrButton, Object.assign({ href: nextButton === null || nextButton === void 0 ? void 0 : nextButton.href }, nextButtonProps, { children: nextLabel }))] })) })));
|
|
32
32
|
});
|
|
33
33
|
exports.Actions = Actions;
|
|
34
34
|
Actions.displayName = "Actions";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Actions.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/Actions.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iCAAwC;AAExC,gDAAwB;AAGxB,qCAAkC;
|
|
1
|
+
{"version":3,"file":"Actions.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/Actions.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iCAAwC;AAExC,gDAAwB;AAGxB,qCAAkC;AAGlC,iDAA8C;AAe9C,MAAM,OAAO,GACX,IAAA,kBAAU,EAAC,CAAC,KAAmB,EAAE,GAAe,EAAE,EAAE;IAClD,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,KAC7D,KAAK,EAD6D,IAAI,UACtE,KAAK,EADD,mEAAoE,CACnE,CAAC;IAER,MAAM,OAAO,GAAG,IAAA,cAAI,EAAC,QAAQ,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,iBAAiB,GAAG,IAAA,cAAI,EAAC,oBAAoB,EAAE;QACnD,iBAAiB,EAAE,CAAC,SAAS;KAC9B,CAAC,CAAC;IAEH,MAAM,eAAe,mCAChB,UAAU,KACb,SAAS,EAAE,oBAAoB,EAC/B,OAAO,EAAE,OAAkB,EAC3B,IAAI,EAAE,WAAuB,EAC7B,IAAI,EAAE,OAAe,GACtB,CAAC;IAEF,MAAM,eAAe,mCAChB,UAAU,KACb,SAAS,EAAE,iBAAiB,EAC5B,IAAI,EAAE,OAAe,GACtB,CAAC;IAEF,OAAO,CACL,uBAAC,WAAI,kBAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAC,QAAQ,IAAK,IAAI,cAClE,wBAAC,WAAI,kBACH,SAAS,EAAC,yBAAyB,EACnC,cAAc,EAAC,eAAe,EAC9B,UAAU,EAAC,QAAQ,iBAEnB,uBAAC,2BAAY,kBAAC,IAAI,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,IAAM,eAAe,cACtD,SAAS,IACG,EACf,uBAAC,2BAAY,kBAAC,IAAI,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,IAAM,eAAe,cACtD,SAAS,IACG,KACV,IACF,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAGI,0BAAO;AADhB,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC"}
|
|
@@ -9,31 +9,31 @@ const NEXT_ACTION_CLASS_NAME = "chopin/ActionsNext";
|
|
|
9
9
|
const NEXT_SINGLE_ACTION_CLASS_NAME = "--single-action";
|
|
10
10
|
const backLabel = "Back";
|
|
11
11
|
const mockOnBackClick = jest.fn();
|
|
12
|
-
const
|
|
12
|
+
const BackLink = {
|
|
13
13
|
href: "https://test.com",
|
|
14
14
|
};
|
|
15
15
|
const mockOnNextClick = jest.fn();
|
|
16
16
|
const nextLabel = "Next step";
|
|
17
|
-
const
|
|
17
|
+
const NextLink = {
|
|
18
18
|
href: "https://test.com",
|
|
19
19
|
};
|
|
20
20
|
describe("Actions", () => {
|
|
21
21
|
describe("uses correct class names", () => {
|
|
22
22
|
it("includes custom class name", () => {
|
|
23
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { "data-testid": "test-id", className: "my-class", nextButton: Object.assign({},
|
|
23
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { "data-testid": "test-id", className: "my-class", nextButton: Object.assign({}, NextLink), nextLabel: nextLabel, backButton: Object.assign({}, BackLink), backLabel: backLabel }));
|
|
24
24
|
expect(react_1.screen.getByTestId("test-id")).toHaveClass("chopin");
|
|
25
25
|
expect(react_1.screen.getByTestId("test-id")).toHaveClass("my-class");
|
|
26
26
|
expect(react_1.screen.getByTestId("test-id")).toHaveClass(ACTION_CLASS_NAME);
|
|
27
27
|
});
|
|
28
28
|
it("uses links class names", () => {
|
|
29
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { backButton: Object.assign({},
|
|
29
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { backButton: Object.assign({}, BackLink), backLabel: backLabel, nextButton: Object.assign({}, NextLink), nextLabel: nextLabel }));
|
|
30
30
|
const nextLinkEl = react_1.screen.getByRole("link", { name: /next step/i });
|
|
31
31
|
expect(react_1.screen.getByRole("link", { name: /back/i })).toHaveClass(BACK_ACTION_CLASS_NAME);
|
|
32
32
|
expect(nextLinkEl).toHaveClass(NEXT_ACTION_CLASS_NAME);
|
|
33
33
|
expect(nextLinkEl).not.toHaveClass(NEXT_SINGLE_ACTION_CLASS_NAME);
|
|
34
34
|
});
|
|
35
35
|
it("uses --single-action class name with one action btn", () => {
|
|
36
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { nextButton: Object.assign({},
|
|
36
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { nextButton: Object.assign({}, NextLink), nextLabel: nextLabel }));
|
|
37
37
|
expect(react_1.screen.getByRole("link", { name: /next step/i })).toHaveClass(NEXT_SINGLE_ACTION_CLASS_NAME);
|
|
38
38
|
});
|
|
39
39
|
});
|
|
@@ -51,22 +51,22 @@ describe("Actions", () => {
|
|
|
51
51
|
})).not.toBeInTheDocument();
|
|
52
52
|
});
|
|
53
53
|
it("renders button elements if elementType is button", () => {
|
|
54
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, {
|
|
55
|
-
|
|
56
|
-
name: /back/i,
|
|
57
|
-
})).not.toBeInTheDocument();
|
|
58
|
-
expect(react_1.screen.queryByRole("link", {
|
|
59
|
-
name: /next step/i,
|
|
60
|
-
})).not.toBeInTheDocument();
|
|
61
|
-
expect(react_1.screen.getByRole("button", {
|
|
54
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { backLabel: backLabel, nextLabel: nextLabel }));
|
|
55
|
+
const backComponent = react_1.screen.queryByRole("button", {
|
|
62
56
|
name: /back/i,
|
|
63
|
-
})
|
|
64
|
-
|
|
57
|
+
});
|
|
58
|
+
const nextComponent = react_1.screen.getByRole("button", {
|
|
65
59
|
name: /next step/i,
|
|
66
|
-
})
|
|
60
|
+
});
|
|
61
|
+
const links = react_1.screen.queryByRole("link");
|
|
62
|
+
expect(links).toBeNull();
|
|
63
|
+
expect(backComponent).toBeInTheDocument();
|
|
64
|
+
expect(nextComponent).toBeInTheDocument();
|
|
67
65
|
});
|
|
68
66
|
it("fires onNextClick handler on click event", () => {
|
|
69
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, {
|
|
67
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { backLabel: backLabel, nextButton: {
|
|
68
|
+
onClick: mockOnNextClick,
|
|
69
|
+
}, nextLabel: nextLabel }));
|
|
70
70
|
const nextActionBtn = react_1.screen.getByRole("button", {
|
|
71
71
|
name: /Next step/i,
|
|
72
72
|
});
|
|
@@ -74,7 +74,9 @@ describe("Actions", () => {
|
|
|
74
74
|
expect(mockOnNextClick).toHaveBeenCalledTimes(1);
|
|
75
75
|
});
|
|
76
76
|
it("fires onBackClick handler on click event", () => {
|
|
77
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { backButton:
|
|
77
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { backButton: {
|
|
78
|
+
onClick: mockOnBackClick,
|
|
79
|
+
}, backLabel: backLabel, nextLabel: nextLabel }));
|
|
78
80
|
const backActionBtn = react_1.screen.getByRole("button", {
|
|
79
81
|
name: /Back/i,
|
|
80
82
|
});
|
|
@@ -82,7 +84,9 @@ describe("Actions", () => {
|
|
|
82
84
|
expect(mockOnBackClick).toHaveBeenCalledTimes(1);
|
|
83
85
|
});
|
|
84
86
|
it("allows buttons to be disabled", () => {
|
|
85
|
-
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { nextButton:
|
|
87
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(_1.Actions, { nextButton: {
|
|
88
|
+
isDisabled: true,
|
|
89
|
+
}, nextLabel: nextLabel }));
|
|
86
90
|
const nextActionBtn = react_1.screen.getByRole("button", {
|
|
87
91
|
name: /Next step/i,
|
|
88
92
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Actions.test.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/Actions.test.tsx"],"names":[],"mappings":";;;AAAA,kDAAmE;AACnE,wBAA4B;AAE5B,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAC3C,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AACpD,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AACpD,MAAM,6BAA6B,GAAG,iBAAiB,CAAC;AAExD,MAAM,SAAS,GAAG,MAAM,CAAC;AACzB,MAAM,eAAe,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAClC,MAAM,
|
|
1
|
+
{"version":3,"file":"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H,iBAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAC/B,MAAM,CAAC,eAAe,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAClD,IAAA,cAAM,EACJ,uBAAC,UAAO,IACN,UAAU,EAAE;oBACV,OAAO,EAAE,eAAe;iBACzB,EACD,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,GACpB,CACH,CAAC;YACF,MAAM,aAAa,GAAG,cAAM,CAAC,SAAS,CAAC,QAAQ,EAAE;gBAC/C,IAAI,EAAE,OAAO;aACd,CAAC,CAAC;YACH,iBAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAC/B,MAAM,CAAC,eAAe,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;YACvC,IAAA,cAAM,EACJ,uBAAC,UAAO,IACN,UAAU,EAAE;oBACV,UAAU,EAAE,IAAI;iBACjB,EACD,SAAS,EAAE,SAAS,GACpB,CACH,CAAC;YACF,MAAM,aAAa,GAAG,cAAM,CAAC,SAAS,CAAC,QAAQ,EAAE;gBAC/C,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;YACH,MAAM,CAAC,aAAa,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.LinkOrButton = void 0;
|
|
15
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
16
|
+
const Button_1 = require("../../Button");
|
|
17
|
+
const LinkButton_1 = require("../../LinkButton");
|
|
18
|
+
const LinkOrButton = (_a) => {
|
|
19
|
+
var { href, children } = _a, rest = __rest(_a, ["href", "children"]);
|
|
20
|
+
if (!children)
|
|
21
|
+
return null;
|
|
22
|
+
if (href) {
|
|
23
|
+
return ((0, jsx_runtime_1.jsx)(LinkButton_1.LinkButton, Object.assign({}, rest, { href: href }, { children: children })));
|
|
24
|
+
}
|
|
25
|
+
return (0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({}, rest, { children: children }));
|
|
26
|
+
};
|
|
27
|
+
exports.LinkOrButton = LinkOrButton;
|
|
28
|
+
//# sourceMappingURL=LinkOrButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkOrButton.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/LinkOrButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAmD;AACnD,iDAA+D;AAExD,MAAM,YAAY,GAAG,CAAC,EAIG,EAAE,EAAE;QAJP,EAC3B,IAAI,EACJ,QAAQ,OAEsB,EAD3B,IAAI,cAHoB,oBAI5B,CADQ;IAEP,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,IAAI,IAAI,EAAE;QACR,OAAO,CACL,uBAAC,uBAAU,oBAAM,IAAwB,IAAE,IAAI,EAAE,IAAK,gBACnD,QAAQ,IACE,CACd,CAAC;KACH;IAED,OAAO,uBAAC,eAAM,oBAAM,IAAoB,cAAG,QAAQ,IAAU,CAAC;AAChE,CAAC,CAAC;AAhBW,QAAA,YAAY,gBAgBvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const react_1 = require("@testing-library/react");
|
|
5
|
+
const LinkOrButton_1 = require("./LinkOrButton");
|
|
6
|
+
describe("LinkOrButton", () => {
|
|
7
|
+
describe("given no children are provided", () => {
|
|
8
|
+
it("renders nothing", () => {
|
|
9
|
+
const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(LinkOrButton_1.LinkOrButton, {}));
|
|
10
|
+
expect(container).toBeEmptyDOMElement();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
describe("given href is provided", () => {
|
|
14
|
+
it("renders anchor tag", () => {
|
|
15
|
+
const url = "http://www.example.com";
|
|
16
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(LinkOrButton_1.LinkOrButton, Object.assign({ className: "green", href: url }, { children: "I am a link" })));
|
|
17
|
+
const link = react_1.screen.getByRole("link");
|
|
18
|
+
expect(link).toBeInTheDocument();
|
|
19
|
+
expect(link).toHaveClass("green");
|
|
20
|
+
expect(link).toHaveAttribute("href", url);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe("given href is not provided", () => {
|
|
24
|
+
it("renders button", () => {
|
|
25
|
+
const clickHandler = jest.fn();
|
|
26
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(LinkOrButton_1.LinkOrButton, Object.assign({ "data-id": "test", onClick: clickHandler }, { children: "I am a button" })));
|
|
27
|
+
const button = react_1.screen.getByRole("button");
|
|
28
|
+
expect(button).toBeInTheDocument();
|
|
29
|
+
expect(button).toHaveAttribute("data-id", "test");
|
|
30
|
+
react_1.fireEvent.click(button);
|
|
31
|
+
expect(clickHandler).toHaveBeenCalled();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=LinkOrButton.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkOrButton.test.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/LinkOrButton.test.tsx"],"names":[],"mappings":";;;AAAA,kDAAmE;AACnE,iDAA8C;AAE9C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;QAC9C,EAAE,CAAC,iBAAiB,EAAE,GAAG,EAAE;YACzB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,cAAM,EAAC,uBAAC,2BAAY,KAAG,CAAC,CAAC;YAE/C,MAAM,CAAC,SAAS,CAAC,CAAC,mBAAmB,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;YAC5B,MAAM,GAAG,GAAG,wBAAwB,CAAC;YAErC,IAAA,cAAM,EACJ,uBAAC,2BAAY,kBAAC,SAAS,EAAC,OAAO,EAAC,IAAI,EAAE,GAAG,iCAE1B,CAChB,CAAC;YAEF,MAAM,IAAI,GAAG,cAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAEtC,MAAM,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;QAC1C,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;YACxB,MAAM,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;YAE/B,IAAA,cAAM,EACJ,uBAAC,2BAAY,6BAAS,MAAM,EAAC,OAAO,EAAE,YAAY,mCAEnC,CAChB,CAAC;YAEF,MAAM,MAAM,GAAG,cAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAE1C,MAAM,CAAC,MAAM,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACnC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAElD,iBAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAExB,MAAM,CAAC,YAAY,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTMLAttributeAnchorTarget } from "react";
|
|
1
|
+
import { HTMLAttributeAnchorTarget, SyntheticEvent } from "react";
|
|
2
2
|
import type { Link } from "react-router-dom";
|
|
3
3
|
import { ButtonProps } from "../Button";
|
|
4
4
|
export interface LinkButtonProps extends Omit<ButtonProps, "elementType"> {
|
|
@@ -9,7 +9,7 @@ export interface LinkButtonProps extends Omit<ButtonProps, "elementType"> {
|
|
|
9
9
|
download?: boolean | string;
|
|
10
10
|
rel?: string;
|
|
11
11
|
target?: HTMLAttributeAnchorTarget;
|
|
12
|
-
onClick?: () => void;
|
|
12
|
+
onClick?: (event: SyntheticEvent) => void;
|
|
13
13
|
to?: React.ComponentProps<typeof Link>["to"];
|
|
14
14
|
elementType?: React.ElementType;
|
|
15
15
|
}
|
|
@@ -13,16 +13,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
13
13
|
import { forwardRef } from "react";
|
|
14
14
|
import clsx from "clsx";
|
|
15
15
|
import { Flex } from "../../Flex";
|
|
16
|
-
import {
|
|
16
|
+
import { LinkOrButton } from "./LinkOrButton";
|
|
17
17
|
const Actions = forwardRef((props, ref) => {
|
|
18
18
|
const { className, backButton, nextButton, backLabel, nextLabel } = props, rest = __rest(props, ["className", "backButton", "nextButton", "backLabel", "nextLabel"]);
|
|
19
19
|
const classes = clsx("chopin", "chopin/Actions", className);
|
|
20
20
|
const nextButtonClasses = clsx("chopin/ActionsNext", {
|
|
21
|
-
"--single-action": !
|
|
21
|
+
"--single-action": !backLabel,
|
|
22
22
|
});
|
|
23
23
|
const backButtonProps = Object.assign(Object.assign({}, backButton), { className: "chopin/ActionsBack", variant: "ghost", icon: "leftArrow", size: "large" });
|
|
24
24
|
const nextButtonProps = Object.assign(Object.assign({}, nextButton), { className: nextButtonClasses, size: "large" });
|
|
25
|
-
return (_jsx(Flex, Object.assign({ ref: ref, className: classes, justifyContent: "center" }, rest, { children: _jsxs(Flex, Object.assign({ className: "chopin/ActionsContainer", justifyContent: "space-between", alignItems: "center" }, { children: [(backButton === null || backButton === void 0 ? void 0 : backButton.href
|
|
25
|
+
return (_jsx(Flex, Object.assign({ ref: ref, className: classes, justifyContent: "center" }, rest, { children: _jsxs(Flex, Object.assign({ className: "chopin/ActionsContainer", justifyContent: "space-between", alignItems: "center" }, { children: [_jsx(LinkOrButton, Object.assign({ href: backButton === null || backButton === void 0 ? void 0 : backButton.href }, backButtonProps, { children: backLabel })), _jsx(LinkOrButton, Object.assign({ href: nextButton === null || nextButton === void 0 ? void 0 : nextButton.href }, nextButtonProps, { children: nextLabel }))] })) })));
|
|
26
26
|
});
|
|
27
27
|
Actions.displayName = "Actions";
|
|
28
28
|
export { Actions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Actions.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/Actions.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,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9B,UAAU,EAAC,QAAQ,iBAEnB,KAAC,YAAY,kBAAC,IAAI,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,IAAM,eAAe,cACtD,SAAS,IACG,EACf,KAAC,YAAY,kBAAC,IAAI,EAAE,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,IAAM,eAAe,cACtD,SAAS,IACG,KACV,IACF,CACR,CAAC;AACJ,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -7,31 +7,31 @@ const NEXT_ACTION_CLASS_NAME = "chopin/ActionsNext";
|
|
|
7
7
|
const NEXT_SINGLE_ACTION_CLASS_NAME = "--single-action";
|
|
8
8
|
const backLabel = "Back";
|
|
9
9
|
const mockOnBackClick = jest.fn();
|
|
10
|
-
const
|
|
10
|
+
const BackLink = {
|
|
11
11
|
href: "https://test.com",
|
|
12
12
|
};
|
|
13
13
|
const mockOnNextClick = jest.fn();
|
|
14
14
|
const nextLabel = "Next step";
|
|
15
|
-
const
|
|
15
|
+
const NextLink = {
|
|
16
16
|
href: "https://test.com",
|
|
17
17
|
};
|
|
18
18
|
describe("Actions", () => {
|
|
19
19
|
describe("uses correct class names", () => {
|
|
20
20
|
it("includes custom class name", () => {
|
|
21
|
-
render(_jsx(Actions, { "data-testid": "test-id", className: "my-class", nextButton: Object.assign({},
|
|
21
|
+
render(_jsx(Actions, { "data-testid": "test-id", className: "my-class", nextButton: Object.assign({}, NextLink), nextLabel: nextLabel, backButton: Object.assign({}, BackLink), backLabel: backLabel }));
|
|
22
22
|
expect(screen.getByTestId("test-id")).toHaveClass("chopin");
|
|
23
23
|
expect(screen.getByTestId("test-id")).toHaveClass("my-class");
|
|
24
24
|
expect(screen.getByTestId("test-id")).toHaveClass(ACTION_CLASS_NAME);
|
|
25
25
|
});
|
|
26
26
|
it("uses links class names", () => {
|
|
27
|
-
render(_jsx(Actions, { backButton: Object.assign({},
|
|
27
|
+
render(_jsx(Actions, { backButton: Object.assign({}, BackLink), backLabel: backLabel, nextButton: Object.assign({}, NextLink), nextLabel: nextLabel }));
|
|
28
28
|
const nextLinkEl = screen.getByRole("link", { name: /next step/i });
|
|
29
29
|
expect(screen.getByRole("link", { name: /back/i })).toHaveClass(BACK_ACTION_CLASS_NAME);
|
|
30
30
|
expect(nextLinkEl).toHaveClass(NEXT_ACTION_CLASS_NAME);
|
|
31
31
|
expect(nextLinkEl).not.toHaveClass(NEXT_SINGLE_ACTION_CLASS_NAME);
|
|
32
32
|
});
|
|
33
33
|
it("uses --single-action class name with one action btn", () => {
|
|
34
|
-
render(_jsx(Actions, { nextButton: Object.assign({},
|
|
34
|
+
render(_jsx(Actions, { nextButton: Object.assign({}, NextLink), nextLabel: nextLabel }));
|
|
35
35
|
expect(screen.getByRole("link", { name: /next step/i })).toHaveClass(NEXT_SINGLE_ACTION_CLASS_NAME);
|
|
36
36
|
});
|
|
37
37
|
});
|
|
@@ -49,22 +49,22 @@ describe("Actions", () => {
|
|
|
49
49
|
})).not.toBeInTheDocument();
|
|
50
50
|
});
|
|
51
51
|
it("renders button elements if elementType is button", () => {
|
|
52
|
-
render(_jsx(Actions, {
|
|
53
|
-
|
|
54
|
-
name: /back/i,
|
|
55
|
-
})).not.toBeInTheDocument();
|
|
56
|
-
expect(screen.queryByRole("link", {
|
|
57
|
-
name: /next step/i,
|
|
58
|
-
})).not.toBeInTheDocument();
|
|
59
|
-
expect(screen.getByRole("button", {
|
|
52
|
+
render(_jsx(Actions, { backLabel: backLabel, nextLabel: nextLabel }));
|
|
53
|
+
const backComponent = screen.queryByRole("button", {
|
|
60
54
|
name: /back/i,
|
|
61
|
-
})
|
|
62
|
-
|
|
55
|
+
});
|
|
56
|
+
const nextComponent = screen.getByRole("button", {
|
|
63
57
|
name: /next step/i,
|
|
64
|
-
})
|
|
58
|
+
});
|
|
59
|
+
const links = screen.queryByRole("link");
|
|
60
|
+
expect(links).toBeNull();
|
|
61
|
+
expect(backComponent).toBeInTheDocument();
|
|
62
|
+
expect(nextComponent).toBeInTheDocument();
|
|
65
63
|
});
|
|
66
64
|
it("fires onNextClick handler on click event", () => {
|
|
67
|
-
render(_jsx(Actions, {
|
|
65
|
+
render(_jsx(Actions, { backLabel: backLabel, nextButton: {
|
|
66
|
+
onClick: mockOnNextClick,
|
|
67
|
+
}, nextLabel: nextLabel }));
|
|
68
68
|
const nextActionBtn = screen.getByRole("button", {
|
|
69
69
|
name: /Next step/i,
|
|
70
70
|
});
|
|
@@ -72,7 +72,9 @@ describe("Actions", () => {
|
|
|
72
72
|
expect(mockOnNextClick).toHaveBeenCalledTimes(1);
|
|
73
73
|
});
|
|
74
74
|
it("fires onBackClick handler on click event", () => {
|
|
75
|
-
render(_jsx(Actions, { backButton:
|
|
75
|
+
render(_jsx(Actions, { backButton: {
|
|
76
|
+
onClick: mockOnBackClick,
|
|
77
|
+
}, backLabel: backLabel, nextLabel: nextLabel }));
|
|
76
78
|
const backActionBtn = screen.getByRole("button", {
|
|
77
79
|
name: /Back/i,
|
|
78
80
|
});
|
|
@@ -80,7 +82,9 @@ describe("Actions", () => {
|
|
|
80
82
|
expect(mockOnBackClick).toHaveBeenCalledTimes(1);
|
|
81
83
|
});
|
|
82
84
|
it("allows buttons to be disabled", () => {
|
|
83
|
-
render(_jsx(Actions, { nextButton:
|
|
85
|
+
render(_jsx(Actions, { nextButton: {
|
|
86
|
+
isDisabled: true,
|
|
87
|
+
}, nextLabel: nextLabel }));
|
|
84
88
|
const nextActionBtn = screen.getByRole("button", {
|
|
85
89
|
name: /Next step/i,
|
|
86
90
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Actions.test.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/Actions.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EA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,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
13
|
+
import { Button } from "../../Button";
|
|
14
|
+
import { LinkButton } from "../../LinkButton";
|
|
15
|
+
export const LinkOrButton = (_a) => {
|
|
16
|
+
var { href, children } = _a, rest = __rest(_a, ["href", "children"]);
|
|
17
|
+
if (!children)
|
|
18
|
+
return null;
|
|
19
|
+
if (href) {
|
|
20
|
+
return (_jsx(LinkButton, Object.assign({}, rest, { href: href }, { children: children })));
|
|
21
|
+
}
|
|
22
|
+
return _jsx(Button, Object.assign({}, rest, { children: children }));
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=LinkOrButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkOrButton.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/LinkOrButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,UAAU,EAAmB,MAAM,kBAAkB,CAAC;AAE/D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAIG,EAAE,EAAE;QAJP,EAC3B,IAAI,EACJ,QAAQ,OAEsB,EAD3B,IAAI,cAHoB,oBAI5B,CADQ;IAEP,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,IAAI,IAAI,EAAE;QACR,OAAO,CACL,KAAC,UAAU,oBAAM,IAAwB,IAAE,IAAI,EAAE,IAAK,gBACnD,QAAQ,IACE,CACd,CAAC;KACH;IAED,OAAO,KAAC,MAAM,oBAAM,IAAoB,cAAG,QAAQ,IAAU,CAAC;AAChE,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
3
|
+
import { LinkOrButton } from "./LinkOrButton";
|
|
4
|
+
describe("LinkOrButton", () => {
|
|
5
|
+
describe("given no children are provided", () => {
|
|
6
|
+
it("renders nothing", () => {
|
|
7
|
+
const { container } = render(_jsx(LinkOrButton, {}));
|
|
8
|
+
expect(container).toBeEmptyDOMElement();
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
describe("given href is provided", () => {
|
|
12
|
+
it("renders anchor tag", () => {
|
|
13
|
+
const url = "http://www.example.com";
|
|
14
|
+
render(_jsx(LinkOrButton, Object.assign({ className: "green", href: url }, { children: "I am a link" })));
|
|
15
|
+
const link = screen.getByRole("link");
|
|
16
|
+
expect(link).toBeInTheDocument();
|
|
17
|
+
expect(link).toHaveClass("green");
|
|
18
|
+
expect(link).toHaveAttribute("href", url);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("given href is not provided", () => {
|
|
22
|
+
it("renders button", () => {
|
|
23
|
+
const clickHandler = jest.fn();
|
|
24
|
+
render(_jsx(LinkOrButton, Object.assign({ "data-id": "test", onClick: clickHandler }, { children: "I am a button" })));
|
|
25
|
+
const button = screen.getByRole("button");
|
|
26
|
+
expect(button).toBeInTheDocument();
|
|
27
|
+
expect(button).toHaveAttribute("data-id", "test");
|
|
28
|
+
fireEvent.click(button);
|
|
29
|
+
expect(clickHandler).toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=LinkOrButton.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinkOrButton.test.js","sourceRoot":"","sources":["../../../../../src/components/Chopin/Actions/LinkOrButton.test.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;QAC9C,EAAE,CAAC,iBAAiB,EAAE,GAAG,EAAE;YACzB,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,KAAC,YAAY,KAAG,CAAC,CAAC;YAE/C,MAAM,CAAC,SAAS,CAAC,CAAC,mBAAmB,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,oBAAoB,EAAE,GAAG,EAAE;YAC5B,MAAM,GAAG,GAAG,wBAAwB,CAAC;YAErC,MAAM,CACJ,KAAC,YAAY,kBAAC,SAAS,EAAC,OAAO,EAAC,IAAI,EAAE,GAAG,iCAE1B,CAChB,CAAC;YAEF,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAEtC,MAAM,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACjC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;QAC1C,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;YACxB,MAAM,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;YAE/B,MAAM,CACJ,KAAC,YAAY,6BAAS,MAAM,EAAC,OAAO,EAAE,YAAY,mCAEnC,CAChB,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAE1C,MAAM,CAAC,MAAM,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACnC,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAElD,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAExB,MAAM,CAAC,YAAY,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/mobius.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { RefAttributes } from 'react';
|
|
|
43
43
|
import { SeparatorProps } from '@react-aria/separator';
|
|
44
44
|
import { SliderProps as SliderProps_2 } from '@react-types/slider';
|
|
45
45
|
import { SSRProvider } from '@react-aria/ssr';
|
|
46
|
+
import { SyntheticEvent } from 'react';
|
|
46
47
|
import { useVisuallyHidden } from '@react-aria/visually-hidden';
|
|
47
48
|
import { Validation } from '@react-types/shared';
|
|
48
49
|
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
|
@@ -84,8 +85,8 @@ declare type ActionsElementType = HTMLDivElement;
|
|
|
84
85
|
declare interface ActionsProps extends DOMProps {
|
|
85
86
|
/** Custom class name for setting specific CSS */
|
|
86
87
|
className?: string;
|
|
87
|
-
backButton?: LinkButtonProps;
|
|
88
|
-
nextButton?: LinkButtonProps;
|
|
88
|
+
backButton?: LinkButtonProps | ButtonProps;
|
|
89
|
+
nextButton?: LinkButtonProps | ButtonProps;
|
|
89
90
|
backLabel?: string;
|
|
90
91
|
nextLabel?: string;
|
|
91
92
|
}
|
|
@@ -604,7 +605,7 @@ export declare interface LinkButtonProps extends Omit<ButtonProps, "elementType"
|
|
|
604
605
|
download?: boolean | string;
|
|
605
606
|
rel?: string;
|
|
606
607
|
target?: HTMLAttributeAnchorTarget;
|
|
607
|
-
onClick?: () => void;
|
|
608
|
+
onClick?: (event: SyntheticEvent) => void;
|
|
608
609
|
to?: React.ComponentProps<typeof Link_2>["to"];
|
|
609
610
|
elementType?: React.ElementType;
|
|
610
611
|
}
|
package/package.json
CHANGED
|
@@ -6,13 +6,7 @@ import { excludeControls } from "../../../utils/excludeControls";
|
|
|
6
6
|
<Meta
|
|
7
7
|
title="Chopin/Actions"
|
|
8
8
|
component={Actions}
|
|
9
|
-
argTypes={excludeControls(
|
|
10
|
-
"className",
|
|
11
|
-
"backElementType",
|
|
12
|
-
"nextElementType",
|
|
13
|
-
"onNextClick",
|
|
14
|
-
"onBackClick",
|
|
15
|
-
)}
|
|
9
|
+
argTypes={excludeControls("className", "backElementType", "nextElementType")}
|
|
16
10
|
/>
|
|
17
11
|
|
|
18
12
|
# Actions
|
|
@@ -37,7 +31,33 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
37
31
|
name="Normal"
|
|
38
32
|
args={{
|
|
39
33
|
backLabel: "Back",
|
|
40
|
-
|
|
34
|
+
nextLabel: "Next Step",
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
{args => (
|
|
38
|
+
<div>
|
|
39
|
+
<Actions {...args} />
|
|
40
|
+
</div>
|
|
41
|
+
)}
|
|
42
|
+
</Story>
|
|
43
|
+
|
|
44
|
+
<!-- prettier-ignore -->
|
|
45
|
+
```jsx
|
|
46
|
+
import { Chopin } from "@simplybusiness/mobius";
|
|
47
|
+
|
|
48
|
+
<Chopin.Actions
|
|
49
|
+
backLabel="Back"
|
|
50
|
+
nextLabel="Next Step"
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## With Links
|
|
55
|
+
|
|
56
|
+
<Story
|
|
57
|
+
name="With Links"
|
|
58
|
+
args={{
|
|
59
|
+
backLabel: "Back",
|
|
60
|
+
backButton: { href: "https://www.example.com" },
|
|
41
61
|
nextLabel: "Next Step",
|
|
42
62
|
nextButton: { href: "https://www.google.com" },
|
|
43
63
|
}}
|
|
@@ -55,9 +75,7 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
55
75
|
|
|
56
76
|
<Chopin.Actions
|
|
57
77
|
backLabel="Back"
|
|
58
|
-
backButton={{ href: "https://www.google.com" }}
|
|
59
78
|
nextLabel="Next Step"
|
|
60
|
-
nextButton={{ href: "https://www.google.com" }}
|
|
61
79
|
/>
|
|
62
80
|
```
|
|
63
81
|
|
|
@@ -67,7 +85,6 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
67
85
|
name="One Action"
|
|
68
86
|
args={{
|
|
69
87
|
nextLabel: "Next Step",
|
|
70
|
-
nextButton: { href: "https://www.google.com" },
|
|
71
88
|
}}
|
|
72
89
|
argTypes={excludeControls("backLabel", "backLink")}
|
|
73
90
|
>
|
|
@@ -84,7 +101,6 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
84
101
|
|
|
85
102
|
<Chopin.Actions
|
|
86
103
|
nextLabel="Next Step"
|
|
87
|
-
nextButton={{ href: "https://www.google.com" }}
|
|
88
104
|
/>
|
|
89
105
|
```
|
|
90
106
|
|
|
@@ -94,7 +110,6 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
94
110
|
name="One Back Action"
|
|
95
111
|
args={{
|
|
96
112
|
backLabel: "Back",
|
|
97
|
-
backButton: { href: "https://www.google.com" },
|
|
98
113
|
}}
|
|
99
114
|
argTypes={excludeControls("nextLabel", "nextLink")}
|
|
100
115
|
>
|
|
@@ -112,28 +127,23 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
112
127
|
<Chopin.Actions
|
|
113
128
|
backLabel="Back"
|
|
114
129
|
backButton={{
|
|
115
|
-
href: "https://www.google.com",
|
|
116
130
|
isDisabled: false,
|
|
117
131
|
}}
|
|
118
132
|
/>
|
|
119
133
|
```
|
|
120
134
|
|
|
121
|
-
##
|
|
135
|
+
## Disabled Actions
|
|
122
136
|
|
|
123
137
|
<Canvas>
|
|
124
138
|
<Story
|
|
125
|
-
name="
|
|
139
|
+
name="Disabled Actions"
|
|
126
140
|
args={{
|
|
127
141
|
backLabel: "Back",
|
|
128
142
|
backButton: {
|
|
129
|
-
href: "https://www.google.com",
|
|
130
|
-
elementType: "button",
|
|
131
143
|
isDisabled: true,
|
|
132
144
|
},
|
|
133
145
|
nextLabel: "Next Step",
|
|
134
146
|
nextButton: {
|
|
135
|
-
href: "https://www.google.com",
|
|
136
|
-
elementType: "button",
|
|
137
147
|
isDisabled: true,
|
|
138
148
|
},
|
|
139
149
|
}}
|
|
@@ -153,12 +163,10 @@ import { Chopin } from "@simplybusiness/mobius";
|
|
|
153
163
|
<Chopin.Actions
|
|
154
164
|
backLabel="Back"
|
|
155
165
|
backButton={{
|
|
156
|
-
href: "https://www.google.com",
|
|
157
166
|
isDisabled: false,
|
|
158
167
|
}}
|
|
159
168
|
nextLabel="Next Step"
|
|
160
169
|
nextButton={{
|
|
161
|
-
href: "https://www.google.com",
|
|
162
170
|
isDisabled: true,
|
|
163
171
|
}}
|
|
164
172
|
/>
|
|
@@ -175,44 +183,43 @@ The following HTML is rendered for a `Actions`:
|
|
|
175
183
|
```html
|
|
176
184
|
<div class="mobius mobius/Flex chopin chopin/Actions">
|
|
177
185
|
<div class="mobius mobius/Flex chopin/ActionsContainer">
|
|
178
|
-
<
|
|
186
|
+
<button
|
|
179
187
|
type="button"
|
|
180
|
-
|
|
181
|
-
class="mobius mobius/Button --has-icon mobius mobius/LinkButton chopin/ActionsBack"
|
|
188
|
+
class="mobius mobius/Button --variant-ghost --size-large --has-icon chopin/ActionsBack"
|
|
182
189
|
>
|
|
183
190
|
<svg class="mobius mobius/Icon">...</svg>
|
|
184
191
|
<span class="">Back</span>
|
|
185
|
-
</
|
|
186
|
-
<
|
|
192
|
+
</button>
|
|
193
|
+
<button
|
|
187
194
|
type="button"
|
|
188
|
-
|
|
189
|
-
class="mobius mobius/Button mobius mobius/LinkButton chopin/ActionsNext"
|
|
195
|
+
class="mobius mobius/Button --variant-primary --size-large chopin/ActionsNext"
|
|
190
196
|
>
|
|
191
197
|
<span class="">Next Step</span>
|
|
192
|
-
</
|
|
198
|
+
</button>
|
|
193
199
|
</div>
|
|
194
200
|
</div>
|
|
195
201
|
```
|
|
196
202
|
|
|
197
|
-
With
|
|
203
|
+
With href provided:
|
|
198
204
|
|
|
199
205
|
```html
|
|
200
206
|
<div class="mobius mobius/Flex chopin chopin/Actions">
|
|
201
207
|
<div class="mobius mobius/Flex chopin/ActionsContainer">
|
|
202
208
|
<a
|
|
203
209
|
type="button"
|
|
204
|
-
href="https://www.
|
|
205
|
-
class="mobius mobius/Button --has-icon mobius mobius/LinkButton chopin/ActionsBack"
|
|
210
|
+
href="https://www.example.com"
|
|
211
|
+
class="mobius mobius/Button --variant-ghost --size-large --has-icon mobius mobius/LinkButton chopin/ActionsBack"
|
|
206
212
|
>
|
|
207
|
-
<svg class="mobius mobius/Icon"
|
|
213
|
+
<svg class="mobius mobius/Icon">...</svg>
|
|
208
214
|
<span class="">Back</span>
|
|
209
215
|
</a>
|
|
210
|
-
<
|
|
216
|
+
<a
|
|
211
217
|
type="button"
|
|
212
|
-
|
|
218
|
+
href="https://www.google.com"
|
|
219
|
+
class="mobius mobius/Button --variant-primary --size-large mobius mobius/LinkButton chopin/ActionsNext"
|
|
213
220
|
>
|
|
214
221
|
<span class="">Next Step</span>
|
|
215
|
-
</
|
|
222
|
+
</a>
|
|
216
223
|
</div>
|
|
217
224
|
</div>
|
|
218
225
|
```
|
|
@@ -8,12 +8,12 @@ const NEXT_SINGLE_ACTION_CLASS_NAME = "--single-action";
|
|
|
8
8
|
|
|
9
9
|
const backLabel = "Back";
|
|
10
10
|
const mockOnBackClick = jest.fn();
|
|
11
|
-
const
|
|
11
|
+
const BackLink = {
|
|
12
12
|
href: "https://test.com",
|
|
13
13
|
};
|
|
14
14
|
const mockOnNextClick = jest.fn();
|
|
15
15
|
const nextLabel = "Next step";
|
|
16
|
-
const
|
|
16
|
+
const NextLink = {
|
|
17
17
|
href: "https://test.com",
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -24,9 +24,9 @@ describe("Actions", () => {
|
|
|
24
24
|
<Actions
|
|
25
25
|
data-testid="test-id"
|
|
26
26
|
className="my-class"
|
|
27
|
-
nextButton={{ ...
|
|
27
|
+
nextButton={{ ...NextLink }}
|
|
28
28
|
nextLabel={nextLabel}
|
|
29
|
-
backButton={{ ...
|
|
29
|
+
backButton={{ ...BackLink }}
|
|
30
30
|
backLabel={backLabel}
|
|
31
31
|
/>,
|
|
32
32
|
);
|
|
@@ -38,9 +38,9 @@ describe("Actions", () => {
|
|
|
38
38
|
it("uses links class names", () => {
|
|
39
39
|
render(
|
|
40
40
|
<Actions
|
|
41
|
-
backButton={{ ...
|
|
41
|
+
backButton={{ ...BackLink }}
|
|
42
42
|
backLabel={backLabel}
|
|
43
|
-
nextButton={{ ...
|
|
43
|
+
nextButton={{ ...NextLink }}
|
|
44
44
|
nextLabel={nextLabel}
|
|
45
45
|
/>,
|
|
46
46
|
);
|
|
@@ -53,7 +53,7 @@ describe("Actions", () => {
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it("uses --single-action class name with one action btn", () => {
|
|
56
|
-
render(<Actions nextButton={{ ...
|
|
56
|
+
render(<Actions nextButton={{ ...NextLink }} nextLabel={nextLabel} />);
|
|
57
57
|
expect(screen.getByRole("link", { name: /next step/i })).toHaveClass(
|
|
58
58
|
NEXT_SINGLE_ACTION_CLASS_NAME,
|
|
59
59
|
);
|
|
@@ -80,44 +80,25 @@ describe("Actions", () => {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it("renders button elements if elementType is button", () => {
|
|
83
|
-
render(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
).not.toBeInTheDocument();
|
|
96
|
-
expect(
|
|
97
|
-
screen.queryByRole("link", {
|
|
98
|
-
name: /next step/i,
|
|
99
|
-
}),
|
|
100
|
-
).not.toBeInTheDocument();
|
|
101
|
-
expect(
|
|
102
|
-
screen.getByRole("button", {
|
|
103
|
-
name: /back/i,
|
|
104
|
-
}),
|
|
105
|
-
).toBeInTheDocument();
|
|
106
|
-
expect(
|
|
107
|
-
screen.getByRole("button", {
|
|
108
|
-
name: /next step/i,
|
|
109
|
-
}),
|
|
110
|
-
).toBeInTheDocument();
|
|
83
|
+
render(<Actions backLabel={backLabel} nextLabel={nextLabel} />);
|
|
84
|
+
const backComponent = screen.queryByRole("button", {
|
|
85
|
+
name: /back/i,
|
|
86
|
+
});
|
|
87
|
+
const nextComponent = screen.getByRole("button", {
|
|
88
|
+
name: /next step/i,
|
|
89
|
+
});
|
|
90
|
+
const links = screen.queryByRole("link");
|
|
91
|
+
|
|
92
|
+
expect(links).toBeNull();
|
|
93
|
+
expect(backComponent).toBeInTheDocument();
|
|
94
|
+
expect(nextComponent).toBeInTheDocument();
|
|
111
95
|
});
|
|
112
96
|
|
|
113
97
|
it("fires onNextClick handler on click event", () => {
|
|
114
98
|
render(
|
|
115
99
|
<Actions
|
|
116
|
-
backButton={{ ...BackButton }}
|
|
117
100
|
backLabel={backLabel}
|
|
118
101
|
nextButton={{
|
|
119
|
-
...NextButton,
|
|
120
|
-
elementType: "button",
|
|
121
102
|
onClick: mockOnNextClick,
|
|
122
103
|
}}
|
|
123
104
|
nextLabel={nextLabel}
|
|
@@ -134,12 +115,9 @@ describe("Actions", () => {
|
|
|
134
115
|
render(
|
|
135
116
|
<Actions
|
|
136
117
|
backButton={{
|
|
137
|
-
...BackButton,
|
|
138
|
-
elementType: "button",
|
|
139
118
|
onClick: mockOnBackClick,
|
|
140
119
|
}}
|
|
141
120
|
backLabel={backLabel}
|
|
142
|
-
nextButton={{ ...NextButton }}
|
|
143
121
|
nextLabel={nextLabel}
|
|
144
122
|
/>,
|
|
145
123
|
);
|
|
@@ -154,8 +132,6 @@ describe("Actions", () => {
|
|
|
154
132
|
render(
|
|
155
133
|
<Actions
|
|
156
134
|
nextButton={{
|
|
157
|
-
...NextButton,
|
|
158
|
-
elementType: "button",
|
|
159
135
|
isDisabled: true,
|
|
160
136
|
}}
|
|
161
137
|
nextLabel={nextLabel}
|
|
@@ -2,18 +2,19 @@ import { forwardRef, Ref } from "react";
|
|
|
2
2
|
import { DOMProps } from "@react-types/shared";
|
|
3
3
|
import clsx from "clsx";
|
|
4
4
|
import type { IconName } from "@simplybusiness/icons";
|
|
5
|
-
import { Size, Variant } from "../../Button";
|
|
5
|
+
import { ButtonProps, Size, Variant } from "../../Button";
|
|
6
6
|
import { Flex } from "../../Flex";
|
|
7
7
|
import { ForwardedRefComponent } from "../../../types/components";
|
|
8
|
-
import {
|
|
8
|
+
import { type LinkButtonProps } from "../../LinkButton";
|
|
9
|
+
import { LinkOrButton } from "./LinkOrButton";
|
|
9
10
|
|
|
10
11
|
export type ActionsElementType = HTMLDivElement;
|
|
11
12
|
|
|
12
13
|
export interface ActionsProps extends DOMProps {
|
|
13
14
|
/** Custom class name for setting specific CSS */
|
|
14
15
|
className?: string;
|
|
15
|
-
backButton?: LinkButtonProps;
|
|
16
|
-
nextButton?: LinkButtonProps;
|
|
16
|
+
backButton?: LinkButtonProps | ButtonProps;
|
|
17
|
+
nextButton?: LinkButtonProps | ButtonProps;
|
|
17
18
|
backLabel?: string;
|
|
18
19
|
nextLabel?: string;
|
|
19
20
|
}
|
|
@@ -27,7 +28,7 @@ const Actions: ForwardedRefComponent<ActionsProps, ActionsElementType> =
|
|
|
27
28
|
|
|
28
29
|
const classes = clsx("chopin", "chopin/Actions", className);
|
|
29
30
|
const nextButtonClasses = clsx("chopin/ActionsNext", {
|
|
30
|
-
"--single-action": !
|
|
31
|
+
"--single-action": !backLabel,
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
const backButtonProps = {
|
|
@@ -51,16 +52,12 @@ const Actions: ForwardedRefComponent<ActionsProps, ActionsElementType> =
|
|
|
51
52
|
justifyContent="space-between"
|
|
52
53
|
alignItems="center"
|
|
53
54
|
>
|
|
54
|
-
{backButton?.href
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<LinkButton {...nextButtonProps} href={nextButtonProps.href!}>
|
|
61
|
-
{nextLabel}
|
|
62
|
-
</LinkButton>
|
|
63
|
-
)}
|
|
55
|
+
<LinkOrButton href={backButton?.href} {...backButtonProps}>
|
|
56
|
+
{backLabel}
|
|
57
|
+
</LinkOrButton>
|
|
58
|
+
<LinkOrButton href={nextButton?.href} {...nextButtonProps}>
|
|
59
|
+
{nextLabel}
|
|
60
|
+
</LinkOrButton>
|
|
64
61
|
</Flex>
|
|
65
62
|
</Flex>
|
|
66
63
|
);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { LinkOrButton } from "./LinkOrButton";
|
|
3
|
+
|
|
4
|
+
describe("LinkOrButton", () => {
|
|
5
|
+
describe("given no children are provided", () => {
|
|
6
|
+
it("renders nothing", () => {
|
|
7
|
+
const { container } = render(<LinkOrButton />);
|
|
8
|
+
|
|
9
|
+
expect(container).toBeEmptyDOMElement();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe("given href is provided", () => {
|
|
14
|
+
it("renders anchor tag", () => {
|
|
15
|
+
const url = "http://www.example.com";
|
|
16
|
+
|
|
17
|
+
render(
|
|
18
|
+
<LinkOrButton className="green" href={url}>
|
|
19
|
+
I am a link
|
|
20
|
+
</LinkOrButton>,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const link = screen.getByRole("link");
|
|
24
|
+
|
|
25
|
+
expect(link).toBeInTheDocument();
|
|
26
|
+
expect(link).toHaveClass("green");
|
|
27
|
+
expect(link).toHaveAttribute("href", url);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("given href is not provided", () => {
|
|
32
|
+
it("renders button", () => {
|
|
33
|
+
const clickHandler = jest.fn();
|
|
34
|
+
|
|
35
|
+
render(
|
|
36
|
+
<LinkOrButton data-id="test" onClick={clickHandler}>
|
|
37
|
+
I am a button
|
|
38
|
+
</LinkOrButton>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const button = screen.getByRole("button");
|
|
42
|
+
|
|
43
|
+
expect(button).toBeInTheDocument();
|
|
44
|
+
expect(button).toHaveAttribute("data-id", "test");
|
|
45
|
+
|
|
46
|
+
fireEvent.click(button);
|
|
47
|
+
|
|
48
|
+
expect(clickHandler).toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Button, ButtonProps } from "../../Button";
|
|
2
|
+
import { LinkButton, LinkButtonProps } from "../../LinkButton";
|
|
3
|
+
|
|
4
|
+
export const LinkOrButton = ({
|
|
5
|
+
href,
|
|
6
|
+
children,
|
|
7
|
+
...rest
|
|
8
|
+
}: LinkButtonProps | ButtonProps) => {
|
|
9
|
+
if (!children) return null;
|
|
10
|
+
|
|
11
|
+
if (href) {
|
|
12
|
+
return (
|
|
13
|
+
<LinkButton {...(rest as LinkButtonProps)} href={href!}>
|
|
14
|
+
{children}
|
|
15
|
+
</LinkButton>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return <Button {...(rest as ButtonProps)}>{children}</Button>;
|
|
20
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTMLAttributeAnchorTarget } from "react";
|
|
1
|
+
import { HTMLAttributeAnchorTarget, SyntheticEvent } from "react";
|
|
2
2
|
import clsx from "clsx";
|
|
3
3
|
import type { Link } from "react-router-dom";
|
|
4
4
|
import { Button, ButtonProps } from "../Button";
|
|
@@ -11,7 +11,7 @@ export interface LinkButtonProps extends Omit<ButtonProps, "elementType"> {
|
|
|
11
11
|
download?: boolean | string;
|
|
12
12
|
rel?: string;
|
|
13
13
|
target?: HTMLAttributeAnchorTarget;
|
|
14
|
-
onClick?: () => void;
|
|
14
|
+
onClick?: (event: SyntheticEvent) => void;
|
|
15
15
|
to?: React.ComponentProps<typeof Link>["to"];
|
|
16
16
|
elementType?: React.ElementType;
|
|
17
17
|
}
|