CSS Modules
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 332
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của reactive-python/reactpy
-
Outdated GIF in Docs Đang mởpriority-3-low type-docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
reactive-python/reactpy#1034 ·
-
priority-2-moderate type-revision
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
reactive-python/reactpy#1319 ·
-
priority-1-high
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
reactive-python/reactpy#1277 ·
-
priority-3-low
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
reactive-python/reactpy#1273 · 1 reaction ·
-
priority-2-moderate
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
reactive-python/reactpy#1272 · 2 reaction ·
Tất cả issue của reactive-python/reactpy
Issue tương tự
-
from:qa priority:P2 reliability tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
spec-kitty/spec-kitty#4874 ·
-
fix: inaccuracy ⚠️
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
uabrc/uabrc.github.io#1255 · 1 bình luận ·
-
kind:bug needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
docs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ethereum-optimism/factory#64 ·