@loadsmart/loadsmart-ui 6.1.4 → 6.2.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadsmart/loadsmart-ui",
3
- "version": "6.1.4",
3
+ "version": "6.2.0",
4
4
  "description": "Miranda UI, a React UI library",
5
5
  "main": "dist",
6
6
  "files": [
@@ -522,15 +522,14 @@ export function WithExpandableRow(args: TableProps): JSX.Element {
522
522
  <Table.Head>
523
523
  <Table.Row>
524
524
  <Table.Expandable.HeadCell />
525
- <Table.Expandable.HeadCell>Reference</Table.Expandable.HeadCell>
526
- <Table.Expandable.HeadCell>Product</Table.Expandable.HeadCell>
527
- <Table.Expandable.HeadCell>Price</Table.Expandable.HeadCell>
525
+ <Table.Expandable.HeadCell>reference</Table.Expandable.HeadCell>
526
+ <Table.Expandable.HeadCell>product</Table.Expandable.HeadCell>
527
+ <Table.Expandable.HeadCell>price</Table.Expandable.HeadCell>
528
528
  </Table.Row>
529
529
  </Table.Head>
530
530
 
531
- <Table.Body>
531
+ <Table.Body withExpandableRows>
532
532
  <Table.Expandable.Row
533
- index={0}
534
533
  leading={leading}
535
534
  expandableContent={<div>Forced expanded with custom leading</div>}
536
535
  expanded
@@ -540,7 +539,6 @@ export function WithExpandableRow(args: TableProps): JSX.Element {
540
539
  <Table.Expandable.Cell>12345</Table.Expandable.Cell>
541
540
  </Table.Expandable.Row>
542
541
  <Table.Expandable.Row
543
- index={1}
544
542
  leading={leading}
545
543
  expandableContent={<div>Initial expanded row with custom leading</div>}
546
544
  initialExpanded
@@ -549,12 +547,12 @@ export function WithExpandableRow(args: TableProps): JSX.Element {
549
547
  <Table.Expandable.Cell>Body 2</Table.Expandable.Cell>
550
548
  <Table.Expandable.Cell>12345</Table.Expandable.Cell>
551
549
  </Table.Expandable.Row>
552
- <Table.Expandable.Row index={2} expandableContent={<div>Expandable row</div>}>
550
+ <Table.Expandable.Row expandableContent={<div>Expandable row</div>}>
553
551
  <Table.Expandable.Cell>123456</Table.Expandable.Cell>
554
552
  <Table.Expandable.Cell>Body 3</Table.Expandable.Cell>
555
553
  <Table.Expandable.Cell>12345</Table.Expandable.Cell>
556
554
  </Table.Expandable.Row>
557
- <Table.Expandable.Row index={3} expanded>
555
+ <Table.Expandable.Row expanded>
558
556
  <Table.Expandable.Cell>123456</Table.Expandable.Cell>
559
557
  <Table.Expandable.Cell>Body 5</Table.Expandable.Cell>
560
558
  <Table.Expandable.Cell>12345</Table.Expandable.Cell>
@@ -196,9 +196,8 @@ describe('<Table />', () => {
196
196
  <Table.HeadCell alignment="right">Price $</Table.HeadCell>
197
197
  </Table.Row>
198
198
  </Table.Head>
199
- <Table.Body>
199
+ <Table.Body withExpandableRows>
200
200
  <Table.Expandable.Row
201
- index={0}
202
201
  expandableContent={<div>This is an expandable content on index 0</div>}
203
202
  expanded
204
203
  >
@@ -208,7 +207,7 @@ describe('<Table />', () => {
208
207
  $9876,50
209
208
  </Table.Cell>
210
209
  </Table.Expandable.Row>
211
- <Table.Expandable.Row index={1}>
210
+ <Table.Expandable.Row>
212
211
  <Table.Cell format="number">#000000-2</Table.Cell>
213
212
  <Table.Cell>Modal X 21</Table.Cell>
214
213
  <Table.Cell format="currency" alignment="right">
@@ -216,7 +215,6 @@ describe('<Table />', () => {
216
215
  </Table.Cell>
217
216
  </Table.Expandable.Row>
218
217
  <Table.Expandable.Row
219
- index={2}
220
218
  expandableContent={<div>This is an expandable content on index 2</div>}
221
219
  leading={(expanded) => (expanded ? 'open' : 'closed')}
222
220
  onExpandedChange={onExpandedChange}
@@ -228,7 +226,6 @@ describe('<Table />', () => {
228
226
  </Table.Cell>
229
227
  </Table.Expandable.Row>
230
228
  <Table.Expandable.Row
231
- index={3}
232
229
  expandableContent={<div>This is an expandable content on index 3</div>}
233
230
  expanded={controlledExpanded4}
234
231
  >
@@ -1,4 +1,4 @@
1
- import React, { Children, Fragment, isValidElement, useCallback, useEffect, useState } from 'react'
1
+ import React, { Children, Fragment, isValidElement, useEffect, useState } from 'react'
2
2
  import styled, { css } from 'styled-components'
3
3
  import type { ReactNode } from 'react'
4
4
  import { isFunction } from '@loadsmart/utils-function'
@@ -36,10 +36,15 @@ import type {
36
36
  TablePickerItemProps,
37
37
  TablePickerProps,
38
38
  ExpandableTableRowProps,
39
+ TableBodyProps,
40
+ TableHeadCellProps,
39
41
  } from './Table.types'
40
42
 
41
- const StyledTableBody = styled.tbody`
42
- /* placeholder */
43
+ const StyledTableBody = styled.tbody<{ $withExpandableRows?: boolean }>`
44
+ background-color: ${conditional({
45
+ 'color-neutral-lightest': whenProps({ $withExpandableRows: true }),
46
+ initial: whenProps({ $withExpandableRows: false }),
47
+ })};
43
48
  `
44
49
 
45
50
  const StyledTableFoot = styled.tfoot`
@@ -79,14 +84,21 @@ const StyledTableCell = styled.td<{ alignment?: string; format?: string }>`
79
84
  })};
80
85
  `
81
86
 
82
- const StyledTableHeadCell = styled.th<{ alignment?: string; clickable: boolean }>`
87
+ const StyledTableHeadCell = styled.th<{
88
+ alignment?: string
89
+ clickable: boolean
90
+ capitalized?: boolean
91
+ }>`
83
92
  ${StyledCell}
84
93
 
85
94
  font-family: ${token('font-family-default')};
86
95
 
87
96
  font-weight: ${token('font-weight-bold')};
88
97
 
89
- text-transform: uppercase;
98
+ text-transform: ${conditional({
99
+ uppercase: whenProps({ capitalized: false }),
100
+ capitalize: whenProps({ capitalized: true }),
101
+ })};
90
102
 
91
103
  cursor: ${conditional({
92
104
  pointer: whenProps({ clickable: true }),
@@ -140,11 +152,36 @@ const StyledTableRow = styled(BaseStyledTableRow)<{ selected?: boolean }>`
140
152
  }
141
153
  `
142
154
 
143
- const StyledExpandableTableRow = styled(BaseStyledTableRow)<{ $even: boolean }>`
144
- background-color: ${conditional({
145
- 'table-row-variant-color': whenProps({ $even: true }),
146
- 'color-transparent': whenProps({ $even: false }),
155
+ const StyledExpandableTableRow = styled.tr<{ $isExpanded: boolean }>`
156
+ background-color: ${token('color-neutral-white')};
157
+
158
+ border-color: ${token('color-neutral-light')};
159
+ border-width: 1px;
160
+ border-style: ${conditional({
161
+ solid: whenProps({ $isExpanded: false }),
162
+ 'hidden solid': whenProps({ $isExpanded: true }),
147
163
  })};
164
+
165
+ box-shadow: ${conditional({
166
+ '0px 4px 8px 3px rgba(32, 42, 49, 0.15), 0px 1px 3px 0px rgba(94, 118, 138, 0.20)': whenProps({
167
+ $isExpanded: true,
168
+ }),
169
+ none: whenProps({ $isExpanded: false }),
170
+ })};
171
+
172
+ ${hoverable`
173
+ background-color: ${token('table-row-variant-color')};
174
+ `}
175
+
176
+ ${focusable`
177
+ box-shadow: inset ${token('shadow-glow-primary')};
178
+ `}
179
+ `
180
+
181
+ const StyledExpandableContentRow = styled.tr`
182
+ border-color: ${token('color-neutral-light')};
183
+ border-width: 1px;
184
+ border-style: hidden solid;
148
185
  `
149
186
 
150
187
  const StyledTable = styled.table<{ scale?: string }>`
@@ -221,8 +258,16 @@ function TableHead({ children, ...others }: TableSectionProps): JSX.Element {
221
258
  return <StyledTableHead {...others}>{children}</StyledTableHead>
222
259
  }
223
260
 
224
- function TableBody({ children, ...others }: TableSectionProps): JSX.Element {
225
- return <StyledTableBody {...others}>{children}</StyledTableBody>
261
+ function TableBody({
262
+ children,
263
+ withExpandableRows = false,
264
+ ...others
265
+ }: TableBodyProps): JSX.Element {
266
+ return (
267
+ <StyledTableBody {...others} $withExpandableRows={withExpandableRows}>
268
+ {children}
269
+ </StyledTableBody>
270
+ )
226
271
  }
227
272
 
228
273
  function TableCell({
@@ -288,8 +333,8 @@ function SelectionHeadCell<T>(props: SelectionCellProps<T>): JSX.Element {
288
333
  )
289
334
  }
290
335
 
291
- function ExpandableHeadCell(props: TableCellProps): JSX.Element {
292
- return <TableHeadCell {...props} />
336
+ function ExpandableHeadCell(props: TableHeadCellProps): JSX.Element {
337
+ return <TableHeadCell capitalized {...props} />
293
338
  }
294
339
 
295
340
  function ExpandableCell(props: TableCellProps): JSX.Element {
@@ -307,7 +352,6 @@ function TableRow({ children, ...others }: TableRowProps): JSX.Element {
307
352
  }
308
353
 
309
354
  function ExpandableTableRow({
310
- index,
311
355
  expandableContent,
312
356
  expanded,
313
357
  leading: propsLeading,
@@ -319,8 +363,8 @@ function ExpandableTableRow({
319
363
  const [openState, setOpenState] = useState(initialExpanded)
320
364
 
321
365
  const open = expanded ?? openState
366
+ const isExpanded = Boolean(open && expandableContent)
322
367
  const colSpan = Array.isArray(children) ? children.length + 1 : 1
323
- const isEven = index % 2 === 0
324
368
 
325
369
  let leading: ReactNode = <RotatableIcon name="caret-right" $rotate={open} />
326
370
  if (propsLeading) {
@@ -336,14 +380,14 @@ function ExpandableTableRow({
336
380
 
337
381
  return (
338
382
  <>
339
- <StyledExpandableTableRow {...others} onClick={toggle} $even={isEven}>
383
+ <StyledExpandableTableRow {...others} onClick={toggle} $isExpanded={isExpanded}>
340
384
  <ExpandableCell>{expandableContent && leading}</ExpandableCell>
341
385
  {children}
342
386
  </StyledExpandableTableRow>
343
- {open && expandableContent && (
344
- <StyledExpandableTableRow $even={isEven}>
387
+ {isExpanded && (
388
+ <StyledExpandableContentRow>
345
389
  <StyledTableCell colSpan={colSpan}>{expandableContent}</StyledTableCell>
346
- </StyledExpandableTableRow>
390
+ </StyledExpandableContentRow>
347
391
  )}
348
392
  </>
349
393
  )
@@ -353,13 +397,15 @@ function TableHeadCell({
353
397
  alignment = 'left',
354
398
  children,
355
399
  onClick,
400
+ capitalized = false,
356
401
  ...others
357
- }: TableCellProps): JSX.Element {
402
+ }: TableHeadCellProps): JSX.Element {
358
403
  return (
359
404
  <StyledTableHeadCell
360
405
  clickable={onClick != null}
361
406
  alignment={alignment}
362
407
  onClick={onClick}
408
+ capitalized={capitalized}
363
409
  {...others}
364
410
  >
365
411
  <Layout.Group space="xs" align="center">
@@ -38,10 +38,13 @@ export interface TableSectionProps extends HTMLAttributes<HTMLTableSectionElemen
38
38
  scale?: Scale
39
39
  }
40
40
 
41
+ export interface TableBodyProps extends TableSectionProps {
42
+ withExpandableRows?: boolean
43
+ }
44
+
41
45
  export type TableRowProps = HTMLAttributes<HTMLTableRowElement>
42
46
 
43
47
  export type ExpandableTableRowProps = TableRowProps & {
44
- index: number
45
48
  expandableContent?: ReactNode
46
49
  leading?: ReactNode | ((expanded: boolean) => ReactNode)
47
50
  initialExpanded?: boolean
@@ -57,6 +60,10 @@ export interface TableCellProps extends HTMLAttributes<HTMLTableCellElement> {
57
60
  selected?: boolean
58
61
  }
59
62
 
63
+ export interface TableHeadCellProps extends TableCellProps {
64
+ capitalized?: boolean
65
+ }
66
+
60
67
  export type TableColumn<T = Record<string, unknown>> = {
61
68
  /**
62
69
  * The accessor of you entry interface