You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/migration.md
+94-3Lines changed: 94 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -343,7 +343,7 @@ To solve the above problems, you only need to implement a css() and cx() method.
343
343
344
344
## Guide
345
345
346
-
-Step1:Addnewthemeoptionsfor antd, eg:
346
+
-Step1:Addnewthemeoptionsfor antd, eg:
347
347
348
348
```csharp
349
349
services.AddAntDesign(option =>
@@ -355,7 +355,7 @@ To solve the above problems, you only need to implement a css() and cx() method.
355
355
});
356
356
```
357
357
358
-
- Step2: Gen style code from ts code.
358
+
- Step2: Gen style code from ts code.
359
359
```bash
360
360
# use cssincs cli tool
361
361
cssincs convert -c cssincs.json
@@ -370,8 +370,99 @@ To solve the above problems, you only need to implement a css() and cx() method.
370
370
├── compact.cs
371
371
├── token.cs
372
372
```
373
+
Each style's index file contains a default export method named `IndexDefault()`. The default naming rule is `filename + Default`, and you can modify the default generation rules by updating the configuration in cssincs.json.
374
+
```json
375
+
{
376
+
"DefaultExportMethodName": "{file}Default",
377
+
}
378
+
```
373
379
374
-
- Step3: Register style for each component
380
+
- Step3: Register style for each component.
381
+
When registering styles, it is generally done in the `OnInitialized` method. However, for antd, it should be done in the `SetClassMap` method because the isolated `HashId` needs to be injected into the `ClassMapper`.
375
382
```csharp
383
+
// Button.razor.cs
384
+
protectedvoidSetClassMap()
385
+
{
386
+
varprefixName="ant-btn";
387
+
// 注入index.cs中的IndexDefault()方法
388
+
varhashId=ButtonStyle.IndexDefault()(prefixName);
389
+
// Add hashId
390
+
ClassMapper
391
+
.Add(prefixName)
392
+
.Add(hashId)
393
+
}
394
+
```
376
395
396
+
- Step4: Merge tokens and render using CssInCSharp.
397
+
The ButtonStyle.IndexDefault method calls `GenStyleHooks`, which needs to be implemented in antd. This method is used to merge the theme tokens and invoke the style injection method from CssInCsharp.
Note: The theme options needs to be retrieved here. Since `IOptions` is injected clsss but the `GenStyleHooks` method is a static method, a static instance must be created to access it. eg:
0 commit comments