Skip to content

classes: accordion #1616

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

classes: accordion #1616

wants to merge 1 commit into from

Conversation

jjagielka
Copy link
Contributor

@jjagielka jjagielka commented May 28, 2025

📑 Description

Accordion component modified to new style with classes.

  • generic ComponentVariants type added to types.ts.
  • Accrodion supplied with active and inactive props to be used in ctx

Should we merge it only in the new branch? next.2.xx ?

Warning

Note that won't work for components with base only. We can workaround that with making slots: { base: "..."} or think of separate solution for simple components. The latter would have an advantage of NOT having classes property.

Status

  • Not Completed
  • Completed

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • I have checked the page with https://validator.unl.edu/
  • All the tests have passed
  • My pull request is based on the latest commit (not the npm version).

ℹ Additional Information

Summary by CodeRabbit

  • New Features
    • Consolidated multiple class-related props into a single classes object for Accordion and AccordionItem components, allowing for more flexible and organized styling.
  • Refactor
    • Updated the public interface of Accordion and AccordionItem components to accept a classes prop instead of separate class props.
  • Documentation
    • Revised documentation to reflect the new classes prop usage and updated example code accordingly.

Copy link
Contributor

coderabbitai bot commented May 28, 2025

Walkthrough

The Accordion and AccordionItem components were refactored to consolidate multiple class-related props into a single classes prop object. Type definitions and theme variants were updated to support this change, and documentation was revised to illustrate the new API for styling active and inactive states.

Changes

File(s) Change Summary
src/lib/accordion/Accordion.svelte Replaced activeClass and inactiveClass props with a single classes prop; context now derives classes from classes.
src/lib/accordion/AccordionItem.svelte Removed separate class props; introduced a single classes prop; used clsx for class composition.
src/lib/accordion/theme.ts Refactored variant definitions to use slot-based structure; added AccordionVariants and AccordionItemVariants type aliases.
src/lib/types.ts Added generic ComponentVariants type; updated AccordionProps and AccordionItemProps to use new variant types and classes prop.
src/routes/docs/components/accordion.md Updated documentation to show usage of the new classes prop instead of separate class props.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Accordion
    participant AccordionItem

    User->>Accordion: Passes { classes: { active, inactive, ... } }
    Accordion->>AccordionItem: Provides classes via context
    AccordionItem->>AccordionItem: Uses classes.active/inactive for styling
Loading

Possibly related PRs

Poem

A hop and a skip, the classes combine,
No more props for every design!
With a single classes object, so neat,
Accordion styling is now a treat.
Rabbits rejoice, for code is concise—
Refactoring done, and it feels so nice!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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

vercel bot commented May 28, 2025

@jjagielka is attempting to deploy a commit to the Themesberg Team on Vercel.

A member of the Team first needs to authorize it.

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)
src/lib/types.ts (1)

73-76: Consider improving type safety by replacing any usage.

The ComponentVariants generic type serves the refactoring well by unifying variant props with the classes object. However, the any usage reduces type safety.

Consider a more constrained approach:

-export type ComponentVariants<T extends ((...args: any) => any) & { slots: object }> = (
-  VariantProps<T> & { classes?: Partial<{ [K in keyof T["slots"]]: ClassValue }> }
-);
+export type ComponentVariants<T extends Record<string, unknown> & { slots: object }> = (
+  VariantProps<T> & { classes?: Partial<{ [K in keyof T["slots"]]: ClassValue }> }
+);

Alternatively, if the function constraint is necessary, consider:

-export type ComponentVariants<T extends ((...args: any) => any) & { slots: object }> = (
+export type ComponentVariants<T extends ((...args: unknown[]) => unknown) & { slots: object }> = (
🧰 Tools
🪛 ESLint

[error] 74-74: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 74-74: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66167c8 and 3fe0234.

📒 Files selected for processing (5)
  • src/lib/accordion/Accordion.svelte (2 hunks)
  • src/lib/accordion/AccordionItem.svelte (3 hunks)
  • src/lib/accordion/theme.ts (2 hunks)
  • src/lib/types.ts (3 hunks)
  • src/routes/docs/components/accordion.md (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/lib/accordion/theme.ts (2)
src/lib/types.ts (1)
  • ComponentVariants (74-76)
src/lib/accordion/index.ts (2)
  • accordion (3-3)
  • accordionitem (3-3)
src/lib/types.ts (1)
src/lib/accordion/theme.ts (2)
  • AccordionVariants (4-4)
  • AccordionItemVariants (20-20)
🪛 ESLint
src/lib/types.ts

[error] 74-74: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 74-74: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Playwright and Lint
🔇 Additional comments (12)
src/lib/accordion/theme.ts (2)

1-11: LGTM! Well-structured theme refactoring for the classes approach.

The conversion from individual class props to a slots-based structure is well-implemented:

  • Proper imports for ComponentVariants and VariantProps
  • Logical slots structure with base, active, and inactive
  • Empty strings for active/inactive allow flexible component-level overrides
  • Type aliases provide proper TypeScript integration

This foundation enables the consolidated classes prop pattern across the accordion components.


20-20: Good addition of AccordionItemVariants type alias.

This provides consistent typing for AccordionItem components, matching the pattern established for AccordionVariants.

src/routes/docs/components/accordion.md (1)

88-98: Excellent documentation update reflecting the new classes API.

The documentation accurately demonstrates the transition from separate activeClass/inactiveClass props to the consolidated classes object structure. The example clearly shows the correct usage pattern:

classes={{
  active: "bg-blue-100 dark:bg-gray-800 text-blue-600...",
  inactive: "text-gray-500 dark:text-gray-400 hover:bg-blue-100..."
}}

This will help users understand and adopt the new API effectively.

src/lib/accordion/Accordion.svelte (2)

5-7: Correct import and props update for the classes refactoring.

The import of AccordionProps and props destructuring properly incorporate the new classes prop while removing the deprecated individual class properties.


16-17: Proper context setup for the new classes structure.

The context correctly extracts active and inactive classes from the classes object using optional chaining. This maintains the existing context pattern while supporting the new consolidated API.

src/lib/accordion/AccordionItem.svelte (4)

7-9: Good addition of clsx for flexible class composition.

The clsx import and updated props destructuring properly support the new classes object structure while maintaining clean component interfaces.


34-34: Excellent priority chain for class resolution.

The buttonClass logic properly prioritizes class sources:

  1. Component-level classes?.active/inactive (highest priority)
  2. Context-level ctx.activeClass/inactiveClass (backward compatibility)
  3. Theme defaults active()/inactive() (fallback)

This ensures both forward compatibility with the new API and backward compatibility with existing usage.


37-37: Clean class composition for the base element.

Using clsx(classes?.base, className) provides flexible and intuitive class merging for the base heading element.


63-63: Consistent content class application.

The content class composition using clsx(classes?.content) is applied consistently across both transition and non-transition rendering blocks, ensuring uniform styling behavior.

Also applies to: 70-70

src/lib/types.ts (3)

59-59: LGTM! Import addition supports the new variant-based approach.

The import of AccordionItemVariants and AccordionVariants correctly supports the accordion component refactoring to use the new classes prop approach.


171-175: Excellent refactoring approach for accordion props consolidation.

The refactoring successfully consolidates multiple class-related props into the variant-based approach:

  • AccordionProps now extends AccordionVariants instead of having separate activeClass, inactiveClass, etc.
  • Addition of transitionParams provides enhanced animation control
  • This aligns perfectly with the PR objective to use a single classes prop object

178-184: Consistent refactoring approach for AccordionItem.

The AccordionItemProps interface follows the same excellent refactoring pattern:

  • Extends AccordionItemVariants for consolidated class management
  • Includes transitionParams for animation flexibility
  • Maintains consistency with the AccordionProps approach

Copy link
Collaborator

Choose a reason for hiding this comment

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

As I mentioned it here, I think classes?.activeCtx and classes?.inactiveCtx make it clear to users that we are using them for context. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Not a problem to change the slots names as above, however why that's important? That's the implementation detail.

@shinokada
Copy link
Collaborator

shinokada commented May 28, 2025

Yes, we should start a branch/tag called v2.0.0-next.1 following Svelte convetion.
I will make it now. Just a second.

@shinokada
Copy link
Collaborator

@jjagielka
Copy link
Contributor Author

How should I push so the PR would go to the new branch?

@shinokada
Copy link
Collaborator

I'm wondering if it is easier to use https://github.com/themesberg/flowbite-svelte-next main branch. What do you think?

Or you could do:

git checkout -b v2.0.0-next.1
git push -u origin v2.0.0-next.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants