-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(recharts): stop routing component props to wrapperStyle #6833
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
base: main
Are you sure you want to change the base?
Changes from all commits
23d2192
b2b834c
4c9fa10
65083f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix Recharts component props (e.g. `stroke_dasharray` on `reference_line`, `tick_formatter` on `x_axis`/`y_axis`) being misclassified as CSS and routed to `wrapperStyle` instead of reaching the underlying Recharts component. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,14 +2,15 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Sequence | ||
| from collections.abc import Callable, Sequence | ||
| from typing import Any, ClassVar, TypedDict | ||
|
|
||
| from reflex_base.components.component import field | ||
| from reflex_base.constants import EventTriggers | ||
| from reflex_base.constants.colors import Color | ||
| from reflex_base.event import EventHandler, no_args_event_spec | ||
| from reflex_base.vars.base import LiteralVar, Var | ||
| from reflex_base.vars.function import FunctionStringVar, FunctionVar | ||
|
|
||
| from .recharts import ( | ||
| ACTIVE_DOT_TYPE, | ||
|
|
@@ -114,10 +115,51 @@ class Axis(Recharts): | |
|
|
||
| tick_size: Var[int] = field(doc="The length of tick line. Default: 6") | ||
|
|
||
| tick_formatter: Var[str | Callable[..., Any]] = field( | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| doc="A function to format the tick value shown in the axis. Pass a " | ||
| "raw JS function expression as a string, e.g. tick_formatter=" | ||
| '"(value) => value.toFixed(2)".' | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| ) | ||
|
|
||
| min_tick_gap: Var[int] = field( | ||
| doc="The minimum gap between two adjacent labels. Default: 5" | ||
| ) | ||
|
|
||
| @classmethod | ||
| def create(cls, *children, **props): | ||
| """Create an Axis component. | ||
|
|
||
| Args: | ||
| *children: The children of the component. | ||
| **props: The properties of the component. | ||
|
|
||
| Returns: | ||
| The Axis component. | ||
| """ | ||
| if (tick_formatter := props.get("tick_formatter")) is not None: | ||
| if isinstance(tick_formatter, str): | ||
| props["tick_formatter"] = FunctionStringVar.create( | ||
| tick_formatter, | ||
| _var_type=Callable[..., Any], # pyright: ignore [reportArgumentType] | ||
| ) | ||
| elif isinstance(tick_formatter, FunctionVar): | ||
| # Normalize to a consistent _var_type regardless of how the | ||
| # caller constructed the FunctionVar, so it satisfies the | ||
| # declared field type below. | ||
| props["tick_formatter"] = tick_formatter._replace( | ||
| _var_type=Callable[..., Any] # pyright: ignore [reportArgumentType] | ||
| ) | ||
| elif not isinstance(tick_formatter, Var): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: A reactive string such as Prompt for AI agents |
||
| msg = ( | ||
| "tick_formatter must be a raw JS function expression string " | ||
| f'(e.g. "(value) => value.toFixed(2)") or a Var, got a Python ' | ||
| f"{type(tick_formatter).__name__}. Python values (including " | ||
| "plain callables like lambdas) cannot be sent to the client " | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Type checkers still accept the Python callables this branch now rejects at runtime because the generated Prompt for AI agents |
||
| "as-is and are not supported." | ||
| ) | ||
| raise TypeError(msg) | ||
| return super().create(*children, **props) | ||
|
|
||
| stroke: Var[str | Color] = field( | ||
| default=LiteralVar.create(Color("gray", 9)), | ||
| doc='The stroke color of axis. Default: rx.color("gray", 9)', | ||
|
|
@@ -816,6 +858,10 @@ class ReferenceLine(Reference): | |
| doc="The width of the stroke. Default: 1" | ||
| ) | ||
|
|
||
| stroke_dasharray: Var[str] = field( | ||
| doc="The pattern of dashes and gaps used to paint the reference line." | ||
| ) | ||
|
|
||
| # Valid children components | ||
| _valid_children: ClassVar[list[str]] = ["Label"] | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.