Skip to content

Commit 521421a

Browse files
committed
Add util for getting sharing URL (which the current state in the hash). Use it for comments in the CSS variables and tailwind config export targets (Other targets are JSON, which aren't support comments out of the box)
1 parent a745406 commit 521421a

5 files changed

Lines changed: 23 additions & 12 deletions

File tree

packages/core/src/components/ExportImportMenu/items/OpenInWebApp.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import { useSubscribe } from "@spred/react";
22

33
import { MenuItemLink } from "@core/components/Menu/MenuItemLink";
4-
import { HARMONIZER_WEB_APP_URL } from "@core/constants";
54
import { $compactExportConfigHash } from "@core/stores/config";
5+
import { getShareUrl } from "@core/utils/url/getShareUrl";
66

77
export function OpenInWebApp() {
88
const configHash = useSubscribe($compactExportConfigHash);
99

1010
return (
11-
<MenuItemLink
12-
value="open-in-web"
13-
href={`${HARMONIZER_WEB_APP_URL}/${configHash}`}
14-
target="_blank"
15-
>
11+
<MenuItemLink value="open-in-web" href={getShareUrl(configHash)} target="_blank">
1612
Open in web app
1713
</MenuItemLink>
1814
);

packages/core/src/stores/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,15 @@ export const ExportTargets = {
169169
name: "Tailwind v3",
170170
filename: "tailwind.config.js",
171171
mimetype: "application/javascript",
172-
getFileData: () => getTailwindConfig(getExportConfigWithColors()),
172+
getFileData: () =>
173+
getTailwindConfig(getExportConfigWithColors(), $compactExportConfigHash.value),
173174
},
174175
"css-variables": {
175176
name: "CSS variables",
176177
filename: "harmonized-palette.css",
177178
mimetype: "application/javascript",
178-
getFileData: () => getCssVariablesConfig(getExportConfigWithColors()),
179+
getFileData: () =>
180+
getCssVariablesConfig(getExportConfigWithColors(), $compactExportConfigHash.value),
179181
},
180182
json: {
181183
name: "JSON Config",
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import type { ExportConfigWithColors } from "@core/types";
22
import { toCss } from "@core/utils/colors/toCss";
3+
import { getShareUrl } from "@core/utils/url/getShareUrl";
34

45
import { buildColorItems } from "./buildColorItems";
56
import { buildName } from "./utils";
67

7-
export function getCssVariablesConfig(config: ExportConfigWithColors): string {
8+
export function getCssVariablesConfig(config: ExportConfigWithColors, configHash: string): string {
89
const colors = buildColorItems(config, (level, hue, color) => {
910
return `--${buildName(hue.name, level.name)}: ${toCss(color, config.settings.colorSpace)};`;
1011
});
1112

12-
return `:root {
13+
return `/*
14+
Generated via Harmonizer: ${getShareUrl(configHash)}
15+
*/
16+
:root {
1317
${colors.join("\n ")}
1418
}`;
1519
}

packages/core/src/utils/config/getTailwindConfig.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import type { ExportConfigWithColors } from "@core/types";
22
import { toCss } from "@core/utils/colors/toCss";
3+
import { getShareUrl } from "@core/utils/url/getShareUrl";
34

45
import { buildColorItems } from "./buildColorItems";
56
import { buildName } from "./utils";
67

7-
export function getTailwindConfig(config: ExportConfigWithColors): string {
8+
export function getTailwindConfig(config: ExportConfigWithColors, configHash: string): string {
89
const colors = buildColorItems(config, (level, hue, color) => {
910
return `"${buildName(hue.name, level.name)}": "${toCss(color, config.settings.colorSpace)}",`;
1011
});
1112

12-
return `/** @type {import('tailwindcss').Config} */
13+
return `/**
14+
* Generated via Harmonizer: ${getShareUrl(configHash)}
15+
* @type {import('tailwindcss').Config}
16+
* */
1317
module.exports = {
1418
theme: {
1519
colors: {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { HARMONIZER_WEB_APP_URL } from "@core/constants";
2+
3+
export function getShareUrl(configHash: string): string {
4+
return `${HARMONIZER_WEB_APP_URL}/${configHash}`;
5+
}

0 commit comments

Comments
 (0)