@conveyorhq/arrow-ds 1.79.0 → 1.80.0
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTMLProps, ReactNode } from "react";
|
|
1
|
+
import { HTMLProps, ReactNode, MouseEvent } from "react";
|
|
2
2
|
export interface ToggleProps {
|
|
3
3
|
checked?: boolean;
|
|
4
4
|
className?: string;
|
|
@@ -6,7 +6,8 @@ export interface ToggleProps {
|
|
|
6
6
|
id?: string;
|
|
7
7
|
inputProps?: HTMLProps<HTMLInputElement>;
|
|
8
8
|
onChange: (checked: boolean) => void;
|
|
9
|
+
onClick: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
9
10
|
children?: ReactNode;
|
|
10
11
|
labelPosition?: "left" | "right";
|
|
11
12
|
}
|
|
12
|
-
export declare const Toggle: ({ checked, disabled, id, inputProps, className, onChange, children, labelPosition, ...rest }: ToggleProps) => JSX.Element;
|
|
13
|
+
export declare const Toggle: ({ checked, disabled, id, inputProps, className, onChange, onClick, children, labelPosition, ...rest }: ToggleProps) => JSX.Element;
|
|
@@ -9,9 +9,9 @@ const classnames_1 = __importDefault(require("classnames"));
|
|
|
9
9
|
const Box_1 = require("../Box");
|
|
10
10
|
const bem_1 = require("../../utilities/bem");
|
|
11
11
|
const cn = bem_1.bemHOF("Toggle");
|
|
12
|
-
const Toggle = ({ checked = false, disabled = false, id, inputProps, className, onChange, children, labelPosition = "right", ...rest }) => {
|
|
12
|
+
const Toggle = ({ checked = false, disabled = false, id, inputProps, className, onChange, onClick, children, labelPosition = "right", ...rest }) => {
|
|
13
13
|
const inputRef = react_1.default.useRef(null);
|
|
14
|
-
const
|
|
14
|
+
const handleChange = () => {
|
|
15
15
|
if (!disabled) {
|
|
16
16
|
onChange(!checked);
|
|
17
17
|
}
|
|
@@ -19,12 +19,15 @@ const Toggle = ({ checked = false, disabled = false, id, inputProps, className,
|
|
|
19
19
|
return (react_1.default.createElement("button", Object.assign({ type: "button", className: classnames_1.default(cn(), cn({ m: labelPosition }), className, {
|
|
20
20
|
isOn: checked,
|
|
21
21
|
isOff: !checked,
|
|
22
|
-
}), id: id, disabled: disabled, role: "switch", "aria-checked": checked, onClick: () => {
|
|
22
|
+
}), id: id, disabled: disabled, role: "switch", "aria-checked": checked, onClick: (event) => {
|
|
23
23
|
if (inputRef.current) {
|
|
24
24
|
inputRef.current.click();
|
|
25
25
|
}
|
|
26
|
+
if (onClick) {
|
|
27
|
+
onClick(event);
|
|
28
|
+
}
|
|
26
29
|
} }, rest),
|
|
27
|
-
react_1.default.createElement("input", Object.assign({ ref: inputRef, disabled: disabled, checked: checked, type: "checkbox", onChange:
|
|
30
|
+
react_1.default.createElement("input", Object.assign({ ref: inputRef, disabled: disabled, checked: checked, type: "checkbox", onChange: handleChange, value: checked ? "on" : "off", hidden: true }, inputProps)),
|
|
28
31
|
react_1.default.createElement(Box_1.Box, { as: "span", className: cn({ e: "track" }), "aria-hidden": "true" },
|
|
29
32
|
react_1.default.createElement(Box_1.Box, { as: "span", className: cn({ e: "thumb" }) })),
|
|
30
33
|
children && (react_1.default.createElement(Box_1.Box, { as: "span", className: classnames_1.default(cn({ e: "label" })) }, children))));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { HTMLProps, ReactNode } from "react";
|
|
1
|
+
import React, { HTMLProps, ReactNode, MouseEvent } from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
3
|
import { Box } from "../Box";
|
|
4
4
|
import { bemHOF } from "../../utilities/bem";
|
|
@@ -30,6 +30,10 @@ export interface ToggleProps {
|
|
|
30
30
|
* Called when a user turns the toggle on/off (unless `disabled` is true)
|
|
31
31
|
*/
|
|
32
32
|
onChange: (checked: boolean) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Optional onClick event
|
|
35
|
+
*/
|
|
36
|
+
onClick: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
33
37
|
/**
|
|
34
38
|
* The label text
|
|
35
39
|
*/
|
|
@@ -47,13 +51,14 @@ export const Toggle = ({
|
|
|
47
51
|
inputProps,
|
|
48
52
|
className,
|
|
49
53
|
onChange,
|
|
54
|
+
onClick,
|
|
50
55
|
children,
|
|
51
56
|
labelPosition = "right",
|
|
52
57
|
...rest
|
|
53
58
|
}: ToggleProps) => {
|
|
54
59
|
const inputRef = React.useRef<HTMLInputElement>(null);
|
|
55
60
|
|
|
56
|
-
const
|
|
61
|
+
const handleChange = () => {
|
|
57
62
|
if (!disabled) {
|
|
58
63
|
onChange(!checked);
|
|
59
64
|
}
|
|
@@ -70,10 +75,13 @@ export const Toggle = ({
|
|
|
70
75
|
disabled={disabled}
|
|
71
76
|
role="switch"
|
|
72
77
|
aria-checked={checked}
|
|
73
|
-
onClick={() => {
|
|
78
|
+
onClick={(event) => {
|
|
74
79
|
if (inputRef.current) {
|
|
75
80
|
inputRef.current.click();
|
|
76
81
|
}
|
|
82
|
+
if (onClick) {
|
|
83
|
+
onClick(event);
|
|
84
|
+
}
|
|
77
85
|
}}
|
|
78
86
|
{...rest}
|
|
79
87
|
>
|
|
@@ -82,7 +90,7 @@ export const Toggle = ({
|
|
|
82
90
|
disabled={disabled}
|
|
83
91
|
checked={checked}
|
|
84
92
|
type="checkbox"
|
|
85
|
-
onChange={
|
|
93
|
+
onChange={handleChange}
|
|
86
94
|
value={checked ? "on" : "off"}
|
|
87
95
|
hidden
|
|
88
96
|
{...inputProps}
|