@dataloop-ai/components 0.13.0 → 0.13.2

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Dataloop Components Library
1
+ # Dataloop Components Library ![components version](https://img.shields.io/npm/v/@dataloop-ai/components?label=Latest%20Library%20Version) ![release status](https://img.shields.io/badge/Relese%20Status-Beta-yellowgreen)
2
2
 
3
3
  This repository contains custom made vue components for Dataloop platform and apps use
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -89,14 +89,8 @@ export default defineComponent({
89
89
  default: null
90
90
  },
91
91
  modelValue: {
92
- type: Object as PropType<DateInterval>,
93
- default: () => {
94
- const date = new Date()
95
- return {
96
- from: date,
97
- to: date
98
- }
99
- }
92
+ type: Object as PropType<DateInterval | null>,
93
+ default: null
100
94
  },
101
95
  withLeftChevron: Boolean,
102
96
  withRightChevron: Boolean,
@@ -138,6 +132,8 @@ export default defineComponent({
138
132
  this.$emit('change', newDate)
139
133
  },
140
134
  getDayStyle(value: Partial<CalendarDate>) {
135
+ if (this.modelValue === null) return
136
+
141
137
  const style: Record<string, any> = {}
142
138
 
143
139
  const from = new CalendarDate(this.modelValue.from)
@@ -170,8 +166,12 @@ export default defineComponent({
170
166
 
171
167
  getInnerDayStyle(value: Partial<CalendarDate>) {
172
168
  let style: Record<string, any> = {}
169
+ const disabledOpacity = 0.6
173
170
 
174
- const isToday = value.isSame(new CalendarDate(), 'date')
171
+ const isToday = value.isSame(
172
+ new CalendarDate().startOf('day'),
173
+ 'day'
174
+ )
175
175
 
176
176
  if (
177
177
  !isInRange(
@@ -179,20 +179,21 @@ export default defineComponent({
179
179
  new CustomDate(value.toString())
180
180
  )
181
181
  ) {
182
- if (isToday) {
182
+ if (isToday && this.disabled) {
183
+ style.color = 'var(--dl-color-secondary)'
184
+ style.opacity = disabledOpacity
185
+ } else if (isToday) {
183
186
  style.color = 'var(--dl-color-secondary)'
184
187
  } else {
185
- style.color = 'var(--dl-color-lighter)'
188
+ style.color = 'var(--dl-color-disabled)'
186
189
  }
187
- } else {
190
+ } else if (this.modelValue !== null) {
188
191
  const selectedStyle = {
189
192
  backgroundColor: 'var(--dl-color-secondary)',
190
193
  color: 'var(--dl-color-text-buttons)',
191
194
  borderRadius: '11px'
192
195
  }
193
196
 
194
- const disabledOpacity = 0.6
195
-
196
197
  const from = new CalendarDate(this.modelValue.from)
197
198
  const to = new CalendarDate(this.modelValue.to)
198
199
 
@@ -221,6 +222,18 @@ export default defineComponent({
221
222
  } else if (value.isDisabled) {
222
223
  style.color = 'var(--dl-color-lighter)'
223
224
  }
225
+ } else {
226
+ if (isToday) {
227
+ style.color = 'var(--dl-color-secondary)'
228
+
229
+ if (this.disabled) {
230
+ style.opacity = disabledOpacity
231
+ }
232
+ } else if (this.disabled) {
233
+ style.color = 'var(--dl-color-disabled)'
234
+ } else if (value.isDisabled) {
235
+ style.color = 'var(--dl-color-lighter)'
236
+ }
224
237
  }
225
238
 
226
239
  return style
@@ -232,6 +245,7 @@ export default defineComponent({
232
245
  },
233
246
 
234
247
  handleMouseEnter(value: CustomDate) {
248
+ if (this.modelValue === null) return
235
249
  if (!isInRange(this.availableRange, value)) return
236
250
 
237
251
  if (value.isBefore(new CustomDate(this.modelValue.from))) return
@@ -93,14 +93,8 @@ export default defineComponent({
93
93
  },
94
94
  props: {
95
95
  modelValue: {
96
- type: Object as PropType<DateInterval>,
97
- default: () => {
98
- const date = new Date()
99
- return {
100
- from: date,
101
- to: date
102
- }
103
- }
96
+ type: Object as PropType<DateInterval | null>,
97
+ default: null
104
98
  },
105
99
  type: {
106
100
  type: String,
@@ -120,7 +114,7 @@ export default defineComponent({
120
114
  calendarFrom: Calendar | null
121
115
  calendarTo: Calendar | null
122
116
  isSelectionMode: boolean
123
- dateInterval: DateInterval
117
+ dateInterval: DateInterval | null
124
118
  } {
125
119
  return {
126
120
  uuid: `dl-date-picker-${v4()}`,
@@ -133,8 +127,7 @@ export default defineComponent({
133
127
  },
134
128
  watch: {
135
129
  type(value: string) {
136
- const cDateFrom = new CalendarDate(this.modelValue.from)
137
- const cDateTo = new CalendarDate(this.modelValue.to)
130
+ const [cDateFrom, cDateTo] = this.getCalendarDates(this.modelValue)
138
131
 
139
132
  this.calendarFrom!.currentDate = cDateFrom
140
133
  this.calendarTo!.currentDate = cDateTo
@@ -148,10 +141,9 @@ export default defineComponent({
148
141
  )
149
142
  },
150
143
  modelValue: {
151
- handler(value: DateInterval) {
144
+ handler(value: DateInterval | null) {
152
145
  this.dateInterval = value
153
- const cDateFrom = new CalendarDate(value.from)
154
- const cDateTo = new CalendarDate(value.to)
146
+ const [cDateFrom, cDateTo] = this.getCalendarDates(value)
155
147
 
156
148
  this.calendarFrom!.currentDate = cDateFrom
157
149
  this.calendarTo!.currentDate = cDateTo
@@ -169,8 +161,7 @@ export default defineComponent({
169
161
  }
170
162
  },
171
163
  beforeMount() {
172
- const cDateFrom = new CalendarDate(this.modelValue.from)
173
- const cDateTo = new CalendarDate(this.modelValue.to)
164
+ const [cDateFrom, cDateTo] = this.getCalendarDates(this.modelValue)
174
165
 
175
166
  const unit = this.type === 'day' ? 'month' : 'year'
176
167
 
@@ -189,6 +180,14 @@ export default defineComponent({
189
180
  }
190
181
  },
191
182
  methods: {
183
+ getCalendarDates(value: DateInterval): [CalendarDate, CalendarDate] {
184
+ if (value === null) {
185
+ const now = new CalendarDate()
186
+ return [now, now]
187
+ }
188
+
189
+ return [new CalendarDate(value.from), new CalendarDate(value.to)]
190
+ },
192
191
  updateModelValue(value: DateInterval) {
193
192
  if (this.disabled) return
194
193
  this.$emit('update:modelValue', value)
@@ -67,14 +67,8 @@ export default defineComponent({
67
67
  default: null
68
68
  },
69
69
  modelValue: {
70
- type: Object as PropType<DateInterval>,
71
- default: () => {
72
- const date = new Date()
73
- return {
74
- from: date,
75
- to: date
76
- }
77
- }
70
+ type: Object as PropType<DateInterval | null>,
71
+ default: null
78
72
  },
79
73
  withLeftChevron: Boolean,
80
74
  withRightChevron: Boolean,
@@ -106,21 +100,24 @@ export default defineComponent({
106
100
  },
107
101
  methods: {
108
102
  handleClick(value: number) {
109
- const d = new CalendarDate(this.modelValue.from)
103
+ const d = new CalendarDate()
110
104
  d.year(parseInt(this.title)).month(value).startOf('month')
111
105
 
112
106
  if (!isInRange(this.availableRange, d)) return
113
107
 
108
+ const date = d.toDate()
114
109
  const newDate = {
115
- from: d.toDate(),
116
- to: d.toDate()
110
+ from: date,
111
+ to: date
117
112
  }
118
113
  this.$emit('update:modelValue', newDate)
119
114
  this.$emit('change', newDate)
120
115
  },
121
116
 
122
117
  handleMouseenter(value: number) {
123
- const d = new CalendarDate(this.modelValue.from)
118
+ if (this.modelValue === null) return
119
+
120
+ const d = new CalendarDate()
124
121
  d.year(parseInt(this.title)).month(value).startOf('month')
125
122
 
126
123
  if (!isInRange(this.availableRange, d)) return
@@ -132,7 +129,7 @@ export default defineComponent({
132
129
  },
133
130
 
134
131
  handleMousedown(value: number) {
135
- const d = new CalendarDate(this.modelValue.from)
132
+ const d = new CalendarDate()
136
133
  d.year(parseInt(this.title)).month(value).startOf('month')
137
134
 
138
135
  if (!isInRange(this.availableRange, d)) return
@@ -148,18 +145,17 @@ export default defineComponent({
148
145
  background: 'var(--dl-color-secondary)'
149
146
  }
150
147
 
151
- const currentD = new CalendarDate(this.modelValue.from)
152
- const d = new CalendarDate(currentD)
153
- d.month(value).year(parseInt(this.title))
148
+ const initialD = new CalendarDate()
149
+ const d = new CalendarDate()
150
+
151
+ d.year(parseInt(this.title)).month(value).startOf('month')
154
152
 
155
153
  if (!isInRange(this.availableRange, d)) {
156
154
  style = {
157
155
  'border-color': 'var(--dl-color-disabled)',
158
156
  color: 'var(--dl-color-disabled)'
159
157
  }
160
- } else {
161
- const initialD = new CalendarDate()
162
-
158
+ } else if (this.modelValue !== null) {
163
159
  const from = new CalendarDate(this.modelValue.from)
164
160
  const to = new CalendarDate(this.modelValue.to)
165
161
 
@@ -204,6 +200,10 @@ export default defineComponent({
204
200
  } else if (d.isSame(initialD, 'month') && !isIntervalBoundary) {
205
201
  style.color = 'var(--dl-color-secondary)'
206
202
  }
203
+ } else {
204
+ if (d.isSame(initialD, 'month')) {
205
+ style.color = 'var(--dl-color-secondary)'
206
+ }
207
207
  }
208
208
 
209
209
  return style
@@ -90,14 +90,8 @@ export default defineComponent({
90
90
  },
91
91
  props: {
92
92
  modelValue: {
93
- type: Object as PropType<DateInterval>,
94
- default: () => {
95
- const date = new Date()
96
- return {
97
- from: date,
98
- to: date
99
- }
100
- }
93
+ type: Object as PropType<DateInterval | null>,
94
+ default: null
101
95
  },
102
96
  showTime: Boolean,
103
97
  type: {
@@ -118,36 +112,38 @@ export default defineComponent({
118
112
  },
119
113
  withSelectedOption: Boolean,
120
114
  disabled: Boolean,
121
- autoClose: Boolean
115
+ autoClose: Boolean,
116
+ placeholder: {
117
+ type: String,
118
+ default: 'Set Due Date'
119
+ }
122
120
  },
123
121
  emits: ['update:modelValue', 'set-type', 'change'],
124
122
  data(): {
125
123
  uuid: string
126
- dateInterval: DateInterval
124
+ dateInterval: DateInterval | null
127
125
  typeState: 'day' | 'month'
128
126
  isOpen: boolean
129
127
  isInputDisabled: boolean
130
- dayTypeOptions: DayTypeOption[]
131
- monthTypeOptions: MonthTypeOption[]
132
128
  currentSidebarOption: DAY_SIDEBAR_OPTION | MONTH_SIDEBAR_OPTION
133
129
  } {
134
- const today = CustomDate.startOf('day').toDate()
135
- const yesterday = CustomDate.subtract(1, 'day').startOf('day').toDate()
136
- const thisMonth = CustomDate.startOf('month').toDate()
137
- const lastMonth = CustomDate.subtract(1, 'months')
138
- .startOf('month')
139
- .toDate()
140
-
141
130
  return {
142
131
  uuid: `dl-date-time-range-${v4()}`,
143
- dateInterval: {
144
- from: this.modelValue.from,
145
- to: this.modelValue.to
146
- },
132
+ dateInterval: this.modelValue,
147
133
  typeState: this.type,
148
134
  isOpen: false,
149
135
  isInputDisabled: false,
150
- dayTypeOptions: [
136
+ currentSidebarOption: DAY_SIDEBAR_OPTION.custom
137
+ }
138
+ },
139
+ computed: {
140
+ dayTypeOptions(): DayTypeOption[] {
141
+ const today = CustomDate.startOf('day').toDate()
142
+ const yesterday = CustomDate.subtract(1, 'day')
143
+ .startOf('day')
144
+ .toDate()
145
+
146
+ return [
151
147
  {
152
148
  title: 'today',
153
149
  key: DAY_SIDEBAR_OPTION.today,
@@ -162,7 +158,9 @@ export default defineComponent({
162
158
  title: 'last 7 days',
163
159
  key: DAY_SIDEBAR_OPTION.last_7_days,
164
160
  value: {
165
- from: CustomDate.subtract(7, 'day').toDate(),
161
+ from: CustomDate.subtract(7, 'day')
162
+ .startOf('day')
163
+ .toDate(),
166
164
  to: today
167
165
  }
168
166
  },
@@ -170,7 +168,9 @@ export default defineComponent({
170
168
  title: 'last 14 days',
171
169
  key: DAY_SIDEBAR_OPTION.last_14_days,
172
170
  value: {
173
- from: CustomDate.subtract(14, 'day').toDate(),
171
+ from: CustomDate.subtract(14, 'day')
172
+ .startOf('day')
173
+ .toDate(),
174
174
  to: today
175
175
  }
176
176
  },
@@ -188,17 +188,24 @@ export default defineComponent({
188
188
  {
189
189
  title: 'custom by month',
190
190
  key: DAY_SIDEBAR_OPTION.custom_by_month,
191
- value: {
192
- from: new CalendarDate(this.modelValue.from)
191
+ value: this.dateInterval && {
192
+ from: new CalendarDate(this.dateInterval.from)
193
193
  .startOf('month')
194
194
  .toDate(),
195
- to: new CalendarDate(this.modelValue.from)
195
+ to: new CalendarDate(this.dateInterval.from)
196
196
  .startOf('month')
197
197
  .toDate()
198
198
  }
199
199
  }
200
- ],
201
- monthTypeOptions: [
200
+ ]
201
+ },
202
+ monthTypeOptions(): MonthTypeOption[] {
203
+ const thisMonth = CustomDate.startOf('month').toDate()
204
+ const lastMonth = CustomDate.subtract(1, 'months')
205
+ .startOf('month')
206
+ .toDate()
207
+
208
+ return [
202
209
  {
203
210
  title: 'this month',
204
211
  key: MONTH_SIDEBAR_OPTION.this_month,
@@ -216,7 +223,7 @@ export default defineComponent({
216
223
  from: CustomDate.subtract(3, 'months')
217
224
  .startOf('month')
218
225
  .toDate(),
219
- to: today
226
+ to: thisMonth
220
227
  }
221
228
  },
222
229
  {
@@ -226,7 +233,7 @@ export default defineComponent({
226
233
  from: CustomDate.subtract(6, 'months')
227
234
  .startOf('month')
228
235
  .toDate(),
229
- to: today
236
+ to: thisMonth
230
237
  }
231
238
  },
232
239
  {
@@ -236,27 +243,24 @@ export default defineComponent({
236
243
  from: CustomDate.subtract(1, 'year')
237
244
  .startOf('month')
238
245
  .toDate(),
239
- to: today
246
+ to: thisMonth
240
247
  }
241
248
  },
242
249
  { title: 'custom by month', key: MONTH_SIDEBAR_OPTION.custom },
243
250
  {
244
251
  title: 'custom by day',
245
252
  key: MONTH_SIDEBAR_OPTION.custom_by_day,
246
- value: {
247
- from: new CalendarDate(this.modelValue.from)
253
+ value: this.dateInterval && {
254
+ from: new CalendarDate(this.dateInterval.from)
248
255
  .startOf('day')
249
256
  .toDate(),
250
- to: new CalendarDate(this.modelValue.from)
257
+ to: new CalendarDate(this.dateInterval.from)
251
258
  .startOf('day')
252
259
  .toDate()
253
260
  }
254
261
  }
255
- ],
256
- currentSidebarOption: DAY_SIDEBAR_OPTION.custom
257
- }
258
- },
259
- computed: {
262
+ ]
263
+ },
260
264
  sidebarDayOptions(): DayTypeOption[] {
261
265
  return this.dayTypeOptions.map((o) => ({
262
266
  ...o,
@@ -273,6 +277,10 @@ export default defineComponent({
273
277
  return { width: `${this.dateInputText.length / 2}em` }
274
278
  },
275
279
  dateInputText(): string {
280
+ if (this.dateInterval === null) {
281
+ return this.placeholder
282
+ }
283
+
276
284
  let text = ''
277
285
 
278
286
  if (this.typeState === 'month') {
@@ -361,7 +369,9 @@ export default defineComponent({
361
369
  type(value: 'day' | 'month') {
362
370
  this.typeState = value
363
371
 
364
- const date = new CustomDate(this.modelValue.from)
372
+ if (this.dateInterval === null) return
373
+
374
+ const date = new CustomDate(this.dateInterval.from)
365
375
  .startOf(value)
366
376
  .toDate()
367
377
 
@@ -382,10 +392,8 @@ export default defineComponent({
382
392
  this.typeState === 'day'
383
393
  ? DAY_SIDEBAR_OPTION.custom
384
394
  : MONTH_SIDEBAR_OPTION.custom
385
- this.updateDateInterval({
386
- from: this.modelValue.from,
387
- to: this.modelValue.to
388
- })
395
+
396
+ this.updateDateInterval(null)
389
397
  },
390
398
  deep: true
391
399
  }
@@ -401,7 +409,7 @@ export default defineComponent({
401
409
  this.typeState = value
402
410
  this.$emit('set-type', value)
403
411
  },
404
- updateDateInterval(value: DateInterval) {
412
+ updateDateInterval(value: DateInterval | null) {
405
413
  this.dateInterval = value
406
414
  this.$emit('update:modelValue', value)
407
415
  this.$emit('change', value)
@@ -718,6 +718,7 @@ export default defineComponent({
718
718
  if (!this.preserveSearch) {
719
719
  const inputRef = this.$refs.searchInput as HTMLInputElement
720
720
  if (inputRef) inputRef.value = ''
721
+ this.$emit('filter', '')
721
722
  }
722
723
  },
723
724
  getLabel,
@@ -5,11 +5,11 @@
5
5
  >
6
6
  <div
7
7
  class="dl-time-picker--input"
8
- :class="{ 'dl-time-picker--input-disabled': disabled }"
8
+ :class="{ 'dl-time-picker--input-disabled': disableInput }"
9
9
  >
10
10
  <span>From: {{ formatedFrom }}</span>
11
11
  <dl-time-picker-input
12
- :disabled="disabled"
12
+ :disabled="disableInput"
13
13
  :model-value="formatedFromValue"
14
14
  @update:modelValue="handleFromTimeChange"
15
15
  />
@@ -19,11 +19,11 @@
19
19
  </div>
20
20
  <div
21
21
  class="dl-time-picker--input"
22
- :class="{ 'dl-time-picker--input-disabled': disabled }"
22
+ :class="{ 'dl-time-picker--input-disabled': disableInput }"
23
23
  >
24
24
  <span>To: {{ formatedTo }}</span>
25
25
  <dl-time-picker-input
26
- :disabled="disabled"
26
+ :disabled="disableInput"
27
27
  :model-value="formatedToValue"
28
28
  @update:modelValue="handleToTimeChange"
29
29
  />
@@ -44,14 +44,8 @@ export default defineComponent({
44
44
  },
45
45
  props: {
46
46
  modelValue: {
47
- type: Object as PropType<DateInterval>,
48
- default: () => {
49
- const date = new Date()
50
- return {
51
- from: date,
52
- to: date
53
- }
54
- }
47
+ type: Object as PropType<DateInterval | null>,
48
+ default: null
55
49
  },
56
50
  disabled: Boolean
57
51
  },
@@ -62,13 +56,22 @@ export default defineComponent({
62
56
  }
63
57
  },
64
58
  computed: {
59
+ disableInput(): boolean {
60
+ return this.modelValue === null || this.disabled
61
+ },
65
62
  formatedFrom(): string {
66
- return (
67
- new CustomDate(this.modelValue.from).format('MMM DD, YYYY') ||
68
- ''
69
- )
63
+ return this.modelValue !== null
64
+ ? new CustomDate(this.modelValue.from).format('MMM DD, YYYY')
65
+ : ''
70
66
  },
71
67
  formatedFromValue(): Time {
68
+ if (this.modelValue === null) {
69
+ return {
70
+ hour: '00',
71
+ minute: '00'
72
+ }
73
+ }
74
+
72
75
  const selectionObj = new CustomDate(this.modelValue.from)
73
76
  return {
74
77
  hour: selectionObj.format('HH'),
@@ -76,11 +79,18 @@ export default defineComponent({
76
79
  }
77
80
  },
78
81
  formatedTo(): string {
79
- return (
80
- new CustomDate(this.modelValue.to).format('MMM DD, YYYY') || ''
81
- )
82
+ return this.modelValue !== null
83
+ ? new CustomDate(this.modelValue.to).format('MMM DD, YYYY')
84
+ : ''
82
85
  },
83
86
  formatedToValue(): Time {
87
+ if (this.modelValue === null) {
88
+ return {
89
+ hour: '00',
90
+ minute: '00'
91
+ }
92
+ }
93
+
84
94
  const selectionObj = new CustomDate(this.modelValue.to)
85
95
  return {
86
96
  hour: selectionObj.format('HH'),
@@ -92,8 +92,8 @@ export default defineComponent({
92
92
  modelValue: {
93
93
  type: Object as PropType<Time>,
94
94
  default: () => ({
95
- hour: formatTime(new Date().getHours()),
96
- minute: formatTime(new Date().getMinutes())
95
+ hour: '00',
96
+ minute: '00'
97
97
  })
98
98
  },
99
99
  disabled: Boolean
@@ -72,13 +72,14 @@
72
72
  </div>
73
73
  <div class="dl-dtr--input">
74
74
  <dl-date-time-range
75
+ v-model="date"
75
76
  :type="type"
76
77
  :available-range="range ? availableRange : null"
77
78
  :mode="mode"
78
79
  :show-time="showTime"
79
80
  :auto-close="autoClose"
80
81
  @set-type="handleSetType"
81
- @update:modelValue="handleModelValueUpdate"
82
+ @change="handleModelValueUpdate"
82
83
  />
83
84
  </div>
84
85
  </div>
@@ -94,6 +95,7 @@ export default defineComponent({
94
95
  DlDateTimeRange
95
96
  },
96
97
  data(): {
98
+ date: DateInterval
97
99
  switchState: any[]
98
100
  availableRange: Partial<DateInterval>
99
101
  } {
@@ -103,6 +105,7 @@ export default defineComponent({
103
105
  to.setDate(to.getDate() + 35)
104
106
 
105
107
  return {
108
+ date: null,
106
109
  availableRange: {
107
110
  from,
108
111
  to