it-tools/src/tools/slugify-string/slugify-string.vue

34 lines
974 B
Vue
Raw Normal View History

<script setup lang="ts">
import { computed, ref } from 'vue';
import slugify from '@sindresorhus/slugify';
import { withDefaultOnError } from '@/utils/defaults';
import { useCopy } from '@/composable/copy';
const input = ref('');
const slug = computed(() => withDefaultOnError(() => slugify(input.value), ''));
const { copy } = useCopy({ source: slug, text: 'Slug copied to clipboard' });
</script>
2023-02-10 22:06:32 +01:00
<template>
<div>
<n-form-item label="Your string to slugify">
<n-input v-model:value="input" type="textarea" placeholder="Put your string here (ex: My file path)" />
2023-02-10 22:06:32 +01:00
</n-form-item>
<n-form-item label="Your slug">
<n-input
:value="slug"
type="textarea"
readonly
placeholder="You slug will be generated here (ex: my-file-path)"
/>
2023-02-10 22:06:32 +01:00
</n-form-item>
2023-05-27 17:36:15 +02:00
<div flex justify-center>
<c-button :disabled="slug.length === 0" @click="copy">
Copy slug
</c-button>
2023-05-27 17:36:15 +02:00
</div>
2023-02-10 22:06:32 +01:00
</div>
</template>