UNPKG

1.49 kBJavaScriptView Raw
1import cx from 'classnames';
2import React, { forwardRef } from 'react';
3import ClearButton from '../ClearButton';
4import { useToken } from '../../behaviors/token';
5import { isFunction } from '../../utils';
6const 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 }))));
11const 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};
20const 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};
25export default Token;