Skip to content

Commit

Permalink
Fix: Improved backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
black7375 committed Sep 24, 2024
1 parent 5d8dd5d commit 8035fa6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
18 changes: 18 additions & 0 deletions text/000-css-literals.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,24 @@ Backward compatibility with [Vanilla Extract's `style()`](https://vanilla-extrac

- `css()` is alised to `style()`
- Should be support [`vars: `](https://vanilla-extract.style/documentation/styling#css-variables) and [`selectors: `](https://vanilla-extract.style/documentation/styling#complex-selectors) properties
- `cssVariants()` is alised to [`styleVariants()`](https://vanilla-extract.style/documentation/api/style-variants/)

```tsx
// Definition
const background = cssVariants({
primary: { background: "blue" },
secondary: { background: "aqua" }
});

// Usage
interface SectionProps {
variant: keyof typeof background;
}

const Section = ({ variant }: SectionProps) => (
<section className={background[variant]}>...</section>
);
```

# Reference-level explanation

Expand Down
40 changes: 34 additions & 6 deletions text/002-css-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,36 @@ function MyComponent() {
}
```

**Backward compatibility**

The `base` field in [Vanilla Extract's recipes](https://vanilla-extract.style/documentation/packages/recipes/) should be supported.

```typescript
const myRule = rules({
base {
color: "blue",
backgroundColor: "red"
}
});
```

When used together, the `base` field has higher priority.

```typescript
const myRule = rules({
color: "red",
base {
color: "blue" // set as "blue"
}
});
```

## 3. Props

AST traversal is required for the implementation of functional rules when static extraction is required.

```typescript
inteface MyRulesProps {
interface MyRulesProps {
color: string;
background: string;
size: number;
Expand Down Expand Up @@ -662,8 +686,10 @@ const button = rules({
},
compoundVariants: [
{
color: brand,
size: small,
variants: {
color: brand,
size: small,
},
style: {
fontSize: "16px"
}
Expand Down Expand Up @@ -695,8 +721,10 @@ const button = rules({
// method 1
compoundVariants: [
{
color: brand,
size: small,
variants: {
color: brand,
size: small,
},
style: {
fontSize: "16px"
}
Expand Down Expand Up @@ -1106,7 +1134,7 @@ If a feature is overly difficult to implement, you may want to implement another
As drafted, functional `rules()` should be possible.

```typescript
inteface MyRulesProps {
interface MyRulesProps {
color: string;
background: string;
size: number;
Expand Down

0 comments on commit 8035fa6

Please sign in to comment.