New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@rmwc/chip

Package Overview
Dependencies
Maintainers
0
Versions
174
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rmwc/chip

RMWC Chip component

  • 14.3.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Chips

Chips represent complex entities in small blocks, such as a contact.

  • Module @rmwc/chip
  • Import styles:
    • Using CSS Loader
      • import '@rmwc/chip/styles';
    • Or include stylesheets
      • '@material/chips/dist/mdc.chips.css'
      • '@rmwc/icon/icon.css'
      • '@material/ripple/dist/mdc.ripple.css'
  • MDC Docs: https://material.io/develop/web/components/chips/
<ChipSet>
  <Chip selected label="Cookies" />
  <Chip label="Pizza" />
  <Chip label="Icecream" />
</ChipSet>
<ChipSet>
  <Chip icon="favorite" label="Cookies" trailingIcon="close" />
</ChipSet>
function Example() {
  const [selected, setSelected] = React.useState(false);
  return (
    <ChipSet>
      <Chip
        key="my-chip"
        label="Click Me"
        checkmark
        selected={selected}
        onRemove={(evt) => console.log('onRemove', evt.detail)}
        onInteraction={(evt) => {
          console.log('onInteraction', evt.detail);
          setSelected(!selected);
        }}
        onTrailingIconInteraction={(evt) =>
          console.log('onTrailingIconIteraction', evt.detail)
        }
        trailingIcon="close"
      />
    </ChipSet>
  );
}

Filter and Choice Chipsets

You can specify a ChipSet as either a filter of choice which slightly changes the visual styling of selected chips. While material-components-web has some built in functionality for chip sets, it doesn't fit well with React's unidirectional data flow. It is recommended you use standard React patterns to store selected chips in your state and render them accordingly.

Clicking on the trailing close icon will trigger a close animation and put the chip in an exited state, but it is up to you to remove component out from rendering. The you use the onRemove prop implement this behavior.

function Example() {
  const [selected, setSelected] = React.useState({
    cookies: false,
    pizza: false,
    icecream: false
  });
  const toggleSelected = (key) =>
    setSelected({
      ...selected,
      [key]: !selected[key]
    });

  return (
    <ChipSet filter>
      <Chip
        selected={selected.cookies}
        checkmark
        onInteraction={() => toggleSelected('cookies')}
        label="Cookies"
      />
      <Chip
        selected={selected.pizza}
        checkmark
        onInteraction={() => toggleSelected('pizza')}
        icon="local_pizza"
        label="Pizza"
      />
      <Chip
        selected={selected.icecream}
        checkmark
        onInteraction={() => toggleSelected('icecream')}
        icon="favorite_border"
        label="Icecream"
      />
    </ChipSet>
  );
}
function Example() {
  const [selected, setSelected] = React.useState({
    cookies: false,
    pizza: false,
    icecream: false
  });
  const toggleSelected = (key) =>
    setSelected({
      ...selected,
      [key]: !selected[key]
    });

  return (
    <ChipSet choice>
      <Chip
        selected={selected.cookies}
        onInteraction={() => toggleSelected('cookies')}
        label="Cookies"
      />
      <Chip
        selected={selected.pizza}
        onInteraction={() => toggleSelected('pizza')}
        icon="local_pizza"
        label="Pizza"
      />
      <Chip
        selected={selected.icecream}
        onInteraction={() => toggleSelected('icecream')}
        icon="favorite_border"
        label="Icecream"
      />
    </ChipSet>
  );
}

Chip

A Chip component.

Props

NameTypeDescription
checkmarkbooleanIncludes an optional checkmark for the chips selected state.
childrenReactNodeAdditional children will be rendered in the text area.
foundationRefRef<any>Advanced: A reference to the MDCFoundation.
iconIconPropTInstance of an Icon Component.
idstringAn optional chip ID that will be included in callback evt.detail. If this is not passed, RMWC will attempt to use the "key" prop if present.
labelReactNodeText for your Chip.
onInteraction(evt: ChipOnInteractionEventT) => voidA callback for click or enter key. This should be used over onClick for accessibility reasons. evt.detail = { chipId: string }
onRemove(evt: ChipOnRemoveEventT) => voidA callback that is fired once the chip is in an exited state from removing it. evt.detail = { chipId: string }
onTrailingIconInteraction(evt: ChipOnTrailingIconInteractionEventT) => voidA callback for click or enter key for the trailing icon. material-components-web always treats this as an intent to remove the chip. evt.detail = { chipId: string }
selectedbooleanmakes the Chip appear selected.
trailingIconIconPropTInstance of an Icon Component.
trailingIconRemovesChipbooleanDefaults to true. Set this to false if your trailing icon is something other than a remove button.

ChipSet

A container for multiple chips.

Props

NameTypeDescription
choicebooleanCreates a choice chipset
filterbooleanCreates a filter chipset

Keywords

FAQs

Package last updated on 24 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc