-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ (#2345): make Callout as a component
Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
- Loading branch information
Vinicius Reis
committed
May 26, 2022
1 parent
11bd79a
commit 46ad510
Showing
4 changed files
with
132 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<!-- | ||
- @copyright Copyright (c) 2022 Vinicius Reis <vinicius@nextcloud.com> | ||
- | ||
- @author Vinicius Reis <vinicius@nextcloud.com> | ||
- | ||
- @license GNU AGPL version 3 or any later version | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program 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 program. If not, see <http://www.gnu.org/licenses/>. | ||
- | ||
--> | ||
<template> | ||
<NodeViewWrapper data-text-el="callout" | ||
class="callout" | ||
:class="`callout--${type}`" | ||
as="div"> | ||
<component :is="icon" class="callout__icon" /> | ||
<NodeViewContent class="callout__content" /> | ||
</NodeViewWrapper> | ||
</template> | ||
|
||
<script> | ||
import { NodeViewWrapper, NodeViewContent } from '@tiptap/vue-2' | ||
import { Positive, Warn, Danger, Info } from '../components/icons.js' | ||
|
||
const ICONS_MAP = { | ||
info: Info, | ||
success: Positive, | ||
error: Danger, | ||
warn: Warn, | ||
} | ||
|
||
export default { | ||
// eslint-disable-next-line vue/match-component-file-name | ||
name: 'Callout', | ||
components: { | ||
NodeViewWrapper, | ||
NodeViewContent, | ||
}, | ||
props: { | ||
node: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
icon() { | ||
return ICONS_MAP[this.type] || Info | ||
}, | ||
type() { | ||
return this.node?.attrs?.type || 'info' | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.callout { | ||
background-color: var(--callout-background, var(--color-background-hover)); | ||
border-left-color: var(--callout-border, var(--color-primary-element)); | ||
border-radius: var(--border-radius); | ||
padding: 1em; | ||
padding-left: 0.5em; | ||
border-left-width: 0.3em; | ||
border-left-style: solid; | ||
position: relative; | ||
margin-bottom: 0.5em; | ||
|
||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
|
||
+ & { | ||
margin-top: 0.5em; | ||
} | ||
|
||
.callout__content { | ||
margin-left: 1em; | ||
&::v-deep p { | ||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
|
||
.callout__icon { | ||
&, ::v-deep svg { | ||
color: var(--callout-border); | ||
} | ||
} | ||
|
||
// Info (default) variables | ||
&, &--info { | ||
--callout-border: var(--color-primary-element); | ||
} | ||
|
||
// Warn variables | ||
&--warn { | ||
--callout-border: var(--color-warning); | ||
} | ||
|
||
// Error variables | ||
&--error { | ||
--callout-border: var(--color-error); | ||
} | ||
|
||
// Success variables | ||
&--success { | ||
--callout-border: var(--color-success); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters