1
0

Create component (#34)

This commit is contained in:
Adrian O.V
2023-04-02 01:53:29 -04:00
committed by GitHub
parent d238b0b9f2
commit 6bdea219bf
4 changed files with 79 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ export default {
{ text: 'Toggle', link: '/components/toggle' },
{ text: 'Promotion', link: '/components/promotion' },
{ text: 'Markdown', link: '/components/markdown' },
{ text: 'Copy Code', link: '/components/copy-code' },
],
},
],

View File

@@ -0,0 +1,13 @@
# Copy Code
<DemoContainer>
<CopyCode
text="urmom"
/>
</DemoContainer>
```vue
<CopyCode
text="urmom"
/>
```

View File

@@ -0,0 +1,64 @@
<template>
<button class="code" :class="{ copied }" title="Copy code to clipboard" @click="copyText">
{{ text }}
<CheckIcon v-if="copied" />
<ClipboardCopyIcon v-else />
</button>
</template>
<script setup>
import { CheckIcon, ClipboardCopyIcon } from '@/components'
</script>
<script>
export default {
props: {
text: {
type: String,
required: true,
},
},
data() {
return {
copied: false,
}
},
methods: {
async copyText() {
await navigator.clipboard.writeText(this.text)
this.copied = true
},
},
}
</script>
<style lang="scss" scoped>
.code {
display: flex;
grid-gap: 0.5rem;
font-family: var(--mono-font);
font-size: var(--font-size-sm);
margin: 0;
padding: 0.25rem 0.5rem;
background-color: var(--color-button-bg);
width: min-content;
border-radius: 10px;
user-select: text;
transition: opacity 0.5s ease-in-out, filter 0.2s ease-in-out, transform 0.05s ease-in-out,
outline 0.2s ease-in-out;
svg {
width: 1em;
height: 1em;
}
&:hover {
filter: brightness(0.85);
}
&:active {
transform: scale(0.95);
filter: brightness(0.8);
}
}
</style>

View File

@@ -18,6 +18,7 @@ export { default as DropdownSelect } from './base/DropdownSelect.vue'
export { default as FileInput } from './base/FileInput.vue'
export { default as DropArea } from './base/DropArea.vue'
export { default as Toggle } from './base/Toggle.vue'
export { default as CopyCode } from './base/CopyCode.vue'
export { default as Categories } from './search/Categories.vue'
export { default as SearchFilter } from './search/SearchFilter.vue'