UNPKG

@procore/core-react

Version:
147 lines (130 loc) • 7.96 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var _excluded = ["as", "clickable", "disabled", "href", "size", "children", "onBlur", "onFocus", "rel", "role", "target"], _excluded2 = ["onPress", "onClick"], _excluded3 = ["icon"], _excluded4 = ["children"], _excluded5 = ["imageUrl"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } 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; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } import { useButton } from '@react-aria/button'; import React from 'react'; import { addSubcomponents } from '../_utils/addSubcomponents'; import { StyledAvatarContainer, StyledAvatarOverlay, StyledIconContainer, StyledLabelContainer, StyledPortraitContainer } from './Avatar.styles'; function AvatarInner(_ref, ref) { var as = _ref.as, clickable = _ref.clickable, disabled = _ref.disabled, href = _ref.href, size = _ref.size, children = _ref.children, onBlur = _ref.onBlur, onFocus = _ref.onFocus, rel = _ref.rel, role = _ref.role, target = _ref.target, props = _objectWithoutProperties(_ref, _excluded); var _ref2 = props, onPress = _ref2.onPress, onClick = _ref2.onClick, buttonPropsBase = _objectWithoutProperties(_ref2, _excluded2); var elementType = typeof as === 'string' && as === 'a' ? 'a' : 'div'; var _useButton = useButton(_objectSpread(_objectSpread({}, buttonPropsBase), {}, { onBlur: onBlur, onFocus: onFocus, elementType: elementType, href: href, isDisabled: disabled, onPress: onPress, rel: rel, target: target, type: 'button' }), ref), buttonProps = _useButton.buttonProps; var linkDisabled = disabled || role === 'link' && !href; var a11yProps = role === 'button' ? _objectSpread(_objectSpread({}, buttonProps), {}, { as: as || 'div', $clickable: !disabled }) : role === 'link' ? _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, 'aria-disabled', linkDisabled ? true : undefined), "as", as || 'a'), "$clickable", !linkDisabled), "href", linkDisabled ? undefined : href), "onBlur", onBlur), "onFocus", onFocus), "rel", rel), "role", 'link'), "target", target) : role === 'img' ? _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, 'aria-disabled', disabled ? true : undefined), "role", 'img'), "onBlur", onBlur), "onFocus", onFocus) : { onBlur: onBlur, onFocus: onFocus }; // For button role, spread buttonPropsBase to preserve useButton's onClick // For other roles, spread all props // Exclude ref since it's passed separately var roleSpecificProps = role === 'button' ? buttonPropsBase : props; return /*#__PURE__*/React.createElement(StyledAvatarContainer, _extends({ ref: ref, $clickable: clickable, $disabled: disabled, $size: size, "data-qa": "core-avatar" }, a11yProps, roleSpecificProps), React.Children.only(children), /*#__PURE__*/React.createElement(StyledAvatarOverlay, { "aria-hidden": true })); } var Avatar_ = /*#__PURE__*/React.forwardRef(AvatarInner); var NextAvatar_ = /*#__PURE__*/React.forwardRef(AvatarInner); export var Icon = /*#__PURE__*/React.forwardRef(function Icon(_ref5, ref) { var icon = _ref5.icon, props = _objectWithoutProperties(_ref5, _excluded3); return /*#__PURE__*/React.createElement(StyledIconContainer, _extends({ ref: ref }, props), icon); }); export var Label = /*#__PURE__*/React.forwardRef(function Label(_ref6, ref) { var children = _ref6.children, props = _objectWithoutProperties(_ref6, _excluded4); // Breaking change: Option to make aria-hidden since parent requires a label. // Can add in major once labelling is enforced return /*#__PURE__*/React.createElement(StyledLabelContainer, _extends({ ref: ref }, props), children); }); export var Portrait = /*#__PURE__*/React.forwardRef(function Portrait(_ref7, ref) { var imageUrl = _ref7.imageUrl, props = _objectWithoutProperties(_ref7, _excluded5); return /*#__PURE__*/React.createElement(StyledPortraitContainer, _extends({ ref: ref, $imageUrl: imageUrl }, props), /*#__PURE__*/React.createElement(StyledAvatarOverlay, null)); }); // @ts-ignore Avatar_.displayName = 'Avatar'; Icon.displayName = 'Avatar.Icon'; Label.displayName = 'Avatar.Label'; Portrait.displayName = 'Avatar.Portrait'; // @ts-ignore NextAvatar_.displayName = 'Avatar'; /** We use avatars to visually represent our users, places, and things in the app. These can be in the form of rich media or representative illustrations. @since 10.19.0 @see [Storybook](https://stories.core.procore.com/?path=/story/core-react_demos-avatar--demo) @see [Design Guidelines](https://design.procore.com/avatar) @a11y Avatar's need a `aria-label` and can be enhanced with `role` for interaction. If decorative only, add `aria-hidden`. The inaccessible `clickable` prop is for UI only */ export var NextAvatar = addSubcomponents({ Icon: Icon, Label: Label, Portrait: Portrait }, NextAvatar_); /** We use avatars to visually represent our users, places, and things in the app. These can be in the form of rich media or representative illustrations. @since 10.19.0 @see [Storybook](https://stories.core.procore.com/?path=/story/core-react_demos-avatar--demo) @see [Design Guidelines](https://design.procore.com/avatar) @a11y Avatar's need a `aria-label` and can be enhanced with `role` for interaction. If decorative only, add `aria-hidden`. The inaccessible `clickable` prop is for UI only */ export var Avatar = addSubcomponents({ Icon: Icon, Label: Label, Portrait: Portrait }, Avatar_); //# sourceMappingURL=Avatar.js.map