@dataloop-ai/components 0.16.30 → 0.16.32
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
|
@@ -7,29 +7,60 @@
|
|
|
7
7
|
<textarea
|
|
8
8
|
ref="textarea"
|
|
9
9
|
:value="modelValue"
|
|
10
|
-
class="
|
|
10
|
+
:class="textareaClasses"
|
|
11
11
|
:placeholder="placeholder"
|
|
12
12
|
:maxlength="maxLength"
|
|
13
13
|
:disabled="disabled"
|
|
14
|
-
:class="!enableResize ? 'textarea-disable-resize' : ''"
|
|
15
14
|
@input="onChange"
|
|
16
15
|
@keydown="onKeydown"
|
|
17
16
|
@focus="onFocus"
|
|
18
17
|
@blur="onBlur"
|
|
19
18
|
/>
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
<div
|
|
20
|
+
v-if="bottomMessage || showCounter"
|
|
21
|
+
class="dl-textarea--bottom-container"
|
|
22
|
+
>
|
|
23
|
+
<dl-info-error-message
|
|
24
|
+
v-if="!!infoMessage.length && !error && !warning"
|
|
25
|
+
position="below"
|
|
26
|
+
:value="infoMessage"
|
|
27
|
+
/>
|
|
28
|
+
<dl-info-error-message
|
|
29
|
+
v-if="error && !!errorMessage && !!errorMessage.length"
|
|
30
|
+
position="below"
|
|
31
|
+
error
|
|
32
|
+
:value="errorMessage"
|
|
33
|
+
/>
|
|
34
|
+
<dl-info-error-message
|
|
35
|
+
v-if="
|
|
36
|
+
warning &&
|
|
37
|
+
!!warningMessage &&
|
|
38
|
+
!!warningMessage.length &&
|
|
39
|
+
!error
|
|
40
|
+
"
|
|
41
|
+
position="below"
|
|
42
|
+
warning
|
|
43
|
+
:value="warningMessage"
|
|
44
|
+
/>
|
|
45
|
+
<span v-show="showCounter">
|
|
46
|
+
{{ modelValue.length
|
|
47
|
+
}}{{ maxLength && maxLength > 0 ? `/${maxLength}` : null }}
|
|
48
|
+
</span>
|
|
49
|
+
</div>
|
|
24
50
|
</div>
|
|
25
51
|
</template>
|
|
26
52
|
|
|
27
53
|
<script lang="ts">
|
|
28
54
|
import { v4 } from 'uuid'
|
|
29
|
-
import {
|
|
55
|
+
import { DlInfoErrorMessage } from '../../shared'
|
|
56
|
+
import { defineComponent, computed, ref } from 'vue-demi'
|
|
57
|
+
import { useSizeObserver } from '../../../hooks/use-size-observer'
|
|
30
58
|
|
|
31
59
|
export default defineComponent({
|
|
32
60
|
name: 'DlTextArea',
|
|
61
|
+
components: {
|
|
62
|
+
DlInfoErrorMessage
|
|
63
|
+
},
|
|
33
64
|
model: {
|
|
34
65
|
prop: 'modelValue',
|
|
35
66
|
event: 'update:model-value'
|
|
@@ -62,19 +93,72 @@ export default defineComponent({
|
|
|
62
93
|
enableResize: {
|
|
63
94
|
type: Boolean,
|
|
64
95
|
default: false
|
|
96
|
+
},
|
|
97
|
+
infoMessage: {
|
|
98
|
+
type: String,
|
|
99
|
+
default: ''
|
|
100
|
+
},
|
|
101
|
+
errorMessage: {
|
|
102
|
+
type: String,
|
|
103
|
+
default: ''
|
|
104
|
+
},
|
|
105
|
+
error: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: false
|
|
108
|
+
},
|
|
109
|
+
warningMessage: {
|
|
110
|
+
type: String,
|
|
111
|
+
default: ''
|
|
112
|
+
},
|
|
113
|
+
warning: {
|
|
114
|
+
type: Boolean,
|
|
115
|
+
default: false
|
|
65
116
|
}
|
|
66
117
|
},
|
|
67
118
|
emits: ['input', 'focus', 'blur', 'update:model-value', 'keydown'],
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
cssVars()
|
|
119
|
+
setup(props) {
|
|
120
|
+
const uuid = ref(`dl-text-area-${v4()}`)
|
|
121
|
+
const textarea = ref(null)
|
|
122
|
+
|
|
123
|
+
const { borderBoxSize } = useSizeObserver(textarea)
|
|
124
|
+
|
|
125
|
+
const cssVars = computed(() => {
|
|
75
126
|
return {
|
|
76
|
-
'--dl-textarea-width':
|
|
127
|
+
'--dl-textarea-max-width': props.width || 'auto',
|
|
128
|
+
'--dl-textarea-width':
|
|
129
|
+
borderBoxSize.value?.[0].inlineSize + 'px' || '100%'
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const bottomMessage = computed(() => {
|
|
134
|
+
return (
|
|
135
|
+
!!props.infoMessage?.length ||
|
|
136
|
+
!!props.errorMessage?.length ||
|
|
137
|
+
!!props.warningMessage?.length
|
|
138
|
+
)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const textareaClasses = computed(() => {
|
|
142
|
+
const classes = ['dl-textarea']
|
|
143
|
+
if (props.error) {
|
|
144
|
+
classes.push('dl-textarea--error')
|
|
145
|
+
} else if (props.warning) {
|
|
146
|
+
classes.push('dl-textarea--warning')
|
|
77
147
|
}
|
|
148
|
+
|
|
149
|
+
if (!props.enableResize) {
|
|
150
|
+
classes.push('dl-textarea--disable-resize')
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return classes
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
uuid,
|
|
158
|
+
cssVars,
|
|
159
|
+
bottomMessage,
|
|
160
|
+
textareaClasses,
|
|
161
|
+
textarea
|
|
78
162
|
}
|
|
79
163
|
},
|
|
80
164
|
methods: {
|
|
@@ -109,10 +193,10 @@ export default defineComponent({
|
|
|
109
193
|
flex-direction: column;
|
|
110
194
|
align-items: flex-end;
|
|
111
195
|
width: 100%;
|
|
112
|
-
max-width: var(--dl-textarea-width);
|
|
196
|
+
max-width: var(--dl-textarea-max-width);
|
|
113
197
|
}
|
|
114
198
|
|
|
115
|
-
.textarea {
|
|
199
|
+
.dl-textarea {
|
|
116
200
|
background: none;
|
|
117
201
|
border: 1px solid var(--dl-color-separator);
|
|
118
202
|
border-radius: 2px;
|
|
@@ -152,9 +236,30 @@ export default defineComponent({
|
|
|
152
236
|
color: rgba(0, 0, 0, 0);
|
|
153
237
|
}
|
|
154
238
|
|
|
155
|
-
|
|
239
|
+
&--disable-resize {
|
|
156
240
|
resize: none;
|
|
157
241
|
}
|
|
242
|
+
|
|
243
|
+
&--error {
|
|
244
|
+
border-color: var(--dl-color-negative);
|
|
245
|
+
&:hover {
|
|
246
|
+
border-color: var(--dl-color-separator) !important;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
&--warning {
|
|
251
|
+
border-color: var(--dl-color-warning);
|
|
252
|
+
&:hover {
|
|
253
|
+
border-color: var(--dl-color-separator) !important;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
&--bottom-container {
|
|
258
|
+
display: flex;
|
|
259
|
+
justify-content: space-between;
|
|
260
|
+
text-align: left;
|
|
261
|
+
width: var(--dl-textarea-width);
|
|
262
|
+
}
|
|
158
263
|
}
|
|
159
264
|
|
|
160
265
|
span {
|
|
@@ -5,11 +5,13 @@ export function useSizeObserver(elRef: Ref) {
|
|
|
5
5
|
const widthRef = ref(0)
|
|
6
6
|
const heightRef = ref(0)
|
|
7
7
|
const hasEllipsis = ref(false)
|
|
8
|
+
const borderBoxSize = ref(null)
|
|
8
9
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
9
10
|
for (const entry of entries) {
|
|
10
11
|
hasEllipsis.value = isEllipsisActive(entry.target)
|
|
11
12
|
widthRef.value = entry.contentRect.width
|
|
12
13
|
heightRef.value = entry.contentRect.height
|
|
14
|
+
borderBoxSize.value = entry.borderBoxSize
|
|
13
15
|
}
|
|
14
16
|
})
|
|
15
17
|
|
|
@@ -19,6 +21,7 @@ export function useSizeObserver(elRef: Ref) {
|
|
|
19
21
|
return {
|
|
20
22
|
widthRef,
|
|
21
23
|
heightRef,
|
|
22
|
-
hasEllipsis
|
|
24
|
+
hasEllipsis,
|
|
25
|
+
borderBoxSize
|
|
23
26
|
}
|
|
24
27
|
}
|