Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(button): show password toggle #4960

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions components/interactables/Input/Input.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
{{ label }}
</TypographyText>
<div class="input-outer" :class="`font-size-${size}`">
<div class="input-inner">
<div
class="input-inner"
:class="[
`is-${color}`,
{
'is-danger': error || invalid,
'has-sibling': $slots.default,
transparent: transparent,
},
]"
>
<input
ref="input"
class="input font-body font-color-light"
:class="[
`is-${color}`,
{
'show-clear-button': showClearButton,
'is-danger': error || invalid,
transparent,
jasonwoodland marked this conversation as resolved.
Show resolved Hide resolved
},
]"
:value="text"
:type="type"
:type="derivedType"
:readonly="readonly"
:placeholder="placeholder"
:minLength="minLength"
Expand All @@ -27,6 +29,10 @@
@input="handleInput"
/>
<div class="append input-options">
<button v-if="type === 'password'" @click="toggleShowPassword">
<eye-icon size="1x" v-if="!showPassword" />
<eye-off-icon size="1x" v-else />
</button>
<button v-if="showClearButton && !isEmpty" @click="clearInput">
<delete-icon size="1x" />
</button>
Expand Down
60 changes: 34 additions & 26 deletions components/interactables/Input/Input.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,50 @@
display: flex;
flex-grow: 1;
min-width: 0;
box-shadow: none;
background: @input-gradient 100% center;
border-radius: @corner-rounding;
border: 1px solid transparent;

.input {
flex-grow: 1;
padding: 0.5rem;
box-shadow: none;
background: @input-gradient 100% center;
border: none;
border-radius: @corner-rounding;
border: 1px solid transparent;
min-width: 0;
&:focus-within {
background-image: @semitransparent-lightest-gradient;
}

&.is-danger {
border-color: @red;
}
&.has-sibling {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

&.show-clear-button {
padding-right: 2rem;
}
&.transparent {
background: #fff0;
border: 0;

&.transparent {
.input {
padding: 0;
border: none;
}

&:focus-within {
background: #fff0;
flex-grow: 1;

&:focus {
.input {
outline: none;
background: #fff0;
}
}
}

&:focus {
background-image: @semitransparent-lightest-gradient;
.input {
flex-grow: 1;
padding: 0.5rem;
min-width: 0;
background: none;
border: 0;

&.is-danger {
border-color: @red;
}

::placeholder {
color: @body;
&::placeholder {
color: @dark;
}

&[type='search']::-webkit-search-cancel-button {
Expand All @@ -60,14 +67,15 @@
}

.append {
position: absolute;
inset: 0 0 0 auto;
font-size: @tiny-icon-size;
display: flex;
align-items: center;
justify-content: center;
padding: 0.5rem;
padding-right: 0.75rem;
padding-left: 0.25rem;
color: @text-muted;
gap: 0.75rem;

.slot {
display: flex;
Expand Down
15 changes: 14 additions & 1 deletion components/interactables/Input/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<script lang="ts">
import Vue, { PropType } from 'vue'
import { DeleteIcon } from 'satellite-lucide-icons'
import { DeleteIcon, EyeIcon, EyeOffIcon } from 'satellite-lucide-icons'
import { InputType, InputColor } from './types'
import { Size } from '~/types/typography'

Expand All @@ -11,6 +11,8 @@ const MOBILE_FOCUS_DELAY = 300 // ms
export default Vue.extend({
components: {
DeleteIcon,
EyeIcon,
EyeOffIcon,
},
model: {
prop: 'text',
Expand Down Expand Up @@ -90,13 +92,21 @@ export default Vue.extend({
default: false,
},
},
data() {
return {
showPassword: false,
}
},
computed: {
isEmpty(): boolean {
return !this.text.length
},
showClearButton(): boolean {
return this.showClear || this.type === 'search'
},
derivedType(): string {
return this.showPassword ? 'text' : this.type
},
},
mounted() {
if (this.autofocus) {
Expand Down Expand Up @@ -128,6 +138,9 @@ export default Vue.extend({
clearInput() {
this.$emit('change', '')
},
toggleShowPassword() {
this.showPassword = !this.showPassword
},
},
})
</script>
Expand Down