-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide CSS based implementation of toggle button
- Loading branch information
1 parent
5de2e98
commit ae312be
Showing
4 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
user-interface/frontend/themes/datamanager/components/toggle-button.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*Adapted from example provided in | ||
https://vaadin.com/forum/t/togglebutton-for-flow-3-0-0-vaadin-24-3-10-problem-with-applying-custom-css/166148/17*/ | ||
|
||
/*Define checkbox width and height*/ | ||
.toggle-button::part(checkbox) { | ||
width: var(--lumo-size-m); | ||
border-radius: 1em; | ||
} | ||
|
||
/*Button size and style within checkbox*/ | ||
.toggle-button::part(checkbox)::after { | ||
content: ""; | ||
height: calc(var(--lumo-size-m) / 3); | ||
background-color: var(--lumo-secondary-text-color); | ||
border-radius: 1em; | ||
inset: 0; | ||
margin: calc(var(--lumo-size-m) / 12); | ||
opacity: 1; | ||
transition: transform 0.3s; | ||
width: calc(var(--lumo-size-m) / 3); | ||
} | ||
|
||
/*After the checkbox is pressed, move the button to the right and change color*/ | ||
.toggle-button[checked]::part(checkbox)::after { | ||
background-color: var(--lumo-primary-contrast-color); | ||
transform: translateX(calc(var(--lumo-size-m) / 2)); | ||
} |
15 changes: 15 additions & 0 deletions
15
user-interface/src/main/java/life/qbic/datamanager/views/general/ToggleButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package life.qbic.datamanager.views.general; | ||
|
||
import com.vaadin.flow.component.checkbox.Checkbox; | ||
|
||
/** | ||
* Custom Toggle Button adapted via css from the default {@link Checkbox} component | ||
*/ | ||
public class ToggleButton extends Checkbox { | ||
|
||
public ToggleButton(String text) { | ||
addClassName("toggle-button"); | ||
this.setLabel(text); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters