Skip to content

Commit 5d8dd5d

Browse files
Jeong-jjblack7375
authored andcommitted
Add: Default Variants, Composition, RulesVariants
1 parent 736bf75 commit 5d8dd5d

File tree

2 files changed

+171
-11
lines changed

2 files changed

+171
-11
lines changed

text/000-css-literals.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,11 @@ const secondary = css([base, { background: "aqua" }]);
506506
padding: 12px;
507507
}
508508

509-
.[FILE_NAME]_base__[HASH] {
509+
.[FILE_NAME]_primary__[HASH] {
510510
background: blue;
511511
}
512512

513-
.[FILE_NAME]_base__[HASH] {
513+
.[FILE_NAME]_secondary__[HASH] {
514514
background: aqua;
515515
}
516516
```

text/002-css-rules.md

+169-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It will be partial coverage of [`@mixin` in SCSS](https://sass-lang.com/document
1111
- Dynamic styling
1212
- Take advantage of preprocessors
1313
- Variants that correspond to semantic hierarchies
14-
- Improve [Vaniila extract's recipes](https://vanilla-extract.style/documentation/packages/recipes/)
14+
- Improve [Vanilla Extract's recipes](https://vanilla-extract.style/documentation/packages/recipes/)
1515
- Make your BEM expressive
1616

1717
## Composition
@@ -81,7 +81,7 @@ const secondary = css([base, { background: "aqua" }]);
8181
It's clear that composition alone can't handle all dynamic cases.
8282
What about dynamic cases?
8383

84-
The solution is known as [`UI = f(state)`](https://docs.flutter.dev/data-and-backend/state-mgmt/declarative) and is It's simple.
84+
The solution is known as [`UI = f(state)`](https://docs.flutter.dev/data-and-backend/state-mgmt/declarative) and it's simple.
8585

8686
If so, is there any reason for Style to not be a function?
8787
This is the same as [fela's approach](https://fela.js.org/docs/latest/intro/principles).
@@ -185,7 +185,7 @@ It leaves the way out open, but we need to find a way to make it as declarative
185185

186186
[Variants](https://stitches.dev/docs/variants), made famous by [stitches](https://stitches.dev/), makes some control flows declarative.
187187

188-
Vanilla extract, which this project is based on, is called [recipe](https://vanilla-extract.style/documentation/packages/recipes/).
188+
The Vanilla extract, which this project is based on, is called [recipe](https://vanilla-extract.style/documentation/packages/recipes/).
189189

190190
```typescript
191191
const avatar = recipe({
@@ -714,10 +714,10 @@ const button = rules({
714714
});
715715
```
716716

717-
First method is original method in stitches's compound variants, and it is still good way for it.
717+
The first method is the original method in stitches's compound variants, and it is still a good way for it.
718718
So we keep it.
719719

720-
And second method we present will provide a more comfortable way to write the conditions.
720+
And the second method we present will provide a more comfortable way to write the conditions.
721721
This feature checks existing variants and provides automatic completion.
722722

723723
**Compiled:**
@@ -745,50 +745,210 @@ button({
745745

746746
## 7. Default Variants
747747

748+
The way of [Stitches's Default Variants](https://stitches.dev/docs/variants#default-variants) is already good to use, so we keep this method in ours.
749+
748750
**Code:**
749751

750752
```typescript
753+
const button = rules({
754+
// base styles
751755

756+
variants: {
757+
color: {
758+
brand: {
759+
color: "#FFFFA0",
760+
backgroundColor: "blueviolet"
761+
},
762+
accent: {
763+
color: "#FFE4B5",
764+
backgroundColor: "slateblue"
765+
}
766+
}
767+
},
768+
defaultVariants: {
769+
color: "brand"
770+
}
771+
});
752772
```
753773

754774
## 8. Composition
755775

756776
**Code:**
757777

778+
[Vanilla Extract's Composition](https://vanilla-extract.style/documentation/style-composition/) is enough to use already. So we maintain this basically.
779+
And It gonna inherit base rules like [Stitches's Composing Components](https://stitches.dev/docs/composing-components).
780+
758781
```typescript
759-
const baseRule = rules({});
782+
const baseRule = rules({
783+
padding: "12px",
760784

761-
const myRule = rules([baseRule, {}]);
785+
variants: {
786+
color: {
787+
brand: { color: "#FFFFA0" },
788+
accent: { color: "#FFE4B5" }
789+
},
790+
size: {
791+
small: { fontSize: "11px" },
792+
large: { fontSize: "20px" }
793+
}
794+
}
795+
});
796+
797+
const myRule = rules([
798+
baseRule,
799+
800+
{
801+
color: "blue",
802+
marginTop: "10px",
803+
804+
toggles: {
805+
rounded: { borderRadius: 999 }
806+
}
807+
}
808+
]);
762809
```
763810

764811
**Compiled:**
765812

766813
```css
814+
.[FILE_NAME]_baseRule__[HASH] {
815+
padding: 12px;
816+
}
767817

818+
.[FILE_NAME]_baseRule_color_brand__[HASH] {
819+
color: "#FFFFA0";
820+
}
821+
.[FILE_NAME]_baseRule_color_accent__[HASH] {
822+
color: "#FFE4B5";
823+
}
824+
.[FILE_NAME]_baseRule_size_small__[HASH] {
825+
font-size: 11px;
826+
}
827+
.[FILE_NAME]_baseRule_size_large__[HASH] {
828+
font-size: 20px;
829+
}
830+
831+
.[FILE_NAME]_myRule__[HASH] {
832+
color: "blue";
833+
margin-top: "10px";
834+
}
835+
.[FILE_NAME]_myRule_toggle_rounded__[HASH] {
836+
border-radius: 999;
837+
}
838+
```
839+
840+
**Usage**
841+
842+
```ts
843+
myRule(["rounded", { color: "brand", size: "small" }]);
768844
```
769845

770846
## 9. rulesVarints
771847

772-
Inspired by the [PandaCSS's `defineSlotRecipe()`](https://panda-css.com/docs/concepts/slot-recipes#config-slot-recipe).
848+
Inspired by the [PandaCSS's `defineSlotRecipe()`](https://panda-css.com/docs/concepts/slot-recipes#config-slot-recipe).
849+
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).
773850

774851
This is a combination of `rules()` and `cssVariants()`.
775852

776853
**Code:**
777854

778855
```typescript
856+
const contents = rulesVariants({
857+
text: {
858+
fontWeight: "bold",
859+
860+
variants: {
861+
color: {
862+
main: { color: "#0078e5" },
863+
sub: { color: "#fff7ed" }
864+
},
865+
size: {
866+
large: { fontSize: "24px" },
867+
medium: { fontSize: "18px" }
868+
small: { fontSize: "12px" }
869+
}
870+
},
779871

872+
toggles: {
873+
accent: { textDecoration: "underline" }
874+
}
875+
},
876+
image: {
877+
width: '100%',
878+
border: "1px solid #ccc",
879+
borderRadius: "5px",
880+
881+
variants: {
882+
style: {
883+
thumbnail: {
884+
width: "50px"
885+
},
886+
detail: {
887+
width: '80%';
888+
marginBottom: '10px';
889+
}
890+
}
891+
}
892+
}
893+
});
780894
```
781895

896+
It helps that we write multiple `rules` at once.
897+
782898
**Compiled:**
783899

784900
```css
901+
.[FILE_NAME]_text__[HASH] {
902+
font-weight: "bold";
903+
}
904+
.[FILE_NAME]_text_color_main__[HASH] {
905+
color: "#0078e5";
906+
}
907+
.[FILE_NAME]_text_color_sub__[HASH] {
908+
color: "#fff7ed";
909+
}
910+
.[FILE_NAME]_text_size_large__[HASH] {
911+
font-size: "24px";
912+
}
913+
.[FILE_NAME]_text_size_medium__[HASH] {
914+
font-size: "18px";
915+
}
916+
.[FILE_NAME]_text_size_small__[HASH] {
917+
font-size: "12px";
918+
}
919+
.[FILE_NAME]_text_toggle_accent__[HASH] {
920+
text-decoration: "underline";
921+
}
785922

923+
.[FILE_NAME]_image__[HASH] {
924+
width: "100%";
925+
border: "1px solid #ccc";
926+
border-radius: "5px";
927+
}
928+
.[FILE_NAME]_image_style_thumbnail__[HASH] {
929+
width: "50px";
930+
}
931+
.[FILE_NAME]_image_style_detail__[HASH] {
932+
width: "80%";
933+
margin-bottom: "10px";
934+
}
786935
```
787936

788937
**Usage:**
789938

790939
```typescript
791-
940+
// case 1
941+
contents.text([
942+
"accent",
943+
{
944+
color: "sub",
945+
size: "medium"
946+
}
947+
]);
948+
// case 2
949+
contents.image({
950+
style: "thumbnail"
951+
});
792952
```
793953

794954
## 10. With `css()`

0 commit comments

Comments
 (0)