@onesy/ui-react
Version:
UI for React
211 lines • 6.71 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["tonal", "color", "version", "underline", "Component", "className", "style", "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 { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import TypeElement from '../Type';
import { staticClassName } from '../utils';
import { jsx as _jsx } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {
position: 'relative',
display: 'inline-flex',
transition: theme.methods.transitions.make(['color', 'text-decoration'], {
duration: 'xxs'
}),
'&::before': {
content: "''",
display: 'inline-flex',
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
background: 'currentColor',
width: '100%',
height: '100%',
zIndex: '0',
padding: '0.14em 0.77em',
borderRadius: `${theme.shape.radius.unit / 8 * 0.4}em`,
transition: theme.methods.transitions.make(['opacity', 'background']),
opacity: '0'
}
},
focus: {
'&::before': {
opacity: theme.palette.visual_contrast.default.opacity.selected
}
},
// Underline
underline: {
textDecoration: 'underline'
},
underline_hover: {
'&:hover': {
textDecoration: 'underline'
}
},
// Color
color_default: {
color: theme.palette.text.default.primary
},
color_neutral: {
color: theme.palette.color.neutral.main
},
color_primary: {
color: theme.palette.color.primary.main
},
color_secondary: {
color: theme.palette.color.secondary.main
},
color_tertiary: {
color: theme.palette.color.tertiary.main
},
color_quaternary: {
color: theme.palette.color.quaternary.main
},
color_info: {
color: theme.palette.color.info.main
},
color_success: {
color: theme.palette.color.success.main
},
color_warning: {
color: theme.palette.color.warning.main
},
color_error: {
color: theme.palette.color.error.main
},
// Tonal
tonal_color_neutral: {
color: theme.methods.palette.color.value('neutral', 30)
},
tonal_color_primary: {
color: theme.methods.palette.color.value('primary', 30)
},
tonal_color_secondary: {
color: theme.methods.palette.color.value('secondary', 30)
},
tonal_color_tertiary: {
color: theme.methods.palette.color.value('tertiary', 30)
},
tonal_color_quaternary: {
color: theme.methods.palette.color.value('quaternary', 30)
},
tonal_color_info: {
color: theme.methods.palette.color.value('info', 30)
},
tonal_color_success: {
color: theme.methods.palette.color.value('success', 30)
},
tonal_color_warning: {
color: theme.methods.palette.color.value('warning', 30)
},
tonal_color_error: {
color: theme.methods.palette.color.value('error', 30)
}
}), {
name: 'onesy-Link'
});
const Link = props_ => {
const $ = _c(4);
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyLink?.props?.default), props_);
const Type = theme?.elements?.Type || TypeElement;
const {
tonal: t0,
color: t1,
version: t2,
underline: t3,
Component: t4,
className,
style,
children
} = props,
other = _objectWithoutProperties(props, _excluded);
const tonal = t0 === undefined ? true : t0;
const color_ = t1 === undefined ? "primary" : t1;
const version = t2 === undefined ? "b2" : t2;
const underline = t3 === undefined ? true : t3;
const Component = t4 === undefined ? "a" : t4;
const {
classes
} = useStyle();
const [focus, setFocus] = React.useState(false);
const [hover, setHover] = React.useState(false);
const styles = {
root: {}
};
let t5;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t5 = event => {
setFocus(true);
};
$[0] = t5;
} else {
t5 = $[0];
}
const onFocus = t5;
let t6;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
t6 = event_0 => {
setFocus(false);
};
$[1] = t6;
} else {
t6 = $[1];
}
const onBlur = t6;
let t7;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t7 = event_1 => {
setHover(true);
};
$[2] = t7;
} else {
t7 = $[2];
}
const onMouseEnter = t7;
let t8;
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
t8 = event_2 => {
setHover(false);
};
$[3] = t8;
} else {
t8 = $[3];
}
const onMouseLeave = t8;
const color = color_;
let palette;
if (!classes[`color_${color}`]) {
styles.root.color = color;
palette = theme.methods.color(color);
if (tonal) {
styles.root.color = theme.methods.palette.color.value(undefined, 30, true, palette);
}
}
if (underline === true && !hover) {
styles.root.textDecorationColor = theme.methods.palette.color.value(color, 70, true, palette);
}
if (hover) {
styles.root.color = theme.methods.palette.color.value(color, 10, true, palette);
}
return /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({
onFocus: onFocus,
onBlur: onBlur,
onMouseEnter: onMouseEnter,
onMouseLeave: onMouseLeave,
version: version,
role: "link",
Component: Component,
className: classNames([staticClassName("Link", theme) && ["onesy-Link-root", hover && "onesy-Link-hover", focus && "onesy-Link-focus"], className, classes.root, classes[`color_${color}`], tonal && classes[`tonal_color_${color}`], underline === true && classes.underline, underline === "hover" && classes.underline_hover, focus && classes.focus]),
style: _objectSpread(_objectSpread({}, style), styles.root)
}, other), {}, {
children: children
}));
};
Link.displayName = 'onesy-Link';
export default Link;