import { assignVars, createThemeContract, globalStyle, keyframes, } from '@vanilla-extract/css'; import { recipe, RecipeVariants } from '@vanilla-extract/recipes'; import { createToneStyles, sys, typography } from '../../styles'; import { components } from '../../styles/layers.css'; const pulseKeyframe = keyframes({ '0%': { opacity: 1, }, '50%': { opacity: 0.4, }, '100%': { opacity: 1, }, }); const skeletonToneVars = createThemeContract({ base: null, onBase: null, }); const skeletonToneDefaults = assignVars(skeletonToneVars, { base: sys.surface.foreground, onBase: sys.surface.foreground, }); const skeletonToneStyles = createToneStyles(skeletonToneVars); export const skeletonRecipe = recipe({ base: { '@layer': { [components]: { display: 'block', backgroundColor: `color-mix(in srgb, ${skeletonToneVars.base} 10%, transparent)`, animationName: pulseKeyframe, animationDuration: '1500ms', animationIterationCount: 'infinite', animationTimingFunction: sys.motion.easing.standard, animationDelay: '500ms', vars: { ...skeletonToneDefaults, }, }, }, }, variants: { type: { text: { '@layer': { [components]: { selectors: { '&:empty::before': { content: '"\\00a0"', }, }, }, }, }, field: { '@layer': { [components]: { display: 'block', width: '100%', height: sys.spacing[6], }, }, }, paragraph: { '@layer': { [components]: { display: 'block', width: '100%', height: sys.spacing[16], }, }, }, block: { '@layer': { [components]: { aspectRatio: '1', }, }, }, }, size: { sm: typography.body.small, md: typography.body.medium, lg: typography.body.large, }, tone: skeletonToneStyles, withChildren: { true: { '@layer': { [components]: { maxWidth: 'fit-content', height: 'auto', }, }, }, }, corner: { square: { '@layer': { [components]: { borderRadius: sys.shape.corner.none, }, }, }, rounded: { '@layer': { [components]: { borderRadius: sys.shape.corner.small, }, }, }, circle: { '@layer': { [components]: { borderRadius: sys.shape.corner.circle, }, }, }, }, }, defaultVariants: { size: 'md', }, }); globalStyle(`${skeletonRecipe.classNames.variants.withChildren.true} *`, { visibility: 'hidden', }); export type SkeletonVariants = NonNullable< RecipeVariants >;