@spectric/ui 0.0.10 → 0.0.12

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.
Files changed (51) hide show
  1. package/dist/classes/DisposibleElement.d.ts +4 -2
  2. package/dist/components/Bitdisplay.d.ts +4 -4
  3. package/dist/components/Button.d.ts +1 -1
  4. package/dist/components/Header.d.ts +1 -1
  5. package/dist/components/input.d.ts +13 -12
  6. package/dist/components/pagination/pagination.d.ts +5 -5
  7. package/dist/components/splitview/splitview.d.ts +5 -5
  8. package/dist/components/table/body.d.ts +2 -1
  9. package/dist/components/table/cell.d.ts +2 -0
  10. package/dist/components/table/header.d.ts +2 -1
  11. package/dist/components/table/sorting.d.ts +5 -0
  12. package/dist/components/table/table.d.ts +51 -14
  13. package/dist/components/table/virtualBody.d.ts +49 -0
  14. package/dist/components/tooltip/tooltip.d.ts +17 -12
  15. package/dist/custom-elements.json +50 -16
  16. package/dist/index.es.js +2099 -1867
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/index.umd.js +128 -93
  19. package/dist/index.umd.js.map +1 -1
  20. package/dist/style.css +1 -1
  21. package/dist/utils/once.d.ts +1 -0
  22. package/dist/utils/spread.d.ts +1 -1
  23. package/package.json +1 -1
  24. package/src/classes/DisposibleElement.ts +15 -9
  25. package/src/components/Bitdisplay.ts +7 -7
  26. package/src/components/Button.ts +1 -1
  27. package/src/components/Header.ts +1 -1
  28. package/src/components/input.ts +18 -15
  29. package/src/components/pagination/pagination.ts +7 -7
  30. package/src/components/query_bar/QueryBar.ts +26 -21
  31. package/src/components/splitview/splitview.ts +5 -5
  32. package/src/components/table/body.ts +13 -5
  33. package/src/components/table/cell.ts +9 -7
  34. package/src/components/table/header.ts +28 -4
  35. package/src/components/table/sorting.ts +34 -0
  36. package/src/components/table/table.css +60 -4
  37. package/src/components/table/table.ts +149 -33
  38. package/src/components/table/virtualBody.css +13 -0
  39. package/src/components/table/virtualBody.ts +127 -0
  40. package/src/components/tooltip/tooltip.ts +38 -32
  41. package/src/docs/HTML-Vue-Python Integration.mdx +3 -3
  42. package/src/docs/html-include.png +0 -0
  43. package/src/docs/vue-example.png +0 -0
  44. package/src/docs/vue-include.png +0 -0
  45. package/src/stories/BitDisplay.stories.ts +2 -0
  46. package/src/stories/fixtures/ExampleContent.ts +15 -8
  47. package/src/stories/fixtures/data.ts +21 -10
  48. package/src/stories/pagination.stories.ts +2 -1
  49. package/src/stories/table.stories.ts +27 -5
  50. package/src/utils/once.ts +12 -0
  51. package/src/utils/spread.ts +3 -3
@@ -2,16 +2,16 @@
2
2
 
3
3
  Add the dist/custom-element.json to the html.languge settings
4
4
  https://code.visualstudio.com/docs/languages/html#_html-custom-data
5
- ![Add spectric custom elements](html-include.png)
5
+ ![Add spectric custom elements](./html-include.png)
6
6
 
7
7
  # VUE Integration
8
8
 
9
9
  Complete steps to include custom elements in the HTML language server
10
10
  then
11
11
  Add the HTML language server in the @ext:Vue.volar extention
12
- ![Add the HTML language server in the @ext:Vue.volar extention](vue-include.png)
12
+ ![Add the HTML language server in the @ext:Vue.volar extention](./vue-include.png)
13
13
  Once setup hovering over spectric elements will provide documentation
14
- ![alt text](vue-example.png)
14
+ ![alt text](./vue-example.png)
15
15
 
16
16
  # Python Jinja
17
17
 
Binary file
Binary file
Binary file
@@ -44,6 +44,8 @@ const meta = {
44
44
  Int16-e: ${pad(dataview.getInt16(0, true))}
45
45
  UInt16-E: ${pad(dataview.getUint16(0, false))} 0x${dataview.getUint16(0, false).toString(16)}
46
46
  Int16-e: ${pad(dataview.getUint16(0, true))} 0x${dataview.getUint16(0, true).toString(16)}
47
+ F32-e: ${pad(dataview.getFloat32(0, true))}
48
+ F32-E: ${pad(dataview.getFloat32(0, false))}
47
49
  </pre>`: null}
48
50
  `},
49
51
 
@@ -1,5 +1,5 @@
1
1
 
2
- import { filterByColumn, tablecolumns, tabledata } from "./data";
2
+ import { filterByColumn, tablecolumns, tabledata, TestData } from "./data";
3
3
  import { ExampleBits } from "./Bits";
4
4
  import { FieldTypes, SpectricQuery } from "../../components/query_bar/QueryBar";
5
5
 
@@ -7,8 +7,9 @@ import { html, LitElement } from 'lit';
7
7
 
8
8
  import { customElement, property, query, state } from 'lit/decorators.js';
9
9
  import "./lorumipsum"
10
- import { PaginationChangeProps } from "../../components/pagination";
10
+ import { PaginationChangeProps, PaginationProps } from "../../components/pagination";
11
11
  import { FilterEvent } from "../../components/table/cell";
12
+ import { TableDataOptions, TableElement } from "../../components/table";
12
13
  type Props = {
13
14
  frameWidth: number
14
15
  }
@@ -23,10 +24,15 @@ export class SpectricStorybookExampleContent extends LitElement implements Props
23
24
  @query("spectric-query")
24
25
  query!: SpectricQuery
25
26
 
27
+ private dataSorter = TableElement.getDefaultDataSorterAndPaginatior<TestData>(tabledata)
26
28
  @state()
27
29
  dialogOpen: boolean = false;
28
- tableData = tabledata.slice(0, 3)
29
- pagination = {
30
+ get tableData() {
31
+ return this.dataSorter(this)
32
+ }
33
+
34
+ columns = tablecolumns
35
+ pagination: PaginationProps = {
30
36
  page: 1,
31
37
  pageSize: 3,
32
38
  size: "xsmall",
@@ -35,17 +41,17 @@ export class SpectricStorybookExampleContent extends LitElement implements Props
35
41
  _handleFilter = (e: CustomEvent<FilterEvent<any>>) => {
36
42
  let include = e.detail.include ? "" : "not "
37
43
  if (e.detail.column.key && e.detail.value) {
38
- if (this.query.value !== "") {
44
+ if (this.query.value.trim() !== "") {
39
45
  this.query.value = `${this.query.value} and ${include}${e.detail.column.key}: '${e.detail.value}'`
40
46
  } else {
41
47
  this.query.value = `${include}${e.detail.column.key}: '${e.detail.value}'`
42
48
  }
43
49
  }
44
50
  }
45
- _handlePaginationChange = (e: CustomEvent<{ pagination: PaginationChangeProps }>) => {
46
- let { pagination } = e.detail
51
+ _handlePaginationChange = (e: CustomEvent<TableDataOptions<TestData>>) => {
52
+ let { pagination, columns } = e.detail
47
53
  this.pagination = { ...this.pagination, ...pagination }
48
- this.tableData = tabledata.slice((pagination.page - 1) * pagination.pageSize, (pagination.page) * pagination.pageSize)
54
+ this.columns = columns
49
55
  this.requestUpdate()
50
56
  }
51
57
  render() {
@@ -89,6 +95,7 @@ export class SpectricStorybookExampleContent extends LitElement implements Props
89
95
 
90
96
  </spectric-query>
91
97
  <spectric-table
98
+ style="height:200px;"
92
99
  .data=${this.tableData}
93
100
  .columns=${tablecolumns}
94
101
  @filter=${this._handleFilter}
@@ -33,21 +33,32 @@ export const filterByColumn = async (field, text) => {
33
33
  return values.filter(v => v.includes(text))
34
34
  }
35
35
 
36
- type TestData = {
36
+ export type TestData = {
37
37
  name: string
38
38
  company: string
39
39
  contact: string
40
40
  location: {
41
41
  country: string,
42
42
  state: string
43
- }
43
+ },
44
+ years: number
44
45
  }
45
46
  export const tabledata: TestData[] = [
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 }]
47
+ { name: "Sean", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" }, years: 11 },
48
+ { name: "Kipp", company: "Spectric Labs", "contact": "123-4567", location: { "country": "UK", state: "N/A" }, years: 5 },
49
+ { name: "Adam", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" }, years: 19 },
50
+ { name: "Chris", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" }, years: 27 },
51
+ { name: "Michael", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" }, years: 3 },
52
+ { name: "Matt", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" }, years: 9 },
53
+ { name: "Matt", company: "Spectric Labs", "contact": "865-6343", location: { "country": "UK", state: "VA" }, years: 5 },
54
+ { name: "Matt", company: "Spectric Labs", "contact": "253-6795", location: { "country": "UK", state: "VA" }, years: 15 },
55
+ { name: "Matt", company: "Spectric Labs (Intern)", "contact": "253-6795", location: { "country": "US", state: "CO" }, years: 1 },
56
+ { name: "Matt", company: "Spectric Labs", "contact": "912-1230", location: { "country": "UK", state: "VA" }, years: 24 },
57
+ { name: "Grant", company: "Spectric Labs", "contact": "123-4567", location: { "country": "US", state: "VA" }, years: 100 },]
58
+ export const tablecolumns: ColumnSettings<TestData>[] = [
59
+ { "title": "Company", key: "company", width: 200 },
60
+ { "title": "Name", key: "name", sortable: true },
61
+ { "title": "Contact", key: "contact" },
62
+ { "title": "Country", key: "location.country", filterable: true },
63
+ { "title": "Years Employed", key: "years", sortable: true }
64
+ ]
@@ -5,6 +5,7 @@ import { html } from "lit";
5
5
  import '../components';
6
6
  import { ifDefined } from "lit/directives/if-defined.js";
7
7
  import { useArgs } from "@storybook/client-api";
8
+ import { ButtonSizes } from "../components";
8
9
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
9
10
  const meta = {
10
11
  title: "UI/Pagination",
@@ -29,7 +30,7 @@ const meta = {
29
30
  argTypes: {
30
31
  size: {
31
32
  control: { type: 'select' },
32
- options: ['small', 'medium', 'large'],
33
+ options: Object.values(ButtonSizes),
33
34
  },
34
35
  },
35
36
  args: {
@@ -1,15 +1,16 @@
1
1
  import type { Meta, StoryObj } from "@storybook/web-components";
2
2
 
3
- import { ColumnSettings, PaginationChangeProps, type TableProps as Props } from "../components/";
3
+ import { ColumnSettings, PaginationChangeProps, TableElement, TableSelectOptions, TableSortDirection, TableSortOption, type TableProps as Props } from "../components/";
4
4
  import { html } from "lit";
5
5
  import '../components';
6
6
  import { ifDefined } from "lit/directives/if-defined.js";
7
7
  import { useArgs } from "@storybook/client-api";
8
- import { FilterEvent } from "../components/table/cell";
8
+ import { FilterEvent, rowGetValue } 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
- const data = tabledata
11
+ const data = JSON.parse(JSON.stringify([...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata, ...tabledata,]))
12
12
  const columns = tablecolumns
13
+ const getData = TableElement.getDefaultDataSorterAndPaginatior<typeof tabledata[0]>(data)
13
14
  const meta = {
14
15
  title: "UI/Table",
15
16
  tags: ["autodocs"],
@@ -19,22 +20,31 @@ const meta = {
19
20
 
20
21
  return html`
21
22
  <spectric-table
23
+ style="height: 150px;"
22
24
  .pagination=${args.pagination}
23
25
  .columns=${args.columns}
24
- .data=${!args.pagination ? data : data.slice((args.pagination.page - 1) * args.pagination.pageSize, (args.pagination.page) * args.pagination.pageSize)}
26
+ .data=${getData(args)}
25
27
  select=${ifDefined(args.select)}
28
+ sort=${ifDefined(args.sort)}
29
+ rowHeight=${ifDefined(args.rowHeight)}
30
+ @selected=${(e) => console.log(e)}
26
31
  @filter=${(e: CustomEvent<FilterEvent<any>>) => {
27
32
  alert(`filter ${e.detail.include ? "for" : "out"} event value ${e.detail.value}`)
28
33
  }}
29
34
  @change=${(e: CustomEvent<PaginationChangeProps>) => {
30
35
  console.log(e)
31
36
  updateArgs({ ...e.detail });
37
+ if (e.target && e.target instanceof TableElement) {
38
+ e.target.data = getData({ ...args, ...e.detail })
39
+ }
32
40
  }}
33
41
  >
34
42
  </spectric-table>
35
43
  `;
36
44
  },
37
45
  argTypes: {
46
+ select: { control: { type: "select" }, options: Object.values(TableSelectOptions) },
47
+ sort: { control: { type: "select" }, options: Object.values(TableSortOption) }
38
48
  },
39
49
  args: {
40
50
  pagination: {
@@ -43,7 +53,8 @@ const meta = {
43
53
  size: "xsmall",
44
54
  totalItems: data.length,
45
55
  },
46
- columns: columns
56
+ columns: columns,
57
+ select: TableSelectOptions.none
47
58
  },
48
59
  } satisfies Meta<Props<typeof tabledata[0]>>;
49
60
 
@@ -79,4 +90,15 @@ export const SingleSelect: Story = {
79
90
  args: {
80
91
  select: "single"
81
92
  },
93
+ };
94
+
95
+
96
+ /**
97
+ * The spectric table by default is set to single column sorting, but you can enable multicolumn sorting with the sort="multi" attribute
98
+ */
99
+ export const MultiColumnSort: Story = {
100
+ args: {
101
+ sort: "multi",
102
+ pagination: { pageSize: 20, page: 1 }
103
+ },
82
104
  };
@@ -0,0 +1,12 @@
1
+ export function once(func: Function) {
2
+ let hasBeenCalled = false;
3
+ let result: any;
4
+ return function (...args: any[]) {
5
+ if (!hasBeenCalled) {
6
+ hasBeenCalled = true;
7
+ //@ts-ignore
8
+ result = func.apply(this, args);
9
+ }
10
+ return result;
11
+ };
12
+ }
@@ -7,7 +7,7 @@ import { AsyncDirective, directive } from 'lit/async-directive.js';
7
7
  /**
8
8
  * Usage:
9
9
  * import { html, render } from 'lit';
10
- * import { spreadProps } from '@open-wc/lit-helpers';
10
+ * import { spreadProps } from '@spectric/ui';
11
11
  *
12
12
  * render(
13
13
  * html`
@@ -44,10 +44,10 @@ export class SpreadPropsDirective extends AsyncDirective {
44
44
 
45
45
  apply(data: any) {
46
46
  if (!data) return;
47
- const { prevData, element } = this;
47
+ const { element } = this;
48
48
  for (const key in data) {
49
49
  const value = data[key];
50
- if (value === prevData[key]) {
50
+ if ((element as any)[key] === value) {
51
51
  continue;
52
52
  }
53
53
  // @ts-ignore