-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathEditNameDialog.vue
More file actions
186 lines (173 loc) · 3.69 KB
/
EditNameDialog.vue
File metadata and controls
186 lines (173 loc) · 3.69 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!--
- SPDX-FileCopyrightText: 2025 LibreCode coop and LibreCode contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcDialog
:name="title"
:buttons="dialogButtons">
<NcNoteCard v-if="localSuccessMessage" type="success">
{{ localSuccessMessage }}
</NcNoteCard>
<NcNoteCard v-if="localErrorMessage" type="error">
{{ localErrorMessage }}
</NcNoteCard>
<div class="edit-name-form">
<label :for="inputId">{{ label }}</label>
<input
:id="inputId"
v-model="localName"
type="text"
class="name-input"
:placeholder="placeholder"
minlength="3"
maxlength="255"
@keydown.enter="handleSave" />
<span class="character-count">{{ localName.length }} / 255</span>
</div>
</NcDialog>
</template>
<script>
import NcButton from '@nextcloud/vue/components/NcButton'
import NcDialog from '@nextcloud/vue/components/NcDialog'
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
export default {
name: 'EditNameDialog',
components: {
NcButton,
NcDialog,
NcNoteCard,
},
props: {
name: {
type: String,
default: '',
},
title: {
type: String,
default: 'Edit name',
},
label: {
type: String,
default: 'Name',
},
placeholder: {
type: String,
default: 'Enter name',
},
},
emits: ['close'],
data() {
return {
localName: this.name || '',
localSuccessMessage: '',
localErrorMessage: '',
inputId: `edit-name-${Math.random().toString(36).substr(2, 9)}`,
}
},
computed: {
isNameValid() {
const trimmedName = this.localName.trim()
return trimmedName.length >= 3 && trimmedName.length <= 255
},
dialogButtons() {
return [
{
label: this.t('libresign', 'Cancel'),
callback: () => {
this.handleClose()
},
},
{
label: this.t('libresign', 'Save'),
type: 'primary',
disabled: !this.isNameValid,
callback: () => {
this.handleSave()
},
},
]
},
},
watch: {
name(newVal) {
this.localName = newVal || ''
},
},
methods: {
clearMessages() {
this.localSuccessMessage = ''
this.localErrorMessage = ''
},
showSuccess(message) {
this.clearMessages()
this.localSuccessMessage = message
setTimeout(() => {
this.localSuccessMessage = ''
}, 5000)
},
showError(message) {
this.clearMessages()
this.localErrorMessage = message
},
handleClose() {
this.$emit('close', null)
},
handleSave() {
if (!this.isNameValid) {
return
}
const trimmedName = this.localName.trim()
if (!trimmedName) {
this.showError(this.t('libresign', 'Name cannot be empty'))
return
}
if (trimmedName.length < 3) {
this.showError(this.t('libresign', 'Name must be at least {min} characters', { min: 3 }))
return
}
if (trimmedName.length > 255) {
this.showError(this.t('libresign', 'Name must not exceed {max} characters', { max: 255 }))
return
}
this.$emit('close', trimmedName)
},
},
}
</script>
<style scoped>
.edit-name-form {
display: flex;
flex-direction: column;
gap: 12px;
padding: 8px 0;
}
.edit-name-form label {
font-weight: 500;
color: var(--color-text);
font-size: 14px;
}
.name-input {
padding: 12px 16px;
border: 2px solid var(--color-border-dark);
border-radius: var(--border-radius-large);
font-size: 16px;
width: 100%;
min-width: 300px;
transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.name-input:hover {
border-color: var(--color-primary-element);
}
.name-input:focus {
outline: none;
border-color: var(--color-primary-element);
box-shadow: 0 0 0 4px rgba(var(--color-primary-element-rgb), 0.1);
}
.character-count {
font-size: 12px;
color: var(--color-text-maxcontrast);
text-align: right;
margin-top: -4px;
}
</style>