-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from lumapps/feat/skeleton
feat(skeleton): create circle, rectangular and typography variants
- Loading branch information
Showing
14 changed files
with
616 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
packages/lumx-core/src/scss/components/skeleton/lumapps/_index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* ========================================================================== | ||
Skeleton | ||
========================================================================== */ | ||
|
||
@keyframes skeleton-loading { | ||
0% { | ||
opacity: 1; | ||
} | ||
50% { | ||
opacity: 0.5; | ||
} | ||
100% { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
/* Circle | ||
========================================================================== */ | ||
|
||
.#{$lumx-base-prefix}-skeleton-circle { | ||
animation: skeleton-loading 1s ease-in-out 0s infinite; | ||
border-radius: 50%; | ||
|
||
&--theme-light { | ||
background-color: lumx-color-variant('dark', 'L5'); | ||
} | ||
|
||
&--theme-dark { | ||
background-color: lumx-color-variant('light', 'L5'); | ||
} | ||
} | ||
|
||
@each $key, $size in $lumx-sizes { | ||
.#{$lumx-base-prefix}-skeleton-circle--size-#{$key} { | ||
width: map-get($lumx-sizes, $key); | ||
height: map-get($lumx-sizes, $key); | ||
} | ||
} | ||
|
||
/* Rectangle | ||
========================================================================== */ | ||
|
||
.#{$lumx-base-prefix}-skeleton-rectangle { | ||
animation: skeleton-loading 1s ease-in-out 0s infinite; | ||
|
||
&--variant-rounded { | ||
border-radius: $lumx-border-radius; | ||
} | ||
|
||
&--theme-light { | ||
background-color: lumx-color-variant('dark', 'L5'); | ||
} | ||
|
||
&--theme-dark { | ||
background-color: lumx-color-variant('light', 'L5'); | ||
} | ||
} | ||
|
||
@each $key, $size in $lumx-sizes { | ||
.#{$lumx-base-prefix}-skeleton-rectangle--width-#{$key} { | ||
width: map-get($lumx-sizes, $key); | ||
} | ||
|
||
.#{$lumx-base-prefix}-skeleton-rectangle--height-#{$key} { | ||
height: map-get($lumx-sizes, $key); | ||
} | ||
|
||
.#{$lumx-base-prefix}-skeleton-rectangle--variant-pill.#{$lumx-base-prefix}-skeleton-rectangle--height-#{$key} { | ||
border-radius: map-get($lumx-sizes, $key) / 2; | ||
} | ||
} | ||
|
||
@each $key, $aspect-ratio in $lumx-thumbnail-aspect-ratio { | ||
.#{$lumx-base-prefix}-skeleton-rectangle--aspect-ratio-#{$key} .#{$lumx-base-prefix}-skeleton-rectangle__inner { | ||
padding-top: $aspect-ratio; | ||
} | ||
} | ||
|
||
/* Typography | ||
========================================================================== */ | ||
|
||
$typography-skeleton-size: ( | ||
'display1': 24px, | ||
'headline': 20px, | ||
'title': 14px, | ||
'subtitle2': 12px, | ||
'subtitle1': 10px, | ||
'body2': 12px, | ||
'body1': 10px, | ||
'caption': 8px, | ||
'overline': 8px, | ||
); | ||
|
||
.#{$lumx-base-prefix}-skeleton-typography { | ||
$self: &; | ||
|
||
display: flex; | ||
align-items: center; | ||
|
||
&__inner { | ||
width: 100%; | ||
animation: skeleton-loading 1s ease-in-out 0s infinite; | ||
border-radius: $lumx-border-radius; | ||
|
||
#{$self}--theme-light & { | ||
background-color: lumx-color-variant('dark', 'L5'); | ||
} | ||
|
||
#{$self}--theme-dark & { | ||
background-color: lumx-color-variant('light', 'L5'); | ||
} | ||
} | ||
} | ||
|
||
@each $key, $line-height in $lumx-typography-line-height { | ||
.#{$lumx-base-prefix}-skeleton-typography--typography-#{$key} { | ||
height: map-get($lumx-typography-line-height, $key); | ||
} | ||
|
||
.#{$lumx-base-prefix}-skeleton-typography--typography-#{$key} .#{$lumx-base-prefix}-skeleton-typography__inner { | ||
height: map-get($typography-skeleton-size, $key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
packages/lumx-react/src/components/skeleton/Skeleton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import { | ||
Alignment, | ||
AspectRatio, | ||
Button, | ||
FlexBox, | ||
Orientation, | ||
Size, | ||
SkeletonCircle, | ||
SkeletonRectangle, | ||
SkeletonRectangleVariant, | ||
SkeletonTypography, | ||
Thumbnail, | ||
Typography, | ||
} from '@lumx/react'; | ||
|
||
export default { title: 'LumX components/skeleton/Skeleton' }; | ||
|
||
const variants = [ | ||
SkeletonRectangleVariant.squared, | ||
SkeletonRectangleVariant.rounded, | ||
SkeletonRectangleVariant.pill, | ||
] as const; | ||
const sizes = [Size.xxs, Size.xs, Size.s, Size.m, Size.l, Size.xl, Size.xxl] as const; | ||
const aspectRatios = [AspectRatio.vertical, AspectRatio.square, AspectRatio.horizontal] as const; | ||
|
||
export const skeletonCircle = ({ theme }: any) => ( | ||
<FlexBox orientation={Orientation.horizontal}> | ||
{sizes.map((size) => ( | ||
<SkeletonCircle theme={theme} key={size} size={size} className="lumx-spacing-margin" /> | ||
))} | ||
</FlexBox> | ||
); | ||
|
||
export const skeletonRectangle = ({ theme }: any) => ( | ||
<> | ||
Sizes: | ||
<FlexBox orientation={Orientation.horizontal}> | ||
{sizes.map((size) => ( | ||
<SkeletonRectangle | ||
key={size} | ||
className="lumx-spacing-margin" | ||
theme={theme} | ||
height={size} | ||
width={size} | ||
/> | ||
))} | ||
</FlexBox> | ||
Variants: | ||
<FlexBox orientation={Orientation.horizontal}> | ||
{variants.map((variant) => ( | ||
<SkeletonRectangle | ||
key={variant} | ||
className="lumx-spacing-margin" | ||
theme={theme} | ||
width={Size.xl} | ||
height={Size.m} | ||
variant={variant} | ||
/> | ||
))} | ||
</FlexBox> | ||
Ratios: | ||
<FlexBox orientation={Orientation.horizontal} hAlign={Alignment.top}> | ||
{aspectRatios.map((aspectRatio) => ( | ||
<SkeletonRectangle | ||
key={aspectRatio} | ||
className="lumx-spacing-margin" | ||
theme={theme} | ||
width={Size.xl} | ||
aspectRatio={aspectRatio} | ||
/> | ||
))} | ||
</FlexBox> | ||
</> | ||
); | ||
|
||
export const skeletonTypography = ({ theme }: any) => ( | ||
<> | ||
<SkeletonTypography | ||
theme={theme} | ||
typography={Typography.title} | ||
width="30%" | ||
className="lumx-spacing-margin-bottom" | ||
/> | ||
<SkeletonTypography theme={theme} typography={Typography.body1} /> | ||
<SkeletonTypography theme={theme} typography={Typography.body1} /> | ||
<SkeletonTypography theme={theme} typography={Typography.body1} /> | ||
<SkeletonTypography theme={theme} typography={Typography.body1} width="70%" /> | ||
</> | ||
); | ||
|
||
export const skeletonRectangleLoadingThumbnail = ({ theme }: any) => { | ||
const [loading, setLoading] = useState(true); | ||
const fakeLoad = () => { | ||
setLoading(true); | ||
setTimeout(() => { | ||
setLoading(false); | ||
}, 2000); | ||
}; | ||
useEffect(fakeLoad, []); | ||
const size = Size.xl; | ||
|
||
return ( | ||
<> | ||
<Button onClick={fakeLoad}>Reload</Button> (fake 2sec loading) | ||
<Thumbnail | ||
style={{ display: loading ? 'none' : undefined }} | ||
image="https://picsum.photos/72/72/?random" | ||
aspectRatio={AspectRatio.square} | ||
size={size} | ||
/> | ||
{loading && <SkeletonRectangle theme={theme} width={size} aspectRatio={AspectRatio.square} />} | ||
</> | ||
); | ||
}; |
38 changes: 38 additions & 0 deletions
38
packages/lumx-react/src/components/skeleton/SkeletonCircle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import classNames from 'classnames'; | ||
import React from 'react'; | ||
|
||
import { GlobalSize, Theme } from '@lumx/react'; | ||
import { COMPONENT_PREFIX } from '@lumx/react/constants'; | ||
import { GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils'; | ||
|
||
/** | ||
* Defines the props of the component. | ||
*/ | ||
interface SkeletonCircleProps extends GenericProps { | ||
/** The size variant of the component. */ | ||
size: GlobalSize; | ||
/** Theme. */ | ||
theme?: Theme; | ||
} | ||
|
||
/** | ||
* The display name of the component. | ||
*/ | ||
const COMPONENT_NAME = `${COMPONENT_PREFIX}SkeletonCircle`; | ||
|
||
/** | ||
* The default class name and classes prefix for this component. | ||
*/ | ||
const CLASSNAME: string = getRootClassName(COMPONENT_NAME); | ||
|
||
const SkeletonCircle: React.FC<SkeletonCircleProps> = ({ className, size, theme, ...forwardedProps }) => { | ||
return ( | ||
<div | ||
{...forwardedProps} | ||
className={classNames(className, handleBasicClasses({ prefix: CLASSNAME, size, theme }))} | ||
/> | ||
); | ||
}; | ||
SkeletonCircle.displayName = COMPONENT_NAME; | ||
|
||
export { CLASSNAME, COMPONENT_NAME, SkeletonCircle, SkeletonCircleProps }; |
Oops, something went wrong.