@dataloop-ai/components 0.13.19 → 0.14.4
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/.nvmrc +1 -0
- package/README.md +3 -1
- package/package.json +19 -17
- package/src/assets/globals.scss +38 -3
- package/src/assets/grid.scss +9 -0
- package/src/components/DlAccordion/DlAccordion.vue +4 -4
- package/src/components/DlAlert.vue +6 -6
- package/src/components/DlChart/BrushThumb.vue +83 -0
- package/src/components/DlChart/DlBarChart.vue +545 -0
- package/src/components/DlChart/DlBrush.vue +475 -0
- package/src/components/DlChart/DlChartLabels.vue +279 -0
- package/src/components/DlChart/DlChartLegend.vue +141 -0
- package/src/components/DlChart/DlColumnChart.vue +555 -0
- package/src/components/DlChart/DlLineChart.vue +644 -0
- package/src/components/DlChart/DlScrollBar.vue +147 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChart.vue +448 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChartLegend.vue +281 -0
- package/src/components/DlChart/Doughnut/DlDoughnutChartWidget.vue +64 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartAnimation.ts +4 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartData.ts +16 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartOptions.ts +11 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutChartProps.ts +8 -0
- package/src/components/DlChart/Doughnut/types/TDoughnutWithOriginalColor.ts +13 -0
- package/src/components/DlChart/chart.ts +122 -0
- package/src/components/DlChart/index.ts +36 -0
- package/src/components/DlChart/props.ts +348 -0
- package/src/components/DlChart/typedCharts.ts +88 -0
- package/src/components/DlChart/types.ts +63 -0
- package/src/components/DlChart/utils.ts +153 -0
- package/src/components/DlChip/DlChip.vue +40 -13
- package/src/components/DlCounters.vue +31 -7
- package/src/components/DlDatePicker/DlCalendar.vue +22 -10
- package/src/components/DlDatePicker/DlDatePicker.vue +8 -5
- package/src/components/DlDateTimeRange/types.ts +2 -2
- package/src/components/DlDropdownButton.vue +5 -3
- package/src/components/DlMenu/DlMenu.vue +4 -2
- package/src/components/DlPagination/RowsSelector.vue +15 -2
- package/src/components/DlPopup/DlPopup.vue +0 -1
- package/src/components/DlRange/DlRange.vue +3 -2
- package/src/components/DlSearch.vue +1 -1
- package/src/components/DlSelect/DlSelect.vue +3 -2
- package/src/components/DlSlider/sliderStyles.scss +4 -0
- package/src/components/DlSlider/useSlider.ts +39 -12
- package/src/components/DlSmartSearch/DlSuggestionsDropdown.vue +1 -1
- package/src/components/DlSpinner.vue +259 -0
- package/src/components/DlTable/DlTable.vue +4 -1
- package/src/components/DlTable/hooks/tablePagination.ts +8 -2
- package/src/components/DlTextArea.vue +9 -0
- package/src/components/DlTextInput.vue +4 -2
- package/src/components/DlThemeProvider.vue +22 -13
- package/src/components/DlToastMessage/api/useToast.ts +23 -0
- package/src/components/DlToastMessage/components/ToastComponent.vue +279 -0
- package/src/components/DlToastMessage/index.ts +5 -0
- package/src/components/DlToastMessage/types.ts +4 -0
- package/src/components/DlToastMessage/utils/config.ts +17 -0
- package/src/components/DlToastMessage/utils/render.ts +56 -0
- package/src/components/DlTypography.vue +1 -1
- package/src/components/DlWidget/DlGrid.vue +33 -0
- package/src/components/DlWidget/DlGridRow.vue +32 -0
- package/src/components/DlWidget/DlWidget.vue +202 -11
- package/src/components/DlWidget/index.ts +2 -2
- package/src/components/DlWidget/utils.ts +26 -19
- package/src/components/index.ts +8 -3
- package/src/demo/BarChartDemo.vue +77 -0
- package/src/demo/ColumnChartDemo.vue +230 -0
- package/src/demo/DlButtonDemo.vue +1 -1
- package/src/demo/DlChartDoughnutDemo.vue +229 -0
- package/src/demo/DlChipDemo.vue +42 -18
- package/src/demo/DlDialogBoxDemo.vue +4 -4
- package/src/demo/DlDropdownButtonDemo.vue +1 -1
- package/src/demo/DlLineChartDemo.vue +375 -0
- package/src/demo/DlMenuDemo.vue +1 -1
- package/src/demo/DlOptionGroupDemo.vue +1 -1
- package/src/demo/DlSelectDemo.vue +1 -1
- package/src/demo/DlSpinnerDemo.vue +20 -0
- package/src/demo/DlTableDemo.vue +13 -94
- package/src/demo/DlToastMessageDemo.vue +143 -0
- package/src/demo/DlWidgetDemo.vue +105 -143
- package/src/demo/index.ts +20 -2
- package/src/hooks/use-theme.ts +19 -0
- package/src/utils/abbreviate-to-string.ts +14 -0
- package/src/utils/colors.ts +47 -0
- package/src/utils/getRootStyles.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/position-engine.ts +11 -2
- package/src/utils/swapNodes.ts +30 -0
- package/src/utils/update-key.ts +90 -0
- package/tsconfig.json +0 -1
- package/vite.config.ts +17 -0
- package/Dockerfile +0 -12
- package/jest.config.js +0 -16
- package/jest.setup.js +0 -59
- package/src/components/DlWidget/DlWidgetGrid.vue +0 -360
- package/storybook.js +0 -8
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="wrapper">
|
|
3
|
+
<div
|
|
4
|
+
class="spinner"
|
|
5
|
+
:style="spinnerStyles"
|
|
6
|
+
>
|
|
7
|
+
<div
|
|
8
|
+
ref="spinBg"
|
|
9
|
+
class="spin-bg"
|
|
10
|
+
>
|
|
11
|
+
<svg
|
|
12
|
+
id="Layer_2"
|
|
13
|
+
data-name="Layer 2"
|
|
14
|
+
viewBox="0 0 140 140"
|
|
15
|
+
>
|
|
16
|
+
<g
|
|
17
|
+
id="Layer_1-2"
|
|
18
|
+
data-name="Layer 1"
|
|
19
|
+
>
|
|
20
|
+
<path
|
|
21
|
+
class="dl-svg"
|
|
22
|
+
d="M70,0C31.33,0,0,31.33,0,70s31.33,70,70,70,70-31.33,70-70S108.67,0,70,0Zm0,131.97c-34.2,0-61.97-27.77-61.97-61.97S35.8,8.03,70,8.03s61.97,27.77,61.97,61.97-27.77,61.97-61.97,61.97Z"
|
|
23
|
+
/>
|
|
24
|
+
</g>
|
|
25
|
+
</svg>
|
|
26
|
+
</div>
|
|
27
|
+
<div
|
|
28
|
+
ref="spinColor"
|
|
29
|
+
class="spin-loader"
|
|
30
|
+
>
|
|
31
|
+
<svg
|
|
32
|
+
id="Layer_2"
|
|
33
|
+
data-name="Layer 2"
|
|
34
|
+
viewBox="0 0 140 140"
|
|
35
|
+
>
|
|
36
|
+
<defs>
|
|
37
|
+
<linearGradient
|
|
38
|
+
id="linear-gradient"
|
|
39
|
+
x1="12.53"
|
|
40
|
+
y1="229.07"
|
|
41
|
+
x2="119.46"
|
|
42
|
+
y2="229.07"
|
|
43
|
+
gradientTransform="translate(0 246.89) scale(1 -1)"
|
|
44
|
+
gradientUnits="userSpaceOnUse"
|
|
45
|
+
>
|
|
46
|
+
<stop
|
|
47
|
+
offset="0"
|
|
48
|
+
:stop-color="color"
|
|
49
|
+
stop-opacity="0"
|
|
50
|
+
/>
|
|
51
|
+
<stop
|
|
52
|
+
offset=".12"
|
|
53
|
+
:stop-color="color"
|
|
54
|
+
stop-opacity="0"
|
|
55
|
+
/>
|
|
56
|
+
<stop
|
|
57
|
+
offset=".34"
|
|
58
|
+
:stop-color="color"
|
|
59
|
+
/>
|
|
60
|
+
<stop
|
|
61
|
+
offset=".69"
|
|
62
|
+
:stop-color="color"
|
|
63
|
+
/>
|
|
64
|
+
<stop
|
|
65
|
+
offset=".91"
|
|
66
|
+
:stop-color="color"
|
|
67
|
+
stop-opacity="0"
|
|
68
|
+
/>
|
|
69
|
+
</linearGradient>
|
|
70
|
+
</defs>
|
|
71
|
+
<g
|
|
72
|
+
id="Layer_1-2"
|
|
73
|
+
data-name="Layer 1"
|
|
74
|
+
>
|
|
75
|
+
<g>
|
|
76
|
+
<path
|
|
77
|
+
class="spinner-color-bg"
|
|
78
|
+
d="M70,0C31.33,0,0,31.33,0,70s31.33,70,70,70,70-31.33,70-70S108.67,0,70,0Zm0,131.97c-34.2,0-61.97-27.77-61.97-61.97S35.8,8.03,70,8.03s61.97,27.77,61.97,61.97-27.77,61.97-61.97,61.97Z"
|
|
79
|
+
/>
|
|
80
|
+
<path
|
|
81
|
+
class="spinner-color"
|
|
82
|
+
d="M114.87,25.82c1.38-1.38,2.87-2.75,4.25-4.13,.46-.34,.46-1.03,0-1.49C106.49,7.69,89.16,0,70,0,46.36,0,25.48,11.7,12.74,29.72c-.34,.46-.23,.92,.11,1.38l4.25,4.25c.46,.46,1.15,.34,1.61-.11,11.25-16.52,29.95-27.2,51.3-27.2,16.98,0,32.25,6.77,43.49,17.79,.34,.34,1.03,.34,1.38,0Z"
|
|
83
|
+
/>
|
|
84
|
+
</g>
|
|
85
|
+
</g>
|
|
86
|
+
</svg>
|
|
87
|
+
</div>
|
|
88
|
+
<div
|
|
89
|
+
ref="dlIcon"
|
|
90
|
+
class="dl-icon"
|
|
91
|
+
>
|
|
92
|
+
<svg
|
|
93
|
+
viewBox="0 0 51 45"
|
|
94
|
+
fill="none"
|
|
95
|
+
>
|
|
96
|
+
<path
|
|
97
|
+
d="M23.2962 0.558083H0.830566V32.2536L10.1727 44.284H23.2962V38.5002H12.6195L6.39136 30.4028V6.11058H23.2962V0.558083Z"
|
|
98
|
+
:fill="iconColor"
|
|
99
|
+
/>
|
|
100
|
+
<path
|
|
101
|
+
d="M27.5224 6.11058V0.558083C33.3056 -0.137737 52.8796 3.56565 50.6553 25.0816C48.9091 41.9727 34.3436 44.901 27.5224 44.284V38.5002C41.2242 39.4256 45.0945 29.1689 45.3169 23.9249C46.2067 8.19281 33.8246 5.49365 27.5224 6.11058Z"
|
|
102
|
+
:fill="iconColor"
|
|
103
|
+
/>
|
|
104
|
+
<path
|
|
105
|
+
d="M23.2962 19.0664V13.5139H13.0643V27.3952L16.8457 31.7909H23.2962V26.2384H19.07L18.6251 25.5443V19.0664H23.2962Z"
|
|
106
|
+
:fill="iconColor"
|
|
107
|
+
/>
|
|
108
|
+
<path
|
|
109
|
+
d="M27.5224 19.0664V13.5139C31.2296 13.2054 38.644 14.5782 38.644 22.5367C38.644 30.4953 31.2296 32.0223 27.5224 31.7909V26.2384C29.3018 26.7782 33.3056 26.9038 33.3056 22.9994C33.3056 19.0664 29.5984 18.758 27.5224 19.0664Z"
|
|
110
|
+
:fill="iconColor"
|
|
111
|
+
/>
|
|
112
|
+
</svg>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
<div
|
|
116
|
+
v-if="text"
|
|
117
|
+
class="spinner-text"
|
|
118
|
+
:style="textStyles"
|
|
119
|
+
>
|
|
120
|
+
<span>{{ text }}</span>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
</template>
|
|
124
|
+
|
|
125
|
+
<script>
|
|
126
|
+
import { defineComponent } from 'vue-demi'
|
|
127
|
+
|
|
128
|
+
export default defineComponent({
|
|
129
|
+
name: 'DlSpinner',
|
|
130
|
+
props: {
|
|
131
|
+
text: {
|
|
132
|
+
type: String,
|
|
133
|
+
default: null
|
|
134
|
+
},
|
|
135
|
+
textStyles: {
|
|
136
|
+
type: Object,
|
|
137
|
+
default: null
|
|
138
|
+
},
|
|
139
|
+
size: {
|
|
140
|
+
type: String,
|
|
141
|
+
default: '140px'
|
|
142
|
+
},
|
|
143
|
+
iconSize: {
|
|
144
|
+
type: String,
|
|
145
|
+
default: '50px'
|
|
146
|
+
},
|
|
147
|
+
borderColor: {
|
|
148
|
+
type: String,
|
|
149
|
+
default: 'var(--dl-color-separator)'
|
|
150
|
+
},
|
|
151
|
+
color: {
|
|
152
|
+
type: String,
|
|
153
|
+
default: 'var(--dl-color-secondary)'
|
|
154
|
+
},
|
|
155
|
+
iconColor: {
|
|
156
|
+
type: String,
|
|
157
|
+
default: 'var(--dl-color-tooltip-background)'
|
|
158
|
+
},
|
|
159
|
+
rotationSpeed: {
|
|
160
|
+
type: String,
|
|
161
|
+
default: '2s'
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
computed: {
|
|
165
|
+
spinnerStyles() {
|
|
166
|
+
return {
|
|
167
|
+
'--dl-spinner-size': this.size,
|
|
168
|
+
'--dl-spinner-icon-size': this.iconSize,
|
|
169
|
+
'--dl-spinner-border-color': this.borderColor,
|
|
170
|
+
'--dl-spinner-roation-speed': this.rotationSpeed
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
mounted() {
|
|
175
|
+
window.onresize = this.resizeSpinner
|
|
176
|
+
this.resizeSpinner()
|
|
177
|
+
},
|
|
178
|
+
methods: {
|
|
179
|
+
resizeSpinner() {
|
|
180
|
+
const spinColor = this.$refs.spinColor
|
|
181
|
+
const spinBg = this.$refs.spinBg
|
|
182
|
+
const icon = this.$refs.dlIcon
|
|
183
|
+
|
|
184
|
+
const info = spinBg.getBoundingClientRect()
|
|
185
|
+
const x = info.x + window.scrollX
|
|
186
|
+
const y = info.y + window.scrollY
|
|
187
|
+
|
|
188
|
+
spinColor.style.left = `${x}px`
|
|
189
|
+
spinColor.style.top = `${y}px`
|
|
190
|
+
icon.style.top = `${
|
|
191
|
+
y +
|
|
192
|
+
spinBg.offsetHeight -
|
|
193
|
+
spinBg.offsetHeight / 2 -
|
|
194
|
+
icon.offsetHeight / 2.3
|
|
195
|
+
}px`
|
|
196
|
+
icon.style.left = `${
|
|
197
|
+
x +
|
|
198
|
+
spinBg.offsetWidth -
|
|
199
|
+
spinBg.offsetWidth / 2 -
|
|
200
|
+
icon.offsetWidth / 2.3
|
|
201
|
+
}px`
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
</script>
|
|
206
|
+
|
|
207
|
+
<style scoped lang="scss">
|
|
208
|
+
.spin-loader,
|
|
209
|
+
.spin-bg {
|
|
210
|
+
width: var(--dl-spinner-size);
|
|
211
|
+
height: var(--dl-spinner-size);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.spin-loader {
|
|
215
|
+
position: absolute;
|
|
216
|
+
animation: spin var(--dl-spinner-roation-speed) linear infinite;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.dl-icon {
|
|
220
|
+
position: absolute;
|
|
221
|
+
width: var(--dl-spinner-icon-size);
|
|
222
|
+
height: var(--dl-spinner-icon-size);
|
|
223
|
+
opacity: 1;
|
|
224
|
+
animation: pulse var(--dl-spinner-roation-speed) infinite;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.dl-svg {
|
|
228
|
+
fill: var(--dl-spinner-border-color);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.spinner-color-bg {
|
|
232
|
+
fill: none;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.spinner-color {
|
|
236
|
+
fill: url(#linear-gradient);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@keyframes spin {
|
|
240
|
+
0% {
|
|
241
|
+
transform: rotate(0deg);
|
|
242
|
+
}
|
|
243
|
+
100% {
|
|
244
|
+
transform: rotate(360deg);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@keyframes pulse {
|
|
249
|
+
0% {
|
|
250
|
+
opacity: 1;
|
|
251
|
+
}
|
|
252
|
+
50% {
|
|
253
|
+
opacity: 0;
|
|
254
|
+
}
|
|
255
|
+
100% {
|
|
256
|
+
opacity: 1;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
</style>
|
|
@@ -1045,7 +1045,10 @@ export default defineComponent({
|
|
|
1045
1045
|
})
|
|
1046
1046
|
|
|
1047
1047
|
const marginalsScope = computed(() => ({
|
|
1048
|
-
pagination: paginationState.value
|
|
1048
|
+
pagination: paginationState.value,
|
|
1049
|
+
pagesNumber: pagesNumber.value,
|
|
1050
|
+
isFirstPage: isFirstPage.value,
|
|
1051
|
+
isLastPage: isLastPage.value
|
|
1049
1052
|
}))
|
|
1050
1053
|
|
|
1051
1054
|
function getCellValue(
|
|
@@ -54,6 +54,7 @@ export function useTablePaginationState(
|
|
|
54
54
|
getCellValue: Function
|
|
55
55
|
) {
|
|
56
56
|
const { props, emit } = vm
|
|
57
|
+
|
|
57
58
|
const innerPagination = ref(
|
|
58
59
|
Object.assign(
|
|
59
60
|
{
|
|
@@ -72,7 +73,8 @@ export function useTablePaginationState(
|
|
|
72
73
|
withQuickNavigation: true,
|
|
73
74
|
itemsName: 'Rows',
|
|
74
75
|
withLegend: true,
|
|
75
|
-
withRowsPerPage: true
|
|
76
|
+
withRowsPerPage: true,
|
|
77
|
+
rowsPerPageOptions: props.rowsPerPageOptions
|
|
76
78
|
},
|
|
77
79
|
props.pagination
|
|
78
80
|
)
|
|
@@ -137,7 +139,11 @@ export function useTablePagination(
|
|
|
137
139
|
) {
|
|
138
140
|
const { props, emit } = vm
|
|
139
141
|
|
|
140
|
-
const computedRowsNumber = computed(
|
|
142
|
+
const computedRowsNumber = computed(
|
|
143
|
+
() =>
|
|
144
|
+
computedPagination.value?.rowsNumber ??
|
|
145
|
+
filteredSortedRowsNumber.value
|
|
146
|
+
)
|
|
141
147
|
|
|
142
148
|
const firstRowIndex = computed(() => {
|
|
143
149
|
const { page, rowsPerPage } = computedPagination.value
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
:style="cssVars"
|
|
6
6
|
>
|
|
7
7
|
<textarea
|
|
8
|
+
ref="textarea"
|
|
8
9
|
:value="modelValue"
|
|
9
10
|
class="textarea"
|
|
10
11
|
:placeholder="placeholder"
|
|
@@ -85,6 +86,14 @@ export default defineComponent({
|
|
|
85
86
|
},
|
|
86
87
|
onBlur(e: InputEvent) {
|
|
87
88
|
this.$emit('blur', e)
|
|
89
|
+
},
|
|
90
|
+
focus() {
|
|
91
|
+
const inputRef = this.$refs.textarea as HTMLTextAreaElement
|
|
92
|
+
inputRef.focus()
|
|
93
|
+
},
|
|
94
|
+
blur() {
|
|
95
|
+
const inputRef = this.$refs.textarea as HTMLTextAreaElement
|
|
96
|
+
inputRef.blur()
|
|
88
97
|
}
|
|
89
98
|
}
|
|
90
99
|
})
|
|
@@ -118,7 +118,8 @@
|
|
|
118
118
|
auto-close
|
|
119
119
|
no-focus
|
|
120
120
|
:offset="[0, 3]"
|
|
121
|
-
fit
|
|
121
|
+
fit-container
|
|
122
|
+
:fit-content="fitContent"
|
|
122
123
|
@click="onMenuShow"
|
|
123
124
|
>
|
|
124
125
|
<dl-list
|
|
@@ -323,7 +324,8 @@ export default defineComponent({
|
|
|
323
324
|
clearButtonTooltip: {
|
|
324
325
|
type: Boolean,
|
|
325
326
|
default: false
|
|
326
|
-
}
|
|
327
|
+
},
|
|
328
|
+
fitContent: Boolean
|
|
327
329
|
},
|
|
328
330
|
emits: ['input', 'focus', 'blur', 'clear', 'enter', 'update:model-value'],
|
|
329
331
|
data() {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script lang="ts">
|
|
8
|
-
import { defineComponent } from 'vue-demi'
|
|
8
|
+
import { defineComponent, onMounted, watch, provide, ref } from 'vue-demi'
|
|
9
9
|
import { getThemeModeAttr } from '../utils'
|
|
10
10
|
import '@dataloop-ai/icons/docs/style.css'
|
|
11
11
|
import { v4 } from 'uuid'
|
|
@@ -18,22 +18,31 @@ export default defineComponent({
|
|
|
18
18
|
default: false
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
+
setup(props) {
|
|
22
|
+
onMounted(() => {
|
|
23
|
+
const mode = getThemeModeAttr(props.isDark)
|
|
24
|
+
document.documentElement.setAttribute('data-theme', mode)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const isDarkTheme = ref(props.isDark)
|
|
28
|
+
|
|
29
|
+
provide('theme', isDarkTheme)
|
|
30
|
+
|
|
31
|
+
watch(
|
|
32
|
+
() => props.isDark,
|
|
33
|
+
(isDark: boolean) => {
|
|
34
|
+
isDarkTheme.value = isDark
|
|
35
|
+
document.documentElement.setAttribute(
|
|
36
|
+
'data-theme',
|
|
37
|
+
getThemeModeAttr(isDark)
|
|
38
|
+
) // sets the dl data-theme attr
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
},
|
|
21
42
|
data() {
|
|
22
43
|
return {
|
|
23
44
|
uuid: `dl-theme-provider-${v4()}`
|
|
24
45
|
}
|
|
25
|
-
},
|
|
26
|
-
watch: {
|
|
27
|
-
isDark(colorMode: boolean) {
|
|
28
|
-
document.documentElement.setAttribute(
|
|
29
|
-
'data-theme',
|
|
30
|
-
getThemeModeAttr(colorMode)
|
|
31
|
-
) // sets the dl data-theme attr
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
created() {
|
|
35
|
-
const mode = getThemeModeAttr(this.isDark)
|
|
36
|
-
document.documentElement.setAttribute('data-theme', mode)
|
|
37
46
|
}
|
|
38
47
|
})
|
|
39
48
|
</script>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import toastComponent from '../components/ToastComponent.vue'
|
|
2
|
+
import { createComponent } from '../utils/render'
|
|
3
|
+
|
|
4
|
+
export const useToast = (globalProps = {}) => {
|
|
5
|
+
return {
|
|
6
|
+
open(options: Object | string) {
|
|
7
|
+
let message = null
|
|
8
|
+
if (typeof options === 'string') message = options
|
|
9
|
+
|
|
10
|
+
const defaultProps = {
|
|
11
|
+
message
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const propsData = Object.assign(
|
|
15
|
+
{},
|
|
16
|
+
defaultProps,
|
|
17
|
+
globalProps,
|
|
18
|
+
options
|
|
19
|
+
)
|
|
20
|
+
createComponent(toastComponent, propsData, document.body)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition
|
|
3
|
+
:enter-active-class="transition.enter"
|
|
4
|
+
:leave-active-class="transition.leave"
|
|
5
|
+
>
|
|
6
|
+
<div
|
|
7
|
+
v-show="isActive"
|
|
8
|
+
ref="root"
|
|
9
|
+
class="v-toast__item"
|
|
10
|
+
:class="[
|
|
11
|
+
`v-toast__item--${type}`,
|
|
12
|
+
`v-toast__item--${position}`,
|
|
13
|
+
classItem
|
|
14
|
+
]"
|
|
15
|
+
>
|
|
16
|
+
<dl-alert
|
|
17
|
+
:type="type"
|
|
18
|
+
:closable="closable"
|
|
19
|
+
@update:model-value="(val) => closeToast(val)"
|
|
20
|
+
>
|
|
21
|
+
<span
|
|
22
|
+
class="v-toast__text"
|
|
23
|
+
data-test="message-text"
|
|
24
|
+
/>
|
|
25
|
+
</dl-alert>
|
|
26
|
+
</div>
|
|
27
|
+
</transition>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import {
|
|
32
|
+
defineComponent,
|
|
33
|
+
ref,
|
|
34
|
+
onBeforeMount,
|
|
35
|
+
computed,
|
|
36
|
+
onMounted
|
|
37
|
+
} from 'vue-demi'
|
|
38
|
+
import DlAlert from '../../DlAlert.vue'
|
|
39
|
+
import { Positions, Types } from '../utils/config'
|
|
40
|
+
import { removeElement } from '../utils/render'
|
|
41
|
+
import { Animation } from '../types'
|
|
42
|
+
|
|
43
|
+
export default defineComponent({
|
|
44
|
+
name: 'ToastComponent',
|
|
45
|
+
components: { DlAlert },
|
|
46
|
+
props: {
|
|
47
|
+
message: {
|
|
48
|
+
type: String,
|
|
49
|
+
required: true
|
|
50
|
+
},
|
|
51
|
+
type: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: 'success',
|
|
54
|
+
validator(value: string): boolean {
|
|
55
|
+
return Object.values(Types as unknown).includes(value)
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
classItem: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: ''
|
|
61
|
+
},
|
|
62
|
+
duration: {
|
|
63
|
+
type: Number,
|
|
64
|
+
default: 10
|
|
65
|
+
},
|
|
66
|
+
position: {
|
|
67
|
+
type: String,
|
|
68
|
+
default: Positions.bottom,
|
|
69
|
+
validator(value: string): boolean {
|
|
70
|
+
return Object.values(Positions as unknown).includes(value)
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
closable: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
setup(props: any) {
|
|
79
|
+
const { position, duration, message } = props
|
|
80
|
+
const root = ref(null)
|
|
81
|
+
let parentTop: HTMLElement = null
|
|
82
|
+
let parentBottom: HTMLElement = null
|
|
83
|
+
const toastParentPosition = ref(null)
|
|
84
|
+
const isActive = ref(false)
|
|
85
|
+
function closeToastMessage(): void {
|
|
86
|
+
isActive.value = false
|
|
87
|
+
setTimeout(() => removeElement(root.value), 200)
|
|
88
|
+
}
|
|
89
|
+
onBeforeMount(() => {
|
|
90
|
+
setupContainer()
|
|
91
|
+
})
|
|
92
|
+
function setupContainer(): void {
|
|
93
|
+
parentTop = document.querySelector('.v-toast.v-toast--top')
|
|
94
|
+
parentBottom = document.querySelector('.v-toast.v-toast--bottom')
|
|
95
|
+
if (parentTop && parentBottom) return
|
|
96
|
+
if (!parentTop) {
|
|
97
|
+
parentTop = document.createElement('div')
|
|
98
|
+
parentTop.className = 'v-toast v-toast--top'
|
|
99
|
+
}
|
|
100
|
+
if (!parentBottom) {
|
|
101
|
+
parentBottom = document.createElement('div')
|
|
102
|
+
parentBottom.className = 'v-toast v-toast--bottom'
|
|
103
|
+
}
|
|
104
|
+
const container = document.body
|
|
105
|
+
container.appendChild(parentTop)
|
|
106
|
+
container.appendChild(parentBottom)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const correctParent = computed(() => {
|
|
110
|
+
switch (position) {
|
|
111
|
+
case Positions.top:
|
|
112
|
+
case Positions.top_right:
|
|
113
|
+
case Positions.top_left:
|
|
114
|
+
toastParentPosition.value = 'top'
|
|
115
|
+
return parentTop
|
|
116
|
+
case Positions.bottom:
|
|
117
|
+
case Positions.bottom_right:
|
|
118
|
+
case Positions.bottom_left:
|
|
119
|
+
toastParentPosition.value = 'bottom'
|
|
120
|
+
return parentBottom
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const transition = computed((): Animation => {
|
|
125
|
+
switch (position) {
|
|
126
|
+
case Positions.top:
|
|
127
|
+
case Positions.top_right:
|
|
128
|
+
case Positions.top_left:
|
|
129
|
+
return {
|
|
130
|
+
enter: 'v-toast--fade-in-down',
|
|
131
|
+
leave: 'v-toast--fade-out'
|
|
132
|
+
}
|
|
133
|
+
case Positions.bottom:
|
|
134
|
+
case Positions.bottom_right:
|
|
135
|
+
case Positions.bottom_left:
|
|
136
|
+
return {
|
|
137
|
+
enter: 'v-toast--fade-in-up',
|
|
138
|
+
leave: 'v-toast--fade-out'
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
onMounted(() => {
|
|
144
|
+
showNotice()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
function showNotice(): void {
|
|
148
|
+
const parent = correctParent.value
|
|
149
|
+
const container = root.value.closest('.v-toast--pending')
|
|
150
|
+
root.value.querySelector('.v-toast__text').innerHTML = message
|
|
151
|
+
parent.insertAdjacentElement('afterbegin', root.value)
|
|
152
|
+
container?.remove()
|
|
153
|
+
isActive.value = true
|
|
154
|
+
if (duration) {
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
closeToastMessage()
|
|
157
|
+
}, duration * 1000)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function closeToast(val: boolean) {
|
|
161
|
+
if (!val) removeElement(root.value)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
root,
|
|
166
|
+
transition,
|
|
167
|
+
isActive,
|
|
168
|
+
closeToast,
|
|
169
|
+
correctParent
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
</script>
|
|
174
|
+
|
|
175
|
+
<style lang="scss">
|
|
176
|
+
.v-toast {
|
|
177
|
+
position: fixed;
|
|
178
|
+
display: flex;
|
|
179
|
+
top: 0;
|
|
180
|
+
bottom: 0;
|
|
181
|
+
left: 0;
|
|
182
|
+
right: 0;
|
|
183
|
+
overflow: hidden;
|
|
184
|
+
z-index: 1052;
|
|
185
|
+
pointer-events: none;
|
|
186
|
+
&__text {
|
|
187
|
+
min-width: 300px;
|
|
188
|
+
max-width: 800px;
|
|
189
|
+
}
|
|
190
|
+
&__item {
|
|
191
|
+
display: inline-flex;
|
|
192
|
+
align-items: center;
|
|
193
|
+
pointer-events: auto;
|
|
194
|
+
margin-bottom: 5px;
|
|
195
|
+
margin-top: 5px;
|
|
196
|
+
cursor: pointer;
|
|
197
|
+
animation-duration: 150ms;
|
|
198
|
+
&.v-toast__item--top,
|
|
199
|
+
&.v-toast__item--bottom {
|
|
200
|
+
align-self: center;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
&.v-toast__item--top-right,
|
|
204
|
+
&.v-toast__item--bottom-right {
|
|
205
|
+
align-self: flex-end;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&.v-toast__item--top-left,
|
|
209
|
+
&.v-toast__item--bottom-left {
|
|
210
|
+
align-self: flex-start;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
&.v-toast--top {
|
|
215
|
+
flex-direction: column;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
&.v-toast--bottom {
|
|
219
|
+
flex-direction: column-reverse;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@keyframes fadeOut {
|
|
224
|
+
from {
|
|
225
|
+
opacity: 1;
|
|
226
|
+
}
|
|
227
|
+
to {
|
|
228
|
+
opacity: 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.v-toast--fade-out {
|
|
233
|
+
animation-name: fadeOut;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@keyframes fadeInDown {
|
|
237
|
+
from {
|
|
238
|
+
opacity: 0;
|
|
239
|
+
transform: translate3d(0, -100%, 0);
|
|
240
|
+
}
|
|
241
|
+
to {
|
|
242
|
+
opacity: 1;
|
|
243
|
+
transform: none;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.v-toast--fade-in-down {
|
|
248
|
+
animation-name: fadeInDown;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
@keyframes fadeInUp {
|
|
252
|
+
from {
|
|
253
|
+
opacity: 0;
|
|
254
|
+
transform: translate3d(0, 100%, 0);
|
|
255
|
+
}
|
|
256
|
+
to {
|
|
257
|
+
opacity: 1;
|
|
258
|
+
transform: none;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.v-toast--fade-in-up {
|
|
263
|
+
animation-name: fadeInUp;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Vue Transitions
|
|
268
|
+
*/
|
|
269
|
+
|
|
270
|
+
.fade-enter-active,
|
|
271
|
+
.fade-leave-active {
|
|
272
|
+
transition: opacity 150ms ease-out;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.fade-enter,
|
|
276
|
+
.fade-leave-to {
|
|
277
|
+
opacity: 0;
|
|
278
|
+
}
|
|
279
|
+
</style>
|