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): adding theme prop to components #566

Closed
wants to merge 1 commit into from

Conversation

rluders
Copy link
Collaborator

@rluders rluders commented Jan 26, 2023

Description

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

@rluders rluders force-pushed the feat/component-theme-props branch from 8cbb0ae to fb07e4c Compare January 27, 2023 14:28
@rluders rluders force-pushed the feat/component-theme-props branch from fb07e4c to 3640109 Compare January 27, 2023 15:13
@tulup-conner tulup-conner self-assigned this Feb 14, 2023
@tulup-conner tulup-conner added this to the 0.4.0 milestone Feb 14, 2023
@tulup-conner tulup-conner added 🚀 enhancement New feature or request good first issue Good for newcomers labels Feb 14, 2023
tulup-conner added a commit to tulup-conner/flowbite-react that referenced this pull request Feb 19, 2023
tulup-conner added a commit to tulup-conner/flowbite-react that referenced this pull request Feb 20, 2023
rluders pushed a commit that referenced this pull request Feb 20, 2023
* feat(theme): adding theme prop to components

* feat(/theme/default): finish migrating components to use a `root` theme

Follow up to #500

BREAKING CHANGE: Like in #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.

* ci(eslint): remove `prettier` plugins for `eslint`

Instead, use `prettier-plugin-tailwindcss`, which is sufficient.

* refactor(/lib/*): use `yarn prettier` with `prettier-plugin-tailwindcss`

* fix(/lib/components/*.spec): resolve test errors caused by migrating theme

* feat(/lib/components/*): add `theme={}` attribute to components that need it

See notes in #566

* fix(/lib/components/accordion): fix `<Accordion theme={}` types wrong interface

* docs(/pages/theme): update `/theme` documentation to include new theme strategies

We have more powerful options to customize themes now, and they deserve proper documentation.

* ci(eslint): fix `eslint` configured to ignore `src/lib/`

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.

* ci(eslint): resolve outstanding `eslint` issues

* fix(/lib/components/footer/footertitle): allow `<Footer.Title as="..">` 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 #594

* fix(/lib/components/modal): fix `Modal` expects `document` to exist

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

resolve #609

* ci(.github/workflows/build): upgrade `codecov-action` -> `v3`

---------

Co-authored-by: Ricardo Lüders <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers 🚀 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants