Skip to content

Commit 2ab9c35

Browse files
ENG-7843: update web dep. warnings + fix alert block (ENG-7845) (#1647)
* update web dep. warnings + fix alert block * Update docs/library/forms/input.md Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update docs/library/graphing/general/axis.md Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update docs/state_structure/component_state.md Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update docs/state_structure/component_state.md Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update docs/recipes/others/chips.md Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * add bg to MD blocks --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent c561407 commit 2ab9c35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+496
-229
lines changed

blog/2023-09-28-unlocking-new-workflows-with-background-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ screen updating and processing simultaneously.
122122

123123
```python eval
124124
rx.center(
125-
rx.video(url="https://user-images.githubusercontent.com/1524005/271007407-09c832ff-ecbd-4a9d-a8a5-67779c673045.mov"),
125+
rx.video(src="https://user-images.githubusercontent.com/1524005/271007407-09c832ff-ecbd-4a9d-a8a5-67779c673045.mov"),
126126
rx.box(height="3em"),
127127
width="100%",
128128
padding_y="2em"

blog/2023-10-25-implementing-sign-in-with-google.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ and sign in with the Google account that should manage the app and credential to
4646

4747
```python eval
4848
rx.center(
49-
rx.video(url="https://github.com/reflex-dev/reflex-examples/assets/1524005/af2499a6-0bda-4d60-b52b-4f51b7322fd5"),
49+
rx.video(src="https://github.com/reflex-dev/reflex-examples/assets/1524005/af2499a6-0bda-4d60-b52b-4f51b7322fd5"),
5050
rx.box(height="3em"),
5151
width="100%",
5252
padding_y="2em"
@@ -492,7 +492,7 @@ app.add_page(index)
492492

493493
```python eval
494494
rx.center(
495-
rx.video(url="https://github.com/reflex-dev/reflex-examples/assets/1524005/b0c7145b-6c19-4072-bc9d-ae8927c8988f"),
495+
rx.video(src="https://github.com/reflex-dev/reflex-examples/assets/1524005/b0c7145b-6c19-4072-bc9d-ae8927c8988f"),
496496
rx.box(height="3em"),
497497
width="100%",
498498
padding_y="2em"

docs/api-reference/event_triggers.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ SYNTHETIC_EVENTS = [
4343
"state": """class ChangeState(rx.State):
4444
checked: bool = False
4545
46+
@rx.event
47+
def set_checked(self):
48+
self.checked = not self.checked
49+
4650
""",
4751
"example": """rx.switch(on_change=ChangeState.set_checked)""",
4852
},
@@ -102,7 +106,7 @@ SYNTHETIC_EVENTS = [
102106
@rx.event
103107
def on_mount(self):
104108
self.events = self.events[-4:] + ["on_mount @ " + str(datetime.now())]
105-
109+
106110
@rx.event
107111
async def load_data(self):
108112
# Common pattern: Set loading state, yield to update UI, then fetch data
@@ -141,7 +145,7 @@ SYNTHETIC_EVENTS = [
141145
self.events = self.events[-4:] + ["on_unmount @ " + str(datetime.now())]
142146
# Common pattern: Clean up resources when component is removed
143147
self.status = f"Resource {self.resource_id} cleaned up"
144-
148+
145149
@rx.event
146150
def initialize_resource(self):
147151
self.status = f"Resource {self.resource_id} initialized"

docs/client_storage/overview.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ class ClientStorageState(rx.State):
2424
my_local_storage: str = rx.LocalStorage("")
2525
custom_cookie: str = rx.Cookie(name="CustomNamedCookie", max_age=3600)
2626

27+
@rx.event
28+
def set_my_cookie(self, value: str):
29+
self.my_cookie = value
30+
31+
@rx.event
32+
def set_my_local_storage(self, value: str):
33+
self.my_local_storage = value
34+
35+
@rx.event
36+
def set_custom_cookie(self, value: str):
37+
self.custom_cookie = value
2738

2839
def client_storage_example():
2940
return rx.vstack(

docs/components/conditional_rendering.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ You can also set props conditionally using `rx.cond`. In this example, we set th
5353
class PropCondState(rx.State):
5454

5555
value: int
56-
56+
5757
@rx.event
5858
def set_end(self, value: list[int | float]):
5959
self.value = value[0]
@@ -95,6 +95,10 @@ class MatchState(rx.State):
9595
"corgi",
9696
]
9797

98+
@rx.event
99+
def set_cat_breed(self, breed: str):
100+
self.cat_breed = breed
101+
98102

99103
def match_demo():
100104
return rx.flex(

docs/enterprise/drag-and-drop.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import reflex_enterprise as rxe
2929
class BasicDndState(rx.State):
3030
drop_count: int = 0
3131

32+
def increment_drop_count(self):
33+
self.drop_count += 1
34+
35+
3236
@rx.memo
3337
def draggable_card():
3438
return rxe.dnd.draggable(
@@ -64,7 +68,7 @@ def basic_drag_drop():
6468
font_weight="bold"
6569
),
6670
accept=["BasicCard"],
67-
on_drop=BasicDndState.setvar("drop_count", BasicDndState.drop_count + 1),
71+
on_drop=BasicDndState.increment_drop_count,
6872
),
6973
spacing="4",
7074
align="start"
@@ -84,6 +88,10 @@ import reflex_enterprise as rxe
8488
class MultiPositionState(rx.State):
8589
card_position: int = 0
8690

91+
def set_card_position(self, position: int):
92+
self.card_position = position
93+
94+
8795
@rx.memo
8896
def movable_card():
8997
return rxe.dnd.draggable(
@@ -118,7 +126,7 @@ def drop_zone(position: int):
118126
border_color=rx.cond(params.is_over, "green.500", "red.500"),
119127
bg=rx.cond(params.is_over, "green.100", "blue.100"),
120128
accept=["MovableCard"],
121-
on_drop=MultiPositionState.setvar("card_position", position),
129+
on_drop=lambda _: MultiPositionState.set_card_position(position),
122130
display="flex",
123131
align_items="center",
124132
justify_content="center"
@@ -129,7 +137,7 @@ def multi_position_example():
129137
rx.text("Drag the card between positions", weight="bold"),
130138
rx.grid(
131139
drop_zone(0),
132-
drop_zone(1),
140+
drop_zone(1),
133141
drop_zone(2),
134142
drop_zone(3),
135143
columns="2",
@@ -152,7 +160,10 @@ import reflex_enterprise as rxe
152160
class StateTrackingState(rx.State):
153161
drag_info: str = "No drag activity"
154162

155-
@rx.memo
163+
def set_drag_info(self, value: str):
164+
self.drag_info = value
165+
166+
@rx.memo
156167
def tracked_draggable():
157168
drag_params = rxe.dnd.Draggable.collected_params
158169
return rxe.dnd.draggable(
@@ -165,7 +176,7 @@ def tracked_draggable():
165176
opacity=rx.cond(drag_params.is_dragging, 0.5, 1.0)
166177
),
167178
type="TrackedItem",
168-
on_end=StateTrackingState.setvar("drag_info", "Drag ended")
179+
on_end=StateTrackingState.set_drag_info("Drag ended")
169180
)
170181

171182
def tracked_drop_target():
@@ -184,8 +195,8 @@ def tracked_drop_target():
184195
justify_content="center"
185196
),
186197
accept=["TrackedItem"],
187-
on_drop=StateTrackingState.setvar("drag_info", "Item successfully dropped!"),
188-
on_hover=StateTrackingState.setvar("drag_info", "Item hovering over drop zone")
198+
on_drop=StateTrackingState.set_drag_info("Item successfully dropped!"),
199+
on_hover=StateTrackingState.set_drag_info("Item hovering over drop zone")
189200
)
190201

191202
def state_tracking_example():
@@ -227,34 +238,34 @@ class DynamicListState(rx.State):
227238
def move_item(self, item_data: dict, target_list: str):
228239
item_id = item_data.get("id")
229240
source_list = item_data.get("list_id")
230-
241+
231242
if not item_id or not source_list:
232243
return
233-
244+
234245
# Find the item in the source list
235246
source_items = getattr(self, f"list_{source_list.lower()}")
236247
item_to_move = None
237248
for item in source_items:
238249
if item.id == item_id:
239250
item_to_move = item
240251
break
241-
252+
242253
if not item_to_move:
243254
return
244-
255+
245256
# Remove from source list only
246257
if source_list == "A":
247258
self.list_a = [item for item in self.list_a if item.id != item_id]
248259
else:
249260
self.list_b = [item for item in self.list_b if item.id != item_id]
250-
261+
251262
# Create new item for target list
252263
new_item = ListItem(
253264
id=item_id,
254265
text=item_to_move.text,
255266
list_id=target_list
256267
)
257-
268+
258269
# Add to target list
259270
if target_list == "A":
260271
self.list_a.append(new_item)
@@ -421,6 +432,9 @@ import reflex_enterprise as rxe
421432
class SimpleState(rx.State):
422433
message: str = "No items dropped yet"
423434

435+
def set_message_from_item(self, item: dict):
436+
self.message = f"Dropped: {item['name']}"
437+
424438
def simple_draggable():
425439
return rxe.dnd.draggable(
426440
rx.box(
@@ -444,7 +458,7 @@ def simple_drop_target():
444458
min_height="100px"
445459
),
446460
accept=["simple"],
447-
on_drop=lambda item: SimpleState.setvar("message", f"Dropped: {item['name']}")
461+
on_drop=SimpleState.set_message_from_item
448462
)
449463

450464
def item_data_example():
@@ -467,6 +481,12 @@ class CollectState(rx.State):
467481
drag_info: str = "No drag activity"
468482
drop_info: str = "No drop activity"
469483

484+
def handle_drop(self, item: dict):
485+
self.drop_info = f"Dropped: {item.get('name', 'Unknown')}"
486+
return rx.toast(f"Successfully dropped {item.get('name', 'item')}")
487+
488+
489+
470490
def collect_draggable():
471491
params = rxe.dnd.Draggable.collected_params
472492
return rxe.dnd.draggable(
@@ -516,10 +536,7 @@ def collect_drop_target():
516536
min_height="120px"
517537
),
518538
accept=["collect_item"],
519-
on_drop=lambda item: [
520-
CollectState.setvar("drop_info", f"Dropped: {item.get('name', 'Unknown')}"),
521-
rx.toast(f"Successfully dropped {item.get('name', 'item')}")
522-
]
539+
on_drop=CollectState.handle_drop,
523540
)
524541

525542
def custom_collect_example():

docs/enterprise/mantine/json-input.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import reflex as rx
1313
import reflex_enterprise as rxe
1414

1515
class JsonInputState(rx.State):
16-
json_data: str = ''
16+
json_data: str = ""
17+
18+
def set_json_data(self, value: str):
19+
self.json_data = value
20+
1721

1822
def json_input_example():
1923
return rxe.mantine.json_input(
@@ -25,7 +29,7 @@ def json_input_example():
2529
required=True,
2630
size="md",
2731
format_on_blur=True,
28-
on_change=lambda value: JsonInputState.setvar("json_data", value),
32+
on_change=JsonInputState.set_json_data,
2933
width="300px",
3034
)
3135
```

docs/enterprise/mantine/multi-select.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import reflex_enterprise as rxe
1313
class MultiSelectState(rx.State):
1414
selected_fruits: list = []
1515

16+
def set_selected_fruits(self, value: list):
17+
self.selected_fruits = value
18+
1619

1720
def multi_select_example():
1821
return rx.vstack(
@@ -21,7 +24,8 @@ def multi_select_example():
2124
placeholder="Pick all that you like",
2225
data=["Apple", "Banana", "Cherry", "Date", "Elderberry"],
2326
value=MultiSelectState.selected_fruits,
24-
on_change=lambda value: MultiSelectState.setvar("selected_fruits", value),
27+
on_change=MultiSelectState.set_selected_fruits,
2528
)
2629
)
30+
2731
```

0 commit comments

Comments
 (0)