Skip to content

Commit

Permalink
feat: add new scenarios for skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
romainseb committed Dec 11, 2023
1 parent 80176a5 commit d8a2b98
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { forwardRef, HTMLAttributes, Ref } from 'react';

import classNames from 'classnames';

import styles from './Skeleton.module.scss';
Expand Down
9 changes: 8 additions & 1 deletion packages/design-system/src/components/Skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import SkeletonButtonIcon, { SkeletonButtonIconProps } from './variations/Skelet
import SkeletonHeading, { SkeletonHeadingProps } from './variations/SkeletonHeading';
import SkeletonInput, { SkeletonInputProps } from './variations/SkeletonInput';
import SkeletonParagraph, { SkeletonParagraphProps } from './variations/SkeletonParagraph';
import SkeletonSized, { SkeletonSizedProps } from './variations/SkeletonSized';

export type SkeletonProps =
| ({ variant: 'button' } & SkeletonButtonProps)
| ({ variant: 'buttonIcon' } & SkeletonButtonIconProps)
| ({ variant: 'heading' } & SkeletonHeadingProps)
| ({ variant: 'paragraph' } & SkeletonParagraphProps)
| ({ variant: 'input' } & SkeletonInputProps);
| ({ variant: 'input' } & SkeletonInputProps)
| ({ variant: 'sized' } & SkeletonSizedProps);

export const Skeleton = forwardRef((props: SkeletonProps, ref: Ref<HTMLSpanElement>) => {
switch (props.variant) {
Expand Down Expand Up @@ -40,6 +42,11 @@ export const Skeleton = forwardRef((props: SkeletonProps, ref: Ref<HTMLSpanEleme
return <SkeletonInput {...rest} ref={ref} />;
}

case 'sized': {
const { variant, ...rest } = props;
return <SkeletonSized {...rest} ref={ref} />;
}

default: {
return null;
}
Expand Down
13 changes: 11 additions & 2 deletions packages/design-system/src/components/Skeleton/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
export * from './Skeleton';
import SkeletonButton from './variations/SkeletonButton';
import SkeletonButtonIcon from './variations/SkeletonButtonIcon';
import SkeletonHeading from './variations/SkeletonHeading';
import SkeletonInput from './variations/SkeletonInput';
import SkeletonParagraph from './variations/SkeletonParagraph';
import SkeletonSized from './variations/SkeletonSized';

export * from './Skeleton';

export { SkeletonHeading, SkeletonButtonIcon, SkeletonButton, SkeletonParagraph, SkeletonInput };
export {
SkeletonHeading,
SkeletonButtonIcon,
SkeletonButton,
SkeletonParagraph,
SkeletonInput,
SkeletonSized,
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,28 @@
&.size-S {
height: 1.4rem;
}

&.width-XS {
max-width: 10%;
}

&.width-S {
max-width: 20%;
}

&.width-M {
max-width: 40%;
}

&.width-L {
max-width: 60%;
}

&.width-XL {
max-width: 80%;
}

&.width-100 {
max-width: 100%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styles from './SkeletonHeading.module.scss';

export type SkeletonHeadingProps = Omit<SkeletonPrimitiveProps, 'className'> & {
size?: 'L' | 'M' | 'S';
width?: 'XS' | 'S' | 'M' | 'L' | 'XL' | '100%';
};

const SkeletonHeading = forwardRef(
Expand All @@ -19,6 +20,12 @@ const SkeletonHeading = forwardRef(
[styles['size-L']]: size === 'L',
[styles['size-M']]: size === 'M',
[styles['size-S']]: size === 'S',
[styles['width-XS']]: props.width === 'XS',
[styles['width-S']]: props.width === 'S',
[styles['width-M']]: props.width === 'M',
[styles['width-L']]: props.width === 'L',
[styles['width-XL']]: props.width === 'XL',
[styles['width-100']]: props.width === '100%',
})}
{...props}
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,28 @@
&.size-S {
height: 1.2rem;
}

&.width-XS {
max-width: 10%;
}

&.width-S {
max-width: 20%;
}

&.width-M {
max-width: 40%;
}

&.width-L {
max-width: 60%;
}

&.width-XL {
max-width: 80%;
}

&.width-100 {
max-width: 100%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styles from './SkeletonParagraph.module.scss';

export type SkeletonParagraphProps = Omit<SkeletonPrimitiveProps, 'className'> & {
size?: 'M' | 'S';
width?: 'XS' | 'S' | 'M' | 'L' | 'XL' | '100%';
};

const SkeletonParagraph = forwardRef(
Expand All @@ -18,6 +19,12 @@ const SkeletonParagraph = forwardRef(
className={classNames(styles.skeletonParagraph, {
[styles['size-M']]: size === 'M',
[styles['size-S']]: size === 'S',
[styles['width-XS']]: props.width === 'XS',
[styles['width-S']]: props.width === 'S',
[styles['width-M']]: props.width === 'M',
[styles['width-L']]: props.width === 'L',
[styles['width-XL']]: props.width === 'XL',
[styles['width-100']]: props.width === '100%',
})}
{...props}
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.skeleton-sized-circle {
border-radius: 50%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { forwardRef, Ref } from 'react';

import classNames from 'classnames';

import SkeletonPrimitive, { SkeletonPrimitiveProps } from '../Primitive/Skeleton.Primitive';

import style from './SkeletonSized.module.scss';

export type SkeletonSizedProps = Omit<SkeletonPrimitiveProps, 'className'> & {
height?: number;
width?: number;
isCircle?: boolean;
};

const SkeletonSized = forwardRef(
(
{ height = 1.4, width = 2, isCircle, ...props }: SkeletonSizedProps,
ref: Ref<HTMLSpanElement>,
) => {
return (
<SkeletonPrimitive
// @ts-expect-error style is valid
style={{ height: `${height}rem`, width: `${width}rem` }}
className={classNames({ [style['skeleton-sized-circle']]: isCircle })}
{...props}
ref={ref}
/>
);
},
);
SkeletonSized.displayName = 'SkeletonSized';

export default SkeletonSized;
17 changes: 14 additions & 3 deletions packages/design-system/src/stories/feedback/Skeleton.mdx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Meta, Canvas, Story, Controls } from '@storybook/blocks';
import { Canvas, Controls, Meta, Story } from '@storybook/blocks';

import { FigmaImage } from '@talend/storybook-docs';

import {
Skeleton,
SkeletonButton,
SkeletonParagraph,
SkeletonHeading,
SkeletonInput,
Skeleton,
SkeletonParagraph,
StackHorizontal,
StackVertical,
} from '../../';
Expand Down Expand Up @@ -82,6 +84,15 @@ It illustrates any input element.
<Story of={Stories.SkeletonInputStory} />
</Canvas>

#### Sized

It can be the size needed

<Canvas>
<Story of={Stories.SkeletonSizedStory} />
</Canvas>
<Controls of={Stories.SkeletonSizedStory} />

#### Composition example

Combine all of them to mock content!
Expand Down
31 changes: 30 additions & 1 deletion packages/design-system/src/stories/feedback/Skeleton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
SkeletonHeading,
SkeletonInput,
SkeletonParagraph,
SkeletonSized,
StackHorizontal,
StackVertical,
} from '../../';

import SkeletonPrimitive from '../../components/Skeleton/Primitive/Skeleton.Primitive';

export default {
Expand All @@ -34,6 +34,10 @@ const SkeletonParagraphTemplate: StoryFn<typeof SkeletonParagraph> = args => {
return <SkeletonParagraph {...args} />;
};

const SkeletonSizedTemplate: StoryFn<typeof SkeletonSized> = args => {
return <SkeletonSized {...args} />;
};

const SkeletonInputTemplate: StoryFn<typeof SkeletonInput> = args => {
return <SkeletonInput {...args} />;
};
Expand Down Expand Up @@ -71,6 +75,11 @@ SkeletonHeadingStory.argTypes = {
control: { type: 'select' },
description: 'optional (default is "L")',
},
width: {
options: ['XL', 'L', 'M', 'S', 'XS'],
control: { type: 'select' },
description: 'optional',
},
};

export const SkeletonParagraphStory = SkeletonParagraphTemplate.bind({});
Expand All @@ -83,6 +92,26 @@ SkeletonParagraphStory.argTypes = {
control: { type: 'select' },
description: 'optional (default is "M")',
},
width: {
options: ['XL', 'L', 'M', 'S', 'XS'],
control: { type: 'select' },
description: 'optional',
},
};

export const SkeletonSizedStory = SkeletonSizedTemplate.bind({});
SkeletonSizedStory.args = {
isCircle: true,
};
SkeletonSizedStory.argTypes = {
height: {
control: { type: 'number' },
defaultValue: 10,
},
width: {
control: { type: 'number' },
defaultValue: 10,
},
};

export const SkeletonInputStory = SkeletonInputTemplate.bind({});
Expand Down

0 comments on commit d8a2b98

Please sign in to comment.