Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TaskCheckbox.vue « components « src - github.com/nextcloud/tasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d86a9c62766b4070e5af462f1644b09d0633d9c (plain)
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
<!--
Nextcloud - Tasks

@author Raimund Schlüßler
@copyright 2022 Raimund Schlüßler <raimund.schluessler@mailbox.org>

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU AFFERO GENERAL PUBLIC LICENSE for more details.

You should have received a copy of the GNU Affero General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.

-->

<template>
	<div class="task-checkbox">
		<input :id="checkboxId"
			type="checkbox"
			:class="{'disabled': readOnly}"
			:checked="completed"
			:aria-checked="completed"
			:disabled="readOnly"
			:aria-label="ariaLabel"
			@click="toggleCompleted()">
		<label :class="[priorityClass]" :for="checkboxId">
			<CheckboxBlankOffOutline v-if="cancelled && !completed" :size="22" />
			<CheckboxOutline v-else-if="completed" :size="22" />
			<CheckboxBlank v-else-if="readOnly" :size="22" />
			<CheckboxBlankOutline v-else :size="22" />
		</label>
	</div>
</template>

<script>
import { translate as t } from '@nextcloud/l10n'

import CheckboxBlank from 'vue-material-design-icons/CheckboxBlank.vue'
import CheckboxBlankOffOutline from 'vue-material-design-icons/CheckboxBlankOffOutline.vue'
import CheckboxBlankOutline from 'vue-material-design-icons/CheckboxBlankOutline.vue'
import CheckboxOutline from 'vue-material-design-icons/CheckboxOutline.vue'

export default {
	components: {
		CheckboxBlank,
		CheckboxBlankOffOutline,
		CheckboxBlankOutline,
		CheckboxOutline,
	},
	props: {
		completed: {
			type: Boolean,
			required: true,
		},
		cancelled: {
			type: Boolean,
			required: true,
		},
		readOnly: {
			type: Boolean,
			required: true,
		},
		priorityClass: {
			type: String,
			default: '',
		},
	},
	emits: ['toggle-completed'],
	computed: {
		ariaLabel() {
			if (this.cancelled && !this.completed) {
				return t('tasks', 'Task is cancelled')
			} else if (this.completed) {
				return t('tasks', 'Task is completed')
			} else if (this.readOnly) {
				return t('tasks', 'Task is read-only')
			}
			return t('tasks', 'Task is not completed')
		},
		/**
		 * The unique id of the checkbox.
		 */
		checkboxId() {
			return 'checkbox-' + Math.random()
				.toString(36)
				.replace(/[^a-z]+/g, '')
				.slice(0, 6)
		},
	},
	methods: {
		t,

		toggleCompleted() {
			this.$emit('toggle-completed')
		},
	},
}
</script>

<style lang="scss" scoped>
$red_overdue: #b3312d; // overdue dates and high importance
$yellow: #fd0; // medium importance
$blue_due: #4271a6; // due dates and low importance

.task-checkbox {
	display: flex;
	height: 44px;
	width: 44px;
	justify-content: center;
	flex-shrink: 0;

	input[type='checkbox'] {
		position: absolute;
		left: -100000px;
		overflow: hidden;

		&:disabled + label,
		&:disabled + label .material-design-icon {
			cursor: default;
		}

		+ label {
			display: flex;
			align-items: center;
			height: 44px;
			width: 44px;
			padding: 11px;

			.material-design-icon {
				cursor: pointer;
				height: 22px;
				width: 22px;
			}

			&:hover {
				border-color: var(--color-border-dark);
			}

			&.priority {
				&--high {
					color: $red_overdue;
				}

				&--medium {
					color: $yellow;
				}

				&--low {
					color: $blue_due;
				}
			}
		}
	}
}
</style>