123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <script setup>
  2. import { computed } from 'vue'
  3. const props = defineProps({
  4. label: {
  5. type: String,
  6. required: true,
  7. },
  8. disabled: {
  9. type: Boolean,
  10. default: false,
  11. },
  12. placeholder: {
  13. type: String,
  14. required: true,
  15. },
  16. promptLabel: {
  17. type: String,
  18. default: 'Masukan kata sandi',
  19. },
  20. weakLabel: {
  21. type: String,
  22. default: 'Ah Lemah',
  23. },
  24. mediumLabel: {
  25. type: String,
  26. default: 'Lumayan',
  27. },
  28. strongLabel: {
  29. type: String,
  30. default: 'Wow Kuat',
  31. },
  32. error: {
  33. type: String,
  34. default: null,
  35. },
  36. modelValue: null,
  37. })
  38. defineEmits(['update:modelValue'])
  39. const isError = computed(() => (props.error ? true : false))
  40. const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
  41. const ariaDescribedbyLabel = computed(
  42. () => props.label.toLowerCase().replace(/\s+/g, '-') + '-help'
  43. )
  44. </script>
  45. <template>
  46. <div class="field">
  47. <label :for="forLabel">{{ label }}</label>
  48. <Password
  49. class="w-full"
  50. input-class="w-full"
  51. :promptLabel="promptLabel"
  52. :weakLabel="weakLabel"
  53. :mediumLabel="mediumLabel"
  54. :strongLabel="strongLabel"
  55. :disabled="disabled"
  56. :id="forLabel"
  57. :placeholder="placeholder"
  58. :aria-describedby="ariaDescribedbyLabel"
  59. :toggleMask="true"
  60. :value="modelValue"
  61. :model-value="modelValue"
  62. @input="$emit('update:modelValue', $event.target.value)"
  63. />
  64. <small
  65. v-if="error"
  66. :id="ariaDescribedbyLabel"
  67. :class="{ 'p-error': isError }"
  68. >
  69. {{ error }}
  70. </small>
  71. </div>
  72. </template>