-
Notifications
You must be signed in to change notification settings - Fork 172
/
Column.svelte
73 lines (60 loc) · 1.42 KB
/
Column.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script context="module">
export const evidenceInclude = true;
</script>
<script>
import { getContext } from 'svelte';
import { propKey, strictBuild } from './context';
let props = getContext(propKey);
let error;
export let id;
// Simple check of column name in dataset. Should be replaced with robust error handling in the future:
$: checkColumnName();
/**
* Check column name and handle error if doesn't exist
*/
function checkColumnName() {
try {
if (!Object.keys($props.data[0]).includes(id)) {
error = 'Error in table: ' + id + ' does not exist in the dataset';
throw new Error(error);
}
} catch (e) {
error = e.message;
if (strictBuild) {
throw error;
}
}
}
export let title = undefined;
export let align = undefined;
if (align === 'centre') {
align = 'center';
}
export let wrap = false;
// COLUMN CONTENT TYPES:
export let contentType = undefined;
// Images:
export let height = undefined;
export let width = undefined;
export let alt = undefined;
// Links:
export let openInNewTab = false;
openInNewTab = openInNewTab === 'true' || openInNewTab === true;
export let linkLabel = undefined;
let options = {
id: id,
title: title,
align: align,
wrap: wrap,
contentType: contentType,
height: height,
width: width,
alt: alt,
openInNewTab: openInNewTab,
linkLabel: linkLabel
};
props.update((d) => {
d.columns.push(options);
return d;
});
</script>