Skip to content

Commit

Permalink
feat(Skeleton): Add skeleton component (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi6jp authored Nov 28, 2023
1 parent a835ccf commit d7af59e
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Skeleton/Skeleton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import { StoryFn as Story, Meta } from '@storybook/react'

import Skeleton, { SkeletonProps } from '.'

const meta: Meta = {
title: 'Feedback/Skeleton',
component: Skeleton,
parameters: {
controls: { expanded: true },
},
}

export default meta

export const Default: Story<SkeletonProps> = (args) => {
return <Skeleton {...args} />
}
Default.args = {
className: 'w-32 h-32',
}

export const CircleWithContent: Story<SkeletonProps> = ({ dataTheme }) => {
return (
<div className="flex flex-col gap-4 w-52" data-theme={dataTheme}>
<div className="flex gap-4 items-center">
<Skeleton className="w-16 h-16 rounded-full shrink-0"></Skeleton>
<div className="flex flex-col gap-4">
<Skeleton className="h-4 w-20"></Skeleton>
<Skeleton className="h-4 w-28"></Skeleton>
</div>
</div>
<Skeleton className="h-32 w-full"></Skeleton>
</div>
)
}

export const RectangleWithContent: Story<SkeletonProps> = ({ dataTheme }) => {
return (
<div className="flex flex-col gap-4 w-52" data-theme={dataTheme}>
<Skeleton className="h-32 w-full"></Skeleton>
<Skeleton className="h-4 w-28"></Skeleton>
<Skeleton className="h-4 w-full"></Skeleton>
<Skeleton className="h-4 w-full"></Skeleton>
</div>
)
}
47 changes: 47 additions & 0 deletions src/Skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { forwardRef, ReactNode } from 'react'
import clsx from 'clsx'
import { twMerge } from 'tailwind-merge'

import {
IComponentBaseProps,
} from '../types'

export type SkeletonProps =
& React.HTMLAttributes<HTMLDivElement>
& IComponentBaseProps
& {
}

const Skeleton = forwardRef<HTMLDivElement, SkeletonProps>(
(
{
dataTheme,
className,
children,
...props
},
ref
): JSX.Element => {
const classes = twMerge(
'skeleton',
clsx({
}),
className,
)

return (
<div
{...props}
data-theme={dataTheme}
className={classes}
ref={ref}
>
{children}
</div>
)
}
)

Skeleton.displayName = "Skeleton"

export default Skeleton
5 changes: 5 additions & 0 deletions src/Skeleton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './Skeleton';

import Skeleton, { SkeletonProps as TSkeletonProps } from './Skeleton'
export type SkeletonProps = TSkeletonProps
export default Skeleton

0 comments on commit d7af59e

Please sign in to comment.