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

Radix primitive based Drawer component #2445

Merged
merged 9 commits into from Jan 30, 2024
Merged

Conversation

martinxu9
Copy link
Contributor

@martinxu9 martinxu9 commented Jan 24, 2024

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

After these steps, you're ready to open a pull request.

rdxt.flex(
    rdxp.drawer_root(
        rdxp.drawer_trigger(rdxt.button("Open Drawer with snap points"), as_child=True),
        rdxp.drawer_overlay(),
        rdxp.drawer_portal(
            rdxp.drawer_content(
                rdxt.flex(
                    rdxp.drawer_title("Drawer Content"),
                    rdxp.drawer_description("Drawer description"),
                    rdxp.drawer_close(
                        rdxt.button("Close Button"),
                        as_child=True,
                    ),
                    rdxt.text("more content, drag me up"),
                    rdxt.text("more content, drag me up"),
                    rdxt.text("more content, drag me up"),
                    rdxt.text("more content, drag me up"),
                    rdxt.text("more content, drag me up"),
                    rdxt.text("more content, drag me up"),
                    direction="column",
                    margin="5em",
                    align_items="center",
                ),
                top="auto",
                height="100%",
                flex_direction="column",
                background_color="var(--green-3)",
            ),
        ),
        snap_points=["148px", "355px", 1],
    ),
    rdxp.drawer_root(
        rdxp.drawer_trigger(rdxt.button("Open Drawer 1 from bottom"), as_child=True),
        rdxp.drawer_portal(
            rdxp.drawer_overlay(),
            rdxp.drawer_content(
                rdxt.flex(
                    rdxp.drawer_title("Drawer Content 1"),
                    rdxp.drawer_description("Drawer description 1"),
                    rdxp.drawer_close(
                        rdxt.button("Close 1"),
                        as_child=True,
                    ),
                    direction="column",
                    gap="2",
                    align_items="center",
                ),
                top="auto",
                height="auto",
                flex_direction="column",
                background_color="var(--blue-3)",
            ),
        ),
    ),
    rdxp.drawer_root(
        rdxp.drawer_trigger(rdxt.button("Open Drawer 2 from top"), as_child=True),
        rdxp.drawer_portal(
            rdxp.drawer_overlay(),
            rdxp.drawer_content(
                rdxt.flex(
                    rdxp.drawer_title("Drawer Content 2"),
                    rdxp.drawer_description("Drawer description 2"),
                    rdxp.drawer_close(
                        rdxt.button("Close 2"),
                        as_child=True,
                    ),
                    direction="column",
                    gap="2",
                    align_items="center",
                ),
                bottom="auto",
                height="auto",
                flex_direction="column",
                background_color="var(--red-3)",
                margin_bottom="6rem",
            ),
        ),
        direction="top",
    ),
    rdxp.drawer_root(
        rdxp.drawer_trigger(rdxt.button("Open Drawer 3 from left"), as_child=True),
        rdxp.drawer_portal(
            rdxp.drawer_overlay(),
            rdxp.drawer_content(
                rx.vstack(
                    rdxp.drawer_title("Drawer Content 3"),
                    rdxp.drawer_description("Drawer description 3"),
                    rdxp.drawer_close("Close 3"),
                    align_items="end",
                ),
                width="auto",
                right="auto",
                flex_direction="column",
                background_color="var(--red-3)",
            ),
        ),
        direction="left",
    ),
    rdxp.drawer_root(
        rdxp.drawer_trigger(rdxt.button("Open Drawer 4 from right"), as_child=True),
        rdxp.drawer_portal(
            rdxp.drawer_overlay(),
            rdxp.drawer_content(
                rdxt.flex(
                    rdxp.drawer_title("Drawer Content 4"),
                    rdxp.drawer_description("Drawer description 4"),
                    rdxp.drawer_close(
                        rdxt.button("Close 4"),
                        as_child=True,
                    ),
                    align_items="start",
                    direction="column",
                ),
                width="auto",
                left="auto",
                flex_direction="column",
                background_color="var(--yellow-3)",
            ),
        ),
        direction="right",
    ),
    gap="2",
    direction="column",
    spacing="1.5em",
    font_size="2em",
    padding_top="10%",
)

@martinxu9 martinxu9 changed the title Radix primitive based Drawer component [WIP] Radix primitive based Drawer component Jan 24, 2024
@martinxu9 martinxu9 requested a review from Alek99 January 24, 2024 19:53
@martinxu9 martinxu9 marked this pull request as ready for review January 24, 2024 19:53
Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

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

Functionality seems to work, need to improve the default styling - ideally we shouldn't have to set margin/padding props in the usage level

The dictionary of the component style as value and the style notation as key.
"""
base_style = {
"left": "0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be setting all of these? Then it will stretch to the full width of the page I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A variation of that if not that precisely. Basically trying to replicate the shadcn UI implementation, their drawer is basically this drawer component plus this. From the look of it, their drawer is always coming up from bottom. Without these style below, the drawer will be just a dialogue flying in from a certain direction (not sure if that should still be called drawer).

<DrawerPrimitive.Content
      ref={ref}
      className={cn(
        "fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background",
        className
      )}
      {...props}
    >

base_style.update(style)
self.style.update(
{
"css": base_style,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you have to put it in the css tag? I think we automatically handle this now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I must've been misinformed. Can you point me to an example how the latest way to do this?

Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

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

works well for me

@martinxu9 martinxu9 merged commit 0378b2a into main Jan 30, 2024
40 of 45 checks passed
@martinxu9 martinxu9 deleted the martinxu9/drawer-component branch January 30, 2024 04:32
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.

None yet

2 participants