UNPKG

norma-library

Version:

Olos/Norma-DS. Design System based on Material UI, developed with TypeScript and Styled Components to create reusable and consistent components in web applications.

73 lines 3.11 kB
import { __assign, __rest } from "tslib"; import React from 'react'; import { Box, Tabs as MuiTabs, Tab } from '@mui/material'; import { palette } from '../helpers'; import { styled } from '@mui/material/styles'; var colorMap = { inherit: palette.inherit, primary: palette.primary, secondary: palette.secondary, error: palette.error, warning: palette.warning, info: palette.info, success: palette.success, }; var TabsStyled = styled(MuiTabs)(function (_a) { var color = _a.color; return ({ borderBottom: '1px solid #e8e8e8', '& .Mui-selected': { color: colorMap[color], }, '& .MuiTabs-indicator': { backgroundColor: colorMap[color], }, '& .MuiButtonBase-root': { textTransform: 'none', }, }); }); var TabStyled = styled(function (props) { return React.createElement(Tab, __assign({ disableRipple: true }, props)); })(function (_a) { var theme = _a.theme, color = _a.color; return ({ textTransform: 'none', fontWeight: theme.typography.fontWeightRegular, fontSize: theme.typography.pxToRem(15), marginRight: theme.spacing(1), color: '#666666', padding: '5px 15px', top: '5px', minWidth: '60px', '&.Mui-selected': { color: colorMap[color], }, '&.Mui-focusVisible': { backgroundColor: 'rgba(100, 95, 228, 0.32)', }, }); }); function CustomTabPanel(props) { var children = props.children, value = props.value, index = props.index, other = __rest(props, ["children", "value", "index"]); return (React.createElement("div", __assign({ role: "tabpanel", hidden: value !== index, id: "simple-tabpanel-".concat(index), "aria-labelledby": "simple-tab-".concat(index) }, other), value === index && (React.createElement(Box, { sx: { p: 3 } }, children)))); } function a11yProps(index) { return { id: "simple-tab-".concat(index), 'aria-controls': "simple-tabpanel-".concat(index), }; } export var Tabs = function (_a) { var _b = _a.data, data = _b === void 0 ? [] : _b, _c = _a.color, color = _c === void 0 ? 'primary' : _c, onChange = _a.onChange, props = __rest(_a, ["data", "color", "onChange"]); var _d = React.useState(0), value = _d[0], setValue = _d[1]; var handleChange = function (event, newValue) { setValue(newValue); if (!!onChange) onChange(event, newValue); }; return (React.createElement(Box, { sx: { width: '100%' } }, React.createElement(Box, null, React.createElement(TabsStyled, __assign({ value: value, color: color, onChange: handleChange, "aria-label": "basic tabs example" }, props), data && data.map(function (item, key) { return React.createElement(TabStyled, __assign({ label: item.label, color: color }, a11yProps(key))); }))), data && data.map(function (item, key) { return (React.createElement(CustomTabPanel, { value: value, index: key, key: key }, item.children)); }))); }; //# sourceMappingURL=Tabs.js.map