@spectric/ui 0.0.16 → 0.0.18
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/classes/DisposibleElement.d.ts +1 -0
- package/dist/classes/index.d.ts +2 -0
- package/dist/components/ThemeProvider.d.ts +1 -0
- package/dist/components/color_picker/ColorPicker.d.ts +59 -0
- package/dist/components/color_picker/index.d.ts +0 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/input.d.ts +3 -1
- package/dist/components/pagination/pagination.d.ts +1 -1
- package/dist/components/table/body.d.ts +2 -2
- package/dist/components/table/cell.d.ts +2 -2
- package/dist/components/table/header.d.ts +9 -3
- package/dist/components/table/table.d.ts +18 -6
- package/dist/components/table/virtualBody.d.ts +4 -3
- package/dist/components/tooltip/popover.d.ts +85 -0
- package/dist/components/tooltip/tooltip.d.ts +14 -15
- package/dist/custom-elements.json +83 -8
- package/dist/index.d.ts +59 -0
- package/dist/index.es.js +2675 -2245
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +189 -135
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/utils/index.d.ts +3 -0
- package/package.json +6 -2
- package/src/classes/DisposibleElement.ts +3 -0
- package/src/classes/index.ts +2 -0
- package/src/components/Button.ts +1 -1
- package/src/components/ThemeProvider.ts +34 -1
- package/src/components/button.css.ts +2 -2
- package/src/components/color_picker/ColorPicker.css +40 -0
- package/src/components/color_picker/ColorPicker.ts +268 -0
- package/src/components/color_picker/index.ts +1 -0
- package/src/components/index.ts +3 -1
- package/src/components/input.css +10 -2
- package/src/components/input.ts +38 -9
- package/src/components/pagination/pagination.ts +2 -2
- package/src/components/table/__tests__/table.spec.ts +91 -0
- package/src/components/table/body.ts +2 -2
- package/src/components/table/cell.ts +11 -5
- package/src/components/table/header.css +54 -0
- package/src/components/table/header.ts +141 -49
- package/src/components/table/table.css +11 -34
- package/src/components/table/table.ts +51 -17
- package/src/components/table/virtualBody.ts +18 -7
- package/src/components/tooltip/popover.ts +221 -0
- package/src/components/tooltip/tooltip.css +21 -16
- package/src/components/tooltip/tooltip.ts +18 -124
- package/src/index.ts +8 -1
- package/src/stories/fixtures/ExampleContent.ts +4 -3
- package/src/stories/table.stories.ts +6 -7
- package/src/utils/index.ts +3 -0
|
@@ -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
|
|
6
|
+
import { css, CSSResultGroup, html } from "lit-element";
|
|
7
7
|
import { DomRenderable } from "../table";
|
|
8
|
-
import {
|
|
8
|
+
import { PopoverElement } from './popover';
|
|
9
9
|
export type { TooltipProps, TooltipEvents }
|
|
10
10
|
export enum TooltipPostions {
|
|
11
11
|
top = "top",
|
|
@@ -52,7 +52,7 @@ interface TooltipProps {
|
|
|
52
52
|
* Spectric tooltip will add a tooltip to any container
|
|
53
53
|
*/
|
|
54
54
|
@customElement(TooltipElementTag)
|
|
55
|
-
export class TooltipElement extends
|
|
55
|
+
export class TooltipElement extends PopoverElement implements TooltipProps {
|
|
56
56
|
@property({ type: Number, reflect: true })
|
|
57
57
|
delay: number = 100;
|
|
58
58
|
@property({ type: Number, reflect: true })
|
|
@@ -63,143 +63,37 @@ export class TooltipElement extends DisposableElement implements TooltipProps {
|
|
|
63
63
|
position: TooltipPostionsTypes = "right";
|
|
64
64
|
@property({ type: Number, reflect: true })
|
|
65
65
|
maxWidth?: number = 300;
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
portalElement!: HTMLDivElement
|
|
67
|
+
mouseLocation?: { left: number; top: number; };
|
|
68
68
|
static styles?: CSSResultGroup | undefined = css`:host{max-height: 0px;
|
|
69
69
|
max-width: 0px;
|
|
70
70
|
display: none;
|
|
71
71
|
pointer-events:none;}`;
|
|
72
72
|
@property({ attribute: false })
|
|
73
73
|
portalTarget: HTMLElement = document.body
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
timer?: number;
|
|
75
|
+
open: boolean = false;
|
|
76
|
+
mouseframe?: number;
|
|
77
77
|
/**
|
|
78
78
|
* @default parentElement
|
|
79
79
|
*/
|
|
80
80
|
@property({ attribute: false })
|
|
81
81
|
triggerTarget!: HTMLElement;
|
|
82
|
-
private get target() {
|
|
83
|
-
return this.triggerTarget || this.parentElement
|
|
84
|
-
}
|
|
85
82
|
constructor() {
|
|
86
83
|
super()
|
|
87
|
-
this.
|
|
84
|
+
this.showToolTip = this.showToolTip.bind(this)
|
|
88
85
|
this.addDisposableListener(() => this.target, "mouseover", this.showToolTip)
|
|
89
|
-
this.addDisposableListener(() => this.target, "mouseleave", this.
|
|
90
|
-
}
|
|
91
|
-
connectedCallback(): void {
|
|
92
|
-
super.connectedCallback()
|
|
93
|
-
this.portalElement = document.createElement("div")
|
|
94
|
-
this.portalElement.className = "spectric-tooltip-portal"
|
|
86
|
+
this.addDisposableListener(() => this.target, "mouseleave", this.hidePopover)
|
|
95
87
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.mouseLocation = {
|
|
104
|
-
left: ev.clientX,
|
|
105
|
-
top: ev.clientY
|
|
106
|
-
}
|
|
107
|
-
if (this.position == "mouse" && this.open && !this.mouseframe) {
|
|
108
|
-
this.mouseframe = requestAnimationFrame(() => this.positionTooltip())
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
_hideTooltip = () => {
|
|
112
|
-
if (this.timer) {
|
|
113
|
-
clearTimeout(this.timer)
|
|
114
|
-
}
|
|
115
|
-
this.open = false
|
|
116
|
-
this.portalElement.remove()
|
|
117
|
-
}
|
|
118
|
-
private showToolTip = async () => {
|
|
119
|
-
if (this.timer) {
|
|
120
|
-
clearTimeout(this.timer)
|
|
121
|
-
}
|
|
122
|
-
await new Promise(resolve => {
|
|
123
|
-
this.timer = window.setTimeout(resolve, this.delay)
|
|
124
|
-
})
|
|
125
|
-
this.portalElement.style.pointerEvents = "none"
|
|
126
|
-
this.portalElement.className = `spectric-tooltip-portal ${this.position}`
|
|
127
|
-
const tooltip = html`<div class="tooltip-container">
|
|
128
|
-
<span class="tooltip-caret"></span>
|
|
129
|
-
<div class="tooltip-content">${this.text}</div>
|
|
130
|
-
</div>`
|
|
131
|
-
render(tooltip, this.portalElement)
|
|
132
|
-
//with the delay it is possible that the triggering element was removed or hidden lets check that it is visible
|
|
133
|
-
if (!this.target || !this.target.checkVisibility()) {
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
//We need to append our tooltip and let the css updates apply before we can take measurements
|
|
137
|
-
this.portalTarget.appendChild(this.portalElement)
|
|
138
|
-
this.open = true
|
|
139
|
-
requestAnimationFrame(this.positionTooltip)
|
|
140
|
-
}
|
|
141
|
-
private applyStyle = (style: Record<string, string>) => {
|
|
142
|
-
Object.entries(style).forEach(([prop, value]) => {
|
|
143
|
-
this.portalElement.style.setProperty(prop, value)
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
private positionTooltip = () => {
|
|
147
|
-
if (!this.target) {
|
|
148
|
-
//We got detached before the animation frame completed
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
//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
|
|
152
|
-
let computedStyle = getComputedStyle(this)
|
|
153
|
-
let styles = {
|
|
154
|
-
"--spectric-primary": computedStyle.getPropertyValue("--spectric-primary"),
|
|
155
|
-
"--spectric-background-inverse": computedStyle.getPropertyValue("--spectric-background-inverse"),
|
|
156
|
-
"--spectric-background-hover": computedStyle.getPropertyValue("--spectric-background-hover"),
|
|
157
|
-
"--spectric-text-on-color": computedStyle.getPropertyValue("--spectric-text-on-color"),
|
|
158
|
-
"--spectric-border-radius": computedStyle.getPropertyValue("--spectric-border-radius"),
|
|
159
|
-
}
|
|
160
|
-
const bounds = this.target.getBoundingClientRect()
|
|
161
|
-
const portalBounds = this.portalElement.getBoundingClientRect()
|
|
162
|
-
if (this.target !== document.body) {
|
|
163
|
-
if (this.maxWidth && this.maxWidth > 0) {
|
|
164
|
-
portalBounds.width = Math.min(portalBounds.width, this.maxWidth)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
let location: {
|
|
168
|
-
left: string;
|
|
169
|
-
top: string;
|
|
170
|
-
};
|
|
171
|
-
if (this.position === "mouse" && this.mouseLocation) {
|
|
172
|
-
this.mouseframe = undefined
|
|
173
|
-
location = { left: this.mouseLocation.left + 10 + "px", top: this.mouseLocation.top - (portalBounds.height / 2) + "px" }
|
|
174
|
-
} else if (this.position === "top") {
|
|
175
|
-
location = {
|
|
176
|
-
top: bounds.top - portalBounds.height + "px",
|
|
177
|
-
left: (bounds.left + (bounds.width / 2)) - (portalBounds.width / 2) + "px"
|
|
178
|
-
}
|
|
179
|
-
} else if (this.position === "bottom") {
|
|
180
|
-
location = {
|
|
181
|
-
top: bounds.bottom + "px",
|
|
182
|
-
left: (bounds.left + (bounds.width / 2)) - (portalBounds.width / 2) + "px"
|
|
183
|
-
}
|
|
184
|
-
} else if (this.position === "left") {
|
|
185
|
-
location = {
|
|
186
|
-
top: Math.max(0, bounds.top + bounds.height / 2 - portalBounds.height / 2) + "px",
|
|
187
|
-
left: bounds.left - (portalBounds.width) + "px"
|
|
188
|
-
}
|
|
189
|
-
} else if (this.position === "right") {
|
|
190
|
-
location = {
|
|
191
|
-
top: Math.max(0, bounds.top + bounds.height / 2 - portalBounds.height / 2) + "px",
|
|
192
|
-
left: bounds.right + "px"
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
location = { left: "0px", top: "0px" };
|
|
196
|
-
console.error("Unknown position... Maybe we sould implement auto?")
|
|
197
|
-
}
|
|
198
|
-
this.applyStyle({ ...styles, ...location })
|
|
199
|
-
if (this.position !== "mouse") {
|
|
200
|
-
this.portalElement.animate({ opacity: [0, 1] }, { duration: this.animationDuration })
|
|
201
|
-
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Public method to trigger showing the tooltip programatically
|
|
91
|
+
*/
|
|
92
|
+
public async showToolTip() {
|
|
93
|
+
await super.showPopover()
|
|
94
|
+
this.portalElement.classList.add("spectric-tooltip-portal")
|
|
202
95
|
}
|
|
96
|
+
|
|
203
97
|
protected render() {
|
|
204
98
|
//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.
|
|
205
99
|
// See showTooltip for the real rendering
|
package/src/index.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export * from "./components"
|
|
1
|
+
export * from "./components"
|
|
2
|
+
export * from "./classes"
|
|
3
|
+
export * from "./utils"
|
|
4
|
+
import * as classes from "./classes"
|
|
5
|
+
import * as components from "./components"
|
|
6
|
+
import * as utils from "./utils"
|
|
7
|
+
const module = { ...classes, ...components, ...utils }
|
|
8
|
+
export default module
|
|
@@ -7,9 +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 {
|
|
10
|
+
import { PaginationProps } from "../../components/pagination";
|
|
11
11
|
import { FilterEvent } from "../../components/table/cell";
|
|
12
|
-
import { TableDataOptions,
|
|
12
|
+
import { TableDataOptions, SpectricTableElement } from "../../components/table";
|
|
13
13
|
type Props = {
|
|
14
14
|
frameWidth: number
|
|
15
15
|
}
|
|
@@ -24,7 +24,7 @@ export class SpectricStorybookExampleContent extends LitElement implements Props
|
|
|
24
24
|
@query("spectric-query")
|
|
25
25
|
query!: SpectricQuery
|
|
26
26
|
|
|
27
|
-
private dataSorter =
|
|
27
|
+
private dataSorter = SpectricTableElement.getDefaultDataSorterAndPaginatior<TestData>(tabledata)
|
|
28
28
|
@state()
|
|
29
29
|
dialogOpen: boolean = false;
|
|
30
30
|
get tableData() {
|
|
@@ -131,6 +131,7 @@ export class SpectricStorybookExampleContent extends LitElement implements Props
|
|
|
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()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/web-components";
|
|
2
2
|
|
|
3
|
-
import { ColumnSettings, PaginationChangeProps, TableElement, TableSelectOptions, TableSortDirection, TableSortOption, 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
|
-
import
|
|
5
|
+
import { ColumnSettings, PaginationChangeProps, SpectricTableElement, TableDataOptions, TableSelectOptions, TableSortDirection, TableSortOption, type TableProps as Props } from "../index"
|
|
6
6
|
import { ifDefined } from "lit/directives/if-defined.js";
|
|
7
7
|
import { useArgs } from "@storybook/client-api";
|
|
8
8
|
import { FilterEvent, rowGetValue } from "../components/table/cell";
|
|
@@ -10,7 +10,7 @@ import { tablecolumns, tabledata } from "./fixtures/data";
|
|
|
10
10
|
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
|
|
11
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 =
|
|
13
|
+
const getData = SpectricTableElement.getDefaultDataSorterAndPaginatior<typeof tabledata[0]>(data)
|
|
14
14
|
const meta = {
|
|
15
15
|
title: "UI/Table",
|
|
16
16
|
tags: ["autodocs"],
|
|
@@ -27,14 +27,13 @@ const meta = {
|
|
|
27
27
|
select=${ifDefined(args.select)}
|
|
28
28
|
sort=${ifDefined(args.sort)}
|
|
29
29
|
rowHeight=${ifDefined(args.rowHeight)}
|
|
30
|
-
@selected=${(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
|
-
@change=${(e: CustomEvent<
|
|
35
|
-
console.log(e)
|
|
34
|
+
@change=${(e: CustomEvent<TableDataOptions<typeof tabledata[0]>>) => {
|
|
36
35
|
updateArgs({ ...e.detail });
|
|
37
|
-
if (e.target && e.target instanceof
|
|
36
|
+
if (e.target && e.target instanceof SpectricTableElement) {
|
|
38
37
|
e.target.data = getData({ ...args, ...e.detail })
|
|
39
38
|
}
|
|
40
39
|
}}
|