terrier-engine 4.22.2 → 4.23.0

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "files": [
5
5
  "*"
6
6
  ],
7
- "version": "4.22.2",
7
+ "version": "4.23.0",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Terrier-Tech/terrier-engine"
@@ -0,0 +1,87 @@
1
+ import {PartTag} from "tuff-core/parts"
2
+ import TerrierPart from "./parts/terrier-part"
3
+
4
+ type OneToFive<T> = T | [T, T] | [T, T, T] | [T, T, T, T] | [T, T, T, T, T]
5
+
6
+ export type MultiCircularProgressState = {
7
+ /** The total amount represented by the progress bar */
8
+ total: number
9
+ /** Current progress trace(es) of the progress bar */
10
+ progress: OneToFive<number>
11
+ /** Options modifying the appearance and behavior of the progress bar */
12
+ options?: MultiCircularProgressOptions
13
+ }
14
+
15
+ export type MultiCircularProgressOptions = {
16
+ /** Colors of each trace in the progress bar. Any css color string can be used here. */
17
+ color?: OneToFive<string>
18
+ /** The width and height of the circle. If not provided, the circle will fill its container. Any css length string can be used here. */
19
+ outerDiameter?: string
20
+ /** The thickness of the ring. If not provided, 10px. Any css length string can be used here. */
21
+ thickness?: string
22
+ /** The color of the ring when it is not filled. Default is --tt-inactive-color. Any css color string can be used here. */
23
+ backgroundColor?: string
24
+ /** The duration of the transition when progress changes. Default is --tt-transition-duration. Any css duration string can be used here. */
25
+ transitionDuration?: string
26
+ /** The timing function used for the transition when progress changes. Any css timing function can be used here. */
27
+ transitionTimingFunction?: string
28
+ }
29
+
30
+ /**
31
+ * An animated circular progress bar.
32
+ * Supports up to 5 simultaneous progress values. Progress values are assumed to sum to the total or less
33
+ */
34
+ export default class MultiCircularProgressBarPart extends TerrierPart<MultiCircularProgressState> {
35
+
36
+ updateProgress(progress: OneToFive<number>) {
37
+ const oldProgress = this.state.progress;
38
+ const newIsArray = Array.isArray(progress)
39
+ const oldIsArray = Array.isArray(oldProgress)
40
+ const newType = newIsArray !== oldIsArray
41
+ const countDiff = newIsArray && oldIsArray && progress.length != oldProgress.length
42
+ if (newType || countDiff) {
43
+ this.assignState({ ...this.state, progress })
44
+ return
45
+ }
46
+
47
+ this.state.progress = progress
48
+ this.stale()
49
+ }
50
+
51
+ render(parent: PartTag) {
52
+ parent.div('tt-circle-progress')
53
+ }
54
+
55
+ update(elem: HTMLElement) {
56
+ super.update(elem);
57
+
58
+ const bar = elem.querySelector('.tt-circle-progress') as HTMLElement
59
+
60
+ if (Array.isArray(this.state.progress)) {
61
+ let amount = 0
62
+ for (let i = 0; i < this.state.progress.length; i++) {
63
+ amount += this.state.progress[i] / this.state.total
64
+ bar.style.setProperty(`--progress-${i}-value`, `${amount * 100}%`)
65
+ }
66
+ } else {
67
+ bar.style.setProperty('--progress-0-value', `${this.state.progress / this.state.total * 100}%`)
68
+
69
+ }
70
+
71
+ if (!this.state.options) return
72
+
73
+ if (this.state.options.outerDiameter) bar.style.setProperty('--size', this.state.options.outerDiameter)
74
+ if (this.state.options.thickness) bar.style.setProperty('--thickness', this.state.options.thickness)
75
+ if (this.state.options.backgroundColor) bar.style.setProperty('--background-color', this.state.options.backgroundColor)
76
+ if (this.state.options.transitionDuration) bar.style.setProperty('--transition-duration', this.state.options.transitionDuration)
77
+ if (this.state.options.transitionTimingFunction) bar.style.setProperty('--transition-timing-function', this.state.options.transitionTimingFunction)
78
+
79
+ if (Array.isArray(this.state.options?.color)) {
80
+ for (let i = 0; i < this.state.options.color.length; i++) {
81
+ bar.style.setProperty(`--progress-${i}-color`, this.state.options.color[i])
82
+ }
83
+ } else if (this.state.options?.color) {
84
+ bar.style.setProperty(`--progress-0-color`, this.state.options.color)
85
+ }
86
+ }
87
+ }
@@ -26,7 +26,9 @@ export class SelectFieldPart<T extends SelectFieldState> extends TerrierPart<T>
26
26
  async init() {
27
27
  await super.init()
28
28
  this.state.selected_option = this.populateOptionIfBlank(this.state.selected_option)
29
- this.onClick(this._toggleDropdownKey, () => {
29
+ this.onClick(this._toggleDropdownKey, m => {
30
+ const target = m.event.currentTarget as HTMLElement
31
+ if (target.classList.contains('disabled')) return
30
32
  this.toggleDropdown(SelectOptionsDropdown, {
31
33
  options: this.state.options,
32
34
  selected_option: this.state.selected_option,