Skip to content

Commit

Permalink
Add editors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kuethe committed Sep 24, 2024
1 parent e826953 commit 6398735
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/examples/getting_started/shiny_express_all_new_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pytabulator import TableOptions, Tabulator, TabulatorContext, render_tabulator
from pytabulator.utils import create_columns
from pytabulator.formatters import ProgressFormatter, TickCrossFormatter
from pytabulator.editors import ListEditor
from shiny import reactive, render
from shiny.express import input, ui

Expand Down Expand Up @@ -83,6 +84,7 @@ def tabulator():
.set_options(editTriggerEvent="dblclick")
.set_column_formatter("Fare", ProgressFormatter(), hoz_align="left")
.set_column_formatter("Survived", TickCrossFormatter(), hoz_align="center")
.set_column_editor("Sex", ListEditor())
)


Expand Down
65 changes: 63 additions & 2 deletions pytabulator/editors.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from pydantic import BaseModel

from typing import Optional
from typing import Optional, Literal

from ._utils import as_camel_dict_recursive
from enum import Enum


class Editors(Enum):
NUMBER = "number"
INPUT = "input"
TEXTAREA = "textarea"
NUMBER = "number"
RANGE = "range"
TICK_CROSS = "tickCross"
STAR = "star"
PROGRESS = "progress"
LIST = "list"


class Editor(BaseModel):
Expand All @@ -22,21 +26,69 @@ def to_dict(self) -> dict:
return as_camel_dict_recursive(self.model_dump(exclude_none=True))


class InputEditor(Editor):
search: Optional[bool] = None
mask: Optional[str] = None
select_contents: Optional[bool] = None
element_attributes: Optional[dict] = None

@property
def name(self) -> str:
return Editors.INPUT.value


class TextareaEditor(Editor):
mask: Optional[str] = None
select_contents: Optional[bool] = None
vertical_navigation: Literal["hybrid", "editor", "table"] = None
shift_enter_submit: Optional[bool] = None

@property
def name(self) -> str:
return Editors.TEXTAREA.value


class NumberEditor(Editor):
min: Optional[float] = None
max: Optional[float] = None
step: Optional[float] = None
element_attributes: Optional[dict] = None
mask: Optional[str] = None
select_contents: Optional[bool] = None
vertical_navigation: Literal["editor", "table"] = None

@property
def name(self) -> str:
return Editors.NUMBER.value


class RangeEditor(Editor):
min: Optional[float] = None
max: Optional[float] = None
step: Optional[float] = None
element_attributes: Optional[dict] = None

@property
def name(self) -> str:
return Editors.RANGE.value


class TickCrossEditor(Editor):
true_value: Optional[str] = None
false_value: Optional[str] = None
element_attributes: Optional[dict] = None

@property
def name(self) -> str:
return Editors.TICK_CROSS.value


class StarEditor(Editor):
@property
def name(self) -> str:
return Editors.STAR.value


class ProgressEditor(Editor):
min: Optional[float] = None
max: Optional[float] = None
Expand All @@ -45,3 +97,12 @@ class ProgressEditor(Editor):
@property
def name(self) -> str:
return Editors.PROGRESS.value


class ListEditor(Editor):
values: Optional[list] = None
values_lookup: Optional[bool] = True

@property
def name(self) -> str:
return Editors.LIST.value

0 comments on commit 6398735

Please sign in to comment.