Skip to content

Commit ed115c1

Browse files
add additional css declaration option to vanilla framework config
1 parent ca88af2 commit ed115c1

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface WebAdditionalCssDeclarationConfig {
2+
declarations: CssDeclaration[];
3+
}
4+
5+
interface CssDeclaration {
6+
key: {
7+
name: string;
8+
selector: "tag" | "id" | "class";
9+
};
10+
style: object;
11+
}

packages/builder-web-vanilla/export-inline-css-html-file/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { handle } from "@coli.codes/builder";
2-
import { buildCssStandard } from "@coli.codes/css";
2+
import { buildCssStandard, CSSProperties } from "@coli.codes/css";
33
import { ReservedKeywordPlatformPresets } from "@coli.codes/naming/reserved";
44
import {
55
k,
@@ -41,7 +41,20 @@ ${indenter(body, 2)}
4141
</html>`;
4242
};
4343

44-
export function export_inlined_css_html_file(widget: JsxWidget) {
44+
interface CssDeclaration {
45+
key: {
46+
name: string;
47+
selector: "tag" | "id" | "class";
48+
};
49+
style: CSSProperties;
50+
}
51+
52+
export function export_inlined_css_html_file(
53+
widget: JsxWidget,
54+
config: {
55+
additional_css_declarations?: CssDeclaration[];
56+
}
57+
) {
4558
const componentName = widget.key.name;
4659
const styledComponentNamer = new ScopedVariableNamer(
4760
widget.key.id,
@@ -78,6 +91,8 @@ export function export_inlined_css_html_file(widget: JsxWidget) {
7891
};
7992
})
8093
.filter((s) => s);
94+
95+
// global vanilla default injected style
8196
css_declarations.push({
8297
key: {
8398
name: "*",
@@ -86,6 +101,11 @@ export function export_inlined_css_html_file(widget: JsxWidget) {
86101
style: k.user_agent_stylesheet_override_default,
87102
});
88103

104+
// declare additional styles requested by user
105+
config.additional_css_declarations?.forEach((d) => {
106+
css_declarations.push(d);
107+
});
108+
89109
const strfied_css = css_declarations
90110
.map((css) => {
91111
const selectors = {

packages/designto-code/universal/design-to-code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export async function designToVanilla({
255255
input.widget,
256256
vanilla_config
257257
);
258-
const res = tovanilla.buildVanillaFile(vanillawidget);
258+
const res = tovanilla.buildVanillaFile(vanillawidget, vanilla_config);
259259

260260
// ------------------------------------------------------------------------
261261
// finilize temporary assets

packages/designto-vanilla/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import { export_inlined_css_html_file } from "@web-builder/vanilla";
55
import { JsxWidget } from "@web-builder/core";
66

77
export function buildVanillaFile(
8-
widget: JsxWidget
8+
widget: JsxWidget,
9+
config: config.VanillaFrameworkConfig
910
): config.VanillaComponentOutput {
1011
if (!widget) {
1112
throw "A valid reflect widget manifest should be passed as an input. none was passed.";
1213
}
1314

14-
const html = export_inlined_css_html_file(widget);
15+
const html = export_inlined_css_html_file(widget, {
16+
additional_css_declarations:
17+
config.additional_css_declaration?.declarations,
18+
});
19+
1520
return {
1621
id: widget.key.id,
1722
name: widget.key.name,

0 commit comments

Comments
 (0)