Module: IconToggle

Icon toggle button that uses MDCIconButton component implemented by react component.

Parameters:
Name Type Description
props Object

Attributes other than followings are passed to the button element of React as is.

Properties
Name Type Attributes Description
className string <optional>

The class name that is added to the root element.

iconClassName string <optional>

The class name that is added to the icon element. This property is valid only when offIcon or onIcon property is specified.

offIcon string <optional>

The inner text of the “off” icon element. This property is ignored when child element is specified.

onIcon string <optional>

The inner text of the “on” icon element. This property is ignored when child element is specified.

isOnState boolean <optional>

Specifies true if initail state is “on”. Default to false.

label string | Array.<string> <optional>

The label of icon togle button. This property maps to aria-label attribute. If aria label is changed depening on icon button state, specify an array with two elements, whose first element is the label for on state and the second element is the label for off state.

disablesMdcInstance boolean <optional>

Specifies true if you do not want to instantiate MDCRipple Component. MDCIconButtonToggle is instantiated regardless of the setting of this property. Default to false.

mdcIconButtonToggleRef React.MutableRefObject <optional>

MutableRefObject which bind an MDCIconButtonToggle instance to.

mdcRippleRef React.MutableRefObject <optional>

MutableRefObject which bind an MDCRipple instance to. The instance is not bind if props.disablesMdcInstance is true.

Source:
Returns:
Type
DetailedReactHTMLElement
Example
import { IconToggle } from 'material-react-js';

function MyVisibilityToggleButton(props) {
  switch (props.type) {
    case 'material':
      return <IconToggle iconClassName="material-icons"
                         offIcon="visibility_off"
                         onIcon="visibility"
                         label="visibility"/>;
      // The following code also returns the same output
      // return (
      //   <IconToggle label="visibility">
      //     <IconToggle.OffIcon className="material-icons">visibility_off</IconToggle.OffIcon>
      //     <IconToggle.OnIcon className="material-icons">visibility</IconToggle.OnIcon>
      //   </IconToggle>
      // );
    case 'image':
      return (
        <IconToggle label="visibility">
          <IconToggle.OffImage src="./img/visibility_off.png" alt="visibility_off"/>
          <IconToggle.OnImage src="./img/visibility.png" alt="visibility"/>
        </IconToggle>
      );
    case 'svg':
      return (
        <IconToggle label="visibility">
          <IconToggle.OffSVG viewBox="0 0 24 24">
            ...
          </IconToggle.OffSVG>
          <IconToggle.OnSVG viewBox="0 0 24 24">
            ...
          </IconToggle.OnSVG>
        </IconToggle>
      );
    default:
      throw new Error('unknown icon type');
  }
}

Methods

(static) IconToggle.OffIcon(propsopt)

Icon element that is used “off” state icon in IconToggle. This component outputs HTML <i> element with appropriate attributes.

Parameters:
Name Type Attributes Description
props Object <optional>

Attributes passed to the i element.

Source:

(static) IconToggle.OffImage(propsopt)

Image element that is used “off” state icon in IconToggle. This component outputs HTML <img> element with appropriate attributes.

Parameters:
Name Type Attributes Description
props Object <optional>

Attributes passed to the img element.

Source:

(static) IconToggle.OffSVG(propsopt)

SVG element that is used “off” state icon in IconToggle. This component outputs HTML <svg> element with appropriate attributes.

Parameters:
Name Type Attributes Description
props Object <optional>

Attributes passed to the svg element.

Source:

(static) IconToggle.OnIcon(propsopt)

Icon element that is used “on” state icon in IconToggle. This component outputs HTML <i> element with appropriate attributes.

Parameters:
Name Type Attributes Description
props Object <optional>

Attributes passed to the i element.

Source:

(static) IconToggle.OnImage(propsopt)

Image element that is used “on” state icon in IconToggle. This component outputs HTML <img> element with appropriate attributes.

Parameters:
Name Type Attributes Description
props Object <optional>

Attributes passed to the img element.

Source:

(static) IconToggle.OnSVG(propsopt)

SVG element that is used “on” state icon in IconToggle. This component outputs HTML <svg> element with appropriate attributes.

Parameters:
Name Type Attributes Description
props Object <optional>

Attributes passed to the svg element.

Source: