@spectric/ui 0.0.21 → 0.0.23

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 (46) hide show
  1. package/dist/components/dialog/dialog.d.ts +1 -0
  2. package/dist/components/pagination/pagination.d.ts +1 -1
  3. package/dist/components/query_bar/QueryBar.d.ts +30 -10
  4. package/dist/components/query_bar/dateTimePopup.d.ts +2 -0
  5. package/dist/components/query_bar/geojsonPopup.d.ts +2 -0
  6. package/dist/components/query_bar/querylanguage/kuery/functions/geospatial.d.ts +19 -0
  7. package/dist/components/query_bar/querylanguage/outputTypes/toCQL.d.ts +2 -1
  8. package/dist/components/query_bar/querylanguage/outputTypes/toMongo.d.ts +6 -1
  9. package/dist/components/symbols.d.ts +6 -0
  10. package/dist/components/table/cell.d.ts +1 -1
  11. package/dist/components/table/table.d.ts +14 -1
  12. package/dist/custom-elements.json +6 -6
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.es.js +4405 -2803
  15. package/dist/index.es.js.map +1 -1
  16. package/dist/index.umd.js +361 -252
  17. package/dist/index.umd.js.map +1 -1
  18. package/dist/style.css +1 -1
  19. package/package.json +6 -1
  20. package/src/components/dialog/dialog.css.ts +29 -29
  21. package/src/components/dialog/dialog.ts +3 -1
  22. package/src/components/input.css +5 -0
  23. package/src/components/input.ts +50 -41
  24. package/src/components/pagination/pagination.ts +167 -113
  25. package/src/components/query_bar/QueryBar.ts +438 -187
  26. package/src/components/query_bar/dateTimePopup.ts +54 -0
  27. package/src/components/query_bar/geojsonPopup.ts +44 -0
  28. package/src/components/query_bar/querylanguage/kuery/ast/_generated_/kuery.js +1836 -2745
  29. package/src/components/query_bar/querylanguage/kuery/ast/ast.ts +15 -13
  30. package/src/components/query_bar/querylanguage/kuery/ast/kuery.peg +92 -126
  31. package/src/components/query_bar/querylanguage/kuery/functions/geospatial.ts +25 -0
  32. package/src/components/query_bar/querylanguage/kuery/functions/index.ts +9 -7
  33. package/src/components/query_bar/querylanguage/outputTypes/toCQL.ts +56 -34
  34. package/src/components/query_bar/querylanguage/outputTypes/toMongo.ts +46 -34
  35. package/src/components/symbols.ts +6 -0
  36. package/src/components/table/__tests__/table.spec.ts +2 -2
  37. package/src/components/table/cell.ts +28 -11
  38. package/src/components/table/header.ts +3 -2
  39. package/src/components/table/table.css +11 -4
  40. package/src/components/table/table.ts +75 -5
  41. package/src/components/table/virtualBody.ts +8 -3
  42. package/src/components/tooltip/popover.ts +263 -225
  43. package/src/stories/Dialog.stories.ts +59 -0
  44. package/src/stories/QueryBar.stories.ts +46 -37
  45. package/src/stories/fixtures/data.ts +229 -37
  46. package/src/stories/table.stories.ts +77 -29
@@ -1,55 +1,64 @@
1
- import type { Meta, StoryObj } from '@storybook/web-components';
1
+ import type { Meta, StoryObj } from "@storybook/web-components";
2
2
 
3
- import { SupportedLanguages, type IQueryProps } from '../components/query_bar/QueryBar';
4
- import '../components';
5
- import { html } from 'lit';
6
- import { ifDefined } from 'lit/directives/if-defined.js';
7
- import { useArgs } from '@storybook/client-api';
8
- import { filterByColumn } from './fixtures/data';
3
+ import {
4
+ SupportedLanguages,
5
+ type IQueryProps,
6
+ } from "../components/query_bar/QueryBar";
7
+ import "../components";
8
+ import { html } from "lit";
9
+ import { ifDefined } from "lit/directives/if-defined.js";
10
+ import { useArgs } from "@storybook/client-api";
11
+ import { filterByColumn } from "./fixtures/data";
9
12
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
10
- var code = ""
13
+ var code = "";
11
14
 
12
15
  const meta = {
13
- title: 'UI/Query',
14
- tags: ['autodocs'],
16
+ title: "UI/Query",
17
+ tags: ["autodocs"],
15
18
  component: "spectric-query",
16
19
  render: (args) => {
17
20
  const [_, updateArgs] = useArgs();
18
21
  const fakevalues = async (field, text) => {
19
- if (!args.fields.find(f => f.name === field)) {
20
- return []
22
+ if (!args.fields.find((f) => f.name === field)) {
23
+ return [];
21
24
  }
22
- return filterByColumn(field, text)
23
- }
25
+ return filterByColumn(field, text);
26
+ };
24
27
  return html`
25
- <spectric-query
26
- .fields=${args.fields}
27
- .getValuesForField=${fakevalues}
28
- value=${ifDefined(args.value)}
29
- @change=${(e: CustomEvent<any>) => {
30
- code = e.detail
31
- updateArgs({ ...args })
32
- }}
33
- outputLanguage=${args.outputLanguage}
34
- >
35
-
36
- </spectric-query>
37
- <pre>
28
+ <spectric-query
29
+ .fields=${args.fields}
30
+ .getValuesForField=${fakevalues}
31
+ value=${ifDefined(args.value)}
32
+ @change=${(e: CustomEvent<any>) => {
33
+ code = e.detail;
34
+ updateArgs({ ...args });
35
+ }}
36
+ outputLanguage=${args.outputLanguage}
37
+ >
38
+ </spectric-query>
39
+ <pre>
38
40
  ${JSON.stringify(code, null, 2)}
39
- </pre>
40
- `},
41
+ </pre
42
+ >
43
+ `;
44
+ },
41
45
  argTypes: {
42
-
43
46
  outputLanguage: {
44
- control: { type: 'select' },
47
+ control: { type: "select" },
45
48
  options: Object.values(SupportedLanguages),
46
49
  },
47
50
  },
48
51
  args: {
49
- outputLanguage: 'toDSL',
50
- fields: [{ name: "test", type: "string" }, { name: "test_num", type: "number" }, { name: "test_bool", type: "boolean" }, { name: "modulations", type: "string" }, { name: "time_seen", type: "string", format: "date-time" }]
52
+ outputLanguage: "toDSL",
53
+ fields: [
54
+ { name: "test", type: "string" },
55
+ { name: "test_num", type: "number" },
56
+ { name: "test_bool", type: "boolean" },
57
+ { name: "modulations", type: "string" },
58
+ { name: "time_seen", type: "string", format: "date-time" },
59
+ { name: "geo_center", type: "object", format: "geojson" },
60
+ ],
51
61
  },
52
-
53
62
  } satisfies Meta<IQueryProps>;
54
63
 
55
64
  export default meta;
@@ -58,13 +67,13 @@ type Story = StoryObj<IQueryProps>;
58
67
  // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
59
68
  export const Basic: Story = {
60
69
  args: {
61
- outputLanguage: "toCql"
70
+ outputLanguage: "toCql",
62
71
  },
63
72
  };
64
73
 
65
74
  export const ShouldHaveValue: Story = {
66
75
  args: {
67
76
  outputLanguage: "toCql",
68
- value:"test: * and test_num > 10"
77
+ value: "test: * and test_num > 10",
69
78
  },
70
- };
79
+ };
@@ -1,5 +1,6 @@
1
+ import { html, svg } from "lit";
1
2
  import { ColumnSettings } from "../../components/table";
2
-
3
+ import { unsafeSVG } from "lit/directives/unsafe-svg.js";
3
4
 
4
5
  export const modulations = [
5
6
  "AM",
@@ -11,54 +12,245 @@ export const modulations = [
11
12
  "PSK",
12
13
  "OFDM",
13
14
  "PCM",
14
- "DPSK"
15
+ "DPSK",
15
16
  ];
16
17
  //pulled from https://www.sigidwiki.com/wiki/Category:Digital signals that don't have a space or -
17
- export const signals = ["802.11n", "8PSK", "ASCII", "AUTOSPEC", "Aprizesat", "Autocab", "Bluetooth", "CCITT", "CDMA420", "CHIP", "CHU", "COFDMTV", "CompuLert", "Contestia", "Coquelet", "DCF77", "DominoEX", "DominoF", "EIA", "FLEX", "FSK441", "FSQ", "FST4W", "FT4", "FT8", "Hellschreiber", "ISCAT", "JS8", "JT4", "JT65", "JT6M", "JT9", "JTMS", "Kiwi", "Lentus", "LoRa", "MDC1200", "MOBITEX", "MSK144", "MT63", "Milstar", "NML", "NOV", "NPM", "NWC", "Olivia", "OpenSky", "Orbcomm", "PACKET", "PAX", "PI4", "POCSAG", "PSK2K", "Piccolo", "ProVoice", "Q15X25", "ROS", "RTTYM", "ReFLEX", "SIGFOX", "SPREAD", "Serdolik", "SkyOFDM", "THOR", "THROB", "TT2300", "TWINPLEX", "Tetrapol", "VISEL", "VOICE", "WSPR", "WiMAX", "WinDRM"]
18
+ export const signals = [
19
+ "802.11n",
20
+ "8PSK",
21
+ "ASCII",
22
+ "AUTOSPEC",
23
+ "Aprizesat",
24
+ "Autocab",
25
+ "Bluetooth",
26
+ "CCITT",
27
+ "CDMA420",
28
+ "CHIP",
29
+ "CHU",
30
+ "COFDMTV",
31
+ "CompuLert",
32
+ "Contestia",
33
+ "Coquelet",
34
+ "DCF77",
35
+ "DominoEX",
36
+ "DominoF",
37
+ "EIA",
38
+ "FLEX",
39
+ "FSK441",
40
+ "FSQ",
41
+ "FST4W",
42
+ "FT4",
43
+ "FT8",
44
+ "Hellschreiber",
45
+ "ISCAT",
46
+ "JS8",
47
+ "JT4",
48
+ "JT65",
49
+ "JT6M",
50
+ "JT9",
51
+ "JTMS",
52
+ "Kiwi",
53
+ "Lentus",
54
+ "LoRa",
55
+ "MDC1200",
56
+ "MOBITEX",
57
+ "MSK144",
58
+ "MT63",
59
+ "Milstar",
60
+ "NML",
61
+ "NOV",
62
+ "NPM",
63
+ "NWC",
64
+ "Olivia",
65
+ "OpenSky",
66
+ "Orbcomm",
67
+ "PACKET",
68
+ "PAX",
69
+ "PI4",
70
+ "POCSAG",
71
+ "PSK2K",
72
+ "Piccolo",
73
+ "ProVoice",
74
+ "Q15X25",
75
+ "ROS",
76
+ "RTTYM",
77
+ "ReFLEX",
78
+ "SIGFOX",
79
+ "SPREAD",
80
+ "Serdolik",
81
+ "SkyOFDM",
82
+ "THOR",
83
+ "THROB",
84
+ "TT2300",
85
+ "TWINPLEX",
86
+ "Tetrapol",
87
+ "VISEL",
88
+ "VOICE",
89
+ "WSPR",
90
+ "WiMAX",
91
+ "WinDRM",
92
+ ];
18
93
  export const filterByColumn = async (field, text) => {
94
+ if (field === "geo_center") {
95
+ return [
96
+ {
97
+ label: "Tucuman Argentina",
98
+ value:
99
+ "POLYGON ((-66.20361328125 -26.62781822639305, -66.0498046875 -26.64745870265937, -65.830078125 -26.725986812271756, -65.89599609375 -26.92206991673281, -66.181640625 -27.274161117374668, -65.6103515625 -27.994401411046148, -65.4345703125 -27.89734922968425, -65.0390625 -27.89734922968425, -64.4677734375 -26.29341500426577, -65.36865234375 -26.07652055985696, -65.85205078125 -26.31311263768267, -66.11572265625 -26.2145910237943, -66.20361328125 -26.62781822639305))",
100
+ },
101
+ {
102
+ label: "Santiago Argentina",
103
+ value:
104
+ "POLYGON ((-64.42108154296874 -26.28356493253137, -65.0390625 -27.885211577912145, -65.18463134765625 -27.931327412293648, -65.08026123046874 -28.738763971370293, -64.88250732421875 -28.7965462417692, -64.81658935546872 -29.506549442788607, -62.79510498046873 -29.869228848968298, -62.091979980468736 -30.439202087235568, -61.58660888671873 -25.671235828577018, -64.22332763671874 -25.651430347039724, -64.42108154296874 -26.28356493253137))",
105
+ },
106
+ ];
107
+ }
19
108
  if (field === "time_seen") {
20
- return []
109
+ return [];
21
110
  }
22
111
  if (field === "modulations") {
23
- return modulations.filter(v => v.match(new RegExp(text, "gi")))
112
+ return modulations.filter((v) => v.match(new RegExp(text, "gi")));
24
113
  }
25
114
  if (field === "signal") {
26
- return signals.filter(v => v.match(new RegExp(text, "gi")))
115
+ return signals.filter((v) => v.match(new RegExp(text, "gi")));
27
116
  }
28
- let ipsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`
29
- let values = ['test', 'some value', '10000', ...ipsum.split(" ").map(v => `${v}`)]
117
+ let ipsum = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`;
118
+ let values = [
119
+ "test",
120
+ "some value",
121
+ "10000",
122
+ ...ipsum.split(" ").map((v) => `${v}`),
123
+ ];
30
124
  if (text == "") {
31
- return values
125
+ return values;
32
126
  }
33
- return values.filter(v => v.includes(text))
34
- }
127
+ return values.filter((v) => v.includes(text));
128
+ };
35
129
 
36
130
  export type TestData = {
37
- name: string
38
- company: string
39
- contact: string
131
+ name: string;
132
+ company: string;
133
+ contact: string;
40
134
  location: {
41
- country: string,
42
- state: string
43
- },
44
- years: number
45
- }
135
+ country: string;
136
+ state: string;
137
+ };
138
+ years: number;
139
+ };
46
140
  export const tabledata: TestData[] = [
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
- ]
141
+ {
142
+ name: "Sean",
143
+ company: "Spectric Labs",
144
+ contact: "123-4567",
145
+ location: { country: "US", state: "VA" },
146
+ years: 11,
147
+ },
148
+ {
149
+ name: "Kipp",
150
+ company: "Spectric Labs",
151
+ contact: "123-4567",
152
+ location: { country: "UK", state: "N/A" },
153
+ years: 5,
154
+ },
155
+ {
156
+ name: "Adam",
157
+ company: "Spectric Labs",
158
+ contact: "123-4567",
159
+ location: { country: "US", state: "VA" },
160
+ years: 19,
161
+ },
162
+ {
163
+ name: "Chris",
164
+ company: "Spectric Labs",
165
+ contact: "123-4567",
166
+ location: { country: "US", state: "VA" },
167
+ years: 27,
168
+ },
169
+ {
170
+ name: "Michael",
171
+ company: "Spectric Labs",
172
+ contact: "123-4567",
173
+ location: { country: "US", state: "VA" },
174
+ years: 3,
175
+ },
176
+ {
177
+ name: "Matt",
178
+ company: "Spectric Labs",
179
+ contact: "123-4567",
180
+ location: { country: "US", state: "VA" },
181
+ years: 9,
182
+ },
183
+ {
184
+ name: "Matt",
185
+ company: "Spectric Labs",
186
+ contact: "865-6343",
187
+ location: { country: "UK", state: "VA" },
188
+ years: 5,
189
+ },
190
+ {
191
+ name: "Matt",
192
+ company: "Spectric Labs",
193
+ contact: "253-6795",
194
+ location: { country: "UK", state: "VA" },
195
+ years: 15,
196
+ },
197
+ {
198
+ name: "Matt",
199
+ company: "Spectric Labs (Intern)",
200
+ contact: "253-6795",
201
+ location: { country: "US", state: "CO" },
202
+ years: 1,
203
+ },
204
+ {
205
+ name: "Matt",
206
+ company: "Spectric Labs",
207
+ contact: "912-1230",
208
+ location: { country: "UK", state: "VA" },
209
+ years: 24,
210
+ },
211
+ {
212
+ name: "Grant",
213
+ company: "Spectric Labs",
214
+ contact: "123-4567",
215
+ location: { country: "US", state: "VA" },
216
+ years: 100,
217
+ },
218
+ ];
219
+ export const getTableColumns = () => {
220
+ const tablecolumns: ColumnSettings<TestData>[] = [
221
+ { title: "Company", key: "company", width: 200 },
222
+ { title: "Name", key: "name", sortable: true },
223
+ {
224
+ title: "Contact",
225
+ key: "contact",
226
+ cellActions: [
227
+ {
228
+ tooltip: "Call",
229
+ onClick: (row, _column) => {
230
+ alert(`Calling ${row.name} at ${row.contact}`);
231
+ },
232
+ icon: html`<svg
233
+ width="16px"
234
+ height="16px"
235
+ viewBox="0 0 24 24"
236
+ fill="none"
237
+ xmlns="http://www.w3.org/2000/svg"
238
+ >
239
+ <g>
240
+ <path
241
+ d="M14.05 6C15.0268 6.19057 15.9244 6.66826 16.6281 7.37194C17.3318 8.07561 17.8095 8.97326 18 9.95M14.05 2C16.0793 2.22544 17.9716 3.13417 19.4163 4.57701C20.8609 6.01984 21.7721 7.91101 22 9.94M18.5 21C9.93959 21 3 14.0604 3 5.5C3 5.11378 3.01413 4.73086 3.04189 4.35173C3.07375 3.91662 3.08968 3.69907 3.2037 3.50103C3.29814 3.33701 3.4655 3.18146 3.63598 3.09925C3.84181 3 4.08188 3 4.56201 3H7.37932C7.78308 3 7.98496 3 8.15802 3.06645C8.31089 3.12515 8.44701 3.22049 8.55442 3.3441C8.67601 3.48403 8.745 3.67376 8.88299 4.05321L10.0491 7.26005C10.2096 7.70153 10.2899 7.92227 10.2763 8.1317C10.2643 8.31637 10.2012 8.49408 10.0942 8.64506C9.97286 8.81628 9.77145 8.93713 9.36863 9.17882L8 10C9.2019 12.6489 11.3501 14.7999 14 16L14.8212 14.6314C15.0629 14.2285 15.1837 14.0271 15.3549 13.9058C15.5059 13.7988 15.6836 13.7357 15.8683 13.7237C16.0777 13.7101 16.2985 13.7904 16.74 13.9509L19.9468 15.117C20.3262 15.255 20.516 15.324 20.6559 15.4456C20.7795 15.553 20.8749 15.6891 20.9335 15.842C21 16.015 21 16.2169 21 16.6207V19.438C21 19.9181 21 20.1582 20.9007 20.364C20.8185 20.5345 20.663 20.7019 20.499 20.7963C20.3009 20.9103 20.0834 20.9262 19.6483 20.9581C19.2691 20.9859 18.8862 21 18.5 21Z"
242
+ stroke="#000000"
243
+ stroke-width="2"
244
+ stroke-linecap="round"
245
+ stroke-linejoin="round"
246
+ ></path>
247
+ </g>
248
+ </svg>`,
249
+ },
250
+ ],
251
+ },
252
+ { title: "Country", key: "location.country", filterable: true },
253
+ { title: "Years Employed", key: "years", sortable: true },
254
+ ];
255
+ return tablecolumns;
256
+ };
@@ -2,15 +2,54 @@ import type { Meta, StoryObj } from "@storybook/web-components";
2
2
 
3
3
  //import { ColumnSettings, PaginationChangeProps, TableElement, TableSelectOptions, TableSortDirection, TableSortOption, type TableProps as Props } from "../components/";
4
4
  import { html } from "lit";
5
- import { ColumnSettings, PaginationChangeProps, SpectricTableElement, TableDataOptions, TableSelectOptions, TableSortDirection, TableSortOption, type TableProps as Props } from "../index"
5
+ import {
6
+ ColumnSettings,
7
+ PaginationChangeProps,
8
+ SpectricTableElement,
9
+ TableDataOptions,
10
+ TableSelectOptions,
11
+ TableSortDirection,
12
+ TableSortOption,
13
+ type TableProps as Props,
14
+ } from "../index";
6
15
  import { ifDefined } from "lit/directives/if-defined.js";
7
16
  import { useArgs } from "@storybook/client-api";
8
17
  import { FilterEvent, rowGetValue } from "../components/table/cell";
9
- import { tablecolumns, tabledata } from "./fixtures/data";
18
+ import { getTableColumns, tabledata } from "./fixtures/data";
10
19
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
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
- const columns = tablecolumns
13
- const getData = SpectricTableElement.getDefaultDataSorterAndPaginatior<typeof tabledata[0]>(data)
20
+ const data = JSON.parse(
21
+ JSON.stringify([
22
+ ...tabledata,
23
+ ...tabledata,
24
+ ...tabledata,
25
+ ...tabledata,
26
+ ...tabledata,
27
+ ...tabledata,
28
+ ...tabledata,
29
+ ...tabledata,
30
+ ...tabledata,
31
+ ...tabledata,
32
+ ...tabledata,
33
+ ...tabledata,
34
+ ...tabledata,
35
+ ...tabledata,
36
+ ...tabledata,
37
+ ...tabledata,
38
+ ...tabledata,
39
+ ...tabledata,
40
+ ...tabledata,
41
+ ...tabledata,
42
+ ...tabledata,
43
+ ...tabledata,
44
+ ...tabledata,
45
+ ...tabledata,
46
+ ])
47
+ );
48
+
49
+ const getData =
50
+ SpectricTableElement.getDefaultDataSorterAndPaginatior<(typeof tabledata)[0]>(
51
+ data
52
+ );
14
53
  const meta = {
15
54
  title: "UI/Table",
16
55
  tags: ["autodocs"],
@@ -27,23 +66,33 @@ const meta = {
27
66
  select=${ifDefined(args.select)}
28
67
  sort=${ifDefined(args.sort)}
29
68
  rowHeight=${ifDefined(args.rowHeight)}
30
- @selected=${(e) => { }}
69
+ @selected=${(e) => {}}
31
70
  @filter=${(e: CustomEvent<FilterEvent<any>>) => {
32
- alert(`filter ${e.detail.include ? "for" : "out"} event value ${e.detail.value}`)
33
- }}
34
- @change=${(e: CustomEvent<TableDataOptions<typeof tabledata[0]>>) => {
35
- updateArgs({ ...e.detail });
36
- if (e.target && e.target instanceof SpectricTableElement) {
37
- e.target.data = getData({ ...args, ...e.detail })
38
- }
39
- }}
71
+ alert(
72
+ `filter ${e.detail.include ? "for" : "out"} event value ${
73
+ e.detail.value
74
+ }`
75
+ );
76
+ }}
77
+ @change=${(e: CustomEvent<TableDataOptions<(typeof tabledata)[0]>>) => {
78
+ updateArgs({ ...e.detail });
79
+ if (e.target && e.target instanceof SpectricTableElement) {
80
+ e.target.data = getData({ ...args, ...e.detail });
81
+ }
82
+ }}
40
83
  >
41
84
  </spectric-table>
42
85
  `;
43
86
  },
44
87
  argTypes: {
45
- select: { control: { type: "select" }, options: Object.values(TableSelectOptions) },
46
- sort: { control: { type: "select" }, options: Object.values(TableSortOption) }
88
+ select: {
89
+ control: { type: "select" },
90
+ options: Object.values(TableSelectOptions),
91
+ },
92
+ sort: {
93
+ control: { type: "select" },
94
+ options: Object.values(TableSortOption),
95
+ },
47
96
  },
48
97
  args: {
49
98
  pagination: {
@@ -52,13 +101,13 @@ const meta = {
52
101
  size: "xsmall",
53
102
  totalItems: data.length,
54
103
  },
55
- columns: JSON.parse(JSON.stringify(columns)),
56
- select: TableSelectOptions.none
104
+ columns: getTableColumns(),
105
+ select: TableSelectOptions.none,
57
106
  },
58
- } satisfies Meta<Props<typeof tabledata[0]>>;
107
+ } satisfies Meta<Props<(typeof tabledata)[0]>>;
59
108
 
60
109
  export default meta;
61
- type Story = StoryObj<Props<typeof tabledata[0]>>;
110
+ type Story = StoryObj<Props<(typeof tabledata)[0]>>;
62
111
 
63
112
  // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
64
113
  export const Basic: Story = {
@@ -69,7 +118,7 @@ export const Basic: Story = {
69
118
  size: "xsmall",
70
119
  totalItems: data.length,
71
120
  },
72
- columns: JSON.parse(JSON.stringify(columns)),
121
+ columns: getTableColumns(),
73
122
  },
74
123
  };
75
124
 
@@ -77,32 +126,31 @@ export const Basic: Story = {
77
126
  export const NoPagination: Story = {
78
127
  args: {
79
128
  pagination: undefined,
80
- columns: JSON.parse(JSON.stringify(columns)),
129
+ columns: getTableColumns(),
81
130
  },
82
131
  };
83
132
 
84
- export const MiltiSelect: Story = {
133
+ export const MultiSelect: Story = {
85
134
  args: {
86
135
  select: "multi",
87
- columns: JSON.parse(JSON.stringify(columns)),
136
+ columns: getTableColumns(),
88
137
  },
89
138
  };
90
139
 
91
140
  export const SingleSelect: Story = {
92
141
  args: {
93
142
  select: "single",
94
- columns: JSON.parse(JSON.stringify(columns)),
143
+ columns: getTableColumns(),
95
144
  },
96
145
  };
97
146
 
98
-
99
147
  /**
100
148
  * The spectric table by default is set to single column sorting, but you can enable multicolumn sorting with the sort="multi" attribute
101
149
  */
102
150
  export const MultiColumnSort: Story = {
103
151
  args: {
104
152
  sort: "multi",
105
- columns: JSON.parse(JSON.stringify(columns)),
106
- pagination: { pageSize: 20, page: 1 }
153
+ columns: getTableColumns(),
154
+ pagination: { pageSize: 20, page: 1 },
107
155
  },
108
- };
156
+ };