Parameters
Optional placeholder text displayed when the field is empty.
The current text value of the field (will be masked).
Function called when the text changes.
A secure text input field for password entry.
SecureField(props: { placeholder?: string; text: string; setText: (text: string) => void }): Component;
const [password, setPassword] = useState("")
SecureField({
placeholder: "Enter password",
text: password,
setText: setPassword
})
const [username, setUsername] = useState("")
const [password, setPassword] = useState("")
VStack({ spacing: 16 }, [
TextField({
placeholder: "Username",
text: username,
setText: setUsername
}),
SecureField({
placeholder: "Password",
text: password,
setText: setPassword
}),
Button("Login", () => {
console.log("Logging in with:", username)
})
.disabled(username === "" || password === "")
])
const [password, setPassword] = useState("")
const [confirmPassword, setConfirmPassword] = useState("")
const passwordsMatch = password === confirmPassword && password !== ""
VStack({ spacing: 12 }, [
SecureField({
placeholder: "New Password",
text: password,
setText: setPassword
}),
SecureField({
placeholder: "Confirm Password",
text: confirmPassword,
setText: setConfirmPassword
})
.border(confirmPassword !== "" && !passwordsMatch ? Color("red") : Color("gray")),
if (confirmPassword !== "" && !passwordsMatch) {
Text("Passwords do not match")
.foregroundStyle(Color("red"))
.font("caption")
},
Button("Create Account", () => {})
.disabled(!passwordsMatch)
])