Skip to content

Commit

Permalink
Add checkbox styling
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Oct 7, 2021
1 parent ddd81ee commit 00eac4f
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 12 deletions.
26 changes: 14 additions & 12 deletions core/src/main/resources/lib/form/checkbox.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ THE SOFTWARE.
<st:attribute name="negative" />
<st:attribute name="readonly">
If set to true, this will take precedence over the onclick attribute and prevent the state of the checkbox from being changed.

Note: if you want an actual read only checkbox then add:
&lt;j:set var="readOnlyMode" value="true"/&gt; inside your entry tag
See https://www.jenkins.io/doc/developer/views/read-only/#enabling-read-only-view-support
Expand All @@ -67,17 +67,19 @@ THE SOFTWARE.
<j:set var="default" value="${attrs.default ?: false}"/>
<j:set var="value" value="${attrs.checked ?: instance[attrs.field] ?: default}"/>

<input type="checkbox"
name="${name}"
value="${attrs.value}"
title="${attrs.tooltip}"
onclick="${attrs.readonly=='true' ? 'return false;' : attrs.onclick}" id="${attrs.id}" class="${attrs.class} ${attrs.negative!=null ? 'negative' : null} ${attrs.checkUrl!=null?'validated':''}"
checkUrl="${attrs.checkUrl}" checkDependsOn="${attrs.checkDependsOn}" json="${attrs.json}"
disabled="${readOnlyMode ? 'true' : null}"
checked="${value ? 'true' : null}"/>
<label class="attach-previous setting-checkbox ${attrs.title == null ? 'js-checkbox-label-empty' : ''}"
title="${attrs.tooltip}">${attrs.title}</label>
<span class="jenkins-checkbox">
<input type="checkbox"
name="${name}"
value="${attrs.value}"
title="${attrs.tooltip}"
onclick="${attrs.readonly=='true' ? 'return false;' : attrs.onclick}" id="${attrs.id}" class="${attrs.class} ${attrs.negative!=null ? 'negative' : null} ${attrs.checkUrl!=null?'validated':''}"
checkUrl="${attrs.checkUrl}" checkDependsOn="${attrs.checkDependsOn}" json="${attrs.json}"
disabled="${readOnlyMode ? 'true' : null}"
checked="${value ? 'true' : null}"/>
<label class="attach-previous ${attrs.title == null ? 'js-checkbox-label-empty' : ''}"
title="${attrs.tooltip}">${attrs.title}</label>
</span>
<j:if test="${customizedFields != null and attrs.field != null and value != default}">
<j:mute>${customizedFields.add(name)}</j:mute>
</j:if>
</j:jelly>
</j:jelly>
178 changes: 178 additions & 0 deletions war/src/main/less/modules/form.less
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,184 @@
}
}

.jenkins-checkbox {
position: relative;
display: inline-block;
}

.jenkins-checkbox input {
position: absolute;

width: 1px;
height: 1px;

// If margin is set to a negative value it can cause text to be announced in
// the wrong order in VoiceOver for OSX
margin: 0;
padding: 0;

overflow: hidden;
clip: rect(0 0 0 0);
clip-path: inset(50%);

&:checked + label:before {
border: 11px solid var(--focus-input-border);
}

&:checked + label:after {
transform: scale(1)!important;
}
}

.jenkins-checkbox label {
position: relative;
display: flex;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
cursor: pointer;
line-height: 22px;
font-weight: 600;

&::before {
display: inline-block;
content: "";
position: relative;
min-width: 22px;
min-height: 22px;
border: 2px solid var(--input-border);
border-radius: 6px;
transition: 0.2s ease;
margin-right: 11px;
box-shadow: 0 0 0 10px transparent;
}

&::after {
content: "";
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 22px;
color: white;
transition: 0.2s ease;
transform: scale(0);
font-size: 12px;
}

&:hover {
&::before {
border: 5px solid var(--input-border-hover);
}
}

&:active, &:focus {
&::before {
box-shadow: 0 0 0 5px var(--focus-input-glow);
}
}
}

.jenkins-checkbox__description {
margin-top: 15px;
margin-left: 65px;
opacity: 0.75;
}

.jenkins-toggle-switch {
position: relative;
display: inline-block;
}

.jenkins-toggle-switch input {
position: absolute;

width: 1px;
height: 1px;

// If margin is set to a negative value it can cause text to be announced in
// the wrong order in VoiceOver for OSX
margin: 0;
padding: 0;

overflow: hidden;
clip: rect(0 0 0 0);
clip-path: inset(50%);

&:checked + label:before {
background-color: var(--focus-input-border);
}

&:checked + label:after {
left: 25px;
color: var(--focus-input-border);
transform: rotate(0deg);
}

&:active + label:before, &:focus + label:before {
box-shadow: 0 0 0 5px var(--focus-input-glow);
}
}

.jenkins-toggle-switch label {
position: relative;
display: flex;
align-items: flex-start;
justify-content: flex-start;
margin: 0;
cursor: pointer;
line-height: 30px;
font-weight: bold;

&::before {
display: inline-block;
content: "";
position: relative;
min-width: 50px;
min-height: 30px;
background: var(--input-border);
border-radius: 19px;
transition: 0.2s ease;
margin-right: 15px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05), 0 0 0 10px transparent;
}

&::after {
content: "";
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 5px;
left: 5px;
width: 20px;
height: 20px;
background: var(--background);
border-radius: 19px;
color: transparent;
transition: 0.2s ease;
transform: rotate(-90deg);
font-size: 12px;
font-weight: bold;
padding-top: 2px;
box-shadow: -1px 0 0 rgba(0, 0, 0, 0.1);
}

&:hover::before {
background-color: var(--input-border-hover);
}

&:active, &:focus {
&::before {
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05), 0 0 0 5px var(--focus-input-glow);
}
}
}

.jenkins-button {
position: relative;
display: inline-flex;
Expand Down

0 comments on commit 00eac4f

Please sign in to comment.