npm install svelte-password-component --save
import { Grid } from 'svelte-grid-component'
<Grid bind:password bind:validated bind:validate {showValidations} {showIcon} {showHideToggle} {placeholder} {suggestPassword} on:passwordCheck={handlePasswordEvent}/>
{placeholder}
Optional, Placeholder String in the password input field{showValidations}
Optional, Boolean to display build in validation checkers{showIcon}
Optional, Boolean to display the icon on the left of the input field{showHideToggle}
Optional, Boolean to display the toggle icon on the right of the input field in order to display the password as text inside the input field{suggestPassword}
Optional, Boolean to suggest a password that will pass the validationsbind:password
Optional, String to bind to the passwordbind:validated
Optional, Boolean to bind to to check if all validations have passedbind:validate
Optional, Object specifying what to validate against, defaulting to{
length: { min: 12 }, // A total of 12 character in length
uppercase: { min: 1 }, // At least 1 Uppercase letter
lowercase: { min: 1 }, // At lease 1 Lowercase letter
numbers: { min: 1 }, // At lease 1 Number
special: { min: 1 } // At least 1 Special character (@#$%~`!^&*()_+\-=\[\]{};':"\\|,.<>\/?)
}
on:passwordCheck={handlePasswordEvent}
Optional, Dispatch handler from the component that returns an Object containing the following {
password: "", // The typed password value as string
validate: {}, // The individual validations
validated: boolean // If the password string fulfill all validations
}
+page.svelte
<script>
import { Password } from "svelte-password-component";
let password = "";
let placeholder = "Password";
let validated = false;
let validate = {
length: { min: 12 },
uppercase: { min: 4 },
lowercase: { min: 2 },
numbers: { min: 3 },
special: { min: 1 }
}
let showValidations = true;
let showIcon = true;
let showHideToggle = true;
let suggestPassword = true;
function handlePasswordEvent(e) {
console.log(e.detail);
/*
returns
{
password: "",
validate: {},
validated: boolean
}
*/
}
</script>
<Password bind:password bind:validated bind:validate {showValidations} {showIcon} {showHideToggle} {placeholder} {suggestPassword} on:passwordCheck={handlePasswordEvent}/>
<p>Password: {password}</p>
<p>Validated: {validated}</p>
<p>Validate: {JSON.stringify(validate,null,2)}</p>
Can be set with variables associated with every element
--passwordFormBorder
--passwordFormPadding
--passwordInputBorder
--passwordInputFocusOutline
--passwordInputFocusWithinOutline
--passwordButtonBorder
--passwordButtonBackground
--passwordButtonColor
--passwordButtonCursor
--passwordInputTextBackgroundImage
--paswordInputPasswordBackgroundImage
--passwordIconPaddingLeft
--passwordIconMarginLeft
--passwordIconbackground
--passwordIconBackgroundSize
--passwordEyeMarginRight
--passwordEyeHeight
--passwordEyeWidth
--passwordEyeDisplay
--passwordEyeFloat
--passwordEyeRight
--passwordEyeTop
--passwordEyeBackgroundSize
--passwordEyeBackgroundRepeat
--passwordEyeHoverCursor
--passwordGoodPaddingLeft
--passwordGoodColor
--passwordGoodBorderColor
--passwordGoodBackgroundImage
--passwordGoodBackgroundRepeat
--passwordBadPaddingLeft
--passwordBadBackgroundImage
--passwordBadBackgroundRepeat
Please send me feedback or recommendations for improvements at mariusrossouwcr@gmail.com. I would love to here from you. Donations are welcome but not necessary.