You've already forked AstralRinth
forked from didirus/AstralRinth
Create component (#34)
This commit is contained in:
@@ -39,6 +39,7 @@ export default {
|
|||||||
{ text: 'Toggle', link: '/components/toggle' },
|
{ text: 'Toggle', link: '/components/toggle' },
|
||||||
{ text: 'Promotion', link: '/components/promotion' },
|
{ text: 'Promotion', link: '/components/promotion' },
|
||||||
{ text: 'Markdown', link: '/components/markdown' },
|
{ text: 'Markdown', link: '/components/markdown' },
|
||||||
|
{ text: 'Copy Code', link: '/components/copy-code' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
13
docs/components/copy-code.md
Normal file
13
docs/components/copy-code.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Copy Code
|
||||||
|
|
||||||
|
<DemoContainer>
|
||||||
|
<CopyCode
|
||||||
|
text="urmom"
|
||||||
|
/>
|
||||||
|
</DemoContainer>
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<CopyCode
|
||||||
|
text="urmom"
|
||||||
|
/>
|
||||||
|
```
|
||||||
64
lib/components/base/CopyCode.vue
Normal file
64
lib/components/base/CopyCode.vue
Normal 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>
|
||||||
@@ -18,6 +18,7 @@ export { default as DropdownSelect } from './base/DropdownSelect.vue'
|
|||||||
export { default as FileInput } from './base/FileInput.vue'
|
export { default as FileInput } from './base/FileInput.vue'
|
||||||
export { default as DropArea } from './base/DropArea.vue'
|
export { default as DropArea } from './base/DropArea.vue'
|
||||||
export { default as Toggle } from './base/Toggle.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 Categories } from './search/Categories.vue'
|
||||||
export { default as SearchFilter } from './search/SearchFilter.vue'
|
export { default as SearchFilter } from './search/SearchFilter.vue'
|
||||||
|
|||||||
Reference in New Issue
Block a user