reflex-components-gridjs 0.9.0a1__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.
@@ -0,0 +1,5 @@
1
+ """Grid components."""
2
+
3
+ from .datatable import DataTable
4
+
5
+ data_table = DataTable.create
@@ -0,0 +1,128 @@
1
+ """Table components."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Sequence
6
+ from typing import Any
7
+
8
+ from reflex_base.components.component import NoSSRComponent, field
9
+ from reflex_base.components.tags import Tag
10
+ from reflex_base.utils import types
11
+ from reflex_base.utils.imports import ImportDict
12
+ from reflex_base.utils.serializers import serialize
13
+ from reflex_base.vars.base import LiteralVar, Var, is_computed_var
14
+
15
+
16
+ class Gridjs(NoSSRComponent):
17
+ """A component that wraps a nivo bar component."""
18
+
19
+ library = "gridjs-react@6.1.1"
20
+
21
+ lib_dependencies: list[str] = ["gridjs@6.2.0"]
22
+
23
+
24
+ class DataTable(Gridjs):
25
+ """A data table component."""
26
+
27
+ tag = "Grid"
28
+
29
+ alias = "DataTableGrid"
30
+
31
+ data: Any = field(
32
+ doc="The data to display. Either a list of lists or a pandas dataframe."
33
+ )
34
+
35
+ columns: Var[Sequence] = field(
36
+ doc="The list of columns to display. Required if data is a list and should not be provided if the data field is a dataframe"
37
+ )
38
+
39
+ search: Var[bool] = field(doc="Enable a search bar.")
40
+
41
+ sort: Var[bool] = field(doc="Enable sorting on columns.")
42
+
43
+ resizable: Var[bool] = field(doc="Enable resizable columns.")
44
+
45
+ pagination: Var[bool | dict] = field(doc="Enable pagination.")
46
+
47
+ @classmethod
48
+ def create(cls, *children, **props):
49
+ """Create a datatable component.
50
+
51
+ Args:
52
+ *children: The children of the component.
53
+ **props: The props to pass to the component.
54
+
55
+ Returns:
56
+ The datatable component.
57
+
58
+ Raises:
59
+ ValueError: If a pandas dataframe is passed in and columns are also provided.
60
+ """
61
+ data = props.get("data")
62
+ columns = props.get("columns")
63
+
64
+ # The annotation should be provided if data is a computed var. We need this to know how to
65
+ # render pandas dataframes.
66
+ if is_computed_var(data) and data._var_type == Any:
67
+ msg = "Annotation of the computed var assigned to the data field should be provided."
68
+ raise ValueError(msg)
69
+
70
+ if (
71
+ columns is not None
72
+ and is_computed_var(columns)
73
+ and columns._var_type == Any
74
+ ):
75
+ msg = "Annotation of the computed var assigned to the column field should be provided."
76
+ raise ValueError(msg)
77
+
78
+ # If data is a pandas dataframe and columns are provided throw an error.
79
+ if (
80
+ types.is_dataframe(type(data))
81
+ or (isinstance(data, Var) and types.is_dataframe(data._var_type))
82
+ ) and columns is not None:
83
+ msg = "Cannot pass in both a pandas dataframe and columns to the data_table component."
84
+ raise ValueError(msg)
85
+
86
+ # If data is a list and columns are not provided, throw an error
87
+ if (
88
+ (isinstance(data, Var) and types.typehint_issubclass(data._var_type, list))
89
+ or isinstance(data, list)
90
+ ) and columns is None:
91
+ msg = "column field should be specified when the data field is a list type"
92
+ raise ValueError(msg)
93
+
94
+ # Create the component.
95
+ return super().create(
96
+ *children,
97
+ **props,
98
+ )
99
+
100
+ def add_imports(self) -> ImportDict:
101
+ """Add the imports for the datatable component.
102
+
103
+ Returns:
104
+ The import dict for the component.
105
+ """
106
+ return {"": "gridjs/dist/theme/mermaid.css"}
107
+
108
+ def _render(self) -> Tag:
109
+ if isinstance(self.data, Var) and types.is_dataframe(self.data._var_type):
110
+ self.columns = self.data._replace(
111
+ _js_expr=f"{self.data._js_expr}.columns",
112
+ _var_type=list[Any],
113
+ )
114
+ self.data = self.data._replace(
115
+ _js_expr=f"{self.data._js_expr}.data",
116
+ _var_type=list[list[Any]],
117
+ )
118
+ if types.is_dataframe(type(self.data)):
119
+ # If given a pandas df break up the data and columns
120
+ data = serialize(self.data)
121
+ if not isinstance(data, dict):
122
+ msg = "Serialized dataframe should be a dict."
123
+ raise ValueError(msg)
124
+ self.columns = LiteralVar.create(data["columns"])
125
+ self.data = LiteralVar.create(data["data"])
126
+
127
+ # Render the table.
128
+ return super()._render()
@@ -0,0 +1,110 @@
1
+ """Stub file for reflex_components_gridjs/datatable.py"""
2
+
3
+ # ------------------- DO NOT EDIT ----------------------
4
+ # This file was generated by `reflex/utils/pyi_generator.py`!
5
+ # ------------------------------------------------------
6
+ from collections.abc import Mapping, Sequence
7
+ from typing import Any
8
+
9
+ from reflex_base.components.component import NoSSRComponent
10
+ from reflex_base.event import EventType, PointerEventInfo
11
+ from reflex_base.utils.imports import ImportDict
12
+ from reflex_base.vars.base import Var
13
+ from reflex_components_core.core.breakpoints import Breakpoints
14
+
15
+ class Gridjs(NoSSRComponent):
16
+ @classmethod
17
+ def create(
18
+ cls,
19
+ *children,
20
+ style: Sequence[Mapping[str, Any]]
21
+ | Mapping[str, Any]
22
+ | Var[Mapping[str, Any]]
23
+ | Breakpoints
24
+ | None = None,
25
+ key: Any | None = None,
26
+ id: Any | None = None,
27
+ ref: Var | None = None,
28
+ class_name: Any | None = None,
29
+ custom_attrs: dict[str, Var | Any] | None = None,
30
+ on_blur: EventType[()] | None = None,
31
+ on_click: EventType[()] | EventType[PointerEventInfo] | None = None,
32
+ on_context_menu: EventType[()] | EventType[PointerEventInfo] | None = None,
33
+ on_double_click: EventType[()] | EventType[PointerEventInfo] | None = None,
34
+ on_focus: EventType[()] | None = None,
35
+ on_mount: EventType[()] | None = None,
36
+ on_mouse_down: EventType[()] | None = None,
37
+ on_mouse_enter: EventType[()] | None = None,
38
+ on_mouse_leave: EventType[()] | None = None,
39
+ on_mouse_move: EventType[()] | None = None,
40
+ on_mouse_out: EventType[()] | None = None,
41
+ on_mouse_over: EventType[()] | None = None,
42
+ on_mouse_up: EventType[()] | None = None,
43
+ on_scroll: EventType[()] | None = None,
44
+ on_scroll_end: EventType[()] | None = None,
45
+ on_unmount: EventType[()] | None = None,
46
+ **props,
47
+ ) -> Gridjs:
48
+ """Create the component.
49
+
50
+ Args:
51
+ *children: The children of the component.
52
+ **props: The props of the component.
53
+
54
+ Returns:
55
+ The component.
56
+ """
57
+
58
+ class DataTable(Gridjs):
59
+ @classmethod
60
+ def create(
61
+ cls,
62
+ *children,
63
+ data: Any | None = None,
64
+ columns: Sequence | Var[Sequence] | None = None,
65
+ search: Var[bool] | bool | None = None,
66
+ sort: Var[bool] | bool | None = None,
67
+ resizable: Var[bool] | bool | None = None,
68
+ pagination: Var[bool | dict] | bool | dict | None = None,
69
+ style: Sequence[Mapping[str, Any]]
70
+ | Mapping[str, Any]
71
+ | Var[Mapping[str, Any]]
72
+ | Breakpoints
73
+ | None = None,
74
+ key: Any | None = None,
75
+ id: Any | None = None,
76
+ ref: Var | None = None,
77
+ class_name: Any | None = None,
78
+ custom_attrs: dict[str, Var | Any] | None = None,
79
+ on_blur: EventType[()] | None = None,
80
+ on_click: EventType[()] | EventType[PointerEventInfo] | None = None,
81
+ on_context_menu: EventType[()] | EventType[PointerEventInfo] | None = None,
82
+ on_double_click: EventType[()] | EventType[PointerEventInfo] | None = None,
83
+ on_focus: EventType[()] | None = None,
84
+ on_mount: EventType[()] | None = None,
85
+ on_mouse_down: EventType[()] | None = None,
86
+ on_mouse_enter: EventType[()] | None = None,
87
+ on_mouse_leave: EventType[()] | None = None,
88
+ on_mouse_move: EventType[()] | None = None,
89
+ on_mouse_out: EventType[()] | None = None,
90
+ on_mouse_over: EventType[()] | None = None,
91
+ on_mouse_up: EventType[()] | None = None,
92
+ on_scroll: EventType[()] | None = None,
93
+ on_scroll_end: EventType[()] | None = None,
94
+ on_unmount: EventType[()] | None = None,
95
+ **props,
96
+ ) -> DataTable:
97
+ """Create a datatable component.
98
+
99
+ Args:
100
+ *children: The children of the component.
101
+ **props: The props to pass to the component.
102
+
103
+ Returns:
104
+ The datatable component.
105
+
106
+ Raises:
107
+ ValueError: If a pandas dataframe is passed in and columns are also provided.
108
+ """
109
+
110
+ def add_imports(self) -> ImportDict: ...
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: reflex-components-gridjs
3
+ Version: 0.9.0a1
4
+ Summary: Reflex gridjs components.
5
+ Author-email: Khaleel Al-Adhami <khaleel@reflex.dev>
6
+ Maintainer-email: Khaleel Al-Adhami <khaleel@reflex.dev>
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+
10
+ # reflex-components-gridjs
11
+
12
+ Reflex gridjs components.
@@ -0,0 +1,6 @@
1
+ reflex_components_gridjs/__init__.py,sha256=xJwDm1AZ70L5-t9LLqZwGUtDpijbf1KuMYDT-j8g3pM,88
2
+ reflex_components_gridjs/datatable.py,sha256=nknZkPuR5ZFN8IdxohTFXtcWNJum73jJPkzEzhAK1cQ,4337
3
+ reflex_components_gridjs/datatable.pyi,sha256=1Lj_S0n6x5km7tuQF1anGpnB_MfFGU1P-O_dV7Wpz-U,4176
4
+ reflex_components_gridjs-0.9.0a1.dist-info/METADATA,sha256=8wsjT900j1PGeGDun0ZJK3ngyaTaPR3Z3Gn36_X4sVY,334
5
+ reflex_components_gridjs-0.9.0a1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
6
+ reflex_components_gridjs-0.9.0a1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any