| 1 |
import styles from '@patternfly/react-styles/css/components/Skeleton/skeleton'; |
| 2 |
import { css } from '@patternfly/react-styles'; |
| 3 |
import cssHeight from '@patternfly/react-tokens/dist/esm/c_skeleton_Height'; |
| 4 |
import cssWidth from '@patternfly/react-tokens/dist/esm/c_skeleton_Width'; |
| 5 |
|
| 6 |
export interface SkeletonProps extends React.HTMLProps<HTMLDivElement> { |
| 7 |
/** Additional classes added to the Skeleton */ |
| 8 |
className?: string; |
| 9 |
/** The width of the Skeleton. Must specify pixels or percentage. */ |
| 10 |
width?: string; |
| 11 |
/** The height of the Skeleton. Must specify pixels or percentage. */ |
| 12 |
height?: string; |
| 13 |
/** The font size height of the Skeleton */ |
| 14 |
fontSize?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl'; |
| 15 |
/** The shape of the Skeleton */ |
| 16 |
shape?: 'circle' | 'square'; |
| 17 |
/** Text read just to screen reader users */ |
| 18 |
screenreaderText?: string; |
| 19 |
} |
| 20 |
|
| 21 |
export const Skeleton: React.FunctionComponent<SkeletonProps> = ({ |
| 22 |
className, |
| 23 |
width, |
| 24 |
height, |
| 25 |
fontSize, |
| 26 |
shape, |
| 27 |
screenreaderText, |
| 28 |
...props |
| 29 |
}: SkeletonProps) => { |
| 30 |
const fontHeightClassName = fontSize |
| 31 |
? Object.values(styles.modifiers).find((key) => key === `pf-m-text-${fontSize}`) |
| 32 |
: undefined; |
| 33 |
|
| 34 |
return ( |
| 35 |
<div |
| 36 |
{...props} |
| 37 |
className={css( |
| 38 |
styles.skeleton, |
| 39 |
fontSize && fontHeightClassName, |
| 40 |
shape === 'circle' && styles.modifiers.circle, |
| 41 |
shape === 'square' && styles.modifiers.square, |
| 42 |
className |
| 43 |
)} |
| 44 |
{...((width || height) && { |
| 45 |
style: { |
| 46 |
[cssWidth.name]: width ? width : undefined, |
| 47 |
[cssHeight.name]: height ? height : undefined, |
| 48 |
...props.style |
| 49 |
} as React.CSSProperties |
| 50 |
})} |
| 51 |
> |
| 52 |
<span className="pf-v6-screen-reader">{screenreaderText}</span> |
| 53 |
</div> |
| 54 |
); |
| 55 |
}; |
| 56 |
Skeleton.displayName = 'Skeleton'; |