Skip to content

Commit

Permalink
feat(table): add inderminate state & updated selected prop (#372)
Browse files Browse the repository at this point in the history
* feat(table): added indeterminate support for multiselect table

* docs(table): added allSelected and allIndeterminate controls to storybook

* docs(table): updated control name

* fix(table): deprecated allSelected and introduces selected and indeterminate props

* docs(table): updated stoory to use correct prop names
  • Loading branch information
mJarsater authored Oct 24, 2023
1 parent 5ca8038 commit bb75264
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ export default {
defaultValue: { summary: 'Inherit from parent' },
},
},
allSelected: {
name: 'All selected',
description: `Controls the checked state of the "all-selected"-checkbox.`,
control: {
type: 'boolean',
},
},
allIndeterminate: {
name: 'All indeterminate',
description: `Controls the indeterminate state of the "all-selected"-checkbox.`,
control: {
type: 'boolean',
},
},
compactDesign: {
name: 'Compact design',
description: 'Enables compact design of the Table, rows with less height.',
Expand Down Expand Up @@ -116,6 +130,8 @@ export default {
},
args: {
modeVariant: 'Inherit from parent',
allSelected: false,
allIndeterminate: false,
compactDesign: false,
responsiveDesign: false,
verticalDivider: false,
Expand All @@ -129,6 +145,8 @@ export default {

const MultiselectTemplate = ({
modeVariant,
allSelected,
allIndeterminate,
compactDesign,
responsiveDesign,
verticalDivider,
Expand All @@ -150,7 +168,9 @@ const MultiselectTemplate = ({
modeVariant !== 'Inherit from parent' ? `mode-variant="${modeVariant.toLowerCase()}"` : ''
}
>
<tds-table-header>
<tds-table-header ${allSelected ? 'selected' : ''} ${
allIndeterminate ? 'indeterminate' : ''
}>
<tds-header-cell cell-key='truck' cell-value='Truck type' ${
column1Width ? `custom-width="${column1Width}"` : ''
}></tds-header-cell>
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/components/table/table-header/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ------------- | -------------- | ------------------------------------------------------------------------------- | --------- | ------- |
| `allSelected` | `all-selected` | Prop for controling the checked/unchecked state of the "all selected"-checkbox. | `boolean` | `false` |
| Property | Attribute | Description | Type | Default |
| --------------- | --------------- | -------------------------------------------------------------------------------------------- | --------- | ----------- |
| `allSelected` | `all-selected` | <span style="color:red">**[DEPRECATED]**</span> Deprecated, use selected instead..<br/><br/> | `boolean` | `false` |
| `indeterminate` | `indeterminate` | Prop for controling the indeterminate state of the "All selected"-checkbox. | `boolean` | `false` |
| `selected` | `selected` | Prop for controling the checked/unchecked state of the "All selected"-checkbox. | `boolean` | `undefined` |


## Events
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/components/table/table-header/table-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ const relevantTableProps: InternalTdsTablePropChange['changed'] = [
shadow: true,
})
export class TdsTableHeaderRow {
/** Prop for controling the checked/unchecked state of the "all selected"-checkbox. */
/** @deprecated Deprecated, use selected instead.. */
@Prop({ reflect: true, mutable: true }) allSelected: boolean = false;

/** Prop for controling the checked/unchecked state of the "All selected"-checkbox. */
@Prop({ reflect: true, mutable: true }) selected: boolean;

/** Prop for controling the indeterminate state of the "All selected"-checkbox. */
@Prop() indeterminate: boolean = false;

@State() multiselect: boolean = false;

@State() expandableRows: boolean = false;
Expand Down Expand Up @@ -146,7 +152,8 @@ export class TdsTableHeaderRow {
<th class="tds-table__header-cell tds-table__header-cell--checkbox">
<div class="tds-form-label tds-form-label--table">
<tds-checkbox
checked={this.allSelected}
checked={this.allSelected || this.selected}
indeterminate={this.indeterminate}
onTdsChange={(event) => this.handleCheckboxChange(event)}
></tds-checkbox>
</div>
Expand Down

0 comments on commit bb75264

Please sign in to comment.