Merge pull request #17523 from atownson/issue_16009

Closes #16009 - Added styling to form templates to enable floating button groups
This commit is contained in:
Jeremy Stretch 2024-10-15 13:16:02 -04:00 committed by GitHub
commit aab96565f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 80 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,42 @@
import { getElements } from '../util';
/**
* Conditionally add and remove a class that will float the button group
* based on whether or not items in the list are checked
*/
function toggleFloat(): void {
const checkedCheckboxes = document.querySelector<HTMLInputElement>(
'input[type="checkbox"][name="pk"]:checked',
);
const buttonGroup = document.querySelector<HTMLDivElement>(
'div.form.form-horizontal div.btn-list',
);
if (!buttonGroup) {
return;
}
const isFloating = buttonGroup.classList.contains('btn-float-group-left');
if (checkedCheckboxes !== null && !isFloating) {
buttonGroup.classList.add('btn-float-group-left');
} else if (checkedCheckboxes === null && isFloating) {
buttonGroup.classList.remove('btn-float-group-left');
}
}
/**
* Initialize floating bulk buttons.
*/
export function initFloatBulk(): void {
for (const element of getElements<HTMLInputElement>('input[type="checkbox"][name="pk"]')) {
element.addEventListener('change', () => {
toggleFloat();
});
}
// Handle the select-all checkbox
for (const element of getElements<HTMLInputElement>(
'table tr th > input[type="checkbox"].toggle',
)) {
element.addEventListener('change', () => {
toggleFloat();
});
}
}

View File

@ -3,6 +3,7 @@ import { initDepthToggle } from './depthToggle';
import { initMoveButtons } from './moveOptions'; import { initMoveButtons } from './moveOptions';
import { initReslug } from './reslug'; import { initReslug } from './reslug';
import { initSelectAll } from './selectAll'; import { initSelectAll } from './selectAll';
import { initFloatBulk } from './floatBulk';
import { initSelectMultiple } from './selectMultiple'; import { initSelectMultiple } from './selectMultiple';
import { initMarkdownPreviews } from './markdownPreview'; import { initMarkdownPreviews } from './markdownPreview';
import { initSecretToggle } from './secretToggle'; import { initSecretToggle } from './secretToggle';
@ -14,6 +15,7 @@ export function initButtons(): void {
initReslug, initReslug,
initSelectAll, initSelectAll,
initSelectMultiple, initSelectMultiple,
initFloatBulk,
initMoveButtons, initMoveButtons,
initMarkdownPreviews, initMarkdownPreviews,
initSecretToggle, initSecretToggle,

View File

@ -34,6 +34,28 @@ span.color-label {
letter-spacing: .15rem; letter-spacing: .15rem;
} }
// A floating div for form buttons
.btn-float-group {
position: sticky;
bottom: 10px;
z-index: 2;
}
.btn-float-group-left {
@extend .btn-float-group;
float: left;
}
.btn-float-group-right {
@extend .btn-float-group;
float: right;
}
// Override a transparent background
.btn-float {
--tblr-btn-bg: var(--#{$prefix}bg-surface-tertiary) !important;
}
.logo { .logo {
height: 80px; height: 80px;
} }

View File

@ -102,8 +102,8 @@ Context:
{% endif %} {% endif %}
<div class="text-end"> <div class="btn-float-group-right">
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a> <a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
<button type="submit" name="_apply" class="btn btn-primary">{% trans "Apply" %}</button> <button type="submit" name="_apply" class="btn btn-primary">{% trans "Apply" %}</button>
</div> </div>

View File

@ -67,9 +67,9 @@ Context:
{% endblock form %} {% endblock form %}
</div> </div>
<div class="text-end my-3"> <div class="btn-float-group-right">
{% block buttons %} {% block buttons %}
<a href="{{ return_url }}" class="btn btn-outline-secondary">{% trans "Cancel" %}</a> <a href="{{ return_url }}" class="btn btn-outline-secondary btn-float">{% trans "Cancel" %}</a>
{% if object.pk %} {% if object.pk %}
<button type="submit" name="_update" class="btn btn-primary"> <button type="submit" name="_update" class="btn btn-primary">
{% trans "Save" %} {% trans "Save" %}
@ -79,7 +79,7 @@ Context:
<button type="submit" name="_create" class="btn btn-primary"> <button type="submit" name="_create" class="btn btn-primary">
{% trans "Create" %} {% trans "Create" %}
</button> </button>
<button type="submit" name="_addanother" class="btn btn-outline-primary"> <button type="submit" name="_addanother" class="btn btn-outline-primary btn-float">
{% trans "Create & Add Another" %} {% trans "Create & Add Another" %}
</button> </button>
</div> </div>

View File

@ -121,7 +121,7 @@ Context:
{# /Objects table #} {# /Objects table #}
{# Form buttons #} {# Form buttons #}
<div class="btn-list d-print-none mt-2"> <div class="btn-list d-print-none">
{% block bulk_buttons %} {% block bulk_buttons %}
<div class="bulk-action-buttons"> <div class="bulk-action-buttons">
{% if 'bulk_edit' in actions %} {% if 'bulk_edit' in actions %}

View File

@ -37,13 +37,13 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
<div class="card-footer text-end d-print-none border-0"> </div>
<button type="button" class="btn btn-outline-danger m-1" data-reset-select> <div class="btn-float-group-right me-1">
<button type="button" class="btn btn-outline-danger btn-float" data-reset-select>
<i class="mdi mdi-backspace"></i> {% trans "Reset" %} <i class="mdi mdi-backspace"></i> {% trans "Reset" %}
</button> </button>
<button type="submit" class="btn btn-primary m-1"> <button type="submit" class="btn btn-primary">
<i class="mdi mdi-magnify"></i> {% trans "Search" %} <i class="mdi mdi-magnify"></i> {% trans "Search" %}
</button> </button>
</div> </div>
</div>
</form> </form>