Skip to content

Commit

Permalink
Fix(core): rendering of placeholder color
Browse files Browse the repository at this point in the history
  • Loading branch information
noahehall committed Jun 10, 2023
1 parent 38fb42b commit 5d82864
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ const App = () => (
bun install
bun run cosmos
# open localhost:5000
# set network throttling to something really slow
```
15 changes: 11 additions & 4 deletions src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const Image = forwardRef(function Image(
alt,
height,
loadState,
placeholder,
theme,
width,
//
Expand All @@ -38,19 +39,25 @@ export const Image = forwardRef(function Image(
);
const imageProps = useMemo(() => {
const baseProps = { width, height, alt };
const style = { ...theme.img, width, height };
const imgStyle = { ...theme.img, width, height };
const placeholderStyle = {
...theme.placeholder,
width,
height,
backgroundColor: placeholder,
};
return src && loadState === loadStates.Loaded
? {
...baseProps,
src,
style,
style: imgStyle,
}
: {
...baseProps,
ref: svgRef,
style,
style: placeholderStyle,
};
}, [loadState, src, alt, width, height, svgRef, theme]);
}, [loadState, src, alt, width, height, svgRef, theme, placeholder]);

return loadState === loadStates.Loaded ? (
<AnimatePresence>
Expand Down
13 changes: 3 additions & 10 deletions src/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ export const Media: FC<MediaInterface> = ({
[iconSize, iconColor, theme]
);

const useStyle = useMemo(
() => ({
...theme.placeholder,
backgroundColor: placeholder,
}),
[theme, placeholder]
);

const SvgRef: SvgRef = useRef(null);

useEffect(() => {
Expand All @@ -83,12 +75,13 @@ export const Media: FC<MediaInterface> = ({
}, [onDimensions]);

return (
<div className="media" style={useStyle} onClick={onClick}>
<div className="media" onClick={onClick}>
<Image
motionProps={motionProps}
alt={alt}
height={height}
loadState={loadState}
motionProps={motionProps}
placeholder={placeholder}
ref={SvgRef}
src={src}
theme={theme}
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type GetUrl = (x: SrcType) => string;

export type IdealImageProps = BaseProps & {
alt: string;
srcSet: SrcSet;
motionProps?: MotionProps;
placeholder?: string;
srcSet: SrcSet;
};

0 comments on commit 5d82864

Please sign in to comment.