Sha256: bd1002a67b38849753638ff2009328b58044a296727c0ff89c53c6f7ef13bff2

Contents?: true

Size: 1.76 KB

Versions: 12

Compression:

Stored size: 1.76 KB

Contents

Rev.registerComponent('StatelessTabsAccordion', class StatelessTabsAccordion extends React.Component {

  static get defaultProps() {
    return {
      onChange: () => {}, // noop
      activeKey: null,
    }
  }

  render() {
    return (
      <ul className="RevAccordion accordion">
        {this.getNormalizedChildren().map(this.renderChild.bind(this))}
      </ul>
    )
  }

  renderChild(child) {
    const active = child.key === this.props.activeKey

    const className = this.classSet({
      "RevTabsAccordion": true,
      "RevTabsAccordion is-active": true,
      "accordion-navigation": true,
      "active": active,
    })

    const tab = React.cloneElement(child.props.tab, {
      onClick: this.handleTabClick(child),
    })

    const content = React.cloneElement(child, {
      active: active,
    })

    return (
      <li key={child.key} className={className}>
        {tab}
        {content}
      </li>
    )
  }

  handleTabClick(activeTab) {
    return (e) => {
      e.preventDefault()
      e.stopPropagation()
      e.activeTab = activeTab
      this.props.onChange(e)
    }
  }
})

Rev.registerComponent('TabsAccordion', class TabsAccordion extends React.Component {

  static get defaultProps() {
    return {
      onChange: () => {}, // noop
    }
  }

  constructor(props) {
    super(props)
    this.state = {
      activeKey: null,
    }
  }

  render() {
    return (
      <Rev.Components.StatelessTabsAccordion
        {...this.props}
        activeKey={this.state.activeKey}
        onChange={this.handleChange.bind(this)}
      />
    )
  }

  handleChange(e) {
    if(e.activeTab.key === this.state.activeKey) {
      e.activeTab = null
    }

    this.setState({
      activeKey: e.activeTab && e.activeTab.key,
    })

    return this.props.onChange(e)
  }
})

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
revelry_core-0.1.24.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.23.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.22.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.21.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.20.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.19.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.18.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.17.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.16.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.15.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.14.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6
revelry_core-0.1.13.0 app/assets/javascripts/revelry/ui/tabs/TabsAccordion.es6