1.1.2 • Published 3 years ago

material-ui-toggle-icon v1.1.2

Weekly downloads
3,254
License
MIT
Repository
github
Last release
3 years ago

material-ui-toggle-icon

This project provides a toggle icon for Material-UI.

Demo

If you want to try the component yourself instead of watching a gif, head over to the styleguide for a live demo!

Installation

npm i --save material-ui-toggle-icon

Usage

The component takes two icons and a boolean that tells it whether to display the onIcon or the offIcon. When on is changed, the icon is switched with a transition.

import ToggleIcon from "material-ui-toggle-icon";
import IconButton from "@material-ui/core/IconButton";
import Visibility from "@material-ui/icons/Visibility";
import VisibilityOff from "@material-ui/icons/VisibilityOff";

export default class ToggleIconButton extends Component {
  state = { on: false };

  render() {
    <IconButton onClick={() => setState((state) => ({ on: !state.on }))}>
      <ToggleIcon
        on={state.on}
        onIcon={<Visibility />}
        offIcon={<VisibilityOff />}
      />
    </IconButton>;
  }
}

Properties

NameTypeDefaultDescription
offIcon*elementThe icon to be displayed if the on prop is set to false.
onIcon*elementThe icon to be displayed if the on prop is set to true.
on*boolControls whether the onIcon or the offIcon is displayed.
styleobjectOverride the inline-styles of the root element.

* required property

License

The files included in this repository are licensed under the MIT license.

1.1.2

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

0.2.2

6 years ago

1.0.0

6 years ago

0.2.1

6 years ago

1.0.0-1

7 years ago

1.0.0-0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago