Skip to content

Commit

Permalink
fix: styles in storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
raaymax committed Apr 8, 2024
1 parent 802d651 commit a90c3df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"test": "npm run --if-present -ws test",
"lint": "npm run --if-present -ws lint",
"dev": "npm run -w streamsync-ui dev",
"storybook": "npm run -w streamsync-ui storybook",
"storybook.build": "npm run -w streamsync-ui storybook.build",
"custom.dev": "npm run -w streamsync-ui dev",

"cli:test": "pytest tests -o log_cli=true ",
Expand Down
3 changes: 2 additions & 1 deletion src/ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ node_modules/
/playwright-report/
/blob-report/
/playwright/.cache/
storybook-static/

*storybook.log
*storybook.log
34 changes: 31 additions & 3 deletions src/ui/tools/generator_storybook.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ function generateDescription(field) {
return "";
}

function generateStyles(component) {
return Object.entries(component.fields)
.map(([key, field]) => {
if (field.category === "Style") {
return ` "--${key}": args.${key},`;
}
return null;
})
.filter((x) => x !== null)
.join("\n");
}

function generateStylesInfill(component) {
const styles = generateStyles(component);
return ` ...(Object.fromEntries(Object.entries({
${styles}
}).filter(([, value]) => value !== undefined))),`;
}
function mappedControl(field) {
switch (field.type) {
case "Number":
Expand Down Expand Up @@ -146,7 +164,7 @@ export const Sample: Story = {
components: { ${component.nameTrim} },
setup() {
const ss = generateCore();
args.rootStyle = computed(() => {
const rootStyle = computed(() => {
return {
"--accentColor": "#29cf00",
"--buttonColor": "#ffffff",
Expand All @@ -156,6 +174,16 @@ export const Sample: Story = {
"--buttonTextColor": "#202829",
"--secondaryTextColor": "#5d7275",
"--containerBackgroundColor": "#ffffff",
${generateStylesInfill(component)}
"width": "100%",
"outline": "none",
"--notificationsDisplacement": "0",
"font-family": "Inter, sans-serif",
"font-size": "0.8rem",
"color": "var(--primaryTextColor)",
"background": "white",
"min-height": "100%",
"isolation": "isolate",
};
});
provide(injectionKeys.evaluatedFields, {
Expand All @@ -168,10 +196,10 @@ ${generateArgWrap(component)}
provide(injectionKeys.instancePath, [{componentId: "test", instanceNumber: 0}]);
provide(injectionKeys.flattenedInstancePath, "test:0");
provide(injectionKeys.core, ss as any);
return { args };
return { args, rootStyle };
},
template:
'<${component.nameTrim} :style="args.rootStyle" :prop-name="args.propName" />',
'<div :style="rootStyle"><${component.nameTrim} /></div>',
}),
};
`;
Expand Down

0 comments on commit a90c3df

Please sign in to comment.