Skip to content

Commit

Permalink
feat: publish Skeleton Component.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Oct 21, 2024
1 parent 9224838 commit 3801ad1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/ui/Skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import type { HTMLAttributes, ReactNode } from 'react';
import type { HTMLAttributes } from 'react';
import { forwardRef } from 'react';
import { root } from './style.css';
import createSkeletonStyle from './utils';

export interface SkeletonProps extends Omit<HTMLAttributes<HTMLSpanElement>, 'children'> {
children: ReactNode;
export interface SkeletonProps extends HTMLAttributes<HTMLSpanElement> {
width: number | string;
height: number | string;
variant: 'circular' | 'rectangular' | 'rounded' | 'text';
animation: 'pulse' | 'wave';
variant: 'default' | 'circular' | 'rounded';
}

export const Skeleton = forwardRef<HTMLSpanElement, SkeletonProps>((props, forwardedRef) => {
const { children, ...restProps } = props;
const { width, height, variant, ...restProps } = props;

return (
<span ref={forwardedRef} {...restProps}>
{children}
</span>
);
const style = createSkeletonStyle(variant);

return <span className={`${root} ${style}`} ref={forwardedRef} style={{ width, height }} {...restProps} />;
});

Skeleton.displayName = 'Skeleton';
9 changes: 9 additions & 0 deletions packages/ui/Skeleton/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { SkeletonVariant } from './types';

const SkeletonBorderRadius: Record<SkeletonVariant, string> = {
default: '12px',
circular: '100%',
rounded: '100%',
};

export default SkeletonBorderRadius;
32 changes: 32 additions & 0 deletions packages/ui/Skeleton/style.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { colors } from '@sopt-makers/colors';
import { keyframes, style } from '@vanilla-extract/css';
import { createSprinkles, defineProperties } from '@vanilla-extract/sprinkles';
import SkeletonBorderRadius from './constants';

const pulseKeyframe = keyframes({
'0%': {
opacity: 1,
},

'50%': {
opacity: 0.4,
},

'100%': {
opacity: 1,
},
});

export const root = style({
display: 'block',
backgroundColor: colors.gray700,
animation: `${pulseKeyframe} 2s ease-in-out 0.5s infinite`,
});

const sprinkleProperties = defineProperties({
properties: {
borderRadius: SkeletonBorderRadius,
},
});

export const sprinkles = createSprinkles(sprinkleProperties);
1 change: 1 addition & 0 deletions packages/ui/Skeleton/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type SkeletonVariant = 'default' | 'circular' | 'rounded';
8 changes: 8 additions & 0 deletions packages/ui/Skeleton/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sprinkles } from './style.css';
import type { SkeletonVariant } from './types';

const createSkeletonStyle = (variant: SkeletonVariant) => {
return sprinkles({ borderRadius: variant });
};

export default createSkeletonStyle;

0 comments on commit 3801ad1

Please sign in to comment.