@navinc/base-react-components
Version:
Nav's Pattern Library
73 lines (71 loc) • 3.25 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const styled_components_1 = __importDefault(require("styled-components"));
const is_rebrand_1 = __importDefault(require("./is-rebrand"));
const getChannelFill = (checked, disabled, color, theme) => {
if (color && checked)
return color;
if ((0, is_rebrand_1.default)(theme))
return checked ? theme.navPrimary400 : theme.navNeutral300;
if (disabled)
return theme.neutral300;
return checked ? theme.azure : theme.neutral400;
};
const getIndicatorColor = (theme, checked) => {
if ((0, is_rebrand_1.default)(theme))
return checked ? theme.navSecondary100 : theme.navNeutral400;
return theme.white;
};
const ToggleChannel = styled_components_1.default.label.withConfig({ displayName: "brc-sc-ToggleChannel", componentId: "brc-sc-183bjk8" }) `
position: relative;
display: inline-block;
border-radius: 100px;
line-height: 1;
height: 24px;
width: 40px;
background: ${({ checked, disabled, color, theme }) => getChannelFill(checked, disabled, color, theme)};
${({ disabled, theme }) => (0, is_rebrand_1.default)(theme) && disabled && 'opacity: 38%'};
:focus-within {
outline: 0;
box-shadow: 0 0 0 4px ${({ theme }) => ((0, is_rebrand_1.default)(theme) ? theme.navStatusPositive500 : theme.bubbleBlue300)};
}
`;
const ToggleIndicator = styled_components_1.default.input.attrs(() => ({ type: 'checkbox' })).withConfig({ displayName: "brc-sc-ToggleIndicator", componentId: "brc-sc-2h1y13" }) `
position: absolute;
box-sizing: border-box;
border: 2px solid ${({ checked, disabled, color, theme }) => getChannelFill(checked, disabled, color, theme)};
border-radius: 50%;
background: ${({ theme, checked }) => getIndicatorColor(theme, checked)};
height: 24px;
width: 24px;
transition: transform 0.2s ease-in-out;
transform: translateX(${({ checked }) => (checked ? '16px' : '0')});
appearance: none;
margin: 0;
font-size: inherit;
:focus {
outline: 0;
box-shadow: none;
}
`;
const Toggle = (_a) => {
var { checked, disabled, color } = _a, props = __rest(_a, ["checked", "disabled", "color"]);
return ((0, jsx_runtime_1.jsx)(ToggleChannel, Object.assign({ "data-testid": "toggle-channel" }, { checked, disabled, color }, { children: (0, jsx_runtime_1.jsx)(ToggleIndicator, Object.assign({}, { checked, disabled, color }, props)) })));
};
exports.default = (0, styled_components_1.default)(Toggle).withConfig({ componentId: "brc-sc-f5fn0b" }) ``;
//# sourceMappingURL=toggle.js.map