@loadsmart/loadsmart-ui 6.3.0 → 7.0.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.
@@ -36,7 +36,6 @@ import type {
36
36
  TablePickerItemProps,
37
37
  TablePickerProps,
38
38
  ExpandableTableRowProps,
39
- TableHeadCellProps,
40
39
  } from './Table.types'
41
40
 
42
41
  const StyledTableBody = styled.tbody`
@@ -83,7 +82,6 @@ const StyledTableCell = styled.td<{ alignment?: string; format?: string }>`
83
82
  const StyledTableHeadCell = styled.th<{
84
83
  alignment?: string
85
84
  clickable: boolean
86
- capitalized?: boolean
87
85
  }>`
88
86
  ${StyledCell}
89
87
 
@@ -91,10 +89,7 @@ const StyledTableHeadCell = styled.th<{
91
89
 
92
90
  font-weight: ${token('font-weight-bold')};
93
91
 
94
- text-transform: ${conditional({
95
- uppercase: whenProps({ capitalized: false }),
96
- capitalize: whenProps({ capitalized: true }),
97
- })};
92
+ text-transform: capitalize;
98
93
 
99
94
  cursor: ${conditional({
100
95
  pointer: whenProps({ clickable: true }),
@@ -103,17 +98,6 @@ const StyledTableHeadCell = styled.th<{
103
98
  `
104
99
 
105
100
  const StyledTableHead = styled.thead`
106
- box-shadow: 0 1px 0 ${token('color-neutral')};
107
-
108
- ${StyledTableCell} {
109
- padding: ${token('space-s')};
110
-
111
- font-weight: ${token('font-weight-bold')};
112
- text-transform: uppercase;
113
- }
114
- `
115
-
116
- const StyledExpandableTableHead = styled.thead`
117
101
  border: 1px solid ${token('color-neutral-lighter')};
118
102
 
119
103
  ${StyledTableCell} {
@@ -124,43 +108,24 @@ const StyledExpandableTableHead = styled.thead`
124
108
  }
125
109
  `
126
110
 
127
- const BaseStyledTableRow = styled.tr`
111
+ const StyledTableRow = styled.tr<{ selected: boolean; isExpanded: boolean }>`
128
112
  ${StyledTableHead} > & {
129
- height: 36px;
130
-
131
- background-color: ${token('color-neutral-white')};
113
+ background-color: ${token('color-neutral-lightest')};
132
114
  }
133
115
 
134
- ${StyledTableBody} > & {
135
- ${hoverable`
136
- outline: 1px solid ${token('color-accent')};
137
- `}
138
-
139
- ${focusable`
140
- box-shadow: inset ${token('shadow-glow-primary')};
141
- `}
116
+ ${StyledTableFoot} > & {
117
+ background-color: ${token('color-neutral-lightest')};
142
118
  }
143
- `
144
119
 
145
- const StyledTableRow = styled(BaseStyledTableRow)<{ selected?: boolean }>`
146
120
  background-color: ${conditional({
147
121
  'table-row-selected-color': whenProps({ selected: true }),
148
- 'color-transparent': whenProps({ selected: false }),
122
+ 'color-neutral-white': whenProps({ selected: false }),
149
123
  })};
150
-
151
- ${StyledTableBody} > & {
152
- &:nth-child(odd) ${StyledTableCell} {
153
- background: ${token('table-row-variant-color')};
154
- }
155
-
156
- &:nth-child(even) ${StyledTableCell} {
157
- background: ${token('color-transparent')};
158
- }
159
- }
160
- `
161
-
162
- const StyledExpandableTableRow = styled.tr<{ $isExpanded: boolean }>`
163
- background-color: ${token('color-neutral-white')};
124
+ ${hoverable`
125
+ background-color: ${conditional({
126
+ 'table-row-selected-color': whenProps({ selected: true }),
127
+ })} !important;
128
+ `}
164
129
 
165
130
  border-color: ${token('color-neutral-lighter')};
166
131
  border-width: 1px;
@@ -168,22 +133,24 @@ const StyledExpandableTableRow = styled.tr<{ $isExpanded: boolean }>`
168
133
  border-right-style: solid;
169
134
  border-left-style: solid;
170
135
  border-bottom-style: ${conditional({
171
- solid: whenProps({ $isExpanded: false }),
172
- hidden: whenProps({ $isExpanded: true }),
136
+ solid: whenProps({ isExpanded: false }),
137
+ hidden: whenProps({ isExpanded: true }),
173
138
  })};
174
139
 
175
140
  box-shadow: ${conditional({
176
- '0px 3px 3px 0px #C1CED9': whenProps({ $isExpanded: true }),
177
- none: whenProps({ $isExpanded: false }),
141
+ '0px 3px 3px 0px #C1CED9': whenProps({ isExpanded: true }),
142
+ none: whenProps({ isExpanded: false }),
178
143
  })};
179
144
 
180
- ${hoverable`
181
- background-color: ${token('color-neutral-lighter')};
182
- `}
145
+ ${StyledTableBody} > & {
146
+ ${hoverable`
147
+ background-color: ${token('color-neutral-lighter')};
148
+ `}
183
149
 
184
- ${focusable`
185
- box-shadow: inset ${token('shadow-glow-primary')};
186
- `}
150
+ ${focusable`
151
+ box-shadow: inset ${token('shadow-glow-primary')};
152
+ `}
153
+ }
187
154
  `
188
155
 
189
156
  const StyledExpandableContentRow = styled.tr`
@@ -195,20 +162,16 @@ const StyledExpandableContentRow = styled.tr`
195
162
  border-bottom-style: solid;
196
163
  `
197
164
 
198
- const StyledTable = styled.table<{ scale?: string; withExpandableRows?: boolean }>`
165
+ const StyledTable = styled.table<{ scale?: string }>`
199
166
  width: 100%;
200
167
 
201
168
  white-space: nowrap;
202
169
 
203
- background-color: ${conditional({
204
- 'color-neutral-lightest': whenProps({ withExpandableRows: true }),
205
- 'color-neutral-white': whenProps({ withExpandableRows: false }),
206
- })};
170
+ background-color: ${token('color-neutral-lightest')};
207
171
 
208
172
  border-collapse: collapse;
209
173
 
210
- ${StyledTableBody} ${StyledTableRow},
211
- ${StyledTableBody} ${StyledExpandableTableRow} {
174
+ ${StyledTableBody} ${StyledTableRow} {
212
175
  height: ${conditional({
213
176
  '24px': whenProps({ scale: 'small' }),
214
177
  '48px': whenProps({ scale: 'default' }),
@@ -240,14 +203,13 @@ function Table<T>({
240
203
  children,
241
204
  selection,
242
205
  scale = 'default',
243
- withExpandableRows,
244
206
  ...others
245
207
  }: TableProps<T>): JSX.Element {
246
208
  return (
247
209
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
248
210
  // @ts-ignore
249
211
  <TableSelectionProvider selection={selection}>
250
- <StyledTable scale={scale} withExpandableRows={withExpandableRows} {...others}>
212
+ <StyledTable scale={scale} {...others}>
251
213
  {children}
252
214
  </StyledTable>
253
215
  </TableSelectionProvider>
@@ -273,10 +235,6 @@ function TableHead({ children, ...others }: TableSectionProps): JSX.Element {
273
235
  return <StyledTableHead {...others}>{children}</StyledTableHead>
274
236
  }
275
237
 
276
- function ExpandableTableHead({ children, ...others }: TableSectionProps): JSX.Element {
277
- return <StyledExpandableTableHead {...others}>{children}</StyledExpandableTableHead>
278
- }
279
-
280
238
  function TableBody({ children, ...others }: TableSectionProps): JSX.Element {
281
239
  return <StyledTableBody {...others}>{children}</StyledTableBody>
282
240
  }
@@ -344,19 +302,11 @@ function SelectionHeadCell<T>(props: SelectionCellProps<T>): JSX.Element {
344
302
  )
345
303
  }
346
304
 
347
- function ExpandableHeadCell(props: TableHeadCellProps): JSX.Element {
348
- return <TableHeadCell capitalized {...props} />
349
- }
350
-
351
- function ExpandableCell(props: TableCellProps): JSX.Element {
352
- return <TableCell {...props} />
353
- }
354
-
355
305
  function TableRow({ children, ...others }: TableRowProps): JSX.Element {
356
306
  const selected = useIsRowSelected(children)
357
307
 
358
308
  return (
359
- <StyledTableRow {...others} selected={selected}>
309
+ <StyledTableRow {...others} selected={selected} isExpanded={false}>
360
310
  {children}
361
311
  </StyledTableRow>
362
312
  )
@@ -373,6 +323,8 @@ function ExpandableTableRow({
373
323
  }: ExpandableTableRowProps): JSX.Element {
374
324
  const [openState, setOpenState] = useState(initialExpanded)
375
325
 
326
+ const selected = useIsRowSelected(children)
327
+
376
328
  const open = expanded ?? openState
377
329
  const isExpanded = Boolean(open && expandableContent)
378
330
  const colSpan = Array.isArray(children) ? children.length + 1 : 1
@@ -391,10 +343,10 @@ function ExpandableTableRow({
391
343
 
392
344
  return (
393
345
  <>
394
- <StyledExpandableTableRow {...others} onClick={toggle} $isExpanded={isExpanded}>
395
- <ExpandableCell>{expandableContent && leading}</ExpandableCell>
346
+ <StyledTableRow {...others} onClick={toggle} isExpanded={isExpanded} selected={selected}>
347
+ <TableCell>{expandableContent && leading}</TableCell>
396
348
  {children}
397
- </StyledExpandableTableRow>
349
+ </StyledTableRow>
398
350
  {isExpanded && (
399
351
  <StyledExpandableContentRow>
400
352
  <StyledTableCell colSpan={colSpan}>{expandableContent}</StyledTableCell>
@@ -408,15 +360,13 @@ function TableHeadCell({
408
360
  alignment = 'left',
409
361
  children,
410
362
  onClick,
411
- capitalized = false,
412
363
  ...others
413
- }: TableHeadCellProps): JSX.Element {
364
+ }: TableCellProps): JSX.Element {
414
365
  return (
415
366
  <StyledTableHeadCell
416
367
  clickable={onClick != null}
417
368
  alignment={alignment}
418
369
  onClick={onClick}
419
- capitalized={capitalized}
420
370
  {...others}
421
371
  >
422
372
  <Layout.Group space="xs" align="center">
@@ -563,12 +513,7 @@ Table.Selection = {
563
513
  Cell: SelectionCell,
564
514
  HeadCell: SelectionHeadCell,
565
515
  }
566
- Table.Expandable = {
567
- Head: ExpandableTableHead,
568
- HeadCell: ExpandableHeadCell,
569
- Cell: ExpandableCell,
570
- Row: ExpandableTableRow,
571
- }
516
+ Table.ExpandableRow = ExpandableTableRow
572
517
  Table.SortHandle = TableSortHandle
573
518
  TablePicker.Item = TablePickerItem
574
519
  Table.Picker = TablePicker
@@ -17,7 +17,6 @@ export interface TableProps<T extends Selectable = TableSelectableRow>
17
17
  extends HTMLAttributes<HTMLTableElement> {
18
18
  scale?: Scale
19
19
  selection?: TableSelectionConfig<T>
20
- withExpandableRows?: boolean
21
20
  }
22
21
 
23
22
  export interface TableCaptionProps extends HTMLAttributes<HTMLTableCaptionElement> {
@@ -57,10 +56,6 @@ export interface TableCellProps extends HTMLAttributes<HTMLTableCellElement> {
57
56
  selected?: boolean
58
57
  }
59
58
 
60
- export interface TableHeadCellProps extends TableCellProps {
61
- capitalized?: boolean
62
- }
63
-
64
59
  export type TableColumn<T = Record<string, unknown>> = {
65
60
  /**
66
61
  * The accessor of you entry interface
@@ -119,6 +119,21 @@ describe('SelectEvent', () => {
119
119
  await shouldHaveSelectedOption(input, option)
120
120
  })
121
121
 
122
+ it('selects the option when a RegExp is provided', async () => {
123
+ const props = {
124
+ onChange: jest.fn(),
125
+ }
126
+ setup(props)
127
+ const option = generator.pick(OPTIONS) as GenericOption
128
+ const optionRegexp = new RegExp(option.label, 'i')
129
+
130
+ const input = screen.getByLabelText('Select something')
131
+ await selectEvent.select(optionRegexp, input)
132
+
133
+ shouldHaveDisplayValue(input, option.label)
134
+ await shouldHaveSelectedOption(input, option)
135
+ })
136
+
122
137
  it('unselects the clicked item', async () => {
123
138
  setup({})
124
139
 
@@ -116,11 +116,11 @@ async function collapse(input: HTMLElement): Promise<void> {
116
116
  /**
117
117
  * Select the provided option(s), if they are present in the menu.
118
118
  * Notice that we programatically expand the `Select` menu before select the item
119
- * @param {string} option - Label for the option to be selected.
119
+ * @param {string | RegExp} option - Label for the option to be selected.
120
120
  * @param {HTMLElement} input - You can refer to this element by the label you applied to the `Select`.
121
121
  * @returns {Promise<void>}
122
122
  */
123
- async function select(option: string, input: HTMLElement): Promise<void> {
123
+ async function select(option: string | RegExp, input: HTMLElement): Promise<void> {
124
124
  await expand(input)
125
125
 
126
126
  const menuContainer = getSelectMenu(input)
@@ -872,7 +872,7 @@ const mirandaCompatibility = {
872
872
  // Table
873
873
  'table-row-default-color': color('neutral-white'),
874
874
  'table-row-variant-color': toCSSValue('color-neutral-40', 0.2),
875
- 'table-row-selected-color': toCSSValue('color-primary-60', 0.2),
875
+ 'table-row-selected-color': toCSSValue('color-primary-20'),
876
876
 
877
877
  // Top Navigation
878
878
  'top-navigation-height': rem('60px'),
@@ -1,2 +0,0 @@
1
- "use strict";var t=require("./toArray-b56541b4.js"),n=require("./miranda-compatibility.theme-22a9ce26.js"),e=require("./theming/index.js");function r(t,r){return Object.keys(t||{}).reduce(((o,i)=>{var u;let s=t[i];if(n.isFunction(s)&&(s=s(r)),s){const t=i,n=null!==(u=e.getToken(t,r))&&void 0!==u?u:i;return[...o,n]}return o}),[]).join(" ")}function o(...t){const[n,e]=t;return null==n||!1===n||Number.isNaN(n)?e||n:"string"==typeof n&&0===n.length&&e||n}exports.conditional=function(...e){return function(o){let i=[];for(let u=0;u<e.length;u++){const s=e[u];n.isFunction(s)?i.push(s(o)):t.isObject(s)?i=i.concat(r(s,o)):s&&i.push(String(s))}return i.join(" ")}},exports.prop=function(t,n,e=o){return r=>e(r[t],n)},exports.whenProps=function(e){return function(r){const o=t.toArray(e);let i=!1;for(let e=0;e<o.length;e++){const u=o[e],s=Object.keys(u);let c=!0;for(let e=0;e<s.length&&c;e++){const o=s[e],i=n.lodash_get(r,o),l=u[o];c=Array.isArray(l)?c&&t.toArray(l).includes(i):n.isFunction(l)?c&&Boolean(l(i)):c&&l===i}i=i||c}return i}};
2
- //# sourceMappingURL=prop-201ffe28.js.map