Sha256: b7e1588c3baf175cb57b4ad5af8bbd010db96cbe4622352e6b3a43c4ea100e21

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

/* @flow */

import React, { Component } from 'react'
import classnames from 'classnames'

import Icon from '../Icon/Icon'

export type TabType = {
  active: boolean,
  className?: string,
  href?: string,
  icon?: string,
  onClick?: () => mixed,
  target?: '_blank' | '_top',
  text: string,
}

import styles from './tab.scss'

export default class Tab extends Component<TabType> {
  props: TabType

  renderIcon() {
    const { icon } = this.props
    if (icon) return (<Icon name={icon} />)
    return null
  }

  render() {
    const {
      active,
      className,
      href,
      onClick,
      target,
      text,
    } = this.props

    const css = [
      "tab",
      styles.tab,
      active ? styles[`tab-active`] : null,
      className,
    ]

    return (
      <Choose>
        <When condition={href}>
          <a
              className={classnames(css)}
              href={href}
              target={target}
          >
            { this.renderIcon() }
            {text}
          </a>
        </When>
        <When condition={!href}>
          <div
              className={classnames(css)}
              onClick={onClick}
          >
            { this.renderIcon() }
            {text}
          </div>
        </When>
      </Choose>
    )
  }
}

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
playbook_ui-2.7.2 components/Tab/Tab.jsx
playbook_ui-2.7.1 components/Tab/Tab.jsx
playbook_ui-2.7.0 components/Tab/Tab.jsx
playbook_ui-2.6.0 components/Tab/Tab.jsx
playbook_ui-2.5.0 components/Tab/Tab.jsx
nitro_sg-3.0.2 components/Tab/Tab.jsx