@hypericon/mico 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import m from "mithril";
|
|
2
2
|
export type TableCellDisplayFn<T> = (item: T, index: number) => m.Children;
|
|
3
|
+
export interface TableColumnDefinitionOptions {
|
|
4
|
+
/** CSS classes to apply to all the cells in the column, including the header */
|
|
5
|
+
class?: string;
|
|
6
|
+
/** CSS stylees to apply to all the cells in the column, including the header */
|
|
7
|
+
style?: string;
|
|
8
|
+
}
|
|
3
9
|
export type TableColumnDefinition<T> = {
|
|
4
10
|
header: string | m.Vnode<any, any>;
|
|
5
11
|
cell: TableCellDisplayFn<T>;
|
|
12
|
+
/** Optional settings to tweak the column's behaviour */
|
|
13
|
+
options?: TableColumnDefinitionOptions;
|
|
6
14
|
};
|
|
7
15
|
export interface TableAttrs<T> {
|
|
8
16
|
/** The list of items to display as rows */
|
|
@@ -25,7 +33,9 @@ export type TableColumnDefinitionFn<T> = (
|
|
|
25
33
|
/** The label or other element to display in the header */
|
|
26
34
|
header: string | m.Vnode<any, any>,
|
|
27
35
|
/** Function defining how to display a cell in the column using the given row item */
|
|
28
|
-
cell: TableCellDisplayFn<T
|
|
36
|
+
cell: TableCellDisplayFn<T>,
|
|
37
|
+
/** Optional settings to tweak the column's behaviour */
|
|
38
|
+
options?: TableColumnDefinitionOptions) => TableColumnDefinition<T>;
|
|
29
39
|
/**
|
|
30
40
|
* Build a typed Table component which includes type checking for column definitions
|
|
31
41
|
* @example
|
|
@@ -38,7 +38,11 @@ exports.Table = {
|
|
|
38
38
|
(0, mithril_1.default)("thead", [
|
|
39
39
|
(0, mithril_1.default)("tr", [
|
|
40
40
|
attrs.columns.map(col => {
|
|
41
|
-
|
|
41
|
+
var _a, _b;
|
|
42
|
+
return (0, mithril_1.default)("th", {
|
|
43
|
+
class: (_a = col.options) === null || _a === void 0 ? void 0 : _a.class,
|
|
44
|
+
style: (_b = col.options) === null || _b === void 0 ? void 0 : _b.style,
|
|
45
|
+
}, [
|
|
42
46
|
col.header,
|
|
43
47
|
]);
|
|
44
48
|
}),
|
|
@@ -48,9 +52,12 @@ exports.Table = {
|
|
|
48
52
|
attrs.data.map(item => {
|
|
49
53
|
return (0, mithril_1.default)("tr", [
|
|
50
54
|
attrs.columns.map((col, index) => {
|
|
51
|
-
var _a;
|
|
52
|
-
return (0, mithril_1.default)("td",
|
|
53
|
-
(_a = col.
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
return (0, mithril_1.default)("td", {
|
|
57
|
+
class: (_a = col.options) === null || _a === void 0 ? void 0 : _a.class,
|
|
58
|
+
style: (_b = col.options) === null || _b === void 0 ? void 0 : _b.style,
|
|
59
|
+
}, [
|
|
60
|
+
(_c = col.cell) === null || _c === void 0 ? void 0 : _c.call(col, item, index),
|
|
54
61
|
]);
|
|
55
62
|
}),
|
|
56
63
|
]);
|