Files

119 lines
2.9 KiB
Vue
Raw Permalink Normal View History

2023-06-04 16:59:38 +02:00
<script setup lang="ts">
import { computed } from 'vue';
import { toPascalCase } from '@lucide/shared';
import ButtonMenu from '../base/ButtonMenu.vue';
2023-06-04 16:59:38 +02:00
import { useIconStyleContext } from '../../composables/useIconStyle';
import useConfetti from '../../composables/useConfetti';
const props = defineProps<{
name: string;
popoverPosition?: 'top' | 'bottom';
}>();
const { size, color, strokeWidth, absoluteStrokeWidth } = useIconStyleContext();
const { animate, confetti } = useConfetti();
2023-06-04 16:59:38 +02:00
const componentName = computed(() => {
return (toPascalCase(props.name) as string).replace(/\s/g, '');
});
2023-06-04 16:59:38 +02:00
function copyJSX() {
let attrs = [''];
2023-06-04 16:59:38 +02:00
if (size.value && size.value !== 24) {
attrs.push(`size={${size.value}}`);
2023-06-04 16:59:38 +02:00
}
if (color.value && color.value !== 'currentColor') {
attrs.push(`color="${color.value}"`);
2023-06-04 16:59:38 +02:00
}
if (strokeWidth.value && strokeWidth.value !== 2) {
attrs.push(`strokeWidth={${strokeWidth.value}}`);
2023-06-04 16:59:38 +02:00
}
if (absoluteStrokeWidth.value) {
attrs.push(`absoluteStrokeWidth`);
2023-06-04 16:59:38 +02:00
}
const code = `<${componentName.value}${attrs.join(' ')} />`;
2023-06-04 16:59:38 +02:00
navigator.clipboard.writeText(code);
2023-06-04 16:59:38 +02:00
}
2024-06-06 05:22:19 +08:00
function copyComponentName() {
const code = componentName.value;
2024-06-06 05:22:19 +08:00
navigator.clipboard.writeText(code);
2024-06-06 05:22:19 +08:00
}
2023-06-04 16:59:38 +02:00
function copyVue() {
let attrs = [''];
2023-06-04 16:59:38 +02:00
if (size.value && size.value !== 24) {
attrs.push(`:size="${size.value}"`);
2023-06-04 16:59:38 +02:00
}
if (color.value && color.value !== 'currentColor') {
attrs.push(`color="${color.value}"`);
2023-06-04 16:59:38 +02:00
}
if (strokeWidth.value && strokeWidth.value !== 2) {
attrs.push(`:stroke-width="${strokeWidth.value}"`);
2023-06-04 16:59:38 +02:00
}
if (absoluteStrokeWidth.value) {
attrs.push(`absoluteStrokeWidth`);
2023-06-04 16:59:38 +02:00
}
const code = `<${componentName.value}${attrs.join(' ')} />`;
2023-06-04 16:59:38 +02:00
navigator.clipboard.writeText(code);
2023-06-04 16:59:38 +02:00
}
function copyAngular() {
let attrs = [''];
2023-06-04 16:59:38 +02:00
attrs.push(`name="${props.name}"`);
2023-06-04 16:59:38 +02:00
if (size.value && size.value !== 24) {
attrs.push(`[size]="${size.value}"`);
2023-06-04 16:59:38 +02:00
}
if (color.value && color.value !== 'currentColor') {
attrs.push(`color="${color.value}"`);
2023-06-04 16:59:38 +02:00
}
if (strokeWidth.value && strokeWidth.value !== 2) {
attrs.push(`[strokeWidth]="${strokeWidth.value}"`);
2023-06-04 16:59:38 +02:00
}
if (absoluteStrokeWidth.value) {
attrs.push(`[absoluteStrokeWidth]="true"`);
2023-06-04 16:59:38 +02:00
}
const code = `<lucide-icon${attrs.join(' ')}></lucide-icon>`;
2023-06-04 16:59:38 +02:00
navigator.clipboard.writeText(code);
2023-06-04 16:59:38 +02:00
}
</script>
<template>
<ButtonMenu
:buttonClass="`confetti-button ${animate ? 'animate' : ''}`"
id="copy-code-button"
callOptionOnClick
@click="confetti"
@optionClick="confetti"
data-confetti-text="Copied!"
:popoverPosition="popoverPosition"
:options="[
{ text: 'Copy JSX', onClick: copyJSX },
{ text: 'Copy Component Name', onClick: copyComponentName },
{ text: 'Copy Vue', onClick: copyVue },
{ text: 'Copy Svelte', onClick: copyJSX },
{ text: 'Copy Angular', onClick: copyAngular },
2023-06-04 16:59:38 +02:00
]"
/>
</template>
<style src="./confetti.css" />