@veracity/vui 2.18.2-beta.0 → 2.18.2-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veracity/vui",
3
- "version": "2.18.2-beta.0",
3
+ "version": "2.18.2-beta.1",
4
4
  "description": "Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.",
5
5
  "module": "./dist/esm/index.js",
6
6
  "main": "./dist/cjs/index.js",
@@ -1,3 +1,5 @@
1
+ import { ReactNode } from 'react'
2
+
1
3
  import { IconProps } from '../icon'
2
4
  import { SystemProps } from '../system'
3
5
  import { ThemingProps } from '../theme'
@@ -52,7 +54,11 @@ export type TheadProps = SystemProps & {}
52
54
 
53
55
  export type TrProps = SystemProps & {
54
56
  /** Adds selected styling. */
57
+ isExpanded?: boolean
55
58
  isSelected?: boolean
59
+ nested?: ReactNode
60
+ onCollapsed?: () => void
61
+ onExpanded?: () => void
56
62
  }
57
63
 
58
64
  export type TableSortIconProps = Omit<IconProps, 'order'> & {
package/src/table/tr.tsx CHANGED
@@ -1,32 +1,67 @@
1
- import React from 'react'
1
+ import { useEffect, useState } from 'react'
2
2
 
3
+ import Button from '../button'
3
4
  import { styled, useStyleConfig, vui } from '../core'
4
5
  import { cs } from '../utils'
5
6
  import { useTableContext } from './context'
6
7
  import { TrProps } from './table.types'
8
+ import Td from './td'
9
+
10
+ const trClassName = 'vui-tr'
11
+ const buttonClassName = (isExpanded?: boolean) => (isExpanded ? 'falAngleUp' : 'falAngleDown')
7
12
 
8
13
  export const TrBase = styled.trBox`
14
+ position: relative;
9
15
  transition-duration: fast;
10
16
  `
11
17
 
12
18
  /** Displays Table row that can contain heading or data cells. */
13
19
  export const Tr = vui<'tr', TrProps>((props, ref) => {
14
- const { className, isSelected, ...rest } = props
20
+ const { className, isExpanded: isExpandedProp, isSelected, nested, onCollapsed, onExpanded, ...rest } = props
15
21
  const { variant } = useTableContext() ?? {}
16
22
  const styles = useStyleConfig('Table', useTableContext())
23
+ const [isExpanded, setIsExpanded] = useState(isExpandedProp)
24
+
25
+ useEffect(() => {
26
+ setIsExpanded(isExpandedProp)
27
+ }, [isExpandedProp])
28
+
29
+ const onToggle = () => {
30
+ if (isExpanded) {
31
+ setIsExpanded(false)
32
+ onCollapsed?.()
33
+ } else {
34
+ setIsExpanded(true)
35
+ onExpanded?.()
36
+ }
37
+ }
17
38
 
18
39
  const selectedProps = isSelected ? { bg: 'skyBlue.selected' } : {}
19
40
 
41
+ rest.children = (
42
+ <>
43
+ {nested !== undefined && (
44
+ <Td textAlign="center" w={10}>
45
+ {nested ? <Button icon={buttonClassName(isExpanded)} onClick={onToggle} variant="subtleBlue" /> : null}
46
+ </Td>
47
+ )}
48
+ {rest.children}
49
+ </>
50
+ )
51
+
20
52
  return (
21
- <TrBase
22
- className={cs('vui-tr', className)}
23
- data-selected={Boolean(isSelected)}
24
- data-variant={variant}
25
- ref={ref}
26
- {...styles.tr}
27
- {...selectedProps}
28
- {...rest}
29
- />
53
+ <>
54
+ <TrBase
55
+ className={cs(trClassName, `${trClassName}-${isExpanded ? 'expanded' : 'collapsed'}`, className)}
56
+ data-selected={Boolean(isSelected)}
57
+ data-variant={variant}
58
+ ref={ref}
59
+ {...styles.tr}
60
+ {...selectedProps}
61
+ {...rest}
62
+ />
63
+ {isExpanded && nested}
64
+ </>
30
65
  )
31
66
  })
32
67