Skeleton
Installation
yarn add @chewy/kib-foundations
Import
@use '~@chewy/kib-foundations/src/skeleton';
Mixins
aspect-ratio
@mixin aspect-ratio($width, $height) { ... }
@mixin aspect-ratio($width, $height) { aspect-ratio: list.slash($width, $height); $do-math: meta.type-of($width) == 'number' and meta.type-of($height) == 'number'; @supports not (aspect-ratio: auto) { position: relative; &::before { display: block; content: ''; @if $do-math { padding-top: math.percentage(math.div($height, $width)); } @else { padding-top: calc((#{$height} / #{$width}) * 100%); } } } }
Description
Skeleton aspect-ratio
Parameters
parameter Name | parameter Description | parameter Type | parameter Default value |
---|---|---|---|
$width | width ratio | Number | — none |
$height | height ratio | Number | — none |
Example
skeleton with 16:9 aspect ratio
.video {
@include skeleton.base-styles;
@include skeleton.aspect-ratio(16, 9);
}
base-styles
@mixin base-styles($animation: true) { ... }
@mixin base-styles($animation: true) { display: block; width: 100%; max-width: 100%; margin-bottom: spacing.get('s2'); background-color: settings.$background-color-light-bg; @if $animation { /// @param {Boolean} $animation [true] - animation position: relative; overflow: hidden; @at-root { @keyframes wave { 0% { transform: translateX(-100%); } 60% { transform: translateX(100%); } 100% { transform: translateX(100%); } } } &::after { position: absolute; top: 0; right: 0; bottom: 0; left: 0; background-image: settings.$shimmer-gradient-light-bg; animation: wave settings.$speed linear settings.$delay infinite; content: ''; @media screen and (prefers-reduced-motion: reduce) { animation: none; } } } }
Description
Skeleton style generator
Parameters
parameter Name | parameter Description | parameter Type | parameter Default value |
---|---|---|---|
$animation | animation | Boolean | true |
Example
Basic styles with customized width and height
.selector {
@include skeleton.base-styles;
width: unit.rem(250px);
height: unit.rem(250px);
}
Requires
- [function]
get
- [variable]
background-color-light-bg
- [variable]
shimmer-gradient-light-bg
- [variable]
speed
- [variable]
delay
text-skeleton
@mixin text-skeleton($size: 'sm', $animation: true) { ... }
@mixin text-skeleton($size: 'sm', $animation: true) { @include base-styles($animation); height: map.get(settings.$heights, $size); border-radius: settings.$border-radius; }
Description
Skeleton height for text
Parameters
parameter Name | parameter Description | parameter Type | parameter Default value |
---|---|---|---|
$size | size preset alias | String | 'sm' |
$animation | animation | Boolean | true |
Example
skeleton with preset medium(md) text height
.title {
@include skeleton.text-skeleton(md);
}
Requires
- [mixin]
base-styles
- [function]
get
- [variable]
heights
- [variable]
size
- [variable]
border-radius
circular-skeleton
@mixin circular-skeleton($animation: true) { ... }
@mixin circular-skeleton($animation: true) { @include base-styles($animation); border-radius: 50%; }
Description
Circular skeleton
Parameters
parameter Name | parameter Description | parameter Type | parameter Default value |
---|---|---|---|
$animation | animation | Boolean | true |
Example
circular skeleton with user defined width and height
.avatar {
@include skeleton.circular-skeleton;
width: unit.rem(20px);
height: unit.rem(20px);
}
Requires
- [mixin]
base-styles
Css
position: relative; overflow: hidden; @at-root
position: relative; overflow: hidden; @at-root { ... }
position: relative; overflow: hidden; @at-root { @keyframes wave { 0% { transform: translateX(-100%); } 60% { transform: translateX(100%); } 100% { transform: translateX(100%); } } }
Variables
heights
$heights: (
sm: unit.rem(20px),
md: unit.rem(30px),
lg: unit.rem(50px)
) !default;
speed
$speed: 1.6s !default;
delay
$delay: 0.5s !default;
border-radius
$border-radius: unit.rem(4px) !default;
Description
Skeleton border radius
Type
Number
background-color-light-bg
$background-color-light-bg: color.get('ui-elements', 'skeleton', 'primary') !default;
background-color-dark-bg
Deprecated!
not in use
$background-color-dark-bg: color.get('ui-elements', 'skeleton', 'primary') !default;
Description
Skeleton background color on dark background
Type
Color
shimmer-gradient-light-bg
$shimmer-gradient-light-bg: linear-gradient(
90deg,
rgba(255, 255, 255, 0) 0,
#{color.get('ui-elements', 'skeleton', '02')} 20%,
#{color.get('ui-elements', 'skeleton', '03')} 60%,
rgba(255, 255, 255, 0)
) !default;