Adds CSS-based skeleton loader
What does this MR do?
Adds a gl-animation-skeleton-loader
utility class to create skeleton animations.
See Draft: GitLab UI integration branch for kpalchy... (gitlab!129285 - closed) for integration test and a example / comparison with previous <gl-skeleton-loader>
solution.
Currently common utility to use for "skeleton loading" is a <gl-skeleton-loader>
component, that works with SVG:
<gl-skeleton-loader :width="340" :height="100">
<rect width="340" height="16" rx="4" />
<rect y="30" width="118" height="16" rx="8" />
<rect x="122" y="30" width="130" height="16" rx="8" />
<rect y="62" width="38" height="16" rx="4" />
<circle cx="320" cy="68" r="16" />
</gl-skeleton-loader>
But there are a few problems with it:
- we can't use familiar css utils to represent HTML we're trying to mock, e.g. for
gl-rounded-full
we need a<circle />
- because SVG it's not as responsive as HTML/CSS is (it scales instead of adapting, + there's no
gl-lg-display-none
utils) - it's hard to read: all the x/y coordinates need to be calculated
With css-based animation we won't need a dedicated component, we'll be able to use familiar css utils, and it will be responsive. See screenshots section for more.
Screenshots or screen recordings
Simple example:
<div class="gl-display-flex gl-flex-direction-column gl-gap-2">
<div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2"></div>
<div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2"></div>
<div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2"></div>
</div>
A more complex example:
<div class="gl-display-flex gl-flex-direction-column gl-gap-2 gl-w-30">
<div class="gl-animate-skeleton-loader gl-h-8 gl-rounded-base gl-mb-4"></div>
<div class="gl-display-flex gl-flex-direction-row gl-gap-2">
<div class="gl-animate-skeleton-loader gl-h-8 gl-w-8 gl-rounded-full"></div>
<div class="gl-flex-grow-1" style="animation-delay: 100ms">
<div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2"></div>
<div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2"></div>
<div class="gl-animate-skeleton-loader gl-display-inline-block gl-h-4 gl-w-10 gl-rounded-base gl-my-2"></div>
<div class="gl-animate-skeleton-loader gl-display-inline-block gl-h-4 gl-w-10 gl-rounded-base gl-my-2" style="animation-delay: 250ms"></div>
</div>
</div>
</div>
Testing the animation
Apply this patch
patch
diff --git a/src/components/base/skeleton_loader/skeleton_loader.scss b/src/components/base/skeleton_loader/skeleton_loader.scss
index 6850a395..7cb2ce74 100644
--- a/src/components/base/skeleton_loader/skeleton_loader.scss
+++ b/src/components/base/skeleton_loader/skeleton_loader.scss
@@ -15,3 +15,8 @@
@include gl-stop-color-gray-50;
}
}
+
+.gl-animate-skeleton-loader {
+ background-color: red;
+ background-image: linear-gradient(to right, red 0, blue 23%, blue 27%, red 50%);
+}
\ No newline at end of file
diff --git a/src/components/base/skeleton_loader/skeleton_loader.stories.js b/src/components/base/skeleton_loader/skeleton_loader.stories.js
index a219088e..7182a8f0 100644
--- a/src/components/base/skeleton_loader/skeleton_loader.stories.js
+++ b/src/components/base/skeleton_loader/skeleton_loader.stories.js
@@ -2,6 +2,41 @@ import { makeContainer } from '../../../utils/story_decorators/container';
import GlSkeletonLoader from './skeleton_loader.vue';
import readme from './skeleton_loader.md';
+export const CssTest1 = () => ({
+template: `
+<div class="gl-display-flex gl-flex-direction-column gl-gap-2">
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 25px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 50px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 100px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 150px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 200px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 250px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 300px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 350px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 400px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 450px;"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2" style="width: 500px;"></div>
+</div>
+`
+})
+
+export const CssTest2 = () => ({
+template: `
+<div class="gl-display-flex gl-flex-direction-column gl-gap-2 gl-w-30">
+ <div class="gl-animate-skeleton-loader gl-h-8 gl-rounded-base gl-mb-4"></div>
+ <div class="gl-display-flex gl-flex-direction-row gl-gap-2">
+ <div class="gl-animate-skeleton-loader gl-h-8 gl-w-8 gl-rounded-full"></div>
+ <div class="gl-flex-grow-1" style="animation-delay: 100ms">
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2"></div>
+ <div class="gl-animate-skeleton-loader gl-h-4 gl-rounded-base gl-my-2"></div>
+ <div class="gl-animate-skeleton-loader gl-display-inline-block gl-h-4 gl-w-10 gl-rounded-base gl-my-2"></div>
+ <div class="gl-animate-skeleton-loader gl-display-inline-block gl-h-4 gl-w-10 gl-rounded-base gl-my-2" style="animation-delay: 250ms"></div>
+ </div>
+ </div>
+</div>
+`
+})
+
const defaultValue = (prop) => GlSkeletonLoader.props[prop].default;
const generateProps = ({
Run npm run storybook
, open http://localhost:9001/?path=/docs/base-skeleton-loader--docs
Integration merge requests
-
GitLab: gitlab!129285 (closed) (for test only) -
CustomersDot: mr_url -
Status Page: mr_url
Does this MR meet the acceptance criteria?
This checklist encourages the authors, reviewers, and maintainers of merge requests (MRs) to confirm changes were analyzed for conformity with the project's guidelines, security and accessibility.
Toggle the acceptance checklist
Conformity
-
Code review guidelines. -
GitLab UI's contributing guidelines. -
If it changes a Pajamas-compliant component's look & feel, the MR has been reviewed by a UX designer. -
If it changes GitLab UI's documentation guidelines, the MR has been reviewed by a Technical Writer. -
If the MR changes a component's API, integration MR(s) have been opened (see integration merge requests above). -
Added the ~"component:*"
label(s) if applicable.
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
Security reports checked/validated by a reviewer from the AppSec team
Accessibility
If this MR adds or modifies a component, take a few moments to review the following:
-
All actions and functionality can be done with a keyboard. -
Links, buttons, and controls have a visible focus state. -
All content is presented in text or with a text equivalent. For example, alt text for SVG, or aria-label
for icons that have meaning or perform actions. -
Changes in a component’s state are announced by a screen reader. For example, changing aria-expanded="false"
toaria-expanded="true"
when an accordion is expanded. -
Color combinations have sufficient contrast.
This is kinda like https://xkcd.com/927/ ...