carbon-custom-elements
Version:
A Carbon Design System variant that's as easy to use as native HTML elements, with no framework tax, no framework silo.
1 lines • 2.79 kB
Source Map (JSON)
{"version":3,"sources":["components/data-table/table.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAiC,UAAU,EAAE,MAAM,aAAa,CAAC;AAMxE;;GAEG;AACH,oBAAY,kBAAkB;IAC5B;;OAEG;IACH,OAAO,KAAK;IAEZ;;OAEG;IACH,KAAK,UAAU;CAChB;AAED;;GAEG;AACH,oBAAY,UAAU;IACpB;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,KAAK,UAAU;IAEf;;OAEG;IACH,OAAO,KAAK;IAEZ;;OAEG;IACH,IAAI,SAAS;CACd;AAED;;;GAGG;AACH,cACM,OAAQ,SAAQ,UAAU;IAC9B;;OAEG;IAEH,IAAI,aAAsB;IAE1B;;OAEG;IAEH,IAAI,UAAS;IAEb,iBAAiB;IAOjB,OAAO,CAAC,iBAAiB,KAAA;IASzB,MAAM;IAMN;;OAEG;IACH,MAAM,KAAK,sBAAsB,WAEhC;IAED,MAAM,CAAC,MAAM,MAAU;CACxB;AAED,eAAe,OAAO,CAAC","file":"table.d.ts","sourcesContent":["/**\n * @license\n *\n * Copyright IBM Corp. 2019, 2020\n *\n * This source code is licensed under the Apache-2.0 license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport settings from 'carbon-components/es/globals/js/settings';\nimport { html, property, customElement, LitElement } from 'lit-element';\nimport { forEach } from '../../globals/internal/collection-helpers';\nimport styles from './data-table.scss';\n\nconst { prefix } = settings;\n\n/**\n * Table color scheme.\n */\nexport enum TABLE_COLOR_SCHEME {\n /**\n * Regular color scheme.\n */\n REGULAR = '',\n\n /**\n * Color scheme with zebra stripe.\n */\n ZEBRA = 'zebra',\n}\n\n/**\n * Table size.\n */\nexport enum TABLE_SIZE {\n /**\n * Compact size.\n */\n COMPACT = 'compact',\n\n /**\n * Short size.\n */\n SHORT = 'short',\n\n /**\n * Regular size.\n */\n REGULAR = '',\n\n /**\n * Tall size.\n */\n TALL = 'tall',\n}\n\n/**\n * Data table.\n * @element bx-table\n */\n@customElement(`${prefix}-table`)\nclass BXTable extends LitElement {\n /**\n * The table size.\n */\n @property({ reflect: true })\n size = TABLE_SIZE.REGULAR;\n\n /**\n * `true` if this table should support sorting.\n */\n @property({ type: Boolean, reflect: true })\n sort = false;\n\n connectedCallback() {\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'table');\n }\n super.connectedCallback();\n }\n\n updated(changedProperties) {\n if (changedProperties.has('size')) {\n // Propagate `size` attribute to descendants until `:host-context()` gets supported in all major browsers\n forEach(this.querySelectorAll((this.constructor as typeof BXTable).selectorRowsWithHeader), elem => {\n elem.setAttribute('size', this.size);\n });\n }\n }\n\n render() {\n return html`\n <slot></slot>\n `;\n }\n\n /**\n * The CSS selector to find the rows, including header rows.\n */\n static get selectorRowsWithHeader() {\n return `${prefix}-table-header-row,${prefix}-table-row`;\n }\n\n static styles = styles;\n}\n\nexport default BXTable;\n"]}