Add classes
Function: Add classes
This action allows you to dynamically add one or more visual styles (CSS classes) to specific user interface (UI) elements in your application. This is useful for changing the appearance of elements based on certain conditions, such as highlighting a field when it's invalid, showing or hiding content, or applying different themes.
Input
- Elements: A list of UI elements you want to modify. For each element in the list, you can specify:
- Element: The specific UI element you want to target.
- Conditional: (Optional) A True/False condition. If this condition is set and evaluates to
True
, or if it's not set at all, the classes will be added to the element. If the condition isFalse
, the classes will not be added to that specific element.
- Classes: A list of text values, where each text value represents a CSS class name you want to add to the selected elements.
Output
This action does not produce any direct output. Instead, it modifies the visual appearance of the specified UI elements within your application.
Execution Flow
Real-Life Examples
Example 1: Highlight an invalid input field
Imagine you have a form where a user needs to enter their email address. If the email format is incorrect, you want to highlight the input field in red.
- Inputs:
- Elements:
- Element 1:
- Element:
Email Input Field
(e.g., a text input component named "EmailAddressInput") - Conditional:
Is EmailAddressInput.isValid = False
(This condition checks if the email input field's value is not valid)
- Element:
- Element 1:
- Classes:
invalid-field
(Assuming you have a CSS class namedinvalid-field
that applies a red border)
- Elements:
- Result: If the user types an invalid email address, the
Email Input Field
will immediately have theinvalid-field
style applied, making its border turn red.
Example 2: Show a "New" badge on recently added products
You have a product listing page, and you want to display a "New" badge next to products that were added in the last 24 hours.
- Inputs:
- Elements:
- Element 1:
- Element:
Product Card 1
(e.g., a container component for the first product) - Conditional:
Product1.DateAdded > CurrentDate - 24 hours
- Element:
- Element 2:
- Element:
Product Card 2
- Conditional:
Product2.DateAdded > CurrentDate - 24 hours
- Element:
- (...and so on for all product cards)
- Element 1:
- Classes:
badge-new
(A class that styles a "New" badge)
- Elements:
- Result: Only the product cards for products added within the last 24 hours will have the
badge-new
style applied, visually indicating they are new arrivals.
Example 3: Apply a dark theme to a section based on user preference
Your application allows users to switch between a light and dark theme. When a user selects the dark theme, you want to apply a dark-mode
class to the main content area.
- Inputs:
- Elements:
- Element 1:
- Element:
Main Content Area
(e.g., a container component named "AppContent") - Conditional:
CurrentUser.ThemePreference = "Dark"
- Element:
- Element 1:
- Classes:
dark-mode
(A class that defines dark background and light text colors)
- Elements:
- Result: If the current user's theme preference is set to "Dark", the
Main Content Area
will have thedark-mode
style applied, changing its appearance to the dark theme.