-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathNcInputConfirmCancel.vue
More file actions
185 lines (159 loc) Ā· 3.33 KB
/
NcInputConfirmCancel.vue
File metadata and controls
185 lines (159 loc) Ā· 3.33 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
<!--
- SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<docs>
# Usage
```
<NcInputConfirmCancel @confirm="alert('confirm')" @cancel="alert('cancel')" />
```
</docs>
<template>
<div class="app-navigation-input-confirm" :class="{ 'app-navigation-input-confirm--legacy': isLegacy34 }">
<form
@submit.prevent="confirm"
@keydown.esc.exact.stop.prevent="cancel"
@click.stop.prevent>
<input
ref="input"
v-model="valueModel"
type="text"
class="app-navigation-input-confirm__input"
:placeholder="placeholder">
<NcButton
:aria-label="labelConfirm"
type="submit"
variant="primary"
@click.stop.prevent="confirm">
<template #icon>
<IconArrowRight :size="20" />
</template>
</NcButton>
<NcButton
:aria-label="labelCancel"
type="reset"
:variant="primary ? 'primary' : 'tertiary'"
@click.stop.prevent="cancel">
<template #icon>
<IconClose :size="20" />
</template>
</NcButton>
</form>
</div>
</template>
<script>
import IconArrowRight from 'vue-material-design-icons/ArrowRight.vue'
import IconClose from 'vue-material-design-icons/Close.vue'
import { t } from '../../l10n.ts'
import { isLegacy34 } from '../../utils/legacy.ts'
import NcButton from '../NcButton/index.js'
export default {
name: 'NcInputConfirmCancel',
components: {
IconArrowRight,
IconClose,
NcButton,
},
setup() {
return { isLegacy34 }
},
props: {
/**
* If this element is used on a primary element set to true for primary styling.
*/
primary: {
default: false,
type: Boolean,
},
/**
* Placeholder of the edit field
*/
placeholder: {
default: '',
type: String,
},
/**
* The current name (model value)
*/
modelValue: {
default: '',
type: String,
},
},
emits: [
'cancel',
'confirm',
'update:modelValue',
],
data() {
return {
labelConfirm: t('Confirm changes'),
labelCancel: t('Cancel changes'),
}
},
computed: {
valueModel: {
get() { return this.modelValue },
set(newValue) {
this.$emit('update:modelValue', newValue)
},
},
},
methods: {
confirm() {
this.$emit('confirm')
},
cancel() {
this.$emit('cancel')
},
focusInput() {
this.$refs.input.focus()
},
},
}
</script>
<style scoped lang="scss">
$input-height: 34px;
$input-padding: 7px;
$input-margin: 5px;
.app-navigation-input-confirm {
flex: 1 0 100%;
width: 100%;
form {
display: flex;
}
&__input {
height: $input-height;
flex: 1 1 100%;
font-size: 100% !important;
margin: $input-margin !important;
margin-inline-start: -1px - $input-padding !important;
padding: $input-padding !important;
&:active,
&:focus,
&:hover {
outline: none;
background-color: var(--color-main-background);
color: var(--color-main-text);
border-color: var(--color-primary-element);
}
}
// New design (NC34+): square confirm/cancel buttons with consistent gaps.
&:not(&--legacy) {
form {
align-items: center;
gap: $input-margin;
padding-inline-end: $input-margin;
}
.app-navigation-input-confirm__input {
margin-inline-end: 0 !important;
}
:deep(.button-vue) {
width: $input-height !important;
min-width: $input-height !important;
height: $input-height !important;
flex: 0 0 $input-height;
}
}
}
</style>