@clayui/form
Version:
ClayForm component
103 lines (102 loc) • 2.58 kB
JavaScript
import ClayIcon from "@clayui/icon";
import classNames from "classnames";
import React from "react";
const Toggle = React.forwardRef(
({
checked,
containerProps = {},
disabled,
id,
label,
onChange,
onToggle,
role = "switch",
sizing,
spritemap,
symbol,
toggled,
type = "checkbox",
value,
...otherProps
}, ref) => {
if (type === "radio") {
role = "radio";
toggled = checked;
}
return /* @__PURE__ */ React.createElement(
"label",
{
...containerProps,
className: classNames(
"toggle-switch",
"simple-toggle-switch",
containerProps.className,
{
disabled,
[`toggle-switch-${sizing}`]: sizing
}
),
ref
},
/* @__PURE__ */ React.createElement("span", { className: "toggle-switch-check-bar" }, /* @__PURE__ */ React.createElement(
"input",
{
...otherProps,
checked: toggled,
className: "toggle-switch-check",
disabled,
id,
onChange: (event) => {
if (onChange) {
onChange(event);
}
if (onToggle) {
onToggle(!toggled);
}
},
role,
type,
value
}
), /* @__PURE__ */ React.createElement("span", { "aria-hidden": "true", className: "toggle-switch-bar" }, /* @__PURE__ */ React.createElement("span", { className: "toggle-switch-handle" }, symbol && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
"span",
{
className: classNames(
"button-icon",
"button-icon-on",
"toggle-switch-icon"
)
},
/* @__PURE__ */ React.createElement(
ClayIcon,
{
spritemap,
symbol: symbol.on
}
)
), /* @__PURE__ */ React.createElement(
"span",
{
className: classNames(
"button-icon",
"button-icon-off",
"toggle-switch-icon"
)
},
/* @__PURE__ */ React.createElement(
ClayIcon,
{
spritemap,
symbol: symbol.off
}
)
))))),
label && /* @__PURE__ */ React.createElement("span", { className: "toggle-switch-label" }, label)
);
}
);
Toggle.displayName = "ClayToggle";
var Toggle_default = Toggle;
export {
Toggle_default as default
};