Skip to content

Commit

Permalink
Save TS config on file
Browse files Browse the repository at this point in the history
  • Loading branch information
veej committed Dec 1, 2023
1 parent 2a87623 commit 9e1b2c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/configuration-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@react-stately/select": "3.5.4",
"@vanilla-extract/css": "1.12.0",
"@vanilla-extract/recipes": "0.5.0",
"file-saver": "^2.0.5",
"i18next": "22.5.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand All @@ -37,6 +38,7 @@
"@react-types/numberfield": "3.5.0",
"@react-types/shared": "3.19.0",
"@tsconfig/vite-react": "2.0.0",
"@types/file-saver": "^2.0.7",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"@typescript-eslint/eslint-plugin": "6.5.0",
Expand Down
10 changes: 6 additions & 4 deletions packages/configuration-builder/src/MyTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
IconDiamondsFour,
IconSwatches,
} from "./PhosphorIcons";
import { useConfigurationExporter } from "./utils/useConfigurationExporter";
import { useConfigGeneratorTS } from "./utils/useConfigGeneratorTS";
import { saveAs } from "file-saver";

const numberImages = [image1, image2, image3];

Expand Down Expand Up @@ -95,7 +96,7 @@ export function MyTheme() {

const { sections } = useConfiguratorStatusContext();
const navigate = useNavigate();
const exportTS = useConfigurationExporter();
const generateTS = useConfigGeneratorTS();

return (
<Box display="flex" flexGrow={1} overflowY="auto" flexDirection="column">
Expand Down Expand Up @@ -202,8 +203,9 @@ export function MyTheme() {
hierarchy="primary"
label={t("Theme.Export.React.action")}
onPress={() => {
const ts = exportTS();
console.log(ts);
const generatedCode = generateTS();
const blob = new Blob([generatedCode], { type: "text/plain;charset=utf-8" });
saveAs(blob, "generatedCode.ts");
}}
/>
</Inline>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function colorTokenToVarName(colorToken: ColorToken): string {
return `${tokenPart}_${colorToken.alpha}`;
}

export function useConfigurationExporter(): () => string {
export function useConfigGeneratorTS(): () => string {
const { tokens, colors } = useConfiguratorStatusContext().theme;
const colorTokenToValue = _colorTokenToValue(colors);
return () => {
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e1b2c0

Please sign in to comment.