Skip to content

Commit 22309af

Browse files
committed
Add: Draft of RulesVariants
1 parent 7692b78 commit 22309af

File tree

1 file changed

+70
-3
lines changed

1 file changed

+70
-3
lines changed

text/002-css-rules.md

+70-3
Original file line numberDiff line numberDiff line change
@@ -815,26 +815,93 @@ const myRule = rules([baseRule, { color: "blue", marginTop: "10px" }]);
815815

816816
## 9. rulesVarints
817817

818-
Inspired by the [PandaCSS's `defineSlotRecipe()`](https://panda-css.com/docs/concepts/slot-recipes#config-slot-recipe).
818+
Inspired by the [PandaCSS's `defineSlotRecipe()`](https://panda-css.com/docs/concepts/slot-recipes#config-slot-recipe).
819+
And at the same time, We refer to [Vanilla Extract's `styleVariants`](https://vanilla-extract.style/documentation/api/style-variants/) for code style for now. It could be change to [sub functions](https://github.com/mincho-js/mincho/issues/59).
819820

820821
This is a combination of `rules()` and `cssVariants()`.
821822

822823
**Code:**
823824

824825
```typescript
826+
const theme = rulesVariants({
827+
title: {
828+
fontWeight: "bold",
829+
830+
variants: {
831+
color: {
832+
main: { color: "#0078e5" },
833+
sub: { color: "#fff7ed" }
834+
},
835+
size: {
836+
main: { fontSize: "24px" },
837+
sub: { fontSize: "18px" }
838+
}
839+
}
840+
},
841+
body: {
842+
fontSize: "16px",
843+
844+
variants: {
845+
style: {
846+
banner: {
847+
padding: "5px 10px",
848+
border: "1px solid #ccc",
849+
borderRadius: "10px"
850+
},
851+
contents: { padding: "10px 15px", height: "60%", overflow: "auto" }
852+
}
853+
},
825854

855+
toggles: {
856+
accent: { textDecoration: "underline" }
857+
}
858+
}
859+
});
826860
```
827861

862+
It helps that we write many `rules` in once
863+
828864
**Compiled:**
829865

830866
```css
831-
867+
.[FILE_NAME]_title__[HASH] {
868+
font-weight: "bold";
869+
}
870+
.[FILE_NAME]_title_size_main__[HASH] {
871+
font-size: "24px";
872+
}
873+
.[FILE_NAME]_title_size_sub__[HASH] {
874+
font-size: "18px";
875+
}
876+
.[FILE_NAME]_body__[HASH] {
877+
font-size: "16px";
878+
}
879+
.[FILE_NAME]_body_style_banner__[HASH] {
880+
padding: "5px 10px";
881+
border: "1px solid #ccc";
882+
border-radius: "10px";
883+
}
884+
.[FILE_NAME]_body_style_contents__[HASH] {
885+
padding: "10px 15px";
886+
height: "60%";
887+
overflow: "auto";
888+
}
889+
.[FILE_NAME]_body_toggle_accent__[HASH] {
890+
text-decoration: "underline";
891+
}
832892
```
833893

834894
**Usage:**
835895

836896
```typescript
837-
897+
// case 1
898+
theme.title({
899+
size: "main"
900+
});
901+
// case 2
902+
theme.body("accent", {
903+
style: "banner"
904+
});
838905
```
839906

840907
## 10. With `css()`

0 commit comments

Comments
 (0)