1 | import _extends from "@babel/runtime/helpers/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
3 | import cx from 'classnames';
|
4 | import React, { forwardRef } from 'react';
|
5 | import ClearButton from './ClearButton';
|
6 | import { withToken } from '../behaviors/token';
|
7 | import { isFunction } from '../utils';
|
8 | var InteractiveToken = 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 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, React.createElement(ClearButton, {
|
23 | className: "rbt-token-remove-button",
|
24 | label: "Remove",
|
25 | onClick: onRemove,
|
26 | tabIndex: -1
|
27 | }));
|
28 | });
|
29 |
|
30 | var 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 React.createElement("a", {
|
41 | className: classnames,
|
42 | href: href
|
43 | }, children);
|
44 | }
|
45 |
|
46 | return React.createElement("div", {
|
47 | className: classnames
|
48 | }, children);
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | var Token = forwardRef(function (props, ref) {
|
59 | var disabled = props.disabled,
|
60 | onRemove = props.onRemove,
|
61 | readOnly = props.readOnly;
|
62 | return !disabled && !readOnly && isFunction(onRemove) ? React.createElement(InteractiveToken, _extends({}, props, {
|
63 | ref: ref
|
64 | })) : React.createElement(StaticToken, props);
|
65 | });
|
66 | export default withToken(Token); |
\ | No newline at end of file |