MCPcopy
hub / github.com/dvtng/react-loading-skeleton / Skeleton

Function Skeleton

src/Skeleton.tsx:64–166  ·  view source on GitHub ↗
({
  count = 1,
  wrapper: Wrapper,

  className: customClassName,
  containerClassName,
  containerTestId,

  circle = false,

  style: styleProp,
  ...originalPropsStyleOptions
}: SkeletonProps)

Source from the content-addressed store, hash-verified

62}
63
64export function Skeleton({
65 count = 1,
66 wrapper: Wrapper,
67
68 className: customClassName,
69 containerClassName,
70 containerTestId,
71
72 circle = false,
73
74 style: styleProp,
75 ...originalPropsStyleOptions
76}: SkeletonProps): ReactElement {
77 const contextStyleOptions = React.useContext(SkeletonThemeContext);
78
79 const propsStyleOptions = { ...originalPropsStyleOptions };
80
81 // DO NOT overwrite style options from the context if `propsStyleOptions`
82 // has properties explicity set to undefined
83 for (const [key, value] of Object.entries(originalPropsStyleOptions)) {
84 if (typeof value === 'undefined') {
85 delete propsStyleOptions[key as keyof typeof propsStyleOptions];
86 }
87 }
88
89 // Props take priority over context
90 const styleOptions = {
91 ...contextStyleOptions,
92 ...propsStyleOptions,
93 circle,
94 };
95
96 // `styleProp` has the least priority out of everything
97 const style = {
98 ...styleProp,
99 ...styleOptionsToCssProperties(styleOptions),
100 };
101
102 let className = 'react-loading-skeleton';
103 if (customClassName) className += ` ${customClassName}`;
104
105 const inline = styleOptions.inline ?? false;
106
107 const elements: ReactElement[] = [];
108
109 const countCeil = Math.ceil(count);
110
111 for (let i = 0; i < countCeil; i++) {
112 let thisStyle = style;
113
114 if (countCeil > count && i === countCeil - 1) {
115 // count is not an integer and we've reached the last iteration of
116 // the loop, so add a "fractional" skeleton.
117 //
118 // For example, if count is 3.5, we've already added 3 full
119 // skeletons, so now we add one more skeleton that is 0.5 times the
120 // original width.
121

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…