@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
@@ -1,5 +1,5 @@
1
1
  import { html, LitElement, PropertyValues, TemplateResult } from 'lit';
2
- import { customElement, property, state } from 'lit/decorators.js';
2
+ import { customElement, eventOptions, property, state } from 'lit/decorators.js';
3
3
  import { HTMLElementTagWithEvents, ReactElementWithPropsAndEvents } from '../types';
4
4
  import { PopoverElement } from '../tooltip/popover';
5
5
  import { createRef, ref } from 'lit/directives/ref.js';
@@ -12,6 +12,23 @@ export interface ColorPickerProps {
12
12
  showAlpha?: boolean
13
13
  }
14
14
 
15
+ //Not all browsers support eyedropper
16
+ interface EyeDropper {
17
+ new(): EyeDropper;
18
+
19
+ /**
20
+ * Opens the eyedropper mode, allowing the user to select a color from the screen.
21
+ * Returns a Promise that resolves with an object containing the selected color in sRGB hexadecimal format.
22
+ * The Promise rejects if the user cancels the eyedropper mode (e.g., by pressing Escape).
23
+ */
24
+ open(): Promise<{ sRGBHex: string }>;
25
+ }
26
+
27
+ declare var EyeDropper: EyeDropper;
28
+ let eyedropper: EyeDropper | undefined
29
+ if (window.hasOwnProperty("EyeDropper")) {
30
+ eyedropper = new EyeDropper()
31
+ }
15
32
  @customElement('spectric-colorpicker')
16
33
  export class SpectricColorPicker extends LitElement implements ColorPickerProps {
17
34
  @property({ type: String, reflect: true })
@@ -34,7 +51,15 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
34
51
  protected createRenderRoot(): HTMLElement | DocumentFragment {
35
52
  return this
36
53
  }
54
+ constructor() {
55
+ super()
56
+ this._handleAlphaChange = this._handleAlphaChange.bind(this)
57
+ this._handleHueChange = this._handleHueChange.bind(this)
58
+ this._handleApply = this._handleApply.bind(this)
59
+ this._cancel = this._cancel.bind(this)
60
+ this._handleSaturationLightnessClick = this._handleSaturationLightnessClick.bind(this)
37
61
 
62
+ }
38
63
  protected update(changedProperties: PropertyValues): void {
39
64
  if (changedProperties.has("value")) {
40
65
  let { h, s, l, a } = hexToHsl(this.value)
@@ -47,7 +72,6 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
47
72
  super.update(changedProperties)
48
73
  }
49
74
  private renderHueSaturationGrid() {
50
- console.log("canvas render")
51
75
  if (!this.canvas.value) {
52
76
  return
53
77
  }
@@ -69,7 +93,8 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
69
93
  y += ypix;
70
94
  }
71
95
  }
72
- _handleSaturationLightnessClick = (e: PointerEvent) => {
96
+ @eventOptions({ capture: true })
97
+ _handleSaturationLightnessClick(e: PointerEvent) {
73
98
  if (!this.canvas.value) {
74
99
  return
75
100
  }
@@ -78,33 +103,44 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
78
103
  this.lightness = (this.canvas.value.height - offsetY) / this.canvas.value.height
79
104
  this.updateValue()
80
105
  }
81
- _handleHueChange = (e: DomEvent<SpectricInput>) => {
106
+ @eventOptions({ capture: true })
107
+ _handleHueChange(e: DomEvent<SpectricInput>) {
108
+ e.stopPropagation()
82
109
  this.hue = (parseInt(String(e.target.value)) / 100) * 360
83
110
  e.target.style.setProperty("accent-color", `hsl(${this.hue}deg 100% 50%)`)
84
111
  this.renderHueSaturationGrid()
85
112
  this.updateValue()
86
113
  }
87
114
  private updateValue() {
88
- this.value = hslToHex(this.hue, this.saturation * 100, this.lightness * 100) + (Math.round(this.alpha * 255).toString(16).padStart(2, "0"))
115
+ let hex = hslToHex(this.hue, this.saturation * 100, this.lightness * 100) + (Math.round(this.alpha * 255).toString(16).padStart(2, "0"))
116
+ this.value = hex
89
117
  }
90
- _handleAlphaChange = (e: DomEvent<SpectricInput>) => {
118
+ @eventOptions({ capture: true })
119
+ _handleAlphaChange(e: DomEvent<SpectricInput>) {
120
+ e.stopPropagation()
91
121
  this.alpha = parseInt(String(e.target.value)) / 100
92
- console.log(this.alpha, e)
93
122
  this.updateValue()
94
123
  }
95
- _handleApply = () => {
96
- console.log(this.hue, this.saturation, this.lightness, this.alpha)
124
+ @eventOptions({ capture: true })
125
+ _handleApply() {
97
126
  this.updateValue()
98
- console.log(this.value)
99
127
  this.querySelector<PopoverElement>("spectric-popover")?.hidePopover()
128
+ this.dispatchEvent(new Event("change", { bubbles: true }))
100
129
  }
101
- _cancel = () => {
130
+ @eventOptions({ capture: true })
131
+ _cancel() {
102
132
  if (this.original) {
103
133
  this.value = this.original
104
134
  }
105
135
  this.querySelector<PopoverElement>("spectric-popover")?.hidePopover()
136
+ this.dispatchEvent(new Event("cancel"))
106
137
  }
107
- _openPopover = async () => {
138
+ @eventOptions({ capture: true })
139
+ async _openPopover() {
140
+ let popover = this.querySelector<PopoverElement>("spectric-popover")
141
+ if (!popover || popover.isOpen()) {
142
+ return
143
+ }
108
144
  this.original = this.value
109
145
  this.querySelector<PopoverElement>("spectric-popover")?.showPopover()
110
146
  while (!this.canvas.value) {
@@ -115,13 +151,32 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
115
151
  protected getPopover(): TemplateResult {
116
152
  return html`
117
153
  <spectric-input label="Hue" class="hue-gradient" variant="range" .value=${this.hue || 0} style="accent-color:hsl(${this.hue}deg 100% 50%)" @change=${this._handleHueChange}></spectric-input>
118
- <canvas ${ref(this.canvas)} width=200 height=100 class="saturation-lightness-grid" @click=${this._handleSaturationLightnessClick}
119
- @mousedown=${() => { this.sldown = true }}
120
- @mouseup=${() => this.sldown = false}
154
+ <canvas ${ref(this.canvas)} width=200 height=100 class="color-picker-saturation-lightness-grid" @click=${this._handleSaturationLightnessClick}
155
+ @mousedown=${(e: MouseEvent) => {
156
+ this.sldown = true
157
+ e.preventDefault()
158
+ e.stopPropagation()
159
+ }}
160
+ @mouseup=${(e: MouseEvent) => {
161
+ this.sldown = false
162
+ e.preventDefault()
163
+ e.stopPropagation()
164
+ }}
121
165
  @mousemove=${(e: PointerEvent) => { if (this.sldown) { this._handleSaturationLightnessClick(e) } }}
122
166
  ></canvas>
123
167
  <spectric-input class="alpha-gradient" ?hidden=${!this.showAlpha} label="Opacity" variant="range" .value=${(this.alpha || 1) * 100} @change=${this._handleAlphaChange}></spectric-input>
124
168
  <div class="color-picker-footer">
169
+ <spectric-button icon class="color-picker-eyedropper ${eyedropper === undefined ? "hidden" : ""}" @click=${async () => {
170
+ if (eyedropper) {
171
+ let result = await eyedropper?.open()
172
+ let { h, s, l, a } = hexToHsl(result.sRGBHex);
173
+ this.hue = h
174
+ this.saturation = s
175
+ this.lightness = l
176
+ this.alpha = a
177
+ this.updateValue()
178
+ }
179
+ }}>${eyedropper_icon}</spectric-button>
125
180
  <spectric-button @click=${this._handleApply}>Apply</spectric-button>
126
181
  <spectric-button variant="secondary" @click=${this._cancel}>Cancel</spectric-button>
127
182
  </div>
@@ -130,14 +185,14 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
130
185
 
131
186
  protected render(): unknown {
132
187
  return html`
133
- <spectric-button variant="text" @click=${this._openPopover}>
188
+ <spectric-button variant="secondary" @click=${this._openPopover} icon>
134
189
  <spectric-popover .text=${this.getPopover()} icon variant="text"></spectric-popover>
135
190
  <div style="width:15px;height:15px;background-color:${this.value}"></div>
136
191
  </spectric-button>
137
192
  `;
138
193
  }
139
194
  }
140
-
195
+ const eyedropper_icon = html`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" height="15" width="15" fill="currentColor"><path d="M222,67.34a33.81,33.81,0,0,0-10.64-24.25C198.12,30.56,176.68,31,163.54,44.18L142.82,65l-.63-.63a22,22,0,0,0-31.11,0l-9,9a14,14,0,0,0,0,19.81l3.47,3.47L53.14,149.1a37.79,37.79,0,0,0-9.84,36.73l-8.31,19a11.68,11.68,0,0,0,2.46,13A13.91,13.91,0,0,0,47.32,222,14.15,14.15,0,0,0,53,220.82L71,212.92a37.92,37.92,0,0,0,35.84-10.07l52.44-52.46,3.47,3.48a14,14,0,0,0,19.8,0l9-9a22,22,0,0,0,0-31.12l-.66-.66L212,91.85A33.76,33.76,0,0,0,222,67.34Zm-123.61,127a26,26,0,0,1-26,6.47,6,6,0,0,0-4.16.24l-20,8.75a2,2,0,0,1-2.09-.31l9.12-20.9a5.94,5.94,0,0,0,.19-4.31,25.88,25.88,0,0,1,6.26-26.72l52.44-52.45,36.76,36.78Zm105.16-111L178.17,108.9a6,6,0,0,0,0,8.47l4.88,4.89a10,10,0,0,1,0,14.15l-9,9a2,2,0,0,1-2.82,0l-60.69-60.7a2,2,0,0,1,0-2.83l9-9a10,10,0,0,1,14.14,0l4.89,4.89a6,6,0,0,0,4.24,1.75h0a6,6,0,0,0,4.25-1.77L172,52.66c8.58-8.58,22.52-9,31.08-.85a22,22,0,0,1,.44,31.57Z"/></svg>`
141
196
  function* hslGen(hue: number) {
142
197
  for (let l = 100; l >= 0; l--) {
143
198
  for (let s = 0; s <= 100; s++) {
@@ -12,4 +12,5 @@ export * from "./pagination"
12
12
  export * from "./table"
13
13
  export * from "./tooltip"
14
14
  export * from "./types"
15
- export * from "./color_picker"
15
+ export * from "./color_picker"
16
+ export * from "./calendar"
@@ -14,39 +14,6 @@ spectric-input {
14
14
  spectric-input .inputWrapper {
15
15
  color: var(--text-secondary)
16
16
  }
17
- spectric-input.hue-gradient input[type="range"]::-webkit-slider-runnable-track {
18
- background: linear-gradient(
19
- to right,
20
- hsl(0, 100%, 50%), /* Red */
21
- hsl(60, 100%, 50%), /* Yellow */
22
- hsl(120, 100%, 50%), /* Green */
23
- hsl(180, 100%, 50%), /* Cyan */
24
- hsl(240, 100%, 50%), /* Blue */
25
- hsl(300, 100%, 50%), /* Magenta */
26
- hsl(360, 100%, 50%) /* Red (completes the circle) */
27
- )
28
- }
29
-
30
- .saturation-lightness-grid {
31
- /* Assuming a fixed hue, e.g., 240 (blue) */
32
- background: linear-gradient(to right,
33
- hsl(var(--accent-color), 0%, 50%), /* From desaturated */
34
- hsl(var(--accent-color), 100%, 50%) /* To fully saturated */
35
- ),
36
- linear-gradient(to top,
37
- hsl(var(--accent-color), 100%, 0%), /* From dark */
38
- hsl(var(--accent-color), 100%, 50%), /* To mid-lightness */
39
- hsl(var(--accent-color), 100%, 100%) /* To bright */
40
- );
41
- }
42
- spectric-input.alpha-gradient input[type="range"]::-webkit-slider-runnable-track {
43
- background-image:
44
- /* Alpha gradient from transparent to opaque */
45
- linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%);
46
- }
47
- spectric-input.alpha-gradient input[type="range"],spectric-input.hue-gradient input[type="range"]{ -webkit-appearance: none; /* For WebKit browsers (Chrome, Safari) */
48
- -moz-appearance: none; /* For Mozilla Firefox */
49
- appearance: none; /* Standard property */}
50
17
  spectric-input .inputWrapper input {
51
18
  box-sizing: border-box;
52
19
  margin: 0px;
@@ -102,7 +69,7 @@ spectric-input #helper-text {
102
69
  spectric-input #helper-text.hidden {
103
70
  display: none;
104
71
  }
105
- spectric-input[variant="password"] spectric-button {
72
+ spectric-input .input-button-right {
106
73
  position: absolute;
107
74
  right: 4px;
108
75
  bottom: 3px;
@@ -114,4 +81,8 @@ spectric-input .checkbox{
114
81
  }
115
82
  spectric-input spectric-colorpicker{
116
83
  display: block;
84
+ }
85
+
86
+ spectric-input[variant="color"] .fieldwrapper{
87
+ display: inline-block;
117
88
  }