1.1.0 • Published 3 years ago

@pmwcs/icon-button v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Icon Buttons

Icon buttons allow users to take actions, and make choices, with a single tap.

Basic Usage

IconButton inherits from the Icon component and can be passed icons in the same way.

<>
  <IconButton icon="star" label="Rate this!" />

  <IconButton icon="favorite" label="Favorite" disabled />

  <IconButton
    icon="images/icons/twitter.png"
    aria-label="Tweet it!"
    tag="a"
    target="_blank"
    href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(
      'You should definitely be using PMWCS for your next project!'
    )}`}
  />
</>

Usage as a Toggle

To use as a toggle, specify an additional toggled on state using 'onIcon'.

<>
  <IconButton icon="favorite_border" onIcon="favorite" />
  <IconButton icon="favorite" onIcon="favorite" disabled />
</>
function Controlled() {
  const [isChecked, setIsChecked] = React.useState(false);
  return (
    <>
      <IconButton
        checked={isChecked}
        onClick={() => setIsChecked(!isChecked)}
        onIcon="star"
        icon="star_border"
      />

      <IconButton
        checked={isChecked}
        onClick={() => setIsChecked(!isChecked)}
        onIcon="images/icons/twitter.png"
        icon="images/icons/facebook.png"
      />
    </>
  );
}
<IconButton
  onIcon={
    <div
      style={{
        background: 'red',
        width: '24px',
        height: '24px'
      }}
    />
  }
  icon={
    <div
      style={{
        background: 'green',
        width: '24px',
        height: '24px',
        borderRadius: '50%'
      }}
    />
  }
/>

IconButton

An IconButton component that can also be used as a toggle.

Props

NameTypeDescription
checkedundefined \| false \| trueControls the on / off state of the a toggleable button.
disabledundefined \| false \| trueMakes the button disabled
foundationRefRef<MDCIconButtonToggleFoundation>Advanced: A reference to the MDCFoundation. Only for Toggleable buttons.
iconIconPropTIcon for the button
labelundefined \| stringApply an aria label.
onChangeundefined \| (evt: IconButtonOnChangeEventT) => voidAn onChange callback that receives a custom event. evt.detail = { isOn: boolean }
onIconIconPropTIf specified, renders a toggle with this icon as the on state.
rippleRipplePropTAdds a ripple effect to the component
size"xsmall" \| "small" \| "medium" \| "large" \| "xlarge"A size to render the icon
primaryundefined \| false \| trueChoose primary theme.
secondaryundefined \| false \| trueChoose secondary theme.
outlinedundefined \| false \| trueMake the button outlined.