@spectric/ui 0.0.7 → 0.0.8
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.
- package/dist/components/Button.d.ts +8 -3
- package/dist/components/index.d.ts +2 -0
- package/dist/components/pagination/index.d.ts +1 -0
- package/dist/components/pagination/pagination.d.ts +60 -0
- package/dist/components/table/body.d.ts +44 -0
- package/dist/components/table/cell.d.ts +53 -0
- package/dist/components/table/header.d.ts +42 -0
- package/dist/components/table/index.d.ts +1 -0
- package/dist/components/table/table.d.ts +90 -0
- package/dist/custom-elements.json +103 -4
- package/dist/index.es.js +1439 -1130
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +180 -74
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/Button.ts +12 -4
- package/src/components/button.css.ts +66 -0
- package/src/components/index.ts +3 -1
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pagination/pagination.css +10 -0
- package/src/components/pagination/pagination.ts +133 -0
- package/src/components/table/body.ts +69 -0
- package/src/components/table/cell.ts +117 -0
- package/src/components/table/header.ts +68 -0
- package/src/components/table/index.ts +1 -0
- package/src/components/table/table.css +36 -0
- package/src/components/table/table.ts +131 -0
- package/src/stories/Button.stories.ts +3 -2
- package/src/stories/pagination.stories.ts +63 -0
- package/src/stories/table.stories.ts +74 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { html, LitElement, TemplateResult } from 'lit';
|
|
2
|
+
import "../pagination";
|
|
3
|
+
import "./header"
|
|
4
|
+
import "./body"
|
|
5
|
+
import { customElement, property, } from 'lit/decorators.js';
|
|
6
|
+
import { HTMLElementTagWithEvents, ReactElementWithPropsAndEvents } from '../types';
|
|
7
|
+
import "./table.css"
|
|
8
|
+
export const TableElementTag = "spectric-table"
|
|
9
|
+
import { spreadProps } from '../../utils/spread';
|
|
10
|
+
import { PaginationChangeProps, PaginationProps } from '../pagination';
|
|
11
|
+
import { FilterEvent } from './cell';
|
|
12
|
+
export type { TableProps, TableEvents }
|
|
13
|
+
|
|
14
|
+
export type DomRenderable = HTMLElement | TemplateResult | string | number | null
|
|
15
|
+
|
|
16
|
+
export type ColumnSettings<T> = {
|
|
17
|
+
hidden?: boolean
|
|
18
|
+
sortable?: boolean
|
|
19
|
+
filterable?: boolean
|
|
20
|
+
title?: string
|
|
21
|
+
key?: string
|
|
22
|
+
render?: (row: T, table: TableElement<T>) => DomRenderable
|
|
23
|
+
}
|
|
24
|
+
interface TableProps<T> {
|
|
25
|
+
pagination?: PaginationProps
|
|
26
|
+
columns: ColumnSettings<T>[]
|
|
27
|
+
data: T[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Table Element
|
|
32
|
+
*
|
|
33
|
+
* The table element is a bit more complex and the column settings and data can only be set through the properties
|
|
34
|
+
*
|
|
35
|
+
*
|
|
36
|
+
* React
|
|
37
|
+
*
|
|
38
|
+
* ``` tsx
|
|
39
|
+
* <spectric-table data={[{col1:1}]} columns={[{key:"col1",}]} ></spectric-table>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* Javascript
|
|
43
|
+
*
|
|
44
|
+
* ``` js
|
|
45
|
+
* table = document.createElement("spectric-table")
|
|
46
|
+
* table.data = [{col1:1}]
|
|
47
|
+
* table.columns = [{key:"col1",}]
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* HTML
|
|
51
|
+
*
|
|
52
|
+
* ``` html
|
|
53
|
+
* <spectric-table id="table"></spectric-table>
|
|
54
|
+
* <script>
|
|
55
|
+
* document.querySelector("#table")
|
|
56
|
+
* table.data = [{col1:1}]
|
|
57
|
+
* table.columns = [{key:"col1",}]
|
|
58
|
+
* </script>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
@customElement(TableElementTag)
|
|
62
|
+
export class TableElement<T> extends LitElement implements TableProps<T> {
|
|
63
|
+
@property({ type: Array, attribute: false })
|
|
64
|
+
data: T[] = [];
|
|
65
|
+
@property({ type: Object, attribute: false })
|
|
66
|
+
pagination?: PaginationProps | undefined;
|
|
67
|
+
@property({ attribute: false })
|
|
68
|
+
columns: ColumnSettings<T>[] = [];
|
|
69
|
+
private _handlePaginationChange = (e: CustomEvent<PaginationChangeProps>) => {
|
|
70
|
+
e.preventDefault()
|
|
71
|
+
e.stopPropagation()
|
|
72
|
+
if (this.pagination) {
|
|
73
|
+
this.pagination.size
|
|
74
|
+
this.pagination = { ...this.pagination, ...e.detail }
|
|
75
|
+
}
|
|
76
|
+
this._emitChange()
|
|
77
|
+
};
|
|
78
|
+
private _emitChange = () => {
|
|
79
|
+
let { pagination } = this
|
|
80
|
+
this.dispatchEvent(new CustomEvent<{ pagination?: PaginationChangeProps }>("change", { detail: { pagination } }))
|
|
81
|
+
}
|
|
82
|
+
//@ts-ignore
|
|
83
|
+
private __DO_NOT_USE_filter = () => {
|
|
84
|
+
//This is only here to document events that bubble up from lower components
|
|
85
|
+
this.dispatchEvent(new CustomEvent<FilterEvent<T>>("filter"))
|
|
86
|
+
}
|
|
87
|
+
protected createRenderRoot(): HTMLElement | DocumentFragment {
|
|
88
|
+
return this
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected render(): unknown {
|
|
92
|
+
let columns = this.columns.filter(column => !column.hidden)
|
|
93
|
+
return html`
|
|
94
|
+
<div role="table">
|
|
95
|
+
<spectric-table-header .columns=${columns}></spectric-table-header>
|
|
96
|
+
<spectric-table-body .columns=${columns} .data=${this.data} .table=${this}></spectric-table-body>
|
|
97
|
+
</div>
|
|
98
|
+
${this.pagination ? html`<spectric-pagination ${spreadProps(this.pagination)} @change=${this._handlePaginationChange}></spectric-pagination>` : null}
|
|
99
|
+
`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface TableEvents {
|
|
104
|
+
'change': (event: CustomEvent<{ pagination: PaginationChangeProps }>) => void;
|
|
105
|
+
'filter': (event: CustomEvent<FilterEvent<any>>) => void;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
declare global {
|
|
109
|
+
interface HTMLElementTagNameMap {
|
|
110
|
+
[TableElementTag]: HTMLElementTagWithEvents<TableElement<any>, TableEvents>
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
namespace JSX {
|
|
114
|
+
interface IntrinsicElements {
|
|
115
|
+
/**
|
|
116
|
+
* @see {@link DialogElement}
|
|
117
|
+
*/
|
|
118
|
+
[TableElementTag]: ReactElementWithPropsAndEvents<TableElement<any>, TableProps<any>, TableEvents>;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
namespace React {
|
|
122
|
+
namespace JSX {
|
|
123
|
+
interface IntrinsicElements {
|
|
124
|
+
/**
|
|
125
|
+
* @see {@link DialogElement}
|
|
126
|
+
*/
|
|
127
|
+
[TableElementTag]: ReactElementWithPropsAndEvents<TableElement<any>, TableProps<any>, TableEvents>
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -13,6 +13,7 @@ const meta = {
|
|
|
13
13
|
<spectric-button
|
|
14
14
|
?disabled=${args.disabled}
|
|
15
15
|
?danger=${args.danger}
|
|
16
|
+
?icon=${args.icon}
|
|
16
17
|
variant=${ifDefined(args.variant)}
|
|
17
18
|
size=${ifDefined(args.size)}
|
|
18
19
|
backgroundColor=${ifDefined(args.backgroundColor)}
|
|
@@ -31,11 +32,11 @@ const meta = {
|
|
|
31
32
|
backgroundColor: { control: 'color', description: "sets the background color for the element" },
|
|
32
33
|
size: {
|
|
33
34
|
control: { type: 'select' },
|
|
34
|
-
options:
|
|
35
|
+
options: Object.values(ButtonSizes),
|
|
35
36
|
},
|
|
36
37
|
variant: {
|
|
37
38
|
control: { type: 'select' },
|
|
38
|
-
options:
|
|
39
|
+
options: Object.values(ButtonVariants),
|
|
39
40
|
},
|
|
40
41
|
disabled: {
|
|
41
42
|
control: { type: 'boolean' },
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/web-components";
|
|
2
|
+
|
|
3
|
+
import { PaginationChangeProps, type PaginationProps as Props } from "../components/pagination/pagination";
|
|
4
|
+
import { html } from "lit";
|
|
5
|
+
import '../components';
|
|
6
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
7
|
+
import { useArgs } from "@storybook/client-api";
|
|
8
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
9
|
+
const meta = {
|
|
10
|
+
title: "UI/Pagination",
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
component: "spectric-pagination",
|
|
13
|
+
render: (args) => {
|
|
14
|
+
const [_, updateArgs] = useArgs();
|
|
15
|
+
|
|
16
|
+
return html`
|
|
17
|
+
<spectric-pagination
|
|
18
|
+
page=${ifDefined(args.page)}
|
|
19
|
+
pageSize=${ifDefined(args.pageSize)}
|
|
20
|
+
totalItems=${ifDefined(args.totalItems)}
|
|
21
|
+
size=${args.size}
|
|
22
|
+
@change=${(e: CustomEvent<PaginationChangeProps>) => {
|
|
23
|
+
updateArgs({ ...e.detail });
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
</spectric-pagination>
|
|
27
|
+
`;
|
|
28
|
+
},
|
|
29
|
+
argTypes: {
|
|
30
|
+
size: {
|
|
31
|
+
control: { type: 'select' },
|
|
32
|
+
options: ['small', 'medium', 'large'],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
args: {
|
|
36
|
+
page: 1,
|
|
37
|
+
pageSize: 3,
|
|
38
|
+
size: "small",
|
|
39
|
+
totalItems: 103,
|
|
40
|
+
},
|
|
41
|
+
} satisfies Meta<Props>;
|
|
42
|
+
|
|
43
|
+
export default meta;
|
|
44
|
+
type Story = StoryObj<Props>;
|
|
45
|
+
|
|
46
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
47
|
+
export const Basic: Story = {
|
|
48
|
+
args: {
|
|
49
|
+
page: 1,
|
|
50
|
+
pageSize: 3,
|
|
51
|
+
totalItems: 103,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* When the total items is unknown pagination will only shows page size
|
|
56
|
+
*/
|
|
57
|
+
export const NoTotalItems: Story = {
|
|
58
|
+
args: {
|
|
59
|
+
page: 1,
|
|
60
|
+
pageSize: 3,
|
|
61
|
+
totalItems: undefined,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/web-components";
|
|
2
|
+
|
|
3
|
+
import { PaginationChangeProps, type TableProps as Props } from "../components/";
|
|
4
|
+
import { html } from "lit";
|
|
5
|
+
import '../components';
|
|
6
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
7
|
+
import { useArgs } from "@storybook/client-api";
|
|
8
|
+
import { FilterEvent } from "../components/table/cell";
|
|
9
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
10
|
+
type TestData = {
|
|
11
|
+
name: string
|
|
12
|
+
company: string
|
|
13
|
+
contact: string
|
|
14
|
+
country: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const data: TestData[] = [
|
|
18
|
+
{ name: "Sean", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
19
|
+
{ name: "Kipp", company: "Spectric Labs", "contact": "123-4567", "country": "UK" },
|
|
20
|
+
{ name: "Adam", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
21
|
+
{ name: "Chris", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
22
|
+
{ name: "Michael", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
23
|
+
{ name: "Matt", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
24
|
+
{ name: "Grant", company: "Spectric Labs", "contact": "123-4567", "country": "UK" },]
|
|
25
|
+
const meta = {
|
|
26
|
+
title: "UI/Table",
|
|
27
|
+
tags: ["autodocs"],
|
|
28
|
+
component: "spectric-table",
|
|
29
|
+
render: (args) => {
|
|
30
|
+
const [_, updateArgs] = useArgs();
|
|
31
|
+
|
|
32
|
+
return html`
|
|
33
|
+
<spectric-table
|
|
34
|
+
.pagination=${args.pagination}
|
|
35
|
+
.columns=${args.columns}
|
|
36
|
+
.data=${!args.pagination ? data : data.slice((args.pagination.page - 1) * args.pagination.pageSize, (args.pagination.page) * args.pagination.pageSize)}
|
|
37
|
+
@filter=${(e: CustomEvent<FilterEvent<any>>) => {
|
|
38
|
+
alert(`filter ${e.detail.include ? "for" : "out"} event value ${e.detail.value}`)
|
|
39
|
+
}}
|
|
40
|
+
@change=${(e: CustomEvent<PaginationChangeProps>) => {
|
|
41
|
+
console.log(e)
|
|
42
|
+
updateArgs({ ...e.detail });
|
|
43
|
+
}}
|
|
44
|
+
>
|
|
45
|
+
</spectric-table>
|
|
46
|
+
`;
|
|
47
|
+
},
|
|
48
|
+
argTypes: {
|
|
49
|
+
},
|
|
50
|
+
args: {
|
|
51
|
+
pagination: {
|
|
52
|
+
page: 1,
|
|
53
|
+
pageSize: 3,
|
|
54
|
+
size: "small",
|
|
55
|
+
totalItems: data.length,
|
|
56
|
+
},
|
|
57
|
+
columns: [{ "title": "Company", key: "company" }, { "title": "Name", key: "name" }, { "title": "Contact", key: "contact" }, { "title": "Country", key: "country", filterable: true }]
|
|
58
|
+
},
|
|
59
|
+
} satisfies Meta<Props<TestData>>;
|
|
60
|
+
|
|
61
|
+
export default meta;
|
|
62
|
+
type Story = StoryObj<Props<TestData>>;
|
|
63
|
+
|
|
64
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
65
|
+
export const Basic: Story = {
|
|
66
|
+
args: {
|
|
67
|
+
pagination: {
|
|
68
|
+
page: 1,
|
|
69
|
+
pageSize: 3,
|
|
70
|
+
size: "small",
|
|
71
|
+
totalItems: data.length,
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|