Skip to content

Commit cd840f1

Browse files
committed
fixed component / container relationship; added checkbox comp.
1 parent 95259f0 commit cd840f1

File tree

7 files changed

+40
-30
lines changed

7 files changed

+40
-30
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from dataclasses import dataclass, field
2+
3+
from dashipy.lib import Component
4+
5+
6+
@dataclass(frozen=True)
7+
class Checkbox(Component):
8+
value: bool | None = None
9+
label: str = ""

dashipy/dashipy/components/dropdown.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55

66
@dataclass(frozen=True)
77
class Dropdown(Component):
8-
label: str | None = None
98
options: list[tuple[str, str | int | float]] = field(default_factory=list)

dashipy/dashipy/contribs/panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
class Panel(Contribution):
77
"""Panel contribution"""
8-
def __init__(self, name: str, title: str):
8+
def __init__(self, name: str, title: str | None = None):
99
super().__init__(name, title=title)

dashipy/dashipy/lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
from .callback import Input
33
from .callback import Output
44
from .component import Component
5-
from .component import Container
5+
from .container import Container
66
from .extension import Contribution
77
from .extension import Extension

dashipy/dashipy/lib/component.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66
@dataclass(frozen=True)
77
class Component(ABC):
8-
id: str = None
9-
name: str = None
10-
value: str | int | float = None
11-
style: dict[str, Any] = None
8+
# Common HTML properties
9+
id: str | None = None
10+
name: str | None = None
11+
value: bool | int | float | str | None = None
12+
style: dict[str, Any] | None = None
13+
# We may add more here later
14+
#
15+
# Special non-HTML properties
16+
label: str | None = None
17+
children: list["Component"] | None = None
1218

1319
@property
1420
def type(self):
@@ -21,25 +27,14 @@ def to_dict(self) -> dict[str, Any]:
2127
attr_name: attr_value
2228
for attr_name, attr_value in self.__dict__.items()
2329
if attr_value is not None
24-
and not attr_name.startswith("_")
2530
and attr_name
31+
and attr_name != "children"
32+
and not attr_name.startswith("_")
2633
}
2734
)
28-
return d
29-
30-
31-
@dataclass(frozen=True)
32-
class Container(Component, ABC):
33-
children: list[Component] = field(default_factory=list)
34-
35-
def add(self, component: Component):
36-
self.children.append(component)
37-
38-
def to_dict(self) -> dict[str, Any]:
39-
d = super().to_dict()
40-
# Note we use "components" instead of "children" in order
41-
# to avoid later problems with React component's "children"
42-
# property
43-
d.pop("children")
44-
d.update(components=list(c.to_dict() for c in self.children))
35+
if self.children is not None:
36+
# Note we use "components" instead of "children" in order
37+
# to avoid later problems with React component's "children"
38+
# property
39+
d.update(components=list(c.to_dict() for c in self.children))
4540
return d

dashipy/dashipy/lib/container.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from abc import ABC
2+
from dataclasses import dataclass, field
3+
4+
from .component import Component
5+
6+
7+
@dataclass(frozen=True)
8+
class Container(Component, ABC):
9+
children: list[Component] = field(default_factory=list)
10+
11+
def add(self, component: Component):
12+
self.children.append(component)

dashipy/tests/lib/container_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import inspect
21
import unittest
32
from dataclasses import dataclass
4-
from typing import Any
5-
6-
import pytest
73

84
from dashipy.lib import Component, Container
9-
from dashipy.lib.callback import Input, Callback
105

116

127
@dataclass(frozen=True)

0 commit comments

Comments
 (0)