Skip to content

Commit 9cfbc56

Browse files
authored
feat(checkbox): invisible variant for text only
Added an invisible variant to checkbox which allows to use text- or image-only check/radioboxes which are styled by using any other component for the checkbox's label tag like button, message or segment icons, emojis or flag only need the image class for the label tag. A classic "ui image" works as well compact invisible keeps the width to the content
1 parent 0357b6d commit 9cfbc56

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

src/definitions/modules/checkbox.less

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@
5656
cursor: auto;
5757
position: relative;
5858
display: block;
59-
padding-left: @labelDistance;
6059
outline: none;
6160
font-size: @labelFontSize;
6261
}
6362

63+
.ui.checkbox:not(.invisible) label {
64+
padding-left: @labelDistance;
65+
}
66+
6467
.ui.checkbox label::before {
6568
position: absolute;
6669
top: 0;
@@ -130,8 +133,8 @@
130133
background: @checkboxHoverBackground;
131134
border-color: @checkboxHoverBorderColor;
132135
}
133-
.ui.checkbox label:hover,
134-
.ui.checkbox + label:hover {
136+
.ui.checkbox:not(.invisible) label:hover,
137+
.ui.checkbox:not(.invisible) + label:hover {
135138
color: @labelHoverColor;
136139
}
137140

@@ -146,7 +149,7 @@
146149
.ui.checkbox label:active::after {
147150
color: @checkboxPressedColor;
148151
}
149-
.ui.checkbox input:active ~ label {
152+
.ui.checkbox:not(.invisible) input:active ~ label {
150153
color: @labelPressedColor;
151154
}
152155

@@ -161,7 +164,7 @@
161164
.ui.checkbox input:focus ~ label::after {
162165
color: @checkboxFocusCheckColor;
163166
}
164-
.ui.checkbox input:focus ~ label {
167+
.ui.checkbox:not(.invisible) input:focus ~ label {
165168
color: @labelFocusColor;
166169
}
167170

@@ -652,6 +655,59 @@
652655
}
653656
}
654657
}
658+
& when (@variationCheckboxInvisible) {
659+
/* --------------
660+
Invisible
661+
--------------- */
662+
663+
.ui.invisible.checkbox {
664+
&:not(.compact) {
665+
display: block;
666+
}
667+
& input {
668+
left: -99999px;
669+
position: absolute;
670+
}
671+
& label::before,
672+
& label::after {
673+
display: none;
674+
}
675+
& label {
676+
transition: @invisibleCheckboxLabelTransition;
677+
}
678+
}
679+
.ui.ui.ui.ui.ui.invisible.checkbox input:not(:checked) {
680+
& + label {
681+
background: @invisibleCheckboxBackground;
682+
border-color: @invisibleCheckboxBorderColor;
683+
box-shadow: @invisibleCheckboxBoxShadow;
684+
color: @invisibleCheckboxColor;
685+
}
686+
&:not(:hover):focus + label:not(.image) {
687+
box-shadow: @invisibleCheckboxFocusBoxShadow;
688+
}
689+
& + label.image,
690+
.basic& + label {
691+
box-shadow: none;
692+
}
693+
}
694+
695+
.ui.invisible.checkbox input:not(:checked) {
696+
& + label.image {
697+
opacity: @invisibleCheckboxImageOpacityUnchecked;
698+
filter: @invisibleCheckboxImageFilterUnchecked;
699+
}
700+
&:not(:hover):focus + label.image {
701+
opacity: @invisibleCheckboxImageOpacityFocus;
702+
}
703+
& when (@variationCheckboxDisabled) {
704+
&[disabled] + label.image,
705+
.disabled& + label.image {
706+
opacity: @invisibleCheckboxImageOpacityUncheckedDisabled;
707+
}
708+
}
709+
}
710+
}
655711

656712
/* --------------------
657713
Size

src/themes/default/globals/variation.variables

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@
512512
@variationCheckboxDisabled: true;
513513
@variationCheckboxReadonly: true;
514514
@variationCheckboxInverted: true;
515+
@variationCheckboxInvisible: true;
515516
@variationCheckboxRadio: true;
516517
@variationCheckboxSlider: true;
517518
@variationCheckboxToggle: true;

src/themes/default/modules/checkbox.variables

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,18 @@
190190
Variations
191191
-------------------- */
192192

193+
/* Invisible */
194+
@invisibleCheckboxLabelTransition: all @defaultDuration @defaultEasing;
195+
@invisibleCheckboxBackground: transparent;
196+
@invisibleCheckboxBorderColor: transparent;
197+
@invisibleCheckboxColor: inherit;
198+
@invisibleCheckboxBoxShadow: 0 0 0 @borderWidth @borderColor inset;
199+
@invisibleCheckboxFocusBoxShadow: 0 0 0 @borderWidth @selectedBorderColor inset;
200+
@invisibleCheckboxImageOpacityUnchecked: 0.5;
201+
@invisibleCheckboxImageOpacityUncheckedDisabled: @invisibleCheckboxImageOpacityUnchecked * @disabledCheckboxOpacity;
202+
@invisibleCheckboxImageOpacityFocus: 0.75;
203+
@invisibleCheckboxImageFilterUnchecked: grayscale(1);
204+
193205
/* Inverted */
194206
@checkboxInvertedHoverBackground: @black;
195207

0 commit comments

Comments
 (0)