Skip to content

Refactor FwbCheckbox – Improved Styling & Group Support #368

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 17, 2025

This PR refactors the FwbCheckbox component to enhance styling flexibility and enable usage within checkbox groups.

image

image

Summary by CodeRabbit

  • New Features

    • Introduced grouped checkbox examples for handling multiple selections.
    • Added examples with helper text and embedded links in checkbox labels.
    • Enhanced checkbox component with new props for custom classes, names, and values.
    • Added support for a helper message slot and flexible model binding.
  • Documentation

    • Expanded and reorganized Checkbox component documentation with new examples and an API section.
    • Updated examples to demonstrate new features and usage patterns.
  • Style

    • Improved default styling and layout for checkbox elements and examples.

@Sqrcz Sqrcz added the 🔧 enhancement New feature or request label Apr 17, 2025
@Sqrcz Sqrcz self-assigned this Apr 17, 2025
Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

Walkthrough

The changes focus on enhancing the documentation and example usage for the Vue Checkbox component in Flowbite. The documentation was reorganized with new and renamed sections, including expanded examples for checked, disabled, grouped, helper text, and link-embedded checkboxes. The Checkbox component itself was refactored to introduce additional props for class and value customization, improved slot support, and a new approach to model binding using defineModel. The composable for class merging was also updated to support the new prop structure and styling flexibility. No changes were made to exported or public entities outside the documentation and component/internal API.

Changes

File(s) Change Summary
docs/components/checkbox.md Expanded and reorganized documentation: renamed sections, added checked/disabled/group/helper/link examples, introduced a Checkbox group section, and added a component API section. Imports updated for new examples.
docs/components/checkbox/examples/FwbCheckboxExample.vue Updated to include a second checkbox for checked state; uses flex layout and new reactive variable checked.
docs/components/checkbox/examples/FwbCheckboxExampleDisabled.vue Enhanced to show both disabled unchecked and checked checkboxes; added new reactive variable checked.
docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue New example component demonstrating grouped checkboxes for fruits and planets, with array/object binding and display of selected values.
docs/components/checkbox/examples/FwbCheckboxExampleHelper.vue New example component showing a checkbox with helper text using a named slot.
docs/components/checkbox/examples/FwbCheckboxExampleLink.vue Modified to split label and link in the checkbox label; added styling classes to the link.
src/components/FwbCheckbox/FwbCheckbox.vue Refactored template and script: added/updated props (class, labelClass, name, value, wrapperClass), switched to defineModel for binding, improved slot and helper text support, and updated class merging logic.
src/components/FwbCheckbox/composables/useCheckboxClasses.ts Refactored composable to accept reactive props, return four computed class refs, use new useMergeClasses utility, and update default class logic and structure.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FwbCheckboxExampleGroup.vue
    participant FwbCheckbox.vue

    User->>FwbCheckboxExampleGroup.vue: Interacts with checkbox group (fruits/planets)
    FwbCheckboxExampleGroup.vue->>FwbCheckbox.vue: Passes v-model, label, value for each checkbox
    FwbCheckbox.vue-->>FwbCheckboxExampleGroup.vue: Emits updated values via defineModel binding
    FwbCheckboxExampleGroup.vue-->>User: Displays selected values in real-time
Loading
sequenceDiagram
    participant User
    participant FwbCheckboxExampleHelper.vue
    participant FwbCheckbox.vue

    User->>FwbCheckboxExampleHelper.vue: Toggles checkbox
    FwbCheckboxExampleHelper.vue->>FwbCheckbox.vue: Updates v-model
    FwbCheckbox.vue-->>User: Renders checkbox with label and helper text slot
Loading

Suggested labels

📚 documentation

Poem

In the garden of checkboxes, docs now bloom anew,
With helpers and groups, and examples in view.
Checked, unchecked, and disabled in line,
Even planets and fruits in a checkbox design!
With slots for your helpers and classes to style,
This bunny’s quite proud—hop along, stay awhile!
🐇✅🌱

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.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ec762e and f363cfb.

📒 Files selected for processing (2)
  • docs/components/checkbox.md (2 hunks)
  • docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/components/checkbox.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


151-151: Tables should be surrounded by blank lines
null

(MD058, blanks-around-tables)

🔇 Additional comments (13)
docs/components/checkbox.md (13)

4-5: Approve new example component imports
The additions of FwbCheckboxExampleGroup and FwbCheckboxExampleHelper imports align with the new example sections. Paths and ordering look correct.


11-11: Approve section title update
Renaming "Default checkbox" to "## Checkbox example" accurately reflects the expanded examples shown below.


17-17: Approve checked-state example
Adding the second <fwb-checkbox v-model="checked" label="Checked state" /> demonstrates the new checked‐by‐default prop out of the box.


25-25: Approve initialization of checked ref
Defining const checked = ref(true) correctly powers the checked‐state example above.


29-29: Approve section title update
Renaming the disabled section to "## Disabled state" is consistent with the other renames and example components.


47-47: Approve link‐embedded checkbox example inclusion
Introducing <fwb-checkbox-example-link /> here matches the new "Checkbox with link" demo component.


50-55: Approve link example code snippet
The FwbA slot inside <fwb-checkbox> clearly demonstrates embedding links in the label—good usage of the new slot API.


60-60: Approve import of FwbA and FwbCheckbox
Bringing in both FwbA and FwbCheckbox in the link example script is correct for the markup above.


62-62: Approve check ref declaration
Re‑using const check = ref(false) within this example maintains consistency with other snippets.


66-66: Approve helper‐text section title
The new "## Checkbox with helper text" header accurately introduces the helper slot demo.


71-75: Approve helper‐text example snippet
Using <template #helper> correctly showcases the new helper slot beneath the label.


80-80: Approve helper example import
Importing only FwbCheckbox in this snippet is sufficient and clean.


87-144: Approve checkbox‐group examples
The new "Checkbox group" section demonstrates both array and object binding via v-model, and the corrected v-for syntax ((item, idx) in ...) matches Vue best practices.


🪧 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 17, 2025

Deploy Preview for sensational-seahorse-8635f8 ready!

Name Link
🔨 Latest commit f363cfb
🔍 Latest deploy log https://app.netlify.com/sites/sensational-seahorse-8635f8/deploys/6800ea7611f6e500089ef2b6
😎 Deploy Preview https://deploy-preview-368--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: 1

🧹 Nitpick comments (6)
docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue (1)

43-43: Consider using numeric values for numeric IDs

The selectedPlanets ref is initialized with string values (['3']), but your planets object uses numeric keys. For consistency and to avoid potential type comparison issues, consider using numeric values in the array.

-const selectedPlanets = ref(['3'])
+const selectedPlanets = ref([3])
src/components/FwbCheckbox/composables/useCheckboxClasses.ts (2)

35-37: Consider allowing custom helper message classes

The helper message class is computed but doesn't incorporate any custom classes from props. Consider adding a helperClass prop to allow customization of the helper message styling.

export type UseCheckboxClassesProps = {
  class: Ref<string | Record<string, boolean>>
  disabled: Ref<boolean>
  labelClass: Ref<string | Record<string, boolean>>
+ helperClass: Ref<string | Record<string, boolean>>
  wrapperClass: Ref<string | Record<string, boolean>>
}

// Then in the function:
const helperMessageClass = computed(() => useMergeClasses([
  defaultHelperClasses,
+ props.helperClass.value,
]))

39-41: Consider adding default wrapper classes

The wrapper class computation doesn't include any default classes. If there are standard styles that should always be applied to the wrapper, consider adding default wrapper classes.

+const defaultWrapperClasses = 'mb-2'

const wrapperClass = computed(() => useMergeClasses([
+  defaultWrapperClasses,
  props.wrapperClass.value,
]))
docs/components/checkbox.md (2)

31-43: Consider adding a checked disabled state example

The disabled example only shows an unchecked disabled checkbox. It would be helpful to also show a checked disabled state to demonstrate both states.

<template>
  <fwb-checkbox v-model="check" disabled label="Disabled checkbox" />
+ <fwb-checkbox v-model="checkedDisabled" disabled label="Checked disabled checkbox" />
</template>

<script setup>
import { ref } from 'vue'
import { FwbCheckbox } from 'flowbite-vue'

const check = ref(false)
+const checkedDisabled = ref(true)
</script>

151-155: Fix markdown table formatting

There should be blank lines before and after the table according to markdown guidelines.

## Checkbox component API

+
| Name         | Type             | Default | Description                     |
| ------------ | ---------------- | ------- | ------------------------------- |
| wrapperClass | String \| Object | `''`    | Added to main component wrapper |
| labelClass   | String \| Object | `''`    | Added to `<label>` element.     |
| class        | String \| Object | `''`    | Added to `<input>` element.     |
+
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

151-151: Tables should be surrounded by blank lines
null

(MD058, blanks-around-tables)

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

10-11: Maintain consistent HTML formatting

For consistency with other elements in the template, consider keeping the closing bracket on the same line.

-        type="checkbox"
-      >
+        type="checkbox">
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ec2bbd3 and 5fb6429.

📒 Files selected for processing (8)
  • docs/components/checkbox.md (2 hunks)
  • docs/components/checkbox/examples/FwbCheckboxExample.vue (2 hunks)
  • docs/components/checkbox/examples/FwbCheckboxExampleDisabled.vue (2 hunks)
  • docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue (1 hunks)
  • docs/components/checkbox/examples/FwbCheckboxExampleHelper.vue (1 hunks)
  • docs/components/checkbox/examples/FwbCheckboxExampleLink.vue (1 hunks)
  • src/components/FwbCheckbox/FwbCheckbox.vue (1 hunks)
  • src/components/FwbCheckbox/composables/useCheckboxClasses.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/components/FwbCheckbox/composables/useCheckboxClasses.ts (1)
src/composables/useMergeClasses.ts (1)
  • useMergeClasses (27-29)
🪛 markdownlint-cli2 (0.17.2)
docs/components/checkbox.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


151-151: Tables should be surrounded by blank lines
null

(MD058, blanks-around-tables)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: docs-build (20.x)
🔇 Additional comments (11)
docs/components/checkbox/examples/FwbCheckboxExampleLink.vue (1)

2-12: Link integration looks good, wrapper improves VitePress rendering

The implementation of a checkbox with an embedded link is well structured. The "vp-raw" wrapper div helps prevent VitePress styling conflicts, and the text is appropriately split with only the "terms and conditions" part inside the link component.

docs/components/checkbox/examples/FwbCheckboxExampleDisabled.vue (2)

2-13: Good enhancement with both disabled states

The example now demonstrates both unchecked and checked disabled states, which provides a more comprehensive demonstration. The flex column layout with spacing improves visual clarity between the examples.


22-22: Correctly implemented reactive variable for checked state

Adding a second ref variable initialized to true properly supports the new checked-disabled checkbox example.

docs/components/checkbox/examples/FwbCheckboxExample.vue (2)

2-10: Enhanced example with both checkbox states

Good improvement showing both unchecked and checked states in the basic example. The flex column layout with gap spacing provides clear visual separation between the checkboxes.


20-20: Correctly implemented reactive variable for checked state

Adding a second ref variable initialized to true properly supports the new checked checkbox example.

docs/components/checkbox/examples/FwbCheckboxExampleHelper.vue (1)

1-20: Well-implemented helper text example using named slots

This new example effectively demonstrates how to add contextual information to a checkbox using the named helper slot. The implementation follows Vue best practices and provides a clear illustration of the feature.

docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue (1)

1-54: Good implementation of checkbox groups!

This example clearly demonstrates how to use the checkbox component in groups with both array and object data sources. The display of selected values provides helpful visual feedback.

src/components/FwbCheckbox/composables/useCheckboxClasses.ts (1)

1-49: Good refactoring of class composition

The refactored composable correctly handles reactive classes and disabled state. The usage of useMergeClasses for combining default and custom classes is a good approach. The type definitions are comprehensive and will provide good developer experience.

docs/components/checkbox.md (1)

4-147: Comprehensive documentation update

The expanded documentation provides excellent examples covering all the new features: checkbox groups, helper text, links, and the updated component API. The examples are clear and demonstrate the component's flexibility.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)

src/components/FwbCheckbox/FwbCheckbox.vue (2)

56-58: Great use of Vue 3's defineModel API

Using defineModel is a significant improvement over manual emit handling. It simplifies the component code and offers better type safety.


1-66: Excellent refactoring with improved structure and flexibility

The refactored component has significantly improved:

  1. Better DOM structure with a wrapper div
  2. Enhanced styling flexibility with multiple class props
  3. Support for checkbox groups with value props
  4. Helper text slot for additional context
  5. Simplified model binding with defineModel

These changes align perfectly with the PR objectives of improving styling flexibility and enabling group usage.

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/checkbox.md (1)

27-27: Improve Markdown formatting for code fences and tables

  • Ensure all fenced code blocks declare a language (e.g., use ```vue) to satisfy MD040.
  • Surround the props table with blank lines before and after to satisfy MD058 and improve readability.

Also applies to: 64-64, 151-151

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

27-27: 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 5fb6429 and d16185c.

📒 Files selected for processing (1)
  • docs/components/checkbox.md (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/components/checkbox.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


151-151: Tables should be surrounded by blank lines
null

(MD058, blanks-around-tables)

🔇 Additional comments (9)
docs/components/checkbox.md (9)

4-5: Imports for new group and helper examples are well-organized
The FwbCheckboxExampleGroup and FwbCheckboxExampleHelper components have been correctly imported, following the existing ordering.


11-11: Section header renamed to "Checkbox example"
The updated heading accurately reflects the example content.


17-17: Checked state example is now consistent
The second checkbox uses the checked ref initialized to true, matching the "Checked state" label.

Also applies to: 25-25


29-29: Updated section header to "Disabled state"
This heading aligns with the "Disabled" context and maintains consistency with other sections.


47-55: "Checkbox with link" example demonstrates slot usage correctly
The snippet shows the default slot containing text and an embedded <fwb-a> link, and the necessary imports (FwbA, FwbCheckbox) and reactive check ref are in place.

Also applies to: 60-62


66-66: Added "Checkbox with helper text" section
This new section clearly introduces the helper text feature.


71-75: Helper text example implementation is correct
The #helper slot is used appropriately to display additional information, and the import of FwbCheckbox is present.

Also applies to: 80-80


87-91: Added "Checkbox group" section with description and example component
The header, explanatory text, and <fwb-checkbox-example-group /> align to introduce group support clearly.


94-119: Group usage example covers both arrays and objects correctly
The manual Vue snippet shows proper v-for, v-model, and reactive ref initialization for both fruits and planets.

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: 1

🔭 Outside diff range comments (1)
docs/components/checkbox.md (1)

149-156: ⚠️ Potential issue

Extend and format the props API table
The documentation summary mentions new props name and value, but they’re missing from the table below. Also, adding blank lines around the table improves markdown readability.

Proposed diff:

 ## Checkbox component API

 ### FwbCheckbox Props

+ 
| Name         | Type             | Default     | Description                                                     |
| ------------ | ---------------- | ----------- | --------------------------------------------------------------- |
| wrapperClass | String \| Object | `''`        | Added to main component wrapper                                 |
| labelClass   | String \| Object | `''`        | Added to `<label>` element                                      |
| class        | String \| Object | `''`        | Added to `<input>` element                                      |
+| name         | String           | `undefined` | Name attribute for the `<input>` element when part of a group   |
+| value        | any              | `undefined` | Value of the checkbox when part of a checkbox group             |
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

151-151: Tables should be surrounded by blank lines
null

(MD058, blanks-around-tables)

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

24-26: Clarify reactive variable names
Using both check and checked works functionally, but could be confusing. Consider more descriptive names (e.g., isChecked and isDefaultChecked) to make the intent of each ref clearer.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d16185c and 3ec762e.

📒 Files selected for processing (2)
  • docs/components/checkbox.md (2 hunks)
  • docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/components/checkbox/examples/FwbCheckboxExampleGroup.vue
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/components/checkbox.md

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

(MD040, fenced-code-language)


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

(MD040, fenced-code-language)


151-151: Tables should be surrounded by blank lines
null

(MD058, blanks-around-tables)

🔇 Additional comments (5)
docs/components/checkbox.md (5)

2-6: Approve new example imports
The additions of FwbCheckboxExampleGroup and FwbCheckboxExampleHelper properly align with the new examples shown later in the doc. Ensure that those example files exist under docs/components/checkbox/examples/.


11-18: Enhance the "Checkbox example" section
Renaming the header to "Checkbox example" and adding a second checkbox bound to checked accurately demonstrates both unchecked and checked states. This improves clarity for users.


29-32: Approve "Disabled state" renaming
Changing the section title from "Disabled checkbox" to "Disabled state" keeps the naming convention consistent across examples. The FwbCheckboxExampleDisabled component is correctly invoked.


45-55: Validate link slot example
The example embedding <fwb-a> within the checkbox label correctly illustrates the new link slot support. The import of FwbA alongside FwbCheckbox is present and the syntax is on point.


66-75: Approve helper slot usage
The helper text example clearly conveys how to use the helper slot for descriptive messaging. The imports and template structure correctly reflect the updated API.

@Sqrcz Sqrcz merged commit 00fb3df into themesberg:main Apr 17, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant