CSS Modules
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
研究方向
Start by reading the vdom_to_etree and etree_to_vdom utilities mentioned in the issue, then review the linked React CSS Modules examples and previous issue #671. Compare the proposed parser, selector, scoping, caching, and stylesheet-serving options. Done means an agreed interface and implementation plan exists; the issue currently leaves those design choices unresolved.
由索引模型根據 Issue 內容生成。
描述
Current Situation
Currently, there is no way to tie CSS to an individual component, such as React CSS Modules
Here's some samples on how this works in React
- https://css-tricks.com/different-ways-to-write-css-in-react/#aa-use-css-modules
- https://css-tricks.com/css-modules-part-1-need/
See previous issue #671
Proposed Actions
This should be possible by
- Parse a CSS file into selectors and style pairs such as
{'#my-selector': { ... } }. We can do this via... - Parsing the component's VDOM into an LXML node tree using our
vdom_to_etreeutil function - Determining where to apply styles via
cssslect - Convert the etree back into VDOM using
etree_to_vdom.
Note: With the interfaces below, we might want to implement a cache_handler = ... parameter to allow for customization on how we store stylesheet in cache.
Inline Style Interface
The user interface may look something like this
@component
@css_module("/path/to/stylesheet.css") # Allow for string paths or a file handle
def my_component( ... ):
return html.div({"className": "styles.my_selector"}, ... )
However, this kind of interface does not retain the same kind of dot notation that React CSS Modules support. If going with this implementation, we would be forced to apply all styling using in-line styles.
In-line styles are not necessarily an issue, but would severely increase size DOM in situations where one selector can apply to 100+ elements.
CSS Modules Imitation Interface
To more accurately imitate React, we might want to consider this interface instead.
styles = css_module("/path/to/stylesheet.css") # Allow for string paths or a file handle
@component
@styles # Makes the CSS module aware of how to uniquely scope class names (see `hash` below)
def my_component( ... ):
return html.div({"className": styles.my_selector }, ... )
The appended stylesheet will have its selectors converted to be unique {filename}_{classname}_{hash}, and all values referenced by the dot notation (eg styles.my_selector) will use these unique selectors. The hash value should be based on the component's dotted path.
In this example, the uniquely generated selector may look something like styles_my_selector_309571057.
What to do with the stylesheet?
Generally, React CSS modules are precompiled (webpack-esque) and stored in some output directory, then it is left up the the webserver to serve them.
Since we currently have no way of pre-compiling CSS modules, we have a few options
- Serve the file's contents as a string within a
html.styletag- This is the simplest solution, but would lead to duplicated style rules for each time the component is rendered on the page
- Force the user to display a component that renders all CSS modules in one stylesheet
- Would require creating a load/unload framework for CSS Modules
- Force the user to display a component that renders one CSS module in a stylesheet
- Gives the user more control over rending behavior
- Create a Python view that is effectively a primitive static file server
- This could prove useful for future JavaScript module capabilities
- Compile CSS on-the-fly into an output directory and have the user serve this files themselves
- Is less convenient than the methods above
- Would not have compatibility with whitenoise
- 主要語言
- Python
- 星號
- 8.1k
- 分支
- 332
- PR 合併指標
- 30 天內沒有已合併 PR
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
reactive-python/reactpy 的其他 Issue
-
priority-3-low type-docs
難度 2/5 1-3 小時 新手友好度 65/100
reactive-python/reactpy#1034 ·
-
priority-2-moderate type-revision
難度 5/5 一週以上 新手友好度 25/100
reactive-python/reactpy#1319 ·
-
priority-1-high
難度 5/5 一週以上 新手友好度 25/100
reactive-python/reactpy#1277 ·
-
priority-3-low
難度 5/5 一週以上 新手友好度 35/100
reactive-python/reactpy#1273 · 1 個 reaction ·
-
priority-2-moderate
難度 5/5 一週以上 新手友好度 30/100
reactive-python/reactpy#1272 · 2 個 reaction ·
查看 reactive-python/reactpy 的全部 Issue
相似的 Issue
-
🐛 Bug 🔔 Pending processing
難度 2/5 1-3 小時 新手友好度 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難度 2/5 1-3 小時 新手友好度 88/100
OpenHands/extensions#626 · 1 則留言 ·
-
難度 1/5 1 小時以內 新手友好度 90/100
CSCfi/sd-search-api#39 ·