Sha256: 94b3750ddcd8663d529e0cac83c9cd6b2ea037bb3f691b953474cf94e83d9b74

Contents?: true

Size: 1.4 KB

Versions: 70

Compression:

Stored size: 1.4 KB

Contents

/* @flow */

import classnames from 'classnames'
import React, { useContext } from 'react'
import { buildCss } from '../../utilities/props'
import { globalProps } from '../../utilities/globalProps'

import Flex from '../../pb_flex/_flex'
import FlexItem from '../../pb_flex/_flex_item'
import CollapsibleContext from '../context'

type CollapsibleMainProps = {
  children: array<React.ReactNode> | React.ReactNode,
  className?: string,
  padding?: string,
}

type IconProps = {
  collapsed: boolean
}

const Icon = ({ collapsed }: IconProps) => {
  const direction = collapsed ? 'down' : 'up'

  return (
    <div
        key={direction}
        style={{ verticalAlign: 'middle' }}
    >
      <i className={`far fa-chevron-${direction} fa-fw`} />
    </div>
  )
}

const CollapsibleMain = ({
  children,
  className,
  padding = 'md',
  ...props
}: CollapsibleMainProps) => {
  const context = useContext(CollapsibleContext)
  const mainCSS = buildCss('pb_collapsible_main_kit')
  const mainSpacing = globalProps(props, { padding })

  return (
    <div className={classnames(mainCSS, className, mainSpacing)}>
      <div onClick={() => context.collapse()}>
        <Flex
            spacing="between"
            vertical="center"
        >
          <FlexItem>{children}</FlexItem>
          <FlexItem><Icon collapsed={context.collapsed} /></FlexItem>
        </Flex>
      </div>
    </div>
  )
}

export default CollapsibleMain

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
playbook_ui-10.1.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.3.pre.alpha.walkthrough2 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.3.pre.alpha.walkthrough app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.1.alpha.railscusticon app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.2.pre.alpha.pre.iconfix app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.1.alpha.rtflexfix app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.0.pre.alphafonts app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.1 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-10.0.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.19.0.pre.alpha.pre.fonts2 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx