-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathNcNoteCard.vue
More file actions
204 lines (174 loc) Ā· 4.76 KB
/
NcNoteCard.vue
File metadata and controls
204 lines (174 loc) Ā· 4.76 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!--
- SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<docs>
This component is made to display additional information to the user. It is
available in four versions:
- **success**: Display a successful message.<br>
Should be used to show success of an operation or optional information to help a user be more successful.
- **info**: Display an informational message.<br>
Should be used to highlight information that users should take into account.
- **warning**: Display a warning to the user.<br>
Should be used for critical content demanding user attention due to potential risks.
- **error**: Display an error message.<br>
Should be used for negative potential consequences of an action.
### Usage
```vue
<template>
<div>
<NcNoteCard type="warning" text="This is dangerous" />
<NcNoteCard type="error"
heading="Error"
text="The server is not happy and reported the following error" />
<NcNoteCard type="success" text="You won" />
<NcNoteCard type="info" text="For your information" />
<h4>Custom icon</h4>
<NcNoteCard type="warning" text="Custom icon usage">
<template #icon>
<IconCogOutline :size="20"/>
</template>
</NcNoteCard>
<h4>Custom content using the default slot</h4>
<NcNoteCard type="info">
Press <kbd>CTRL</kbd>+<kbd>C</kbd>
</NcNoteCard>
</div>
</template>
<script>
import IconCogOutline from 'vue-material-design-icons/CogOutline.vue'
export default {
components: {
IconCogOutline,
},
}
</script>
```
</docs>
<script setup lang="ts">
import type { Slot } from 'vue'
import { mdiAlert, mdiAlertDecagram, mdiCheckboxMarkedCircle, mdiInformation } from '@mdi/js'
import { computed } from 'vue'
import { isLegacy } from '../../utils/legacy.ts'
import NcIconSvgWrapper from '../NcIconSvgWrapper/index.ts'
const props = withDefaults(defineProps<{
/**
* Optional text to show as a heading of the note card
*/
heading?: string
/**
* Enforce the `alert` role on the note card.
*
* The alert role should only be used for information that requires the user's immediate attention.
*
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/alert_role
*/
showAlert?: boolean
/**
* The message text of the note card
*/
text?: string
/**
* Type or severity of the message
*/
type?: 'success' | 'info' | 'warning' | 'error'
}>(), {
heading: undefined,
text: undefined,
type: 'warning',
})
defineSlots<{
/** The main content (overwrites the `text` prop) */
default?: Slot
/** Manually provided icon */
icon?: Slot
}>()
const shouldShowAlert = computed(() => props.showAlert || props.type === 'error')
const iconPath = computed(() => {
switch (props.type) {
case 'error':
return mdiAlertDecagram
case 'success':
return mdiCheckboxMarkedCircle
case 'info':
return mdiInformation
case 'warning':
default:
return mdiAlert
}
})
</script>
<template>
<div
class="notecard"
:class="{
[`notecard--${type}`]: type,
'notecard--legacy': isLegacy,
}"
:role="shouldShowAlert ? 'alert' : 'note'">
<slot name="icon">
<NcIconSvgWrapper
:path="iconPath"
class="notecard__icon"
:class="{ 'notecard__icon--heading': heading }"
inline />
</slot>
<div>
<p v-if="heading" class="notecard__heading">
{{ heading }}
</p>
<slot>
<p class="notecard__text">
{{ text }}
</p>
</slot>
</div>
</div>
</template>
<style lang="scss" scoped>
.notecard {
--note-card-icon-size: 20px;
--note-card-padding: calc(2 * var(--default-grid-baseline));
color: var(--color-main-text) !important;
background-color: var(--note-background) !important;
border-inline-start: var(--default-grid-baseline) solid var(--note-theme);
border-radius: var(--border-radius-small);
margin: 1rem 0;
padding: var(--note-card-padding);
display: flex;
flex-direction: row;
gap: var(--note-card-padding);
&__heading {
font-size: var(--note-card-icon-size); // Same as icon
font-weight: var(--font-weight-heading, 600);
}
&__icon {
color: var(--note-theme);
&--heading {
font-size: var(--note-card-icon-size);
// Ensure icon is on the same height as the heading
margin-block: calc((1lh - 1em) / 2) auto;
}
}
&--success {
--note-background: var(--color-success);
--note-theme: var(--color-success-text);
}
&--info {
--note-background: var(--color-info);
--note-theme: var(--color-info-text);
}
&--error {
--note-background: var(--color-error);
--note-theme: var(--color-error-text);
}
&--warning {
--note-background: var(--color-warning);
--note-theme: var(--color-warning-text);
}
&--legacy {
background-color: color-mix(in srgb, var(--note-background), var(--color-main-background) 80%) !important;
color: var(--color-main-text) !important;
}
}
</style>