Sha256: 10708a3ce63d4168d9364556418c093006b69814410a2cce0abeac831df70bdb

Contents?: true

Size: 1.9 KB

Versions: 367

Compression:

Stored size: 1.9 KB

Contents

import React, { useContext } from "react"
import { Getter, Row } from "@tanstack/react-table"

import { GenericObject } from "../../types"

import { GlobalProps } from "../../utilities/globalProps"

import Flex from "../../pb_flex/_flex"
import FlexItem from "../../pb_flex/_flex_item"
import Icon from "../../pb_icon/_icon"

import AdvancedTableContext from "../Context/AdvancedTableContext"

interface CustomCellProps {
  getValue?: Getter<string>
  onRowToggleClick?: (arg: Row<GenericObject>) => void
  row: Row<GenericObject>
  value?: string
} 

export const CustomCell = ({
  getValue,
  onRowToggleClick,
  row,
  value,
}: CustomCellProps & GlobalProps) => {
  const { setExpanded, expanded, expandedControl, inlineRowLoading } = useContext(AdvancedTableContext);

  const handleOnExpand = (row: Row<GenericObject>) => {
    onRowToggleClick && onRowToggleClick(row);
    
    if (!expandedControl) {
      setExpanded({ ...expanded, [row.id]: !row.getIsExpanded() });
    }
  };

  const RowHasChildren = row.original.children ? true : false
  const renderButton = inlineRowLoading ? RowHasChildren : row.getCanExpand()

  return (
    <div style={{ paddingLeft: `${row.depth * 1.25}em` }}>
      <Flex alignItems="center" 
          columnGap="xs"
          orientation="row"
      >
        {renderButton ? (
          <button
              className="gray-icon expand-toggle-icon"
              onClick={() => handleOnExpand(row)}
          >
            {row.getIsExpanded() ? (
              <Icon cursor="pointer"
                  icon="circle-play"
                  rotation={90}
              />
            ) : (
              <Icon cursor="pointer"
                  icon="circle-play"    
               />
            )}
          </button>
        ) : null}
        <FlexItem paddingLeft={renderButton? "none" : "xs"}>
          {row.depth === 0 ? getValue() : value}
        </FlexItem>
      </Flex>
    </div>
  )
}

Version data entries

367 entries across 367 versions & 1 rubygems

Version Path
playbook_ui-14.7.0.pre.rc.16 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.15 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.14 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.13 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.12 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PLAY15814384 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4380 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.11 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.10 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PLAY1551tiptapextbump4350 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PLAY15814348 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.9 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.8 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4316 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.7 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4312 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4305 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.7.0.pre.rc.6 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PBNTR576tooltiptruncatedformpills4304 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx
playbook_ui-14.6.2.pre.alpha.PBNTR633dropdownavailablepropstable4303 app/pb_kits/playbook/pb_advanced_table/Components/CustomCell.tsx