Skip to content

Commit

Permalink
Merge pull request #17 from HenestrosaDev/dev
Browse files Browse the repository at this point in the history
Add button to toggle password visibility in `FloatingLabel`
  • Loading branch information
HenestrosaDev authored Jun 17, 2024
2 parents 580c37a + e425e76 commit 496d280
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
15 changes: 15 additions & 0 deletions public/images/icons/eye-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions public/images/icons/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 29 additions & 2 deletions resources/js/Components/Forms/FloatingLabel.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<script setup>
// https://preline.co/docs/input.html#floating-label
import { trans } from "laravel-vue-i18n";
import { ref } from "vue";
import IconEye from "@icons/eye.svg?component";
import IconEyeOff from "@icons/eye-off.svg?component";
const value = defineModel("value"); // eslint-disable-line
defineProps({
const props = defineProps({
inputId: {
type: String,
required: true,
Expand Down Expand Up @@ -63,6 +66,13 @@ defineProps({
default: null,
},
});
const mutableInputType = ref(props.inputType);
const togglePasswordVisibility = () => {
mutableInputType.value =
mutableInputType.value === "password" ? "text" : "password";
};
</script>

<template>
Expand All @@ -71,7 +81,7 @@ defineProps({
<input
:id="inputId"
v-model="value"
:type="inputType"
:type="mutableInputType"
:autocomplete="inputAutocomplete"
:inputmode="inputMode"
:placeholder="inputPlaceholder"
Expand All @@ -91,6 +101,23 @@ defineProps({
:aria-invalid="errorMessage ? true : false"
:aria-describedby="`${inputId}-annotation`"
/>

<button
v-if="inputType === 'password'"
type="button"
class="absolute end-0 top-0 mt-2 px-4 py-2"
@click="togglePasswordVisibility"
>
<IconEye
v-if="mutableInputType === 'password'"
class="h-6 w-6"
/>
<IconEyeOff
v-else-if="mutableInputType === 'text'"
class="h-6 w-6"
/>
</button>

<label
:for="inputId"
class="pointer-events-none absolute start-0 top-0 h-full truncate border border-transparent p-4 text-sm transition duration-100 ease-in-out peer-focus:-translate-y-1.5 peer-focus:text-xs peer-focus:text-skin-muted peer-disabled:pointer-events-none peer-disabled:opacity-50 peer-[:not(:placeholder-shown)]:-translate-y-1.5 peer-[:not(:placeholder-shown)]:text-xs peer-[:not(:placeholder-shown)]:text-skin-muted"
Expand Down

0 comments on commit 496d280

Please sign in to comment.