@spectric/ui 0.0.17 → 0.0.19

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 (49) hide show
  1. package/dist/components/Button.d.ts +2 -1
  2. package/dist/components/Panel.d.ts +6 -3
  3. package/dist/components/ThemeProvider.d.ts +1 -0
  4. package/dist/components/calendar/calendar.d.ts +58 -0
  5. package/dist/components/calendar/index.d.ts +1 -0
  6. package/dist/components/color_picker/ColorPicker.d.ts +7 -6
  7. package/dist/components/index.d.ts +1 -0
  8. package/dist/components/input.d.ts +24 -20
  9. package/dist/components/pagination/pagination.d.ts +1 -1
  10. package/dist/components/query_bar/QueryBar.d.ts +2 -1
  11. package/dist/components/table/table.d.ts +3 -0
  12. package/dist/components/table/virtualBody.d.ts +2 -1
  13. package/dist/components/tooltip/popover.d.ts +32 -2
  14. package/dist/components/tooltip/tooltip.d.ts +1 -32
  15. package/dist/custom-elements.json +60 -15
  16. package/dist/index.d.ts +3 -0
  17. package/dist/index.es.js +2895 -2573
  18. package/dist/index.es.js.map +1 -1
  19. package/dist/index.umd.js +305 -182
  20. package/dist/index.umd.js.map +1 -1
  21. package/dist/style.css +1 -1
  22. package/package.json +1 -1
  23. package/src/components/Button.ts +14 -13
  24. package/src/components/Panel.ts +25 -18
  25. package/src/components/ThemeProvider.ts +34 -1
  26. package/src/components/button.css.ts +15 -2
  27. package/src/components/calendar/calendar.css +50 -0
  28. package/src/components/calendar/calendar.ts +281 -0
  29. package/src/components/calendar/index.ts +1 -0
  30. package/src/components/color_picker/ColorPicker.css +69 -0
  31. package/src/components/color_picker/ColorPicker.ts +72 -17
  32. package/src/components/index.ts +2 -1
  33. package/src/components/input.css +5 -34
  34. package/src/components/input.ts +207 -144
  35. package/src/components/pagination/pagination.ts +2 -2
  36. package/src/components/panel.css.ts +7 -5
  37. package/src/components/query_bar/QueryBar.css +6 -2
  38. package/src/components/query_bar/QueryBar.ts +25 -13
  39. package/src/components/table/__tests__/table.spec.ts +1 -1
  40. package/src/components/table/header.ts +0 -3
  41. package/src/components/table/table.ts +43 -35
  42. package/src/components/table/virtualBody.ts +18 -6
  43. package/src/components/tooltip/popover.ts +73 -33
  44. package/src/components/tooltip/tooltip.css +7 -2
  45. package/src/components/tooltip/tooltip.ts +4 -37
  46. package/src/stories/Calendar.stories.ts +70 -0
  47. package/src/stories/fixtures/ExampleContent.ts +2 -1
  48. package/src/stories/table.stories.ts +1 -2
  49. package/src/stories/tooltip.stories.ts +9 -2
@@ -8,6 +8,7 @@ import "./QueryBar.css"
8
8
  import { DialogElement } from "../dialog";
9
9
  import { createRef, ref } from "lit/directives/ref.js";
10
10
  import { SpectricButton } from "../Button";
11
+ import { PopoverElement } from "../tooltip/popover";
11
12
  export type FieldTypes = {
12
13
  name: string;
13
14
  type: "string" | "number" | "boolean"
@@ -120,7 +121,7 @@ export class SpectricQuery extends LitElement implements IQueryProps {
120
121
  fields: FieldTypes[] = [];
121
122
 
122
123
  @query(".autocomplete")
123
- _autocomplete?: HTMLDivElement
124
+ _autocomplete?: PopoverElement
124
125
 
125
126
  @queryAsync(".autocomplete")
126
127
  //@ts-expect-error
@@ -182,7 +183,7 @@ export class SpectricQuery extends LitElement implements IQueryProps {
182
183
  if (suggestion.type !== "cursor") {
183
184
  return
184
185
  }
185
- let completions = []
186
+ let completions: Completion[] = []
186
187
  this.suggestion = suggestion
187
188
  let { start, end } = suggestion
188
189
  for (let type of suggestion.suggestionTypes) {
@@ -260,14 +261,17 @@ export class SpectricQuery extends LitElement implements IQueryProps {
260
261
  }
261
262
  this.completions = completions
262
263
  if (this.completions.length && this._autocomplete) {
263
- let { width, left, bottom } = this._input.getBoundingClientRect();
264
+ let { width } = this._input.getBoundingClientRect();
265
+ this._autocomplete.maxWidth = width
264
266
  this._autocomplete.showPopover();
265
- //Older firefox doesn't support anchor positions using css properties so manually position here
266
- if (!("anchorName" in document.documentElement.style)) {
267
- this._autocomplete.style.left = `${left + 3.75}px`
268
- this._autocomplete.style.top = `${bottom}px`
269
- }
267
+
270
268
  this._autocomplete.style.width = `${width - 15}px`;
269
+ let popover = this._autocomplete.querySelector<HTMLElement>("[popover]")
270
+ if (popover) {
271
+ popover.style.width = `${width - 15}px`;
272
+ }
273
+ } else {
274
+ this._autocomplete?.hidePopover()
271
275
  }
272
276
  }
273
277
  protected updated(changed: PropertyValues): void {
@@ -345,14 +349,22 @@ export class SpectricQuery extends LitElement implements IQueryProps {
345
349
  protected render() {
346
350
  return html`
347
351
  <spectric-input .value=${this.value} .placeholder=${this.placeholder} style=${`anchor-name:--${this.uuid};`} autocomplete="off" @input=${this._parseQuery} @keydown=${this._handleArrows} @change=${(e: Event) => e.stopPropagation()}></spectric-input>
348
- <div class="autocomplete" popover style=${`position-anchor: --${this.uuid};`}>
349
- ${this.completions.map((option: Completion, index) =>
352
+ <spectric-popover position="bottom" class="autocomplete" .text=${this.completions.map((option: Completion, index) =>
350
353
  html`<div @click=${() => {
351
354
  this.completionIndex = index;
352
355
  this._selectCompletion()
353
- }} class=${this.completionIndex == index ? "option active" : "option"}><span class="optiontype ${option.type}">${option.type}</span> <span class="value">${option.value}</span> <span class="label">${option.label}</span></span> </div></div>`
354
- )}
355
- </div>`
356
+ }}
357
+ class=${this.completionIndex == index ? "option active" : "option"}>
358
+ <span class="optiontype ${option.type}">${option.type}</span>
359
+ <span class="value">${option.value}</span>
360
+ <span class="label">${option.label}</span>
361
+ </div>
362
+ `
363
+ )
364
+ }>
365
+
366
+ </spectric-popover>
367
+ `
356
368
  }
357
369
  }
358
370
 
@@ -2,6 +2,7 @@ import { test, expect } from '@playwright/test';
2
2
  import type { SpectricTableElement, TableEvents } from '../index';
3
3
  import type SpectricModule from "../../../index.ts"
4
4
  test.beforeEach(async ({ page }) => {
5
+ page.on('console', msg => { console.log(`Page[${msg.type()}]:` + msg.text()) });
5
6
  await page.addInitScript(() => {
6
7
  //@ts-ignore
7
8
  window.awaitEvent = function awaitEvent(target, event, trigger) {
@@ -26,7 +27,6 @@ test.describe("Spectric Table Tests", () => {
26
27
  tableLocator.waitFor()
27
28
  var selected = await tableLocator.evaluate<number, SpectricTableElement>(
28
29
  async (table) => {
29
- console.log("here")
30
30
  let selectAll = table.querySelectorAll<HTMLElement>("spectric-table-header spectric-input[variant='checkbox'] spectric-button")[0]
31
31
  let [event] = await window.awaitEvent<TableEvents>(table, "selected", () => selectAll.click()) as Parameters<TableEvents["selected"]>
32
32
  return event.detail.length
@@ -71,8 +71,6 @@ export class TableHeaderElement<T>
71
71
  return;
72
72
  }
73
73
  let delta = e.pageX - this._resizeStart?.event.pageX;
74
- let before = this._resizeStart.column.width;
75
- console.log(delta);
76
74
  if (this._resizeStart.column.width) {
77
75
  this._resizeStart.column.width = this._resizeStart.column.width + delta;
78
76
  } else {
@@ -82,7 +80,6 @@ export class TableHeaderElement<T>
82
80
  this._resizeStart.column.width =
83
81
  cell.getBoundingClientRect().width + delta;
84
82
  }
85
- console.log(before, this._resizeStart.column.width);
86
83
  this.dispatchEvent(
87
84
  new CustomEvent("columnResize", { detail: this._resizeStart.column })
88
85
  );
@@ -33,6 +33,7 @@ export enum TableSortDirection {
33
33
  }
34
34
  export type TableSortDirectionTypes = `${TableSortDirection}`
35
35
  export type ColumnSettings<T> = {
36
+ [TABLE_CREATED_SELECTION_COLUMN]?: boolean
36
37
  width?: number
37
38
  /**
38
39
  * Enabled/disables resizing by dragging column header Default true
@@ -73,6 +74,9 @@ interface TableProps<T> extends TableDataOptions<T> {
73
74
  export type DomEvent<T> = Event & {
74
75
  target: T
75
76
  }
77
+
78
+ export const TD_BorderAndPadding = 4;
79
+ const TABLE_CREATED_SELECTION_COLUMN = Symbol("spectric-table-selection-column")
76
80
  /**
77
81
  * React example
78
82
  * <iframe width="100%" height="400px" src="https://stackblitz.com/edit/react-ts-2ue7azag?ctl=1&embed=1&file=App.tsx&hideExplorer=1&hideNavigation=1"/>
@@ -215,6 +219,42 @@ export class SpectricTableElement<T = any> extends LitElement implements TablePr
215
219
  }
216
220
  }
217
221
  protected update(changedProperties: PropertyValues): void {
222
+ if (changedProperties.has("columns")) {
223
+ if (this.select !== TableSelectOptions.none) {
224
+ if (!this.columns.find(col => col[TABLE_CREATED_SELECTION_COLUMN])) {
225
+ this.columns.unshift({
226
+ [TABLE_CREATED_SELECTION_COLUMN]: true,
227
+ title: this.select === "multi" ? html`<spectric-input variant="checkbox" @change=${this._handleSelectAllChange} .helperText=${"Select All"}></spectric-input>` : null,
228
+ render: (row) => {
229
+ let container = document.createElement("div")
230
+ let checked = this.selected.includes(row)
231
+ let template = html`<spectric-input variant="checkbox" class="table-checkbox-${this.select}" .helperText=${""} ${spreadProps({ checked })} @change=${(e: DomEvent<HTMLInputElement>) => {
232
+ e.stopPropagation()
233
+ let index = this.selected.findIndex(value => value === row)
234
+ if (e.target.checked && index !== -1) {
235
+ return
236
+ }
237
+ else if (!e.target.checked && index === -1) {
238
+ return
239
+ }
240
+ else if (!e.target.checked && index !== -1) {
241
+ this.selected.splice(index, 1)
242
+ }
243
+ if (e.target.checked) {
244
+ if (this.select === "single") {
245
+ this.selected = []
246
+ }
247
+ this.selected.push(row)
248
+ }
249
+ this.dispatchEvent(new CustomEvent("selected", { detail: [...this.selected] }))
250
+ }}></spectric-input>`
251
+ render(template, container)
252
+ return template
253
+ }
254
+ })
255
+ }
256
+ }
257
+ }
218
258
  if (changedProperties.has("select")) {
219
259
  if (this.select === "single" && this.selected.length > 1) {
220
260
  this.selected = [this.selected[0]]
@@ -225,41 +265,9 @@ export class SpectricTableElement<T = any> extends LitElement implements TablePr
225
265
  }
226
266
  protected render(): unknown {
227
267
  let columns = this.columns.filter(column => !column.hidden)
228
- if (this.select !== TableSelectOptions.none) {
229
- columns.unshift({
230
- title: this.select === "multi" ? html`<spectric-input variant="checkbox" @change=${this._handleSelectAllChange} .helperText=${"Select All"}></spectric-input>` : null,
231
- render: (row) => {
232
- let container = document.createElement("div")
233
- let checked = this.selected.includes(row)
234
- let template = html`<spectric-input variant="checkbox" class="table-checkbox-${this.select}" ${spreadProps({ checked })} @change=${(e: DomEvent<HTMLInputElement>) => {
235
- e.stopPropagation()
236
- let index = this.selected.findIndex(value => value === row)
237
- if (e.target.checked && index !== -1) {
238
- return
239
- }
240
- else if (!e.target.checked && index === -1) {
241
- return
242
- }
243
- else if (!e.target.checked && index !== -1) {
244
- this.selected.splice(index, 1)
245
- }
246
- if (e.target.checked) {
247
- if (this.select === "single") {
248
- this.selected = []
249
- }
250
- this.selected.push(row)
251
- }
252
- this.dispatchEvent(new CustomEvent("selected", { detail: [...this.selected] }))
253
- }}></spectric-input>`
254
- render(template, container)
255
- return template
256
- }
257
- })
258
- }
259
- const tdBorderAndPadding = 4;
260
- let rowHeight = this.rowHeight - tdBorderAndPadding;
261
- if (rowHeight < this.fontSize + tdBorderAndPadding) {
262
- rowHeight = this.fontSize + tdBorderAndPadding
268
+ let rowHeight = this.rowHeight - TD_BorderAndPadding;
269
+ if (rowHeight < this.fontSize + TD_BorderAndPadding) {
270
+ rowHeight = this.fontSize + TD_BorderAndPadding
263
271
  }
264
272
  return html`
265
273
  <div class="table-wrapper" style="--rowHeight:${rowHeight}px;--fontSize:${this.fontSize}px;--lineClamp:${Math.floor(rowHeight / this.fontSize)}">
@@ -3,7 +3,7 @@ import { customElement, property, } from 'lit/decorators.js';
3
3
  import { HTMLElementTagWithEvents, ReactElementWithPropsAndEvents } from '../types';
4
4
  export const TableBodyElementTag = "spectric-table-virtual-body"
5
5
  import "./cell"
6
- import { ColumnSettings, SpectricTableElement } from './table';
6
+ import { ColumnSettings, SpectricTableElement, TD_BorderAndPadding } from './table';
7
7
  import { repeat } from 'lit/directives/repeat.js';
8
8
  import { DisposableElement } from '../../classes/DisposibleElement';
9
9
  import "./virtualBody.css"
@@ -30,6 +30,7 @@ export class TableVirtualBodyElement<T> extends DisposableElement implements Bod
30
30
  startIndex: number = 0
31
31
 
32
32
  table!: SpectricTableElement<T>
33
+ columnsMeasured: boolean = false;
33
34
  constructor() {
34
35
  super()
35
36
  this.addDisposableListener(() => this.table.querySelector(".table-wrapper")!, "scroll", () => {
@@ -39,12 +40,23 @@ export class TableVirtualBodyElement<T> extends DisposableElement implements Bod
39
40
  })
40
41
  })
41
42
  }
42
- protected firstUpdated(): void {
43
- this.columns.forEach(col => {
44
- if (!col.width) {
45
- console.warn("When using virtual scrolling it is recomended to set the width of the columns to prevent columns widths from jittering during scroll")
43
+ protected updated(): void {
44
+ if (this.columnsMeasured === false) {
45
+ let tr = this.querySelector("tr");
46
+ let cells = tr?.querySelectorAll("spectric-table-cell td")
47
+ if (tr && cells && cells.length) {
48
+ this.columns.forEach((col, index) => {
49
+ if (!col.width || col.width === 0) {
50
+ let rect = cells[index].getBoundingClientRect()
51
+ if (rect.width > 0) {
52
+ this.columnsMeasured = true
53
+ col.width = rect.width - TD_BorderAndPadding
54
+ }
55
+ }
56
+ })
57
+ this.columns = [...this.columns]
46
58
  }
47
- })
59
+ }
48
60
  }
49
61
  protected createRenderRoot(): HTMLElement | DocumentFragment {
50
62
  return this
@@ -1,11 +1,12 @@
1
1
 
2
- import { customElement, property } from 'lit/decorators.js';
2
+ import { customElement, property, query } from 'lit/decorators.js';
3
3
  import "./tooltip.css"
4
4
  export const PopoverElementTag = "spectric-popover"
5
- import { css, CSSResultGroup, html, render } from "lit-element";
5
+ import { css, CSSResultGroup, html } from "lit-element";
6
6
  import { DomRenderable } from "../table";
7
7
  import { DisposableElement } from '../../classes/DisposibleElement';
8
- export type { TooltipProps, TooltipEvents }
8
+ import { HTMLElementTagWithEvents, ReactElementWithPropsAndEvents } from '../types';
9
+ export type { TooltipProps, PopOverEvents }
9
10
  export enum TooltipPostions {
10
11
  top = "top",
11
12
  bottom = "bottom",
@@ -45,6 +46,8 @@ interface TooltipProps {
45
46
  * The element that triggers the tooltip. This is used for special cases like in the shadow dom if you want to target a host element instead of the immediate parent element
46
47
  */
47
48
  triggerTarget?: HTMLElement
49
+ mouseOffsetX?: number
50
+ mouseOffsetY?: number
48
51
  }
49
52
 
50
53
  /**
@@ -62,6 +65,11 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
62
65
  position: TooltipPostionsTypes = "right";
63
66
  @property({ type: Number, reflect: true })
64
67
  maxWidth?: number = 300;
68
+ @property({ type: Number, reflect: false })
69
+ mouseOffsetX = 10
70
+ @property({ type: Number, reflect: false })
71
+ mouseOffsetY = 0
72
+ @query(".spectric-popover-portal")
65
73
  protected portalElement!: HTMLDivElement
66
74
  protected mouseLocation?: { left: number; top: number; };
67
75
  static styles?: CSSResultGroup | undefined = css`:host{max-height: 0px;
@@ -73,6 +81,9 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
73
81
  protected timer?: number;
74
82
  protected open: boolean = false;
75
83
  protected mouseframe?: number;
84
+ isOpen() {
85
+ return this.open
86
+ }
76
87
  /**
77
88
  * @default parentElement
78
89
  */
@@ -90,17 +101,19 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
90
101
  this.hidePopover = this.hidePopover.bind(this)
91
102
  this.addDisposableListener(() => this.target, "mousemove", this._getMousePosition)
92
103
  }
104
+ protected createRenderRoot(): HTMLElement | DocumentFragment {
105
+ return this
106
+ }
93
107
  connectedCallback(): void {
94
108
  super.connectedCallback()
95
- this.portalElement = document.createElement("div")
96
- this.portalElement.className = "spectric-tooltip-portal"
97
- console.log("connected")
109
+ //this.portalElement = document.createElement("div")
110
+ //this.portalElement.className = "spectric-tooltip-portal"
98
111
  }
99
112
  disconnectedCallback(): void {
100
113
  super.disconnectedCallback();
101
- this.portalElement.remove()
114
+ //this.portalElement.remove()
102
115
  //@ts-ignore
103
- this.portalElement = undefined
116
+ //this.portalElement = undefined
104
117
  }
105
118
  protected _getMousePosition = (ev: MouseEvent) => {
106
119
  this.mouseLocation = {
@@ -119,7 +132,7 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
119
132
  clearTimeout(this.timer)
120
133
  }
121
134
  this.open = false
122
- this.portalElement.remove()
135
+ this.portalElement.hidePopover()
123
136
  }
124
137
  /**
125
138
  * Public method to trigger showing the tooltip programatically
@@ -131,18 +144,19 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
131
144
  await new Promise(resolve => {
132
145
  this.timer = window.setTimeout(resolve, this.delay)
133
146
  })
134
- this.portalElement.className = `spectric-popover-portal ${this.position}`
135
- const tooltip = html`<div class="tooltip-container">
136
- <span class="tooltip-caret"></span>
137
- <div class="tooltip-content">${this.text}</div>
138
- </div>`
139
- render(tooltip, this.portalElement)
140
- //with the delay it is possible that the triggering element was removed or hidden lets check that it is visible
141
- if (!this.target || !this.target.checkVisibility()) {
142
- return
143
- }
144
- //We need to append our tooltip and let the css updates apply before we can take measurements
145
- this.portalTarget.appendChild(this.portalElement)
147
+ // this.portalElement.className = `spectric-popover-portal ${this.position}`
148
+ // const tooltip = html`<div class="tooltip-container">
149
+ // <span class="tooltip-caret"></span>
150
+ // <div class="tooltip-content">${this.text}</div>
151
+ // </div>`
152
+ // render(tooltip, this.portalElement)
153
+ // //with the delay it is possible that the triggering element was removed or hidden lets check that it is visible
154
+ // if (!this.target || !this.target.checkVisibility()) {
155
+ // return
156
+ // }
157
+ // //We need to append our tooltip and let the css updates apply before we can take measurements
158
+ // this.portalTarget.appendChild(this.portalElement)
159
+ this.portalElement.showPopover()
146
160
  this.open = true
147
161
  requestAnimationFrame(this.positionTooltip)
148
162
  }
@@ -157,13 +171,9 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
157
171
  return
158
172
  }
159
173
  //Since we are attaching to a body we need to send the correct styles from the target portion of the dom to the portal element
160
- let computedStyle = getComputedStyle(this)
161
- let styles = {
162
- "--spectric-primary": computedStyle.getPropertyValue("--spectric-primary"),
163
- "--spectric-background-inverse": computedStyle.getPropertyValue("--spectric-background-inverse"),
164
- "--spectric-background-hover": computedStyle.getPropertyValue("--spectric-background-hover"),
165
- "--spectric-text-on-color": computedStyle.getPropertyValue("--spectric-text-on-color"),
166
- "--spectric-border-radius": computedStyle.getPropertyValue("--spectric-border-radius"),
174
+
175
+ let styles: Record<string, string> = {
176
+
167
177
  }
168
178
  const bounds = this.target.getBoundingClientRect()
169
179
  const portalBounds = this.portalElement.getBoundingClientRect()
@@ -178,7 +188,7 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
178
188
  };
179
189
  if (this.position === "mouse" && this.mouseLocation) {
180
190
  this.mouseframe = undefined
181
- location = { left: this.mouseLocation.left + 10 + "px", top: this.mouseLocation.top - (portalBounds.height / 2) + "px" }
191
+ location = { left: this.mouseLocation.left + this.mouseOffsetX + "px", top: this.mouseLocation.top + this.mouseOffsetY - (portalBounds.height / 2) + "px" }
182
192
  } else if (this.position === "top") {
183
193
  location = {
184
194
  top: bounds.top - portalBounds.height + "px",
@@ -209,13 +219,43 @@ export class PopoverElement extends DisposableElement implements TooltipProps {
209
219
  }
210
220
  }
211
221
  protected render() {
212
- //We don't need to render anything here this is just a placeholder element the content is displayed in a portal attached to the body.
213
- // See showTooltip for the real rendering
214
- return html`<!-- ToolTip -->`
222
+ return html`<!-- ToolTip -->
223
+ <div class="spectric-popover-portal ${this.position}" popover>
224
+ <div class="tooltip-container">
225
+ <span class="tooltip-caret"></span>
226
+ <div class="tooltip-content">${this.text}<slot></slot></div>
227
+ </div>
228
+ </div>`
215
229
  }
216
230
  }
217
231
 
218
- interface TooltipEvents {
232
+ interface PopOverEvents {
219
233
  //'open': (event: CustomEvent<{ pagination: PaginationChangeProps }>) => void;
220
234
  //'filter': (event: CustomEvent<FilterEvent>) => void;
221
235
  }
236
+
237
+
238
+ declare global {
239
+ interface HTMLElementTagNameMap {
240
+ [PopoverElementTag]: HTMLElementTagWithEvents<PopoverElement, PopOverEvents>
241
+
242
+ }
243
+ namespace JSX {
244
+ interface IntrinsicElements {
245
+ /**
246
+ * @see {@link TooltipElement}
247
+ */
248
+ [PopoverElementTag]: ReactElementWithPropsAndEvents<PopoverElement, TooltipProps, PopOverEvents>;
249
+ }
250
+ }
251
+ namespace React {
252
+ namespace JSX {
253
+ interface IntrinsicElements {
254
+ /**
255
+ * @see {@link TooltipElement}
256
+ */
257
+ [PopoverElementTag]: ReactElementWithPropsAndEvents<PopoverElement, TooltipProps, PopOverEvents>
258
+ }
259
+ }
260
+ }
261
+ }
@@ -1,8 +1,13 @@
1
1
  .spectric-popover-portal{
2
+ margin: 0px;
3
+ border: 0px;
4
+ padding: 0px;
2
5
  position: fixed;
3
6
  z-index: 9999;
4
- --spectric-tooltip-background-color: var(--spectric-tooltip-background, #000000);
5
- --spectric-tooltip-text-color: var(--spectric-tooltip-text, var(--spectric-text-primary, white));
7
+ background: transparent;
8
+ pointer-events: all;
9
+ --spectric-tooltip-background-color: var(--spectric-tooltip-background, var(--spectric-background,#ffffff));
10
+ --spectric-tooltip-text-color: var(--spectric-tooltip-text, var(--spectric-text-primary, rgb(0, 0, 0)));
6
11
  --spectric-tooltip-accent-color: var(--spectric-tooltip-accent, var(--spectric-primary, #1ea7fd));
7
12
  }
8
13
  .spectric-popover-portal.spectric-tooltip-portal{
@@ -3,9 +3,9 @@ import { customElement, property } from 'lit/decorators.js';
3
3
  import { HTMLElementTagWithEvents, ReactElementWithPropsAndEvents } from '../types';
4
4
  import "./tooltip.css"
5
5
  export const TooltipElementTag = "spectric-tooltip"
6
- import { css, CSSResultGroup, html } from "lit-element";
6
+ import { css, CSSResultGroup } from "lit-element";
7
7
  import { DomRenderable } from "../table";
8
- import { PopoverElement } from './popover';
8
+ import { PopoverElement, TooltipProps } from './popover';
9
9
  export type { TooltipProps, TooltipEvents }
10
10
  export enum TooltipPostions {
11
11
  top = "top",
@@ -16,37 +16,7 @@ export enum TooltipPostions {
16
16
  }
17
17
 
18
18
  export type TooltipPostionsTypes = `${TooltipPostions}`
19
- interface TooltipProps {
20
- /**
21
- * How long you need to hover before the tooltip displays
22
- */
23
- delay?: number;
24
- /**
25
- * How long the fade in animation should run
26
- */
27
- animationDuration?: number;
28
- /**
29
- * Tooltip contents
30
- */
31
- text: DomRenderable
32
- /**
33
- * Where to anchor the tooltip
34
- */
35
- position?: TooltipPostionsTypes
36
- /**
37
- * Sets a max width for the contents you can disable this by setting to 0 or -1
38
- */
39
- maxWidth?: number
40
- /**
41
- * Container the tool tip will be attached to.
42
- */
43
- portalTarget?: HTMLElement
44
19
 
45
- /**
46
- * The element that triggers the tooltip. This is used for special cases like in the shadow dom if you want to target a host element instead of the immediate parent element
47
- */
48
- triggerTarget?: HTMLElement
49
- }
50
20
 
51
21
  /**
52
22
  * Spectric tooltip will add a tooltip to any container
@@ -81,6 +51,7 @@ export class TooltipElement extends PopoverElement implements TooltipProps {
81
51
  triggerTarget!: HTMLElement;
82
52
  constructor() {
83
53
  super()
54
+ this.showToolTip = this.showToolTip.bind(this)
84
55
  this.addDisposableListener(() => this.target, "mouseover", this.showToolTip)
85
56
  this.addDisposableListener(() => this.target, "mouseleave", this.hidePopover)
86
57
  }
@@ -93,11 +64,7 @@ export class TooltipElement extends PopoverElement implements TooltipProps {
93
64
  this.portalElement.classList.add("spectric-tooltip-portal")
94
65
  }
95
66
 
96
- protected render() {
97
- //We don't need to render anything here this is just a placeholder element the content is displayed in a portal attached to the body.
98
- // See showTooltip for the real rendering
99
- return html`<!-- ToolTip -->`
100
- }
67
+
101
68
  }
102
69
 
103
70
 
@@ -0,0 +1,70 @@
1
+ import type { Meta, StoryObj } from "@storybook/web-components";
2
+
3
+ import { type SpectricCalendarProps as Props } from "../components/calendar";
4
+ import { html } from "lit";
5
+ import '../components';
6
+ import { useArgs } from "@storybook/client-api";
7
+ import { ifDefined } from "lit/directives/if-defined.js";
8
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
9
+ const meta = {
10
+ title: "UI/Calendar",
11
+ tags: ["autodocs"],
12
+ component: "spectric-calendar",
13
+ render: (args) => {
14
+ const [_, updateArgs] = useArgs();
15
+
16
+ return html`
17
+ <spectric-calendar
18
+ ?popup=${args.popup}
19
+ ?disabled=${args.disabled}
20
+ .currentDate=${args.currentDate}
21
+ @select=${(e: CustomEvent<Date>) => {
22
+ updateArgs({ ...e.detail });
23
+ }}
24
+ >
25
+ </spectric-calendar>
26
+ `;
27
+ },
28
+ argTypes: {
29
+ popup: {
30
+ control: { type: 'boolean' },
31
+ },
32
+ disabled: {
33
+ control: { type: 'boolean' },
34
+ },
35
+ currentDate: {
36
+ control: { type: "date" }
37
+ }
38
+ },
39
+ args: {
40
+ popup: false,
41
+ disabled: false,
42
+ currentDate: new Date()
43
+ },
44
+ } satisfies Meta<Props>;
45
+
46
+ export default meta;
47
+ type Story = StoryObj<Props>;
48
+
49
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
50
+ export const Basic: Story = {
51
+ args: {
52
+ popup: false,
53
+ currentDate: new Date()
54
+ },
55
+ };
56
+ export const Popup: Story = {
57
+ args: {
58
+ popup: true,
59
+ currentDate: new Date()
60
+ },
61
+ };
62
+ /**
63
+ * When the total items is unknown pagination will only shows page size
64
+ */
65
+ export const Disabled: Story = {
66
+ args: {
67
+ disabled: true,
68
+ currentDate: new Date()
69
+ },
70
+ };
@@ -127,10 +127,11 @@ export class SpectricStorybookExampleContent extends LitElement implements Props
127
127
  <spectric-button size="small" >Submit</spectric-button><spectric-button size="small" variant="secondary">Continue</spectric-button><spectric-button size="small" variant="text">Cancel</spectric-button>
128
128
  </spectric-panel>
129
129
  </spectric-splitview>
130
-
130
+ <spectric-calendar></spectric-calendar>
131
131
  </spectric-panel>
132
132
  <div style="display:flex">
133
133
  <span style="flex-grow:1"></span>
134
+ <spectric-input variant="color" .value=${"#00FF00"}></spectric-input>
134
135
  <spectric-button size="small" danger @click=${() => {
135
136
  this.dialogOpen = true
136
137
  this.requestUpdate()
@@ -27,12 +27,11 @@ const meta = {
27
27
  select=${ifDefined(args.select)}
28
28
  sort=${ifDefined(args.sort)}
29
29
  rowHeight=${ifDefined(args.rowHeight)}
30
- @selected=${(e) => console.log(e)}
30
+ @selected=${(e) => { }}
31
31
  @filter=${(e: CustomEvent<FilterEvent<any>>) => {
32
32
  alert(`filter ${e.detail.include ? "for" : "out"} event value ${e.detail.value}`)
33
33
  }}
34
34
  @change=${(e: CustomEvent<TableDataOptions<typeof tabledata[0]>>) => {
35
- console.log(e)
36
35
  updateArgs({ ...e.detail });
37
36
  if (e.target && e.target instanceof SpectricTableElement) {
38
37
  e.target.data = getData({ ...args, ...e.detail })
@@ -20,8 +20,10 @@ const meta = {
20
20
  <spectric-tooltip
21
21
  position=${p}
22
22
  text=${args.text || p}
23
- delay=${args.delay}
23
+ delay=${ifDefined(args.delay)}
24
24
  animationDuration=${ifDefined(args.animationDuration)}
25
+ mouseOffsetX=${ifDefined(args.mouseOffsetX)}
26
+ mouseOffsetY=${ifDefined(args.mouseOffsetY)}
25
27
  >
26
28
  </spectric-tooltip>
27
29
  ${p}
@@ -31,7 +33,12 @@ const meta = {
31
33
  })}
32
34
  `;
33
35
  },
34
- argTypes: {},
36
+ argTypes: {
37
+ mouseOffsetX: { "control": { "type": "number" } },
38
+ mouseOffsetY: { "control": { "type": "number" } },
39
+ maxWidth: { "control": { "type": "number" } },
40
+ text: { "control": { "type": "text" } }
41
+ },
35
42
  args: {
36
43
  animationDuration: 500,
37
44
  delay: 100