Skip to content

Hide/show a component's children. It's like ng-show or ng-hide for react.

Notifications You must be signed in to change notification settings

Zombaya/react-toggle-display

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-toggle-display

Build Status

A stateless react component that toggles the display of it's children. It's like ng-show, ng-hide or ng-if but for react.

This allows you to DRY up statements like this:

<div className={this.props.shouldHide ? 'hidden' : ''}>

Example usage:

import ToggleDisplay from 'react-toggle-display';

export default React.createClass({

	getInitialState() {
		return {
			isAuthorized: false
		};
	},

	render() {
		return (
			<ToggleDisplay show={this.state.isAuthorized}>
				<p>Secret stuff for authorized people only.</p>
			</ToggleDisplay>
		);
	}

});

View demo

Props

hide - boolean

show - boolean

if - boolean

tag - string. The tag name to use as the ToggleDisplay element. Defaults to span.

The two first props are simply the inverse of each other. Using both at the same time will result in canceling each other out.

Install

npm install react-toggle-display

Tests

To run tests: npm test

Contributors

Big thanks to willgm for his contributions.

Change Notes

Note that if you are using a version under 0.1.1, you will have to compile react-toggle-display's JSX yourself. I recommend just updating to 1.x so you don't have to worry about that. No breaking API changes in 1.x.

While v2 does not change anything functionally, it was refactored to be a "stateless functional component", which won't work in React versions less than 0.14.

About

Hide/show a component's children. It's like ng-show or ng-hide for react.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%