Skip to content

Commit 818243b

Browse files
committed
update docs
1 parent eee4370 commit 818243b

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

README.md

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dotnet add package CssInCSharp
1313
```
1414

1515
## Usage
16-
- Used in native style tag
16+
- Used within a native `<style>` tag.
1717
```csharp
1818
<div class="basic">
1919
<div class="title">Title</div>
@@ -58,7 +58,7 @@ dotnet add package CssInCSharp
5858
}
5959
```
6060

61-
- Use StyleContent Or Style Component
61+
- Use the `StyleContent` and `Style` components on the page.
6262
```csharp
6363
<div class="div1">
6464
Style In Head
@@ -106,7 +106,41 @@ dotnet add package CssInCSharp
106106
}
107107
```
108108

109-
- Register style
109+
- Use StyleHelper to inject styles in custom components.
110+
```csharp
111+
<div class="@_token.HashId @Name">
112+
@foreach (var item in Items)
113+
{
114+
<div class="item">@item</div>
115+
}
116+
</div>
117+
118+
@code {
119+
[Parameter]
120+
public string[] Items { get; set; }
121+
122+
[Parameter]
123+
public int Width { get; set; } = 500;
124+
125+
protected override void OnInitialized()
126+
{
127+
// use style helper to register style
128+
StyleHelper.Register(new StyleInfo
129+
{
130+
HashId = _token.HashId,
131+
Path = new string[]{ "component", "demo" },
132+
StyleFn = UseStyle
133+
});
134+
}
135+
136+
private CSSInterpolation UseStyle()
137+
{
138+
...
139+
}
140+
}
141+
```
142+
143+
- Inject a `CSSObject` or `CSSString` into the head.
110144
```csharp
111145
@_node
112146

@@ -116,19 +150,6 @@ dotnet add package CssInCSharp
116150

117151
protected override void OnInitialized()
118152
{
119-
var token = new
120-
{
121-
ColorBgLayout = "#ddd",
122-
BorderRadiusLG = "8px",
123-
BoxShadow = "5px #DEDEDE",
124-
Padding = 20,
125-
BorderRadius = 4,
126-
ColorTextTertiary = "#000",
127-
ColorBgContainer = "#EFEFEF",
128-
MotionEaseInBack = "",
129-
ColorTextSecondary = "",
130-
BoxShadowSecondary = ""
131-
};
132153
var styles = new
133154
{
134155
container = new CSSObject
@@ -163,15 +184,15 @@ dotnet add package CssInCSharp
163184
}
164185
""""),
165186
};
166-
187+
// The CX and CSS methods are defined in the StyleHelper class.
188+
// @using static CssInCSharp.StyleHelper
167189
_node = @<div class="@CX("a-simple-create-style-demo-classname", styles.container)">
168190
<div class="@styles.card">createStyles Demo</div>
169191
<div>Current theme mode: dark</div>
170192
</div>;
171193
}
172194
}
173195
```
174-
175196
For other examples, you can check out the example code. For more information, please refer to the [document](./docs/index.md).
176197

177198
## Css Compiler

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ The style output:
667667
```
668668

669669
## Custom Component Style
670-
On a page, you can use the `<StyleContent>` component to add styles, but you can't use StyleContent in custom component, so if you need to add a style to the head in the custom component, you need to use the `Register` method in the `StyleHelper` class to register the style.
670+
On a page, you can use the `<StyleContent>` component to add page-specific styles. However, StyleContent cannot be used inside custom components. For example, if you create a `<DemoComponent>` component, how can you inject its styles into the `<head>` tag? CssInCsharp provides a global helper class called `StyleHelper`. You can use the `Register` method to inject styles into the `<head>` tag.
671671

672672
DemoComponent.razor
673673
```csharp

0 commit comments

Comments
 (0)