#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum ValidationBehavior {
#[default]
Native,
Aria,
}
impl ValidationBehavior {
pub fn as_str(self) -> &'static str {
match self {
Self::Native => "native",
Self::Aria => "aria",
}
}
pub fn is_native(self) -> bool {
self == Self::Native
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum EncType {
#[default]
UrlEncoded,
MultipartFormData,
TextPlain,
}
impl EncType {
pub fn as_str(self) -> &'static str {
match self {
Self::UrlEncoded => "application/x-www-form-urlencoded",
Self::MultipartFormData => "multipart/form-data",
Self::TextPlain => "text/plain",
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Method {
#[default]
Get,
Post,
Dialog,
}
impl Method {
pub fn as_str(self) -> &'static str {
match self {
Self::Get => "get",
Self::Post => "post",
Self::Dialog => "dialog",
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Target {
#[default]
Self_,
Blank,
Parent,
Top,
Custom(&'static str),
}
impl Target {
pub fn as_str(self) -> &'static str {
match self {
Self::Self_ => "_self",
Self::Blank => "_blank",
Self::Parent => "_parent",
Self::Top => "_top",
Self::Custom(s) => s,
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum FormStatus {
#[default]
Idle,
Submitting,
Submitted,
Error,
}
impl FormStatus {
pub fn is_submitting(self) -> bool {
self == Self::Submitting
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Variant {
#[default]
Outlined,
Filled,
Standard,
}
impl Variant {
pub fn to_class(self) -> &'static str {
match self {
Self::Outlined => "form-control--outlined",
Self::Filled => "form-control--filled",
Self::Standard => "form-control--standard",
}
}
pub fn to_field_style(self) -> &'static str {
match self {
Self::Outlined => {
"border: 1.5px solid #3f3f46; border-radius: 8px; background: transparent;"
}
Self::Filled => {
"border: none; border-bottom: 1.5px solid #3f3f46; border-radius: 8px 8px 0 0; background: rgba(255,255,255,0.05);"
}
Self::Standard => {
"border: none; border-bottom: 1.5px solid #3f3f46; border-radius: 0; background: transparent;"
}
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Color {
#[default]
Primary,
Secondary,
Error,
Info,
Success,
Warning,
Custom(&'static str),
}
impl Color {
pub fn to_hex(self) -> &'static str {
match self {
Self::Primary => "#7c3aed",
Self::Secondary => "#3b82f6",
Self::Error => "#dc2626",
Self::Info => "#06b6d4",
Self::Success => "#16a34a",
Self::Warning => "#d97706",
Self::Custom(s) => s,
}
}
pub fn to_focus_ring(self) -> String {
format!(
"border-color: {}; box-shadow: 0 0 0 3px {}40;",
self.to_hex(),
self.to_hex()
)
}
pub fn to_label_color(self) -> String {
format!("color: {};", self.to_hex())
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Size {
Small,
#[default]
Medium,
}
impl Size {
pub fn to_input_style(self) -> &'static str {
match self {
Self::Small => "padding: 6px 10px; font-size: 13px;",
Self::Medium => "padding: 10px 14px; font-size: 15px;",
}
}
pub fn to_class(self) -> &'static str {
match self {
Self::Small => "form-control--small",
Self::Medium => "form-control--medium",
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Margin {
#[default]
None,
Dense,
Normal,
}
impl Margin {
pub fn to_style(self) -> &'static str {
match self {
Self::None => "",
Self::Dense => "margin-top: 4px; margin-bottom: 4px;",
Self::Normal => "margin-top: 8px; margin-bottom: 4px;",
}
}
pub fn to_class(self) -> &'static str {
match self {
Self::None => "",
Self::Dense => "form-control--margin-dense",
Self::Normal => "form-control--margin-normal",
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum LabelPlacement {
#[default]
End,
Start,
Top,
Bottom,
}
impl LabelPlacement {
pub fn to_flex_direction(self) -> &'static str {
match self {
Self::End => "flex-direction: row; align-items: center;",
Self::Start => "flex-direction: row-reverse; align-items: center;",
Self::Top => "flex-direction: column-reverse; align-items: flex-start;",
Self::Bottom => "flex-direction: column; align-items: flex-start;",
}
}
pub fn to_class(self) -> &'static str {
match self {
Self::End => "form-control-label--end",
Self::Start => "form-control-label--start",
Self::Top => "form-control-label--top",
Self::Bottom => "form-control-label--bottom",
}
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub enum ValidationState {
#[default]
None,
Valid,
Invalid(String),
}
impl ValidationState {
pub fn is_invalid(&self) -> bool {
matches!(self, Self::Invalid(_))
}
pub fn error_message(&self) -> Option<&str> {
match self {
Self::Invalid(msg) => Some(msg.as_str()),
_ => None,
}
}
}
pub fn base_form_style() -> &'static str {
"display: flex; flex-direction: column; gap: 16px;"
}
pub fn base_form_control_style() -> &'static str {
"display: flex; flex-direction: column; gap: 4px; position: relative; width: 100%;"
}
pub fn base_label_style() -> &'static str {
"font-size: 13px; font-weight: 500; color: #a1a1aa; line-height: 1.4; \
transition: color 0.15s ease; letter-spacing: 0.01em;"
}
pub fn base_helper_text_style() -> &'static str {
"font-size: 11.5px; color: #71717a; margin: 0; line-height: 1.5; \
transition: color 0.15s ease;"
}
pub fn base_form_group_style() -> &'static str {
"display: flex; flex-direction: column; gap: 8px;"
}
pub fn base_form_group_row_style() -> &'static str {
"display: flex; flex-direction: row; flex-wrap: wrap; gap: 16px; align-items: center;"
}
pub fn base_input_field_style() -> &'static str {
"width: 100%; background: transparent; outline: none; \
font-family: 'Inter', ui-sans-serif, system-ui, sans-serif; \
transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease; \
box-sizing: border-box;"
}
pub fn field_error_style() -> &'static str {
"border-color: #dc2626 !important; box-shadow: 0 0 0 3px rgba(220,38,38,0.18);"
}
pub fn field_valid_style() -> &'static str {
"border-color: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,0.15);"
}
pub fn field_disabled_style() -> &'static str {
"opacity: 0.5; cursor: not-allowed; pointer-events: none;"
}
pub fn label_error_style() -> &'static str {
"color: #dc2626;"
}
pub fn label_valid_style() -> &'static str {
"color: #16a34a;"
}
pub fn helper_error_style() -> &'static str {
"color: #dc2626; font-weight: 500;"
}
pub fn helper_valid_style() -> &'static str {
"color: #16a34a;"
}
pub fn required_asterisk_style() -> &'static str {
"color: #dc2626; margin-inline-start: 2px;"
}