@spectric/ui 0.0.18 → 0.0.20

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 (42) hide show
  1. package/dist/components/Button.d.ts +2 -1
  2. package/dist/components/Panel.d.ts +6 -3
  3. package/dist/components/calendar/calendar.d.ts +58 -0
  4. package/dist/components/calendar/index.d.ts +1 -0
  5. package/dist/components/color_picker/ColorPicker.d.ts +7 -6
  6. package/dist/components/index.d.ts +1 -0
  7. package/dist/components/input.d.ts +24 -20
  8. package/dist/components/query_bar/QueryBar.d.ts +2 -1
  9. package/dist/components/table/table.d.ts +3 -0
  10. package/dist/components/tooltip/popover.d.ts +32 -2
  11. package/dist/components/tooltip/tooltip.d.ts +1 -32
  12. package/dist/custom-elements.json +59 -14
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.es.js +2842 -2564
  15. package/dist/index.es.js.map +1 -1
  16. package/dist/index.umd.js +298 -178
  17. package/dist/index.umd.js.map +1 -1
  18. package/dist/style.css +1 -1
  19. package/package.json +1 -1
  20. package/src/components/Button.ts +14 -13
  21. package/src/components/Panel.ts +25 -18
  22. package/src/components/button.css.ts +13 -0
  23. package/src/components/calendar/calendar.css +50 -0
  24. package/src/components/calendar/calendar.ts +281 -0
  25. package/src/components/calendar/index.ts +1 -0
  26. package/src/components/color_picker/ColorPicker.css +36 -3
  27. package/src/components/color_picker/ColorPicker.ts +46 -15
  28. package/src/components/index.ts +2 -1
  29. package/src/components/input.css +1 -1
  30. package/src/components/input.ts +203 -142
  31. package/src/components/panel.css.ts +7 -5
  32. package/src/components/query_bar/QueryBar.css +6 -2
  33. package/src/components/query_bar/QueryBar.ts +25 -13
  34. package/src/components/table/table.ts +43 -35
  35. package/src/components/table/virtualBody.ts +5 -4
  36. package/src/components/tooltip/popover.ts +70 -30
  37. package/src/components/tooltip/tooltip.css +7 -2
  38. package/src/components/tooltip/tooltip.ts +3 -37
  39. package/src/stories/Calendar.stories.ts +70 -0
  40. package/src/stories/fixtures/ExampleContent.ts +1 -1
  41. package/src/stories/table.stories.ts +10 -5
  42. 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';
@@ -26,9 +26,9 @@ interface EyeDropper {
26
26
 
27
27
  declare var EyeDropper: EyeDropper;
28
28
  let eyedropper: EyeDropper | undefined
29
- // if (window.hasOwnProperty("EyeDropper")) {
30
- // eyedropper = new EyeDropper()
31
- // }
29
+ if (window.hasOwnProperty("EyeDropper")) {
30
+ eyedropper = new EyeDropper()
31
+ }
32
32
  @customElement('spectric-colorpicker')
33
33
  export class SpectricColorPicker extends LitElement implements ColorPickerProps {
34
34
  @property({ type: String, reflect: true })
@@ -51,7 +51,15 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
51
51
  protected createRenderRoot(): HTMLElement | DocumentFragment {
52
52
  return this
53
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)
54
61
 
62
+ }
55
63
  protected update(changedProperties: PropertyValues): void {
56
64
  if (changedProperties.has("value")) {
57
65
  let { h, s, l, a } = hexToHsl(this.value)
@@ -85,7 +93,8 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
85
93
  y += ypix;
86
94
  }
87
95
  }
88
- _handleSaturationLightnessClick = (e: PointerEvent) => {
96
+ @eventOptions({ capture: true })
97
+ _handleSaturationLightnessClick(e: PointerEvent) {
89
98
  if (!this.canvas.value) {
90
99
  return
91
100
  }
@@ -94,30 +103,44 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
94
103
  this.lightness = (this.canvas.value.height - offsetY) / this.canvas.value.height
95
104
  this.updateValue()
96
105
  }
97
- _handleHueChange = (e: DomEvent<SpectricInput>) => {
106
+ @eventOptions({ capture: true })
107
+ _handleHueChange(e: DomEvent<SpectricInput>) {
108
+ e.stopPropagation()
98
109
  this.hue = (parseInt(String(e.target.value)) / 100) * 360
99
110
  e.target.style.setProperty("accent-color", `hsl(${this.hue}deg 100% 50%)`)
100
111
  this.renderHueSaturationGrid()
101
112
  this.updateValue()
102
113
  }
103
114
  private updateValue() {
104
- 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
105
117
  }
106
- _handleAlphaChange = (e: DomEvent<SpectricInput>) => {
118
+ @eventOptions({ capture: true })
119
+ _handleAlphaChange(e: DomEvent<SpectricInput>) {
120
+ e.stopPropagation()
107
121
  this.alpha = parseInt(String(e.target.value)) / 100
108
122
  this.updateValue()
109
123
  }
110
- _handleApply = () => {
124
+ @eventOptions({ capture: true })
125
+ _handleApply() {
111
126
  this.updateValue()
112
127
  this.querySelector<PopoverElement>("spectric-popover")?.hidePopover()
128
+ this.dispatchEvent(new Event("change", { bubbles: true }))
113
129
  }
114
- _cancel = () => {
130
+ @eventOptions({ capture: true })
131
+ _cancel() {
115
132
  if (this.original) {
116
133
  this.value = this.original
117
134
  }
118
135
  this.querySelector<PopoverElement>("spectric-popover")?.hidePopover()
136
+ this.dispatchEvent(new Event("cancel"))
119
137
  }
120
- _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
+ }
121
144
  this.original = this.value
122
145
  this.querySelector<PopoverElement>("spectric-popover")?.showPopover()
123
146
  while (!this.canvas.value) {
@@ -129,13 +152,21 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
129
152
  return html`
130
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>
131
154
  <canvas ${ref(this.canvas)} width=200 height=100 class="color-picker-saturation-lightness-grid" @click=${this._handleSaturationLightnessClick}
132
- @mousedown=${() => { this.sldown = true }}
133
- @mouseup=${() => this.sldown = false}
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
+ }}
134
165
  @mousemove=${(e: PointerEvent) => { if (this.sldown) { this._handleSaturationLightnessClick(e) } }}
135
166
  ></canvas>
136
167
  <spectric-input class="alpha-gradient" ?hidden=${!this.showAlpha} label="Opacity" variant="range" .value=${(this.alpha || 1) * 100} @change=${this._handleAlphaChange}></spectric-input>
137
168
  <div class="color-picker-footer">
138
- <spectric-button ?hidden=${eyedropper === undefined} icon class="color-picker-eyedropper" @click=${async () => {
169
+ <spectric-button icon class="color-picker-eyedropper ${eyedropper === undefined ? "hidden" : ""}" @click=${async () => {
139
170
  if (eyedropper) {
140
171
  let result = await eyedropper?.open()
141
172
  let { h, s, l, a } = hexToHsl(result.sRGBHex);
@@ -154,7 +185,7 @@ export class SpectricColorPicker extends LitElement implements ColorPickerProps
154
185
 
155
186
  protected render(): unknown {
156
187
  return html`
157
- <spectric-button variant="text" @click=${this._openPopover} icon>
188
+ <spectric-button variant="secondary" @click=${this._openPopover} icon>
158
189
  <spectric-popover .text=${this.getPopover()} icon variant="text"></spectric-popover>
159
190
  <div style="width:15px;height:15px;background-color:${this.value}"></div>
160
191
  </spectric-button>
@@ -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"
@@ -69,7 +69,7 @@ spectric-input #helper-text {
69
69
  spectric-input #helper-text.hidden {
70
70
  display: none;
71
71
  }
72
- spectric-input[variant="password"] spectric-button {
72
+ spectric-input .input-button-right {
73
73
  position: absolute;
74
74
  right: 4px;
75
75
  bottom: 3px;