@amaui/ui-react
Version:
UI for React
89 lines (88 loc) • 5.24 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const style_react_1 = require("@amaui/style-react");
const Button_1 = __importDefault(require("../Button"));
const Type_1 = __importDefault(require("../Type"));
const utils_1 = require("../utils");
const utils_2 = require("@amaui/utils");
const useStyle = (0, style_react_1.style)(theme => ({
root: {
'&.amaui-Button-root': {
cursor: 'default',
overflow: 'hidden',
borderRadius: theme.methods.shape.radius.value(40, 'px')
}
},
square: {
borderRadius: '0px'
},
imageWrapper: {
display: 'inline-flex',
height: '100%',
width: '100%',
alignItems: 'center',
justifyContent: 'center'
},
image: {
objectFit: 'cover'
}
}), { name: 'amaui-Avatar' });
const Avatar = react_1.default.forwardRef((props_, ref) => {
const theme = (0, style_react_1.useAmauiTheme)();
const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.amauiAvatar) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
const Button = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Button) || Button_1.default; }, [theme]);
const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]);
const { tonal = false, version = 'filled', size = 'regular', color: color_ = 'auto', image, alt, square, elevation = 0, disabled, TypeProps, InteractionProps, Component = 'button', className, children: children_ } = props, other = __rest(props, ["tonal", "version", "size", "color", "image", "alt", "square", "elevation", "disabled", "TypeProps", "InteractionProps", "Component", "className", "children"]);
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'];
}
children = ((0, jsx_runtime_1.jsx)("span", Object.assign({ className: classes.imageWrapper }, { children: (0, jsx_runtime_1.jsx)("img", Object.assign({ className: classes.image, src: image, alt: alt }, imageProps)) })));
}
else if (!react_1.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 = ((0, jsx_runtime_1.jsx)(Type, Object.assign({}, typeProps, TypeProps, { children: children })));
}
const color = color_ === 'auto' ? (0, utils_2.stringToColor)(children_) : color_;
return ((0, jsx_runtime_1.jsx)(Button, Object.assign({ ref: ref, tonal: tonal, color: color, elevation: elevation, version: version, size: size, disabled: disabled, icon: true, InteractionProps: Object.assign({ background: false, wave: false }, InteractionProps), Component: Component, className: (0, style_react_1.classNames)([
(0, utils_1.staticClassName)('Avatar', theme) && [
'amaui-Avatar-root',
`amaui-Avatar-version-${version}`,
`amaui-Avatar-size-${size}`
],
className,
classes.root,
square && classes.square
]) }, other, { children: children })));
});
Avatar.displayName = 'amaui-Avatar';
exports.default = Avatar;
;