Sha256: 92ad9aa45e1b75b73d781466a6fac7cdde05daa66dd85b0e43315611852fbd69

Contents?: true

Size: 1.95 KB

Versions: 71

Compression:

Stored size: 1.95 KB

Contents

/* eslint-disable react/no-multi-comp */

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

import Flex from '../../pb_flex/_flex'
import FlexItem from '../../pb_flex/_flex_item'
import { IconSizes } from "../../pb_icon/_icon"
import CollapsibleContext from '../context'
import CollapsibleIcon from './CollapsibleIcon'

type CollapsibleMainProps = {
  children: React.ReactNode[] | React.ReactNode,
  className?: string,
  cursor?: string,
  dark?: boolean,
  onClick?: ()=> void
}
type IconColors =  "default" | "light" | "lighter" | "link" | "error" | "success"

const CollapsibleMain = ({
  children,
  className,
  cursor = 'pointer',
  ...props
}: CollapsibleMainProps & GlobalProps): React.ReactElement=> {
  const {collapsed, toggle, icon, iconSize, iconColor, onIconClick, onClick}: any = useContext(CollapsibleContext)
  const mainCSS = buildCss('pb_collapsible_main_kit')
  const mainSpacing = globalProps(props, { cursor })

  const handleCollapsibleClick = () => {
    onClick && onClick();
    //To disable default toggling behavior return "true" in the onClick()
    const disableToggle = onClick && onClick();
    if (disableToggle !== true) {
    toggle();
    }
  }

  return (
    <div className={classnames(mainCSS, mainSpacing, className)}>
      <div onClick={handleCollapsibleClick}>
        <Flex
            spacing="between"
            vertical="center"
        >
          <FlexItem>{children}</FlexItem>
          <FlexItem>
            <CollapsibleIcon
                collapsed={collapsed as () => void}
                icon={icon as string[] | string}
                iconColor={iconColor as IconColors}
                iconSize={iconSize as IconSizes}
                onIconClick={onIconClick}
            />
            </FlexItem>
        </Flex>
      </div>
    </div>
  )
}

export default CollapsibleMain

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
playbook_ui-14.11.0.pre.rc.3 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.alpha.PBNTR662stickyrightcolumnreact5160 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.11.0.pre.rc.2 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.11.0.pre.rc.1 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.alpha.PBNTR775formmatingmaskdefaultvalue5137 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.11.0.pre.rc.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.9.0.pre.alpha.PBNTR767advancedtablemultiheadercolumns5136 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.9.0.pre.alpha.PBNTR775formmatingmaskdefaultvalue5121 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.9.0.pre.alpha.PBNTR775formmatingmaskdefaultvalue5120 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.24 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.23 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.22 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.21 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.9.0.pre.alpha.play1703errorstatealignment5060 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.20 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.19 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.18 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.9.0.pre.alpha.PLAY1660reactdropzone5020 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-14.10.0.pre.rc.17 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx