@spectric/ui 0.0.9 → 0.0.10
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 +2 -2
- package/dist/components/query_bar/QueryBar.d.ts +4 -4
- package/dist/components/table/table.d.ts +2 -28
- package/dist/custom-elements.json +1 -1
- package/dist/index.es.js +636 -632
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +53 -53
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Button.ts +2 -2
- package/src/components/query_bar/QueryBar.ts +6 -6
- package/src/components/table/cell.ts +14 -3
- package/src/components/table/table.ts +2 -28
- package/src/stories/fixtures/data.ts +12 -10
- package/src/stories/table.stories.ts +2 -8
package/package.json
CHANGED
package/src/components/Button.ts
CHANGED
|
@@ -25,14 +25,14 @@ export enum ButtonVariants {
|
|
|
25
25
|
type ButtonVariantsTypes = `${ButtonVariants}`
|
|
26
26
|
export interface ButtonProps {
|
|
27
27
|
/** Is this the principal call to action on the page? */
|
|
28
|
-
variant
|
|
28
|
+
variant?: ButtonVariantsTypes;
|
|
29
29
|
/** What background color to use */
|
|
30
30
|
backgroundColor?: string;
|
|
31
31
|
/** How large should the button be? */
|
|
32
32
|
size: ButtonSizesTypes;
|
|
33
33
|
label?: string,
|
|
34
34
|
/* should the button be disabled*/
|
|
35
|
-
disabled
|
|
35
|
+
disabled?: boolean;
|
|
36
36
|
danger?: boolean;
|
|
37
37
|
icon?: boolean
|
|
38
38
|
tooltip?: DomRenderable
|
|
@@ -39,7 +39,7 @@ export interface IQueryProps {
|
|
|
39
39
|
/**
|
|
40
40
|
* The output of the query in a specific format
|
|
41
41
|
*/
|
|
42
|
-
outputLanguage
|
|
42
|
+
outputLanguage?: SupportedLanguagesTypes;
|
|
43
43
|
/**
|
|
44
44
|
* The output of the query
|
|
45
45
|
*/
|
|
@@ -47,16 +47,16 @@ export interface IQueryProps {
|
|
|
47
47
|
/**
|
|
48
48
|
* Fields that are used for the auto complete
|
|
49
49
|
*/
|
|
50
|
-
fields
|
|
50
|
+
fields?: FieldTypes[];
|
|
51
51
|
/**
|
|
52
52
|
* Callback that will provide values for specific fields
|
|
53
53
|
*/
|
|
54
|
-
getValuesForField
|
|
54
|
+
getValuesForField?: (field: string, text: string) => Promise<string[]>;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Input placeholder
|
|
58
58
|
*/
|
|
59
|
-
placeholder
|
|
59
|
+
placeholder?: string;
|
|
60
60
|
}
|
|
61
61
|
type LabelValue = {
|
|
62
62
|
label?: string;
|
|
@@ -133,7 +133,7 @@ export class SpectricQuery extends LitElement implements IQueryProps {
|
|
|
133
133
|
protected _input!: SpectricInput;
|
|
134
134
|
_parseQuery = (e: InputEvent | undefined = undefined) => {
|
|
135
135
|
let ast;
|
|
136
|
-
if(e && e?.currentTarget && (e.currentTarget as HTMLInputElement).value){
|
|
136
|
+
if (e && e?.currentTarget && (e.currentTarget as HTMLInputElement).value) {
|
|
137
137
|
this.value = (e.currentTarget as HTMLInputElement).value
|
|
138
138
|
}
|
|
139
139
|
if (this.value == "") {
|
|
@@ -293,7 +293,7 @@ export class SpectricQuery extends LitElement implements IQueryProps {
|
|
|
293
293
|
let value = await completion.onSelect()
|
|
294
294
|
if (value !== undefined) {
|
|
295
295
|
this.value += value
|
|
296
|
-
setTimeout(()=>{this._input.focus();})
|
|
296
|
+
setTimeout(() => { this._input.focus(); })
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
this.completionIndex = 0;
|
|
@@ -43,7 +43,7 @@ export class TableCellElement<T> extends LitElement implements CellProps<T> {
|
|
|
43
43
|
_handleFilterOut = () => {
|
|
44
44
|
let value = undefined;
|
|
45
45
|
if (this.column.key && typeof this.row === "object") {
|
|
46
|
-
value = (this.row as Record<any, any
|
|
46
|
+
value = getValue(this.row as Record<any, any>, this.column.key)
|
|
47
47
|
}
|
|
48
48
|
this.dispatchEvent(new CustomEvent<FilterEvent<T>>("filter", {
|
|
49
49
|
composed: true,
|
|
@@ -59,7 +59,7 @@ export class TableCellElement<T> extends LitElement implements CellProps<T> {
|
|
|
59
59
|
_handleFilterFor = () => {
|
|
60
60
|
let value = undefined;
|
|
61
61
|
if (this.column.key && typeof this.row === "object") {
|
|
62
|
-
value = (this.row as Record<any, any
|
|
62
|
+
value = getValue(this.row as Record<any, any>, this.column.key)
|
|
63
63
|
}
|
|
64
64
|
this.dispatchEvent(new CustomEvent<FilterEvent<T>>("filter", {
|
|
65
65
|
composed: true,
|
|
@@ -77,7 +77,8 @@ export class TableCellElement<T> extends LitElement implements CellProps<T> {
|
|
|
77
77
|
if (this.column.render) {
|
|
78
78
|
rendered = this.column.render(this.row, this.table)
|
|
79
79
|
} else if (this.column.key && typeof this.row === 'object') {
|
|
80
|
-
|
|
80
|
+
|
|
81
|
+
rendered = getValue(this.row as any, this.column.key)
|
|
81
82
|
} else {
|
|
82
83
|
rendered = html`error`
|
|
83
84
|
}
|
|
@@ -131,3 +132,13 @@ declare global {
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
const getValue = (context: Record<string, any>, key: string) => {
|
|
138
|
+
let path = key.split(".")
|
|
139
|
+
let value = context[path[0]]
|
|
140
|
+
if (path.length > 1) {
|
|
141
|
+
value = getValue(value, path.slice(1).join("."))
|
|
142
|
+
}
|
|
143
|
+
return value
|
|
144
|
+
}
|
|
@@ -35,35 +35,9 @@ type DomEvent<T> = Event & {
|
|
|
35
35
|
target: T
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
38
|
+
* React example
|
|
39
|
+
* <iframe width="100%" height="400px" src="https://stackblitz.com/edit/react-ts-2ue7azag?ctl=1&embed=1&file=App.tsx&hideExplorer=1&hideNavigation=1"/>
|
|
39
40
|
*
|
|
40
|
-
* The table element is a bit more complex and the column settings and data can only be set through the properties
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* React
|
|
44
|
-
*
|
|
45
|
-
* ``` tsx
|
|
46
|
-
* <spectric-table data={[{col1:1}]} columns={[{key:"col1",}]} ></spectric-table>
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* Javascript
|
|
50
|
-
*
|
|
51
|
-
* ``` js
|
|
52
|
-
* table = document.createElement("spectric-table")
|
|
53
|
-
* table.data = [{col1:1}]
|
|
54
|
-
* table.columns = [{key:"col1",}]
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* HTML
|
|
58
|
-
*
|
|
59
|
-
* ``` html
|
|
60
|
-
* <spectric-table id="table"></spectric-table>
|
|
61
|
-
* <script>
|
|
62
|
-
* document.querySelector("#table")
|
|
63
|
-
* table.data = [{col1:1}]
|
|
64
|
-
* table.columns = [{key:"col1",}]
|
|
65
|
-
* </script>
|
|
66
|
-
* ```
|
|
67
41
|
*/
|
|
68
42
|
@customElement(TableElementTag)
|
|
69
43
|
export class TableElement<T> extends LitElement implements TableProps<T> {
|
|
@@ -37,15 +37,17 @@ type TestData = {
|
|
|
37
37
|
name: string
|
|
38
38
|
company: string
|
|
39
39
|
contact: string
|
|
40
|
-
|
|
40
|
+
location: {
|
|
41
|
+
country: string,
|
|
42
|
+
state: string
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
|
-
|
|
43
45
|
export const tabledata: TestData[] = [
|
|
44
|
-
{ name: "Sean", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
45
|
-
{ name: "Kipp", company: "Spectric Labs", "contact": "123-4567", "country": "UK" },
|
|
46
|
-
{ name: "Adam", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
47
|
-
{ name: "Chris", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
48
|
-
{ name: "Michael", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
49
|
-
{ name: "Matt", company: "Spectric Labs", "contact": "123-4567", "country": "US" },
|
|
50
|
-
{ name: "Grant", company: "Spectric Labs", "contact": "123-4567", "country": "
|
|
51
|
-
export const tablecolumns: ColumnSettings<TestData>[] = [{ "title": "Company", key: "company" }, { "title": "Name", key: "name" }, { "title": "Contact", key: "contact" }, { "title": "Country", key: "country", filterable: true }]
|
|
46
|
+
{ name: "Sean", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" } },
|
|
47
|
+
{ name: "Kipp", company: "Spectric Labs", "contact": "123-4567", location: { "country": "UK", state: "N/A" } },
|
|
48
|
+
{ name: "Adam", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" } },
|
|
49
|
+
{ name: "Chris", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" } },
|
|
50
|
+
{ name: "Michael", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" } },
|
|
51
|
+
{ name: "Matt", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" } },
|
|
52
|
+
{ name: "Grant", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" } },]
|
|
53
|
+
export const tablecolumns: ColumnSettings<TestData>[] = [{ "title": "Company", key: "company" }, { "title": "Name", key: "name" }, { "title": "Contact", key: "contact" }, { "title": "Country", key: "location.country", filterable: true }]
|
|
@@ -8,12 +8,6 @@ import { useArgs } from "@storybook/client-api";
|
|
|
8
8
|
import { FilterEvent } from "../components/table/cell";
|
|
9
9
|
import { tablecolumns, tabledata } from "./fixtures/data";
|
|
10
10
|
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
11
|
-
type TestData = {
|
|
12
|
-
name: string
|
|
13
|
-
company: string
|
|
14
|
-
contact: string
|
|
15
|
-
country: string
|
|
16
|
-
}
|
|
17
11
|
const data = tabledata
|
|
18
12
|
const columns = tablecolumns
|
|
19
13
|
const meta = {
|
|
@@ -51,10 +45,10 @@ const meta = {
|
|
|
51
45
|
},
|
|
52
46
|
columns: columns
|
|
53
47
|
},
|
|
54
|
-
} satisfies Meta<Props<
|
|
48
|
+
} satisfies Meta<Props<typeof tabledata[0]>>;
|
|
55
49
|
|
|
56
50
|
export default meta;
|
|
57
|
-
type Story = StoryObj<Props<
|
|
51
|
+
type Story = StoryObj<Props<typeof tabledata[0]>>;
|
|
58
52
|
|
|
59
53
|
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
60
54
|
export const Basic: Story = {
|