feat: twind plugin (#513)

This adds a first-party twind plugin to use twind for styling.
This commit is contained in:
Luca Casonato
2022-08-09 21:41:11 +02:00
committed by GitHub
parent fd4e2bbe17
commit 660e0f5fef
20 changed files with 296 additions and 238 deletions
+11 -14
View File
@@ -1,6 +1,5 @@
/** @jsx h */
import { h } from "preact";
import { apply, tw } from "@twind";
import {
CATEGORIES,
@@ -10,7 +9,7 @@ import {
export default function DocsSidebar(props: { path: string }) {
return (
<ol class={tw`list-decimal list-inside font-semibold` + " nested"}>
<ol class="list-decimal list-inside font-semibold nested">
{CATEGORIES.map((category) => (
<SidebarCategory path={props.path} category={category} />
))}
@@ -18,24 +17,22 @@ export default function DocsSidebar(props: { path: string }) {
);
}
const link = apply`text(gray-900 hover:gray-600)`;
const linkActive = apply`text(green-600 hover:green-500)`;
const link = "text(gray-900 hover:gray-600)";
const linkActive = "text(green-600 hover:green-500)";
export function SidebarCategory(props: {
path: string;
category: TableOfContentsCategory;
}) {
const outerItem = tw`my-2 block`;
const innerList = tw`pl-4 list-decimal` + " nested";
const { title, href, entries } = props.category;
const outerLink = tw`${href == props.path ? linkActive : link} font-bold`;
const outerLink = `${href == props.path ? linkActive : link} font-bold`;
return (
<li class={outerItem}>
<li class="my-2 block">
<a href={href} class={outerLink}>{title}</a>
{entries.length > 0 && (
<ol class={innerList}>
<ol class="pl-4 list-decimal nested">
{entries.map((entry) => (
<SidebarEntry path={props.path} entry={entry} />
))}
@@ -49,12 +46,12 @@ export function SidebarEntry(props: {
path: string;
entry: TableOfContentsCategoryEntry;
}) {
const innerItem = tw`my-0.5`;
const { title, href } = props.entry;
const innerLink = tw`${href == props.path ? linkActive : link} font-normal`;
const innerLink = `${href == props.path ? linkActive : link} font-normal`;
return (
<li class={innerItem}>
<li class="my-0.5">
<a href={href} class={innerLink}>{title}</a>
</li>
);