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

Improve disclosure component for state creating content, add options to control a transition's initial and after-end classes #862

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

haukesomm
Copy link
Collaborator

@haukesomm haukesomm commented Apr 26, 2024

Overview

This PR changes the headless disclosure to only render its panel's content once and then show/hide it based on styling. Currently, the panel's content is rendered every time the disclosure is opened/closed.

Warning

In order to achieve this, the headless component no longer controls the panel's visibility. All styling is now solely done by the implementor of a headless discloure and needs to be adjusted accordingly. Thus, the changes introduced in this PR are api breaking!

Additionally, the transition function for Flow-based transitions has been extended to allow optional control over initial classes and classes that should be present after the leave-transition has ended. This is useful to allow transitions on an element's visibility which are normally not possible using pure CSS.

Disclosure

As mentioned earlier, the headless disclosure no longer creates a mount-point for its panel to re-render based on the open-state. Instead, it now only provides the state and leaves the styling to the implementor.

This is necessary due to multiple reasons:

  1. Creating a mount-point is not related to styling, thus it can easily be done in headless. Hiding/showing an element is - that's why it cannot be done in headless.
  2. Leaving the entire styling (including the styles used for hiding/showing the element) to the implementor allows for greater flexibility on how a concrete disclosure component might work. For example, it might behave similar to a spoiler element on social media sites and provide a blurred preview of some content that is revealed when clicked.
  3. By leaving the styling to the user, all styling can be applied in a single place whithout some internal styling working against you.

Migration

In order to migrate an existing disclosure component, styling information for the opened/closed states must be provided.
Find different migration scenarios below.

Note

All examples below are using Tailwind CSS. However, you are free to use any CSS framework, or even plain CSS, as well.

1) The disclosure to migrate does not use transitions

In this case, the appropriate styling for the opened/closed states needs to be added. No existing styles have to be adjusted.
This can be as easy as simply providing basic styles via the className function.

Before:

disclosurePanel {
    // some content
}

After:

disclosurePanel {
    className(
        opened.map { if (it) "" else "hidden" },
        initial = "hidden"
    )
    // some content
}

2) The existing disclosure makes use of transitions

In this case, the existing transition call needs to be adjusted in order to provide visible/hidden classes. As mentioned in the beginning, this function has been adjusted accordingly.

Before:

disclosurePanel {
    transition(
        "transition transition-all duration-500 ease-in",
        "opacity-0 scale-y-95 max-h-0",
        "opacity-100 scale-y-100 max-h-[100vh]",
        "transition transition-all duration-500 ease-out",
        "opacity-100 scale-y-100 max-h-[100vh]",
        "opacity-0 scale-y-95 max-h-[0]"
    )
    // some content
}

After:

disclosurePanel {
    transition(
        opened,
//      ^^^^^^
//      change the transition to be flow based by specifing a triggering flow via the `on` parameter
        "transition transition-all duration-500 ease-in",
        "opacity-0 scale-y-95 max-h-0",
        "opacity-100 scale-y-100 max-h-[100vh]",
        "transition transition-all duration-500 ease-out",
        "opacity-100 scale-y-100 max-h-[100vh]",
        "opacity-0 scale-y-95 max-h-[0]",
         afterLeaveClasses = "hidden",
//      ^^^^^^
//      provide classes that should be present when the leave transition is over (panel hidden)
         initialClasses = "hidden"
//      ^^^^^^
//      provide an initial styling. In this case: `hidden`, since `opened` is false by default
    )
    // some content
}

Closes #754

@haukesomm haukesomm added api breaking Forces client sources to change headless All about headless components and foundations labels Apr 26, 2024
@haukesomm haukesomm added this to the 1.0-RC18 milestone Apr 26, 2024
@haukesomm haukesomm force-pushed the haukesomm/disclosure-visibility branch from 32e8340 to 463162c Compare April 26, 2024 13:37
This commit changes the headless disclosure
component to only render its content once and
provide a mechanism to then display or hide its
panel's content via CSS.

Previously, the panel content has been re-rendered
whenever the disclosure was opened or closed.
@haukesomm haukesomm force-pushed the haukesomm/disclosure-visibility branch from 463162c to 1ca099a Compare April 26, 2024 13:48
@haukesomm haukesomm marked this pull request as ready for review April 26, 2024 15:13
@haukesomm haukesomm changed the title Improve Disclosure Component for State Creating Content, add options to control a transition's initial and after-end classes Improve disclosure component for state creating content, add options to control a transition's initial and after-end classes Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api breaking Forces client sources to change headless All about headless components and foundations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Disclosure Component for State Creating Content
1 participant