Skip to content

Commit a93bab5

Browse files
committed
fix(image): use css
1 parent e39f8d2 commit a93bab5

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

packages/start/src/image/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
mergeImageVariantsToSrcSet,
99
} from "./transformer.ts";
1010
import type { StartImageSource, StartImageTransformer, StartImageVariant } from "./types.ts";
11-
import { BLOCKER_STYLE, getAspectRatioBoxStyle, IMAGE_CONTAINER, IMAGE_STYLE } from "./utils.ts";
11+
import { getAspectRatioBoxStyle } from "./utils.ts";
12+
13+
import "./styles.css";
1214

1315
export interface StartImageProps<T> {
1416
src: StartImageSource<T>;
@@ -58,15 +60,15 @@ export function StartImage<T>(props: StartImageProps<T>): JSX.Element {
5860
const height = createMemo(() => props.src.height);
5961

6062
return (
61-
<div ref={laze.ref} data-start-image="image-container" style={IMAGE_CONTAINER}>
63+
<div ref={laze.ref} data-start-image="container">
6264
<div
6365
data-start-image="aspect-ratio"
6466
style={getAspectRatioBoxStyle({
6567
width: width(),
6668
height: height(),
6769
})}
6870
>
69-
<picture style={IMAGE_STYLE}>
71+
<picture data-start-image="picture">
7072
<Show when={props.transformer} fallback={<source src={props.src.source} />}>
7173
{cb => <StartImageSources variants={createImageVariants(props.src, cb())} {...props} />}
7274
</Show>
@@ -75,7 +77,6 @@ export function StartImage<T>(props: StartImageProps<T>): JSX.Element {
7577
<img
7678
data-start-image="image"
7779
alt={props.alt}
78-
style={IMAGE_STYLE}
7980
crossOrigin={props.crossOrigin}
8081
fetchpriority={props.fetchPriority}
8182
decoding={props.decoding}
@@ -107,7 +108,7 @@ export function StartImage<T>(props: StartImageProps<T>): JSX.Element {
107108
</ClientOnly>
108109
</picture>
109110
</div>
110-
<div style={BLOCKER_STYLE}>
111+
<div data-start-image="blocker">
111112
<ClientOnly>
112113
<Show when={laze.visible}>{props.fallback(showPlaceholder, onPlaceholderLoad)}</Show>
113114
</ClientOnly>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[data-start-image="blocker"],
2+
[data-start-image="image"],
3+
[data-start-image="picture"] {
4+
position: absolute;
5+
top: 0;
6+
left: 0;
7+
right: 0;
8+
bottom: 0;
9+
}
10+
11+
[data-start-image="image"],
12+
[data-start-image="picture"] {
13+
width: 100%;
14+
height: 100%;
15+
object-fit: contain;
16+
pointer-events: none;
17+
user-select: none;
18+
}
19+
20+
[data-start-image="container"] {
21+
width: 100%;
22+
height: 100%;
23+
position: relative;
24+
}

packages/start/src/image/utils.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,6 @@ export function getAspectRatioBoxStyle(ratio: AspectRatio): JSX.CSSProperties {
3030
};
3131
}
3232

33-
export const IMAGE_CONTAINER: JSX.CSSProperties = {
34-
width: "100%",
35-
height: "100%",
36-
position: "relative",
37-
};
38-
39-
export const BLOCKER_STYLE: JSX.CSSProperties = {
40-
position: "absolute",
41-
top: 0,
42-
left: 0,
43-
right: 0,
44-
bottom: 0,
45-
};
46-
47-
export const IMAGE_STYLE: JSX.CSSProperties = {
48-
...BLOCKER_STYLE,
49-
width: "100%",
50-
height: "100%",
51-
"object-fit": "contain",
52-
"pointer-events": "none",
53-
"user-select": "none",
54-
};
55-
5633
export function getEmptySVGPlaceholder({ width, height }: AspectRatio): string {
5734
return `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg" version="1.1"/>`;
5835
}

0 commit comments

Comments
 (0)