Skip to content

Commit 21bd28c

Browse files
authored
KDS-442: use KdsCheckbox in JSONForms (#105)
1 parent 6de068a commit 21bd28c

File tree

13 files changed

+99
-66
lines changed

13 files changed

+99
-66
lines changed

.changeset/chilled-roses-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@knime/jsonforms": patch
3+
---
4+
5+
KDS-442: use KdsCheckbox in JSONForms

.stylelintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
"packages/styles/css/variables/index.css",
1010
"packages/components/src/components/forms/variables.css",
1111
"packages/jsonforms/src/higherOrderComponents/control/errorMessage/error-messages.css",
12+
"node_modules/@knime/kds-styles/dist/tokens/css/_variables.css",
1213
],
1314
},
1415
],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@changesets/cli": "^2.27.7",
4141
"@knime/eslint-config": "workspace:*",
4242
"@knime/licenses": "workspace:*",
43+
"@knime/kds-styles": "catalog:",
4344
"@tsconfig/node24": "24.0.3",
4445
"@types/jsdom": "^21.1.7",
4546
"@types/lodash-es": "4.17.12",

packages/jsonforms/src/JsonFormsDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,6 @@ const jsonFormsDialogBindings = computed(() => ({
179179
* The settings subpanel does overflow for animation reasons
180180
*/
181181
overflow-x: hidden;
182-
background-color: var(--knime-gray-ultra-light);
182+
background-color: var(--kds-color-surface-default);
183183
}
184184
</style>

packages/jsonforms/src/higherOrderComponents/control/LabeledControl.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ const title = computed(() => (props.label === "" ? " " : props.label));
7575
min-width: 0;
7676
white-space: pre;
7777
}
78+
79+
/**
80+
* see src/uiComponents/composables/useHideOnNull.ts
81+
*/
82+
& :deep(.checkbox-hide-on-null) {
83+
margin-top: 2px;
84+
margin-right: var(--kds-spacing-container-0-5x);
85+
}
7886
}
7987
}
8088

packages/jsonforms/src/higherOrderComponents/control/withLabel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { computed, h, ref, toRef } from "vue";
22

3-
import { Checkbox } from "@knime/components";
3+
import { KdsCheckbox } from "@knime/kds-components";
44

55
import useHideOnNull from "../../uiComponents/composables/useHideOnNull";
66

@@ -53,7 +53,7 @@ const addLabelToComponent =
5353
},
5454
{
5555
"before-label": () =>
56-
showCheckbox.value ? h(Checkbox, checkboxProps.value) : null,
56+
showCheckbox.value ? h(KdsCheckbox, checkboxProps.value) : null,
5757
default: ({ labelForId }: { labelForId: string }) => {
5858
if (!showControl.value) {
5959
return null;

packages/jsonforms/src/layoutComponents/section/SectionHeading.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ defineProps<{
2121
top: 0;
2222
z-index: 1;
2323
margin: 0 calc(-1 * var(--horizontal-dialog-padding, 0));
24-
background-color: var(--knime-gray-ultra-light);
24+
background-color: var(--kds-color-surface-default);
2525
2626
& .section-header-layout-container {
2727
display: flex;
2828
align-items: center;
2929
justify-content: space-between;
3030
width: calc(100% - var(--horizontal-dialog-padding, 0) * 2);
3131
margin: 0 var(--horizontal-dialog-padding, 0);
32-
border-bottom: 1px solid var(--knime-silver-sand);
32+
border-bottom: var(--kds-border-base-muted);
3333
3434
& h3 {
3535
margin: 0;
3636
font-size: 16px;
3737
line-height: 40px;
38-
color: var(--knime-masala);
38+
color: var(--kds-color-text-and-icon-neutral);
3939
}
4040
}
4141
}

packages/jsonforms/src/uiComponents/CheckboxControl.vue

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
22
import { ref } from "vue";
33
4-
import { Checkbox } from "@knime/components";
4+
import { KdsCheckbox, type KdsCheckboxProps } from "@knime/kds-components";
55
66
import type { VueControlProps } from "../higherOrderComponents/control/types";
77
8+
type CheckboxValue = KdsCheckboxProps["modelValue"];
9+
810
defineProps<VueControlProps<boolean>>();
911
const hover = ref(false);
1012
</script>
@@ -15,15 +17,18 @@ const hover = ref(false);
1517
@mouseover="hover = true"
1618
@mouseleave="hover = false"
1719
>
18-
<Checkbox
19-
class="checkbox"
20-
:disabled="disabled"
21-
:model-value="control.data"
22-
@update:model-value="changeValue"
23-
>
24-
{{ control.label }}
20+
<div class="checkbox-container">
21+
<KdsCheckbox
22+
class="checkbox"
23+
:disabled="disabled"
24+
:model-value="control.data"
25+
:label="control.label"
26+
@update:model-value="
27+
(value: CheckboxValue) => changeValue(value as boolean)
28+
"
29+
/>
2530
<slot name="icon" />
26-
</Checkbox>
31+
</div>
2732
<slot name="buttons" :hover="hover" />
2833
</div>
2934
</template>
@@ -37,12 +42,14 @@ const hover = ref(false);
3742
display: flex;
3843
margin-bottom: -10px;
3944
40-
& .checkbox {
45+
& .checkbox-container {
46+
display: flex;
4147
flex: 1;
4248
min-width: 0;
4349
}
4450
}
4551
52+
/* via slot */
4653
.reexecution-icon {
4754
display: inline-block;
4855
height: 10px;

packages/jsonforms/src/uiComponents/__tests__/CheckboxControl.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "vitest";
1010
import type { VueWrapper } from "@vue/test-utils";
1111

12-
import { Checkbox } from "@knime/components";
12+
import { KdsCheckbox } from "@knime/kds-components";
1313

1414
import {
1515
type VueControlTestProps,
@@ -60,21 +60,23 @@ describe("CheckboxControl", () => {
6060
});
6161

6262
it("renders", () => {
63-
expect(wrapper.findComponent(Checkbox).exists()).toBe(true);
63+
expect(wrapper.findComponent(KdsCheckbox).exists()).toBe(true);
6464
});
6565

6666
it("calls changeValue when checkbox is changed", async () => {
67-
await wrapper.findComponent(Checkbox).vm.$emit("update:modelValue", true);
67+
await wrapper.getComponent(KdsCheckbox).vm.$emit("update:modelValue", true);
6868
expect(changeValue).toHaveBeenCalledWith(true);
6969
});
7070

7171
it("sets correct initial value", () => {
72-
expect(wrapper.findComponent(Checkbox).vm.modelValue).toBe(
72+
expect(wrapper.getComponent(KdsCheckbox).props().modelValue).toBe(
7373
props.control.data,
7474
);
7575
});
7676

7777
it("sets correct label", () => {
78-
expect(wrapper.find("label").text()).toBe(props.control.label);
78+
expect(wrapper.getComponent(KdsCheckbox).props().label).toBe(
79+
props.control.label,
80+
);
7981
});
8082
});

packages/jsonforms/src/uiComponents/composables/__tests__/__integrationTests__/hide-on-null.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { describe, expect, it, vi } from "vitest";
22
import { VueWrapper, flushPromises, mount } from "@vue/test-utils";
33

4-
import { Checkbox, InputField } from "@knime/components";
4+
import { InputField } from "@knime/components";
5+
import { KdsCheckbox } from "@knime/kds-components";
56

67
import JsonFormsDialog from "../../../../JsonFormsDialog.vue";
78
import { controls, toRenderers } from "../../../../renderers";
89

910
describe("hide on null", () => {
1011
let wrapper: VueWrapper;
1112

12-
const findCheckbox = (wrapper: VueWrapper) => wrapper.findComponent(Checkbox);
13+
const findCheckbox = (wrapper: VueWrapper) =>
14+
wrapper.findComponent(KdsCheckbox);
1315

1416
const defaultValue = "default value";
1517

0 commit comments

Comments
 (0)