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

[REF-668] Wrap MyApp with radix Theme component #1867

Merged
merged 32 commits into from
Oct 16, 2023
Merged

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Sep 25, 2023

MVP to test radix-ui/themes integration with reflex.

Sample code

import reflex as rx
import reflex.components.radix.themes as rdxt


class State(rx.State):
    pass


def index() -> rx.Component:
    return rdxt.box(
        rx.color_mode_switch(),
        rdxt.heading("Welcome to Reflex!"),
        rdxt.text("Radix-ui/themes edition!"),
        rdxt.button("Click me!", variant="soft"),
        rdxt.button("I'm Gray 🌈!", color="gray"),
        rdxt.text_field(),
    )


# Add state and page to the app.
app = rx.App(theme=rdxt.theme(accent_color="grass"), overlay_component=None)
app.add_page(index)
app.compile()

(hint: open Theme Panel via Cmd+C to play with colors, borders, etc)

I need to merge the pyi_generator changes up separately and update all existing pyi files, which will probably happen before this merges.

still not perfect, as the RadixColorModeProvider seems to trip hydration errors
when using color_mode_cond component, but for now, this provides a nice balance
between the two libraries and allows them to interoperate.
avoid templating json and applying it, avoid non-customizable logic

just add the radix Theme component as an app wrap if the user specifies it to
rx.App, and any other app-wrap theme-like component could _also_ be used
without having to change the code.

this also allows different themes for different sections of the app by simply
placing elements inside a different rdxt.theme wrapper.
this is always used, regardless of the component library
@masenf masenf marked this pull request as ready for review October 12, 2023 00:40
we only need the compile result, we're not actually trying to install packages
until all of our components look good in dark mode, need to keep the default as
light mode regardless of the system setting.
@Alek99 Alek99 self-requested a review October 16, 2023 21:35
@Alek99
Copy link
Member

Alek99 commented Oct 16, 2023

Looking at this now

Copy link
Member

@Alek99 Alek99 left a comment

Choose a reason for hiding this comment

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

This looks good to me. I tested with a couple of different small apps. Also Chakra and Radix themes don't seem to be conflicting on reflex web 👍

@Alek99
Copy link
Member

Alek99 commented Oct 16, 2023

import reflex as rx
import reflex.components.radix.themes as rdxt


class State(rx.State):
    pass


def index() -> rx.Component:
    return rdxt.box(
        rx.color_mode_switch(),
        rdxt.heading("Welcome to Reflex!"),
        rdxt.flex(
            rdxt.button("Click me!", variant="classic"),
            rdxt.button("Click me!", variant="soft"),
            rdxt.button("Click me!", variant="solid"),
            rdxt.button("Click me!", variant="outline"),
            rdxt.button("Click me!", variant="surface"),
            gap="2",
        ),
        rdxt.heading("."),
        rdxt.flex(
            rdxt.button("Click me!", variant="classic", high_contrast=True),
            rdxt.button("Click me!", variant="soft", high_contrast=True),
            rdxt.button("Click me!", variant="solid", high_contrast=True),
            rdxt.button("Click me!", variant="outline", high_contrast=True),
            rdxt.button("Click me!", variant="surface", high_contrast=True),
            gap="2",
        ),
        rdxt.theme_panel(),
    )


# Add state and page to the app.
app = rx.App(theme=rdxt.theme(accent_color="grass"), overlay_component=None)
app.add_page(index)
app.compile()

For anyone else

@Alek99 Alek99 merged commit 6760656 into main Oct 16, 2023
Lendemor pushed a commit that referenced this pull request Oct 17, 2023
* partly add some radix-ui/themes based components

* add @radix-ui/themes integration to top-level app

* WiP: compile _app_wrap based on which component library is used

TODO: working color mode

* WiP get color mode working with agnostic provider

still not perfect, as the RadixColorModeProvider seems to trip hydration errors
when using color_mode_cond component, but for now, this provides a nice balance
between the two libraries and allows them to interoperate.

* WiP template _app.js instead of making a separate wrap file

* WiP: use next-themes for consistent darkmode switching

* strict pin chakra deps

* Move ChakraColorModeProvider to separate js file

* move nasty radix themes js code into js files

* remove chakra from default imports

* chakra fixup import to use .js extension

* Add radix theme typography and layout components

* do NOT special case the radix theme...

avoid templating json and applying it, avoid non-customizable logic

just add the radix Theme component as an app wrap if the user specifies it to
rx.App, and any other app-wrap theme-like component could _also_ be used
without having to change the code.

this also allows different themes for different sections of the app by simply
placing elements inside a different rdxt.theme wrapper.

* Theme uses "radius" not "borderRadius"

* move next-themes to main packages.json

this is always used, regardless of the component library

* test_app: test cases for app_wrap interface

* Finish wrapping Button, Switch, and TextField components

* docstring, comments, static fixups

* debounce: use alias or tag when passing child Element

Fix REF-830

* test_app: ruin my beautiful indentation

* py38 compatibility

* Add event triggers for switch and TextField

* Add type hints for radix theme components

* radix themes fixups from writing the tests

* Add integration test for radix themes components

* test_app: mock out package installation

we only need the compile result, we're not actually trying to install packages

* avoid incompatible version of @emotion/react

* test_radix_themes: include theme_panel component

* next-themes default scheme: "light"

until all of our components look good in dark mode, need to keep the default as
light mode regardless of the system setting.
@masenf masenf deleted the masenf/radix-theme-mvp branch October 18, 2023 18:12
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