appkit-ui 0.12.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
appkit_ui/__init__.py ADDED
File without changes
@@ -0,0 +1,17 @@
1
+ from __future__ import annotations
2
+
3
+ from appkit_ui.components.collabsible import collabsible
4
+ from appkit_ui.components.editor import (
5
+ EditorButtonList,
6
+ EditorOptions,
7
+ EventHandler,
8
+ editor,
9
+ )
10
+
11
+ __all__ = [
12
+ "EditorButtonList",
13
+ "EditorOptions",
14
+ "EventHandler",
15
+ "collabsible",
16
+ "editor",
17
+ ]
@@ -0,0 +1,84 @@
1
+ from collections.abc import Callable
2
+
3
+ import reflex as rx
4
+
5
+
6
+ def collabsible(
7
+ *children: rx.Component,
8
+ title: str,
9
+ info_text: str = "",
10
+ show_condition: bool = True,
11
+ expanded: bool = False,
12
+ on_toggle: Callable | None = None,
13
+ **props,
14
+ ) -> rx.Component:
15
+ """
16
+ Erstellt eine Collapsible Komponente mit beliebig vielen Child-Komponenten
17
+
18
+ Args:
19
+ *children: Beliebige Anzahl von Reflex Komponenten als positionale Argumente
20
+ title: Titel der Collapsible Sektion
21
+ info_text: Info-Text rechts neben dem Titel
22
+ show_condition: Bedingung, wann die Komponente angezeigt wird
23
+ expanded: Zustand, ob die Komponente erweitert ist
24
+ on_toggle: Event handler für das Umschalten
25
+ **props: Zusätzliche Props für das Container-Element
26
+ """
27
+ return rx.vstack(
28
+ # Collapsible header - klickbarer Bereich
29
+ rx.vstack(
30
+ rx.hstack(
31
+ rx.icon(
32
+ rx.cond(
33
+ expanded,
34
+ "chevron-down",
35
+ "chevron-right",
36
+ ),
37
+ size=16,
38
+ ),
39
+ rx.text(
40
+ title,
41
+ size="1",
42
+ font_weight="medium",
43
+ color=rx.color("gray", 11),
44
+ flex_grow="1",
45
+ ),
46
+ rx.text(
47
+ info_text,
48
+ size="1",
49
+ color=rx.color("gray", 9),
50
+ text_align="right",
51
+ width="40%",
52
+ ),
53
+ spacing="2",
54
+ align="start",
55
+ width="100%",
56
+ ),
57
+ on_click=on_toggle,
58
+ padding="8px",
59
+ width="100%",
60
+ _hover={"background_color": rx.color("gray", 2)},
61
+ ),
62
+ # Expandierbarer Inhalt - alle Children werden in einem vstack angeordnet
63
+ rx.cond(
64
+ expanded,
65
+ *children, # Alle übergebenen Komponenten werden hier eingefügt
66
+ ),
67
+ # Container Styling
68
+ spacing="3",
69
+ width="calc(90% + 18px)",
70
+ background_color=rx.color("gray", 1),
71
+ border=f"1px solid {rx.color('gray', 6)}",
72
+ border_radius="8px",
73
+ # Animationen
74
+ opacity=rx.cond(show_condition, "1", "0"),
75
+ transform=rx.cond(show_condition, "translateY(0)", "translateY(-20px)"),
76
+ height=rx.cond(show_condition, "auto", "0"),
77
+ max_height=rx.cond(show_condition, "500px", "0"),
78
+ padding=rx.cond(show_condition, "3px", "0"),
79
+ margin_top=rx.cond(show_condition, "16px", "-16px"),
80
+ overflow="hidden",
81
+ pointer_events=rx.cond(show_condition, "auto", "none"),
82
+ # transition="all 1s ease-out",
83
+ **props,
84
+ )
@@ -0,0 +1,123 @@
1
+ import reflex as rx
2
+
3
+
4
+ def delete_dialog(
5
+ title: str,
6
+ content: str,
7
+ on_click: rx.EventHandler,
8
+ icon_button: bool = False,
9
+ class_name: str = "dialog",
10
+ **kwargs,
11
+ ) -> rx.Component:
12
+ """Generic delete confirmation dialog.
13
+
14
+ Args:
15
+ title: Dialog title
16
+ content: The name/identifier of the item to delete
17
+ on_click: Event handler for delete action
18
+ icon_button: If True, use icon_button instead of button for trigger
19
+ **kwargs: Additional props for the trigger button
20
+ """
21
+ # Create the appropriate trigger based on icon_button parameter
22
+ if icon_button:
23
+ trigger = rx.icon_button(rx.icon("trash-2", size=19), **kwargs)
24
+ else:
25
+ trigger = rx.button(rx.icon("trash-2", size=16), **kwargs)
26
+
27
+ return rx.alert_dialog.root(
28
+ rx.alert_dialog.trigger(trigger),
29
+ rx.alert_dialog.content(
30
+ rx.alert_dialog.title(title),
31
+ rx.alert_dialog.description(
32
+ rx.text(
33
+ "Bist du sicher, dass du ",
34
+ rx.text.strong(content),
35
+ " löschen möchtest? ",
36
+ "Diese Aktion wird das ausgewählte Element und alle zugehörigen ",
37
+ "Daten dauerhaft löschen. Dieser Vorgang kann nicht rückgängig ",
38
+ "gemacht werden!",
39
+ ),
40
+ class_name="mb-4",
41
+ ),
42
+ rx.flex(
43
+ rx.alert_dialog.cancel(
44
+ rx.button(
45
+ "Abbrechen",
46
+ class_name=(
47
+ "bg-gray-100 dark:bg-neutral-700 text-gray-700 "
48
+ "dark:text-neutral-300 hover:bg-gray-200 "
49
+ "dark:hover:bg-neutral-600 px-4 py-2 rounded"
50
+ ),
51
+ ),
52
+ ),
53
+ rx.alert_dialog.action(
54
+ rx.button(
55
+ "Löschen",
56
+ class_name=(
57
+ "bg-red-500 text-white hover:bg-red-600 px-4 py-2 rounded"
58
+ ),
59
+ on_click=on_click,
60
+ )
61
+ ),
62
+ class_name="justify-end gap-3",
63
+ ),
64
+ class_name=class_name,
65
+ ),
66
+ )
67
+
68
+
69
+ def dialog_header(icon: str, title: str, description: str) -> rx.Component:
70
+ """Reusable dialog header component."""
71
+ return rx.hstack(
72
+ rx.badge(
73
+ rx.icon(tag=icon, size=34),
74
+ color_scheme="grass",
75
+ radius="full",
76
+ padding="0.65rem",
77
+ ),
78
+ rx.vstack(
79
+ rx.dialog.title(
80
+ title,
81
+ weight="bold",
82
+ margin="0",
83
+ ),
84
+ rx.dialog.description(description),
85
+ spacing="1",
86
+ height="100%",
87
+ align_items="start",
88
+ ),
89
+ height="100%",
90
+ spacing="4",
91
+ margin_bottom="1.5em",
92
+ align_items="center",
93
+ width="100%",
94
+ )
95
+
96
+
97
+ def dialog_buttons(
98
+ submit_text: str, spacing: str = "3", has_errors: bool = False
99
+ ) -> rx.Component:
100
+ """Reusable dialog action buttons."""
101
+ return rx.flex(
102
+ rx.dialog.close(
103
+ rx.button(
104
+ "Abbrechen",
105
+ class_name=(
106
+ "bg-gray-100 dark:bg-neutral-700 text-gray-700 "
107
+ "dark:text-neutral-300 hover:bg-gray-200 "
108
+ "dark:hover:bg-neutral-600 px-4 py-2 rounded"
109
+ ),
110
+ ),
111
+ ),
112
+ rx.form.submit(
113
+ rx.dialog.close(
114
+ rx.button(
115
+ submit_text,
116
+ class_name="px-4 py-2 rounded",
117
+ disabled=has_errors,
118
+ ),
119
+ ),
120
+ as_child=True,
121
+ ),
122
+ class_name=f"pt-8 gap-{spacing} mt-4 justify-end",
123
+ )
@@ -0,0 +1,274 @@
1
+ """A Rich Text Editor based on SunEditor."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import enum
6
+ from typing import Literal
7
+
8
+ from pydantic import BaseModel
9
+ from reflex.components.component import Component, NoSSRComponent
10
+ from reflex.event import EventHandler, no_args_event_spec, passthrough_event_spec
11
+ from reflex.utils.format import to_camel_case
12
+ from reflex.utils.imports import ImportDict, ImportVar
13
+ from reflex.vars.base import Var
14
+
15
+
16
+ class EditorButtonList(list, enum.Enum):
17
+ """List enum that provides three predefined button lists."""
18
+
19
+ BASIC = [
20
+ ["font", "fontSize"],
21
+ ["fontColor"],
22
+ ["horizontalRule"],
23
+ ["link", "image"],
24
+ ]
25
+ FORMATTING = [
26
+ ["undo", "redo"],
27
+ ["bold", "underline", "italic", "strike", "subscript", "superscript"],
28
+ ["removeFormat"],
29
+ ["outdent", "indent"],
30
+ ["fullScreen", "showBlocks", "codeView"],
31
+ ["preview", "print"],
32
+ ]
33
+ COMPLEX = [
34
+ ["undo", "redo"],
35
+ ["font", "fontSize", "formatBlock"],
36
+ ["bold", "underline", "italic", "strike", "subscript", "superscript"],
37
+ ["removeFormat"],
38
+ "/",
39
+ ["fontColor", "hiliteColor"],
40
+ ["outdent", "indent"],
41
+ ["align", "horizontalRule", "list", "table"],
42
+ ["link", "image", "video"],
43
+ ["fullScreen", "showBlocks", "codeView"],
44
+ ["preview", "print"],
45
+ ["save", "template"],
46
+ ]
47
+
48
+
49
+ class EditorOptions(BaseModel):
50
+ """Some of the additional options to configure the Editor.
51
+
52
+ Complete list of options found here:
53
+ https://github.com/JiHong88/SunEditor/blob/master/README.md#options.
54
+ """
55
+
56
+ # Specifies default tag name of the editor.
57
+ # default: 'p' {String}
58
+ default_tag: str | None = None
59
+
60
+ # The mode of the editor ('classic', 'inline', 'balloon', 'balloon-always').
61
+ # default: 'classic' {String}
62
+ mode: str | None = None
63
+
64
+ # If true, the editor is set to RTL(Right To Left) mode.
65
+ # default: false {Boolean}
66
+ rtl: bool | None = None
67
+
68
+ # List of buttons to use in the toolbar.
69
+ button_list: list[list[str] | str] | None
70
+
71
+
72
+ def on_blur_spec(_e: Var, content: Var[str]) -> tuple[Var[str]]:
73
+ """A helper function to specify the on_blur event handler.
74
+
75
+ Args:
76
+ _e: The event.
77
+ content: The content of the editor.
78
+
79
+ Returns:
80
+ A tuple containing the content of the editor.
81
+ """
82
+ return (content,)
83
+
84
+
85
+ def on_paste_spec(
86
+ _e: Var, clean_data: Var[str], max_char_count: Var[bool]
87
+ ) -> tuple[Var[str], Var[bool]]:
88
+ """A helper function to specify the on_paste event handler.
89
+
90
+ Args:
91
+ _e: The event.
92
+ clean_data: The clean data.
93
+ max_char_count: The maximum character count.
94
+
95
+ Returns:
96
+ A tuple containing the clean data and the maximum character count.
97
+ """
98
+ return (clean_data, max_char_count)
99
+
100
+
101
+ class Editor(NoSSRComponent):
102
+ """A Rich Text Editor component based on SunEditor.
103
+
104
+ Not every JS prop is listed here (some are not easily usable from python),
105
+ refer to the library docs for a complete list.
106
+ """
107
+
108
+ library = "suneditor-react@3.6.1"
109
+
110
+ tag = "SunEditor"
111
+
112
+ is_default = True
113
+
114
+ lib_dependencies: list[str] = ["suneditor"]
115
+
116
+ # Language of the editor.
117
+ # Alternatively to a string, a dict of your language can be passed to this prop.
118
+ # Please refer to the library docs for this.
119
+ # options: "en" | "da" | "de" | "es" | "fr" | "ja" | "ko" | "pt_br" |
120
+ # "ru" | "zh_cn" | "ro" | "pl" | "ckb" | "lv" | "se" | "ua" | "he" | "it"
121
+ # default: "en".
122
+ lang: Var[
123
+ Literal[
124
+ "en",
125
+ "da",
126
+ "de",
127
+ "es",
128
+ "fr",
129
+ "ja",
130
+ "ko",
131
+ "pt_br",
132
+ "ru",
133
+ "zh_cn",
134
+ "ro",
135
+ "pl",
136
+ "ckb",
137
+ "lv",
138
+ "se",
139
+ "ua",
140
+ "he",
141
+ "it",
142
+ ]
143
+ | dict
144
+ ]
145
+
146
+ # This is used to set the HTML form name of the editor.
147
+ # This means on HTML form submission,
148
+ # it will be submitted together with contents of the editor by the name provided.
149
+ name: Var[str]
150
+
151
+ # Sets the default value of the editor.
152
+ # This is useful if you don't want the on_change method to be called on render.
153
+ # If you want the on_change method to be called on render use the set_contents prop
154
+ default_value: Var[str]
155
+
156
+ # Sets the width of the editor.
157
+ # px and percentage values are accepted, eg width="100%" or width="500px"
158
+ # default: 100%
159
+ width: Var[str]
160
+
161
+ # Sets the height of the editor.
162
+ # px and percentage values are accepted, eg height="100%" or height="100px"
163
+ height: Var[str]
164
+
165
+ # Sets the placeholder of the editor.
166
+ placeholder: Var[str]
167
+
168
+ # Should the editor receive focus when initialized?
169
+ auto_focus: Var[bool]
170
+
171
+ # Pass an EditorOptions instance to modify the behaviour of Editor even more.
172
+ set_options: Var[dict]
173
+
174
+ # Whether all SunEditor plugins should be loaded.
175
+ # default: True.
176
+ set_all_plugins: Var[bool]
177
+
178
+ # Set the content of the editor.
179
+ # Note: To set the initial contents of the editor
180
+ # without calling the on_change event,
181
+ # please use the default_value prop.
182
+ # set_contents is used to set the contents of the editor programmatically.
183
+ # You must be aware that, when the set_contents's prop changes,
184
+ # the on_change event is triggered.
185
+ set_contents: Var[str]
186
+
187
+ # Append editor content
188
+ append_contents: Var[str]
189
+
190
+ # Sets the default style of the editor's edit area
191
+ set_default_style: Var[str]
192
+
193
+ # Disable the editor
194
+ # default: False.
195
+ disable: Var[bool]
196
+
197
+ # Hide the editor
198
+ # default: False.
199
+ hide: Var[bool]
200
+
201
+ # Hide the editor toolbar
202
+ # default: False.
203
+ hide_toolbar: Var[bool]
204
+
205
+ # Disable the editor toolbar
206
+ # default: False.
207
+ disable_toolbar: Var[bool]
208
+
209
+ # Fired when the editor content changes.
210
+ on_change: EventHandler[passthrough_event_spec(str)]
211
+
212
+ # Fired when the something is inputted in the editor.
213
+ on_input: EventHandler[no_args_event_spec]
214
+
215
+ # Fired when the editor loses focus.
216
+ on_blur: EventHandler[on_blur_spec]
217
+
218
+ # Fired when the editor is loaded.
219
+ on_load: EventHandler[passthrough_event_spec(bool)]
220
+
221
+ # Fired when the editor content is copied.
222
+ on_copy: EventHandler[no_args_event_spec]
223
+
224
+ # Fired when the editor content is cut.
225
+ on_cut: EventHandler[no_args_event_spec]
226
+
227
+ # Fired when the editor content is pasted.
228
+ on_paste: EventHandler[on_paste_spec]
229
+
230
+ # Fired when the code view is toggled.
231
+ toggle_code_view: EventHandler[passthrough_event_spec(bool)]
232
+
233
+ # Fired when the full screen mode is toggled.
234
+ toggle_full_screen: EventHandler[passthrough_event_spec(bool)]
235
+
236
+ def add_imports(self) -> ImportDict:
237
+ """Add imports for the Editor component.
238
+
239
+ Returns:
240
+ The import dict.
241
+ """
242
+ return {
243
+ "": ImportVar(tag="suneditor/dist/css/suneditor.min.css", install=False)
244
+ }
245
+
246
+ @classmethod
247
+ def create(
248
+ cls, set_options: EditorOptions | None = None, **props: object
249
+ ) -> Component:
250
+ """Create an instance of Editor. No children allowed.
251
+
252
+ Args:
253
+ set_options: Configuration object to further configure the instance.
254
+ **props: Any properties to be passed to the Editor
255
+
256
+ Returns:
257
+ An Editor instance.
258
+
259
+ Raises:
260
+ ValueError: If set_options is a state Var.
261
+ """
262
+ if set_options is not None:
263
+ if isinstance(set_options, Var):
264
+ msg = "EditorOptions cannot be a state Var"
265
+ raise ValueError(msg)
266
+ props["set_options"] = {
267
+ to_camel_case(k): v
268
+ for k, v in set_options.dict().items()
269
+ if v is not None
270
+ }
271
+ return super().create(*[], **props)
272
+
273
+
274
+ editor = Editor.create