From 6d1b4c5ae6503c9a4710e4f400f3d1a023459bd2 Mon Sep 17 00:00:00 2001 From: jotoh Date: Sat, 15 Oct 2022 22:43:25 +0200 Subject: [PATCH] added scale to component, refactored to css-class approach --- components/skeleton/skeleton.tsx | 223 ++++++++++++++++------------ pages/en-us/components/skeleton.mdx | 8 +- 2 files changed, 135 insertions(+), 96 deletions(-) diff --git a/components/skeleton/skeleton.tsx b/components/skeleton/skeleton.tsx index 081a0a8bc..315e27b6b 100644 --- a/components/skeleton/skeleton.tsx +++ b/components/skeleton/skeleton.tsx @@ -1,106 +1,145 @@ import React from 'react' -import useTheme from "../use-theme"; +import useTheme from '../use-theme' +import { useScale, withScale } from '../use-scale' +import useClasses from '../use-classes' interface Props { - width?: number - squared?: boolean - rounded?: boolean - component?: keyof JSX.IntrinsicElements - className?: string - show?: boolean - minHeight?: number - animate?: boolean - height?: number + width?: number + squared?: boolean + rounded?: boolean + component?: keyof JSX.IntrinsicElements + className?: string + show?: boolean + minHeight?: number + animate?: boolean + height?: number } const defaultProps = { - squared: false, - rounded: false, - component: 'span' as keyof JSX.IntrinsicElements, - className: '', - show: false, - minHeight: 24, - animate: true, + squared: false, + rounded: false, + component: 'span' as keyof JSX.IntrinsicElements, + className: '', + show: false, + minHeight: 24, + animate: true, } type NativeAttrs = Omit, keyof Props> export type SkeletonProps = Props & NativeAttrs -const Skeleton: React.FC> = ({ - component, - children, - width, - squared, - rounded, - show, - minHeight, - className, - animate, - height, - ...props - }: React.PropsWithChildren & typeof defaultProps) => { - const Component = component - let theme = useTheme(); - - return ( - - {children} - - - ) +const SkeletonComponent: React.FC> = ({ + component, + children, + width, + squared, + rounded, + show, + minHeight, + className, + animate, + height, + ...props +}: React.PropsWithChildren & typeof defaultProps) => { + const Component = component + let theme = useTheme() + const { SCALES } = useScale() + const classes = useClasses( + 'skeleton', + { rounded, squared, show, stop: !animate, hasChildren: !!children }, + className, + ) + + return ( + + {children} + + + ) } -Skeleton.defaultProps = defaultProps -Skeleton.displayName = 'GeistCol' +SkeletonComponent.defaultProps = defaultProps +SkeletonComponent.displayName = 'GeistCol' +const Skeleton = withScale(SkeletonComponent) export default Skeleton diff --git a/pages/en-us/components/skeleton.mdx b/pages/en-us/components/skeleton.mdx index 448c61c8f..08173de07 100644 --- a/pages/en-us/components/skeleton.mdx +++ b/pages/en-us/components/skeleton.mdx @@ -15,7 +15,7 @@ Show a placeholder in place of content that is loading. title="Default with set width." scope={{ Skeleton }} code={` - + `} /> @@ -39,7 +39,7 @@ Show a placeholder in place of content that is loading. title="Rounded skeleton." scope={{ Skeleton }} code={` - + `} /> @@ -47,7 +47,7 @@ Show a placeholder in place of content that is loading. title="Squared skeleton." scope={{ Skeleton }} code={` - + `} /> @@ -55,7 +55,7 @@ Show a placeholder in place of content that is loading. title="Disabled animation." scope={{ Skeleton }} code={` - + `} />