fix editable column and theme casting (#2051)
This commit is contained in:
parent
edf9c32142
commit
3262f29613
@ -19,6 +19,7 @@ export function locateCell(row, column) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function formatCell(value, column) {
|
export function formatCell(value, column) {
|
||||||
|
const editable = column.editable || true
|
||||||
switch (column.type) {
|
switch (column.type) {
|
||||||
case "int":
|
case "int":
|
||||||
case "float":
|
case "float":
|
||||||
@ -26,8 +27,8 @@ export function formatCell(value, column) {
|
|||||||
kind: GridCellKind.Number,
|
kind: GridCellKind.Number,
|
||||||
data: value,
|
data: value,
|
||||||
displayData: value + "",
|
displayData: value + "",
|
||||||
readonly: false,
|
readonly: !editable,
|
||||||
allowOverlay: false
|
allowOverlay: editable,
|
||||||
}
|
}
|
||||||
case "datetime":
|
case "datetime":
|
||||||
// value = moment format?
|
// value = moment format?
|
||||||
@ -36,15 +37,14 @@ export function formatCell(value, column) {
|
|||||||
kind: GridCellKind.Text,
|
kind: GridCellKind.Text,
|
||||||
data: value,
|
data: value,
|
||||||
displayData: value,
|
displayData: value,
|
||||||
readonly: false,
|
readonly: !editable,
|
||||||
allowOverlay: true
|
allowOverlay: editable,
|
||||||
}
|
}
|
||||||
case "bool":
|
case "bool":
|
||||||
return {
|
return {
|
||||||
kind: GridCellKind.Boolean,
|
kind: GridCellKind.Boolean,
|
||||||
data: value,
|
data: value,
|
||||||
readonly: false,
|
readonly: !editable,
|
||||||
// allowOverlay: true
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return {
|
return {
|
||||||
|
@ -33,6 +33,7 @@ code_block = CodeBlock.create
|
|||||||
connection_banner = ConnectionBanner.create
|
connection_banner = ConnectionBanner.create
|
||||||
connection_modal = ConnectionModal.create
|
connection_modal = ConnectionModal.create
|
||||||
data_editor = DataEditor.create
|
data_editor = DataEditor.create
|
||||||
|
data_editor_theme = DataEditorTheme
|
||||||
data_table = DataTable.create
|
data_table = DataTable.create
|
||||||
divider = Divider.create
|
divider = Divider.create
|
||||||
list = List.create
|
list = List.create
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from .badge import Badge
|
from .badge import Badge
|
||||||
from .code import Code, CodeBlock
|
from .code import Code, CodeBlock
|
||||||
from .dataeditor import DataEditor
|
from .dataeditor import DataEditor, DataEditorTheme
|
||||||
from .datatable import DataTable
|
from .datatable import DataTable
|
||||||
from .divider import Divider
|
from .divider import Divider
|
||||||
from .keyboard_key import KeyboardKey
|
from .keyboard_key import KeyboardKey
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Callable, Dict, List, Optional
|
from typing import Any, Callable, Dict, List, Optional, Union
|
||||||
|
|
||||||
from reflex.base import Base
|
from reflex.base import Base
|
||||||
from reflex.components.component import Component, NoSSRComponent
|
from reflex.components.component import Component, NoSSRComponent
|
||||||
@ -68,38 +68,38 @@ class GridColumnIcons(Enum):
|
|||||||
class DataEditorTheme(Base):
|
class DataEditorTheme(Base):
|
||||||
"""The theme for the DataEditor component."""
|
"""The theme for the DataEditor component."""
|
||||||
|
|
||||||
accentColor: Optional[str] = None
|
accent_color: Optional[str] = None
|
||||||
accentFg: Optional[str] = None
|
accent_fg: Optional[str] = None
|
||||||
accentLight: Optional[str] = None
|
accent_light: Optional[str] = None
|
||||||
baseFontStyle: Optional[str] = None
|
base_font_style: Optional[str] = None
|
||||||
bgBubble: Optional[str] = None
|
bg_bubble: Optional[str] = None
|
||||||
bgBubbleSelected: Optional[str] = None
|
bg_bubble_selected: Optional[str] = None
|
||||||
bgCell: Optional[str] = None
|
bg_cell: Optional[str] = None
|
||||||
bgCellMedium: Optional[str] = None
|
bg_cell_medium: Optional[str] = None
|
||||||
bgHeader: Optional[str] = None
|
bg_header: Optional[str] = None
|
||||||
bgHeaderHasFocus: Optional[str] = None
|
bg_header_has_focus: Optional[str] = None
|
||||||
bgHeaderHovered: Optional[str] = None
|
bg_header_hovered: Optional[str] = None
|
||||||
bgIconHeader: Optional[str] = None
|
bg_icon_header: Optional[str] = None
|
||||||
bgSearchResult: Optional[str] = None
|
bg_search_result: Optional[str] = None
|
||||||
borderColor: Optional[str] = None
|
border_color: Optional[str] = None
|
||||||
cellHorizontalPadding: Optional[int] = None
|
cell_horizontal_padding: Optional[int] = None
|
||||||
cellVerticalPadding: Optional[int] = None
|
cell_vertical_padding: Optional[int] = None
|
||||||
drilldownBorder: Optional[str] = None
|
drilldown_border: Optional[str] = None
|
||||||
editorFontSize: Optional[str] = None
|
editor_font_size: Optional[str] = None
|
||||||
fgIconHeader: Optional[str] = None
|
fg_icon_header: Optional[str] = None
|
||||||
fontFamily: Optional[str] = None
|
font_family: Optional[str] = None
|
||||||
headerBottomBorderColor: Optional[str] = None
|
header_bottom_border_color: Optional[str] = None
|
||||||
headerFontStyle: Optional[str] = None
|
header_font_style: Optional[str] = None
|
||||||
horizontalBorderColor: Optional[str] = None
|
horizontal_border_color: Optional[str] = None
|
||||||
lineHeight: Optional[int] = None
|
line_height: Optional[int] = None
|
||||||
linkColor: Optional[str] = None
|
link_color: Optional[str] = None
|
||||||
textBubble: Optional[str] = None
|
text_bubble: Optional[str] = None
|
||||||
textDark: Optional[str] = None
|
text_dark: Optional[str] = None
|
||||||
textGroupHeader: Optional[str] = None
|
text_group_header: Optional[str] = None
|
||||||
textHeader: Optional[str] = None
|
text_header: Optional[str] = None
|
||||||
textHeaderSelected: Optional[str] = None
|
text_header_selected: Optional[str] = None
|
||||||
textLight: Optional[str] = None
|
text_light: Optional[str] = None
|
||||||
textMedium: Optional[str] = None
|
text_medium: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class DataEditor(NoSSRComponent):
|
class DataEditor(NoSSRComponent):
|
||||||
@ -198,7 +198,7 @@ class DataEditor(NoSSRComponent):
|
|||||||
scroll_offset_y: Var[int]
|
scroll_offset_y: Var[int]
|
||||||
|
|
||||||
# global theme
|
# global theme
|
||||||
theme: Var[DataEditorTheme]
|
theme: Var[Union[DataEditorTheme, Dict]]
|
||||||
|
|
||||||
def _get_imports(self):
|
def _get_imports(self):
|
||||||
return imports.merge_imports(
|
return imports.merge_imports(
|
||||||
@ -317,6 +317,11 @@ class DataEditor(NoSSRComponent):
|
|||||||
format.format_data_editor_column(col) for col in columns
|
format.format_data_editor_column(col) for col in columns
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if "theme" in props:
|
||||||
|
theme = props.get("theme")
|
||||||
|
if isinstance(theme, Dict):
|
||||||
|
props["theme"] = DataEditorTheme(**theme)
|
||||||
|
|
||||||
# Allow by default to select a region of cells in the grid.
|
# Allow by default to select a region of cells in the grid.
|
||||||
props.setdefault("getCellForSelection", True)
|
props.setdefault("getCellForSelection", True)
|
||||||
|
|
||||||
@ -405,4 +410,6 @@ def serialize_dataeditortheme(theme: DataEditorTheme):
|
|||||||
Returns:
|
Returns:
|
||||||
The serialized theme.
|
The serialized theme.
|
||||||
"""
|
"""
|
||||||
return format.json_dumps({k: v for k, v in theme.__dict__.items() if v is not None})
|
return format.json_dumps(
|
||||||
|
{format.to_camel_case(k): v for k, v in theme.__dict__.items() if v is not None}
|
||||||
|
)
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
# This file was generated by `scripts/pyi_generator.py`!
|
# This file was generated by `scripts/pyi_generator.py`!
|
||||||
# ------------------------------------------------------
|
# ------------------------------------------------------
|
||||||
|
|
||||||
from typing import Any, Dict, Optional, overload, Literal, Union, List
|
from typing import Dict, Union, Literal, overload, List, Any, Optional
|
||||||
from reflex.vars import Var, BaseVar, ComputedVar
|
from reflex.vars import Var, BaseVar, ComputedVar
|
||||||
from reflex.event import EventChain, EventHandler, EventSpec
|
from reflex.event import EventChain, EventHandler, EventSpec
|
||||||
from reflex.style import Style
|
from reflex.style import Style
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Callable, Dict, List, Optional
|
from typing import Any, Callable, Dict, List, Optional, Union
|
||||||
from reflex.base import Base
|
from reflex.base import Base
|
||||||
from reflex.components.component import Component, NoSSRComponent
|
from reflex.components.component import Component, NoSSRComponent
|
||||||
from reflex.components.literals import LiteralRowMarker
|
from reflex.components.literals import LiteralRowMarker
|
||||||
@ -19,38 +19,38 @@ from reflex.vars import ImportVar, Var, get_unique_variable_name
|
|||||||
class GridColumnIcons(Enum): ...
|
class GridColumnIcons(Enum): ...
|
||||||
|
|
||||||
class DataEditorTheme(Base):
|
class DataEditorTheme(Base):
|
||||||
accentColor: Optional[str]
|
accent_color: Optional[str]
|
||||||
accentFg: Optional[str]
|
accent_fg: Optional[str]
|
||||||
accentLight: Optional[str]
|
accent_light: Optional[str]
|
||||||
baseFontStyle: Optional[str]
|
base_font_style: Optional[str]
|
||||||
bgBubble: Optional[str]
|
bg_bubble: Optional[str]
|
||||||
bgBubbleSelected: Optional[str]
|
bg_bubble_selected: Optional[str]
|
||||||
bgCell: Optional[str]
|
bg_cell: Optional[str]
|
||||||
bgCellMedium: Optional[str]
|
bg_cell_medium: Optional[str]
|
||||||
bgHeader: Optional[str]
|
bg_header: Optional[str]
|
||||||
bgHeaderHasFocus: Optional[str]
|
bg_header_has_focus: Optional[str]
|
||||||
bgHeaderHovered: Optional[str]
|
bg_header_hovered: Optional[str]
|
||||||
bgIconHeader: Optional[str]
|
bg_icon_header: Optional[str]
|
||||||
bgSearchResult: Optional[str]
|
bg_search_result: Optional[str]
|
||||||
borderColor: Optional[str]
|
border_color: Optional[str]
|
||||||
cellHorizontalPadding: Optional[int]
|
cell_horizontal_padding: Optional[int]
|
||||||
cellVerticalPadding: Optional[int]
|
cell_vertical_padding: Optional[int]
|
||||||
drilldownBorder: Optional[str]
|
drilldown_border: Optional[str]
|
||||||
editorFontSize: Optional[str]
|
editor_font_size: Optional[str]
|
||||||
fgIconHeader: Optional[str]
|
fg_icon_header: Optional[str]
|
||||||
fontFamily: Optional[str]
|
font_family: Optional[str]
|
||||||
headerBottomBorderColor: Optional[str]
|
header_bottom_border_color: Optional[str]
|
||||||
headerFontStyle: Optional[str]
|
header_font_style: Optional[str]
|
||||||
horizontalBorderColor: Optional[str]
|
horizontal_border_color: Optional[str]
|
||||||
lineHeight: Optional[int]
|
line_height: Optional[int]
|
||||||
linkColor: Optional[str]
|
link_color: Optional[str]
|
||||||
textBubble: Optional[str]
|
text_bubble: Optional[str]
|
||||||
textDark: Optional[str]
|
text_dark: Optional[str]
|
||||||
textGroupHeader: Optional[str]
|
text_group_header: Optional[str]
|
||||||
textHeader: Optional[str]
|
text_header: Optional[str]
|
||||||
textHeaderSelected: Optional[str]
|
text_header_selected: Optional[str]
|
||||||
textLight: Optional[str]
|
text_light: Optional[str]
|
||||||
textMedium: Optional[str]
|
text_medium: Optional[str]
|
||||||
|
|
||||||
class DataEditor(NoSSRComponent):
|
class DataEditor(NoSSRComponent):
|
||||||
def get_event_triggers(self) -> Dict[str, Callable]: ...
|
def get_event_triggers(self) -> Dict[str, Callable]: ...
|
||||||
@ -94,7 +94,9 @@ class DataEditor(NoSSRComponent):
|
|||||||
overscroll_y: Optional[Union[Var[int], int]] = None,
|
overscroll_y: Optional[Union[Var[int], int]] = None,
|
||||||
scroll_offset_x: Optional[Union[Var[int], int]] = None,
|
scroll_offset_x: Optional[Union[Var[int], int]] = None,
|
||||||
scroll_offset_y: Optional[Union[Var[int], int]] = None,
|
scroll_offset_y: Optional[Union[Var[int], int]] = None,
|
||||||
theme: Optional[Union[Var[DataEditorTheme], DataEditorTheme]] = None,
|
theme: Optional[
|
||||||
|
Union[Var[Union[DataEditorTheme, Dict]], Union[DataEditorTheme, Dict]]
|
||||||
|
] = None,
|
||||||
style: Optional[Style] = None,
|
style: Optional[Style] = None,
|
||||||
key: Optional[Any] = None,
|
key: Optional[Any] = None,
|
||||||
id: Optional[Any] = None,
|
id: Optional[Any] = None,
|
||||||
|
Loading…
Reference in New Issue
Block a user