-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathQuestionColor.vue
More file actions
127 lines (112 loc) · 2.78 KB
/
Copy pathQuestionColor.vue
File metadata and controls
127 lines (112 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!--
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<Question
v-bind="questionProps"
:titlePlaceholder="answerType.titlePlaceholder"
:warningInvalid="answerType.warningInvalid"
:errorMessage="errorMessage"
v-on="commonListeners">
<div
class="question__content"
role="group"
:aria-labelledby="titleId"
:aria-describedby="description ? descriptionId : undefined">
<NcColorPicker
:modelValue="pickedColor"
advancedFields
:aria-required="isRequired"
:aria-errormessage="hasError ? errorId : undefined"
:aria-invalid="hasError ? 'true' : undefined"
@update:modelValue="onUpdatePickedColor">
<NcButton :disabled="!readOnly">
{{ colorPickerPlaceholder }}
</NcButton>
</NcColorPicker>
<div :style="{ 'background-color': pickedColor }" class="color__field">
<NcButton
v-if="pickedColor !== '' && !isRequired"
class="color__field__button"
:aria-label="t('forms', 'Clear selected color')"
variant="tertiary"
@click="onUpdatePickedColor('')">
<template #icon>
<NcIconSvgWrapper :svg="IconClose" />
</template>
</NcButton>
</div>
</div>
<template #insert>
<slot name="insert" />
</template>
</Question>
</template>
<script>
import IconClose from '@material-symbols/svg-400/outlined/close.svg?raw'
import NcButton from '@nextcloud/vue/components/NcButton'
import NcColorPicker from '@nextcloud/vue/components/NcColorPicker'
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
import Question from './Question.vue'
import QuestionMixin from '../../mixins/QuestionMixin.js'
export default {
name: 'QuestionColor',
components: {
NcIconSvgWrapper,
NcButton,
NcColorPicker,
Question,
},
mixins: [QuestionMixin],
emits: ['update:values'],
setup() {
return {
IconClose,
}
},
data() {
return {
isLoading: false,
}
},
computed: {
colorPickerPlaceholder() {
return this.readOnly
? this.answerType.submitPlaceholder
: this.answerType.createPlaceholder
},
pickedColor() {
return this.values[0] ?? ''
},
},
methods: {
async validate() {
if (this.isRequired && this.pickedColor === '') {
this.errorMessage = t('forms', 'You must answer this question')
return false
}
this.errorMessage = null
return true
},
onUpdatePickedColor(color) {
this.$emit('update:values', [color])
},
},
}
</script>
<style lang="scss" scoped>
.question__content {
display: flex;
gap: var(--clickable-area-small);
}
.color__field {
width: 100px;
height: var(--default-clickable-area);
border-radius: var(--border-radius-element);
&__button {
position: relative;
margin-inline-start: calc(100% - var(--default-clickable-area));
}
}
</style>