@geezee/react-ui
Version:
Modern and minimalist React UI library.
71 lines (66 loc) • 3.87 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _JSXStyle from "styled-jsx/style";
import React from 'react';
import withDefaults from '../utils/with-defaults';
import useTheme from '../styles/use-theme';
import useWarning from '../utils/use-warning';
import LinkIcon from './icon';
var defaultProps = {
href: '',
color: false,
plain: false,
pure: false,
icon: false,
underline: false,
block: false,
disabled: false,
className: ''
};
var Link = React.forwardRef(function (_ref, ref) {
var href = _ref.href,
color = _ref.color,
plain = _ref.plain,
pure = _ref.pure,
icon = _ref.icon,
iconLeft = _ref.iconLeft,
iconRight = _ref.iconRight,
underline = _ref.underline,
block = _ref.block,
disabled = _ref.disabled,
className = _ref.className,
children = _ref.children,
props = _objectWithoutProperties(_ref, ["href", "color", "plain", "pure", "icon", "iconLeft", "iconRight", "underline", "block", "disabled", "className", "children"]);
var theme = useTheme();
var linkColor = plain ? 'inherit' : theme.palette.cTheme5;
var hoverColor = theme.palette.cTheme6;
var disabledColor = theme.palette.cNeutral5;
var padding = block ? '2px 4px' : '0';
var decoration = underline ? 'underline' : 'none';
if (pure) {
useWarning('Props "pure" is deprecated, now the default Link is pure.', 'Link');
}
if (color) {
useWarning('Props "color" is deprecated, now the default Link is colored.', 'Link', 'info');
}
if (icon) {
useWarning('Props "icon" is no longer supported, use "iconLeft" or "iconRight" instead.', 'Link', 'info');
}
return /*#__PURE__*/React.createElement("a", _extends({
href: href,
ref: ref
}, props, {
className: _JSXStyle.dynamic([["4020703463", [padding, linkColor, block ? theme.expressiveness.R2 : 0, decoration, hoverColor, block ? theme.palette.cTheme0 : 'unset', disabledColor]]]) + " " + (props && props.className != null && props.className || "link ".concat(className).concat(disabled ? ' disabled' : ''))
}), iconLeft && /*#__PURE__*/React.createElement(LinkIcon, {
icon: iconLeft,
className: "left"
}), children, iconRight && /*#__PURE__*/React.createElement(LinkIcon, {
icon: iconRight,
className: "right"
}), /*#__PURE__*/React.createElement(_JSXStyle, {
id: "4020703463",
dynamic: [padding, linkColor, block ? theme.expressiveness.R2 : 0, decoration, hoverColor, block ? theme.palette.cTheme0 : 'unset', disabledColor]
}, ".link.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:baseline;-webkit-box-align:baseline;-ms-flex-align:baseline;align-items:baseline;padding:".concat(padding, ";width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;line-height:inherit;-webkit-text-decoration:none;text-decoration:none;color:").concat(linkColor, ";border-radius:").concat(block ? theme.expressiveness.R2 : 0, ";-webkit-transition:color 200ms ease 0ms;transition:color 200ms ease 0ms;}.link.__jsx-style-dynamic-selector:hover,.link.__jsx-style-dynamic-selector:active,.link.__jsx-style-dynamic-selector:focus{-webkit-text-decoration:").concat(decoration, ";text-decoration:").concat(decoration, ";}.link.__jsx-style-dynamic-selector:hover{color:").concat(hoverColor, ";background-color:").concat(block ? theme.palette.cTheme0 : 'unset', ";}.link.disabled.__jsx-style-dynamic-selector{color:").concat(disabledColor, ";pointer-events:none;cursor:default;}.link.__jsx-style-dynamic-selector .left{margin-left:0;}.link.__jsx-style-dynamic-selector .right{margin-right:0;}")));
});
var MemoLink = React.memo(Link);
export default withDefaults(MemoLink, defaultProps);