Sha256: 02dcedbedc06d386d9d8346daaac583c12cfb448e91fbad1fedd5c9b5f285705

Contents?: true

Size: 1.37 KB

Versions: 74

Compression:

Stored size: 1.37 KB

Contents

/* @flow */

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

import { CollapsibleContext } from '../_collapsible.jsx'

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

74 entries across 74 versions & 1 rubygems

Version Path
playbook_ui-9.19.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.19.0.pre.alphafonts app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.18.0.flow.bin.alpha app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.18.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.17.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.17.0.pre.decouple.website2 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.16.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.15.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.15.0.pre.decouple.website1 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.14.1.alpha.radio.alignment app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.14.1.alpha.highcharts9 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.14.1 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.13.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.12.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.12.0.pre.text.addon app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.11.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.10.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.10.0.pre.date.time.stacked.1 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.10.0.pre.alpha2 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx
playbook_ui-9.10.0.pre.alpha1 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.jsx