MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Hero

Function Hero

packages/dev/docs/src/Image.js:20–70  ·  view source on GitHub ↗
({
  wide,
  narrow,
  wide2x,
  narrow2x,
  wideWebp,
  narrowWebp,
  wide2xWebp,
  narrow2xWebp,
  alt
})

Source from the content-addressed store, hash-verified

18export const ImageContext = React.createContext();
19
20export function Hero({
21 wide,
22 narrow,
23 wide2x,
24 narrow2x,
25 wideWebp,
26 narrowWebp,
27 wide2xWebp,
28 narrow2xWebp,
29 alt
30}) {
31 // Temporary fix for parcel issue with relative urls in server rendering.
32 let publicUrl = React.useContext(ImageContext);
33 let baseUrl = publicUrl.replace(/\/$/, '');
34 let narrowUrl = baseUrl + '/' + path.basename(narrow);
35 let narrow2xUrl = baseUrl + '/' + path.basename(narrow2x);
36 let wideUrl = baseUrl + '/' + path.basename(wide);
37 let wide2xUrl = baseUrl + '/' + path.basename(wide2x);
38 let narrowWebpUrl = baseUrl + '/' + path.basename(narrowWebp);
39 let narrow2xWebpUrl = baseUrl + '/' + path.basename(narrow2xWebp);
40 let wideWebpUrl = baseUrl + '/' + path.basename(wideWebp);
41 let wide2xWebpUrl = baseUrl + '/' + path.basename(wide2xWebp);
42
43 return (
44 <div className={docStyles.heroImage}>
45 <picture>
46 <source
47 srcSet={` ${wideWebpUrl} 967w, ${wide2xWebpUrl} 2x`}
48 type="image/webp"
49 media="(min-width: 600px)"
50 />
51 <source
52 srcSet={`${narrowWebpUrl} 600w, ${narrow2xWebpUrl} 2x`}
53 type="image/webp"
54 media="(max-width: 600px)"
55 />
56 <source
57 srcSet={` ${wideUrl} 967w, ${wide2xUrl} 2x`}
58 type="image/png"
59 media="(min-width: 600px)"
60 />
61 <source
62 srcSet={`${narrowUrl} 600w, ${narrow2xUrl} 2x`}
63 type="image/png"
64 media="(max-width: 600px)"
65 />
66 <img src={wideUrl} alt={alt} />
67 </picture>
68 </div>
69 );
70}
71
72export function Image({src, expandable, ...otherProps}) {
73 let publicUrl = React.useContext(ImageContext);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected