# @pmwcs/icon-button

> PMWCS icon-button component

Latest version **1.1.0** (published 2021-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pmwcs/icon-button
pnpm add @pmwcs/icon-button
yarn add @pmwcs/icon-button
bun add @pmwcs/icon-button
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-06-20 |
| First published | 2020-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Maintainers | commenthol |
| Keywords | pmwcs, preact, material, web, components, icon-button |

## Links

- npm: https://www.npmjs.com/package/@pmwcs/icon-button
- Repository: https://github.com/pmwcs/pmwcs
- Homepage: https://github.com/pmwcs/pmwcs#readme
- Issues: https://github.com/pmwcs/pmwcs/issues
- npm.io page: https://npm.io/package/@pmwcs/icon-button

## Dependencies (4)

- [@pmwcs/base](https://npm.io/package/@pmwcs/base.md) ^1.1.0
- [@pmwcs/icon](https://npm.io/package/@pmwcs/icon.md) ^1.1.0
- [@pmwcs/ripple](https://npm.io/package/@pmwcs/ripple.md) ^1.1.0
- [@material/icon-button](https://npm.io/package/@material/icon-button.md) ^7.0.0

## Alternatives

- [@progress/kendo-ooxml](https://npm.io/package/@progress/kendo-ooxml.md) — 152.1K weekly downloads
- [@progress/kendo-react-ripple](https://npm.io/package/@progress/kendo-react-ripple.md) — 8.0K weekly downloads
- [@progress/kendo-react-orgchart](https://npm.io/package/@progress/kendo-react-orgchart.md) — 4.3K weekly downloads
- [@praxisui/dynamic-fields](https://npm.io/package/@praxisui/dynamic-fields.md) — 2.4K weekly downloads
- [@progress/kendo-vue-listbox](https://npm.io/package/@progress/kendo-vue-listbox.md) — 932 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2021-06-20
- 1.0.0-2 (next) — 2020-09-05
- 1.0.2 — 2020-12-30
- 1.0.1 — 2020-10-11
- 1.0.0 — 2020-10-07
- 1.0.0-1 — 2020-08-30

## README

# Icon Buttons

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

- Module **@pmwcs/icon-button**
- Import styles:
  - Using CSS Loader
    - import '@pmwcs/icon-button/styles';
  - Or include stylesheets
    - **'@material/icon-button/dist/mdc.icon-button.css'**
    - **'@pmwcs/icon/icon.css'**
    - **'@material/ripple/dist/mdc.ripple.css'**
- MDC Docs: [https://material.io/develop/web/components/buttons/icon-buttons/](https://material.io/develop/web/components/buttons/icon-buttons/)

## Basic Usage

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

```jsx
<>
  <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'.

```jsx
<>
  <IconButton icon="favorite_border" onIcon="favorite" />
  <IconButton icon="favorite" onIcon="favorite" disabled />
</>
```

```jsx
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"
      />
    </>
  );
}
```

```jsx
<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

| Name | Type | Description |
|------|------|-------------|
| `checked` | `undefined \| false \| true` | Controls the on / off state of the a toggleable button. |
| `disabled` | `undefined \| false \| true` | Makes the button disabled |
| `foundationRef` | `Ref<MDCIconButtonToggleFoundation>` | Advanced: A reference to the MDCFoundation. Only for Toggleable buttons. |
| `icon` | `IconPropT` | Icon for the button |
| `label` | `undefined \| string` | Apply an aria label. |
| `onChange` | `undefined \| (evt: IconButtonOnChangeEventT) => void` | An onChange callback that receives a custom event. evt.detail = { isOn: boolean } |
| `onIcon` | `IconPropT` | If specified, renders a toggle with this icon as the on state. |
| `ripple` | `RipplePropT` | Adds a ripple effect to the component |
| `size` | `"xsmall" \| "small" \| "medium" \| "large" \| "xlarge"` | A size to render the icon |
| `primary` | `undefined \| false \| true` | Choose primary theme. |
| `secondary` | `undefined \| false \| true` | Choose secondary theme. |
| `outlined` | `undefined \| false \| true` | Make the button outlined. |

---
_Source: https://npm.io/package/@pmwcs/icon-button · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
