@onesy/ui-react
Version:
UI for React
149 lines (148 loc) • 6.62 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _compilerRuntime = require("react/compiler-runtime");
var _react = _interopRequireDefault(require("react"));
var _utils = require("@onesy/utils");
var _styleReact = require("@onesy/style-react");
var _Button = _interopRequireDefault(require("../Button"));
var _Type = _interopRequireDefault(require("../Type"));
var _utils2 = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["tonal", "version", "size", "color", "image", "alt", "square", "elevation", "disabled", "TypeProps", "InteractionProps", "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) { (0, _defineProperty2.default)(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; }
const useStyle = (0, _styleReact.style)(theme => ({
root: {
'&.onesy-Button-root': {
cursor: 'default',
overflow: 'hidden',
borderRadius: theme.methods.shape.radius.value(40, 'px'),
'& .onesy-Button-icon-root': {
width: '100%',
height: '100%'
}
}
},
square: {
borderRadius: '0px'
},
image: {
width: '100%',
height: '100%',
backgroundPosition: 'center',
backgroundSize: 'cover',
backgroundRepeat: 'no-repeat'
}
}), {
name: 'onesy-Avatar'
});
const Avatar = props_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2;
const $ = (0, _compilerRuntime.c)(3);
const theme = (0, _styleReact.useOnesyTheme)();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesyAvatar) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
const Button = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Button) || _Button.default;
const Type = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Type) || _Type.default;
const {
tonal: t0,
version: t1,
size: t2,
color: t3,
image,
alt,
square,
elevation: t4,
disabled,
TypeProps,
InteractionProps,
Component: t5,
className,
children: children_
} = props,
other = (0, _objectWithoutProperties2.default)(props, _excluded);
const tonal = t0 === undefined ? false : t0;
const version = t1 === undefined ? "filled" : t1;
const size = t2 === undefined ? "regular" : t2;
const color_ = t3 === undefined ? "auto" : t3;
const elevation = t4 === undefined ? 0 : t4;
const Component = t5 === undefined ? "button" : t5;
const {
classes
} = useStyle();
let children = children_;
if (image) {
const imageProps = {
style: {}
};
if (["text", "outlined"].includes(version) && disabled) {
imageProps.style.opacity = theme.palette.visual_contrast.default.opacity[theme.palette.light ? "disabled" : "active"];
}
const t6 = `url(${image})`;
const t7 = imageProps === null || imageProps === void 0 ? void 0 : imageProps.style;
let t8;
if ($[0] !== t6 || $[1] !== t7) {
t8 = _objectSpread({
backgroundImage: t6
}, t7);
$[0] = t6;
$[1] = t7;
$[2] = t8;
} else {
t8 = $[2];
}
children = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", _objectSpread(_objectSpread({}, imageProps), {}, {
className: (0, _styleReact.classNames)([imageProps === null || imageProps === void 0 ? void 0 : imageProps.className, classes.image]),
style: t8
}));
} else {
if (! /*#__PURE__*/_react.default.isValidElement(children)) {
const typeProps = {
version: "t1"
};
if (size === "small") {
typeProps.size = "0.75rem";
} else {
if (size === "regular") {
typeProps.size = "1rem";
} else {
if (size === "large") {
typeProps.size = "1.25rem";
} else {
if (!["small", "regular", "large"].includes(size)) {
typeProps.size = `${size * 0.4 / 16}rem`;
}
}
}
}
children = /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread(_objectSpread({}, typeProps), TypeProps), {}, {
children: children
}));
}
}
const color = color_ === "auto" ? (0, _utils.stringToColor)(children_ || "") : color_;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, _objectSpread(_objectSpread({
tonal: tonal,
color: color,
elevation: elevation,
version: version,
size: size,
disabled: disabled,
icon: true,
InteractionProps: _objectSpread({
background: false,
wave: false
}, InteractionProps),
Component: Component,
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)("Avatar", theme) && ["onesy-Avatar-root", `onesy-Avatar-version-${version}`, `onesy-Avatar-size-${size}`], className, classes.root, square && classes.square])
}, other), {}, {
children: children
}));
};
Avatar.displayName = 'onesy-Avatar';
var _default = exports.default = Avatar;