Skip to content

Commit 3911560

Browse files
committed
feat(cfasim-ui): add fontSize prop to ParamEditor
1 parent b651251 commit 3911560

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎cfasim-ui/components/src/ParamEditor/ParamEditor.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The editor is **lazy-loaded**: the underlying CodeMirror bundle and YAML/TOML pa
1313

1414
Users can switch formats from the dropdown; the editor round-trips the current value through the new format. Apply emits an `apply` event with the parsed value — the parent decides what to do with it (typically merge back into its own parameter state).
1515

16+
Set the editor font size with the `fontSize` prop (any CSS length, e.g. `"16px"` or `"1rem"`); it defaults to `var(--font-size-sm)`.
17+
1618
## Examples
1719

1820
<script setup>
@@ -66,4 +68,20 @@ function onApply(v) {
6668
</template>
6769
</ComponentDemo>
6870

71+
### Custom font size
72+
73+
<ComponentDemo>
74+
<div style="width: 100%">
75+
<ParamEditor :value="params" font-size="16px" @apply="onApply" />
76+
</div>
77+
78+
<template #code>
79+
80+
```vue
81+
<ParamEditor :value="params" font-size="16px" @apply="onApply" />
82+
```
83+
84+
</template>
85+
</ComponentDemo>
86+
6987
<!--@include: ./_api/param-editor.md-->

‎cfasim-ui/components/src/ParamEditor/ParamEditor.spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ test("exports the current text with a timestamped default filename", async ({
7070
expect(download.suggestedFilename()).toMatch(/^params-\d{8}-\d{6}\.json$/);
7171
});
7272

73+
test("applies the fontSize prop to the editor", async ({ page }) => {
74+
await page.goto("./cfasim-ui/components/param-editor");
75+
// The "Custom font size" demo passes font-size="16px". vue-codemirror
76+
// applies the wrapper's :style to the inner .cm-editor (the .v-codemirror
77+
// wrapper is display:contents), so assert on that element.
78+
const editor = page.locator(".param-editor-cm .cm-editor").nth(2);
79+
await expect(editor).toBeVisible();
80+
await expect(editor).toHaveCSS("font-size", "16px");
81+
});
82+
7383
test("switches format and round-trips the parsed value", async ({ page }) => {
7484
const demo = await openDemo(page);
7585
await expect(demo.locator(".cm-content")).toContainText('"beta"');

‎cfasim-ui/components/src/ParamEditor/ParamEditor.vue‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ defineProps<{
99
value: ParamEditorValue;
1010
format?: ParamEditorFormat;
1111
height?: string;
12+
/** Editor font size, as any CSS length (e.g. `"16px"`, `"1rem"`).
13+
* Defaults to `var(--font-size-sm)`. */
14+
fontSize?: string;
1215
/** Basename for the Export download (no extension). Defaults to
1316
* `params-YYYYMMDD-HHMMSS` computed at click time. */
1417
filename?: string;
@@ -33,6 +36,7 @@ const Impl = defineAsyncComponent({
3336
:value="value"
3437
:format="format"
3538
:height="height"
39+
:font-size="fontSize"
3640
:filename="filename"
3741
@apply="$emit('apply', $event)"
3842
/>

‎cfasim-ui/components/src/ParamEditor/ParamEditorImpl.vue‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ const props = withDefaults(
2727
value: Value;
2828
format?: Format;
2929
height?: string;
30+
fontSize?: string;
3031
filename?: string;
3132
}>(),
32-
{ format: "json", height: "320px" },
33+
{ format: "json", height: "320px", fontSize: "var(--font-size-sm)" },
3334
);
3435
3536
const emit = defineEmits<{ apply: [value: Value] }>();
@@ -264,7 +265,7 @@ async function onFileChange(e: Event) {
264265
<Codemirror
265266
v-model="text"
266267
:extensions="extensions"
267-
:style="{ height }"
268+
:style="{ height, fontSize }"
268269
:indent-with-tab="false"
269270
:tab-size="2"
270271
class="param-editor-cm"
@@ -317,7 +318,6 @@ async function onFileChange(e: Event) {
317318
.param-editor-cm {
318319
border: 1px solid var(--color-border);
319320
border-radius: 0.375em;
320-
font-size: var(--font-size-sm);
321321
overflow: hidden;
322322
}
323323

0 commit comments

Comments
 (0)