@newhighsco/chipset 6.21.1 → 6.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { arrayOf, oneOf, shape, string } from 'prop-types'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
|
+
import { useImage } from '../../providers'
|
|
5
|
+
|
|
4
6
|
const Image = ({
|
|
5
7
|
src,
|
|
6
8
|
sources,
|
|
@@ -10,6 +12,8 @@ const Image = ({
|
|
|
10
12
|
className,
|
|
11
13
|
...rest
|
|
12
14
|
}) => {
|
|
15
|
+
const renderImage = useImage()
|
|
16
|
+
|
|
13
17
|
if (!src) return null
|
|
14
18
|
|
|
15
19
|
const Picture = ({ render, children }) =>
|
|
@@ -26,14 +30,14 @@ const Image = ({
|
|
|
26
30
|
</picture>
|
|
27
31
|
)}
|
|
28
32
|
>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
src
|
|
32
|
-
alt
|
|
33
|
-
loading
|
|
34
|
-
decoding
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
{renderImage({
|
|
34
|
+
...(!sources?.length && { className }),
|
|
35
|
+
src,
|
|
36
|
+
alt,
|
|
37
|
+
loading,
|
|
38
|
+
decoding,
|
|
39
|
+
...rest
|
|
40
|
+
})}
|
|
37
41
|
</Picture>
|
|
38
42
|
)
|
|
39
43
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { func, node } from 'prop-types'
|
|
2
|
+
import React, { createContext, useContext } from 'react'
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line jsx-a11y/alt-text
|
|
5
|
+
const ImageContext = createContext(props => <img {...props} />)
|
|
6
|
+
|
|
7
|
+
export const useImage = () => {
|
|
8
|
+
const renderImage = useContext(ImageContext)
|
|
9
|
+
|
|
10
|
+
if (!renderImage) {
|
|
11
|
+
throw new Error("<ImageProvider /> missing 'renderImage'")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return renderImage
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ImageProvider = ({ children, renderImage }) => {
|
|
18
|
+
return (
|
|
19
|
+
<ImageContext.Provider value={renderImage}>
|
|
20
|
+
{children}
|
|
21
|
+
</ImageContext.Provider>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
ImageProvider.propTypes = {
|
|
26
|
+
children: node,
|
|
27
|
+
renderImage: func
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ImageProvider'
|
package/src/providers/index.js
CHANGED