1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
use yew::prelude::*;
/// HTML attribute: autocomplete
/// https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
///
#[derive(Clone, PartialEq)]
pub enum AutocompleteNameType {
/// The field expects the value to be a person's full name.
FullName,
/// The prefix or title, such as "Mrs.", "Mr.", "Miss", "Ms.", "Dr.", or "Mlle.".
HonorificPrefix,
/// The given (or "first") name.
GivenName,
/// The middle name.
AdditionalName,
/// The family (or "last") name.
FamilyName,
/// The suffix, such as "Jr.", "B.Sc.", "PhD.", "MBASW", or "IV".
HonorificSuffix,
/// A nickname or handle.
Nickname,
}
/// The street address to send the product.
/// This can be combined with other tokens,
/// such as "shipping street-address" and "shipping address-level2"
/// or "billing street-address" and "billing address-level2".
#[derive(Clone, PartialEq)]
pub enum AutocompleteAddressType {
StreetAddress,
AddressLevel2,
}
#[derive(Clone, PartialEq)]
pub enum AutocompletePasswordType {
/// A new password. When creating a new account or changing passwords,
/// this should be used for an "Enter your new password" or "Confirm new password" field,
/// as opposed to a general "Enter your current password" field that might be present.
NewPassword,
/// The user's current password.
CurrentPassword,
}
#[derive(Clone, PartialEq)]
pub enum AutocompleteTelType {
/// A full telephone number, including the country code.
Tel,
/// The country code, such as "1" for the United States, Canada, and
/// other areas in North America and parts of the Caribbean.
TelCountryCode,
/// The entire phone number without the country code component,
/// including a country-internal prefix. For the phone number "1-855-555-6502",
/// this field's value would be "855-555-6502".
TelNational,
/// The area code, with any country-internal prefix applied if appropriate.
TelAreaCode,
/// The phone number without the country or area code. This can be split further into two parts,
/// for phone numbers which have an exchange number and then a number within the exchange.
/// For the phone number "555-6502", use "tel-local-prefix" for "555" and "tel-local-suffix" for "6502".
TelLocal,
TelLocalPrefix,
TelLocalSuffix,
/// A telephone extension code within the phone number,
/// such as a room or suite number in a hotel or an office extension in a company.
TelExtension,
}
/// # Type of form autocomplete, to be used with [crate::component::form::FormControl].
#[derive(Clone, PartialEq)]
pub enum FormAutocompleteType {
/// The browser is not permitted to automatically enter or select a value for this field.
/// It is possible that the document or application provides its own autocomplete feature,
/// or that security concerns require that the field's value not be automatically entered.
Off,
/// The browser is allowed to automatically complete the input.
/// No guidance is provided as to the type of data expected in the field, so the browser may use its own judgement.
On,
Name { value: AutocompleteNameType },
/// An email address.
Email,
/// A username or account name.
Username,
Password { value: AutocompletePasswordType },
///A one-time password (OTP) for verifying user identity that is used as an additional factor in a sign-in flow.
/// Most commonly this is a code received via some out-of-channel mechanism, such as SMS, email, or authenticator application.
OTP,
/// A job title, or the title a person has within an organization, such as
/// "Senior Technical Writer", "President", or "Assistant Troop Leader".
OrganizationTitle,
/// A company or organization name, such as "Acme Widget Company" or "Girl Scouts of America".
Organization,
/// A street address. This can be multiple lines of text, and should fully identify the location of the address
/// within its second administrative level (typically a city or town), but should not include the city name,
/// ZIP or postal code, or country name.
StreetAddress,
ShippingAddress { value: AutocompleteAddressType },
BillingAddress { value: AutocompleteAddressType },
/// Each individual line of the street address. These should only be present if the "street-address" is not present.
AddressLine1,
AddressLine2,
AddressLine3,
/// The finest-grained administrative level, in addresses which have four levels.
AddressLevel4,
/// The third administrative level, in addresses with at least three administrative levels.
AddressLevel3,
/// The second administrative level, in addresses with at least two of them. In countries with two administrative levels,
/// this would typically be the city, town, village, or other locality in which the address is located.
AddressLevel2,
/// The first administrative level in the address. This is typically the province in which the address is located.
/// In the United States, this would be the state. In Switzerland, the canton. In the United Kingdom, the post town.
AddressLevel1,
/// A country or territory code.
Country,
/// A country or territory name.
CountryName,
/// A postal code (in the United States, this is the ZIP code).
PostalCode,
/// The full name as printed on or associated with a payment instrument such as a credit card.
/// Using a full name field is preferred, typically, over breaking the name into pieces.
CcName,
/// A given (first) name as given on a payment instrument like a credit card.
CcGivenName,
/// A middle name as given on a payment instrument or credit card.
CcAdditionalName,
/// A family name, as given on a credit card.
CcFamilyName,
/// A credit card number or other number identifying a payment method, such as an account number.
CcNumber,
/// A payment method expiration date, typically in the form "MM/YY" or "MM/YYYY".
CcExp,
/// The month in which the payment method expires.
CcExpMonth,
/// The year in which the payment method expires.
CcExpYear,
/// The security code for the payment instrument; on credit cards,
/// this is the 3-digit verification number on the back of the card.
CcCsc,
/// The type of payment instrument (such as "Visa" or "Master Card").
CcType,
/// The currency in which the transaction is to take place.
TransactionCurrency,
/// The amount, given in the currency specified by "transaction-currency", of the transaction, for a payment form.
TransactionAmount,
/// A preferred language, given as a valid BCP 47 language tag
Language,
/// A birth date, as a full date.
Bday,
/// The day of the month of a birth date.
BdayDay,
/// The month of the year of a birth date.
BdayMonth,
/// The year of a birth date.
BdayYear,
/// A gender identity (such as "Female", "Fa'afafine", "Hijra", "Male", "Nonbinary"), as freeform text without newlines.
Sex,
Tel { value: AutocompleteTelType },
/// A URL for an instant messaging protocol endpoint, such as "xmpp:username@example.net".
Impp,
/// A URL, such as a home page or company website address as appropriate given the context of the other fields in the form.
Url,
/// The URL of an image representing the person, company, or contact information given in the other fields in the form.
Photo,
/// Passkeys generated by the Web Authentication API, as requested by a conditional navigator.credentials.get() call (i.e., one that includes mediation: 'conditional').
Webauthn,
}
impl FormAutocompleteType {
/// Convert enum to HTML type string
pub fn to_str(&self) -> AttrValue {
let value = match &self {
Self::Off => "off",
Self::On => "on",
Self::Name { value } => {
match value {
AutocompleteNameType::FullName => "name",
AutocompleteNameType::HonorificPrefix => "honorific-prefix",
AutocompleteNameType::GivenName => "given-name",
AutocompleteNameType::AdditionalName => "additional-name",
AutocompleteNameType::FamilyName => "family-name",
AutocompleteNameType::HonorificSuffix => "honorific-suffix",
AutocompleteNameType::Nickname => "nickname"
}
}
Self::Email => "email",
Self::Username => "username",
Self::Password { value } => {
match value {
AutocompletePasswordType::NewPassword => "new-password",
AutocompletePasswordType::CurrentPassword => "current-password"
}
},
Self::OTP => "one-time-code",
Self::OrganizationTitle => "organization-title",
Self::Organization => "organization",
Self::StreetAddress => "street-address",
Self::ShippingAddress { value } => {
match value {
AutocompleteAddressType::StreetAddress => "shipping street-address",
AutocompleteAddressType::AddressLevel2 => "shipping address-level2"
}
}
Self::BillingAddress { value } => {
match value {
AutocompleteAddressType::StreetAddress => "billing street-address",
AutocompleteAddressType::AddressLevel2 => "billing address-level2"
}
}
Self::AddressLine1 => "address-line1",
Self::AddressLine2 => "address-line2",
Self::AddressLine3 => "address-line3",
Self::AddressLevel4 => "address-level4",
Self::AddressLevel3 => "address-level3",
Self::AddressLevel2 => "address-level2",
Self::AddressLevel1 => "address-level1",
Self::Country => "country",
Self::CountryName => "country-name",
Self::PostalCode => "postal-code",
Self::CcName => "cc-name",
Self::CcGivenName => "cc-given-name",
Self::CcAdditionalName => "cc-additional-name",
Self::CcFamilyName => "cc-family-name",
Self::CcNumber => "cc-number",
Self::CcExp => "cc-exp",
Self::CcExpMonth => "cc-exp-month",
Self::CcExpYear => "cc-exp-year",
Self::CcCsc => "cc-csc",
Self::CcType => "cc-type",
Self::TransactionCurrency => "transaction-currency",
Self::TransactionAmount => "transaction-amount",
Self::Language => "language",
Self::Bday => "bday",
Self::BdayDay => "bday-day",
Self::BdayMonth => "bday-month",
Self::BdayYear => "bday-year",
Self::Sex => "sex",
Self::Tel { value } => {
match value {
AutocompleteTelType::Tel => "tel",
AutocompleteTelType::TelCountryCode => "tel-country-code",
AutocompleteTelType::TelNational => "tel-national",
AutocompleteTelType::TelAreaCode => "tel-area-code",
AutocompleteTelType::TelLocal => "tel-local",
AutocompleteTelType::TelLocalPrefix => "tel-local-prefix",
AutocompleteTelType::TelLocalSuffix => "tel-local-suffix",
AutocompleteTelType::TelExtension => "tel-extension",
}
}
Self::Impp => "impp",
Self::Url => "url",
Self::Photo => "photo",
Self::Webauthn => "webauthn",
};
AttrValue::from(value)
}
}