@bitrise/bitkit 10.21.0 → 10.22.0

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "10.21.0",
4
+ "version": "10.22.0",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -132,13 +132,14 @@ ExpandableRows.args = {
132
132
  <TableCaption description="Click on a row">Expandable rows</TableCaption>
133
133
  <Thead>
134
134
  <Tr>
135
+ <Th />
135
136
  <Th colSpan={2}>ID</Th>
136
137
  <Th>Status</Th>
137
138
  <Th>Time</Th>
138
139
  </Tr>
139
140
  </Thead>
140
141
  <Tbody>
141
- <Tr expandableContent={<Box paddingY="12">😎</Box>}>
142
+ <Tr expandableContent={<Box paddingY="12">😎</Box>} defaultIsExpanded>
142
143
  <Td>f6963af857c8f2fe</Td>
143
144
  <Td>Success</Td>
144
145
  <Td>May 29, 2022 10:11:32am</Td>
@@ -148,6 +149,12 @@ ExpandableRows.args = {
148
149
  <Td>Aborted</Td>
149
150
  <Td>May 29, 2022 9:12:50am</Td>
150
151
  </Tr>
152
+ <Tr>
153
+ <Td />
154
+ <Td>f6963af857c8f2fe</Td>
155
+ <Td>Failed</Td>
156
+ <Td>May 29, 2022 10:11:32am</Td>
157
+ </Tr>
151
158
  </Tbody>
152
159
  </>
153
160
  ),
@@ -91,9 +91,7 @@ const Tabletheme: SystemStyleObject = {
91
91
  expandTd: {
92
92
  borderBottomColor: 'transparent',
93
93
  width: '1%',
94
- '+ td': {
95
- paddingLeft: 0,
96
- },
94
+ paddingRight: 0,
97
95
  },
98
96
  },
99
97
  };
@@ -1,4 +1,4 @@
1
- import { Children, ReactNode } from 'react';
1
+ import { Children, ReactNode, useCallback } from 'react';
2
2
  import {
3
3
  Collapse,
4
4
  Tr as ChakraTr,
@@ -10,19 +10,33 @@ import {
10
10
  import IconButton from '../IconButton/IconButton';
11
11
  import Td from './Td';
12
12
 
13
- export interface TableRowProps extends ChakraTableRowProps {
14
- expandableContent?: ReactNode | undefined;
13
+ type RowProps = ChakraTableRowProps & {
15
14
  /**
16
15
  * @deprecated - Please use it only when really necessary, we are working on a new table-like components with clickable items
17
16
  */
18
17
  onClick?: ChakraTableRowProps['onClick'];
19
- }
18
+ };
19
+
20
+ type NonExpandableProps = ChakraTableRowProps & {
21
+ expandableContent?: never;
22
+ defaultIsExpanded?: never;
23
+ onExpandedChanged?: never;
24
+ };
25
+
26
+ type ExpandableProps = ChakraTableRowProps & {
27
+ expandableContent: ReactNode | undefined;
28
+ defaultIsExpanded?: boolean;
29
+ onExpandedChanged?(isExpanded: boolean): void;
30
+ };
31
+
32
+ export type TableRowProps = RowProps & (NonExpandableProps | ExpandableProps);
20
33
 
21
34
  const Tr = forwardRef<TableRowProps, 'tr'>((props, ref) => {
22
- const { isOpen, onToggle } = useDisclosure();
35
+ const { children, defaultIsExpanded, onExpandedChanged, expandableContent, onClick, ...rest } = props;
36
+
37
+ const { isOpen, onToggle } = useDisclosure({ defaultIsOpen: defaultIsExpanded });
23
38
  const css = useTableStyles();
24
39
 
25
- const { children, expandableContent, onClick, ...rest } = props;
26
40
  const properties: ChakraTableRowProps = {
27
41
  onClick,
28
42
  ...rest,
@@ -32,7 +46,12 @@ const Tr = forwardRef<TableRowProps, 'tr'>((props, ref) => {
32
46
  properties.sx = css.clickableTr;
33
47
  }
34
48
 
35
- //
49
+ const onToggleClick = useCallback(() => {
50
+ const nextOpen = !isOpen;
51
+ onToggle();
52
+ onExpandedChanged?.(nextOpen);
53
+ }, [isOpen, onToggle, onExpandedChanged]);
54
+
36
55
  if (expandableContent) {
37
56
  const colSpan = Children.count(children) + 1;
38
57
  return (
@@ -42,7 +61,7 @@ const Tr = forwardRef<TableRowProps, 'tr'>((props, ref) => {
42
61
  <IconButton
43
62
  iconName="ChevronDown"
44
63
  aria-label="Toggle current row"
45
- onClick={onToggle}
64
+ onClick={onToggleClick}
46
65
  size="small"
47
66
  variant="tertiary"
48
67
  sx={{