Skip to content

Commit

Permalink
Restyle file uploads to fit in with modern forms UI (#7452)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Brandes <brandes.alexander@web.de>
Co-authored-by: Tim Jacomb <timjacomb1@gmail.com>
Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 30, 2022
1 parent f98c276 commit ce4f9de
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/PluginManager/advanced.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ THE SOFTWARE.
<div style="margin-bottom: 1em;">
${%deploytext}
</div>
<f:entry title="${%File}">
<input type="file" name="name" class="jenkins-input" accept=".hpi,.jpi"/>
<f:entry title="${%File}" field="name">
<f:file accept=".hpi,.jpi" />
</f:entry>
<p>${%Or}</p>
<f:entry title="${%URL}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ THE SOFTWARE.
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<j:set var="escapeEntryTitleAndDescription" value="false"/>
<f:entry title="${h.escape(it.name)}" description="${it.formattedDescription}">
<f:entry title="${h.escape(it.name)}" description="${it.formattedDescription}" field="file">
<div name="parameter">
<input type="hidden" name="name" value="${it.name}" />
<input name="file" type="file" jsonAware="true" />
<f:file jsonAware="true" />
</div>
</f:entry>
</j:jelly>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ THE SOFTWARE.
${%description} (<a href="${%fingerprint.link}">${%more details}</a>)
</div>
</f:block>
<f:entry title="${%File to check}">
<input type="file" name="name" class="jenkins-input" />
<f:entry title="${%File to check}" field="name">
<f:file />
</f:entry>
<f:block>
<f:submit value="${%Check}" />
Expand Down
51 changes: 51 additions & 0 deletions core/src/main/resources/lib/form/file.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--
The MIT License
Copyright (c) 2022, Jenkins project contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form">
<st:documentation>
Generates an input field <code>&lt;input type="file" ... /></code>

<st:attribute name="field">
Used for databinding.
</st:attribute>
<st:attribute name="jsonAware">
Enable structured form submission.
</st:attribute>
<st:attribute name="accept">
Defines the file types the file input should accept. This string is a comma-separated list.
</st:attribute>
@since TODO
</st:documentation>
<f:prepareDatabinding />

<j:set var="name" value="${attrs.name ?: attrs.field}"/>

<input name="${name}"
type="file"
jsonAware="${attrs.jsonAware}"
class="jenkins-file-upload"
accept="${attrs.accept}"
/>
</j:jelly>
2 changes: 1 addition & 1 deletion war/src/main/less/base/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pre.console {
}

.setting-name,
.setting-main > input,
.setting-main > input:not([type="file"]),
.setting-main > textarea {
vertical-align: middle;
margin-top: 0;
Expand Down
62 changes: 62 additions & 0 deletions war/src/main/less/form/file-upload.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.jenkins-file-upload {
position: relative;
width: 100%;
margin: -10px 0 0 -10px;
padding: 10px 0 10px 10px;
outline: none;
background: transparent;

&::before {
content: "";
position: absolute;
display: block;
left: calc(10px + 0.9rem);
width: 1rem;
height: 36px;
background: currentColor;
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M320 367.79h76c55 0 100-29.21 100-83.6s-53-81.47-96-83.6c-8.89-85.06-71-136.8-144-136.8-69 0-113.44 45.79-128 91.2-60 5.7-112 43.88-112 106.4s54 106.4 120 106.4h56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='40'/%3E%3Cpath fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='40' d='M320 255.79l-64-64-64 64M256 448.21V207.79'/%3E%3C/svg%3E");
mask-position: center;
mask-repeat: no-repeat;
pointer-events: none;
}

&::file-selector-button {
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
outline: none;
margin: 0 1rem 0 0;
padding: 0.5rem 0.85rem 0.5rem 2.5rem;
// Firefox doesn't support pseudo elements on inputs so don't increase padding to accommodate
@supports (-moz-appearance: none) {
padding: 0.5rem 0.85rem;
}

font-size: 0.8rem;
font-weight: 500;
color: var(--text-color);
border-radius: 0.66rem;
cursor: pointer;
min-height: 36px;
white-space: nowrap;
background: var(--button-background);
transition: var(--standard-transition);
box-shadow: 0 0 0 10px transparent;

&:hover {
background: var(--button-background--hover);
}

&:active {
background: var(--button-background--active);
box-shadow: 0 0 0 5px var(--button-box-shadow--focus);
}
}

&:focus-visible {
&::file-selector-button {
box-shadow: 0 0 0 0.2rem var(--text-color) !important;
}
}
}
1 change: 1 addition & 0 deletions war/src/main/less/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@import url("./base/yui-compatibility");
@import url("./form/checkbox");
@import url("./form/codemirror");
@import url("./form/file-upload");
@import url("./form/input");
@import url("./form/layout");
@import url("./form/radio");
Expand Down

0 comments on commit ce4f9de

Please sign in to comment.