Skip to content
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

feat(theme): add theme={} attribute to components that need it #611

Merged
merged 13 commits into from
Feb 20, 2023

Conversation

tulup-conner
Copy link
Collaborator

@tulup-conner tulup-conner commented Feb 19, 2023

Description

This is a continuation of #566

The following components can now be customized with a theme={} attribute inline:

  • Accordion
    • Accordion.Content
    • Accordion.Title
  • Alert
  • Avatar
    • Avatar.Group
    • Avatar.GroupCounter
  • Badge
  • Breadcrumb
    • Breadcrumb.Item
  • Button
    • Button.Group
  • Card
  • Carousel
  • Checkbox
  • DarkThemeToggle
  • Dropdown
    • Dropdown.Item
  • FileInput
  • Footer
    • Footer.Brand
    • Footer.Copyright
    • Footer.Divider
    • Footer.Icon
    • Footer.Link
    • Footer.LinkGroup
    • Footer.Title
  • HelperText
  • Label
  • ListGroup
    • ListGroup.Item
  • Modal
    • Modal.Body
    • Modal.Footer
    • Modal.Header
  • Navbar
    • Navbar.Brand
    • Navbar.Collapse
    • Navbar.Link
    • Navbar.Toggle
  • Pagination
    • Pagination.Button
  • Progress
  • Radio
  • RangeSlider
  • Rating
    • Rating.Advanced
    • Rating.Star
  • Select
  • Sidebar
    • Sidebar.Collapse
    • Sidebar.CTA
    • Sidebar.Item
    • Sidebar.Logo
  • Spinner
  • Tabs.Group
  • Table
    • Table.Body
    • Table.Cell
    • Table.Head
    • Table.HeadCell
    • Table.Row
  • Textarea
  • TextInput
  • Timeline
    • Timeline.Body
    • Timeline.Content
    • Timeline.Item
    • Timeline.Point
    • Timeline.Time
    • Timeline.Title
  • Toast
    • Toast.Toggle
  • ToggleSwitch
  • Tooltip

Please note that components you do NOT see on this list can STILL be customized by simply adding a className. These components do not have any default classes or complex structure and thus don't need a theme at all.

This behavior is still considered a work in progress, and in general, we are still experimenting with how to provide users with the best way to customize components. You can expect that this API might change at any time. We also need your feedback on how to improve it.

Related to #465

Type of change

  • New feature (non-breaking change which adds functionality)

Breaking changes

We are also finishing the process of converting components to a new theme structure, so you can expect the themes of almost all components to change in expected behavior.

Now, components that can have children will have a root section which contains the classes that apply only to the parent component. That's kind of a complicated sentence, so here's an example.

<Accordion>s can contain any number of <Accordion.Title>s and <Accordion.Content>s as children. The new accordion theme looks like:

export interface FlowbiteAccordionTheme {
  root: FlowbiteAccordionRootTheme; /* classes that apply to <Accordion> itself only */
  content: FlowbiteAccordionComponentTheme; /* <Accordion.Content> classes */
  title: FlowbiteAccordionTitleTheme; /* <Accordion.Title> classes */
}

Previously, the accordion theme was:

export interface FlowbiteAccordionTheme {
  base: string; /* class that applies to <Accordion> itself only */
  flush: string; /* another class that applies to <Accordion>s */
  content: FlowbiteAccordionComponentTheme; /* <Accordion.Content> classes */
  title: FlowbiteAccordionTitleTheme; /* <Accordion.Title> classes */
}

We've just moved the loose classes - for <Accordion>s, that's accordion.base and accordion.flush - into root to make the theme more clearly reflect the relationship between flowbite-react components.

How Has This Been Tested?

  • yarn test
  • Visual inspection of local servers at yarn start, yarn start:storybook

We should consider adding tests using the theme={} attribute in every component where it is allowed. The specific benefit of that is to ensure that the expected theme format actually works.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Ricardo Lüders and others added 5 commits February 14, 2023 12:07
Follow up to themesberg#500

BREAKING CHANGE: Like in themesberg#500, this version permanently changes the `FlowbiteTheme` for numerous
components.

The philosophy is that themes will more clearly reflect the component's structure.

For example, an `<Accordion>` can contain any number of `<Accordion.Title>` or `<Accordion.Content>`
sections. The theme used to look like:

```js
accordion: {
  base: "..",
  content: "..",
  flush: "..",
  title: "..",
}
```

And now, the theme for an `<Accordion>` looks like:

```
js
accordion: {
  root: {
    base: "..",
    flush: "..",
  },
  content: "..",
  title: "..",
}
```

So now the options in the theme which apply to the `<Accordion>` itself will always be found under
`root`. Likewise, `<Accordion.Content>` can be themed via the `content` subsection.

This ultimately will apply to all components.
Instead, use `prettier-plugin-tailwindcss`, which is sufficient.
@tulup-conner tulup-conner self-assigned this Feb 19, 2023
@tulup-conner tulup-conner added the 🚀 enhancement New feature or request label Feb 19, 2023
@codecov
Copy link

codecov bot commented Feb 19, 2023

Codecov Report

Base: 99.29% // Head: 99.35% // Increases project coverage by +0.06% 🎉

Coverage data is based on head (a5f947f) compared to base (6501245).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #611      +/-   ##
==========================================
+ Coverage   99.29%   99.35%   +0.06%     
==========================================
  Files         131      131              
  Lines        5794     6378     +584     
  Branches      480      480              
==========================================
+ Hits         5753     6337     +584     
  Misses         41       41              
Impacted Files Coverage Δ
src/lib/components/Accordion/Accordion.tsx 100.00% <100.00%> (ø)
src/lib/components/Accordion/AccordionContent.tsx 100.00% <100.00%> (ø)
src/lib/components/Accordion/AccordionPanel.tsx 100.00% <100.00%> (ø)
src/lib/components/Accordion/AccordionTitle.tsx 100.00% <100.00%> (ø)
src/lib/components/Alert/Alert.tsx 100.00% <100.00%> (ø)
src/lib/components/Avatar/Avatar.tsx 100.00% <100.00%> (ø)
src/lib/components/Avatar/AvatarGroup.tsx 100.00% <100.00%> (ø)
src/lib/components/Avatar/AvatarGroupCounter.tsx 100.00% <100.00%> (ø)
src/lib/components/Badge/Badge.tsx 100.00% <100.00%> (ø)
src/lib/components/Breadcrumb/Breadcrumb.tsx 100.00% <100.00%> (ø)
... and 76 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

…e strategies

We have more powerful options to customize themes now, and they deserve proper documentation.
Well this sucks! We've not been linting the vast majority of the actual code of the library due to a
misconfigured `.eslintignore`. Mass-fix coming.
…>` to not use `<h2>`

You can cast the component to a component of your own, or a generic HTML element, e.g.,
`<Footer.Title as="h3">`.

resolve themesberg#594
So, I originally fixed this issue across every component in themesberg#124, but the bug was reintroduced by

resolve themesberg#609
Copy link
Collaborator

@rluders rluders left a comment

Choose a reason for hiding this comment

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

This PR is huge. So, I'm trusting the unit test (we have a nice coverage here), and I also tested manually a little bit.

Since this will unblock some other PRs and as well it is a SUPER NICE feature and unblock us for the 0.4.0 release, I'm willing to take the risk to have to submit some patches in the sequence to fix any potential issues.

Thank you @tulup-conner

@rluders rluders merged commit 005d78a into themesberg:main Feb 20, 2023
@tulup-conner tulup-conner added this to the 0.4.0 milestone Feb 21, 2023
@osilkin98 osilkin98 mentioned this pull request Feb 26, 2023
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.

2 participants