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

Implement accordion component #2262

Merged
merged 10 commits into from Dec 9, 2023
Merged

Implement accordion component #2262

merged 10 commits into from Dec 9, 2023

Conversation

picklelo
Copy link
Contributor

@picklelo picklelo commented Dec 6, 2023

Test code:

"""Welcome to Reflex! This file outlines the steps to create a basic app."""
from rxconfig import config

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


docs_url = "https://reflex.dev/docs/getting-started/introduction"
filename = f"{config.app_name}/{config.app_name}.py"
import random

data = [
    {"name": "Page A", "uv": 4000, "pv": 2400, "amt": 2400},
    {"name": "Page B", "uv": 3000, "pv": 1398, "amt": 2210},
    {"name": "Page C", "uv": 2000, "pv": 9800, "amt": 2290},
    {"name": "Page D", "uv": 2780, "pv": 3908, "amt": 2000},
    {"name": "Page E", "uv": 1890, "pv": 4800, "amt": 2181},
    {"name": "Page F", "uv": 2390, "pv": 3800, "amt": 2500},
    {"name": "Page G", "uv": 3490, "pv": 4300, "amt": 2100},
]

data01 = [
    {"x": 100, "y": 200, "z": 200},
    {"x": 120, "y": 100, "z": 260},
    {"x": 170, "y": 300, "z": 400},
    {"x": 170, "y": 250, "z": 280},
    {"x": 150, "y": 400, "z": 500},
    {"x": 110, "y": 280, "z": 200},
]

data02 = [
    {"name": "Group A", "value": 400},
    {"name": "Group B", "value": 300},
    {"name": "Group C", "value": 300},
    {"name": "Group D", "value": 200},
    {"name": "Group E", "value": 278},
    {"name": "Group F", "value": 189},
]


class State(rx.State):
    """The app state."""

    count = 0

    def increment(self):
        """Increment the count."""
        self.count += 1

    def decrement(self):
        """Decrement the count."""
        self.count -= 1

    def random(self):
        """Randomize the count."""
        self.count = random.randint(0, 100)

def index() -> rx.Component:
    return rdxt.theme(
        rdxt.container(
            rdxt.flex(
                rdxp.accordion(
                    [
                        ("Is it accessible?", rdxt.button("Test button")),
                        ("Is it unstyled?", "Yes. It's unstyled by default, giving you freedom over the look and feel."),
                        ("Is it finished?", "It's still in beta, but it's ready to use in production.")
                    ],
                    type="single",
                    collapsible=True,
                    width="300px",
                ),
                rdxt.heading(State.count),
                rdxt.flex(
                    rdxt.button("Decrement", on_click=State.decrement),
                    rdxt.button(
                        "Randomize",
                        on_click=State.random,
                    ),
                    rdxt.button("Increment", on_click=State.increment),
                    direction="row",
                ),
                rx.recharts.area_chart(
                    rx.recharts.area(
                        data_key="uv",
                    ),
                    rx.recharts.x_axis(data_key="name"),
                    rx.recharts.y_axis(),
                    data=data,
                ),
                rx.recharts.scatter_chart(
                    rx.recharts.scatter(
                        data=data01,
                    ),
                    rx.recharts.x_axis(data_key="x", type_="number"),
                    rx.recharts.y_axis(data_key="y"),
                ),
                rx.recharts.pie_chart(
                    rx.recharts.pie(
                        data=data02,
                        data_key="value",
                        name_key="name",
                        cx="50%",
                        cy="50%",
                        label=True,
                        color_scheme="amber",
                    )
                ),
                # rx.data_editor(
                #     columns=columns,
                #     data=data,
                # ),
                direction="column",
                padding="1em",
                border_radius="1em",
                box_shadow="lg",
                gap="4",
            ),
            padding_y="5em",
            font_size="2em",
            text_align="center",
        )
    )


# Add state and page to the app.
app = rx.App(
    theme=rdxt.theme(
        appearance="dark", has_background=True, radius="none", accent_color="crimson"
    ),
)

app.add_page(index)
app.compile()

@picklelo picklelo marked this pull request as draft December 6, 2023 01:44
@@ -1,4 +1,5 @@
{% import 'web/pages/utils.js.jinja2' as utils %}
/** @jsxImportSource @emotion/react */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure why, but in my app this is rendering as

/** @jsxImportSource @emotion/react */import { Fragment } from "react"

It still seems to work, somehow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah not sure I added an extra blank line but doesn't seem to care

@picklelo picklelo marked this pull request as ready for review December 7, 2023 20:45
@picklelo picklelo requested a review from Alek99 December 7, 2023 20:45
reflex/style.py Outdated
@@ -48,7 +48,7 @@ def convert(style_dict):
var_data = None # Track import/hook data from any Vars in the style dict.
out = {}
for key, value in style_dict.items():
key = format.to_camel_case(key)
key = format.to_camel_case(key, allow_hyphens=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is this intending to support? this breaks the code that i was working on to support things like ::-webkit-scrollbar as pseudo elements

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 needed this for certain aria-label props, that were getting converted automatically toariaLabel and messing it up. I'll see if I can remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Undid this change

style: Style = Style(
{
"fontFamily": "inherit",
"backgroundColor": "white",
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably should use a theme color here

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 made it "transparent" though I think actually it should be using one of the gray colors (either white or black). We can update this with the themes PR

@@ -195,6 +196,10 @@ class Cartesian(Recharts):
# The type of icon in legend. If set to 'none', no legend item will be rendered. 'line' | 'plainline' | 'square' | 'rect'| 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye' | 'none'optional
# legend_type: Var[LiteralLegendType]

def _apply_theme(self, theme: Component):
self.stroke = Var.create(f"var(--accent-8)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem to be working... when i change the accent color, it does not affect the charts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the graphing changes for now

@Alek99 Alek99 merged commit 96f68cb into main Dec 9, 2023
45 checks passed
@picklelo picklelo deleted the nikhil/radix-primitives branch January 30, 2024 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants