Skip to content

Commit 3fd06dd

Browse files
hamsterbacke23ChristianAlbrecht
authored andcommitted
HUB-9781: Add checkmark
HUB-9781 (UX: Add checkmark to toggle) HUB-9781: Remove unused styles, add review fixes HUB-9781 (UX: Add checkmark to toggle) HUB-9781: Fix typo in comment HUB-9781 (UX: Add checkmark to toggle) HUB-9781: Improve browser-zoom behavior by switching to non-pixel value for stroke-width HUB-9781 (UX: Add checkmark to toggle)
1 parent 9b16208 commit 3fd06dd

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

Diff for: .changeset/dirty-donuts-scream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@knime/components": patch
3+
---
4+
5+
Improved styling for toggleSwitch

Diff for: packages/components/src/components/forms/ToggleSwitch/ToggleSwitch.vue

+32-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<script>
2+
import CheckIcon from "@knime/styles/img/icons/check.svg";
3+
24
export default {
35
name: "ToggleSwitch",
6+
components: {
7+
CheckIcon,
8+
},
49
props: {
510
id: {
611
type: String,
@@ -47,6 +52,7 @@ export default {
4752

4853
<template>
4954
<label :class="['toggle', labelSize]">
55+
<CheckIcon :class="{ checked: modelValue }" />
5056
<input
5157
:id="id"
5258
ref="input"
@@ -63,13 +69,31 @@ export default {
6369

6470
<style lang="postcss" scoped>
6571
.toggle {
66-
display: inline-block;
72+
--component-height: 18px;
73+
74+
display: inline-flex;
6775
position: relative;
6876
isolation: isolate;
6977
padding: 3px 0 3px 37px;
7078
max-width: 100%;
7179
cursor: pointer;
72-
vertical-align: middle;
80+
81+
& svg {
82+
opacity: 0;
83+
position: absolute;
84+
z-index: 1;
85+
left: 15px;
86+
width: 10px;
87+
height: 10px;
88+
top: 50%;
89+
margin-top: -5px; /* half of the height */
90+
stroke-width: 2.5; /* manual setting the stroke-width as the usual calc-expression result is too thick */
91+
92+
&.checked {
93+
opacity: 1;
94+
transition: opacity 0.1s ease 0.3s;
95+
}
96+
}
7397
7498
& input {
7599
user-select: none;
@@ -82,9 +106,6 @@ export default {
82106
& + span {
83107
display: inline-flex;
84108
align-items: center;
85-
overflow: hidden;
86-
text-overflow: ellipsis;
87-
white-space: nowrap;
88109
}
89110
90111
& + span::before {
@@ -152,30 +173,23 @@ export default {
152173
153174
/* label size */
154175
&.regular {
155-
--regular-height: 18px;
156-
157176
font-size: 13px;
158177
font-weight: 300;
159-
line-height: var(--regular-height);
160-
161-
& > span {
162-
min-height: var(--regular-height);
163-
}
178+
min-height: var(--component-height);
164179
}
165180
166181
&.large {
167-
--large-height: 20px;
182+
--component-height: 20px;
168183
169184
font-family: var(--theme-text-bold-font-family);
170185
color: var(--theme-text-bold-color);
171186
font-size: 16px;
172187
font-weight: 700;
173-
line-height: var(--large-height);
188+
min-height: var(--component-height);
189+
}
174190
175-
& > span {
176-
min-height: var(--large-height);
177-
max-width: 100%;
178-
}
191+
&:has(:checked:focus) svg {
192+
stroke: var(--knime-white);
179193
}
180194
}
181195
</style>

Diff for: packages/components/src/components/forms/ToggleSwitch/__tests__/ToggleSwitch.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe("ToggleSwitch.vue", () => {
1414
expect(wrapper.isVisible()).toBeTruthy();
1515
expect(wrapper.find("label").exists()).toBeTruthy();
1616
expect(wrapper.find("input").element.checked).toBe(false);
17+
expect(wrapper.find(".checked").exists()).toBeFalsy();
1718
});
1819

1920
it("renders checked state", () => {
@@ -24,6 +25,7 @@ describe("ToggleSwitch.vue", () => {
2425
});
2526
expect(wrapper.find("input").element.checked).toBe(true);
2627
expect(wrapper.vm.isChecked()).toBe(true);
28+
expect(wrapper.find(".checked").exists()).toBeTruthy();
2729
});
2830

2931
it("emits input events", async () => {

Diff for: tsconfig.vitest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": "./tsconfig.app.json",
3-
"exclude": ["node_mdules"],
3+
"exclude": ["node_modules"],
44
"compilerOptions": {
55
"composite": true,
66
"lib": ["ES2022", "ES2023.Array", "DOM"],

0 commit comments

Comments
 (0)