-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HTMX loading styles and related documentation in styleguide #35419
Changes from all commits
b9079d7
736f442
3837b2d
e99781e
5d27879
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
@mixin htmx-spinner($width) { | ||
position: absolute; | ||
height: $width; | ||
width: $width; | ||
$offset: $width / 2; | ||
left: calc(50% - $offset); | ||
top: calc(50% - $offset); | ||
} | ||
|
||
form.htmx-request { | ||
button[type="submit"] { | ||
position: relative; | ||
&::before { | ||
content: " "; | ||
@extend .spinner-border; | ||
@extend .spinner-border-sm; | ||
@include htmx-spinner(22px); | ||
} | ||
&.btn-sm::before { | ||
@include htmx-spinner(18px); | ||
} | ||
} | ||
.input-group button[type="submit"]::before { | ||
vertical-align: -0.28em; | ||
} | ||
} | ||
|
||
.htmx-request.page-link { | ||
background-color: $blue-300; | ||
color: $white; | ||
position: relative; | ||
|
||
&::after { | ||
content: " "; | ||
@extend .spinner-border; | ||
@extend .spinner-border-sm; | ||
@include htmx-spinner(22px); | ||
} | ||
} | ||
|
||
.htmx-request[type="checkbox"] { | ||
position: relative; | ||
|
||
&::after { | ||
content: " "; | ||
color: $blue-400; | ||
@extend .spinner-border; | ||
@extend .spinner-border-sm; | ||
@include htmx-spinner(22px); | ||
} | ||
} | ||
|
||
.htmx-request.form-check-input { | ||
&::after { | ||
@include htmx-spinner(30px); | ||
} | ||
} | ||
|
||
button.htmx-request { | ||
position: relative; | ||
&::before { | ||
content: " "; | ||
@extend .spinner-border; | ||
@extend .spinner-border-sm; | ||
@include htmx-spinner(22px); | ||
opacity: .5; | ||
} | ||
|
||
&.btn-sm::before { | ||
@include htmx-spinner(18px); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{% if content.partial %} | ||
<div> | ||
{% include content.partial %} | ||
</div> | ||
{% endif %} | ||
<div class="pb-3"> | ||
{% include 'styleguide/bootstrap5/partials/readable_code_block.html' with content=content.code language=content.language %} | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<button | ||
class="btn btn-primary" type="button" | ||
hx-get="{% url 'styleguide_a_hanging_view' %}" | ||
hx-disabled-elt="this" | ||
hx-swap="none" {# example view returns nothing to display #} | ||
> | ||
Click Me | ||
</button> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="form-check"> | ||
<input | ||
class="form-check-input" type="checkbox" value="" id="flexCheckDefault" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. javascript standard is to use CamelCase, and this id is primarily used with javascript, not css |
||
hx-get="{% url 'styleguide_a_hanging_view' %}" | ||
hx-disabled-elt="this" | ||
hx-swap="none" {# example view returns nothing to display #} | ||
/> | ||
<label class="form-check-label" for="flexCheckDefault"> | ||
Try to check me | ||
</label> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<form | ||
hx-get="{% url 'styleguide_a_hanging_view' %}" | ||
hx-disabled-elt="find button" | ||
hx-swap="none" {# example view returns nothing to display #} | ||
> | ||
<div class="mb-3"> | ||
<label for="id_value" class="form-label">Value</label> | ||
<input type="text" name="value" class="textinput form-control" id="id_value"/> | ||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copied from crispy form, the id doesn't matter. ( still in group review ) |
||
</div> | ||
<button class="btn btn-primary" type="submit"> | ||
Submit Me! | ||
</button> | ||
</form> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
{% extends 'styleguide/bootstrap5/base.html' %} | ||
{% load hq_shared_tags %} | ||
|
||
{% block head %} | ||
<script src="{% static 'htmx.org/dist/htmx.min.js' %}"></script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this loaded somewhere else prior to this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Styleguide is not using webpack, so we need to import the library here, we might migrate styleguide to webpack in the future. |
||
{% endblock head %} | ||
|
||
{% block intro %} | ||
<h1 class="sg-title mb-0" id="content">HTMX and Alpine</h1> | ||
|
@@ -31,6 +36,14 @@ <h5 class="my-2 ms-3">On this page</h5> | |
</ul> | ||
</li> | ||
<li><a href="#debugging">Debugging During Development</a></li> | ||
<li> | ||
<a href="#loading-indicators">Loading Indicators</a> | ||
<ul> | ||
<a href="#button-loading">Buttons</a></li> | ||
<a href="#checkbox-loading">Checkboxes</a></li> | ||
<a href="#form-loading">Forms</a></li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</nav> | ||
{% endblock toc %} | ||
|
@@ -241,4 +254,49 @@ <h2 id="debugging" class="pt-4"> | |
You can check out the <code>HqHtmxDebugMixin</code> directly for additional documentation and usage | ||
guidance. | ||
</p> | ||
|
||
<h2 id="loading-indicators" class="pt-4"> | ||
Loading Indicators | ||
</h2> | ||
<p> | ||
You can use the <code>hx-indicator</code> attribute | ||
(<a href="https://htmx.org/attributes/hx-indicator/" target="_blank">see docs here</a>) | ||
to mark which element gets the <code>htmx-request</code> class appended to it during a request. | ||
We've added custom styling to <code>_htmx.scss</code> to support the common states outlined | ||
later in this section. | ||
</p> | ||
<p> | ||
By default, if an element triggers an HTMX request, it will automatically get the <code>htmx-request</code> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Emphasize the default behavior |
||
CSS class applied to it. No extra usage of the <code>hx-indicator</code> attribute is necessary. The | ||
example submitting elements below showcase this default behavior <strong>without</strong> the need for | ||
specific <code>hx-indicator</code> usage. | ||
</p> | ||
<p> | ||
It's often a great idea to pair button requests with <code>hx-disabled-elt="this"</code> | ||
(<a href="https://htmx.org/attributes/hx-disabled-elt/" target="_blank`">see docs for hx-disabled-elt</a>), | ||
like the examples below, so that the requesting element or related element is disabled during the request. | ||
</p> | ||
<h3 id="button-loading" class="pt-4"> | ||
Buttons | ||
</h3> | ||
{% include 'styleguide/bootstrap5/code_display.html' with content=examples.loading_button %} | ||
|
||
<h3 id="checkbox-loading" class="pt-4"> | ||
Checkboxes | ||
</h3> | ||
{% include 'styleguide/bootstrap5/code_display.html' with content=examples.loading_checkbox %} | ||
|
||
<h3 id="form-loading" class="pt-4"> | ||
Forms | ||
</h3> | ||
<p> | ||
In the example below, note that the <code>form</code> is the triggering element, so the | ||
<code>hx-disabled-elt</code> value is set to <code>find button</code> to disable all button children | ||
of that form during an HTMX request. Since <code>form</code> is the submitting element, by default | ||
it has the <code>htmx-request</code> class applied. Our styles ensure that | ||
<code>button type="submit"</code> elements of a submitting form show the loading indicator during | ||
an HTMX request. | ||
</p> | ||
{% include 'styleguide/bootstrap5/code_display.html' with content=examples.loading_form %} | ||
|
||
{% endblock content %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the various
px
sizing is this going to look right if it gets used on alternate sized inputs e.g.btn-sm
orbtn-lg
? Not that we do it often, just wondering out loud.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Evan, we asked Biyeun in group review, there is
htmx-spinner(18px)
forbtn-sm
. Otherwise, it will always behtmx-spinner(22px)
. The way the mixin is constructed only acceptpx
, due to the usage ofcalc
.