UNPKG

@geezee/react-ui

Version:

Modern and minimalist React UI library.

67 lines (62 loc) 3.36 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import _JSXStyle from "styled-jsx/style"; import React, { useMemo } from 'react'; import useTheme from '../styles/use-theme'; import withDefaults from '../utils/with-defaults'; var defaultProps = { type: 'default', label: 'note', small: false, filled: false, className: '' }; var getStatusColor = function getStatusColor(type, filled, theme) { var colors = { secondary: theme.palette.secondary, success: theme.palette.success, warning: theme.palette.warning, error: theme.palette.error }; var statusColor = colors[type]; if (!filled) return { color: statusColor || theme.palette.foreground, borderColor: statusColor || theme.palette.border, bgColor: theme.palette.background }; var filledColor = statusColor ? 'white' : theme.palette.background; return { color: filledColor, borderColor: statusColor || theme.palette.foreground, bgColor: statusColor || theme.palette.foreground }; }; export var Note = function Note(_ref) { var children = _ref.children, type = _ref.type, label = _ref.label, filled = _ref.filled, small = _ref.small, className = _ref.className, props = _objectWithoutProperties(_ref, ["children", "type", "label", "filled", "small", "className"]); var theme = useTheme(); var _useMemo = useMemo(function () { return getStatusColor(type, filled, theme); }, [type, filled, theme]), color = _useMemo.color, borderColor = _useMemo.borderColor, bgColor = _useMemo.bgColor; var padding = small ? "calc(".concat(theme.layout.gapHalf, " / 2) calc(").concat(theme.layout.gap, " / 2)") : "".concat(theme.layout.gapHalf, " ").concat(theme.layout.gap); return /*#__PURE__*/React.createElement("div", _extends({}, props, { className: _JSXStyle.dynamic([["528989377", [padding, borderColor, color, bgColor, theme.expressiveness.R2, theme.layout.gapQuarter]]]) + " " + (props && props.className != null && props.className || "note ".concat(className)) }), label && /*#__PURE__*/React.createElement("span", { className: _JSXStyle.dynamic([["528989377", [padding, borderColor, color, bgColor, theme.expressiveness.R2, theme.layout.gapQuarter]]]) + " " + "label" }, /*#__PURE__*/React.createElement("b", { className: _JSXStyle.dynamic([["528989377", [padding, borderColor, color, bgColor, theme.expressiveness.R2, theme.layout.gapQuarter]]]) }, label, ":")), children, /*#__PURE__*/React.createElement(_JSXStyle, { id: "528989377", dynamic: [padding, borderColor, color, bgColor, theme.expressiveness.R2, theme.layout.gapQuarter] }, ".note.__jsx-style-dynamic-selector{padding:".concat(padding, ";font-size:14px;line-height:1.8;border:1px solid ").concat(borderColor, ";color:").concat(color, ";background-color:").concat(bgColor, ";border-radius:").concat(theme.expressiveness.R2, ";}.note.__jsx-style-dynamic-selector p{margin:0;}.label.__jsx-style-dynamic-selector{text-transform:uppercase;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;line-height:1.5;padding-right:").concat(theme.layout.gapQuarter, ";}"))); }; var MemoNote = React.memo(Note); export default withDefaults(MemoNote, defaultProps);