-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend Component Documentation (#176)
* feat: compound components * docs: link to compound component example * docs: kick off compound components page * fix: prettier and syncpack failures * docs: update example to include boolean variants * chore(vue): include boolean variant * chore(astro-with-tailwindcss): include boolean variant * chore(react-with-tailwindcss): include boolean variant * chore(react-with-css-modules): include boolean variant * chore(svelte): include boolean variant * docs: polymorphism * chore(react-with-tailwindcss-compound): tidy * feat: compound docs * fix: sync versions * Update packages/cva/package.json * chore: kick off beta examples * chore: create latest examples dir * chore: add beta examples * chore: add stackblitz embeds to beta pages * chore: revert manual branch override * docs: compound components * chore: tidy up
- Loading branch information
Showing
182 changed files
with
2,790 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
import invariant from "tiny-invariant"; | ||
export interface Props { | ||
dir?: string; | ||
file?: string; | ||
} | ||
const branch = "main"; | ||
const { dir, file } = Astro.props; | ||
invariant(dir, "No directory specified"); | ||
invariant(file, "No file specified"); | ||
--- | ||
|
||
<div class="mt-4 block [&>*+*]:mt-4"> | ||
<a href={`https://github.com/joe-bell/cva/tree/${branch}/${dir}/${file}`}> | ||
View on GitHub <span aria-label="External">↗</span> | ||
</a> | ||
<iframe | ||
style={{ aspectRatio: 1 / 1, width: "100%" }} | ||
src={`https://stackblitz.com/github/cva/tree/${branch}/${dir}?embed=1&file=${file}&hideNavigation=1&view=preview`} | ||
></iframe> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: Astro | ||
--- | ||
|
||
import StackBlitz from "../../../components/stackblitz.astro"; | ||
|
||
## Tailwind CSS | ||
|
||
<StackBlitz | ||
dir="examples/latest/astro-with-tailwindcss" | ||
file="src/components/button.astro" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: BEM | ||
--- | ||
|
||
```css | ||
/* styles.css */ | ||
.button { | ||
/* */ | ||
} | ||
|
||
.button--primary { | ||
/* */ | ||
} | ||
.button--secondary { | ||
/* */ | ||
} | ||
|
||
.button--small { | ||
/* */ | ||
} | ||
.button--medium { | ||
/* */ | ||
} | ||
|
||
.button--primary-small { | ||
/* */ | ||
} | ||
``` | ||
|
||
```ts | ||
import { cva } from "class-variance-authority"; | ||
|
||
const button = cva("button", { | ||
variants: { | ||
intent: { | ||
primary: "button--primary", | ||
secondary: "button--secondary", | ||
}, | ||
size: { | ||
small: "button--small", | ||
medium: "button--medium", | ||
}, | ||
}, | ||
compoundVariants: [ | ||
{ intent: "primary", size: "medium", class: "button--primary-small" }, | ||
], | ||
defaultVariants: { | ||
intent: "primary", | ||
size: "medium", | ||
}, | ||
}); | ||
|
||
button(); | ||
// => "button button--primary button--medium" | ||
|
||
button({ intent: "secondary", size: "small" }); | ||
// => "button button--secondary button--small" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: Other Use Cases | ||
--- | ||
|
||
Although primarily designed for handling class names, at its core, `cva` is really just a fancy way of managing a string… | ||
|
||
## Dynamic Text Content | ||
|
||
```ts | ||
const greeter = cva("Good morning!", { | ||
variants: { | ||
isLoggedIn: { | ||
true: "Here's a secret only logged in users can see", | ||
false: "Log in to find out more…", | ||
}, | ||
}, | ||
defaultVariants: { | ||
isLoggedIn: "false", | ||
}, | ||
}); | ||
|
||
greeter(); | ||
// => "Good morning! Log in to find out more…" | ||
|
||
greeter({ isLoggedIn: "true" }); | ||
// => "Good morning! Here's a secret only logged in users can see" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
title: React with CSS Modules | ||
--- | ||
|
||
import StackBlitz from "../../../../components/stackblitz.astro"; | ||
|
||
<StackBlitz | ||
dir="examples/beta/react-with-css-modules" | ||
file="src/components/button/button.tsx" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
title: React with Tailwind CSS | ||
--- | ||
|
||
import StackBlitz from "../../../../components/stackblitz.astro"; | ||
|
||
## Basic Component | ||
|
||
<StackBlitz | ||
dir="examples/beta/react-with-tailwindcss" | ||
file="src/components/button/button.tsx" | ||
/> | ||
|
||
## Compound Components | ||
|
||
<StackBlitz | ||
dir="examples/beta/react-with-tailwindcss-compound" | ||
file="src/components/nav/nav.tsx" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: Svelte | ||
--- | ||
|
||
import StackBlitz from "../../../components/stackblitz.astro"; | ||
|
||
<StackBlitz dir="examples/latest/svelte" file="src/components/button.svelte" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: Vue | ||
--- | ||
|
||
import StackBlitz from "../../../components/stackblitz.astro"; | ||
|
||
<StackBlitz dir="examples/latest/vue" file="src/components/Button.vue" /> |
31 changes: 31 additions & 0 deletions
31
docs/beta/src/content/docs/getting-started/compound-components.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
title: Compound Components | ||
--- | ||
|
||
For larger, more complex components, you may end up wanting to create a set of composable components that work together: "Compound Components" | ||
|
||
<details> | ||
<summary>e.g. <code><Accordion.Subcomponent /></code> instead of <code><Accordion /></code></summary> | ||
|
||
```tsx | ||
import * as Accordion from "./Accordion"; | ||
|
||
function Example() { | ||
return ( | ||
<Accordion.Root> | ||
<Accordion.Item> | ||
<Accordion.Header>Section 1</Accordion.Header> | ||
<Accordion.Content>Content 1</Accordion.Content> | ||
</Accordion.Item> | ||
</Accordion.Root> | ||
); | ||
} | ||
``` | ||
|
||
</details> | ||
|
||
`cva` encourages you to build these compound components **with the power of CSS**; leverage the cascade, custom properties, `:has()` selectors, and more… | ||
|
||
## Examples | ||
|
||
- [React with Tailwind CSS (Compound Components)](../examples/react/tailwindcss#compound-components) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.