@navinc/base-react-components
Version:
Nav's Pattern Library
68 lines (66 loc) • 2.8 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;
};
import { jsx as _jsx } from "react/jsx-runtime";
import styled from 'styled-components';
import isRebrand from './is-rebrand';
const getChannelFill = (checked, disabled, color, theme) => {
if (color && checked)
return color;
if (isRebrand(theme))
return checked ? theme.navPrimary400 : theme.navNeutral300;
if (disabled)
return theme.neutral300;
return checked ? theme.azure : theme.neutral400;
};
const getIndicatorColor = (theme, checked) => {
if (isRebrand(theme))
return checked ? theme.navSecondary100 : theme.navNeutral400;
return theme.white;
};
const ToggleChannel = styled.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 }) => isRebrand(theme) && disabled && 'opacity: 38%'};
:focus-within {
outline: 0;
box-shadow: 0 0 0 4px ${({ theme }) => (isRebrand(theme) ? theme.navStatusPositive500 : theme.bubbleBlue300)};
}
`;
const ToggleIndicator = styled.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 (_jsx(ToggleChannel, Object.assign({ "data-testid": "toggle-channel" }, { checked, disabled, color }, { children: _jsx(ToggleIndicator, Object.assign({}, { checked, disabled, color }, props)) })));
};
export default styled(Toggle).withConfig({ componentId: "brc-sc-f5fn0b" }) ``;
//# sourceMappingURL=toggle.js.map