<!-- Use the Custom Input Component in your HTML -->
<div form="input">
<input type="text" placeholder="Type something...">
</div>
form
Attribute: (input
)<!-- Use the Custom Input Component with Left Icon -->
<div form="input" class="my" left="icon">
<error>somting error</error>
<icon><!--<img src="/icons/credit.svg">--></icon>
<input>
</div>
<!-- Use the Custom Input Component with Left Text -->
<div form="input" class="my" left="text">
<text>Left Text</text>
<input>
</div>
Icon Container (<icon>
):
- Represents the container for the left-aligned icon.
- Use the <img>
<svg>
tag to include the icon image.
Text Container (<text>
):
- Represents the container for the left-aligned text.
- Specify the text content within the <text>
tag.
Error Container (<error>
):
- Represents the container for displaying error messages.
- Populate the <error>
tag with the relevant error message text.
Input Field (<input>
):
- Represents the actual input field.
To include a left-aligned icon, set the left
attribute to "icon"
.
Left Text:
left
attribute to "text"
.<!-- Example with Left Icon -->
<div form="input" class="my" left="icon">
<icon></icon>
<input>
</div>
<div form="input" class="my" left="text">
<text>Left Text</text>
<input>
</div>
The Multiple Input Custom Component allows you to create a container for managing multiple input fields, such as those commonly found in credit card forms. Here's how you can use the component:
<!-- Use the Multiple Input Component with Left Icon -->
<div form="input" multiple class="my" left="icon">
<icon><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 2C6.4889971 2 2 6.4889971 2 12C2 17.511003 6.4889971 22 12 22C17.511003 22 22 17.511003 22 12C22 6.4889971 17.511003 2 12 2 z M 12 4C16.430123 4 20 7.5698774 20 12C20 16.430123 16.430123 20 12 20C7.5698774 20 4 16.430123 4 12C4 7.5698774 7.5698774 4 12 4 z M 11 7L11 9L13 9L13 7L11 7 z M 11 11L11 17L13 17L13 11L11 11 z" />
</svg></icon>
<input placeholder="Card Number">
<input placeholder="Expiry">
<input placeholder="CVV">
</div>
Icon Container (<icon>
):
- Represents the container for the left-aligned icon.
- Use the <img>
tag to include the icon image.
Error Container (<error>
):
- Represents the container for displaying error messages.
- Populate the <error>
tag with the relevant error message text.
Input Fields (<input>
):
- Represents the individual input fields.
- Include multiple <input>
tags for each input field.
- Set the placeholder
attribute for each input field to provide a placeholder text.
To include a left-aligned icon, set the left
attribute to "icon"
.
Multiple Inputs:
multiple
attribute to indicate that this component will contain multiple input fields.<!-- Example with Left Icon and Multiple Inputs -->
<div form="input" multiple class="my" left="icon">
<input placeholder="Card Number">
<input placeholder="Expiry">
<input placeholder="CVV">
</div>
Feel free to customize the appearance of the Multiple Input Custom Component by adding your preferred styles to the provided classes (my
, icon
, etc.) based on your project's design requirements.
left
Attribute:"text"
or "icon"
Description: Aligns content to the left side of the input. Use "text"
for left-aligned text and "icon"
for left-aligned icons.
checkmark
Attribute:
Description: Indicates that the input has passed validation, often visualized by a checkmark icon.
checking
Attribute:
Description: Indicates that the input is currently undergoing validation.
disabled
Attribute:
Description: Disables the input, preventing user interaction.
error
Attribute:
Description: Indicates that there is an error with the input, often visualized by an error message.
toggle
Attribute:
Description: Converts the input into a password field with a toggle option to show/hide the password.
multiple
Attribute:
Description: Indicates that the component will contain multiple input fields.
join
Attribute:
"/"
multiple
attribute is used.<!-- Example with Icon, Disabled, and Password Toggle -->
<div form="input" left="icon" disabled toggle>
<icon><img src="/icons/lock.svg"></icon>
<input placeholder="Password" type="password">
</div>
The pattern
, required
, min
, and maxlength
attributes provide additional control and validation for input fields.
pattern
Attribute: <input pattern="[a-zA-Z0-9]{3,10}" placeholder="Alphanumeric, 3 to 10 characters">
required
Attribute:"number"
"password"
"username"
"mail"
<input required="password" placeholder="Password">
min
Attribute: <input type="number" min="1" placeholder="Minimum value is 1">
maxlength
Attribute: <input maxlength="50" placeholder="Maximum length is 50 characters">
These attributes offer flexibility and control over the input field's content and validation rules. Use them as needed based on your specific requirements.
The $input function enhances the properties of input elements within a custom input component. It defines and sets up various attributes and methods for improved styling and functionality. Here's how you can use it:
<div form="input">
<!-- Input field goes here -->
<input placeholder="Type something...">
</div>
$input
var customInput = $input(document.querySelector('div[form="input"]'));
disabled
Property: customInput.disabled = true; // Disable the input
var isDisabled = customInput.disabled; // Get the disabled state
focus
Method: customInput.focus();
blur
Method: customInput.blur();
invalid
Method:bool
(Type: boolean
, Default: false
): Set to true
to indicate an invalid state.message
(Type: string
, Default: null
): Optional error message to display. customInput.invalid(true, "Invalid input");
isValid
Property:true
if valid, false
if invalid. var isValid = customInput.isValid;
checkmark
Property: customInput.checkmark = true; // Show the checkmark
var hasCheckmark = customInput.checkmark; // Check the checkmark state
check
Property: customInput.check = true; // Show the checking state
var isChecking = customInput.check; // Check the checking state
icon
Method:obj
(Type: string
or SVGElement
or HTMLImageElement
): The icon content. customInput.icon('<img src="/icons/left.svg">');
text
Method:leftText
(Type: string
): The text content. customInput.text("Left Text");
getIcon
Property: var iconElement = customInput.getIcon;
getText
Property: var leftTextContent = customInput.getText;
input
Property: var customInput = document.querySelector('div[form="input"]');
var inputElement = $input(customInput).input;
When the custom input component has the multiple
attribute, the property returns a NodeList of all input elements. Otherwise, it returns the single input element.
var customInput = document.querySelector('div[form="input"]');
var singleInputElement = $input(customInput).input;
var customInputMultiple = document.querySelector('div[form="input"][multiple]');
var multipleInputElements = $input(customInputMultiple).input;
The input field component provides a way for users to enter data. Below are the variables you can customize to match your desired theme:
Variable | Description |
---|---|
--font-size |
Size of the input field font. |
--border-style |
Style, width, and color of the input field border. |
--border-color |
Color of the input field border. |
--border-radius |
Border radius of the input field. |
--background-color |
Background color of the input field. |
--disabled-background |
Background color of the disabled input field. |
--disabled-opacity |
Opacity of the disabled input field. |
--color |
Text color of the input field. |
--error-color |
Color of the error text and border for invalid input. |
Variable | Description |
---|---|
--left-background |
Background color of the left text in the input field. |
--min-height |
Minimum height of the input field. |
/* General Input Fields */
div[form=input] input {
/* Add your customizations here */
}
div[form=input] input:disabled {
/* Add your customizations here */
}
div[form=input][error] input {
/* Add your customizations here */
}
/* Additional Features */
div[form=input] [form-input-left-text] {
/* Add your customizations here */
}
div[form=input][left="icon"] [form-input-left-icon] {
/* Add your customizations here */
}
div[form=input][toggle] [pass-icons] {
/* Add your customizations here */
}