-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
255 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
import Generics from "./output"; | ||
</script> | ||
|
||
<Generics | ||
headers={[ | ||
{ | ||
key: "name", | ||
value: "Name", | ||
}, | ||
{ | ||
key: "port", | ||
value: "Port", | ||
}, | ||
]} | ||
rows={[ | ||
{ id: 1, name: "Name 1", port: 3000 }, | ||
{ id: 2, name: "Name 2", port: 3000 }, | ||
{ id: 3, name: "Name 3", port: 3000 }, | ||
]} | ||
let:rows | ||
> | ||
{#each rows as row} | ||
{row.name} | ||
{/each} | ||
</Generics> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script> | ||
/** | ||
* @typedef {{ id: string | number; [key: string]: any; }} DataTableRow | ||
* @typedef {Exclude<keyof Row, "id">} DataTableKey<Row> | ||
* @typedef {{ key: DataTableKey<Row>; value: string; }} DataTableHeader<Row> | ||
* @template {DataTableRow} Row | ||
* @generics {Row extends DataTableRow = DataTableRow} Row | ||
*/ | ||
/** @type {ReadonlyArray<DataTableHeader<Row>>} */ | ||
export let headers = []; | ||
/** @type {ReadonlyArray<Row>} */ | ||
export let rows = []; | ||
</script> | ||
|
||
<slot {rows} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { SvelteComponentTyped } from "svelte"; | ||
|
||
export interface DataTableRow { | ||
id: string | number; | ||
[key: string]: any; | ||
} | ||
|
||
export type DataTableKey<Row> = Exclude<keyof Row, "id">; | ||
|
||
export interface DataTableHeader<Row> { | ||
key: DataTableKey<Row>; | ||
value: string; | ||
} | ||
|
||
export interface GenericsProps<Row> { | ||
/** | ||
* @default [] | ||
*/ | ||
headers?: ReadonlyArray<DataTableHeader<Row>>; | ||
|
||
/** | ||
* @default [] | ||
*/ | ||
rows?: ReadonlyArray<Row>; | ||
} | ||
|
||
export default class Generics<Row extends DataTableRow = DataTableRow> extends SvelteComponentTyped< | ||
GenericsProps<Row>, | ||
Record<string, any>, | ||
{ default: { rows: ReadonlyArray<Row> } } | ||
> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"props": [ | ||
{ | ||
"name": "headers", | ||
"kind": "let", | ||
"type": "ReadonlyArray<DataTableHeader<Row>>", | ||
"value": "[]", | ||
"isFunction": false, | ||
"isFunctionDeclaration": false, | ||
"isRequired": false, | ||
"constant": false, | ||
"reactive": false | ||
}, | ||
{ | ||
"name": "rows", | ||
"kind": "let", | ||
"type": "ReadonlyArray<Row>", | ||
"value": "[]", | ||
"isFunction": false, | ||
"isFunctionDeclaration": false, | ||
"isRequired": false, | ||
"constant": false, | ||
"reactive": false | ||
} | ||
], | ||
"moduleExports": [], | ||
"slots": [ | ||
{ | ||
"name": "__default__", | ||
"default": true, | ||
"slot_props": "{ rows: ReadonlyArray<Row> }" | ||
} | ||
], | ||
"events": [], | ||
"typedefs": [ | ||
{ | ||
"type": "{ id: string | number; [key: string]: any; }", | ||
"name": "DataTableRow", | ||
"ts": "interface DataTableRow { id: string | number; [key: string]: any; }" | ||
}, | ||
{ | ||
"type": "Exclude<keyof Row, \"id\">", | ||
"name": "DataTableKey<Row>", | ||
"ts": "type DataTableKey<Row> = Exclude<keyof Row, \"id\">" | ||
}, | ||
{ | ||
"type": "{ key: DataTableKey<Row>; value: string; }", | ||
"name": "DataTableHeader<Row>", | ||
"ts": "interface DataTableHeader<Row> { key: DataTableKey<Row>; value: string; }" | ||
} | ||
], | ||
"generics": [ | ||
"Row", | ||
"Row extends DataTableRow = DataTableRow" | ||
] | ||
} |