@procore/core-react
Version:
React library of Procore Design Guidelines
97 lines (91 loc) • 3.95 kB
JavaScript
var _excluded = ["children", "disabled", "focused", "error", "variant"],
_excluded2 = ["children"];
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 _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 { Clear } from '@procore/core-icons';
import { useId } from '@react-aria/utils';
import React from 'react';
import { useI18nContext } from '../_hooks/I18n';
import { addSubcomponents } from '../_utils/addSubcomponents';
import { StyledLabel, StyledRemove, StyledToken } from './Token.styles';
var TokenContext = /*#__PURE__*/React.createContext({
labelId: '',
removeId: '',
isDisabled: false
});
var Parent = /*#__PURE__*/React.forwardRef(function Token(_ref, ref) {
var children = _ref.children,
_ref$disabled = _ref.disabled,
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
_ref$focused = _ref.focused,
focused = _ref$focused === void 0 ? false : _ref$focused,
_ref$error = _ref.error,
error = _ref$error === void 0 ? false : _ref$error,
variant = _ref.variant,
props = _objectWithoutProperties(_ref, _excluded);
var labelId = useId();
var removeId = useId();
var isDisabled = disabled || variant === 'disabled';
var isFocused = focused || variant === 'focused';
return /*#__PURE__*/React.createElement(TokenContext.Provider, {
value: {
labelId: labelId,
removeId: removeId,
isDisabled: isDisabled
}
}, /*#__PURE__*/React.createElement(StyledToken, _extends({
ref: ref,
tabIndex: -1
}, props, {
$disabled: isDisabled,
$focused: isFocused,
$error: error
}), children));
});
var Remove = /*#__PURE__*/React.forwardRef(function TokenRemove(props, ref) {
var i18n = useI18nContext();
var _React$useContext = React.useContext(TokenContext),
labelId = _React$useContext.labelId,
removeId = _React$useContext.removeId,
isDisabled = _React$useContext.isDisabled;
return /*#__PURE__*/React.createElement(StyledRemove, _extends({
ref: ref,
"aria-hidden": "false",
"aria-label": i18n.t('core.token.remove'),
"aria-labelledby": "".concat(removeId, " ").concat(labelId),
id: removeId,
disabled: isDisabled
}, props, {
icon: /*#__PURE__*/React.createElement(Clear, {
role: "img"
}),
size: "sm",
variant: "tertiary"
}));
});
var Label = /*#__PURE__*/React.forwardRef(function Label(_ref2, ref) {
var children = _ref2.children,
props = _objectWithoutProperties(_ref2, _excluded2);
var _React$useContext2 = React.useContext(TokenContext),
labelId = _React$useContext2.labelId;
return /*#__PURE__*/React.createElement(StyledLabel, _extends({
id: labelId,
ref: ref
}, props), children);
});
Parent.displayName = 'Token';
Remove.displayName = 'Token.Remove';
Label.displayName = 'Token.Label';
/**
We use tokens in our multi select dropdowns and file attachers to indicate what
has been selected or attached. Tokens in these components are removable.
@since 10.19.0
@see [Storybook](https://stories.core.procore.com/?path=/story/core-react_demos-token--demo)
@see [Design Guidelines](https://design.procore.com/tokens)
*/
export var Token = addSubcomponents({
Label: Label,
Remove: Remove
}, Parent);
//# sourceMappingURL=Token.js.map