Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

design tokens left panel and new token popover

Oleg Isonend4055f3b211a
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/design-tokens.tsx b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/design-tokens.tsx
new file mode 100644
index 0000000000..8b730695b7
--- /dev/null
+++ b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/design-tokens.tsx
@@ -0,0 +1,22 @@
+import { TokensIcon } from "@webstudio-is/icons";
+import { DesignTokensManager } from "~/designer/shared/design-tokens-manager";
+import { TabName } from "../../types";
+import { Header, CloseButton } from "../../lib/header";
+
+export const TabContent = ({
+ onSetActiveTab,
+}: {
+ onSetActiveTab: (tabName: TabName) => void;
+}) => {
+ return (
+ <>
+ <Header
+ title="Design Tokens"
+ suffix={<CloseButton onClick={() => onSetActiveTab("none")} />}
+ />
+ <DesignTokensManager />
+ </>
+ );
+};
+
+export const icon = <TokensIcon />;
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/index.ts b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/index.ts
new file mode 100644
index 0000000000..531913bc9a
--- /dev/null
+++ b/apps/designer/app/designer/features/sidebar-left/panels/design-tokens/index.ts
@@ -0,0 +1 @@
+export * from "./design-tokens";
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/index.ts b/apps/designer/app/designer/features/sidebar-left/panels/index.ts
index 72410a298c..8fcdad47d3 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/index.ts
+++ b/apps/designer/app/designer/features/sidebar-left/panels/index.ts
@@ -2,5 +2,12 @@ import * as components from "./components";
import * as navigator from "./navigator";
import * as assets from "./assets";
import * as pages from "./pages";
+import * as designTokens from "./design-tokens";
-export const panels = { components, navigator, assets, pages } as const;
+export const panels = {
+ components,
+ navigator,
+ assets,
+ pages,
+ designTokens,
+} as const;
diff --git a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx
index e52f4ae750..7a86f14ec5 100644
--- a/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/sidebar-left.tsx
@@ -35,6 +35,8 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
const enabledPanels = (Object.keys(panels) as Array<TabName>).filter(
(panel) => {
switch (panel) {
+ case "designTokens":
+ return isFeatureEnabled("designTokens");
case "assets":
return isFeatureEnabled("assets");
case "navigator":
diff --git a/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsx b/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsx
new file mode 100644
index 0000000000..d966e6e6c5
--- /dev/null
+++ b/apps/designer/app/designer/shared/design-tokens-manager/design-tokens-manager.tsx
@@ -0,0 +1,127 @@
+import { useFetcher } from "@remix-run/react";
+import {
+ Button,
+ Flex,
+ Label,
+ Popover,
+ PopoverContent,
+ PopoverHeader,
+ PopoverPortal,
+ PopoverTrigger,
+ TextArea,
+ TextField,
+} from "@webstudio-is/design-system";
+import { PlusIcon } from "@webstudio-is/icons";
+import { type FormEvent, useState } from "react";
+import { createValueContainer, useValue } from "react-nano-state";
+import { restTokensPath } from "~/shared/router-utils";
+import { CollapsibleSection } from "../inspector";
+import { groups } from "./groups";
+import type {
+ DesignToken,
+ DesignTokensGroup,
+ GroupName,
+ TokenName,
+} from "./schema";
+
+const initialTokenGroups = groups.reduce(
+ (acc: DesignTokensGroup, { group }) => {
+ acc[group] = {};
+ return acc;
+ },
+ {}
+);
+
+const tokenGroupsContainer =
+ createValueContainer<DesignTokensGroup>(initialTokenGroups);
+
+const TokenEditor = ({
+ group,
+ name,
+}: {
+ group: GroupName;
+ name?: TokenName;
+}) => {
+ const [open, setOpen] = useState(false);
+ const isNew = name === undefined;
+ const fetcher = useFetcher<any>();
+ const handleSubmit = (event: FormEvent<HTMLFormElement>) => {
+ event.preventDefault();
+ if (isSubmitting) return;
+
+ //fetcher.submit(event.target as HTMLFormElement);
+ };
+ const isSubmitting = fetcher.state !== "idle";
+
+ return (
+ <Popover modal open={open} onOpenChange={setOpen}>
+ <PopoverTrigger
+ asChild
+ aria-label={isNew ? "Create Token" : "Edit Token"}
+ >
+ <Button
+ ghost
+ onClick={(event) => {
+ event.preventDefault();
+ setOpen(true);
+ }}
+ >
+ <PlusIcon />
+ </Button>
+ </PopoverTrigger>
+ <PopoverPortal>
+ <PopoverContent align="end" css={{ zIndex: "$1" }}>
+ <form onSubmit={handleSubmit} method="post" action={restTokensPath()}>
+ <Flex direction="column" gap="2" css={{ padding: "$spacing$7" }}>
+ <Label htmlFor="name">Name</Label>
+ <TextField id="name" name="$name" />
+ <Label htmlFor="value">Value</Label>
+ <TextField id="value" name="$value" />
+ <Label htmlFor="description">Description</Label>
+ <TextArea id="description" name="$description" />
+ {isNew && (
+ <Button
+ type="submit"
+ variant="blue"
+ state={isSubmitting ? "waiting" : undefined}
+ >
+ Create
+ </Button>
+ )}
+ </Flex>
+ </form>
+ <PopoverHeader title={isNew ? "New Token" : name} />
+ </PopoverContent>
+ </PopoverPortal>
+ </Popover>
+ );
+};
+
+const TokenItem = ({ token }: { token: DesignToken }) => {
+ return <div>{token.$value}</div>;
+};
+
+export const DesignTokensManager = () => {
+ const [tokenGroups] = useValue(tokenGroupsContainer);
+
+ return (
+ <>
+ {Object.keys(tokenGroups).map((group) => {
+ const tokens = tokenGroups[group];
+ return (
+ <CollapsibleSection
+ label={group}
+ key={group}
+ rightSlot={<TokenEditor group={group} />}
+ >
+ <>
+ {Object.keys(tokens).map((name) => {
+ return <TokenItem token={tokens[name]} key={name} />;
+ })}
+ </>
+ </CollapsibleSection>
+ );
+ })}
+ </>
+ );
+};
diff --git a/apps/designer/app/designer/shared/design-tokens-manager/groups.ts b/apps/designer/app/designer/shared/design-tokens-manager/groups.ts
new file mode 100644
index 0000000000..df9de4c06c
--- /dev/null
+++ b/apps/designer/app/designer/shared/design-tokens-manager/groups.ts
@@ -0,0 +1,19 @@
+// Copied from https://docs.tokens.studio/available-tokens/available-tokens
+
+export const groups = [
+ { type: "sizing", group: "Sizing" },
+ { type: "spacing", group: "Spacing" },
+ { type: "color", group: "Color" },
+ { type: "borderRadius", group: "Border Radius" },
+ { type: "borderWidth", group: "Border Width" },
+ { type: "boxShadow", group: "Box Shadow" },
+ { type: "opacity", group: "Opacity" },
+ { type: "fontFamilies", group: "Font Families" },
+ { type: "fontSizes", group: "Font Size" },
+ { type: "fontWeights", group: "Font Weight" },
+ { type: "lineHeight", group: "Line Height" },
+ { type: "letterSpacing", group: "Letter Spacing" },
+ { type: "paragraphSpacing", group: "Paragraph Spacing" },
+ { type: "textCase", group: "Text Case" },
+ { type: "textDecoration", group: "Text Decoration" },
+] as const;
diff --git a/apps/designer/app/designer/shared/design-tokens-manager/index.ts b/apps/designer/app/designer/shared/design-tokens-manager/index.ts
new file mode 100644
index 0000000000..59a37a93ff
--- /dev/null
+++ b/apps/designer/app/designer/shared/design-tokens-manager/index.ts
@@ -0,0 +1 @@
+export * from "./design-tokens-manager";
diff --git a/apps/designer/app/designer/shared/design-tokens-manager/schema.ts b/apps/designer/app/designer/shared/design-tokens-manager/schema.ts
new file mode 100644
index 0000000000..ac8fb13494
--- /dev/null
+++ b/apps/designer/app/designer/shared/design-tokens-manager/schema.ts
@@ -0,0 +1,44 @@
+import { z } from "zod";
+import { groups } from "./groups";
+
+// Example data
+// {
+// "Sizing": {
+// "Token 1 name": {
+// "$type": "sizing",
+// "$value": "Token 1 value",
+// "$description": "Token 1 description"
+// },
+// "Toke, 2 name": {
+// "$type": "sizing",
+// "$value": "Token 2 value",
+// "$description": "Token 2 description"
+// },
+// },
+// }
+
+type Type = typeof groups[number]["type"];
+
+const types: Array<Type> = groups.map((group) => group.type);
+
+export const TokenName = z.string();
+export type TokenName = z.infer<typeof TokenName>;
+
+export const GroupName = z.string();
+export type GroupName = z.infer<typeof GroupName>;
+
+export const DesignToken = z.object({
+ // @todo help
+ $type: z.enum(types as any),
+ $value: z.string(),
+ $description: z.string(),
+});
+export type DesignToken = z.infer<typeof DesignToken>;
+
+export const DesignTokens = z.record(TokenName, DesignToken);
+
+export type DesignTokens = z.infer<typeof DesignTokens>;
+
+export const DesignTokensGroup = z.record(GroupName, DesignTokens);
+
+export type DesignTokensGroup = z.infer<typeof DesignTokensGroup>;
diff --git a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx b/apps/designer/app/designer/shared/inspector/collapsible-section.tsx
index 12cc8c4ffd..eedb7cd8a6 100644
--- a/apps/designer/app/designer/shared/inspector/collapsible-section.tsx
+++ b/apps/designer/app/designer/shared/inspector/collapsible-section.tsx
@@ -60,9 +60,9 @@ export const CollapsibleSection = ({
justify="center"
css={{ marginRight: "-$spacing$3", color: "$slate9" }}
>
+ {rightSlot}
{isOpenFinal ? <ChevronLeftIcon /> : <ChevronRightIcon />}
</Flex>
- {rightSlot}
</Flex>
</Collapsible.Trigger>
<Collapsible.Content asChild>
diff --git a/apps/designer/app/shared/feature-flags/flags.ts b/apps/designer/app/shared/feature-flags/flags.ts
index 12dd85ea82..9a1c3089a9 100644
--- a/apps/designer/app/shared/feature-flags/flags.ts
+++ b/apps/designer/app/shared/feature-flags/flags.ts
@@ -1,3 +1,3 @@
export const assets = false;
-export const fonts = false;
+export const designTokens = false;
export const example = false;
diff --git a/apps/designer/app/shared/router-utils/path-utils.ts b/apps/designer/app/shared/router-utils/path-utils.ts
index 9ee983ae14..290ddf77a0 100644
--- a/apps/designer/app/shared/router-utils/path-utils.ts
+++ b/apps/designer/app/shared/router-utils/path-utils.ts
@@ -57,6 +57,8 @@ export const restPatchPath = () => "/rest/patch";
export const restPublishPath = () => "/rest/publish";
+export const restTokensPath = () => "/rest/tokens";
+
export const getBuildUrl = ({
buildOrigin,
project,
diff --git a/packages/design-system/src/components/button.tsx b/packages/design-system/src/components/button.tsx
index 32171f8d8c..31154684c6 100644
--- a/packages/design-system/src/components/button.tsx
+++ b/packages/design-system/src/components/button.tsx
@@ -205,16 +205,10 @@ export const Button = styled("button", {
waiting: {
backgroundColor: "$slate4",
boxShadow: "inset 0 0 0 1px $colors$slate8",
- color: "transparent",
- pointerEvents: "none",
- "@hover": {
- "&:hover": {
- backgroundColor: "$slate6",
- boxShadow: "inset 0 0 0 1px $colors$slate8",
- },
- },
- "&:active": {
- backgroundColor: "$slate6",
+ color: "$colors$slate9",
+ cursor: "wait",
+ "&:hover, &:active": {
+ color: "$colors$slate9",
},
"&:focus": {
boxShadow: "inset 0 0 0 1px $colors$slate8",
diff --git a/packages/design-system/src/components/text-area.tsx b/packages/design-system/src/components/text-area.tsx
index 817601156a..4b0295a779 100644
--- a/packages/design-system/src/components/text-area.tsx
+++ b/packages/design-system/src/components/text-area.tsx
@@ -8,7 +8,6 @@ export const TextArea = styled("textarea", {
margin: "0",
outline: "none",
padding: "$spacing$3",
- width: "100%",
WebkitTapHighlightColor: "rgba(0,0,0,0)",
backgroundColor: "$loContrast",
boxShadow: "inset 0 0 0 1px $colors$muted",
diff --git a/packages/icons/src/legacy.ts b/packages/icons/src/legacy.ts
index 1cae8ef769..8d221b609d 100644
--- a/packages/icons/src/legacy.ts
+++ b/packages/icons/src/legacy.ts
@@ -27,4 +27,5 @@ export {
InfoCircledIcon,
CrossCircledIcon,
CheckCircledIcon,
+ TokensIcon,
} from "@radix-ui/react-icons";