-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ent' into oxdcomponent
- Loading branch information
Showing
9 changed files
with
769 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,142 @@ | ||
<template> | ||
<oxd-input type="password" /> | ||
<div :class="strengthClass"> | ||
<oxd-text class="password-strength-check" v-if="showStrength"> | ||
{{ strengthLabel }} | ||
</oxd-text> | ||
<oxd-input | ||
v-bind="$attrs" | ||
class="password-input" | ||
:hasError="hasError" | ||
:disabled="disabled" | ||
:readonly="readonly" | ||
:type="isPasswordVisible ? 'text' : 'password'" | ||
></oxd-input> | ||
<div | ||
:class="[ | ||
'password-view-icon-container', | ||
{'password-visible': isPasswordVisible}, | ||
]" | ||
@click="togglePasswordVisibility" | ||
> | ||
<oxd-icon-button | ||
class="oxd-password-view-icon" | ||
:name="isPasswordVisible ? 'eye-slash-fill' : 'eye-fill'" | ||
:iconStyles="isPasswordVisible ? {color: 'white'} : {}" | ||
:tooltip="isPasswordVisible ? 'Hide Password' : 'Show Password'" | ||
size="large" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent} from 'vue'; | ||
import {defineComponent, ref, computed} from 'vue'; | ||
import Input from '@orangehrm/oxd/core/components/Input/Input.vue'; | ||
import oxdText from '@orangehrm/oxd/core/components/Text/Text.vue'; | ||
import IconButton from '@orangehrm/oxd/core/components/Button/Icon.vue'; | ||
import useTranslate from '@orangehrm/oxd/composables/useTranslate'; | ||
export default defineComponent({ | ||
name: 'oxd-password-input', | ||
components: { | ||
'oxd-input': Input, | ||
'oxd-text': oxdText, | ||
'oxd-icon-button': IconButton, | ||
}, | ||
props: { | ||
strength: { | ||
type: Number, | ||
default: -1, | ||
validator: (value: number) => [-1, 0, 1, 2, 3, 4, 5].includes(value), | ||
}, | ||
hasError: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
readonly: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
hasMinimumPasswordStrength: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
}, | ||
setup(props) { | ||
// Reactive reference for password visibility | ||
const isPasswordVisible = ref(false); | ||
const {$t} = useTranslate(); | ||
// Computed properties for strengthClass, strengthLabel, and showStrength | ||
const strengthClass = computed(() => { | ||
const strengthClasses = [ | ||
'very-weak-strength', | ||
'weak-strength', | ||
'better-strength', | ||
'medium-strength', | ||
'strong-strength', | ||
'strongest-strength', | ||
]; | ||
if (!props.hasMinimumPasswordStrength) { | ||
return 'password-container below-minimum-strength'; | ||
} | ||
if ( | ||
props.strength === -1 || | ||
props.hasError || | ||
props.disabled || | ||
props.readonly | ||
) { | ||
return 'password-container'; | ||
} | ||
return `password-container ${strengthClasses[props.strength]}`; | ||
}); | ||
const strengthLabel = computed(() => { | ||
const strengthLabels = [ | ||
'Very Weak', | ||
'Weak', | ||
'Better', | ||
'Medium', | ||
'Strong', | ||
'Strongest', | ||
]; | ||
return $t(strengthLabels[props.strength]); | ||
}); | ||
const showStrength = computed(() => { | ||
if (!props.hasMinimumPasswordStrength && props.strength !== -1) { | ||
return true; | ||
} | ||
return ( | ||
props.strength !== -1 && | ||
!props.hasError && | ||
!props.disabled && | ||
!props.readonly | ||
); | ||
}); | ||
// Method to toggle password visibility | ||
const togglePasswordVisibility = () => { | ||
isPasswordVisible.value = !isPasswordVisible.value; | ||
}; | ||
return { | ||
isPasswordVisible, | ||
strengthClass, | ||
strengthLabel, | ||
showStrength, | ||
togglePasswordVisibility, | ||
}; | ||
}, | ||
}); | ||
</script> | ||
<style src="./password-input.scss" lang="scss" scoped></style> |
57 changes: 51 additions & 6 deletions
57
components/src/core/components/Input/__tests__/__snapshots__/password-input.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,67 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PasswordInput.vue renders OXD Input 1`] = ` | ||
<div class="input-outer-wrapper"> | ||
<div class="password-container" label="Input"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active" type="password" label="Input"> | ||
<div class="input-outer-wrapper"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active password-input" label="Input" type="password"> | ||
</div> | ||
<div class="password-view-icon-container"><button type="button" class="oxd-icon-button oxd-password-view-icon" tooltip="Show Password" flow="top"><i class="oxd-icon oxd-icon--large bi-eye-fill"></i></button></div> | ||
</div> | ||
`; | ||
exports[`PasswordInput.vue should renders OXD Input with custom color 1`] = ` | ||
<div class="input-outer-wrapper"> | ||
<div class="password-container" label="Input" style="background-color: aliceblue;"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active" style="background-color: aliceblue;" type="password" label="Input"> | ||
<div class="input-outer-wrapper"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active password-input" style="background-color: aliceblue;" label="Input" type="password"> | ||
</div> | ||
<div class="password-view-icon-container"><button type="button" class="oxd-icon-button oxd-password-view-icon" tooltip="Show Password" flow="top"><i class="oxd-icon oxd-icon--large bi-eye-fill"></i></button></div> | ||
</div> | ||
`; | ||
exports[`PasswordInput.vue should renders OXD Input with custom placeholder 1`] = ` | ||
<div class="password-container" label="Input" placeholder="Custom placeholder"> | ||
<!--v-if--> | ||
<div class="input-outer-wrapper"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active password-input" label="Input" placeholder="Custom placeholder" type="password"> | ||
</div> | ||
<div class="password-view-icon-container"><button type="button" class="oxd-icon-button oxd-password-view-icon" tooltip="Show Password" flow="top"><i class="oxd-icon oxd-icon--large bi-eye-fill"></i></button></div> | ||
</div> | ||
`; | ||
exports[`PasswordInput.vue should renders OXD Input with error 1`] = ` | ||
<div class="input-outer-wrapper"> | ||
<div class="password-container" label="Input"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active oxd-input--error" type="password" label="Input"> | ||
<div class="input-outer-wrapper"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active oxd-input--error password-input" label="Input" type="password"> | ||
</div> | ||
<div class="password-view-icon-container"><button type="button" class="oxd-icon-button oxd-password-view-icon" tooltip="Show Password" flow="top"><i class="oxd-icon oxd-icon--large bi-eye-fill"></i></button></div> | ||
</div> | ||
`; | ||
exports[`PasswordInput.vue should renders OXD Input with error message 1`] = ` | ||
<div class="password-container" label="Input" errormessage="Error message"> | ||
<!--v-if--> | ||
<div class="input-outer-wrapper"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active oxd-input--error password-input" label="Input" errormessage="Error message" type="password"> | ||
</div> | ||
<div class="password-view-icon-container"><button type="button" class="oxd-icon-button oxd-password-view-icon" tooltip="Show Password" flow="top"><i class="oxd-icon oxd-icon--large bi-eye-fill"></i></button></div> | ||
</div> | ||
`; | ||
exports[`PasswordInput.vue should renders OXD Input with strength meter 1`] = ` | ||
<div class="password-container weak-strength" label="Input"> | ||
<p class="oxd-text oxd-text--p password-strength-check">Weak</p> | ||
<div class="input-outer-wrapper"> | ||
<!--v-if--> | ||
<!--v-if--><input class="oxd-input oxd-input--active password-input" label="Input" type="password"> | ||
</div> | ||
<div class="password-view-icon-container"><button type="button" class="oxd-icon-button oxd-password-view-icon" tooltip="Show Password" flow="top"><i class="oxd-icon oxd-icon--large bi-eye-fill"></i></button></div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.