1 | import cx from 'classnames';
|
2 | import React, { forwardRef } from 'react';
|
3 | import ClearButton from '../ClearButton';
|
4 | import { useToken } from '../../behaviors/token';
|
5 | import { isFunction } from '../../utils';
|
6 | const InteractiveToken = forwardRef(({ active, children, className, onRemove, tabIndex, ...props }, ref) => (React.createElement("div", { ...props, className: cx('rbt-token', 'rbt-token-removeable', {
|
7 | 'rbt-token-active': !!active,
|
8 | }, className), ref: ref, tabIndex: tabIndex || 0 },
|
9 | children,
|
10 | React.createElement(ClearButton, { className: "rbt-token-remove-button", label: "Remove", onClick: onRemove, tabIndex: -1 }))));
|
11 | const StaticToken = ({ children, className, disabled, href, }) => {
|
12 | const classnames = cx('rbt-token', {
|
13 | 'rbt-token-disabled': disabled,
|
14 | }, className);
|
15 | if (href && !disabled) {
|
16 | return (React.createElement("a", { className: classnames, href: href }, children));
|
17 | }
|
18 | return React.createElement("div", { className: classnames }, children);
|
19 | };
|
20 | const Token = ({ children, option, readOnly, ...props }) => {
|
21 | const { ref, ...tokenProps } = useToken({ ...props, option });
|
22 | const child = React.createElement("div", { className: "rbt-token-label" }, children);
|
23 | return !props.disabled && !readOnly && isFunction(tokenProps.onRemove) ? (React.createElement(InteractiveToken, { ...props, ...tokenProps, ref: ref }, child)) : (React.createElement(StaticToken, { ...props }, child));
|
24 | };
|
25 | export default Token;
|