Sha256: bc2c14b2ad0841c31648c9fcaec957ac05c027c37a2d7699c91e17589e78507c

Contents?: true

Size: 1.92 KB

Versions: 428

Compression:

Stored size: 1.92 KB

Contents

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

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 { 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): 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

428 entries across 428 versions & 1 rubygems

Version Path
playbook_ui-13.29.0 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-13.28.0.pre.alpha.PBNTR297gradientoverlay3029 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-13.28.0.pre.alpha.pbntr312tableheaderflexremoval3019 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-13.28.0.pre.alpha.dialogturbostreameventlistener3017 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-13.28.0.pre.alpha.PLAY1338alpha3001 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-13.28.0.pre.alpha.PLAY1343fixTooltiprunwayissue2987 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-13.28.0.pre.alpha.PLAY1343fixTooltiprunwayissue2986 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx
playbook_ui-13.28.0.pre.alpha.PLAY1343fixTooltiprunwayissue2984 app/pb_kits/playbook/pb_collapsible/child_kits/CollapsibleMain.tsx