Skip to content

Commit

Permalink
feat!: Improve overall structure
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldedik committed Jun 25, 2024
1 parent 0d35a29 commit 5f643a2
Show file tree
Hide file tree
Showing 36 changed files with 353 additions and 368 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ cookiecutter gh:getludic/template
```python
from typing import override

from ludic import Attrs, Component
from ludic.html import a
from ludic.types import Attrs, Component

class LinkAttrs(Attrs):
to: str
Expand Down
3 changes: 2 additions & 1 deletion examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from ludic.attrs import NoAttrs
from ludic.catalog.layouts import Center, Stack
from ludic.catalog.pages import Body, Head, HtmlPage
from ludic.components import Component
from ludic.html import meta
from ludic.styles import set_default_theme, themes, types
from ludic.types import AnyChildren, Component
from ludic.types import AnyChildren

set_default_theme(themes.LightTheme(measure=types.Size(90, "ch")))

Expand Down
5 changes: 3 additions & 2 deletions examples/bulk_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from examples import Page, init_db

from ludic.attrs import Attrs
from ludic.catalog.buttons import ButtonPrimary
from ludic.catalog.forms import FieldMeta, Form
from ludic.catalog.headers import H1, H2
from ludic.catalog.layouts import Cluster
from ludic.catalog.quotes import Quote
from ludic.catalog.tables import ColumnMeta, Table, create_rows
from ludic.components import Inline
from ludic.html import span, style
from ludic.types import Attrs
from ludic.web import Endpoint, LudicApp
from ludic.web.parsers import ListParser

Expand All @@ -31,7 +32,7 @@ class PeopleAttrs(Attrs):
people: list[PersonAttrs]


class Toast(span):
class Toast(Inline):
id: str = "toast"
target: str = f"#{id}"
styles = style.use(
Expand Down
2 changes: 1 addition & 1 deletion examples/click_to_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from examples import Page, init_db

from ludic.attrs import Attrs
from ludic.catalog.buttons import Button, ButtonDanger, ButtonPrimary
from ludic.catalog.forms import FieldMeta, Form, create_fields
from ludic.catalog.headers import H1, H2
from ludic.catalog.items import Pairs
from ludic.catalog.layouts import Box, Cluster, Stack
from ludic.catalog.quotes import Quote
from ludic.types import Attrs
from ludic.web import Endpoint, LudicApp
from ludic.web.exceptions import NotFoundError
from ludic.web.parsers import Parser, ValidationError
Expand Down
5 changes: 4 additions & 1 deletion examples/click_to_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

from examples import Page

from ludic.attrs import Attrs
from ludic.catalog.buttons import ButtonPrimary
from ludic.catalog.headers import H1, H2
from ludic.catalog.quotes import Quote
from ludic.catalog.tables import Table, TableHead, TableRow
from ludic.components import Component, ComponentStrict
from ludic.elements import Blank
from ludic.html import td
from ludic.types import Attrs, Blank, Component, ComponentStrict, URLType
from ludic.types import URLType
from ludic.web import Endpoint, LudicApp
from ludic.web.datastructures import QueryParams

Expand Down
4 changes: 3 additions & 1 deletion examples/infinite_scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from examples import Page

from ludic.attrs import Attrs
from ludic.catalog.headers import H1, H2
from ludic.catalog.quotes import Quote
from ludic.catalog.tables import Table, TableHead, TableRow
from ludic.types import Attrs, Blank, Component
from ludic.components import Component
from ludic.elements import Blank
from ludic.web import Endpoint, LudicApp
from ludic.web.datastructures import QueryParams

Expand Down
14 changes: 14 additions & 0 deletions ludic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from ludic.attrs import Attrs, GlobalAttrs, NoAttrs
from ludic.components import Block, Component, ComponentStrict, Inline
from ludic.elements import Blank

__all__ = (
"Attrs",
"GlobalAttrs",
"NoAttrs",
"Block",
"Component",
"ComponentStrict",
"Inline",
"Blank",
)
31 changes: 27 additions & 4 deletions ludic/attrs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Annotated, Literal, Protocol
from typing import Annotated, Literal, Protocol, TypedDict

from .base import Attrs as Attrs
from .base import NoAttrs as NoAttrs
from .styles import CSSProperties
from .styles.types import CSSProperties


class URLType(Protocol):
Expand All @@ -15,6 +13,31 @@ class Alias(str):
"""Alias type for attributes."""


class Attrs(TypedDict, total=False):
"""Attributes of an element or component.
Example usage::
class PersonAttrs(Attributes):
name: str
age: NotRequired[int]
class Person(Component[PersonAttrs]):
@override
def render(self) -> dl:
return dl(
dt("Name"),
dd(self.attrs["name"]),
dt("Age"),
dd(self.attrs.get("age", "N/A")),
)
"""


class NoAttrs(TypedDict):
"""Placeholder for element with no attributes."""


class HtmlAttrs(Attrs, total=False):
"""Common attributes for HTML elements."""

Expand Down
Loading

0 comments on commit 5f643a2

Please sign in to comment.