@navinc/base-react-components
Version:
Nav's Pattern Library
64 lines • 3.34 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 react_1 = require("react");
const styled_components_1 = __importDefault(require("styled-components"));
const prop_types_1 = __importDefault(require("prop-types"));
const text_js_1 = __importDefault(require("./text.js"));
const is_rebrand_js_1 = __importDefault(require("./is-rebrand.js"));
const TabContainer = styled_components_1.default.div.withConfig({ displayName: "brc-sc-TabContainer", componentId: "brc-sc-2gw3qn" }) `
display: grid;
grid-template-columns: 1fr 1fr;
background-color: ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navSecondary100 : theme.neutral100)};
border: 1px solid ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navNeutral300 : theme.neutral300)};
border-radius: 99px;
position: relative;
`;
const setTabTextColor = (isActive, theme) => {
if ((0, is_rebrand_js_1.default)(theme))
return isActive ? theme.navNeutralLight : theme.navNeutral400;
return isActive ? theme.white : theme.neutral400;
};
const Tab = (0, styled_components_1.default)(text_js_1.default).attrs(() => ({ $bold: true })).withConfig({ displayName: "brc-sc-Tab", componentId: "brc-sc-ys6xtm" }) `
text-align: center;
padding: 16px 32px;
border-radius: 99px;
cursor: pointer;
color: ${({ isActive, theme }) => setTabTextColor(isActive, theme)};
transition: all 0.25s ease-in;
position: relative;
`;
const Glider = styled_components_1.default.div.withConfig({ displayName: "brc-sc-Glider", componentId: "brc-sc-da8bhm" }) `
display: flex;
position: absolute;
top: 0;
bottom: 0;
background-color: ${({ theme }) => ((0, is_rebrand_js_1.default)(theme) ? theme.navPrimary400 : theme.azure)};
width: 50%;
border-radius: 99px;
transition: 0.25s ease-out;
`;
Tab.propTypes = {
isActive: prop_types_1.default.bool,
};
exports.default = (_a) => {
var { children, filterName } = _a, props = __rest(_a, ["children", "filterName"]);
const [isOn, setIsOn] = (0, react_1.useState)(true);
const handleToggleClick = () => setIsOn((isOn) => !isOn);
return ((0, jsx_runtime_1.jsxs)(TabContainer, Object.assign({ "data-testid": "sliding-tabs" }, props, { onClick: handleToggleClick }, { children: [(0, jsx_runtime_1.jsx)(Glider, { "data-testid": "sliding-tabs-glider", style: { transform: `${isOn ? 'translateX(0)' : 'translateX(100%)'}` } }), react_1.Children.toArray(children).map(({ type, key, props }, i) => ((0, jsx_runtime_1.jsx)(Tab, Object.assign({ as: type }, props, { id: i, "data-testid": `sliding-tabs-children-${i}` }), key)))] })));
};
//# sourceMappingURL=sliding-tabs.js.map