@onesy/ui-react
Version:
UI for React
255 lines • 8.59 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["tonal", "color", "version", "size", "value", "onChange", "active", "index", "name", "label", "icon", "iconPosition", "activateOnFocus", "tooltip", "disabled", "onBlur", "onFocus", "LineProps", "TooltipProps", "Component", "className", "children"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import { c as _c } from "react/compiler-runtime";
import React from 'react';
import { is } from '@onesy/utils';
import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import TooltipElement from '../Tooltip';
import TypeElement from '../Type';
import SurfaceElement from '../Surface';
import LineElement from '../Line';
import InteractionElement from '../Interaction';
import { staticClassName } from '../utils';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {
// Reset
fontFamily: 'inherit',
'-webkit-appearance': 'none',
appearance: 'none',
background: 'transparent',
border: 'none',
fontSize: '100%',
lineHeight: '1.15',
margin: '0',
overflow: 'visible',
textTransform: 'none',
position: 'relative',
flex: '0 0 auto',
alignSelf: 'stretch',
userSelect: 'none',
cursor: 'pointer',
opacity: theme.palette.visual_contrast.default.opacity.tertiary,
transition: theme.methods.transitions.make('opacity')
},
size_small: {
padding: `${theme.methods.space.value(1.5, 'px')} ${theme.methods.space.value(3, 'px')}`,
minWidth: '40px',
maxWidth: '200px'
},
size_regular: {
padding: `${theme.methods.space.value(2, 'px')} ${theme.methods.space.value(4, 'px')}`,
minWidth: '70px',
maxWidth: '240px'
},
size_large: {
padding: `${theme.methods.space.value(2.5, 'px')} ${theme.methods.space.value(5, 'px')}`,
minWidth: '100px',
maxWidth: '280px'
},
type_small: {
maxHeight: '2rem'
},
type_regular: {
maxHeight: '2.15rem'
},
type_large: {
maxHeight: '2.6rem'
},
line: {
overflow: 'hidden'
},
active: {
opacity: '1'
},
disabled: {
pointerEvents: 'none',
opacity: theme.palette.visual_contrast.default.opacity.disabled,
cursor: 'default'
}
}), {
name: 'onesy-Tab'
});
const Tab = props_ => {
const $ = _c(28);
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyTab?.props?.default), props_);
const Line = theme?.elements?.Line || LineElement;
const Type = theme?.elements?.Type || TypeElement;
const Surface = theme?.elements?.Surface || SurfaceElement;
const Interaction = theme?.elements?.Interaction || InteractionElement;
const Tooltip = theme?.elements?.Tooltip || TooltipElement;
const {
tonal: t0,
color: t1,
version: t2,
size: t3,
value,
onChange,
active,
index,
name,
label: label_,
icon,
iconPosition: t4,
activateOnFocus,
tooltip,
disabled,
onBlur: onBlur_,
onFocus: onFocus_,
LineProps: t5,
TooltipProps,
Component: t6,
className,
children
} = props,
other = _objectWithoutProperties(props, _excluded);
const tonal = t0 === undefined ? true : t0;
const color = t1 === undefined ? "primary" : t1;
const version = t2 === undefined ? "primary" : t2;
const size = t3 === undefined ? "regular" : t3;
const iconPosition = t4 === undefined ? "start" : t4;
const LineProps = t5 === undefined ? {} : t5;
const Component = t6 === undefined ? "button" : t6;
const {
classes
} = useStyle();
const [focus, setFocus] = React.useState(false);
const label = name !== undefined ? name : label_;
const onBlur = event => {
if (!disabled) {
setFocus(false);
}
if (is("function", onBlur_)) {
onBlur_(event);
}
};
const onFocus = event_0 => {
if (!disabled) {
setFocus(true);
if (activateOnFocus) {
onChange(value, index);
}
}
if (is("function", onFocus_)) {
onFocus_(event_0);
}
};
if (icon !== undefined) {
LineProps.direction = iconPosition === "start" ? "row" : iconPosition === "top" ? "column" : iconPosition === "end" ? "row-reverse" : "column-reverse";
}
let typeVersion = "l2";
if (size === "large") {
typeVersion = "l1";
} else {
if (size === "small") {
typeVersion = "l3";
}
}
const hasTooltip = ![null, undefined].includes(tooltip);
const Wrapper = hasTooltip ? Tooltip : React.Fragment;
const wrapperProps = hasTooltip ? _objectSpread({
name: tooltip
}, TooltipProps) : undefined;
const t7 = !disabled ? 0 : -1;
const t8 = "tab";
const t9 = classNames([staticClassName("Tab", theme) && ["onesy-Tab-root", `onesy-Tab-version-${version}`, `onesy-Tab-size-${size}`, active && "onesy-Tab-active", disabled && "onesy-Tab-disabled"], className, classes.root, classes[`size_${size}`], active && classes.active, disabled && classes.disabled]);
let t10;
if ($[0] !== Interaction || $[1] !== focus) {
t10 = /*#__PURE__*/_jsx(Interaction, {
pulse: focus
});
$[0] = Interaction;
$[1] = focus;
$[2] = t10;
} else {
t10 = $[2];
}
const t11 = 1;
const t12 = "row";
const t13 = "center";
const t14 = "center";
const t15 = classNames([staticClassName("Tab", theme) && ["onesy-Tab-line"], LineProps?.className, classes.line]);
const t16 = label !== undefined && (is("simple", label) ? /*#__PURE__*/_jsx(Type, {
version: typeVersion,
className: classNames([staticClassName("Tab", theme) && ["onesy-Tab-type"], classes[`type_${size}`]]),
children: label
}) : label);
const t17 = children !== undefined && (is("simple", children) ? /*#__PURE__*/_jsx(Type, {
version: typeVersion,
className: classNames([staticClassName("Tab", theme) && ["onesy-Tab-type"], classes[`type_${size}`]]),
children: children
}) : children);
let t18;
if ($[3] !== Line || $[4] !== LineProps || $[5] !== icon || $[6] !== t15 || $[7] !== t16 || $[8] !== t17) {
t18 = /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({
gap: t11,
direction: t12,
align: t13,
justify: t14
}, LineProps), {}, {
className: t15,
children: [icon, t16, t17]
}));
$[3] = Line;
$[4] = LineProps;
$[5] = icon;
$[6] = t15;
$[7] = t16;
$[8] = t17;
$[9] = t18;
} else {
t18 = $[9];
}
let t19;
if ($[10] !== Component || $[11] !== Surface || $[12] !== active || $[13] !== color || $[14] !== onBlur || $[15] !== onFocus || $[16] !== other || $[17] !== t10 || $[18] !== t18 || $[19] !== t7 || $[20] !== t9 || $[21] !== tonal || $[22] !== value) {
t19 = /*#__PURE__*/_jsxs(Surface, _objectSpread(_objectSpread({
tabIndex: t7,
tonal: tonal,
color: color,
onBlur: onBlur,
onFocus: onFocus,
role: t8,
"aria-selected": active,
"data-onesy-tab-value": value,
Component: Component,
className: t9
}, other), {}, {
children: [t10, t18]
}));
$[10] = Component;
$[11] = Surface;
$[12] = active;
$[13] = color;
$[14] = onBlur;
$[15] = onFocus;
$[16] = other;
$[17] = t10;
$[18] = t18;
$[19] = t7;
$[20] = t9;
$[21] = tonal;
$[22] = value;
$[23] = t19;
} else {
t19 = $[23];
}
let t20;
if ($[24] !== Wrapper || $[25] !== t19 || $[26] !== wrapperProps) {
t20 = /*#__PURE__*/_jsx(Wrapper, _objectSpread(_objectSpread({}, wrapperProps), {}, {
children: t19
}));
$[24] = Wrapper;
$[25] = t19;
$[26] = wrapperProps;
$[27] = t20;
} else {
t20 = $[27];
}
return t20;
};
Tab.displayName = 'onesy-Tab';
export default Tab;