ZeroIntensity / view.py

The Batteries-Detachable Web Framework
https://view.zintensity.dev
MIT License
206 stars 15 forks source link

Better Component Styling #99

Open ZeroIntensity opened 7 months ago

ZeroIntensity commented 7 months ago

Improvement Description

Styling right now consists of manually writing style() tags or loading CSS files. I think there could be a better way that this is done. I have a number of ideas on how this could be done, all of which could be implemented.

Improvement Request Example API

Dataclass-like API

from view import body, Style

class MyStyle(Style, cls="my_class"):
    font_family = ["sans-serif"]

body(style=MyStyle)
body(cls="my_class")

CSS Loading API

from view import body, css

body(style=css("index.css"))

Object API

from view import styled, body

my_class = styled(font_family=["sans-serif"])
body(style=styled(font_family=["sans-serif"]))
body(cls=my_class)  # perhaps some magic could be done to make it accessible via cls="my_class" (not a variable reference)

Anything else?

Waiting on #12, of course.