Socket
Socket
Sign inDemoInstall

react-collapsible-mixin

Package Overview
Dependencies
34
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-collapsible-mixin

React component mixin to enable Bootstrap style collapse elements


Version published
Maintainers
1
Install size
8.10 MB
Created

Readme

Source

Build Status

React Collapsible mixin

Bootstrap like Collapsible mixin which work with a predefined toggling behaviour.

Usage

Usage via npm and browserify is recommended at this stage.

Install

npm install --save react-collapsible-mixin

Use

  • Each collapsible content element must have unique ref that has collapsible prefix
  • Each collapser (trigger) element must have href set referencing '#' + ref
  • Each collapser (trigger) element must pass ref of the content its responsible for toggling
var CollapsibleMixin = require('react-collapsible-mixin');

var MyComponent = React.createClass({
	mixins: [CollapsibleMixin],

	render: function () {
		var c1_ref = 'collapsible-content-1';
		var c2_ref = 'collapsible-content-2';

		return (
			<div className="row">
				<div className="col-xs-12">
					<a
						href={'#' + c1_ref}
						className={this.getCollapserClassSet(c1_ref)}
						onClick={this._onToggleCollapsible}>
						Toggle
					</a>
					<a
						href={'#' + c2_ref}
						className={this.getCollapserClassSet(c2_ref)}
						onClick={this._onToggleCollapsible}>
						Toggle
					</a>
				</div>
				<div
					ref={c1_ref}
					className={this.getCollapsibleClassSet(c1_ref)}>
					<p>Here are some random content</p>
					<p>That will toggle</p>
				</div>
				<div
					ref={c2_ref}
					className={this.getCollapsibleClassSet(c2_ref)}>
					<p>Here are some random content</p>
					<p>That will toggle</p>
				</div>
			</div>
		);
	}
});
API

When you include CollapsibleMixin in your component you will get the following states and functions added to your component:

State

this.state.expanded: contains key values pairs that map each ref to its current expanded state. State is obtained initial after component has been mounted by inspecting collapsible content element for existing in className.

getCollapserClassSet(ref, defaults)

Helper function to grab class names for the collapser element. You can optionally pass in defaults object to set extra class names.

getCollapsibleClassSet(ref, defaults)

Helper function to grab class names for the collapsible element. You can optionally pass in defaults object to set extra class names.

_onToggleCollapsible

Event handler which you can attach to collapsers.

Remembering state

Use it with existing LocalStorageMixin to remember the state of the collapsible element.

Recent changes

13th Feb 2015
  • Add support for multiple collapsible elements

Keywords

FAQs

Last updated on 13 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc