|
1 |
| -<svelte:options runes={false} /> |
| 1 | +<svelte:options runes /> |
2 | 2 |
|
3 | 3 | {#if header}
|
4 | 4 | <th
|
|
22 | 22 | : 'none'
|
23 | 23 | : undefined}
|
24 | 24 | {...internalAttrs}
|
25 |
| - {...$$restProps} |
| 25 | + {...restProps} |
26 | 26 | onchange={(e) => {
|
27 | 27 | if (checkbox) {
|
28 | 28 | notifyHeaderChange(e);
|
29 | 29 | }
|
30 |
| - $$restProps.onchange?.(e); |
| 30 | + restProps.onchange?.(e); |
31 | 31 | }}
|
32 | 32 | >{#if sortable}
|
33 | 33 | <div class="mdc-data-table__header-cell-wrapper">
|
34 |
| - <slot /> |
| 34 | + {@render children?.()} |
35 | 35 | <div
|
36 | 36 | class="mdc-data-table__sort-status-label"
|
37 | 37 | aria-hidden="true"
|
|
44 | 44 | : ''}
|
45 | 45 | </div>
|
46 | 46 | </div>
|
47 |
| - {:else}<slot />{/if}</th |
| 47 | + {:else}{@render children?.()}{/if}</th |
48 | 48 | >
|
49 | 49 | {:else}
|
50 | 50 | <td
|
|
58 | 58 | ...internalClasses,
|
59 | 59 | })}
|
60 | 60 | {...internalAttrs}
|
61 |
| - {...$$restProps} |
| 61 | + {...restProps} |
62 | 62 | onchange={(e) => {
|
63 | 63 | if (checkbox) {
|
64 | 64 | notifyBodyChange(e);
|
65 | 65 | }
|
66 |
| - $$restProps.onchange?.(e); |
67 |
| - }}><slot /></td |
| 66 | + restProps.onchange?.(e); |
| 67 | + }}>{@render children?.()}</td |
68 | 68 | >
|
69 | 69 | {/if}
|
70 | 70 |
|
|
74 | 74 |
|
75 | 75 | <script lang="ts">
|
76 | 76 | import type { SortValue } from '@material/data-table';
|
| 77 | + import type { Snippet } from 'svelte'; |
77 | 78 | import { onMount, getContext, setContext } from 'svelte';
|
78 | 79 | import type { Writable } from 'svelte/store';
|
79 | 80 | import type { SmuiAttrs } from '@smui/common';
|
|
82 | 83 |
|
83 | 84 | import type { SMUIDataTableCellAccessor } from './Cell.types.js';
|
84 | 85 |
|
| 86 | + let header = getContext<boolean>('SMUI:data-table:row:header'); |
| 87 | +
|
85 | 88 | type OwnProps = {
|
| 89 | + /** |
| 90 | + * An array of Action or [Action, ActionProps] to be applied to the element. |
| 91 | + */ |
86 | 92 | use?: ActionArray;
|
| 93 | + /** |
| 94 | + * A space separated list of CSS classes. |
| 95 | + */ |
87 | 96 | class?: string;
|
| 97 | + /** |
| 98 | + * Whether to apply numeric column styling. |
| 99 | + */ |
88 | 100 | numeric?: boolean;
|
| 101 | + /** |
| 102 | + * Whether this cell contains the checkbox to select. |
| 103 | + */ |
89 | 104 | checkbox?: boolean;
|
| 105 | + /** |
| 106 | + * The column ID for the column this cell is a header for. |
| 107 | + * |
| 108 | + * You only need this on sortable columns and you only need to put it on the |
| 109 | + * cell in the header. |
| 110 | + */ |
90 | 111 | columnId?: string;
|
| 112 | + /** |
| 113 | + * Whether sorting is enabled on the column this cell is a header for. |
| 114 | + * |
| 115 | + * This will default to true if the data table is sortable. |
| 116 | + */ |
91 | 117 | sortable?: boolean;
|
92 |
| - }; |
93 |
| - type $$Props = SmuiAttrs<'th', keyof OwnProps> & |
94 |
| - SmuiAttrs<'td', keyof OwnProps> & |
95 |
| - OwnProps; |
96 | 118 |
|
97 |
| - let header = getContext<boolean>('SMUI:data-table:row:header'); |
98 |
| -
|
99 |
| - // Remember to update $$Props if you add/remove/rename props. |
100 |
| - export let use: ActionArray = []; |
101 |
| - let className = ''; |
102 |
| - export { className as class }; |
103 |
| - export let numeric = false; |
104 |
| - export let checkbox = false; |
105 |
| - export let columnId = header |
106 |
| - ? 'SMUI-data-table-column-' + counter++ |
107 |
| - : 'SMUI-data-table-unused'; |
108 |
| - export let sortable = getContext<boolean>('SMUI:data-table:sortable'); |
| 119 | + children?: Snippet; |
| 120 | + }; |
| 121 | + let { |
| 122 | + use = [], |
| 123 | + class: className = '', |
| 124 | + numeric = false, |
| 125 | + checkbox = false, |
| 126 | + columnId = header |
| 127 | + ? 'SMUI-data-table-column-' + counter++ |
| 128 | + : 'SMUI-data-table-unused', |
| 129 | + sortable = getContext<boolean>('SMUI:data-table:sortable'), |
| 130 | + children, |
| 131 | + ...restProps |
| 132 | + }: OwnProps & |
| 133 | + SmuiAttrs<'th', keyof OwnProps> & |
| 134 | + SmuiAttrs<'td', keyof OwnProps> = $props(); |
109 | 135 |
|
110 | 136 | let element: HTMLTableCellElement;
|
111 |
| - let internalClasses: { [k: string]: boolean } = {}; |
112 |
| - let internalAttrs: { [k: string]: string | undefined } = {}; |
| 137 | + let internalClasses: { [k: string]: boolean } = $state({}); |
| 138 | + let internalAttrs: { [k: string]: string | undefined } = $state({}); |
113 | 139 | let sort = getContext<Writable<string | null>>('SMUI:data-table:sort');
|
114 | 140 | let sortDirection = getContext<Writable<SortValue>>(
|
115 | 141 | 'SMUI:data-table:sortDirection',
|
|
0 commit comments