@dataloop-ai/components 0.18.75 → 0.18.76

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.18.75",
3
+ "version": "0.18.76",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -5,23 +5,23 @@
5
5
  :style="sliderStyles"
6
6
  >
7
7
  <div
8
- v-if="editable"
9
- class="slider editable"
10
- data-test="editable-slider"
8
+ v-if="slim"
9
+ class="slider slim"
10
+ data-test="slim-slider"
11
11
  >
12
12
  <span class="text capitalize">{{ text }}</span>
13
13
  <dl-slider-input
14
- v-model="sliderValue"
14
+ v-model="value"
15
15
  :min="min"
16
16
  :max="max"
17
17
  :readonly="readonly"
18
18
  :disabled="disabled"
19
19
  :style="{ marginRight: '10px' }"
20
- data-test="editable-slider-input"
20
+ data-test="slim-slider-input"
21
21
  />
22
22
  <div class="slider-bar-container">
23
23
  <dl-slider-base
24
- v-model.number="sliderValue"
24
+ v-model.number="value"
25
25
  :min="min"
26
26
  :max="max"
27
27
  :step="step"
@@ -37,8 +37,8 @@
37
37
  </div>
38
38
  <div
39
39
  v-else
40
- class="slider non-editable"
41
- data-test="non-editable-slider"
40
+ class="slider non-slim"
41
+ data-test="non-slim-slider"
42
42
  >
43
43
  <div class="header">
44
44
  <div class="row text capitalize">
@@ -60,24 +60,24 @@
60
60
  size="12px"
61
61
  label="Reset"
62
62
  :disabled="disabled || readonly"
63
- data-test="non-editable-slider-button"
63
+ data-test="non-slim-slider-button"
64
64
  @click="handleResetButtonClick"
65
65
  />
66
66
  <dl-slider-input
67
67
  id="slider-input"
68
- v-model="sliderValue"
68
+ v-model="value"
69
69
  :min="min"
70
70
  :max="max"
71
71
  :readonly="readonly"
72
72
  :disabled="disabled"
73
- data-test="non-editable-slider-input"
74
- @change="handleChange"
73
+ data-test="non-slim-slider-input"
74
+ @change="onChange"
75
75
  />
76
76
  </div>
77
77
  </div>
78
78
  <div class="slider-bar-container">
79
79
  <dl-slider-base
80
- v-model.number="sliderValue"
80
+ v-model.number="value"
81
81
  :min="min"
82
82
  :max="max"
83
83
  :step="step"
@@ -87,7 +87,7 @@
87
87
  :disabled="disabled"
88
88
  :snap="snap"
89
89
  :name="name"
90
- @change="handleChange"
90
+ @change="onChange"
91
91
  />
92
92
  </div>
93
93
  </div>
@@ -95,7 +95,7 @@
95
95
  </template>
96
96
 
97
97
  <script lang="ts">
98
- import { defineComponent } from 'vue-demi'
98
+ import { computed, defineComponent, ref, toRefs, watch } from 'vue-demi'
99
99
  import { DlSliderBase, DlSliderInput } from './components/'
100
100
  import { DlButton } from '../../basic'
101
101
  import { DlIcon } from '../../essential'
@@ -133,7 +133,7 @@ export default defineComponent({
133
133
  type: Boolean,
134
134
  default: false
135
135
  },
136
- editable: {
136
+ slim: {
137
137
  type: Boolean,
138
138
  default: false
139
139
  },
@@ -185,60 +185,82 @@ export default defineComponent({
185
185
  }
186
186
  },
187
187
  emits: ['update:model-value', 'change'],
188
- data() {
189
- const val =
190
- this.modelValue === null
191
- ? this.min
192
- : between(this.modelValue, this.min, this.max)
188
+ setup(props, { emit }) {
189
+ const { modelValue, min, max, textColor, width, thumbSize, color } =
190
+ toRefs(props)
191
+ const initialValue = ref(
192
+ modelValue.value === null
193
+ ? min.value
194
+ : between(modelValue.value, min.value, max.value)
195
+ )
196
+ const displaySliderInput = ref(false)
193
197
 
194
- return {
195
- uuid: `dl-slider-${v4()}`,
196
- initialValue: val,
197
- value: val,
198
- displaySliderInput: false
199
- }
200
- },
201
- computed: {
202
- valueUpdate(): string {
203
- return `${this.modelValue}|${this.min}|${this.max}`
204
- },
205
- sliderValue: {
206
- get(): number {
207
- return this.value
198
+ const value = computed({
199
+ get: () => {
200
+ return modelValue.value === null
201
+ ? min.value
202
+ : between(modelValue.value, min.value, max.value)
208
203
  },
209
- set(val: number | string): void {
210
- this.$emit(
211
- 'update:model-value',
212
- typeof val === 'number' ? val : null
204
+ set(val: number) {
205
+ console.log(
206
+ '@@@ intial, cur',
207
+ initialValue.value,
208
+ modelValue.value
213
209
  )
210
+ console.log(`@@@ model value update `, val)
211
+ if (val === modelValue.value) {
212
+ return
213
+ }
214
+ emit('update:model-value', val)
215
+ emit('change', val)
214
216
  }
215
- },
216
- sliderStyles(): Record<string, any> {
217
+ })
218
+
219
+ const sliderStyles = computed<Record<string, any>>(() => {
217
220
  return {
218
- '--text-color': getColor(this.textColor, 'dl-color-darker'),
219
- '--width': this.width,
220
- '--thumb-size': parseInt(this.thumbSize) / 2 + 'px',
221
- '--color': getColor(this.color, 'dl-color-secondary')
221
+ '--text-color': getColor(textColor.value, 'dl-color-darker'),
222
+ '--width': width.value,
223
+ '--thumb-size': parseInt(thumbSize.value) / 2 + 'px',
224
+ '--color': getColor(color.value, 'dl-color-secondary')
222
225
  }
226
+ })
227
+
228
+ const onChange = (val: number) => {
229
+ value.value = between(val, min.value, max.value)
223
230
  }
224
- },
225
- watch: {
226
- valueUpdate() {
227
- this.value =
228
- this.modelValue === null
229
- ? this.min
230
- : between(this.modelValue, this.min, this.max)
231
+
232
+ const handleResetButtonClick = () => {
233
+ onChange(initialValue.value)
231
234
  }
232
- },
233
- methods: {
234
- handleChange(value: number) {
235
- if (this.sliderValue === value) return
236
235
 
237
- this.$emit('change', value)
238
- this.sliderValue = value
239
- },
240
- handleResetButtonClick() {
241
- this.handleChange(this.initialValue)
236
+ watch(
237
+ modelValue,
238
+ () => {
239
+ if (modelValue.value === value.value) {
240
+ return
241
+ }
242
+
243
+ if (modelValue.value === null) {
244
+ value.value = min.value
245
+ } else {
246
+ value.value = between(
247
+ modelValue.value,
248
+ min.value,
249
+ max.value
250
+ )
251
+ }
252
+ },
253
+ { immediate: true }
254
+ )
255
+
256
+ return {
257
+ uuid: `dl-slider-${v4()}`,
258
+ initialValue,
259
+ value,
260
+ sliderStyles,
261
+ displaySliderInput,
262
+ onChange,
263
+ handleResetButtonClick
242
264
  }
243
265
  }
244
266
  })
@@ -85,12 +85,12 @@
85
85
  }
86
86
  }
87
87
 
88
- .editable {
88
+ .slim {
89
89
  align-items: center;
90
90
  flex-direction: row;
91
91
  }
92
92
 
93
- .non-editable {
93
+ .non-slim {
94
94
  flex-direction: column;
95
95
 
96
96
  & .header {
@@ -7,14 +7,14 @@
7
7
  :step="1"
8
8
  :min="-100"
9
9
  :max="100"
10
- :editable="editable"
10
+ :slim="slim"
11
11
  :readonly="readonly"
12
12
  :disabled="disabled"
13
13
  @change="handleChange"
14
14
  />
15
15
  <div>
16
- <button @click="editable = !editable">
17
- Editable: {{ editable }}
16
+ <button @click="slim = !slim">
17
+ slim: {{ slim }}
18
18
  </button>
19
19
  <button @click="readonly = !readonly">
20
20
  Readonly: {{ readonly }}
@@ -23,6 +23,10 @@
23
23
  Disable: {{ disabled }}
24
24
  </button>
25
25
  </div>
26
+ <div>
27
+ Events: <br>
28
+ {{ events }}
29
+ </div>
26
30
  </div>
27
31
  </template>
28
32
 
@@ -37,20 +41,23 @@ export default defineComponent({
37
41
  },
38
42
  data() {
39
43
  return {
40
- value: 0,
41
- editable: false,
44
+ value: null,
45
+ slim: false,
42
46
  disabled: false,
43
- readonly: false
47
+ readonly: false,
48
+ events: []
44
49
  }
45
50
  },
46
51
  watch: {
47
52
  value(newValue, oldValue) {
48
53
  console.log(`@@@ model value update ${oldValue} to ${newValue}`)
54
+ this.events[0] = `@@@ model value update ${oldValue} to ${newValue}`
49
55
  }
50
56
  },
51
57
  methods: {
52
58
  handleChange(value: number) {
53
59
  console.log(`@@@ handling change ${value}`)
60
+ this.events[1] = `@@@ handling change ${value}`
54
61
  }
55
62
  },
56
63
  template: 'dl-slider-demo'