Input RS

Edit Component

Y Input RS Yew Usage

Adding Input RS to your project is simple:

  1. Make sure your project is set up with Yew. Follow their Getting Started Guide for setup instructions.

  2. Add the Input RS component to your dependencies by including it in your Cargo.toml file:

    cargo add input-rs --features=yew
    
  3. Import the Input component into your Yew component and start using it in your app.

🛠️ Usage

Incorporating Yew Input RS into your application is easy. Follow these steps:

  1. Import the Input component into your Yew project:

    use yew::prelude::*;
    use input_rs::yew::Input;
    use regex::Regex;
  2. Use the Input component within your Yew application:

    use yew::prelude::*;
    use regex::Regex;
    use input_rs::yew::Input;
    
    fn validate_email(email: String) -> bool {
        let pattern = Regex::new(r"^[^ ]+@[^ ]+\.[a-z]{2,3}$").unwrap();
        pattern.is_match(&email)
    }
    
    #[function_component(App)]
    pub fn app() -> Html {
        let input_email_ref = use_node_ref();
        let input_email_handle = use_state(String::default);
        let email_valid_handle = use_state(|| true);
    
        html! {
            <form>
                <Input
                    r#type="email"
                    name="email"
                    r#ref={input_email_ref}
                    handle={input_email_handle}
                    valid_handle={email_valid_handle}
                    validate_function={validate_email}
                    placeholder="Enter your email"
                    label="Email Address"
                    required={true}
                    error_message="Please provide a valid email address"
                    class="form-field"
                    label_class="form-label"
                    input_class="form-input"
                    error_class="error-text"
                />
            </form>
        }
    }

🔧 Props

Main Props

PropertyTypeDescriptionDefault
type&'static strInput type, e.g., "text", "email", "password", "textarea"."text"
name&'static strName attribute for the input element.""
label&'static strText label displayed above the input.""
placeholder&'static strPlaceholder text inside the input field.""
id&'static strID attribute for the input element.""
requiredboolIndicates whether the field is required.false
handleUseStateHandle<String>State handle for managing the value of the input.None
valid_handleUseStateHandle<bool>State handle for managing the validity of the input value.None
validate_functionCallback<String, bool>Validation function that checks the input value and returns a boolean.None
error_message&'static strMessage displayed when the input value is invalid.""

Styling Props

+-----------------------------+  <-- `class`
|                             |
|  +-----------------------+  |  <-- `label_class`
|  |       Label           |  |
|  +-----------------------+  |
|                             |
|  +-----------------------+  |  <-- `field_class`
|  | +-------+  +--------+ |  |
|  | | Input |  |  Icon  | |  |  <-- `input_class` and `icon_class`
|  | +-------+  +--------+ |  |
|  +-----------------------+  |
|                             |
|  +-----------------------+  |  <-- `error_class` (if invalid)
|  |       Error Message   |  |
|  +-----------------------+  |
+-----------------------------+
PropertyTypeDescriptionDefault
class&'static strCSS class applied to the wrapper container.""
label_class&'static strCSS class applied to the label element.""
input_class&'static strCSS class applied to the input element.""
field_class&'static strCSS class applied to the input wrapper element (includes icons, etc.).""
error_class&'static strCSS class applied to the error message container when validation fails.""
icon_class&'static strCSS class applied to the optional icon (if specified).""

Password Icon Props

PropertyTypeDescriptionDefault
eye_active&'static strIcon CSS class for showing the "visible" state in password fields."cursor-pointer right-4 top-1 text-2xl text-gray-600 toggle-button fa fa-eye"
eye_disabled&'static strIcon CSS class for showing the "hidden" state in password fields."cursor-pointer right-4 top-1 text-2xl text-gray-600 toggle-button fa fa-eye-slash"

Accessibility Props

PropertyTypeDescriptionDefault
aria_label&'static strAria-label for the input element for screen reader users.""
aria_required&'static strSpecifies whether the input is required for screen readers."true"
aria_invalid&'static strIndicates whether the input value is invalid for screen readers."false"
aria_describedby&'static strID of the element that describes the input (e.g., error message container).""

💡 Notes

  • The Input component can be used for various input types like text, password, etc.
  • You can bind the component to state hooks for two-way data binding.
  • Utilize validate_function to validate user input and display error messages.
  • The eye_active and eye_disabled props allow for password visibility toggling with FontAwesome icons.
  • Customize the appearance with CSS classes for better integration into your app's design.

Usage

CLI Usage

You can import Input RS directly into your project to customize and modify it using the opensass cli:

os add input-rs yew