diff --git a/src/scripts/Lookup.js b/src/scripts/Lookup.js index 23d2f2d3a..32142134b 100644 --- a/src/scripts/Lookup.js +++ b/src/scripts/Lookup.js @@ -6,7 +6,7 @@ import { FormElement } from './FormElement'; import Input from './Input'; import { Icon } from './Icon'; import { Spinner } from './Spinner'; -import Pill from './Pill'; +import { Pill } from './Pill'; import DropdownButton from './DropdownButton'; import { DropdownMenuItem } from './DropdownMenu'; import { uuid, isElInChildren, registerStyle } from './util'; diff --git a/src/scripts/Pill.js b/src/scripts/Pill.tsx similarity index 65% rename from src/scripts/Pill.js rename to src/scripts/Pill.tsx index c0fcf9f27..de3277b4c 100644 --- a/src/scripts/Pill.js +++ b/src/scripts/Pill.tsx @@ -1,18 +1,32 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; +import React, { Component, ReactHTML } from 'react'; import classnames from 'classnames'; -import { Icon } from './Icon'; +import { Icon, IconCategory } from './Icon'; import { Button } from './Button'; -class Pill extends Component { - onPillClick(e) { +export type PillProps = { + className?: string; + label?: string; + truncate?: boolean; + disabled?: boolean; + tag?: keyof ReactHTML; + icon?: { + category?: IconCategory; + icon?: string; + }; + pillRef?: (node?: HTMLElement) => void; + onClick?: (e: React.MouseEvent) => void; + onRemove?: (e: any) => void; +}; + +export class Pill extends Component { + onPillClick(e: React.MouseEvent) { if (this.props.onClick) { this.props.onClick(e); } } - onPillRemove(e) { + onPillRemove(e: any) { e.preventDefault(); e.stopPropagation(); if (this.props.onRemove) { @@ -20,7 +34,7 @@ class Pill extends Component { } } - onKeyDown(e) { + onKeyDown(e: React.KeyboardEvent) { if (e.keyCode === 8 || e.keyCode === 46) { // Bacspace / DEL e.preventDefault(); @@ -39,7 +53,7 @@ class Pill extends Component { truncate, className, } = this.props; - const Tag = disabled ? 'span' : tag || 'a'; + const Tag: any = disabled ? 'span' : tag || 'a'; const pillClassNames = classnames( 'slds-pill', { 'slds-truncate': truncate }, @@ -47,14 +61,14 @@ class Pill extends Component { ); return ( { + ref={(node: HTMLElement) => { if (pillRef) pillRef(node); }} className={pillClassNames} onKeyDown={this.onKeyDown.bind(this)} onClick={this.onPillClick.bind(this)} > - {icon ? ( + {icon && icon.icon ? (