1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. const isError = computed(() => (props.error ? true : false))
  39. const forLabel = computed(() => props.label.toLowerCase().replace(/\s+/g, '-'))
  40. const ariaDescribedbyLabel = computed(
  41. () => props.label.toLowerCase().replace(/\s+/g, '-') + '-error'
  42. )
  43. </script>
  44. <template>
  45. <div class="field">
  46. <label :for="forLabel">{{ label }}</label>
  47. <Password
  48. class="w-full"
  49. input-class="w-full"
  50. :promptLabel="promptLabel"
  51. :weakLabel="weakLabel"
  52. :mediumLabel="mediumLabel"
  53. :strongLabel="strongLabel"
  54. :disabled="disabled"
  55. :id="forLabel"
  56. :placeholder="placeholder"
  57. :toggleMask="true"
  58. :model-value="modelValue"
  59. @input="$emit('update:modelValue', $event.target.value)"
  60. />
  61. <small
  62. v-if="error"
  63. :id="ariaDescribedbyLabel"
  64. :class="{ 'p-error': isError }"
  65. >
  66. {{ error }}
  67. </small>
  68. </div>
  69. </template>