2022-04-04 23:33:39 +02:00
|
|
|
<template>
|
2022-04-15 23:10:47 +02:00
|
|
|
<div>
|
|
|
|
<n-card title="Arabic to roman">
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-space align="center" justify="space-between">
|
2023-04-08 19:33:33 +02:00
|
|
|
<n-form-item v-bind="validationNumeral">
|
|
|
|
<n-input-number v-model:value="inputNumeral" :min="1" style="width: 200px" :show-button="false" />
|
|
|
|
</n-form-item>
|
2022-04-15 23:10:47 +02:00
|
|
|
<div class="result">
|
|
|
|
{{ outputRoman }}
|
|
|
|
</div>
|
2023-04-08 19:33:33 +02:00
|
|
|
<n-button secondary autofocus :disabled="validationNumeral.validationStatus === 'error'" @click="copyRoman">
|
|
|
|
Copy
|
|
|
|
</n-button>
|
2022-04-15 23:10:47 +02:00
|
|
|
</n-space>
|
|
|
|
</n-card>
|
2022-04-22 23:31:40 +02:00
|
|
|
<br />
|
2022-04-15 23:10:47 +02:00
|
|
|
<n-card title="Roman to arabic">
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-space align="center" justify="space-between">
|
2023-04-08 19:33:33 +02:00
|
|
|
<n-form-item v-bind="validationRoman">
|
|
|
|
<n-input v-model:value="inputRoman" style="width: 200px" />
|
|
|
|
</n-form-item>
|
2022-04-15 23:10:47 +02:00
|
|
|
<div class="result">
|
|
|
|
{{ outputNumeral }}
|
|
|
|
</div>
|
2023-04-08 19:33:33 +02:00
|
|
|
<n-button secondary autofocus :disabled="validationRoman.validationStatus === 'error'" @click="copyArabic">
|
|
|
|
Copy
|
|
|
|
</n-button>
|
2022-04-15 23:10:47 +02:00
|
|
|
</n-space>
|
|
|
|
</n-card>
|
|
|
|
</div>
|
2022-04-04 23:33:39 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { useCopy } from '@/composable/copy';
|
2022-04-22 23:31:40 +02:00
|
|
|
import { ref, computed } from 'vue';
|
2023-04-08 19:33:33 +02:00
|
|
|
import { useValidation } from '@/composable/validation';
|
|
|
|
import {
|
|
|
|
arabicToRoman,
|
|
|
|
romanToArabic,
|
|
|
|
MAX_ARABIC_TO_ROMAN,
|
|
|
|
MIN_ARABIC_TO_ROMAN,
|
|
|
|
isValidRomanNumber,
|
|
|
|
} from './roman-numeral-converter.service';
|
2022-04-04 23:33:39 +02:00
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const inputNumeral = ref(42);
|
|
|
|
const outputRoman = computed(() => arabicToRoman(inputNumeral.value));
|
2022-04-04 23:33:39 +02:00
|
|
|
|
2023-04-08 19:33:33 +02:00
|
|
|
const { attrs: validationNumeral } = useValidation({
|
|
|
|
source: inputNumeral,
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
validator: (value) => value >= MIN_ARABIC_TO_ROMAN && value <= MAX_ARABIC_TO_ROMAN,
|
|
|
|
message: `We can only convert numbers between ${MIN_ARABIC_TO_ROMAN.toLocaleString()} and ${MAX_ARABIC_TO_ROMAN.toLocaleString()}`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2023-03-24 18:35:37 +01:00
|
|
|
const inputRoman = ref('XLII');
|
2022-04-22 23:31:40 +02:00
|
|
|
const outputNumeral = computed(() => romanToArabic(inputRoman.value));
|
2022-04-04 23:33:39 +02:00
|
|
|
|
2023-04-08 19:33:33 +02:00
|
|
|
const { attrs: validationRoman } = useValidation({
|
|
|
|
source: inputRoman,
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
validator: (value) => isValidRomanNumber(value),
|
|
|
|
message: `The input you entered is not a valid roman number`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const { copy: copyRoman } = useCopy({ source: outputRoman, text: 'Roman number copied to the clipboard' });
|
|
|
|
const { copy: copyArabic } = useCopy({ source: outputNumeral, text: 'Arabic number copied to the clipboard' });
|
2022-04-04 23:33:39 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
.result {
|
2022-04-22 23:31:40 +02:00
|
|
|
font-size: 22px;
|
2022-04-04 23:33:39 +02:00
|
|
|
}
|
2022-04-22 23:31:40 +02:00
|
|
|
</style>
|