Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

chip

v1.10.0arrow_drop_down
v1.10.0
v1.9.0
v1.7.0
v1.6.1
v1.4.0
STATUS
Passing
DOWNLOADS
404
VISIBILITY
Public
PUBLISHED
A year ago
SIZE
22 KB
A Chip displays a label that can be removed from view.
1 contributor
Install chip as a package?
Copied
npm i @bit/nexxtway.react-rainbow.chip
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
components/Chip/index.js
55 Lines(41 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React from 'react';
import PropTypes from 'prop-types';
import CloseIcon from './closeIcon';
import RenderIf from '../RenderIf';
import StyledContainer from './styled/container';
import TruncatedText from '../Structural/truncatedText';
import StyledButtonIcon from './styled/buttonIcon';

/**
 * A Chip displays a label that can be removed from view.
 */
export default function Chip(props) {
    const { label, onDelete, variant, title, className, style } = props;

    return (
        <StyledContainer className={className} style={style} variant={variant} title={title}>
            <TruncatedText>{label}</TruncatedText>
            <RenderIf isTrue={!!onDelete}>
                <StyledButtonIcon
                    variant={variant}
                    icon={<CloseIcon />}
                    size="small"
                    title="Close"
                    onClick={onDelete}
                    assistiveText="Remove"
                />
            </RenderIf>
        </StyledContainer>
    );
}

Chip.propTypes = {
    /** The content to be displayed inside the Chip. */
    label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
    /** Displays tooltip text when the mouse moves over the element. */
    title: PropTypes.string,
    /** The variant changes the appearance of the Chip. Accepted variants include base,
     * neutral, outline-brand and brand. This value defaults to base. */
    variant: PropTypes.oneOf(['base', 'neutral', 'outline-brand', 'brand']),
    /** The action triggered when the close button is clicked. */
    onDelete: PropTypes.func,
    /** A CSS class for the outer element, in addition to the component's base classes. */
    className: PropTypes.string,
    /** An object with custom style applied to the outer element. */
    style: PropTypes.object,
};

Chip.defaultProps = {
    label: null,
    title: undefined,
    variant: 'base',
    onDelete: undefined,
    className: undefined,
    style: undefined,
};