mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 18:56:39 +00:00
Add ha-data-table (#3647)
* Work in progress * add sorting implemented in unused entities to try it * implement sorting * fix * Refactor * Default sort, filterable, id * Fix * Add local mdc-data-table + comments + fixes * Move mdc-data-tabel So our linters won't complain...
This commit is contained in:
parent
9f213cf055
commit
b46c9406ff
32
mdc-data-table/CHANGELOG.md
Normal file
32
mdc-data-table/CHANGELOG.md
Normal file
@ -0,0 +1,32 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [3.1.1](https://github.com/material-components/material-components-web/compare/v3.1.0...v3.1.1) (2019-08-14)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **data-table:** Fixed alignment of header cell title for numer… ([#4963](https://github.com/material-components/material-components-web/issues/4963)) ([b6274a7](https://github.com/material-components/material-components-web/commit/b6274a7))
|
||||
|
||||
# [4.0.0-alpha.0](https://github.com/material-components/material-components-web/compare/v3.1.0...v4.0.0-alpha.0) (2019-08-07)
|
||||
|
||||
**Note:** Version bump only for package @material/data-table
|
||||
|
||||
# [3.1.0](https://github.com/material-components/material-components-web/compare/v3.0.0...v3.1.0) (2019-07-22)
|
||||
|
||||
### Features
|
||||
|
||||
- **data-table:** Added data table component ([#4889](https://github.com/material-components/material-components-web/issues/4889)) ([7d3380a](https://github.com/material-components/material-components-web/commit/7d3380a))
|
||||
|
||||
# [3.1.0-alpha.0](https://github.com/material-components/material-components-web/compare/v3.0.0...v3.1.0-alpha.0) (2019-07-16)
|
||||
|
||||
### Features
|
||||
|
||||
- **data-table:** Added data table component ([#4889](https://github.com/material-components/material-components-web/issues/4889)) ([7d3380a](https://github.com/material-components/material-components-web/commit/7d3380a))
|
||||
|
||||
# [3.1.0](https://github.com/material-components/material-components-web/compare/v3.0.0...v3.1.0) (2019-07-16)
|
||||
|
||||
### Features
|
||||
|
||||
- **data-table:** Added data table component ([#4889](https://github.com/material-components/material-components-web/issues/4889)) ([7d3380a](https://github.com/material-components/material-components-web/commit/7d3380a))
|
21
mdc-data-table/LICENSE
Normal file
21
mdc-data-table/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2014-2019 Google, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
411
mdc-data-table/README.md
Normal file
411
mdc-data-table/README.md
Normal file
@ -0,0 +1,411 @@
|
||||
<!--docs:
|
||||
title: "Data Tables"
|
||||
layout: detail
|
||||
section: components
|
||||
excerpt: "Material Design-styled tables."
|
||||
iconId: data_table
|
||||
path: /catalog/data-tables/
|
||||
-->
|
||||
|
||||
# Data Table
|
||||
|
||||
Data tables display information in a grid-like format of rows and columns. They organize information in a way that's
|
||||
easy to scan, so that users can look for patterns and insights.
|
||||
|
||||
## Design & API Documentation
|
||||
|
||||
<ul class="icon-list">
|
||||
<li class="icon-list-item icon-list-item--spec">
|
||||
<a href="https://material.io/go/design-data-tables">Material Design guidelines: Data tables</a>
|
||||
</li>
|
||||
<li class="icon-list-item icon-list-item--link">
|
||||
<a href="https://material-components.github.io/material-components-web-catalog/#/component/data-table">Demo</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install @material/data-table
|
||||
```
|
||||
|
||||
### Styles
|
||||
|
||||
```scss
|
||||
@import "@material/checkbox/mdc-checkbox"; // Required only for data table with row selection.
|
||||
@import "@material/data-table/mdc-data-table";
|
||||
```
|
||||
|
||||
> _NOTE_: Styles for any components you intend to include within data-table (e.g. Checkboxes, Buttons etc.) must be
|
||||
> imported.
|
||||
|
||||
### JavaScript Instantiation
|
||||
|
||||
```js
|
||||
import { MDCDataTable } from "@material/data-table";
|
||||
const dataTable = new MDCDataTable(document.querySelector(".mdc-data-table"));
|
||||
```
|
||||
|
||||
> See [Importing the JS component](../../docs/importing-js.md) for more information on how to import JavaScript.
|
||||
|
||||
> Instantiating `MDCDataTable` component is only required to add interactions for example, row selection.
|
||||
|
||||
MDC Data Table component auto instantiates `MDCCheckbox` for header row checkbox and all row checkboxes. Make sure to set required class names to instantiate checkbox component. We suggest to use `layout` API when rows are added or removed from data table to register new checkbox components.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
### HTML Structure
|
||||
|
||||
```html
|
||||
<div class="mdc-data-table">
|
||||
<table class="mdc-data-table__table" aria-label="Dessert calories">
|
||||
<thead>
|
||||
<tr class="mdc-data-table__header-row">
|
||||
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">
|
||||
Dessert
|
||||
</th>
|
||||
<th
|
||||
class="mdc-data-table__header-cell mdc-data-table__header-cell--numeric"
|
||||
role="columnheader"
|
||||
scope="col"
|
||||
>
|
||||
Carbs (g)
|
||||
</th>
|
||||
<th
|
||||
class="mdc-data-table__header-cell mdc-data-table__header-cell--numeric"
|
||||
role="columnheader"
|
||||
scope="col"
|
||||
>
|
||||
Protein (g)
|
||||
</th>
|
||||
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">
|
||||
Comments
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="mdc-data-table__content">
|
||||
<tr class="mdc-data-table__row">
|
||||
<td class="mdc-data-table__cell">Frozen yogurt</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">24</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">4.0</td>
|
||||
<td class="mdc-data-table__cell">Super tasty</td>
|
||||
</tr>
|
||||
<tr class="mdc-data-table__row">
|
||||
<td class="mdc-data-table__cell">Ice cream sandwich</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">37</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">
|
||||
4.33333333333
|
||||
</td>
|
||||
<td class="mdc-data-table__cell">I like ice cream more</td>
|
||||
</tr>
|
||||
<tr class="mdc-data-table__row">
|
||||
<td class="mdc-data-table__cell">Eclair</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">24</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">6.0</td>
|
||||
<td class="mdc-data-table__cell">New filing flavor</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Variants
|
||||
|
||||
### Data table with row selection
|
||||
|
||||
```html
|
||||
<div class="mdc-data-table">
|
||||
<table class="mdc-data-table__table" aria-label="Dessert calories">
|
||||
<thead>
|
||||
<tr class="mdc-data-table__header-row">
|
||||
<th
|
||||
class="mdc-data-table__header-cell mdc-data-table__header-cell--checkbox"
|
||||
role="columnheader"
|
||||
scope="col"
|
||||
>
|
||||
<div
|
||||
class="mdc-checkbox mdc-data-table__header-row-checkbox mdc-checkbox--selected"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mdc-checkbox__native-control"
|
||||
aria-label="Checkbox for header row selection"
|
||||
/>
|
||||
<div class="mdc-checkbox__background">
|
||||
<svg class="mdc-checkbox__checkmark" viewbox="0 0 24 24">
|
||||
<path
|
||||
class="mdc-checkbox__checkmark-path"
|
||||
fill="none"
|
||||
d="M1.73,12.91 8.1,19.28 22.79,4.59"
|
||||
/>
|
||||
</svg>
|
||||
<div class="mdc-checkbox__mixedmark"></div>
|
||||
</div>
|
||||
</div>
|
||||
</th>
|
||||
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">
|
||||
Status
|
||||
</th>
|
||||
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">
|
||||
Signal name
|
||||
</th>
|
||||
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">
|
||||
Severity
|
||||
</th>
|
||||
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">
|
||||
Stage
|
||||
</th>
|
||||
<th
|
||||
class="mdc-data-table__header-cell mdc-data-table__header-cell--numeric"
|
||||
role="columnheader"
|
||||
scope="col"
|
||||
>
|
||||
Time
|
||||
</th>
|
||||
<th class="mdc-data-table__header-cell" role="columnheader" scope="col">
|
||||
Roles
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="mdc-data-table__content">
|
||||
<tr data-row-id="u0" class="mdc-data-table__row">
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--checkbox">
|
||||
<div class="mdc-checkbox mdc-data-table__row-checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mdc-checkbox__native-control"
|
||||
aria-labelledby="u0"
|
||||
/>
|
||||
<div class="mdc-checkbox__background">
|
||||
<svg class="mdc-checkbox__checkmark" viewbox="0 0 24 24">
|
||||
<path
|
||||
class="mdc-checkbox__checkmark-path"
|
||||
fill="none"
|
||||
d="M1.73,12.91 8.1,19.28 22.79,4.59"
|
||||
/>
|
||||
</svg>
|
||||
<div class="mdc-checkbox__mixedmark"></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="mdc-data-table__cell">Online</td>
|
||||
<td class="mdc-data-table__cell" id="u0">Arcus watch slowdown</td>
|
||||
<td class="mdc-data-table__cell">Medium</td>
|
||||
<td class="mdc-data-table__cell">Triaged</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">0:33</td>
|
||||
<td class="mdc-data-table__cell">Allison Brie</td>
|
||||
</tr>
|
||||
<tr
|
||||
data-row-id="u1"
|
||||
class="mdc-data-table__row mdc-data-table__row--selected"
|
||||
aria-selected="true"
|
||||
>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--checkbox">
|
||||
<div
|
||||
class="mdc-checkbox mdc-data-table__row-checkbox mdc-checkbox--selected"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mdc-checkbox__native-control"
|
||||
checked
|
||||
aria-labelledby="u1"
|
||||
/>
|
||||
<div class="mdc-checkbox__background">
|
||||
<svg class="mdc-checkbox__checkmark" viewbox="0 0 24 24">
|
||||
<path
|
||||
class="mdc-checkbox__checkmark-path"
|
||||
fill="none"
|
||||
d="M1.73,12.91 8.1,19.28 22.79,4.59"
|
||||
/>
|
||||
</svg>
|
||||
<div class="mdc-checkbox__mixedmark"></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="mdc-data-table__cell">Offline</td>
|
||||
<td class="mdc-data-table__cell" id="u1">
|
||||
monarch: prod shared ares-managed-features-provider-heavy
|
||||
</td>
|
||||
<td class="mdc-data-table__cell">Huge</td>
|
||||
<td class="mdc-data-table__cell">Triaged</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">0:33</td>
|
||||
<td class="mdc-data-table__cell">Brie Larson</td>
|
||||
</tr>
|
||||
<tr
|
||||
data-row-id="u2"
|
||||
class="mdc-data-table__row mdc-data-table__row--selected"
|
||||
aria-selected="true"
|
||||
>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--checkbox">
|
||||
<div
|
||||
class="mdc-checkbox mdc-data-table__row-checkbox mdc-checkbox--selected"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mdc-checkbox__native-control"
|
||||
checked
|
||||
aria-labelledby="u2"
|
||||
/>
|
||||
<div class="mdc-checkbox__background">
|
||||
<svg class="mdc-checkbox__checkmark" viewbox="0 0 24 24">
|
||||
<path
|
||||
class="mdc-checkbox__checkmark-path"
|
||||
fill="none"
|
||||
d="M1.73,12.91 8.1,19.28 22.79,4.59"
|
||||
/>
|
||||
</svg>
|
||||
<div class="mdc-checkbox__mixedmark"></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="mdc-data-table__cell">Online</td>
|
||||
<td class="mdc-data-table__cell" id="u2">
|
||||
monarch: prod shared ares-managed-features-provider-heavy
|
||||
</td>
|
||||
<td class="mdc-data-table__cell">Minor</td>
|
||||
<td class="mdc-data-table__cell">Not triaged</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">0:33</td>
|
||||
<td class="mdc-data-table__cell">Jeremy Lake</td>
|
||||
</tr>
|
||||
<tr data-row-id="u3" class="mdc-data-table__row">
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--checkbox">
|
||||
<div class="mdc-checkbox mdc-data-table__row-checkbox">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="mdc-checkbox__native-control"
|
||||
aria-labelledby="u3"
|
||||
/>
|
||||
<div class="mdc-checkbox__background">
|
||||
<svg class="mdc-checkbox__checkmark" viewbox="0 0 24 24">
|
||||
<path
|
||||
class="mdc-checkbox__checkmark-path"
|
||||
fill="none"
|
||||
d="M1.73,12.91 8.1,19.28 22.79,4.59"
|
||||
/>
|
||||
</svg>
|
||||
<div class="mdc-checkbox__mixedmark"></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="mdc-data-table__cell">Online</td>
|
||||
<td class="mdc-data-table__cell" id="u3">Arcus watch slowdown</td>
|
||||
<td class="mdc-data-table__cell">Negligible</td>
|
||||
<td class="mdc-data-table__cell">Triaged</td>
|
||||
<td class="mdc-data-table__cell mdc-data-table__cell--numeric">0:33</td>
|
||||
<td class="mdc-data-table__cell">Angelina Cheng</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Style Customization
|
||||
|
||||
### CSS Classes
|
||||
|
||||
| CSS Class | Description |
|
||||
| --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `mdc-data-table` | Mandatory. The root DOM element containing `table` and other supporting elements. |
|
||||
| `mdc-data-table__table` | Mandatory. Table element. Added to `table` HTML tag. |
|
||||
| `mdc-data-table__header-row` | Mandatory. Table header row element. Added to `thead > tr` HTML tag. |
|
||||
| `mdc-data-table__header-cell` | Mandatory. Table header cell element. Added to `thead > th > td` HTML tag. |
|
||||
| `mdc-data-table__header-cell--checkbox` | Optional. Table header cell element that contains `mdc-checkbox`. Added to `thead> th > td:first-child` HTML tag. |
|
||||
| `mdc-data-table__header-cell--numeric` | Optional. Table header cell element that maps to numeric cells. Added to `thead > th > td` HTML tag. |
|
||||
| `mdc-data-table__content` | Mandatory. Table body element. Added to `tbody` HTML tag. |
|
||||
| `mdc-data-table__row` | Mandatory. Table row element. Added to `tbody > tr` HTML tag. |
|
||||
| `mdc-data-table__cell` | Mandatory. Table cell element. Added to `tbody > tr > td` HTML tag. |
|
||||
| `mdc-data-table__cell--numeric` | Optional. Table cell element that contains numeric data. Added to `tbody > tr > td` HTML tag. |
|
||||
| `mdc-data-table__cell--checkbox` | Optional. Table cell element that contains `mdc-checkbox`. Added to `thead> th > td:first-child` HTML tag. |
|
||||
| `mdc-data-table__header-row-checkbox` | Optional. Checkbox element rendered inside table header row element. Add this class name to `mdc-checkbox` element to override styles required for data-table. |
|
||||
| `mdc-data-table__row-checkbox` | Optional. Checkbox element rendered inside table row element. Add this class name to `mdc-checkbox` element to override styles required for data-table. |
|
||||
| `mdc-data-table__row--selected` | Optional. Modifier class added to `mdc-data-table__row` when table row is selected. |
|
||||
|
||||
### Sass Mixins
|
||||
|
||||
| Mixin | Description |
|
||||
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
|
||||
| `mdc-data-table-fill-color($color)` | Sets the background color of data-table surface. |
|
||||
| `mdc-data-table-row-fill-color($color)` | Sets the background color of table row container. |
|
||||
| `mdc-data-table-header-row-fill-color($color)` | Sets the background color of table header row container. |
|
||||
| `mdc-data-table-selected-row-fill-color($color)` | Sets the background color of selected row container. |
|
||||
| `mdc-data-table-checked-icon-color($color)` | Sets the checked icon color. |
|
||||
| `mdc-data-table-divider-color($color)` | Sets the table rows divider color. |
|
||||
| `mdc-data-table-divider-size($size)` | Sets the table rows divider size. |
|
||||
| `mdc-data-table-row-hover-fill-color($color)` | Sets the background color of table row on hover. |
|
||||
| `mdc-data-table-header-row-text-color($color)` | Sets the header row text color. |
|
||||
| `mdc-data-table-row-text-color($color)` | Sets the row text color. |
|
||||
| `mdc-data-table-shape-radius($radius)` | Sets the rounded shape with given radius size. `$radius` can be single radius or list radius values up to 4 list size. |
|
||||
| `mdc-data-table-stroke-size($size)` | Sets the border size of data-table. |
|
||||
| `mdc-data-table-stroke-color($color)` | Sets the border color of data-table. |
|
||||
| `mdc-data-table-header-row-height($height)` | Sets the header row height. |
|
||||
| `mdc-data-table-row-height($height)` | Sets row height. |
|
||||
| `mdc-data-table-cell-padding($leading-padding, $trailing-padding)` | Sets leading & trailing padding for all cells. |
|
||||
| `mdc-data-table-column-widths($width-list)` | Sets the custom widths for each table column. |
|
||||
|
||||
## Accessibility
|
||||
|
||||
Please refer [WAI-ARIA Authoring Practices for table](https://www.w3.org/TR/wai-aria-practices-1.1/#table) for ARIA recommended role, states & properties required for table element.
|
||||
|
||||
## Events
|
||||
|
||||
Please use MDCDataTable's constants file to access these event constants.
|
||||
|
||||
```ts
|
||||
const {events} from '@material/data-table/constants';
|
||||
// `events.ROW_SELECTION_CHANGED` to access event constant.
|
||||
```
|
||||
|
||||
| Event constant | Event name | Description |
|
||||
| ----------------------- | ---------------------------- | -------------------------------------------------------- |
|
||||
| `ROW_SELECTION_CHANGED` | `MDCDataTable:changed` | Event emitted when row checkbox is checked or unchecked. |
|
||||
| `SELECTED_ALL` | `MDCDataTable:selectedAll` | Event emitted when header row checkbox is checked. |
|
||||
| `UNSELECTED_ALL` | `MDCDataTable:unselectedAll` | Event emitted when header row checkbox is unchecked. |
|
||||
|
||||
## `MDCDataTable` Properties and Methods
|
||||
|
||||
| Method Signature | Description |
|
||||
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `layout() => void` | Registers new row checkboxes, header row checkbox and updates the state of header row checkbox. Use this when rows are added / removed from data table. |
|
||||
| `getRows() => HTMLElement[]` | Returns array of row elements. |
|
||||
| `getSelectedRowIds() => Array<string \| null>` | Returns array of selected row ids. |
|
||||
| `setSelectedRowIds(rowIds: string[])` | Sets selected row ids. Overwrites previously selected rows. |
|
||||
|
||||
## Usage within Web Frameworks
|
||||
|
||||
If you are using a JavaScript framework, such as React or Angular, you can create a Data Table for your framework. Depending on your needs, you can use the _Simple Approach: Wrapping MDC Web Vanilla Components_, or the _Advanced Approach: Using Foundations and Adapters_. Please follow the instructions [here](../../docs/integrating-into-frameworks.md).
|
||||
|
||||
### `MDCDataTableAdapter`
|
||||
|
||||
| Method Signature | Description |
|
||||
| ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `addClassAtRowIndex(rowIndex: number, cssClasses: string) => void` | Adds a class name to row element at given row index excluding header row. |
|
||||
| `getRowCount() => number` | Returns row count excluding header row. |
|
||||
| `getRowElements() => HTMLElement[]` | Returns array of row elements excluding header row. |
|
||||
| `getRowIdAtIndex(rowIndex: number) => string \| null` | Returns row id of row element at given row index based on `data-row-id` attribute on row element `tr`. |
|
||||
| `getRowIndexByChildElement(el: Element) => number` | Returns index of row element that contains give child element. |
|
||||
| `getSelectedRowCount() => number` | Returns selected row count. |
|
||||
| `isCheckboxAtRowIndexChecked(rowIndex: number) => boolean;` | Returns True if row checkbox at given row index is checked. |
|
||||
| `isHeaderRowCheckboxChecked() => boolean` | Returns true if header row checkbox is checked. |
|
||||
| `isRowsSelectable() => boolean` | Returns true if table rows are selectable. |
|
||||
| `notifyRowSelectionChanged(data: MDCDataTableRowSelectionChangedEventDetail) => void` | Notifies when row selection is changed. |
|
||||
| `notifySelectedAll() => void` | Notifies when header row is checked. |
|
||||
| `notifyUnselectedAll() => void` | Notifies when header row is unchecked. |
|
||||
| `registerHeaderRowCheckbox() => Promise<void> \| void` | Initializes header row checkbox. Destroys previous header row checkbox instance if any. Can return Promise only if registering checkbox is asynchronous. |
|
||||
| `registerRowCheckboxes() => Promise<void> \| void` | Initializes all row checkboxes. Destroys all previous row checkbox instances if any. This is usually called when row checkboxes are added or removed from table. Can return Promise only if registering checkbox is asynchronous. |
|
||||
| `removeClassAtRowIndex(rowIndex: number, cssClasses: string) => void` | Removes class name from row element at give row index. |
|
||||
| `setAttributeAtRowIndex(rowIndex: number, attr: string, value: string) => void` | Sets attribute to row element at given row index. |
|
||||
| `setHeaderRowCheckboxChecked(checked: boolean) => void` | Sets header row checkbox checked or unchecked. |
|
||||
| `setHeaderRowCheckboxIndeterminate(indeterminate: boolean) => void` | Sets header row checkbox to indeterminate. |
|
||||
| `setRowCheckboxCheckedAtIndex(rowIndex: number, checked: boolean) => void` | Sets row checkbox to checked or unchecked at given row index. |
|
||||
|
||||
### `MDCDataTableFoundation`
|
||||
|
||||
| Method Signature | Description |
|
||||
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `layout() => void` | Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table. Use this if registering checkbox is synchronous. |
|
||||
| `layoutAsync() => Promise<void> \| void` | Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table. Use this only if `registerRowCheckboxes` and `registerHeaderRowCheckboxe` are asynchronous. |
|
||||
| `getRows() => HTMLElement[]` | Returns array of row elements. |
|
||||
| `setSelectedRowIds(rowIds: string[]) => void` | Sets selected row ids. Overwrites previously selected rows. |
|
||||
| `getSelectedRowIds() => Array<string \| null>` | Returns array of selected row ids. |
|
||||
| `handleHeaderRowCheckboxChange() => void` | Handles header row checkbox change event. |
|
||||
| `handleRowCheckboxChange(event: Event) => void` | Handles change event originated from row checkboxes. |
|
306
mdc-data-table/_mixins.scss
Normal file
306
mdc-data-table/_mixins.scss
Normal file
@ -0,0 +1,306 @@
|
||||
//
|
||||
// Copyright 2019 Google Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
@import "@material/animation/functions";
|
||||
@import "@material/elevation/mixins";
|
||||
@import "@material/feature-targeting/functions";
|
||||
@import "@material/feature-targeting/mixins";
|
||||
@import "@material/checkbox/mixins";
|
||||
@import "@material/rtl/mixins";
|
||||
@import "@material/shape/mixins";
|
||||
@import "@material/theme/mixins";
|
||||
@import "@material/theme/variables"; // for mdc-theme-prop-value.
|
||||
@import "@material/typography/mixins";
|
||||
@import "./variables";
|
||||
|
||||
@mixin mdc-data-table-core-styles($query: mdc-feature-all()) {
|
||||
$feat-structure: mdc-feature-create-target($query, structure);
|
||||
$feat-typography: mdc-feature-create-target($query, typography);
|
||||
|
||||
// postcss-bem-linter: define data-table
|
||||
|
||||
.mdc-data-table__content {
|
||||
@include mdc-typography(body2, $query: $query);
|
||||
}
|
||||
|
||||
.mdc-data-table {
|
||||
@include mdc-data-table-fill-color($mdc-data-table-fill-color, $query: $query);
|
||||
@include mdc-data-table-shape-radius($mdc-data-table-shape-radius, $query: $query);
|
||||
@include mdc-data-table-stroke-size($mdc-data-table-stroke-size, $query: $query);
|
||||
@include mdc-data-table-stroke-color($mdc-data-table-stroke-color, $query: $query);
|
||||
|
||||
@at-root {
|
||||
@include mdc-data-table-row-fill-color($mdc-data-table-row-fill-color, $query: $query);
|
||||
@include mdc-data-table-header-row-fill-color($mdc-data-table-header-row-fill-color, $query: $query);
|
||||
@include mdc-data-table-selected-row-fill-color($mdc-data-table-selected-row-fill-color, $query: $query);
|
||||
@include mdc-data-table-divider-color($mdc-data-table-divider-color, $query: $query);
|
||||
@include mdc-data-table-divider-size($mdc-data-table-divider-size, $query: $query);
|
||||
@include mdc-data-table-row-hover-fill-color($mdc-data-table-row-hover-fill-color, $query: $query);
|
||||
@include mdc-data-table-header-row-text-color($mdc-data-table-header-row-text-color, $query: $query);
|
||||
@include mdc-data-table-row-text-color($mdc-data-table-row-text-color, $query: $query);
|
||||
@include mdc-data-table-header-row-height($mdc-data-table-header-row-height, $query: $query);
|
||||
@include mdc-data-table-row-height($mdc-data-table-row-height, $query: $query);
|
||||
@include mdc-data-table-cell-padding(
|
||||
$leading-padding: $mdc-data-table-cell-leading-padding,
|
||||
$trailing-padding: $mdc-data-table-cell-trailing-padding,
|
||||
$query: $query
|
||||
);
|
||||
}
|
||||
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
overflow-x: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.mdc-data-table__table {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
width: 100%;
|
||||
border: 0;
|
||||
white-space: nowrap;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
}
|
||||
|
||||
.mdc-data-table__cell {
|
||||
@include mdc-typography(body2, $query: $query);
|
||||
}
|
||||
|
||||
.mdc-data-table__cell--numeric {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
@include mdc-rtl {
|
||||
/* @noflip */
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mdc-data-table__header-cell {
|
||||
@include mdc-typography(subtitle2, $query: $query);
|
||||
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
@include mdc-rtl {
|
||||
/* @noflip */
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mdc-data-table__header-cell--numeric {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
@include mdc-rtl {
|
||||
/* @noflip */
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-fill-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
@include mdc-theme-prop("background-color", $color);
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-header-row-fill-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
.mdc-data-table__header-row {
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
@include mdc-theme-prop("background-color", $color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-row-fill-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
.mdc-data-table__row {
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
@include mdc-theme-prop("background-color", $color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-selected-row-fill-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
.mdc-data-table__row--selected {
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
@include mdc-theme-prop("background-color", $color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-checked-icon-color($color, $query: mdc-feature-all()) {
|
||||
.mdc-data-table__header-row-checkbox,
|
||||
.mdc-data-table__row-checkbox {
|
||||
@include mdc-checkbox-focus-indicator-color($color, $query: $query);
|
||||
@include mdc-checkbox-container-colors($marked-stroke-color: $color, $marked-fill-color: $color, $query: $query);
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-divider-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
.mdc-data-table__row {
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
border-top-color: $color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-divider-size($size, $query: mdc-feature-all()) {
|
||||
$feat-structure: mdc-feature-create-target($query, structure);
|
||||
|
||||
.mdc-data-table__row {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
border-top-width: $size;
|
||||
border-top-style: solid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-row-hover-fill-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
.mdc-data-table__row:not(.mdc-data-table__row--selected):hover {
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
@include mdc-theme-prop("background-color", $color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-header-row-text-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
.mdc-data-table__header-cell {
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
@include mdc-theme-prop("color", $color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-row-text-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
.mdc-data-table__cell {
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
@include mdc-theme-prop("color", $color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-shape-radius($radius, $rtl-reflexive: false, $query: mdc-feature-all()) {
|
||||
@include mdc-shape-radius($radius, $rtl-reflexive, $query: $query);
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-stroke-size($size, $query: mdc-feature-all()) {
|
||||
$feat-structure: mdc-feature-create-target($query, structure);
|
||||
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
border-width: $size;
|
||||
border-style: solid;
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-stroke-color($color, $query: mdc-feature-all()) {
|
||||
$feat-color: mdc-feature-create-target($query, color);
|
||||
|
||||
@include mdc-feature-targets($feat-color) {
|
||||
border-color: $color;
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-header-row-height($height, $query: mdc-feature-all()) {
|
||||
$feat-structure: mdc-feature-create-target($query, structure);
|
||||
|
||||
.mdc-data-table__header-row {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
height: $height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-row-height($height, $query: mdc-feature-all()) {
|
||||
$feat-structure: mdc-feature-create-target($query, structure);
|
||||
|
||||
.mdc-data-table__row {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
height: $height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-cell-padding(
|
||||
$leading-padding: $mdc-data-table-cell-leading-padding,
|
||||
$trailing-padding: $mdc-data-table-cell-trailing-padding,
|
||||
$query: mdc-feature-all()) {
|
||||
$feat-structure: mdc-feature-create-target($query, structure);
|
||||
|
||||
.mdc-data-table__cell,
|
||||
.mdc-data-table__header-cell {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
padding-right: $trailing-padding;
|
||||
padding-left: $leading-padding;
|
||||
}
|
||||
}
|
||||
|
||||
.mdc-data-table__header-cell--checkbox,
|
||||
.mdc-data-table__cell--checkbox {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
@include mdc-rtl-reflexive-property(padding, $leading-padding, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-column-widths($width-list, $query: mdc-feature-all()) {
|
||||
$feat-structure: mdc-feature-create-target($query, structure);
|
||||
|
||||
@for $i from 1 through length($width-list) {
|
||||
.mdc-data-table__row > :nth-child(#{$i}) {
|
||||
@include mdc-feature-targets($feat-structure) {
|
||||
width: nth($width-list, $i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@mixin mdc-data-table-theme-baseline($query: mdc-feature-all()) {
|
||||
@include mdc-data-table-checked-icon-color($mdc-data-table-checked-icon-color, $query: $query);
|
||||
}
|
46
mdc-data-table/_variables.scss
Normal file
46
mdc-data-table/_variables.scss
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright 2019 Google Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
@import "@material/theme/functions";
|
||||
|
||||
$mdc-data-table-fill-color: surface !default;
|
||||
$mdc-data-table-header-row-fill-color: inherit !default;
|
||||
$mdc-data-table-row-fill-color: inherit !default;
|
||||
$mdc-data-table-selected-row-fill-color: rgba(mdc-theme-prop-value(primary), .04) !default;
|
||||
|
||||
$mdc-data-table-checked-icon-color: primary !default;
|
||||
$mdc-data-table-divider-color: rgba(mdc-theme-prop-value(on-surface), .12) !default;
|
||||
$mdc-data-table-divider-size: 1px !default;
|
||||
$mdc-data-table-row-hover-fill-color: rgba(mdc-theme-prop-value(on-surface), .04) !default;
|
||||
$mdc-data-table-checkbox-touch-dimension: 48px !default;
|
||||
|
||||
$mdc-data-table-header-row-text-color: rgba(mdc-theme-prop-value(on-surface), .87) !default;
|
||||
$mdc-data-table-row-text-color: rgba(mdc-theme-prop-value(on-surface), .87) !default;
|
||||
|
||||
$mdc-data-table-shape-radius: medium !default;
|
||||
$mdc-data-table-stroke-size: 1px !default;
|
||||
$mdc-data-table-stroke-color: rgba(mdc-theme-prop-value(on-surface), .12) !default;
|
||||
|
||||
$mdc-data-table-row-height: 52px !default;
|
||||
$mdc-data-table-header-row-height: $mdc-data-table-row-height + 4px !default;
|
||||
$mdc-data-table-cell-leading-padding: 16px !default;
|
||||
$mdc-data-table-cell-trailing-padding: 16px !default;
|
140
mdc-data-table/adapter.d.ts
vendored
Normal file
140
mdc-data-table/adapter.d.ts
vendored
Normal file
@ -0,0 +1,140 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
/**
|
||||
* Defines the shape of the adapter expected by the foundation.
|
||||
* Implement this adapter for your framework of choice to delegate updates to
|
||||
* the component in your framework of choice. See architecture documentation
|
||||
* for more details.
|
||||
* https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
|
||||
*/
|
||||
import { MDCDataTableRowSelectionChangedEventDetail } from "./types";
|
||||
export interface MDCDataTableAdapter {
|
||||
/**
|
||||
* Adds a class name to row element at given row index excluding header row.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row.
|
||||
* @param cssClasses CSS Class string to add.
|
||||
*/
|
||||
addClassAtRowIndex(rowIndex: number, cssClasses: string): void;
|
||||
/**
|
||||
* @return Row count excluding header row.
|
||||
*/
|
||||
getRowCount(): number;
|
||||
/**
|
||||
* @return Array of row elements excluding header row.
|
||||
*/
|
||||
getRowElements(): Element[];
|
||||
/**
|
||||
* Returns row id of row element at given row index based on `data-row-id` attribute on row element `tr`.
|
||||
*
|
||||
* @param rowIndex Index of row element.
|
||||
* @return Row id of row element, returns `null` in absence of `data-row-id` attribute on row element.
|
||||
*/
|
||||
getRowIdAtIndex(rowIndex: number): string | null;
|
||||
/**
|
||||
* Returns index of row element that contains give child element. Returns -1 if element is not child of any row
|
||||
* element.
|
||||
*
|
||||
* @param el Child element of row element.
|
||||
* @return Index of row element.
|
||||
*/
|
||||
getRowIndexByChildElement(el: Element): number;
|
||||
/**
|
||||
* @return Selected row count.
|
||||
*/
|
||||
getSelectedRowCount(): number;
|
||||
/**
|
||||
* @param rowIndex Index of row element.
|
||||
* @return True if row checkbox at given row index is checked.
|
||||
*/
|
||||
isCheckboxAtRowIndexChecked(rowIndex: number): boolean;
|
||||
/**
|
||||
* @return True if header row checkbox is checked.
|
||||
*/
|
||||
isHeaderRowCheckboxChecked(): boolean;
|
||||
/**
|
||||
* @return True if table rows are selectable.
|
||||
*/
|
||||
isRowsSelectable(): boolean;
|
||||
/**
|
||||
* Notifies when row selection is changed.
|
||||
*
|
||||
* @param data Event detail data for row selection changed event.
|
||||
*/
|
||||
notifyRowSelectionChanged(
|
||||
data: MDCDataTableRowSelectionChangedEventDetail
|
||||
): void;
|
||||
/**
|
||||
* Notifies when header row is checked.
|
||||
*/
|
||||
notifySelectedAll(): void;
|
||||
/**
|
||||
* Notifies when header row is unchecked.
|
||||
*/
|
||||
notifyUnselectedAll(): void;
|
||||
/**
|
||||
* Initializes header row checkbox. Destroys previous header row checkbox instance if any.
|
||||
* @return Can return Promise only if registering checkbox is asynchronous.
|
||||
*/
|
||||
registerHeaderRowCheckbox(): Promise<void> | void;
|
||||
/**
|
||||
* Initializes all row checkboxes. Destroys previous row checkbox instances if any. This is usually called when row
|
||||
* checkboxes are added or removed from table.
|
||||
* @return Can return Promise only if registering checkbox is asynchronous.
|
||||
*/
|
||||
registerRowCheckboxes(): Promise<void> | void;
|
||||
/**
|
||||
* Removes class name from row element at give row index.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row element.
|
||||
* @param cssClasses Class name string.
|
||||
*/
|
||||
removeClassAtRowIndex(rowIndex: number, cssClasses: string): void;
|
||||
/**
|
||||
* Sets attribute to row element at given row index.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row element.
|
||||
* @param attr Name of attribute.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
setAttributeAtRowIndex(rowIndex: number, attr: string, value: string): void;
|
||||
/**
|
||||
* Sets header row checkbox checked or unchecked.
|
||||
*
|
||||
* @param checked True to set header row checkbox checked.
|
||||
*/
|
||||
setHeaderRowCheckboxChecked(checked: boolean): void;
|
||||
/**
|
||||
* Sets header row checkbox to indeterminate.
|
||||
*
|
||||
* @param indeterminate True to set header row checkbox indeterminate.
|
||||
*/
|
||||
setHeaderRowCheckboxIndeterminate(indeterminate: boolean): void;
|
||||
/**
|
||||
* Sets row checkbox to checked or unchecked at given row index.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row element.
|
||||
* @param checked True to set checked.
|
||||
*/
|
||||
setRowCheckboxCheckedAtIndex(rowIndex: number, checked: boolean): void;
|
||||
}
|
23
mdc-data-table/adapter.js
Normal file
23
mdc-data-table/adapter.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
//# sourceMappingURL=adapter.js.map
|
1
mdc-data-table/adapter.js.map
Normal file
1
mdc-data-table/adapter.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
161
mdc-data-table/adapter.ts
Normal file
161
mdc-data-table/adapter.ts
Normal file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the shape of the adapter expected by the foundation.
|
||||
* Implement this adapter for your framework of choice to delegate updates to
|
||||
* the component in your framework of choice. See architecture documentation
|
||||
* for more details.
|
||||
* https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
|
||||
*/
|
||||
|
||||
import { MDCDataTableRowSelectionChangedEventDetail } from "./types";
|
||||
|
||||
export interface MDCDataTableAdapter {
|
||||
/**
|
||||
* Adds a class name to row element at given row index excluding header row.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row.
|
||||
* @param cssClasses CSS Class string to add.
|
||||
*/
|
||||
addClassAtRowIndex(rowIndex: number, cssClasses: string): void;
|
||||
|
||||
/**
|
||||
* @return Row count excluding header row.
|
||||
*/
|
||||
getRowCount(): number;
|
||||
|
||||
/**
|
||||
* @return Array of row elements excluding header row.
|
||||
*/
|
||||
getRowElements(): Element[];
|
||||
|
||||
/**
|
||||
* Returns row id of row element at given row index based on `data-row-id` attribute on row element `tr`.
|
||||
*
|
||||
* @param rowIndex Index of row element.
|
||||
* @return Row id of row element, returns `null` in absence of `data-row-id` attribute on row element.
|
||||
*/
|
||||
getRowIdAtIndex(rowIndex: number): string | null;
|
||||
|
||||
/**
|
||||
* Returns index of row element that contains give child element. Returns -1 if element is not child of any row
|
||||
* element.
|
||||
*
|
||||
* @param el Child element of row element.
|
||||
* @return Index of row element.
|
||||
*/
|
||||
getRowIndexByChildElement(el: Element): number;
|
||||
|
||||
/**
|
||||
* @return Selected row count.
|
||||
*/
|
||||
getSelectedRowCount(): number;
|
||||
|
||||
/**
|
||||
* @param rowIndex Index of row element.
|
||||
* @return True if row checkbox at given row index is checked.
|
||||
*/
|
||||
isCheckboxAtRowIndexChecked(rowIndex: number): boolean;
|
||||
|
||||
/**
|
||||
* @return True if header row checkbox is checked.
|
||||
*/
|
||||
isHeaderRowCheckboxChecked(): boolean;
|
||||
|
||||
/**
|
||||
* @return True if table rows are selectable.
|
||||
*/
|
||||
isRowsSelectable(): boolean;
|
||||
|
||||
/**
|
||||
* Notifies when row selection is changed.
|
||||
*
|
||||
* @param data Event detail data for row selection changed event.
|
||||
*/
|
||||
notifyRowSelectionChanged(
|
||||
data: MDCDataTableRowSelectionChangedEventDetail
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Notifies when header row is checked.
|
||||
*/
|
||||
notifySelectedAll(): void;
|
||||
|
||||
/**
|
||||
* Notifies when header row is unchecked.
|
||||
*/
|
||||
notifyUnselectedAll(): void;
|
||||
|
||||
/**
|
||||
* Initializes header row checkbox. Destroys previous header row checkbox instance if any.
|
||||
* @return Can return Promise only if registering checkbox is asynchronous.
|
||||
*/
|
||||
registerHeaderRowCheckbox(): Promise<void> | void;
|
||||
|
||||
/**
|
||||
* Initializes all row checkboxes. Destroys previous row checkbox instances if any. This is usually called when row
|
||||
* checkboxes are added or removed from table.
|
||||
* @return Can return Promise only if registering checkbox is asynchronous.
|
||||
*/
|
||||
registerRowCheckboxes(): Promise<void> | void;
|
||||
|
||||
/**
|
||||
* Removes class name from row element at give row index.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row element.
|
||||
* @param cssClasses Class name string.
|
||||
*/
|
||||
removeClassAtRowIndex(rowIndex: number, cssClasses: string): void;
|
||||
|
||||
/**
|
||||
* Sets attribute to row element at given row index.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row element.
|
||||
* @param attr Name of attribute.
|
||||
* @param value Value of attribute.
|
||||
*/
|
||||
setAttributeAtRowIndex(rowIndex: number, attr: string, value: string): void;
|
||||
|
||||
/**
|
||||
* Sets header row checkbox checked or unchecked.
|
||||
*
|
||||
* @param checked True to set header row checkbox checked.
|
||||
*/
|
||||
setHeaderRowCheckboxChecked(checked: boolean): void;
|
||||
|
||||
/**
|
||||
* Sets header row checkbox to indeterminate.
|
||||
*
|
||||
* @param indeterminate True to set header row checkbox indeterminate.
|
||||
*/
|
||||
setHeaderRowCheckboxIndeterminate(indeterminate: boolean): void;
|
||||
|
||||
/**
|
||||
* Sets row checkbox to checked or unchecked at given row index.
|
||||
*
|
||||
* @param rowIndex Index of row element excluding header row element.
|
||||
* @param checked True to set checked.
|
||||
*/
|
||||
setRowCheckboxCheckedAtIndex(rowIndex: number, checked: boolean): void;
|
||||
}
|
58
mdc-data-table/component.d.ts
vendored
Normal file
58
mdc-data-table/component.d.ts
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import { MDCComponent } from "@material/base/component";
|
||||
import { MDCCheckboxFactory } from "@material/checkbox/component";
|
||||
import { MDCDataTableFoundation } from "./foundation";
|
||||
export declare class MDCDataTable extends MDCComponent<MDCDataTableFoundation> {
|
||||
static attachTo(root: Element): MDCDataTable;
|
||||
private headerRowCheckbox_;
|
||||
private rowCheckboxList_;
|
||||
private checkboxFactory_;
|
||||
private headerRow_;
|
||||
private content_;
|
||||
private handleHeaderRowCheckboxChange_;
|
||||
private handleRowCheckboxChange_;
|
||||
initialize(checkboxFactory?: MDCCheckboxFactory): void;
|
||||
initialSyncWithDOM(): void;
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
*/
|
||||
layout(): void;
|
||||
/**
|
||||
* @return Returns array of row elements.
|
||||
*/
|
||||
getRows(): Element[];
|
||||
/**
|
||||
* @return Returns array of selected row ids.
|
||||
*/
|
||||
getSelectedRowIds(): Array<string | null>;
|
||||
/**
|
||||
* Sets selected row ids. Overwrites previously selected rows.
|
||||
* @param rowIds Array of row ids that needs to be selected.
|
||||
*/
|
||||
setSelectedRowIds(rowIds: string[]): void;
|
||||
destroy(): void;
|
||||
getDefaultFoundation(): MDCDataTableFoundation;
|
||||
private getRowByIndex_;
|
||||
private getRowIdByIndex_;
|
||||
}
|
202
mdc-data-table/component.js
Normal file
202
mdc-data-table/component.js
Normal file
@ -0,0 +1,202 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import * as tslib_1 from "tslib";
|
||||
import { MDCComponent } from "@material/base/component";
|
||||
import { MDCCheckbox } from "@material/checkbox/component";
|
||||
import { closest } from "@material/dom/ponyfill";
|
||||
import { cssClasses, events, strings } from "./constants";
|
||||
import { MDCDataTableFoundation } from "./foundation";
|
||||
var MDCDataTable = /** @class */ (function(_super) {
|
||||
tslib_1.__extends(MDCDataTable, _super);
|
||||
function MDCDataTable() {
|
||||
return (_super !== null && _super.apply(this, arguments)) || this;
|
||||
}
|
||||
MDCDataTable.attachTo = function(root) {
|
||||
return new MDCDataTable(root);
|
||||
};
|
||||
MDCDataTable.prototype.initialize = function(checkboxFactory) {
|
||||
if (checkboxFactory === void 0) {
|
||||
checkboxFactory = function(el) {
|
||||
return new MDCCheckbox(el);
|
||||
};
|
||||
}
|
||||
this.checkboxFactory_ = checkboxFactory;
|
||||
};
|
||||
MDCDataTable.prototype.initialSyncWithDOM = function() {
|
||||
var _this = this;
|
||||
this.headerRow_ = this.root_.querySelector("." + cssClasses.HEADER_ROW);
|
||||
this.handleHeaderRowCheckboxChange_ = function() {
|
||||
return _this.foundation_.handleHeaderRowCheckboxChange();
|
||||
};
|
||||
this.headerRow_.addEventListener(
|
||||
"change",
|
||||
this.handleHeaderRowCheckboxChange_
|
||||
);
|
||||
this.content_ = this.root_.querySelector("." + cssClasses.CONTENT);
|
||||
this.handleRowCheckboxChange_ = function(event) {
|
||||
return _this.foundation_.handleRowCheckboxChange(event);
|
||||
};
|
||||
this.content_.addEventListener("change", this.handleRowCheckboxChange_);
|
||||
this.layout();
|
||||
};
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
*/
|
||||
MDCDataTable.prototype.layout = function() {
|
||||
this.foundation_.layout();
|
||||
};
|
||||
/**
|
||||
* @return Returns array of row elements.
|
||||
*/
|
||||
MDCDataTable.prototype.getRows = function() {
|
||||
return this.foundation_.getRows();
|
||||
};
|
||||
/**
|
||||
* @return Returns array of selected row ids.
|
||||
*/
|
||||
MDCDataTable.prototype.getSelectedRowIds = function() {
|
||||
return this.foundation_.getSelectedRowIds();
|
||||
};
|
||||
/**
|
||||
* Sets selected row ids. Overwrites previously selected rows.
|
||||
* @param rowIds Array of row ids that needs to be selected.
|
||||
*/
|
||||
MDCDataTable.prototype.setSelectedRowIds = function(rowIds) {
|
||||
this.foundation_.setSelectedRowIds(rowIds);
|
||||
};
|
||||
MDCDataTable.prototype.destroy = function() {
|
||||
this.headerRow_.removeEventListener(
|
||||
"change",
|
||||
this.handleHeaderRowCheckboxChange_
|
||||
);
|
||||
this.content_.removeEventListener("change", this.handleRowCheckboxChange_);
|
||||
this.headerRowCheckbox_.destroy();
|
||||
this.rowCheckboxList_.forEach(function(checkbox) {
|
||||
return checkbox.destroy();
|
||||
});
|
||||
};
|
||||
MDCDataTable.prototype.getDefaultFoundation = function() {
|
||||
var _this = this;
|
||||
// DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
|
||||
// To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
|
||||
// tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
|
||||
var adapter = {
|
||||
addClassAtRowIndex: function(rowIndex, className) {
|
||||
return _this.getRows()[rowIndex].classList.add(className);
|
||||
},
|
||||
getRowCount: function() {
|
||||
return _this.getRows().length;
|
||||
},
|
||||
getRowElements: function() {
|
||||
return [].slice.call(
|
||||
_this.root_.querySelectorAll(strings.ROW_SELECTOR)
|
||||
);
|
||||
},
|
||||
getRowIdAtIndex: function(rowIndex) {
|
||||
return _this.getRows()[rowIndex].getAttribute(strings.DATA_ROW_ID_ATTR);
|
||||
},
|
||||
getRowIndexByChildElement: function(el) {
|
||||
return _this.getRows().indexOf(closest(el, strings.ROW_SELECTOR));
|
||||
},
|
||||
getSelectedRowCount: function() {
|
||||
return _this.root_.querySelectorAll(strings.ROW_SELECTED_SELECTOR)
|
||||
.length;
|
||||
},
|
||||
isCheckboxAtRowIndexChecked: function(rowIndex) {
|
||||
return _this.rowCheckboxList_[rowIndex].checked;
|
||||
},
|
||||
isHeaderRowCheckboxChecked: function() {
|
||||
return _this.headerRowCheckbox_.checked;
|
||||
},
|
||||
isRowsSelectable: function() {
|
||||
return !!_this.root_.querySelector(strings.ROW_CHECKBOX_SELECTOR);
|
||||
},
|
||||
notifyRowSelectionChanged: function(data) {
|
||||
_this.emit(
|
||||
events.ROW_SELECTION_CHANGED,
|
||||
{
|
||||
row: _this.getRowByIndex_(data.rowIndex),
|
||||
rowId: _this.getRowIdByIndex_(data.rowIndex),
|
||||
rowIndex: data.rowIndex,
|
||||
selected: data.selected,
|
||||
},
|
||||
/** shouldBubble */ true
|
||||
);
|
||||
},
|
||||
notifySelectedAll: function() {
|
||||
return _this.emit(events.SELECTED_ALL, {}, /** shouldBubble */ true);
|
||||
},
|
||||
notifyUnselectedAll: function() {
|
||||
return _this.emit(events.UNSELECTED_ALL, {}, /** shouldBubble */ true);
|
||||
},
|
||||
registerHeaderRowCheckbox: function() {
|
||||
if (_this.headerRowCheckbox_) {
|
||||
_this.headerRowCheckbox_.destroy();
|
||||
}
|
||||
var checkboxEl = _this.root_.querySelector(
|
||||
strings.HEADER_ROW_CHECKBOX_SELECTOR
|
||||
);
|
||||
_this.headerRowCheckbox_ = _this.checkboxFactory_(checkboxEl);
|
||||
},
|
||||
registerRowCheckboxes: function() {
|
||||
if (_this.rowCheckboxList_) {
|
||||
_this.rowCheckboxList_.forEach(function(checkbox) {
|
||||
return checkbox.destroy();
|
||||
});
|
||||
}
|
||||
_this.rowCheckboxList_ = [];
|
||||
_this.getRows().forEach(function(rowEl) {
|
||||
var checkbox = _this.checkboxFactory_(
|
||||
rowEl.querySelector(strings.ROW_CHECKBOX_SELECTOR)
|
||||
);
|
||||
_this.rowCheckboxList_.push(checkbox);
|
||||
});
|
||||
},
|
||||
removeClassAtRowIndex: function(rowIndex, className) {
|
||||
_this.getRows()[rowIndex].classList.remove(className);
|
||||
},
|
||||
setAttributeAtRowIndex: function(rowIndex, attr, value) {
|
||||
_this.getRows()[rowIndex].setAttribute(attr, value);
|
||||
},
|
||||
setHeaderRowCheckboxChecked: function(checked) {
|
||||
_this.headerRowCheckbox_.checked = checked;
|
||||
},
|
||||
setHeaderRowCheckboxIndeterminate: function(indeterminate) {
|
||||
_this.headerRowCheckbox_.indeterminate = indeterminate;
|
||||
},
|
||||
setRowCheckboxCheckedAtIndex: function(rowIndex, checked) {
|
||||
_this.rowCheckboxList_[rowIndex].checked = checked;
|
||||
},
|
||||
};
|
||||
return new MDCDataTableFoundation(adapter);
|
||||
};
|
||||
MDCDataTable.prototype.getRowByIndex_ = function(index) {
|
||||
return this.getRows()[index];
|
||||
};
|
||||
MDCDataTable.prototype.getRowIdByIndex_ = function(index) {
|
||||
return this.getRowByIndex_(index).getAttribute(strings.DATA_ROW_ID_ATTR);
|
||||
};
|
||||
return MDCDataTable;
|
||||
})(MDCComponent);
|
||||
export { MDCDataTable };
|
||||
//# sourceMappingURL=component.js.map
|
1
mdc-data-table/component.js.map
Normal file
1
mdc-data-table/component.js.map
Normal file
File diff suppressed because one or more lines are too long
209
mdc-data-table/component.ts
Normal file
209
mdc-data-table/component.ts
Normal file
@ -0,0 +1,209 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { MDCComponent } from "@material/base/component";
|
||||
import { SpecificEventListener } from "@material/base/types";
|
||||
import { MDCCheckbox, MDCCheckboxFactory } from "@material/checkbox/component";
|
||||
import { closest } from "@material/dom/ponyfill";
|
||||
import { MDCDataTableAdapter } from "./adapter";
|
||||
import { cssClasses, events, strings } from "./constants";
|
||||
import { MDCDataTableFoundation } from "./foundation";
|
||||
import { MDCDataTableRowSelectionChangedEventDetail } from "./types";
|
||||
|
||||
export class MDCDataTable extends MDCComponent<MDCDataTableFoundation> {
|
||||
static attachTo(root: Element): MDCDataTable {
|
||||
return new MDCDataTable(root);
|
||||
}
|
||||
|
||||
private headerRowCheckbox_!: MDCCheckbox;
|
||||
private rowCheckboxList_!: MDCCheckbox[];
|
||||
private checkboxFactory_!: MDCCheckboxFactory;
|
||||
private headerRow_!: HTMLElement;
|
||||
private content_!: HTMLElement;
|
||||
private handleHeaderRowCheckboxChange_!: SpecificEventListener<"change">;
|
||||
private handleRowCheckboxChange_!: SpecificEventListener<"change">;
|
||||
|
||||
initialize(
|
||||
checkboxFactory: MDCCheckboxFactory = (el: Element) => new MDCCheckbox(el)
|
||||
) {
|
||||
this.checkboxFactory_ = checkboxFactory;
|
||||
}
|
||||
|
||||
initialSyncWithDOM() {
|
||||
this.headerRow_ = this.root_.querySelector(
|
||||
`.${cssClasses.HEADER_ROW}`
|
||||
) as HTMLElement;
|
||||
this.handleHeaderRowCheckboxChange_ = () =>
|
||||
this.foundation_.handleHeaderRowCheckboxChange();
|
||||
this.headerRow_.addEventListener(
|
||||
"change",
|
||||
this.handleHeaderRowCheckboxChange_
|
||||
);
|
||||
|
||||
this.content_ = this.root_.querySelector(
|
||||
`.${cssClasses.CONTENT}`
|
||||
) as HTMLElement;
|
||||
this.handleRowCheckboxChange_ = (event) =>
|
||||
this.foundation_.handleRowCheckboxChange(event);
|
||||
this.content_.addEventListener("change", this.handleRowCheckboxChange_);
|
||||
|
||||
this.layout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
*/
|
||||
layout() {
|
||||
this.foundation_.layout();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns array of row elements.
|
||||
*/
|
||||
getRows(): Element[] {
|
||||
return this.foundation_.getRows();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns array of selected row ids.
|
||||
*/
|
||||
getSelectedRowIds(): Array<string | null> {
|
||||
return this.foundation_.getSelectedRowIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets selected row ids. Overwrites previously selected rows.
|
||||
* @param rowIds Array of row ids that needs to be selected.
|
||||
*/
|
||||
setSelectedRowIds(rowIds: string[]) {
|
||||
this.foundation_.setSelectedRowIds(rowIds);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.headerRow_.removeEventListener(
|
||||
"change",
|
||||
this.handleHeaderRowCheckboxChange_
|
||||
);
|
||||
this.content_.removeEventListener("change", this.handleRowCheckboxChange_);
|
||||
|
||||
this.headerRowCheckbox_.destroy();
|
||||
this.rowCheckboxList_.forEach((checkbox) => checkbox.destroy());
|
||||
}
|
||||
|
||||
getDefaultFoundation() {
|
||||
// DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
|
||||
// To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
|
||||
// tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
|
||||
const adapter: MDCDataTableAdapter = {
|
||||
addClassAtRowIndex: (rowIndex: number, className: string) =>
|
||||
this.getRows()[rowIndex].classList.add(className),
|
||||
getRowCount: () => this.getRows().length,
|
||||
getRowElements: () =>
|
||||
[].slice.call(this.root_.querySelectorAll(strings.ROW_SELECTOR)),
|
||||
getRowIdAtIndex: (rowIndex: number) =>
|
||||
this.getRows()[rowIndex].getAttribute(strings.DATA_ROW_ID_ATTR),
|
||||
getRowIndexByChildElement: (el: Element) => {
|
||||
return this.getRows().indexOf(closest(
|
||||
el,
|
||||
strings.ROW_SELECTOR
|
||||
) as HTMLElement);
|
||||
},
|
||||
getSelectedRowCount: () =>
|
||||
this.root_.querySelectorAll(strings.ROW_SELECTED_SELECTOR).length,
|
||||
isCheckboxAtRowIndexChecked: (rowIndex: number) =>
|
||||
this.rowCheckboxList_[rowIndex].checked,
|
||||
isHeaderRowCheckboxChecked: () => this.headerRowCheckbox_.checked,
|
||||
isRowsSelectable: () =>
|
||||
!!this.root_.querySelector(strings.ROW_CHECKBOX_SELECTOR),
|
||||
notifyRowSelectionChanged: (
|
||||
data: MDCDataTableRowSelectionChangedEventDetail
|
||||
) => {
|
||||
this.emit(
|
||||
events.ROW_SELECTION_CHANGED,
|
||||
{
|
||||
row: this.getRowByIndex_(data.rowIndex),
|
||||
rowId: this.getRowIdByIndex_(data.rowIndex),
|
||||
rowIndex: data.rowIndex,
|
||||
selected: data.selected,
|
||||
},
|
||||
/** shouldBubble */ true
|
||||
);
|
||||
},
|
||||
notifySelectedAll: () =>
|
||||
this.emit(events.SELECTED_ALL, {}, /** shouldBubble */ true),
|
||||
notifyUnselectedAll: () =>
|
||||
this.emit(events.UNSELECTED_ALL, {}, /** shouldBubble */ true),
|
||||
registerHeaderRowCheckbox: () => {
|
||||
if (this.headerRowCheckbox_) {
|
||||
this.headerRowCheckbox_.destroy();
|
||||
}
|
||||
|
||||
const checkboxEl = this.root_.querySelector(
|
||||
strings.HEADER_ROW_CHECKBOX_SELECTOR
|
||||
) as HTMLElement;
|
||||
this.headerRowCheckbox_ = this.checkboxFactory_(checkboxEl);
|
||||
},
|
||||
registerRowCheckboxes: () => {
|
||||
if (this.rowCheckboxList_) {
|
||||
this.rowCheckboxList_.forEach((checkbox) => checkbox.destroy());
|
||||
}
|
||||
|
||||
this.rowCheckboxList_ = [];
|
||||
this.getRows().forEach((rowEl) => {
|
||||
const checkbox = this.checkboxFactory_(rowEl.querySelector(
|
||||
strings.ROW_CHECKBOX_SELECTOR
|
||||
) as HTMLElement);
|
||||
this.rowCheckboxList_.push(checkbox);
|
||||
});
|
||||
},
|
||||
removeClassAtRowIndex: (rowIndex: number, className: string) => {
|
||||
this.getRows()[rowIndex].classList.remove(className);
|
||||
},
|
||||
setAttributeAtRowIndex: (
|
||||
rowIndex: number,
|
||||
attr: string,
|
||||
value: string
|
||||
) => {
|
||||
this.getRows()[rowIndex].setAttribute(attr, value);
|
||||
},
|
||||
setHeaderRowCheckboxChecked: (checked: boolean) => {
|
||||
this.headerRowCheckbox_.checked = checked;
|
||||
},
|
||||
setHeaderRowCheckboxIndeterminate: (indeterminate: boolean) => {
|
||||
this.headerRowCheckbox_.indeterminate = indeterminate;
|
||||
},
|
||||
setRowCheckboxCheckedAtIndex: (rowIndex: number, checked: boolean) => {
|
||||
this.rowCheckboxList_[rowIndex].checked = checked;
|
||||
},
|
||||
};
|
||||
return new MDCDataTableFoundation(adapter);
|
||||
}
|
||||
|
||||
private getRowByIndex_(index: number): Element {
|
||||
return this.getRows()[index];
|
||||
}
|
||||
|
||||
private getRowIdByIndex_(index: number): string | null {
|
||||
return this.getRowByIndex_(index).getAttribute(strings.DATA_ROW_ID_ATTR);
|
||||
}
|
||||
}
|
46
mdc-data-table/constants.d.ts
vendored
Normal file
46
mdc-data-table/constants.d.ts
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
export declare const cssClasses: {
|
||||
CELL: string;
|
||||
CELL_NUMERIC: string;
|
||||
CONTENT: string;
|
||||
HEADER_ROW: string;
|
||||
HEADER_ROW_CHECKBOX: string;
|
||||
ROOT: string;
|
||||
ROW: string;
|
||||
ROW_CHECKBOX: string;
|
||||
ROW_SELECTED: string;
|
||||
};
|
||||
export declare const strings: {
|
||||
ARIA_SELECTED: string;
|
||||
DATA_ROW_ID_ATTR: string;
|
||||
HEADER_ROW_CHECKBOX_SELECTOR: string;
|
||||
ROW_CHECKBOX_SELECTOR: string;
|
||||
ROW_SELECTED_SELECTOR: string;
|
||||
ROW_SELECTOR: string;
|
||||
};
|
||||
export declare const events: {
|
||||
ROW_SELECTION_CHANGED: string;
|
||||
SELECTED_ALL: string;
|
||||
UNSELECTED_ALL: string;
|
||||
};
|
47
mdc-data-table/constants.js
Normal file
47
mdc-data-table/constants.js
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
export var cssClasses = {
|
||||
CELL: "mdc-data-table__cell",
|
||||
CELL_NUMERIC: "mdc-data-table__cell--numeric",
|
||||
CONTENT: "mdc-data-table__content",
|
||||
HEADER_ROW: "mdc-data-table__header-row",
|
||||
HEADER_ROW_CHECKBOX: "mdc-data-table__header-row-checkbox",
|
||||
ROOT: "mdc-data-table",
|
||||
ROW: "mdc-data-table__row",
|
||||
ROW_CHECKBOX: "mdc-data-table__row-checkbox",
|
||||
ROW_SELECTED: "mdc-data-table__row--selected",
|
||||
};
|
||||
export var strings = {
|
||||
ARIA_SELECTED: "aria-selected",
|
||||
DATA_ROW_ID_ATTR: "data-row-id",
|
||||
HEADER_ROW_CHECKBOX_SELECTOR: "." + cssClasses.HEADER_ROW_CHECKBOX,
|
||||
ROW_CHECKBOX_SELECTOR: "." + cssClasses.ROW_CHECKBOX,
|
||||
ROW_SELECTED_SELECTOR: "." + cssClasses.ROW_SELECTED,
|
||||
ROW_SELECTOR: "." + cssClasses.ROW,
|
||||
};
|
||||
export var events = {
|
||||
ROW_SELECTION_CHANGED: "MDCDataTable:rowSelectionChanged",
|
||||
SELECTED_ALL: "MDCDataTable:selectedAll",
|
||||
UNSELECTED_ALL: "MDCDataTable:unselectedAll",
|
||||
};
|
||||
//# sourceMappingURL=constants.js.map
|
1
mdc-data-table/constants.js.map
Normal file
1
mdc-data-table/constants.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"constants.js","sourceRoot":"","sources":["constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,CAAC,IAAM,UAAU,GAAG;IACxB,IAAI,EAAE,sBAAsB;IAC5B,YAAY,EAAE,+BAA+B;IAC7C,OAAO,EAAE,yBAAyB;IAClC,UAAU,EAAE,4BAA4B;IACxC,mBAAmB,EAAE,qCAAqC;IAC1D,IAAI,EAAE,gBAAgB;IACtB,GAAG,EAAE,qBAAqB;IAC1B,YAAY,EAAE,8BAA8B;IAC5C,YAAY,EAAE,+BAA+B;CAC9C,CAAC;AAEF,MAAM,CAAC,IAAM,OAAO,GAAG;IACrB,aAAa,EAAE,eAAe;IAC9B,gBAAgB,EAAE,aAAa;IAC/B,4BAA4B,EAAE,MAAI,UAAU,CAAC,mBAAqB;IAClE,qBAAqB,EAAE,MAAI,UAAU,CAAC,YAAc;IACpD,qBAAqB,EAAE,MAAI,UAAU,CAAC,YAAc;IACpD,YAAY,EAAE,MAAI,UAAU,CAAC,GAAK;CACnC,CAAC;AAEF,MAAM,CAAC,IAAM,MAAM,GAAG;IACpB,qBAAqB,EAAE,kCAAkC;IACzD,YAAY,EAAE,0BAA0B;IACxC,cAAc,EAAE,4BAA4B;CAC7C,CAAC"}
|
49
mdc-data-table/constants.ts
Normal file
49
mdc-data-table/constants.ts
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export const cssClasses = {
|
||||
CELL: "mdc-data-table__cell",
|
||||
CELL_NUMERIC: "mdc-data-table__cell--numeric",
|
||||
CONTENT: "mdc-data-table__content",
|
||||
HEADER_ROW: "mdc-data-table__header-row",
|
||||
HEADER_ROW_CHECKBOX: "mdc-data-table__header-row-checkbox",
|
||||
ROOT: "mdc-data-table",
|
||||
ROW: "mdc-data-table__row",
|
||||
ROW_CHECKBOX: "mdc-data-table__row-checkbox",
|
||||
ROW_SELECTED: "mdc-data-table__row--selected",
|
||||
};
|
||||
|
||||
export const strings = {
|
||||
ARIA_SELECTED: "aria-selected",
|
||||
DATA_ROW_ID_ATTR: "data-row-id",
|
||||
HEADER_ROW_CHECKBOX_SELECTOR: `.${cssClasses.HEADER_ROW_CHECKBOX}`,
|
||||
ROW_CHECKBOX_SELECTOR: `.${cssClasses.ROW_CHECKBOX}`,
|
||||
ROW_SELECTED_SELECTOR: `.${cssClasses.ROW_SELECTED}`,
|
||||
ROW_SELECTOR: `.${cssClasses.ROW}`,
|
||||
};
|
||||
|
||||
export const events = {
|
||||
ROW_SELECTION_CHANGED: "MDCDataTable:rowSelectionChanged",
|
||||
SELECTED_ALL: "MDCDataTable:selectedAll",
|
||||
UNSELECTED_ALL: "MDCDataTable:unselectedAll",
|
||||
};
|
69
mdc-data-table/foundation.d.ts
vendored
Normal file
69
mdc-data-table/foundation.d.ts
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import { MDCFoundation } from "@material/base/foundation";
|
||||
import { MDCDataTableAdapter } from "./adapter";
|
||||
export declare class MDCDataTableFoundation extends MDCFoundation<
|
||||
MDCDataTableAdapter
|
||||
> {
|
||||
static readonly defaultAdapter: MDCDataTableAdapter;
|
||||
constructor(adapter?: Partial<MDCDataTableAdapter>);
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
* Use this if registering checkbox is synchronous.
|
||||
*/
|
||||
layout(): void;
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
* Use this if registering checkbox is asynchronous.
|
||||
*/
|
||||
layoutAsync(): Promise<void>;
|
||||
/**
|
||||
* @return Returns array of row elements.
|
||||
*/
|
||||
getRows(): Element[];
|
||||
/**
|
||||
* Sets selected row ids. Overwrites previously selected rows.
|
||||
* @param rowIds Array of row ids that needs to be selected.
|
||||
*/
|
||||
setSelectedRowIds(rowIds: string[]): void;
|
||||
/**
|
||||
* @return Returns array of selected row ids.
|
||||
*/
|
||||
getSelectedRowIds(): Array<string | null>;
|
||||
/**
|
||||
* Handles header row checkbox change event.
|
||||
*/
|
||||
handleHeaderRowCheckboxChange(): void;
|
||||
/**
|
||||
* Handles change event originated from row checkboxes.
|
||||
*/
|
||||
handleRowCheckboxChange(event: Event): void;
|
||||
/**
|
||||
* Updates header row checkbox state based on number of rows selected.
|
||||
*/
|
||||
private setHeaderRowCheckboxState_;
|
||||
/**
|
||||
* Sets the attributes of row element based on selection state.
|
||||
*/
|
||||
private selectRowAtIndex_;
|
||||
}
|
244
mdc-data-table/foundation.js
vendored
Normal file
244
mdc-data-table/foundation.js
vendored
Normal file
@ -0,0 +1,244 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
import * as tslib_1 from "tslib";
|
||||
import { MDCFoundation } from "@material/base/foundation";
|
||||
import { cssClasses, strings } from "./constants";
|
||||
var MDCDataTableFoundation = /** @class */ (function(_super) {
|
||||
tslib_1.__extends(MDCDataTableFoundation, _super);
|
||||
function MDCDataTableFoundation(adapter) {
|
||||
return (
|
||||
_super.call(
|
||||
this,
|
||||
tslib_1.__assign({}, MDCDataTableFoundation.defaultAdapter, adapter)
|
||||
) || this
|
||||
);
|
||||
}
|
||||
Object.defineProperty(MDCDataTableFoundation, "defaultAdapter", {
|
||||
get: function() {
|
||||
return {
|
||||
addClassAtRowIndex: function() {
|
||||
return undefined;
|
||||
},
|
||||
getRowCount: function() {
|
||||
return 0;
|
||||
},
|
||||
getRowElements: function() {
|
||||
return [];
|
||||
},
|
||||
getRowIdAtIndex: function() {
|
||||
return "";
|
||||
},
|
||||
getRowIndexByChildElement: function() {
|
||||
return 0;
|
||||
},
|
||||
getSelectedRowCount: function() {
|
||||
return 0;
|
||||
},
|
||||
isCheckboxAtRowIndexChecked: function() {
|
||||
return false;
|
||||
},
|
||||
isHeaderRowCheckboxChecked: function() {
|
||||
return false;
|
||||
},
|
||||
isRowsSelectable: function() {
|
||||
return false;
|
||||
},
|
||||
notifyRowSelectionChanged: function() {
|
||||
return undefined;
|
||||
},
|
||||
notifySelectedAll: function() {
|
||||
return undefined;
|
||||
},
|
||||
notifyUnselectedAll: function() {
|
||||
return undefined;
|
||||
},
|
||||
registerHeaderRowCheckbox: function() {
|
||||
return undefined;
|
||||
},
|
||||
registerRowCheckboxes: function() {
|
||||
return undefined;
|
||||
},
|
||||
removeClassAtRowIndex: function() {
|
||||
return undefined;
|
||||
},
|
||||
setAttributeAtRowIndex: function() {
|
||||
return undefined;
|
||||
},
|
||||
setHeaderRowCheckboxChecked: function() {
|
||||
return undefined;
|
||||
},
|
||||
setHeaderRowCheckboxIndeterminate: function() {
|
||||
return undefined;
|
||||
},
|
||||
setRowCheckboxCheckedAtIndex: function() {
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
* Use this if registering checkbox is synchronous.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.layout = function() {
|
||||
if (this.adapter_.isRowsSelectable()) {
|
||||
this.adapter_.registerHeaderRowCheckbox();
|
||||
this.adapter_.registerRowCheckboxes();
|
||||
this.setHeaderRowCheckboxState_();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
* Use this if registering checkbox is asynchronous.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.layoutAsync = function() {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function() {
|
||||
return tslib_1.__generator(this, function(_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
if (!this.adapter_.isRowsSelectable()) return [3 /*break*/, 3];
|
||||
return [4 /*yield*/, this.adapter_.registerHeaderRowCheckbox()];
|
||||
case 1:
|
||||
_a.sent();
|
||||
return [4 /*yield*/, this.adapter_.registerRowCheckboxes()];
|
||||
case 2:
|
||||
_a.sent();
|
||||
this.setHeaderRowCheckboxState_();
|
||||
_a.label = 3;
|
||||
case 3:
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
/**
|
||||
* @return Returns array of row elements.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.getRows = function() {
|
||||
return this.adapter_.getRowElements();
|
||||
};
|
||||
/**
|
||||
* Sets selected row ids. Overwrites previously selected rows.
|
||||
* @param rowIds Array of row ids that needs to be selected.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.setSelectedRowIds = function(rowIds) {
|
||||
for (var rowIndex = 0; rowIndex < this.adapter_.getRowCount(); rowIndex++) {
|
||||
var rowId = this.adapter_.getRowIdAtIndex(rowIndex);
|
||||
var isSelected = false;
|
||||
if (rowId && rowIds.indexOf(rowId) >= 0) {
|
||||
isSelected = true;
|
||||
}
|
||||
this.adapter_.setRowCheckboxCheckedAtIndex(rowIndex, isSelected);
|
||||
this.selectRowAtIndex_(rowIndex, isSelected);
|
||||
}
|
||||
this.setHeaderRowCheckboxState_();
|
||||
};
|
||||
/**
|
||||
* @return Returns array of selected row ids.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.getSelectedRowIds = function() {
|
||||
var selectedRowIds = [];
|
||||
for (var rowIndex = 0; rowIndex < this.adapter_.getRowCount(); rowIndex++) {
|
||||
if (this.adapter_.isCheckboxAtRowIndexChecked(rowIndex)) {
|
||||
selectedRowIds.push(this.adapter_.getRowIdAtIndex(rowIndex));
|
||||
}
|
||||
}
|
||||
return selectedRowIds;
|
||||
};
|
||||
/**
|
||||
* Handles header row checkbox change event.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.handleHeaderRowCheckboxChange = function() {
|
||||
var isHeaderChecked = this.adapter_.isHeaderRowCheckboxChecked();
|
||||
for (var rowIndex = 0; rowIndex < this.adapter_.getRowCount(); rowIndex++) {
|
||||
this.adapter_.setRowCheckboxCheckedAtIndex(rowIndex, isHeaderChecked);
|
||||
this.selectRowAtIndex_(rowIndex, isHeaderChecked);
|
||||
}
|
||||
if (isHeaderChecked) {
|
||||
this.adapter_.notifySelectedAll();
|
||||
} else {
|
||||
this.adapter_.notifyUnselectedAll();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Handles change event originated from row checkboxes.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.handleRowCheckboxChange = function(event) {
|
||||
var rowIndex = this.adapter_.getRowIndexByChildElement(event.target);
|
||||
if (rowIndex === -1) {
|
||||
return;
|
||||
}
|
||||
var selected = this.adapter_.isCheckboxAtRowIndexChecked(rowIndex);
|
||||
this.selectRowAtIndex_(rowIndex, selected);
|
||||
this.setHeaderRowCheckboxState_();
|
||||
var rowId = this.adapter_.getRowIdAtIndex(rowIndex);
|
||||
this.adapter_.notifyRowSelectionChanged({
|
||||
rowId: rowId,
|
||||
rowIndex: rowIndex,
|
||||
selected: selected,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Updates header row checkbox state based on number of rows selected.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.setHeaderRowCheckboxState_ = function() {
|
||||
if (this.adapter_.getSelectedRowCount() === this.adapter_.getRowCount()) {
|
||||
this.adapter_.setHeaderRowCheckboxChecked(true);
|
||||
this.adapter_.setHeaderRowCheckboxIndeterminate(false);
|
||||
} else if (this.adapter_.getSelectedRowCount() === 0) {
|
||||
this.adapter_.setHeaderRowCheckboxIndeterminate(false);
|
||||
this.adapter_.setHeaderRowCheckboxChecked(false);
|
||||
} else {
|
||||
this.adapter_.setHeaderRowCheckboxIndeterminate(true);
|
||||
this.adapter_.setHeaderRowCheckboxChecked(false);
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Sets the attributes of row element based on selection state.
|
||||
*/
|
||||
MDCDataTableFoundation.prototype.selectRowAtIndex_ = function(
|
||||
rowIndex,
|
||||
selected
|
||||
) {
|
||||
if (selected) {
|
||||
this.adapter_.addClassAtRowIndex(rowIndex, cssClasses.ROW_SELECTED);
|
||||
this.adapter_.setAttributeAtRowIndex(
|
||||
rowIndex,
|
||||
strings.ARIA_SELECTED,
|
||||
"true"
|
||||
);
|
||||
} else {
|
||||
this.adapter_.removeClassAtRowIndex(rowIndex, cssClasses.ROW_SELECTED);
|
||||
this.adapter_.setAttributeAtRowIndex(
|
||||
rowIndex,
|
||||
strings.ARIA_SELECTED,
|
||||
"false"
|
||||
);
|
||||
}
|
||||
};
|
||||
return MDCDataTableFoundation;
|
||||
})(MDCFoundation);
|
||||
export { MDCDataTableFoundation };
|
||||
//# sourceMappingURL=foundation.js.map
|
1
mdc-data-table/foundation.js.map
Normal file
1
mdc-data-table/foundation.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"foundation.js","sourceRoot":"","sources":["foundation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAC,UAAU,EAAE,OAAO,EAAC,MAAM,aAAa,CAAC;AAEhD;IAA4C,kDAAkC;IAyB5E,gCAAY,OAAsC;eAChD,uCAAU,sBAAsB,CAAC,cAAc,EAAK,OAAO,EAAE;IAC/D,CAAC;IA1BD,sBAAW,wCAAc;aAAzB;YACE,OAAO;gBACL,kBAAkB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBACnC,WAAW,EAAE,cAAM,OAAA,CAAC,EAAD,CAAC;gBACpB,cAAc,EAAE,cAAM,OAAA,EAAE,EAAF,CAAE;gBACxB,eAAe,EAAE,cAAM,OAAA,EAAE,EAAF,CAAE;gBACzB,yBAAyB,EAAE,cAAM,OAAA,CAAC,EAAD,CAAC;gBAClC,mBAAmB,EAAE,cAAM,OAAA,CAAC,EAAD,CAAC;gBAC5B,2BAA2B,EAAE,cAAM,OAAA,KAAK,EAAL,CAAK;gBACxC,0BAA0B,EAAE,cAAM,OAAA,KAAK,EAAL,CAAK;gBACvC,gBAAgB,EAAE,cAAM,OAAA,KAAK,EAAL,CAAK;gBAC7B,yBAAyB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBAC1C,iBAAiB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBAClC,mBAAmB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBACpC,yBAAyB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBAC1C,qBAAqB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBACtC,qBAAqB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBACtC,sBAAsB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBACvC,2BAA2B,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBAC5C,iCAAiC,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;gBAClD,4BAA4B,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;aAC9C,CAAC;QACJ,CAAC;;;OAAA;IAMD;;;OAGG;IACH,uCAAM,GAAN;QACE,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,EAAE;YACpC,IAAI,CAAC,QAAQ,CAAC,yBAAyB,EAAE,CAAC;YAC1C,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,CAAC;YAEtC,IAAI,CAAC,0BAA0B,EAAE,CAAC;SACnC;IACH,CAAC;IAED;;;OAGG;IACG,4CAAW,GAAjB;;;;;6BACM,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,EAAhC,wBAAgC;wBAClC,qBAAM,IAAI,CAAC,QAAQ,CAAC,yBAAyB,EAAE,EAAA;;wBAA/C,SAA+C,CAAC;wBAChD,qBAAM,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,EAAA;;wBAA3C,SAA2C,CAAC;wBAE5C,IAAI,CAAC,0BAA0B,EAAE,CAAC;;;;;;KAErC;IAED;;OAEG;IACH,wCAAO,GAAP;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,kDAAiB,GAAjB,UAAkB,MAAgB;QAChC,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE;YACzE,IAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;YAEtD,IAAI,UAAU,GAAG,KAAK,CAAC;YACvB,IAAI,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;gBACvC,UAAU,GAAG,IAAI,CAAC;aACnB;YAED,IAAI,CAAC,QAAQ,CAAC,4BAA4B,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YACjE,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;SAC9C;QAED,IAAI,CAAC,0BAA0B,EAAE,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,kDAAiB,GAAjB;QACE,IAAM,cAAc,GAAuB,EAAE,CAAC;QAC9C,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE;YACzE,IAAI,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,QAAQ,CAAC,EAAE;gBACvD,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;aAC9D;SACF;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,8DAA6B,GAA7B;QACE,IAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,0BAA0B,EAAE,CAAC;QAEnE,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE;YACzE,IAAI,CAAC,QAAQ,CAAC,4BAA4B,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;YACtE,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;SACnD;QAED,IAAI,eAAe,EAAE;YACnB,IAAI,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC;SACnC;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,mBAAmB,EAAE,CAAC;SACrC;IACH,CAAC;IAED;;OAEG;IACH,wDAAuB,GAAvB,UAAwB,KAAY;QAClC,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC,KAAK,CAAC,MAA0B,CAAC,CAAC;QAE3F,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE;YACnB,OAAO;SACR;QAED,IAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;QAErE,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAElC,IAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QACtD,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAC,KAAK,OAAA,EAAE,QAAQ,UAAA,EAAE,QAAQ,UAAA,EAAC,CAAC,CAAC;IACvE,CAAC;IAED;;OAEG;IACK,2DAA0B,GAAlC;QACE,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB,EAAE,KAAK,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE;YACvE,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC;YAChD,IAAI,CAAC,QAAQ,CAAC,iCAAiC,CAAC,KAAK,CAAC,CAAC;SACxD;aAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB,EAAE,KAAK,CAAC,EAAE;YACpD,IAAI,CAAC,QAAQ,CAAC,iCAAiC,CAAC,KAAK,CAAC,CAAC;YACvD,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC;SAClD;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,iCAAiC,CAAC,IAAI,CAAC,CAAC;YACtD,IAAI,CAAC,QAAQ,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC;SAClD;IACH,CAAC;IAED;;OAEG;IACK,kDAAiB,GAAzB,UAA0B,QAAgB,EAAE,QAAiB;QAC3D,IAAI,QAAQ,EAAE;YACZ,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;YACpE,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;SAC/E;aAAM;YACL,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;YACvE,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;SAChF;IACH,CAAC;IACH,6BAAC;AAAD,CAAC,AAjKD,CAA4C,aAAa,GAiKxD"}
|
199
mdc-data-table/foundation.ts
Normal file
199
mdc-data-table/foundation.ts
Normal file
@ -0,0 +1,199 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { MDCFoundation } from "@material/base/foundation";
|
||||
import { MDCDataTableAdapter } from "./adapter";
|
||||
import { cssClasses, strings } from "./constants";
|
||||
|
||||
export class MDCDataTableFoundation extends MDCFoundation<MDCDataTableAdapter> {
|
||||
static get defaultAdapter(): MDCDataTableAdapter {
|
||||
return {
|
||||
addClassAtRowIndex: () => undefined,
|
||||
getRowCount: () => 0,
|
||||
getRowElements: () => [],
|
||||
getRowIdAtIndex: () => "",
|
||||
getRowIndexByChildElement: () => 0,
|
||||
getSelectedRowCount: () => 0,
|
||||
isCheckboxAtRowIndexChecked: () => false,
|
||||
isHeaderRowCheckboxChecked: () => false,
|
||||
isRowsSelectable: () => false,
|
||||
notifyRowSelectionChanged: () => undefined,
|
||||
notifySelectedAll: () => undefined,
|
||||
notifyUnselectedAll: () => undefined,
|
||||
registerHeaderRowCheckbox: () => undefined,
|
||||
registerRowCheckboxes: () => undefined,
|
||||
removeClassAtRowIndex: () => undefined,
|
||||
setAttributeAtRowIndex: () => undefined,
|
||||
setHeaderRowCheckboxChecked: () => undefined,
|
||||
setHeaderRowCheckboxIndeterminate: () => undefined,
|
||||
setRowCheckboxCheckedAtIndex: () => undefined,
|
||||
};
|
||||
}
|
||||
|
||||
constructor(adapter?: Partial<MDCDataTableAdapter>) {
|
||||
super({ ...MDCDataTableFoundation.defaultAdapter, ...adapter });
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
* Use this if registering checkbox is synchronous.
|
||||
*/
|
||||
layout() {
|
||||
if (this.adapter_.isRowsSelectable()) {
|
||||
this.adapter_.registerHeaderRowCheckbox();
|
||||
this.adapter_.registerRowCheckboxes();
|
||||
|
||||
this.setHeaderRowCheckboxState_();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-initializes header row checkbox and row checkboxes when selectable rows are added or removed from table.
|
||||
* Use this if registering checkbox is asynchronous.
|
||||
*/
|
||||
async layoutAsync(): Promise<void> {
|
||||
if (this.adapter_.isRowsSelectable()) {
|
||||
await this.adapter_.registerHeaderRowCheckbox();
|
||||
await this.adapter_.registerRowCheckboxes();
|
||||
|
||||
this.setHeaderRowCheckboxState_();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns array of row elements.
|
||||
*/
|
||||
getRows(): Element[] {
|
||||
return this.adapter_.getRowElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets selected row ids. Overwrites previously selected rows.
|
||||
* @param rowIds Array of row ids that needs to be selected.
|
||||
*/
|
||||
setSelectedRowIds(rowIds: string[]) {
|
||||
for (let rowIndex = 0; rowIndex < this.adapter_.getRowCount(); rowIndex++) {
|
||||
const rowId = this.adapter_.getRowIdAtIndex(rowIndex);
|
||||
|
||||
let isSelected = false;
|
||||
if (rowId && rowIds.indexOf(rowId) >= 0) {
|
||||
isSelected = true;
|
||||
}
|
||||
|
||||
this.adapter_.setRowCheckboxCheckedAtIndex(rowIndex, isSelected);
|
||||
this.selectRowAtIndex_(rowIndex, isSelected);
|
||||
}
|
||||
|
||||
this.setHeaderRowCheckboxState_();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns array of selected row ids.
|
||||
*/
|
||||
getSelectedRowIds(): Array<string | null> {
|
||||
const selectedRowIds: Array<string | null> = [];
|
||||
for (let rowIndex = 0; rowIndex < this.adapter_.getRowCount(); rowIndex++) {
|
||||
if (this.adapter_.isCheckboxAtRowIndexChecked(rowIndex)) {
|
||||
selectedRowIds.push(this.adapter_.getRowIdAtIndex(rowIndex));
|
||||
}
|
||||
}
|
||||
|
||||
return selectedRowIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles header row checkbox change event.
|
||||
*/
|
||||
handleHeaderRowCheckboxChange() {
|
||||
const isHeaderChecked = this.adapter_.isHeaderRowCheckboxChecked();
|
||||
|
||||
for (let rowIndex = 0; rowIndex < this.adapter_.getRowCount(); rowIndex++) {
|
||||
this.adapter_.setRowCheckboxCheckedAtIndex(rowIndex, isHeaderChecked);
|
||||
this.selectRowAtIndex_(rowIndex, isHeaderChecked);
|
||||
}
|
||||
|
||||
if (isHeaderChecked) {
|
||||
this.adapter_.notifySelectedAll();
|
||||
} else {
|
||||
this.adapter_.notifyUnselectedAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles change event originated from row checkboxes.
|
||||
*/
|
||||
handleRowCheckboxChange(event: Event) {
|
||||
const rowIndex = this.adapter_.getRowIndexByChildElement(
|
||||
event.target as HTMLInputElement
|
||||
);
|
||||
|
||||
if (rowIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const selected = this.adapter_.isCheckboxAtRowIndexChecked(rowIndex);
|
||||
|
||||
this.selectRowAtIndex_(rowIndex, selected);
|
||||
this.setHeaderRowCheckboxState_();
|
||||
|
||||
const rowId = this.adapter_.getRowIdAtIndex(rowIndex);
|
||||
this.adapter_.notifyRowSelectionChanged({ rowId, rowIndex, selected });
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates header row checkbox state based on number of rows selected.
|
||||
*/
|
||||
private setHeaderRowCheckboxState_() {
|
||||
if (this.adapter_.getSelectedRowCount() === this.adapter_.getRowCount()) {
|
||||
this.adapter_.setHeaderRowCheckboxChecked(true);
|
||||
this.adapter_.setHeaderRowCheckboxIndeterminate(false);
|
||||
} else if (this.adapter_.getSelectedRowCount() === 0) {
|
||||
this.adapter_.setHeaderRowCheckboxIndeterminate(false);
|
||||
this.adapter_.setHeaderRowCheckboxChecked(false);
|
||||
} else {
|
||||
this.adapter_.setHeaderRowCheckboxIndeterminate(true);
|
||||
this.adapter_.setHeaderRowCheckboxChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attributes of row element based on selection state.
|
||||
*/
|
||||
private selectRowAtIndex_(rowIndex: number, selected: boolean) {
|
||||
if (selected) {
|
||||
this.adapter_.addClassAtRowIndex(rowIndex, cssClasses.ROW_SELECTED);
|
||||
this.adapter_.setAttributeAtRowIndex(
|
||||
rowIndex,
|
||||
strings.ARIA_SELECTED,
|
||||
"true"
|
||||
);
|
||||
} else {
|
||||
this.adapter_.removeClassAtRowIndex(rowIndex, cssClasses.ROW_SELECTED);
|
||||
this.adapter_.setAttributeAtRowIndex(
|
||||
rowIndex,
|
||||
strings.ARIA_SELECTED,
|
||||
"false"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
27
mdc-data-table/index.d.ts
vendored
Normal file
27
mdc-data-table/index.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
export * from "./adapter";
|
||||
export * from "./component";
|
||||
export * from "./foundation";
|
||||
export * from "./constants";
|
||||
export * from "./types";
|
26
mdc-data-table/index.js
Normal file
26
mdc-data-table/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
export * from "./component";
|
||||
export * from "./foundation";
|
||||
export * from "./constants";
|
||||
//# sourceMappingURL=index.js.map
|
1
mdc-data-table/index.js.map
Normal file
1
mdc-data-table/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
28
mdc-data-table/index.ts
Normal file
28
mdc-data-table/index.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export * from "./adapter";
|
||||
export * from "./component";
|
||||
export * from "./foundation";
|
||||
export * from "./constants";
|
||||
export * from "./types";
|
25
mdc-data-table/mdc-data-table.scss
Normal file
25
mdc-data-table/mdc-data-table.scss
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright 2019 Google Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
@import "./mixins";
|
||||
@include mdc-data-table-core-styles;
|
||||
@include mdc-data-table-theme-baseline;
|
37
mdc-data-table/package.json
Normal file
37
mdc-data-table/package.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@material/data-table",
|
||||
"version": "3.1.1",
|
||||
"description": "The Material Components Web data table component",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"material components",
|
||||
"material design",
|
||||
"data table"
|
||||
],
|
||||
"main": "dist/mdc.dataTable.js",
|
||||
"module": "index.js",
|
||||
"sideEffects": false,
|
||||
"types": "dist/mdc.dataTable.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/material-components/material-components-web.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@material/animation": "^3.1.0",
|
||||
"@material/base": "^3.1.0",
|
||||
"@material/checkbox": "^3.1.0",
|
||||
"@material/dom": "^3.1.0",
|
||||
"@material/elevation": "^3.1.0",
|
||||
"@material/feature-targeting": "^3.1.0",
|
||||
"@material/ripple": "^3.1.0",
|
||||
"@material/rtl": "^3.1.0",
|
||||
"@material/shape": "^3.1.0",
|
||||
"@material/theme": "^3.1.0",
|
||||
"@material/typography": "^3.1.0",
|
||||
"tslib": "^1.10.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"gitHead": "4a7d0aa41afb294e54c4aeae56558b1793416074"
|
||||
}
|
27
mdc-data-table/types.d.ts
vendored
Normal file
27
mdc-data-table/types.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
export interface MDCDataTableRowSelectionChangedEventDetail {
|
||||
rowIndex: number;
|
||||
rowId: string | null;
|
||||
selected: boolean;
|
||||
}
|
23
mdc-data-table/types.js
Normal file
23
mdc-data-table/types.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
//# sourceMappingURL=types.js.map
|
1
mdc-data-table/types.js.map
Normal file
1
mdc-data-table/types.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
28
mdc-data-table/types.ts
Normal file
28
mdc-data-table/types.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
export interface MDCDataTableRowSelectionChangedEventDetail {
|
||||
rowIndex: number;
|
||||
rowId: string | null;
|
||||
selected: boolean;
|
||||
}
|
@ -17,6 +17,7 @@
|
||||
"author": "Paulus Schoutsen <Paulus@PaulusSchoutsen.nl> (http://paulusschoutsen.nl)",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@material/data-table": "^3.1.1",
|
||||
"@material/mwc-base": "^0.8.0",
|
||||
"@material/mwc-button": "^0.8.0",
|
||||
"@material/mwc-checkbox": "^0.8.0",
|
||||
|
455
src/components/ha-data-table.ts
Normal file
455
src/components/ha-data-table.ts
Normal file
@ -0,0 +1,455 @@
|
||||
import { repeat } from "lit-html/directives/repeat";
|
||||
|
||||
import {
|
||||
MDCDataTableAdapter,
|
||||
MDCDataTableFoundation,
|
||||
} from "../../mdc-data-table/index"; // Because mdc-data-table published ts files, temporary load them from own repo, outside src so our linters won't complain
|
||||
|
||||
import {
|
||||
BaseElement,
|
||||
html,
|
||||
query,
|
||||
queryAll,
|
||||
CSSResult,
|
||||
css,
|
||||
customElement,
|
||||
property,
|
||||
unsafeCSS,
|
||||
classMap,
|
||||
TemplateResult,
|
||||
PropertyValues,
|
||||
} from "@material/mwc-base/base-element";
|
||||
|
||||
// @ts-ignore
|
||||
import styles from "@material/data-table/dist/mdc.data-table.min.css";
|
||||
|
||||
import memoizeOne from "memoize-one";
|
||||
|
||||
import "./ha-icon";
|
||||
import "../common/search/search-input";
|
||||
import "./ha-checkbox";
|
||||
// tslint:disable-next-line
|
||||
import { HaCheckbox } from "./ha-checkbox";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
|
||||
declare global {
|
||||
// for fire event
|
||||
interface HASSDomEvents {
|
||||
"selection-changed": SelectionChangedEvent;
|
||||
"sorting-changed": SortingChangedEvent;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SelectionChangedEvent {
|
||||
id: string;
|
||||
selected: boolean;
|
||||
}
|
||||
|
||||
export interface SortingChangedEvent {
|
||||
column: string;
|
||||
direction: SortingDirection;
|
||||
}
|
||||
|
||||
export type SortingDirection = "desc" | "asc" | null;
|
||||
|
||||
export interface DataTabelColumnContainer {
|
||||
[key: string]: DataTabelColumnData;
|
||||
}
|
||||
|
||||
export interface DataTabelColumnData {
|
||||
title: string;
|
||||
type?: "numeric";
|
||||
sortable?: boolean;
|
||||
filterable?: boolean;
|
||||
filterKey?: string;
|
||||
direction?: SortingDirection;
|
||||
template?: (data: any) => TemplateResult;
|
||||
}
|
||||
|
||||
export interface DataTabelRowData {
|
||||
id: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@customElement("ha-data-table")
|
||||
export class HaDataTable extends BaseElement {
|
||||
@property({ type: Object }) public columns: DataTabelColumnContainer = {};
|
||||
@property({ type: Array }) public data: DataTabelRowData[] = [];
|
||||
@property({ type: Boolean }) public selectable = false;
|
||||
@property({ type: String }) public id = "id";
|
||||
protected mdcFoundation!: MDCDataTableFoundation;
|
||||
protected readonly mdcFoundationClass = MDCDataTableFoundation;
|
||||
@query(".mdc-data-table") protected mdcRoot!: HTMLElement;
|
||||
@queryAll(".mdc-data-table__row") protected rowElements!: HTMLElement[];
|
||||
@query("#header-checkbox") private _headerCheckbox!: HaCheckbox;
|
||||
@property({ type: Boolean }) private _filterable = false;
|
||||
@property({ type: Boolean }) private _headerChecked = false;
|
||||
@property({ type: Boolean }) private _headerIndeterminate = false;
|
||||
@property({ type: Array }) private _checkedRows: string[] = [];
|
||||
@property({ type: String }) private _filter = "";
|
||||
@property({ type: String }) private _sortColumn?: string;
|
||||
@property({ type: String }) private _sortDirection: SortingDirection = null;
|
||||
|
||||
private _filterSortData = memoizeOne(
|
||||
(
|
||||
data: DataTabelRowData[],
|
||||
columns: DataTabelColumnContainer,
|
||||
filter: string,
|
||||
direction: SortingDirection,
|
||||
sortColumn?: string
|
||||
) =>
|
||||
sortColumn
|
||||
? this._memSortData(
|
||||
this._memFilterData(data, columns, filter),
|
||||
columns,
|
||||
direction,
|
||||
sortColumn
|
||||
)
|
||||
: this._memFilterData(data, columns, filter)
|
||||
);
|
||||
|
||||
private _memFilterData = memoizeOne(
|
||||
(
|
||||
data: DataTabelRowData[],
|
||||
columns: DataTabelColumnContainer,
|
||||
filter: string
|
||||
) => {
|
||||
if (!filter) {
|
||||
return data;
|
||||
}
|
||||
const ucFilter = filter.toUpperCase();
|
||||
return data.filter((row) => {
|
||||
return Object.entries(columns).some((columnEntry) => {
|
||||
const [key, column] = columnEntry;
|
||||
if (column.filterable) {
|
||||
if (
|
||||
(column.filterKey ? row[key][column.filterKey] : row[key])
|
||||
.toUpperCase()
|
||||
.includes(ucFilter)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
private _memSortData = memoizeOne(
|
||||
(
|
||||
data: DataTabelRowData[],
|
||||
columns: DataTabelColumnContainer,
|
||||
direction: SortingDirection,
|
||||
sortColumn: string
|
||||
) => {
|
||||
const sorted = [...data];
|
||||
const column = columns[sortColumn];
|
||||
return sorted.sort((a, b) => {
|
||||
let sort = 1;
|
||||
if (direction === "desc") {
|
||||
sort = -1;
|
||||
}
|
||||
|
||||
let valA = column.filterKey
|
||||
? a[sortColumn][column.filterKey]
|
||||
: a[sortColumn];
|
||||
|
||||
let valB = column.filterKey
|
||||
? b[sortColumn][column.filterKey]
|
||||
: b[sortColumn];
|
||||
|
||||
if (typeof valA === "string") {
|
||||
valA = valA.toUpperCase();
|
||||
}
|
||||
if (typeof valB === "string") {
|
||||
valB = valB.toUpperCase();
|
||||
}
|
||||
|
||||
if (valA < valB) {
|
||||
return sort * -1;
|
||||
}
|
||||
if (valA > valB) {
|
||||
return sort * 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
protected updated(properties: PropertyValues) {
|
||||
super.updated(properties);
|
||||
|
||||
if (properties.has("columns")) {
|
||||
this._filterable = Object.values(this.columns).some(
|
||||
(column) => column.filterable
|
||||
);
|
||||
|
||||
for (const columnId in this.columns) {
|
||||
if (this.columns[columnId].direction) {
|
||||
this._sortDirection = this.columns[columnId].direction!;
|
||||
this._sortColumn = columnId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
return html`
|
||||
${this._filterable
|
||||
? html`
|
||||
<search-input
|
||||
@value-changed=${this._handleSearchChange}
|
||||
></search-input>
|
||||
`
|
||||
: ""}
|
||||
<div class="mdc-data-table">
|
||||
<table class="mdc-data-table__table">
|
||||
<thead>
|
||||
<tr class="mdc-data-table__header-row">
|
||||
${this.selectable
|
||||
? html`
|
||||
<th
|
||||
class="mdc-data-table__header-cell mdc-data-table__header-cell--checkbox"
|
||||
role="columnheader"
|
||||
scope="col"
|
||||
>
|
||||
<ha-checkbox
|
||||
id="header-checkbox"
|
||||
class="mdc-data-table__row-checkbox"
|
||||
@change=${this._handleHeaderRowCheckboxChange}
|
||||
.indeterminate=${this._headerIndeterminate}
|
||||
.checked=${this._headerChecked}
|
||||
>
|
||||
</ha-checkbox>
|
||||
</th>
|
||||
`
|
||||
: ""}
|
||||
${Object.entries(this.columns).map((columnEntry) => {
|
||||
const [key, column] = columnEntry;
|
||||
const sorted = key === this._sortColumn;
|
||||
const classes = {
|
||||
"mdc-data-table__cell--numeric": Boolean(
|
||||
column.type && column.type === "numeric"
|
||||
),
|
||||
sortable: Boolean(column.sortable),
|
||||
"not-sorted": Boolean(column.sortable && !sorted),
|
||||
};
|
||||
return html`
|
||||
<th
|
||||
class="mdc-data-table__header-cell ${classMap(classes)}"
|
||||
role="columnheader"
|
||||
scope="col"
|
||||
@click=${this._handleHeaderClick}
|
||||
data-column-id="${key}"
|
||||
>
|
||||
${column.sortable
|
||||
? html`
|
||||
<ha-icon
|
||||
.icon=${sorted && this._sortDirection === "desc"
|
||||
? "hass:arrow-down"
|
||||
: "hass:arrow-up"}
|
||||
></ha-icon>
|
||||
`
|
||||
: ""}
|
||||
<span>${column.title}</span>
|
||||
</th>
|
||||
`;
|
||||
})}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="mdc-data-table__content">
|
||||
${repeat(
|
||||
this._filterSortData(
|
||||
this.data,
|
||||
this.columns,
|
||||
this._filter,
|
||||
this._sortDirection,
|
||||
this._sortColumn
|
||||
),
|
||||
(row: DataTabelRowData) => row[this.id],
|
||||
(row: DataTabelRowData) => html`
|
||||
<tr data-row-id="${row[this.id]}" class="mdc-data-table__row">
|
||||
${this.selectable
|
||||
? html`
|
||||
<td
|
||||
class="mdc-data-table__cell mdc-data-table__cell--checkbox"
|
||||
>
|
||||
<ha-checkbox
|
||||
class="mdc-data-table__row-checkbox"
|
||||
@change=${this._handleRowCheckboxChange}
|
||||
.checked=${this._checkedRows.includes(row[this.id])}
|
||||
>
|
||||
</ha-checkbox>
|
||||
</td>
|
||||
`
|
||||
: ""}
|
||||
${Object.entries(this.columns).map((columnEntry) => {
|
||||
const [key, column] = columnEntry;
|
||||
return html`
|
||||
<td
|
||||
class="mdc-data-table__cell ${classMap({
|
||||
"mdc-data-table__cell--numeric": Boolean(
|
||||
column.type && column.type === "numeric"
|
||||
),
|
||||
})}"
|
||||
>
|
||||
${column.template
|
||||
? column.template(row[key])
|
||||
: row[key]}
|
||||
</td>
|
||||
`;
|
||||
})}
|
||||
</tr>
|
||||
`
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
protected createAdapter(): MDCDataTableAdapter {
|
||||
return {
|
||||
addClassAtRowIndex: (rowIndex: number, cssClasses: string) => {
|
||||
this.rowElements[rowIndex].classList.add(cssClasses);
|
||||
},
|
||||
getRowCount: () => this.data.length,
|
||||
getRowElements: () => this.rowElements,
|
||||
getRowIdAtIndex: (rowIndex: number) => this._getRowIdAtIndex(rowIndex),
|
||||
getRowIndexByChildElement: (el: Element) =>
|
||||
Array.prototype.indexOf.call(this.rowElements, el.closest("tr")),
|
||||
getSelectedRowCount: () => this._checkedRows.length,
|
||||
isCheckboxAtRowIndexChecked: (rowIndex: number) =>
|
||||
this._checkedRows.includes(this._getRowIdAtIndex(rowIndex)),
|
||||
isHeaderRowCheckboxChecked: () => this._headerChecked,
|
||||
isRowsSelectable: () => true,
|
||||
notifyRowSelectionChanged: () => undefined,
|
||||
notifySelectedAll: () => undefined,
|
||||
notifyUnselectedAll: () => undefined,
|
||||
registerHeaderRowCheckbox: () => undefined,
|
||||
registerRowCheckboxes: () => undefined,
|
||||
removeClassAtRowIndex: (rowIndex: number, cssClasses: string) => {
|
||||
this.rowElements[rowIndex].classList.remove(cssClasses);
|
||||
},
|
||||
setAttributeAtRowIndex: (
|
||||
rowIndex: number,
|
||||
attr: string,
|
||||
value: string
|
||||
) => {
|
||||
this.rowElements[rowIndex].setAttribute(attr, value);
|
||||
},
|
||||
setHeaderRowCheckboxChecked: (checked: boolean) => {
|
||||
this._headerChecked = checked;
|
||||
},
|
||||
setHeaderRowCheckboxIndeterminate: (indeterminate: boolean) => {
|
||||
this._headerIndeterminate = indeterminate;
|
||||
},
|
||||
setRowCheckboxCheckedAtIndex: (rowIndex: number, checked: boolean) => {
|
||||
this._setRowChecked(this._getRowIdAtIndex(rowIndex), checked);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private _getRowIdAtIndex(rowIndex: number): string {
|
||||
return this.rowElements[rowIndex].getAttribute("data-row-id")!;
|
||||
}
|
||||
|
||||
private _handleHeaderClick(ev: Event) {
|
||||
const columnId = (ev.target as HTMLElement)
|
||||
.closest("th")!
|
||||
.getAttribute("data-column-id")!;
|
||||
if (!this.columns[columnId].sortable) {
|
||||
return;
|
||||
}
|
||||
if (!this._sortDirection || this._sortColumn !== columnId) {
|
||||
this._sortDirection = "asc";
|
||||
} else if (this._sortDirection === "asc") {
|
||||
this._sortDirection = "desc";
|
||||
} else {
|
||||
this._sortDirection = null;
|
||||
}
|
||||
|
||||
this._sortColumn = this._sortDirection === null ? undefined : columnId;
|
||||
|
||||
fireEvent(this, "sorting-changed", {
|
||||
column: columnId,
|
||||
direction: this._sortDirection,
|
||||
});
|
||||
}
|
||||
|
||||
private _handleHeaderRowCheckboxChange() {
|
||||
this._headerChecked = this._headerCheckbox.checked;
|
||||
this._headerIndeterminate = this._headerCheckbox.indeterminate;
|
||||
this.mdcFoundation.handleHeaderRowCheckboxChange();
|
||||
}
|
||||
|
||||
private _handleRowCheckboxChange(ev: Event) {
|
||||
const checkbox = ev.target as HaCheckbox;
|
||||
const rowId = checkbox.parentElement!.parentElement!.getAttribute(
|
||||
"data-row-id"
|
||||
);
|
||||
|
||||
this._setRowChecked(rowId!, checkbox.checked);
|
||||
this.mdcFoundation.handleRowCheckboxChange(ev);
|
||||
}
|
||||
|
||||
private _setRowChecked(rowId: string, checked: boolean) {
|
||||
if (checked && !this._checkedRows.includes(rowId)) {
|
||||
this._checkedRows = [...this._checkedRows, rowId];
|
||||
} else if (!checked) {
|
||||
const index = this._checkedRows.indexOf(rowId);
|
||||
if (index !== -1) {
|
||||
this._checkedRows.splice(index, 1);
|
||||
}
|
||||
}
|
||||
fireEvent(this, "selection-changed", {
|
||||
id: rowId,
|
||||
selected: checked,
|
||||
});
|
||||
}
|
||||
|
||||
private _handleSearchChange(ev: CustomEvent): void {
|
||||
this._filter = ev.detail.value;
|
||||
}
|
||||
|
||||
static get styles(): CSSResult {
|
||||
return css`
|
||||
${unsafeCSS(styles)}
|
||||
.mdc-data-table {
|
||||
display: block;
|
||||
}
|
||||
.mdc-data-table__header-cell {
|
||||
overflow: hidden;
|
||||
}
|
||||
.mdc-data-table__header-cell.sortable {
|
||||
cursor: pointer;
|
||||
}
|
||||
.mdc-data-table__header-cell.not-sorted:not(.mdc-data-table__cell--numeric)
|
||||
span {
|
||||
position: relative;
|
||||
left: -24px;
|
||||
}
|
||||
.mdc-data-table__header-cell.not-sorted > * {
|
||||
transition: left 0.2s ease 0s;
|
||||
}
|
||||
.mdc-data-table__header-cell.not-sorted ha-icon {
|
||||
left: -36px;
|
||||
}
|
||||
.mdc-data-table__header-cell.not-sorted:not(.mdc-data-table__cell--numeric):hover
|
||||
span {
|
||||
left: 0px;
|
||||
}
|
||||
.mdc-data-table__header-cell:hover.not-sorted ha-icon {
|
||||
left: 0px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-data-table": HaDataTable;
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
import {
|
||||
html,
|
||||
LitElement,
|
||||
TemplateResult,
|
||||
customElement,
|
||||
property,
|
||||
css,
|
||||
CSSResult,
|
||||
} from "lit-element";
|
||||
|
||||
import { Checkbox } from "@material/mwc-checkbox";
|
||||
import { HomeAssistant } from "../../../../types";
|
||||
import computeStateName from "../../../../common/entity/compute_state_name";
|
||||
import computeDomain from "../../../../common/entity/compute_domain";
|
||||
|
||||
import "../../../../components/ha-checkbox";
|
||||
import "../../../../components/entity/state-badge";
|
||||
import "../../../../components/ha-relative-time";
|
||||
import "../../../../components/ha-icon";
|
||||
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
|
||||
declare global {
|
||||
// for fire event
|
||||
interface HASSDomEvents {
|
||||
"entity-selection-changed": EntitySelectionChangedEvent;
|
||||
}
|
||||
}
|
||||
|
||||
export interface EntitySelectionChangedEvent {
|
||||
entity: string;
|
||||
selected: boolean;
|
||||
}
|
||||
|
||||
@customElement("hui-select-row")
|
||||
class HuiSelectRow extends LitElement {
|
||||
@property() public hass!: HomeAssistant;
|
||||
|
||||
@property() public entity?: string;
|
||||
|
||||
@property() public selectable = true;
|
||||
|
||||
protected render(): TemplateResult | void {
|
||||
if (!this.entity) {
|
||||
return html``;
|
||||
}
|
||||
|
||||
const stateObj = this.entity ? this.hass.states[this.entity] : undefined;
|
||||
|
||||
if (!stateObj) {
|
||||
return html``;
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="flex-row" role="rowgroup">
|
||||
<div class="flex-cell" role="cell">
|
||||
${this.selectable
|
||||
? html`
|
||||
<ha-checkbox @change=${this._handleSelect}></ha-checkbox>
|
||||
`
|
||||
: ""}
|
||||
<state-badge .hass=${this.hass} .stateObj=${stateObj}></state-badge>
|
||||
${computeStateName(stateObj)}
|
||||
</div>
|
||||
<div class="flex-cell" role="cell">${stateObj.entity_id}</div>
|
||||
<div class="flex-cell" role="cell">
|
||||
${computeDomain(stateObj.entity_id)}
|
||||
</div>
|
||||
<div class="flex-cell" role="cell">
|
||||
<ha-relative-time
|
||||
.hass=${this.hass}
|
||||
.datetime=${stateObj.last_changed}
|
||||
></ha-relative-time>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private _handleSelect(ev: Event): void {
|
||||
const checkbox = ev.currentTarget as Checkbox;
|
||||
fireEvent(this, "entity-selection-changed", {
|
||||
entity: this.entity!,
|
||||
selected: checkbox.checked as boolean,
|
||||
});
|
||||
}
|
||||
|
||||
static get styles(): CSSResult {
|
||||
return css`
|
||||
div {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.flex-row {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
}
|
||||
|
||||
.flex-row:hover {
|
||||
background: var(--table-row-alternative-background-color, #eee);
|
||||
}
|
||||
|
||||
.flex-cell {
|
||||
width: calc(100% / 4);
|
||||
padding: 12px 24px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 40px;
|
||||
}
|
||||
|
||||
@media all and (max-width: 767px) {
|
||||
.flex-cell {
|
||||
width: calc(100% / 3);
|
||||
padding-top: 0;
|
||||
}
|
||||
.flex-cell:first-child {
|
||||
width: 100%;
|
||||
padding-top: 12px;
|
||||
padding-bottom: 0;
|
||||
border-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media all and (max-width: 430px) {
|
||||
.flex-cell {
|
||||
border-bottom: 0;
|
||||
padding: 0 24px;
|
||||
}
|
||||
|
||||
.flex-cell:first-child {
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.flex-cell:last-child {
|
||||
padding-bottom: 12px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.flex-cell {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"hui-select-row": HuiSelectRow;
|
||||
}
|
||||
}
|
@ -11,8 +11,16 @@ import {
|
||||
|
||||
import { classMap } from "lit-html/directives/class-map";
|
||||
import "../../../../components/ha-fab";
|
||||
import "../../../../components/entity/state-badge";
|
||||
import "../../../../components/ha-relative-time";
|
||||
import "../../../../components/ha-icon";
|
||||
|
||||
import "./hui-select-row";
|
||||
import "../../../../components/ha-data-table";
|
||||
// tslint:disable-next-line
|
||||
import { SelectionChangedEvent } from "../../../../components/ha-data-table";
|
||||
|
||||
import computeStateName from "../../../../common/entity/compute_state_name";
|
||||
import computeDomain from "../../../../common/entity/compute_domain";
|
||||
|
||||
import { computeRTL } from "../../../../common/util/compute_rtl";
|
||||
import { computeUnusedEntities } from "../../common/compute-unused-entities";
|
||||
@ -37,6 +45,41 @@ export class HuiUnusedEntities extends LitElement {
|
||||
return this.lovelace!.config;
|
||||
}
|
||||
|
||||
private _columns = {
|
||||
entity: {
|
||||
title: "Entity",
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
filterKey: "friendly_name",
|
||||
direction: "asc",
|
||||
template: (stateObj) => html`
|
||||
<state-badge .hass=${this.hass!} .stateObj=${stateObj}></state-badge>
|
||||
${stateObj.friendly_name}
|
||||
`,
|
||||
},
|
||||
entity_id: {
|
||||
title: "Entity id",
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
},
|
||||
domain: {
|
||||
title: "Domain",
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
},
|
||||
last_changed: {
|
||||
title: "Last Changed",
|
||||
type: "numeric",
|
||||
sortable: true,
|
||||
template: (lastChanged: string) => html`
|
||||
<ha-relative-time
|
||||
.hass=${this.hass!}
|
||||
.datetime=${lastChanged}
|
||||
></ha-relative-time>
|
||||
`,
|
||||
},
|
||||
};
|
||||
|
||||
protected updated(changedProperties: PropertyValues): void {
|
||||
super.updated(changedProperties);
|
||||
|
||||
@ -66,29 +109,25 @@ export class HuiUnusedEntities extends LitElement {
|
||||
`
|
||||
: ""}
|
||||
</div>
|
||||
<div
|
||||
class="table-container"
|
||||
role="table"
|
||||
aria-label="Unused Entities"
|
||||
@entity-selection-changed=${this._handleSelectionChanged}
|
||||
>
|
||||
<div class="flex-row header" role="rowgroup">
|
||||
<div class="flex-cell" role="columnheader">Entity</div>
|
||||
<div class="flex-cell" role="columnheader">Entity id</div>
|
||||
<div class="flex-cell" role="columnheader">Domain</div>
|
||||
<div class="flex-cell" role="columnheader">Last Changed</div>
|
||||
</div>
|
||||
${this._unusedEntities.map((entity) => {
|
||||
return html`
|
||||
<hui-select-row
|
||||
.selectable=${this.lovelace!.mode === "storage"}
|
||||
.hass=${this.hass}
|
||||
.entity=${entity}
|
||||
></hui-select-row>
|
||||
`;
|
||||
})}
|
||||
</div>
|
||||
</ha-card>
|
||||
<ha-data-table
|
||||
.columns=${this._columns}
|
||||
.data=${this._unusedEntities.map((entity) => {
|
||||
const stateObj = this.hass!.states[entity];
|
||||
return {
|
||||
entity_id: entity,
|
||||
entity: {
|
||||
...stateObj,
|
||||
friendly_name: computeStateName(stateObj),
|
||||
},
|
||||
domain: computeDomain(entity),
|
||||
last_changed: stateObj!.last_changed,
|
||||
};
|
||||
})}
|
||||
.id=${"entity_id"}
|
||||
.selectable=${this.lovelace!.mode === "storage"}
|
||||
@selection-changed=${this._handleSelectionChanged}
|
||||
></ha-data-table>
|
||||
${this.lovelace.mode === "storage"
|
||||
? html`
|
||||
<ha-fab
|
||||
@ -114,11 +153,13 @@ export class HuiUnusedEntities extends LitElement {
|
||||
this._unusedEntities = computeUnusedEntities(this.hass, this._config!);
|
||||
}
|
||||
|
||||
private _handleSelectionChanged(ev: any): void {
|
||||
if (ev.detail.selected) {
|
||||
this._selectedEntities.push(ev.detail.entity);
|
||||
private _handleSelectionChanged(ev: CustomEvent): void {
|
||||
const changedSelection = ev.detail as SelectionChangedEvent;
|
||||
const entity = changedSelection.id;
|
||||
if (changedSelection.selected) {
|
||||
this._selectedEntities.push(entity);
|
||||
} else {
|
||||
const index = this._selectedEntities.indexOf(ev.detail.entity);
|
||||
const index = this._selectedEntities.indexOf(entity);
|
||||
if (index !== -1) {
|
||||
this._selectedEntities.splice(index, 1);
|
||||
}
|
||||
@ -155,52 +196,8 @@ export class HuiUnusedEntities extends LitElement {
|
||||
ha-fab.rtl {
|
||||
float: left;
|
||||
}
|
||||
|
||||
div {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.flex-row {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
}
|
||||
.flex-row .flex-cell {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.flex-cell {
|
||||
width: calc(100% / 4);
|
||||
padding: 12px 24px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@media all and (max-width: 767px) {
|
||||
.flex-cell {
|
||||
width: calc(100% / 3);
|
||||
}
|
||||
.flex-cell:first-child {
|
||||
width: 100%;
|
||||
border-bottom: 0;
|
||||
}
|
||||
}
|
||||
@media all and (max-width: 430px) {
|
||||
.flex-cell {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.flex-cell:last-child {
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.flex-cell {
|
||||
width: 100%;
|
||||
}
|
||||
ha-card {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
20
yarn.lock
20
yarn.lock
@ -532,7 +532,7 @@
|
||||
"@material/theme" "^3.1.0"
|
||||
"@material/typography" "^3.1.0"
|
||||
|
||||
"@material/checkbox@^3.0.0":
|
||||
"@material/checkbox@^3.0.0", "@material/checkbox@^3.1.0":
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@material/checkbox/-/checkbox-3.1.0.tgz#bb8eadda0d260e75e8a7479418490eec846a8520"
|
||||
integrity sha512-Rcv6Srj2p3MTsODPLJLgRzGW142ovQTKblkCy9AxABZriQUPRCV/fkJwB0LlqecHgubhnjhtj2Zui0o9jhfu/w==
|
||||
@ -546,6 +546,24 @@
|
||||
"@material/theme" "^3.1.0"
|
||||
tslib "^1.9.3"
|
||||
|
||||
"@material/data-table@^3.1.1":
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@material/data-table/-/data-table-3.1.1.tgz#3e88e2f8ba7d8a56208cbe506b7db342911c5bd3"
|
||||
integrity sha512-6p85gotXObC47KYaEOM1sJKqrXOFkhfHutmrsHMFDLr4B3mCS7XH9KxvBFX4uw9uEZlgiUJBJtbiUIXuHhLIEQ==
|
||||
dependencies:
|
||||
"@material/animation" "^3.1.0"
|
||||
"@material/base" "^3.1.0"
|
||||
"@material/checkbox" "^3.1.0"
|
||||
"@material/dom" "^3.1.0"
|
||||
"@material/elevation" "^3.1.0"
|
||||
"@material/feature-targeting" "^3.1.0"
|
||||
"@material/ripple" "^3.1.0"
|
||||
"@material/rtl" "^3.1.0"
|
||||
"@material/shape" "^3.1.0"
|
||||
"@material/theme" "^3.1.0"
|
||||
"@material/typography" "^3.1.0"
|
||||
tslib "^1.10.0"
|
||||
|
||||
"@material/dom@^3.1.0":
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@material/dom/-/dom-3.1.0.tgz#1e58cad0cd5e1d9d6f6cb07422e327ad34a9d405"
|
||||
|
Loading…
x
Reference in New Issue
Block a user