UNPKG

@retailmenot/anchor

Version:

A React UI Library by RetailMeNot

92 lines (88 loc) 3.46 kB
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; }; // VENDOR import * as React from 'react'; import classNames from 'classnames'; import styled, { css, ThemeContext } from '@xstyled/styled-components'; import { th, space as spaceStyles } from '@xstyled/system'; // ANCHOR import { variantStyles } from '../utils'; const StyledTab = styled('div') ` display: flex; cursor: pointer; user-select: none; position: relative; transition: 250ms ease background, 250ms ease color, 125ms ease border-color; &.disabled { color: text.disabled; cursor: not-allowed; } ${({ tabTheme }) => tabTheme.styles} ${spaceStyles} ${({ background, active, borderRadius = 'base' }) => css({ color: active ? 'primary.base' : undefined, background: th.color(background), borderRadius, })} ${({ tabTheme, active, activeBorder = tabTheme.activeBorder, activeBorderColor = tabTheme.activeBorderColor, spacing = tabTheme.spacing, position = 'top', }) => ({ left: css({ borderRight: active ? activeBorder : undefined, borderRightColor: active ? activeBorderColor : undefined, marginBottom: spacing, borderTopRightRadius: 0, borderBottomRightRadius: 0, textAlign: 'right', justifyContent: 'flex-end', '&:last-of-type': { marginBottom: 0, }, }), top: css({ borderBottom: active ? activeBorder : undefined, borderBottomColor: active ? activeBorderColor : undefined, marginRight: spacing, borderBottomLeftRadius: 0, borderBottomRightRadius: 0, '&:last-of-type': { marginRight: 0, }, }), bottom: css({ borderTop: active ? activeBorder : undefined, borderTopColor: active ? activeBorderColor : undefined, marginRight: spacing, borderTopLeftRadius: 0, borderTopRightRadius: 0, '&:last-of-type': { marginRight: 0, }, }), right: css({ borderLeft: active ? activeBorder : undefined, borderLeftColor: active ? activeBorderColor : undefined, marginBottom: spacing, borderTopLeftRadius: 0, borderBottomLeftRadius: 0, textAlign: 'left', '&:last-of-type': { marginBottom: 0, }, }), }[position])} `; export const Tab = (_a) => { var { className, position = 'top', onClick, disabled, active } = _a, props = __rest(_a, ["className", "position", "onClick", "disabled", "active"]); const theme = React.useContext(ThemeContext); const tabTheme = variantStyles(Object.assign(Object.assign({}, props), { theme })).tab || {}; return (React.createElement(StyledTab, Object.assign({ className: classNames('anchor-tabs-header-item', className, active && 'active', disabled && 'disabled'), disabled: disabled, position: position, onClick: !disabled ? onClick : undefined, active: active, tabTheme: tabTheme }, props))); }; //# sourceMappingURL=Tab.component.js.map