Commit Graph

169 Commits

Author SHA1 Message Date
Masen Furer
b89a18f632
Separate get_hooks and get_hooks_internal for stable output (#2710)
* Separate `get_hooks` and `get_hooks_internal` for stable output

When downstream component wrappers depend on State when writing hooks, they
need to be assured that all internal hooks (events, var hooks, memoized
handlers, etc) will be rendered prior to user-defined hooks.

This also makes it less likely for downstream components to feel the need to
overwrite `get_hooks` (no underscore) directly and break internal functioning
of Reflex components.

* Include internal hooks in AppWrap and Page

* Apply get_hooks_internal in a few more places
2024-03-15 16:16:09 -07:00
Masen Furer
432fcd4a5b
Account for imports of @rx.memo components for frontend package installation (#2863)
* CustomComponent ignores the annotation type in favor of the passed value

Do not require rx.memo wrapped functions to have 100% correct annotations.

* test_custom_component_get_imports: test imports from wrapped custom components

* Account for imports of custom components for frontend installation

Create new ImportVar that only install the package to avoid rendering the
imports in the page that contains the custom component itself.

* Handle Imports that should never be installed

* Fix up double negative logic

* Perf Optimization: use the imports we already calculate during compile

Instead of augmenting _get_imports with a weird, slow, recursive crawl and
dictionary reconstruction, just use the imports that we compile into the
components.js file to install frontend packages needed by the custom
components.

Same effect, but adds essentially zero overhead to the compilation.
2024-03-15 09:59:59 -07:00
Masen Furer
036afa951a
Make @rx.memo work with state vars passed as props (#2810)
* Make @rx.memo work with state vars passed as props

Seems like this was a regression from the StatefulComponent refactor, because
trying to pass a state Var to a CustomComponent gave undefined, likely due to
`_get_vars` not accounting for `self.props` in CustomComponents.

With this change, it works.

Integration test added to `test_var_operations.py`

* Allow CustomComponent props to be Component

Avoid calling `.json()` on all Base types because the Var serializer already
does that, but this way, more specific types (like Component) can be serialized
differently.

When the type is Component, attach a VarData with the imports and hooks to when
the Var is rendered, it also carries the correct imports/hooks and does not
throw frontend errors.
2024-03-13 13:41:17 -07:00
Masen Furer
c809107d09
[REF-2158] Enable state when on_load or event_triggers are set. (#2815)
* [REF-2158] Enable state when `on_load` or event_triggers are set.

Basically all events in a reflex app require the backend to be up, even the
built-in server side events round trip to the backend and require "state" even
if no user-defined state classes are declared.

test_app_state_determination: checking that state is enabled at the right time

* Clear out DECORATED_PAGES when initializing a new app
2024-03-08 17:34:09 -08:00
benedikt-bartscher
19a5cdd408
Track state usage (#2441)
* rebase

* pass include_children kwarg in radix FormRoot

* respect include_children

* ruff fixes

* readd statemanager init, run pyi gen

* minor performance imporovements, fix for state changes

* fix pyi and pyright

* pass include_children for chakra

* remove old state detection

* add test for unused states in stateless app

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-03-07 14:25:55 -08:00
Masen Furer
c79719f7be
Expose on_drop event trigger for rx.upload component. (#2766)
* Expose `on_drop` event trigger for rx.upload component.

If `on_drop` is provided, it should be an EventSpec accepting the special
rx.upload_files() arg.

When `on_drop` is provided, it will be called immediately when files are
selected. The default functionality of saving a file list to be uploaded later
will not be available.

* update pyi file

* Undeprecate explicit EventChain
2024-03-05 12:07:36 -08:00
Elijah Ahianyo
37f66207fc
Use classes for allowed components (#2662) 2024-02-20 14:40:48 -08:00
Elijah Ahianyo
eeff4142ab
Accordion Root Exclude color_scheme and variant props in tag (#2664)
* Accordion Root Exclude `color_scheme` and `variant` props in tag

* colorScheme -> color for radix primitives

* remove _rename_props based on pr comments

* lint

* pyi fix

* pop instead of del
2024-02-20 09:57:01 -08:00
Nikhil Rao
4ad238c42c
Update deprecation version to 0.5.0 (#2642) 2024-02-16 11:23:15 -08:00
Masen Furer
3350fa0388
Component: translate underscore suffix for props supported by chakra (#2636)
* Component: translate underscore suffix for props supported by chakra

type_ becomes type
min_ becomes min
max_ becomes max
id_ becomes id

The deprecation warning is only displayed when the underscore suffix prop is
passed and the non-underscore suffix prop is defined on the given component.

* Rename type_ to type in accordion and scroll_area

All of the new radix components avoid the underscore suffix names where
possible.

* Update deprecation warning wording

* Refactor for readability

* Do not raise deprecation warning for `id_`

id is kind of a special prop because it exists on all components

* Add test case for deprecating underscore suffix props
2024-02-15 20:46:06 -08:00
Nikhil Rao
7240f8ee6f
Handle component namespaces in global styles (#2630) 2024-02-15 16:03:10 -08:00
Masen Furer
f12746d859
Inherit _rename_props from parent classes (#2613)
Ensure that _rename_props from base classes add to the list of _rename_props in subclasses.

Add a test case to validate this behavior.
2024-02-14 14:36:01 -08:00
Elijah Ahianyo
5e9b472d1b
[REF-1919] Valid Children/parents to allow Foreach,Cond,Match and Fragment (#2591) 2024-02-13 14:22:22 -08:00
Masen Furer
4206afeb7b
[REF-1958] Remove shadowed radix css props (#2590)
* style: shorthand replacements need camelCase

Avoid warning on terminal and in browser console from using kebab-case CSS
props with emotion.

* _rename_props only replace prop name once

In case the value also contains the prop name, we don't want to replace it
multiple times.

* pyi_generator: ignore _rename_props in create signature

* Avoid shadowing CSS prop `display` and `gap`

Replace usages of `gap` with `spacing` to retain Radix sizing number system,
while allowing users to specify a responsive `gap` using CSS units.

Remove `display` props from radix components, allowing `display` to accept
responsive lists.

* checkbox: apply `gap` to `flex` if provided

* Remove _rename_props from .create signatures

* Fix spacing prop in blank template

* Fixup tests after changing style shorthand to return camelCase
2024-02-13 10:06:28 -08:00
Elijah Ahianyo
64a90fa6eb
Decorator to validate rx.color prop fields (#2553) 2024-02-08 11:21:46 -08:00
Tom Gotsman
1b4229691a
All event handlers inherit from event triggers (#2507)
* update to ensure every radix component only inherits events from EventTriggers class

* update the naming of event handlers to swap name on_value_change and on_checked_change to on_change

* update to call _replace_prop_names in component.py

* small darglint error fix

* update to ensure every radix component only inherits events from EventTriggers class

* update the naming of event handlers to swap name on_value_change and on_checked_change to on_change

* update to call _replace_prop_names in component.py

* small darglint error fix

* updates to pass pytest tests

* small fix

* duplicate removal

---------

Co-authored-by: Tom Gotsman <tomgotsman@toms-mbp.lan>
2024-02-01 16:11:15 -08:00
Nikhil Rao
5176a7cb14
Support component create methods as keys in global styles (#2498) 2024-01-31 12:25:18 -08:00
Tianze
209c5fab7b
Tabs validate parent is proper tab container (#2463) 2024-01-30 11:45:00 -08:00
Elijah Ahianyo
5f1751acc2
Vardata for rx.Match (#2439) 2024-01-24 14:55:49 -08:00
Alek Petuskey
d466c2aaa2
Radix Accordion (#2310) 2024-01-18 14:20:21 -08:00
Thomas Brandého
527fa4bc3f
Add slider, progress, and form primitives (#2306) 2023-12-21 10:32:40 -08:00
Nikhil Rao
93c97383d9
Refactor chakra components into separate folder (#2315) 2023-12-21 09:52:08 -08:00
Masen Furer
e52267477c
[REF-1417] Convert underscore-prefixed style props to pseudo selector (#2266) 2023-12-11 13:37:57 -08:00
Nikhil Rao
96f68cb94d
Implement accordion component (#2262)
* Implement accordion component

* Fix literal annotation

* Use style prop instead of css

* Move accordion to primitives folder

* Add pyi file

* Fix pyright

* Add apply_theme method

* Fix apply_theme

* Use apply_theme method

* Fix lint
2023-12-08 21:20:30 -08:00
Thomas Brandého
caf32605ca
add next/image and next-video in next namespace (#2223) 2023-12-07 10:38:47 -08:00
Nikhil Rao
46d03880e6
Format var better in error message (#2269) 2023-12-06 13:31:29 -08:00
Masen Furer
e0a1b39231
[REF-1425] Always capitalize tag of StatefulComponent (#2264) 2023-12-06 09:41:09 -08:00
Masen Furer
49ccd2f1fb
Generalize MemoizationLeaf Component mixin (#2247) 2023-12-01 11:41:11 -08:00
Masen Furer
4ada79c1e5
[REF-1349] RechartsCharts and ResponsiveContainer must be memo leaf (#2240) 2023-12-01 09:49:59 -08:00
Masen Furer
a2d5bbc133
[reflex-web tweaks] Do not memoize children of InputGroup (#2230) 2023-11-30 09:48:28 -08:00
Masen Furer
0c55723df4
[REF-1158] Move chakra-only deps to chakra lib (#2171) 2023-11-28 00:04:07 -08:00
Masen Furer
527437cf23
[REF-144] Add context in each component to prevent rerenders (#2198) 2023-11-27 16:05:59 -08:00
Thomas Brandého
ed5b3818cb
update removal version of deprecated features (#2224) 2023-11-27 14:04:55 -08:00
Masen Furer
1603144c7d
[REF-889] useContext per substate (#2149) 2023-11-21 11:52:06 -08:00
Nikhil Rao
e9437ad941
Use singleton app provider to speed up compiles (#2172) 2023-11-20 18:11:24 -08:00
Thomas Brandého
1a83f85783
_valid_children and _invalid_children accessible from class (#2192) 2023-11-17 12:30:18 -08:00
Masen Furer
ce47fcfd6c
Fix CustomComponent rendering (#2169) 2023-11-14 13:03:12 -08:00
Masen Furer
f3929f47e3
form: only pass handleSubmit when on_submit is defined (#2162) 2023-11-13 23:27:42 -08:00
Nikhil Rao
33e4816950
Lazy import modules in reflex (#2144) 2023-11-13 19:48:12 -08:00
Thomas Brandého
eb52edb067
components as props (#2124) 2023-11-03 13:29:18 -07:00
Masen Furer
56476d0a86
Expose DOM event actions on EventHandler, EventSpec, and EventChain (stopPropagation) (#1891)
* Expose preventDefault and stopPropagation for DOM events

All EventHandler, EventSpec, and EventChain can now carry these extra
"event_actions" that will be applied inside the frontend code when an event is
triggered from the DOM.

Fix #1621
Fix REF-675

* Test cases (and fixes) for "event_actions"

* form: from __future__ import annotations

for py38, py39 compat

* Revert overzealous merge conflict resolution
2023-10-31 11:42:42 -07:00
Elijah Ahianyo
d785bd98da
Radix Themes style notation fix (#2025) 2023-10-24 10:29:44 -07:00
Elijah Ahianyo
b8f0674556
Improve Event handler Error message (#2019) 2023-10-24 10:28:51 -07:00
Thomas Brandého
490ae40a40
Wrap Moment Component (#1994)
* wip wrap moment

* add some props to moment

* fix typing for 3.8

* fix comment for props and add create method for moment-timezone
2023-10-23 13:24:11 +02:00
Elijah Ahianyo
06bdf9ed8a
Remove 0.3.0 deprecated features (#1947) 2023-10-19 09:44:32 -07:00
Masen Furer
67606561d3
[REF-668] Wrap MyApp with radix Theme component (#1867)
* 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.
2023-10-16 15:31:50 -07:00
Elijah Ahianyo
c6abeb31a5
Props as Literals (#1921) 2023-10-15 20:16:39 -07:00
Masen Furer
024cb5fa9b
Var field cleanup (#1943) 2023-10-13 14:53:55 -07:00
Nikhil Rao
7019708638
Fix custom components special props (#1956) 2023-10-12 15:27:41 -07:00
Alek Petuskey
06103a4d8d
Namespace Recharts + Victory Back With Depreciation Warning (#1928) 2023-10-08 19:09:09 -07:00
Elijah Ahianyo
513835cf74
Update Deprecations (#1927) 2023-10-05 12:12:42 -07:00
Thomas Brandého
dcb17103bb
code cleanup (split constants into a folder) (#1866) 2023-09-28 17:27:20 -07:00
Nikhil Rao
8231993e5a
Improvements to custom styles in rx.markdown (#1852) 2023-09-25 15:59:48 -07:00
Masen Furer
2f284a08b6
component: imports override _get_dependencies_imports (#1859) 2023-09-24 01:46:35 -07:00
Thomas Brandého
211dc15995
New API to define triggers (#1820) 2023-09-21 09:47:22 -07:00
Nikhil Rao
ac8dfc5f91
Format component as React string (#1848) 2023-09-20 19:30:38 -07:00
Thomas Brandého
15ced6b795
allow for non-installable imports (#1843) 2023-09-20 16:47:27 -07:00
Thomas Brandého
27eeab485e
move dynamic imports to dedicated method (#1785) 2023-09-08 14:53:39 -07:00
Alek Petuskey
fed75ea7f8
Incrementally Add New Packages (#1607) 2023-08-31 14:20:44 -07:00
Masen Furer
2392c52928
Implement on_mount and on_unmount for all components. (#1636) 2023-08-30 09:50:39 -07:00
Elijah Ahianyo
217a5806ee
Validate component children (#1647) 2023-08-23 15:56:27 -07:00
Martin Xu
fd4a6257c3
Remove unused full_control related code (#1624)
* remove full_control related code

* remove more unused code
2023-08-18 12:56:33 -07:00
Masen Furer
2eefb5d26c
Fix non-default imports for NoSSRComponent (#1548) 2023-08-15 17:32:23 -07:00
Nikhil Rao
6d15326abf
Support f-strings in component children and non-style props (#1575) 2023-08-14 11:33:16 -07:00
Alek Petuskey
9f7a7a1e4a
Got rid of mod_import (#1547) 2023-08-08 17:20:09 -07:00
Masen Furer
e214aa26aa
NoSSRComponent recognizes is_default (#1533) 2023-08-07 11:50:37 -07:00
Alek Petuskey
b9536bcf40
Fix Nextjs Dynamic Import (#1480)
* Fix dunamic imoprt for react player and plotly

* Fix format

* Fix pr comments

* Update react player

---------

Co-authored-by: Alek Petuskey <alekpetuskey@aleks-mbp.lan>
2023-07-31 16:02:14 -07:00
Masen Furer
333e2b3184
component: do not create ref for dynamic id (#1307)
allow dynamic id (BaseVar) to be specified (from state value or foreach), but
do not create a react reference for it, since that must be known at compile
time.

if a react ref is needed, then specify a string _at compile time_, not from
state.

fix #1302
2023-07-06 06:16:13 -07:00
Nikhil Rao
139ce38df1
Rename pynecone to reflex (#1236) 2023-06-25 16:56:55 -07:00