Skip to content

Commit 7db5cf5

Browse files
committed
feat(Image): simplify image component
BREAKING CHANGE: no longer accepts classes prop, image and loading placeholder are no longer wrapped by a div
1 parent a4f96a0 commit 7db5cf5

File tree

2 files changed

+6
-57
lines changed

2 files changed

+6
-57
lines changed

src/components/Image/Image.tsx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ export interface ImageProps extends Remove<ImgHTMLAttributes<HTMLImageElement>,
99
* undefined or if a promise will display as loading.
1010
*/
1111
src?: FuturableOrLazy<string>;
12-
/**
13-
* Specific classes for all of the internal elements. If you just wish to give
14-
* a class to image, you can use `className`.
15-
*/
16-
classes?: { wrapper?: string; image?: string; overlay?: string };
1712
/**
1813
* Render out an element to be shown while src is loading.
1914
*/
2015
onRenderLoading?(): ReactNode;
2116
}
2217

2318
export const Image = forwardRef<HTMLImageElement, ImageProps>(
24-
({ src, classes, onRenderLoading, alt, className, ...imgProps }, ref) => {
19+
({ src, onRenderLoading, alt, className, ...imgProps }, ref) => {
2520
const [source, setSource] = useState<string | undefined>(typeof src === 'string' ? src : undefined);
2621

2722
const getSource = useCallback(async (srcGetter: FuturableOrLazy<string>) => {
@@ -34,24 +29,12 @@ export const Image = forwardRef<HTMLImageElement, ImageProps>(
3429
getSource(src);
3530
}, [src, getSource]);
3631

37-
const wrapperClass = classnames('ui__base ui__image__wrapper', classes?.wrapper);
38-
39-
const imageClass = classnames('ui__image', { 'ui__image--loading': !source }, classes?.image, className);
40-
41-
const overlayClass = classnames(
42-
'ui__image__overlay',
43-
{
44-
'ui__image__overlay--loading': !source,
45-
'ui__image__overlay--hide': !onRenderLoading,
46-
},
47-
classes?.overlay,
48-
);
32+
const imageClass = classnames('ui__image', className);
4933

50-
return (
51-
<div className={wrapperClass}>
52-
<img {...imgProps} alt={alt} src={source} className={imageClass} ref={ref} />
53-
<div className={overlayClass}>{onRenderLoading?.()}</div>
54-
</div>
34+
return source ? (
35+
<img {...imgProps} alt={alt} src={source} className={imageClass} ref={ref} />
36+
) : (
37+
<>{onRenderLoading?.()}</>
5538
);
5639
},
5740
);

src/components/Image/_Image.scss

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,4 @@
1-
.ui__image__wrapper {
2-
height: 100%;
3-
width: 100%;
4-
position: relative;
5-
user-select: none;
6-
pointer-events: none;
7-
flex-grow: 0;
8-
display: flex;
9-
justify-content: center;
10-
align-items: center;
11-
}
12-
131
.ui__image {
142
max-width: 100%;
153
max-height: 100%;
16-
17-
&--loading {
18-
opacity: 0;
19-
}
20-
}
21-
22-
.ui__image__overlay {
23-
opacity: 0;
24-
pointer-events: none;
25-
26-
> * {
27-
position: absolute;
28-
top: 50%;
29-
left: 50%;
30-
transform: translate(-50%, -50%);
31-
overflow: visible;
32-
}
33-
34-
&--loading:not(.ui__image__overlay--hide) {
35-
opacity: 1;
36-
pointer-events: all;
37-
}
384
}

0 commit comments

Comments
 (0)