UNPKG

2.15 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3import cx from 'classnames';
4import React, { forwardRef } from 'react';
5import ClearButton from './ClearButton';
6import { withToken } from '../behaviors/token';
7import { isFunction } from '../utils';
8var InteractiveToken = /*#__PURE__*/forwardRef(function (_ref, ref) {
9 var active = _ref.active,
10 children = _ref.children,
11 className = _ref.className,
12 onRemove = _ref.onRemove,
13 tabIndex = _ref.tabIndex,
14 props = _objectWithoutPropertiesLoose(_ref, ["active", "children", "className", "onRemove", "tabIndex"]);
15
16 return /*#__PURE__*/React.createElement("div", _extends({}, props, {
17 className: cx('rbt-token', 'rbt-token-removeable', {
18 'rbt-token-active': !!active
19 }, className),
20 ref: ref,
21 tabIndex: tabIndex || 0
22 }), children, /*#__PURE__*/React.createElement(ClearButton, {
23 className: "rbt-token-remove-button",
24 label: "Remove",
25 onClick: onRemove,
26 tabIndex: -1
27 }));
28});
29
30var StaticToken = function StaticToken(_ref2) {
31 var children = _ref2.children,
32 className = _ref2.className,
33 disabled = _ref2.disabled,
34 href = _ref2.href;
35 var classnames = cx('rbt-token', {
36 'rbt-token-disabled': disabled
37 }, className);
38
39 if (href && !disabled) {
40 return /*#__PURE__*/React.createElement("a", {
41 className: classnames,
42 href: href
43 }, children);
44 }
45
46 return /*#__PURE__*/React.createElement("div", {
47 className: classnames
48 }, children);
49};
50/**
51 * Token
52 *
53 * Individual token component, generally displayed within the TokenizerInput
54 * component, but can also be rendered on its own.
55 */
56
57
58var Token = /*#__PURE__*/forwardRef(function (props, ref) {
59 var disabled = props.disabled,
60 onRemove = props.onRemove,
61 readOnly = props.readOnly;
62 return !disabled && !readOnly && isFunction(onRemove) ? /*#__PURE__*/React.createElement(InteractiveToken, _extends({}, props, {
63 ref: ref
64 })) : /*#__PURE__*/React.createElement(StaticToken, props);
65});
66export default withToken(Token);
\No newline at end of file