Skip to main content

Chip

A chip is a compact component used to represent information or selected choices.

Overview

GitHub Workflow Status GitHub Workflow Status

pie-chip is a Web Component built using Lit. It offers a simple and accessible chip component for web applications.

This component can be easily integrated into various frontend frameworks and customised through a set of properties.

Installation

To install pie-chip in your application, run the following on your command line:

npm i @justeattakeaway/pie-webc
yarn add @justeattakeaway/pie-webc

Props

PropOptionsDescriptionDefault
variant"default"
"outline"
"ghost"
Sets the variant of the chip."default"
disabledtrue
false
If true, disables the chip.false
isSelectedtrue
false
If true, the chip component will apply the selected styles.false
isDismissibletrue
false
If true, displays a close icon. Can be only used if isSelected is set to truefalse
isLoadingtrue
false
If true, displays a loading indicator inside the chip.false
aria{ label?: string, close?: string }
Aria properties for the chip to help with making it accessible.undefined

Slots

SlotDescription
default
The default slot is used to pass text into the chip component.
icon
Used to pass an icon into the chip component.

Using pie-icons-webc with the pie-chip icon slot

We recommend using pie-icons-webc when using the icon slot. Here is an example of how you would do this:

<!--
  Note that pie-chip and the icons that you want to use will need to be imported as components into your application.
  See the `pie-icons-webc` README for more info on importing these icons.
-->
<pie-chip>
    <icon-vegan slot="icon"></icon-vegan>
    String
</pie-chip>

Events

When the chip component is not dismissible, it does not emit any custom events. In order to add event listening to this component, you can treat it like a native HTML element in your application.

When the component is dismissible, you will need to listen to the close event listed in the table below.

EventTypeDescription
pie-chip-closeCustomEventTriggered when the user interacts with the close icon.

Examples

For HTML:

// import as module into a js file e.g. main.js
import '@justeattakeaway/pie-webc/components/chip.js'
<!-- pass js file into <script> chip -->
<pie-chip>String</pie-chip>
<script type="module" src="/main.js"></script>

For Native JS Applications, Vue, Angular, Svelte etc.:

// Vue templates (using Nuxt 3)
import '@justeattakeaway/pie-webc/components/chip.js';

<pie-chip>String</pie-chip>

For React Applications:

import { PieChip } from '@justeattakeaway/pie-webc/react/chip.js';

<PieChip>String</PieChip>
// React templates (using Next 13 and SSR)
import { PieChip } from '@justeattakeaway/pie-chip/dist/react';

<PieChip>String</PieChip>

Changelog