aboutsummaryrefslogtreecommitdiff
path: root/src/tools/slugify-string/slugify-string.vue
blob: 760302a912977a0d60cf1b2ce30aa61576d8c970 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<script setup lang="ts">
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>

<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)" />
    </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)"
      />
    </n-form-item>

    <div flex justify-center>
      <c-button :disabled="slug.length === 0" @click="copy">
        Copy slug
      </c-button>
    </div>
  </div>
</template>