2020-02-17 18:01:57 +01:00
|
|
|
<script>
|
2020-02-18 16:05:09 +01:00
|
|
|
import { getContext } from "svelte";
|
2020-02-24 16:59:54 +01:00
|
|
|
import ClassBuilder from "../ClassBuilder.js"
|
|
|
|
|
2020-02-18 16:05:09 +01:00
|
|
|
export let onSelect = () => {};
|
|
|
|
export let isHeader = false;
|
2020-02-20 18:06:50 +01:00
|
|
|
|
|
|
|
export let _bb
|
|
|
|
|
2020-02-18 16:05:09 +01:00
|
|
|
let row = null;
|
|
|
|
let selected = false;
|
2020-02-17 18:01:57 +01:00
|
|
|
|
2020-02-24 16:59:54 +01:00
|
|
|
const cb = new ClassBuilder("data-table")
|
2020-02-17 18:01:57 +01:00
|
|
|
|
2020-02-18 16:05:09 +01:00
|
|
|
let elementName = isHeader ? "header-row" : "row";
|
|
|
|
let modifiers = {};
|
2020-02-17 18:01:57 +01:00
|
|
|
|
2020-02-18 16:05:09 +01:00
|
|
|
$: modifiers = { selected };
|
|
|
|
$: props = { modifiers };
|
|
|
|
$: rowClass = cb.build({ elementName, props });
|
2020-02-20 18:06:50 +01:00
|
|
|
$: row && _bb.attachChildren(row)
|
|
|
|
|
2020-02-18 16:05:09 +01:00
|
|
|
function rowSelected() {
|
|
|
|
selected = !selected;
|
|
|
|
onSelect();
|
|
|
|
}
|
2020-02-17 18:01:57 +01:00
|
|
|
</script>
|
|
|
|
|
2020-02-18 16:05:09 +01:00
|
|
|
<tr bind:this={row} class={rowClass} on:click={rowSelected}>
|
2020-02-17 18:01:57 +01:00
|
|
|
<slot />
|
|
|
|
</tr>
|