Skip to content

Feature: Improved FwbInput component flexibility #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Sqrcz
Copy link
Collaborator

@Sqrcz Sqrcz commented Apr 9, 2025

This PR enables customizing the looks of input fields by adding new props to allow passing classes to proper elements:

image

It also fixes:

  • the default color of text inside input field in dark mode
  • cursor for disabled state

Summary by CodeRabbit

  • Documentation

    • Revised component guides with updated examples, including new sections on styling inputs and expanded API details.
    • Updated validation sections featuring revised labels (e.g., "Your name"), placeholders, and engaging success/error messages.
  • New Features

    • Enhanced input customization with dedicated props for wrapper, label, and input styling, enabling more precise visual control.
    • Improved validation feedback with distinct success and error states reflected in input styling and messages.

@Sqrcz Sqrcz added 🪲 bug Something isn't working 🔧 enhancement New feature or request labels Apr 9, 2025
@Sqrcz Sqrcz self-assigned this Apr 9, 2025
Copy link
Contributor

coderabbitai bot commented Apr 9, 2025

Walkthrough

This pull request updates and refines the input component’s implementation and its documentation. Documentation is revised with new import statements, updated v-model bindings, refreshed labels and placeholders, and additional sections for styling and API details. The component code has been refactored to change class binding names, update prop interfaces, and use new utility functions for merging classes. Additionally, the global types and merging functions have been enhanced for better flexibility in handling class inputs.

Changes

File(s) Change Summary
docs/components/input.md, docs/components/input/examples/FwbInputExampleStyling.vue, docs/components/input/examples/FwbInputExampleValidation.vue Updated documentation and examples: revised import statements, updated v-model bindings, labels, placeholders, and validation messages; removed the "Extra CSS classes" section; added new sections on Styling Inputs and Input component API.
src/components/FwbInput/FwbInput.vue, src/components/FwbInput/composables/useInputClasses.ts, src/components/FwbInput/types.ts Refactored the input component: updated class bindings (to wrapperClass, labelClass, inputClass), revised the InputProps interface with new properties, integrated computed styling logic, and restored the Success status in the validation map.
src/composables/useMergeClasses.ts, src/types/global.ts Enhanced utility functions and types: updated useMergeClasses to accept broader ClassInput types with a new normalizeClasses function; introduced global type definitions for class handling.

Sequence Diagram(s)

sequenceDiagram
    participant Component as FwbInput Component
    participant InputClasses as useInputClasses
    participant Merge as useMergeClasses

    Component->>InputClasses: Request computed class bindings
    InputClasses->>Merge: Merge default & custom classes
    Merge-->>InputClasses: Return merged class string
    InputClasses-->>Component: Provide wrapperClass, labelClass, inputClass, etc.
Loading

Possibly related PRs

Suggested labels

📚 documentation

Poem

I'm a bunny, hopping around in code,
Carrots and classes in harmony bestowed.
Inputs now styled with care so neat,
With clear new props all set to greet.
A joyful hop in every updated line,
Celebrating changes that truly shine!
🥕🐇

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Apr 9, 2025

Deploy Preview for sensational-seahorse-8635f8 ready!

Name Link
🔨 Latest commit 6286957
🔍 Latest deploy log https://app.netlify.com/sites/sensational-seahorse-8635f8/deploys/680037811d51260008731f53
😎 Deploy Preview https://deploy-preview-365--sensational-seahorse-8635f8.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (3)
src/components/FwbInput/FwbInput.vue (2)

38-39: Remove unnecessary empty class attribute

The empty string class attribute (class="") doesn't add any value and can be removed for cleaner code.

-      :class="helperMessageClass"
-      class=""
+      :class="helperMessageClass"

54-66: Update the interface documentation

Consider adding JSDoc comments to describe each property in the InputProps interface, especially the newly added ones. This would make the component API more self-documenting.

 interface InputProps {
+  /** Specifies the autocomplete attribute for the input element */
   autocomplete?: CommonAutoFill
+  /** Classes to be applied to the input wrapper element */
   class?: string | Record<string, boolean>
   disabled?: boolean
+  /** Classes to be applied to the input element */
   inputClass?: string | Record<string, boolean>
   label?: string
+  /** Classes to be applied to the label element */
   labelClass?: string | Record<string, boolean>
   modelValue?: string | number
   required?: boolean
   size?: InputSize
   type?: InputType
   validationStatus?: ValidationStatus
+  /** Classes to be applied to the outer wrapper element */
   wrapperClass?: string | Record<string, boolean>
 }
docs/components/input.md (1)

251-251: Add language specifier to code fence

The fenced code block is missing a language specifier, which violates markdown linting rules.

-<script setup>
+<script lang="ts" setup>
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

251-251: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cf7c5c and e17b522.

📒 Files selected for processing (8)
  • docs/components/input.md (3 hunks)
  • docs/components/input/examples/FwbInputExampleStyling.vue (1 hunks)
  • docs/components/input/examples/FwbInputExampleValidation.vue (2 hunks)
  • src/components/FwbInput/FwbInput.vue (3 hunks)
  • src/components/FwbInput/composables/useInputClasses.ts (1 hunks)
  • src/components/FwbInput/types.ts (1 hunks)
  • src/composables/useMergeClasses.ts (1 hunks)
  • src/types/global.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/composables/useMergeClasses.ts (1)
src/types/global.ts (1)
  • ClassInput (3-3)
src/components/FwbInput/composables/useInputClasses.ts (2)
src/components/FwbInput/types.ts (3)
  • InputSize (1-1)
  • ValidationStatus (13-13)
  • validationStatusMap (8-11)
src/composables/useMergeClasses.ts (1)
  • useMergeClasses (27-29)
🪛 markdownlint-cli2 (0.17.2)
docs/components/input.md

251-251: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (14)
src/types/global.ts (1)

1-5: Well-structured type definitions for class handling

The ClassInput and ClassRef type definitions are clean and provide excellent flexibility for handling CSS classes in Vue components. These types will allow components to accept classes in various formats (strings, objects, or arrays), making them more versatile.

src/components/FwbInput/types.ts (1)

8-11: Good addition of the Success validation state

Adding the Success state to the validation status map improves the component's feedback capabilities. This allows the input component to provide positive validation feedback, not just error states, which is a meaningful enhancement to the user experience.

src/composables/useMergeClasses.ts (3)

3-4: Clean import of new type definition

Good job importing the new ClassInput type from the global types file. This maintains proper type safety and code organization.


5-25: Well-implemented class normalization function

The normalizeClasses function is robust and handles all possible input formats cleanly. The recursive approach for arrays is particularly well-designed, and the edge case handling is thorough.


27-29: Good update to useMergeClasses function

The updated function now accepts the more flexible ClassInput type and properly uses the new normalization function. This change aligns perfectly with the PR's goal of improving component flexibility.

docs/components/input/examples/FwbInputExampleValidation.vue (3)

3-13: Improved validation example with success state

The updates to this example effectively demonstrate the new success validation state. The more engaging validation message ("Well done!") and clearer placeholder text make the example more user-friendly and instructive.


15-25: Consistent styling between validation states

Good job maintaining consistency between the success and error examples. The parallel structure helps users understand how to implement both validation states in their own code.


34-34: Appropriate variable renaming

The ref variable name change from email to name properly reflects the updated purpose of the input field, maintaining code clarity.

src/components/FwbInput/FwbInput.vue (1)

87-88: Good use of defineModel

The switch from useVModel to Vue 3's defineModel is a good improvement. This makes the component more aligned with modern Vue 3 patterns.

src/components/FwbInput/composables/useInputClasses.ts (3)

13-14: Good implementation of cursor styling for disabled state

The addition of cursor-not-allowed for disabled inputs addresses one of the issues mentioned in the PR objectives. This improves the UX by providing clear visual feedback that the input is not interactive.


69-77: Improved input class handling

The enhanced implementation for inputClass is well structured, with proper consideration for validation states and disabled state. The order of class merging ensures that prop-provided classes take precedence over default classes, which is the expected behavior.


10-10: Dark mode text color fix

The updated defaultInputClasses correctly includes the dark mode text color (dark:text-white), addressing one of the issues mentioned in the PR objectives about text visibility in dark mode.

docs/components/input.md (2)

226-251: Excellent documentation for the new styling features

The new "Styling Inputs" section clearly explains how to use the new class properties with a concise example. This significantly improves the component's documentation and will help users understand how to customize the component's appearance.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

251-251: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


256-262: Well-structured API documentation

The added API documentation for the new class-related properties is clear and helps users understand the purpose of each property. The table format makes it easy to scan and reference.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/components/input.md (1)

213-214: Typo in error message slot content.

The validation message displays “Oh, snapp!”—consider removing the extra “p” to read “Oh, snap!” for clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e17b522 and 6286957.

📒 Files selected for processing (5)
  • docs/components/input.md (3 hunks)
  • docs/components/input/examples/FwbInputExampleDisabled.vue (1 hunks)
  • docs/components/input/examples/FwbInputExampleHelper.vue (1 hunks)
  • docs/components/input/examples/FwbInputExampleStyling.vue (1 hunks)
  • src/components/FwbInput/FwbInput.vue (3 hunks)
✅ Files skipped from review due to trivial changes (3)
  • docs/components/input/examples/FwbInputExampleHelper.vue
  • docs/components/input/examples/FwbInputExampleDisabled.vue
  • docs/components/input/examples/FwbInputExampleStyling.vue
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/FwbInput/FwbInput.vue
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/components/input.md

251-251: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (8)
docs/components/input.md (8)

7-9: Import new styling and size example components.

The imports for FwbInputExampleSize, FwbInputExampleStyling, and FwbInputExampleSuffix have been added to demonstrate the new styling props and size variations. The ordering remains alphabetical and consistent with the other examples.


194-196: Consistent v-model, label, and placeholder updates.

The validation slot example now correctly uses name for the v-model, updates the label to “Your name,” and adjusts the placeholder to “Success input,” aligning with the updated example component.


199-203: Validation slot markup is clear and correct.

The closing > for <fwb-input> and the <template #validationMessage> block are properly formatted and indented. The styled <span class="font-medium"> highlights the message as intended.


206-208: Error input example consistency.

The second <fwb-input> example mirrors the success case, using the same name ref, updated placeholder “Error input,” and validation-status="error". All attributes are consistent.


222-222: Ref declaration aligns with examples.

The const name = ref('') line is correctly placed and matches the v-model in all examples.


226-229: New “Styling Inputs” section introduction.

The heading and description clearly introduce the feature for passing classes via dedicated props. This addition enhances the docs.


231-243: Styling example demonstrates new props effectively.

The <fwb-input> example covers class, input-class, label-class, and wrapper-class props with realistic Tailwind utilities. All props are shown in context, and the component import matches.


249-249: Variable setup in styling example is correct.

The const name = ref('') declaration aligns with the usage in the styling example template.

@Sqrcz Sqrcz merged commit ec2bbd3 into themesberg:main Apr 16, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working 🔧 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant