@macive/ui 0.0.16 → 0.0.18
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/dist/src/components/Icon/Icon.js +9 -2
- package/dist/src/components/Image/Image.js +55 -22
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/components/Checkbox/Checkbox.d.ts +1 -1
- package/dist/types/src/components/Icon/Icon.d.ts.map +1 -1
- package/dist/types/src/components/Image/Image.d.ts +1 -2
- package/dist/types/src/components/Image/Image.d.ts.map +1 -1
- package/dist/types/src/components/Input/Input.d.ts +1 -1
- package/dist/types/src/components/Scrollable/Scrollable.d.ts +1 -1
- package/package.json +1 -1
|
@@ -47,7 +47,14 @@ function Icon({ source, color, backdrop, accessibilityLabel, size = 20, theme })
|
|
|
47
47
|
}
|
|
48
48
|
else if (typeof source === 'object' && source !== null) {
|
|
49
49
|
// Handle objects (e.g., raw SVG data or custom icon objects)
|
|
50
|
-
sourceType = 'object'
|
|
50
|
+
// sourceType = 'object'
|
|
51
|
+
const iconToFunction = (IconComponent, props) => {
|
|
52
|
+
const Icon = () => (0, jsx_runtime_1.jsx)(IconComponent, { ...props });
|
|
53
|
+
Icon.displayName = 'Icon';
|
|
54
|
+
return Icon;
|
|
55
|
+
};
|
|
56
|
+
source = iconToFunction(source);
|
|
57
|
+
sourceType = 'function';
|
|
51
58
|
}
|
|
52
59
|
else {
|
|
53
60
|
// Fallback to placeholder for unrecognized types
|
|
@@ -55,7 +62,7 @@ function Icon({ source, color, backdrop, accessibilityLabel, size = 20, theme })
|
|
|
55
62
|
}
|
|
56
63
|
// Warn for unsupported recoloring of external SVGs, URLs, or objects
|
|
57
64
|
if (color &&
|
|
58
|
-
(sourceType === 'external' || sourceType === 'url'
|
|
65
|
+
(sourceType === 'external' || sourceType === 'url') &&
|
|
59
66
|
process.env.NODE_ENV === 'development') {
|
|
60
67
|
console.warn(`Recoloring ${sourceType} sources is not supported. Set the intended color on your icon source instead.`);
|
|
61
68
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Image = exports.fallbackImageSVG = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
/* eslint-disable @next/next/no-img-element */
|
|
5
6
|
const react_1 = require("react");
|
|
6
|
-
// Fallback SVG as a data URL
|
|
7
7
|
exports.fallbackImageSVG = `
|
|
8
8
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="#ccc">
|
|
9
9
|
<rect width="100" height="100" />
|
|
@@ -13,27 +13,64 @@ exports.fallbackImageSVG = `
|
|
|
13
13
|
const fallbackSVG = `
|
|
14
14
|
<svg xmlns="http://www.w3.org/2000/svg" fill="#eae6e6" width="32" height="32" viewBox="0 0 32 32" stroke="#eae6e6">
|
|
15
15
|
<path d="M30 3.4141L28.5859 2 2 28.5859 3.4141 30l2-2H26a2.0027 2.0027 0 0 0 2-2V5.4141ZM26 26H7.4141l7.7929-7.793 2.3788 2.3787a2 2 0 0 0 2.8284 0L22 19l4 3.9973ZM26 20.1682l-2.5858-2.5859a2 2 0 0 0-2.8284 0L19 19.1682l-2.377-2.3771L26 7.4141Z"/>
|
|
16
|
-
<path d="M6 22V19l5-4.9966 1.3733 1.3733 1.4159-1.416-1.375-1.375a2 2 0 0 0-2.8284 0L6 16.1716V6H22V4H6A2.002 2.
|
|
16
|
+
<path d="M6 22V19l5-4.9966 1.3733 1.3733 1.4159-1.416-1.375-1.375a2 2 0 0 0-2.8284 0L6 16.1716V6H22V4H6A2.002 2.0027 0 0 0 4 6V22Z"/>
|
|
17
17
|
</svg>
|
|
18
18
|
`;
|
|
19
19
|
const errorkSVG = `
|
|
20
20
|
<svg xmlns="http://www.w3.org/2000/svg" fill="#dfc3c3" width="32" height="32" viewBox="0 0 32 32" stroke="#dfc3c3">
|
|
21
21
|
<path d="M30 3.4141L28.5859 2 2 28.5859 3.4141 30l2-2H26a2.0027 2.0027 0 0 0 2-2V5.4141ZM26 26H7.4141l7.7929-7.793 2.3788 2.3787a2 2 0 0 0 2.8284 0L22 19l4 3.9973ZM26 20.1682l-2.5858-2.5859a2 2 0 0 0-2.8284 0L19 19.1682l-2.377-2.3771L26 7.4141Z"/>
|
|
22
|
-
<path d="M6 22V19l5-4.9966 1.3733 1.3733 1.4159-1.416-1.375-1.375a2 2 0 0 0-2.8284 0L6 16.1716V6H22V4H6A2.002 2.
|
|
22
|
+
<path d="M6 22V19l5-4.9966 1.3733 1.3733 1.4159-1.416-1.375-1.375a2 2 0 0 0-2.8284 0L6 16.1716V6H22V4H6A2.002 2.0027 0 0 0 4 6V22Z"/>
|
|
23
23
|
</svg>
|
|
24
24
|
`;
|
|
25
25
|
const fallbackImageURL = `data:image/svg+xml;utf8,${encodeURIComponent(fallbackSVG)}`;
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
// SVG loader (spinning circle)
|
|
27
|
+
const loaderSVG = `
|
|
28
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 50 50">
|
|
29
|
+
<circle cx="25" cy="25" r="20" stroke="#ccc" stroke-width="5" fill="none" stroke-dasharray="31.415, 31.415">
|
|
30
|
+
<animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="1s" repeatCount="indefinite" />
|
|
31
|
+
</circle>
|
|
32
|
+
</svg>
|
|
33
|
+
`;
|
|
34
|
+
const loaderImageURL = `data:image/svg+xml;utf8,${encodeURIComponent(loaderSVG)}`;
|
|
35
|
+
// Inline CSS for loader and image wrapper
|
|
36
|
+
const imageStyles = `
|
|
37
|
+
.image-wrapper {
|
|
38
|
+
position: relative;
|
|
39
|
+
width: 100%;
|
|
40
|
+
height: 100%;
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
background: #f0f0f0; /* Light background for loader */
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.loader {
|
|
48
|
+
width: 40px;
|
|
49
|
+
height: 40px;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.image {
|
|
53
|
+
width: 100%;
|
|
54
|
+
height: 100%;
|
|
55
|
+
object-fit: cover;
|
|
56
|
+
position: absolute;
|
|
57
|
+
top: 0;
|
|
58
|
+
left: 0;
|
|
59
|
+
transition: opacity 0.3s ease-in-out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.image-loading {
|
|
63
|
+
opacity: 0;
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className, rounded, lazy = true, style, ...rest }) {
|
|
28
67
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
29
|
-
const [imgSrc, setImgSrc] = (0, react_1.useState)(lazy ?
|
|
30
|
-
const [isInView, setIsInView] = (0, react_1.useState)(!lazy);
|
|
68
|
+
const [imgSrc, setImgSrc] = (0, react_1.useState)(lazy ? null : source);
|
|
69
|
+
const [isInView, setIsInView] = (0, react_1.useState)(!lazy);
|
|
31
70
|
const imgRef = (0, react_1.useRef)(null);
|
|
32
|
-
// Intersection Observer for lazy loading
|
|
33
71
|
(0, react_1.useEffect)(() => {
|
|
34
72
|
if (!lazy)
|
|
35
73
|
return;
|
|
36
|
-
// Store the current ref value in a variable
|
|
37
74
|
const currentImgRef = imgRef.current;
|
|
38
75
|
if (!currentImgRef)
|
|
39
76
|
return;
|
|
@@ -41,12 +78,12 @@ style, ...rest }) {
|
|
|
41
78
|
entries.forEach((entry) => {
|
|
42
79
|
if (entry.isIntersecting) {
|
|
43
80
|
setIsInView(true);
|
|
44
|
-
observer.unobserve(entry.target);
|
|
81
|
+
observer.unobserve(entry.target);
|
|
45
82
|
}
|
|
46
83
|
});
|
|
47
84
|
}, {
|
|
48
85
|
rootMargin: '0px',
|
|
49
|
-
threshold: 0.1,
|
|
86
|
+
threshold: 0.1,
|
|
50
87
|
});
|
|
51
88
|
observer.observe(currentImgRef);
|
|
52
89
|
return () => {
|
|
@@ -55,7 +92,6 @@ style, ...rest }) {
|
|
|
55
92
|
}
|
|
56
93
|
};
|
|
57
94
|
}, [lazy]);
|
|
58
|
-
// Load image when in view
|
|
59
95
|
(0, react_1.useEffect)(() => {
|
|
60
96
|
if (!isInView)
|
|
61
97
|
return;
|
|
@@ -76,30 +112,27 @@ style, ...rest }) {
|
|
|
76
112
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad();
|
|
77
113
|
};
|
|
78
114
|
img.onerror = () => {
|
|
79
|
-
setImgSrc(fallbackImageURL);
|
|
115
|
+
setImgSrc(fallbackImageURL);
|
|
80
116
|
setIsLoading(false);
|
|
81
117
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
82
118
|
};
|
|
83
119
|
}
|
|
84
120
|
catch (error) {
|
|
85
|
-
setImgSrc(fallbackImageURL);
|
|
121
|
+
setImgSrc(fallbackImageURL);
|
|
86
122
|
setIsLoading(false);
|
|
87
123
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
88
124
|
}
|
|
89
125
|
};
|
|
90
126
|
loadImage();
|
|
91
127
|
}, [source, sourceSet, crossOrigin, onLoad, onError, isInView]);
|
|
92
|
-
// Combine styles for rounded corners
|
|
93
128
|
const combinedStyle = {
|
|
94
129
|
...(rounded ? { borderRadius: 'var(--p-border-radius-3)' } : {}),
|
|
95
130
|
...style,
|
|
96
131
|
};
|
|
97
|
-
return (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
onError === null || onError === void 0 ? void 0 : onError();
|
|
103
|
-
} }));
|
|
132
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("style", { children: imageStyles }), (0, jsx_runtime_1.jsxs)("div", { style: combinedStyle, className: `image-wrapper ${className || ''}`, children: [isLoading && (0, jsx_runtime_1.jsx)("img", { src: loaderImageURL, alt: 'Loading', className: 'loader' }), (0, jsx_runtime_1.jsx)("img", { ...rest, ref: imgRef, alt: alt, src: imgSrc !== null && imgSrc !== void 0 ? imgSrc : undefined, crossOrigin: crossOrigin, srcSet: sourceSet === null || sourceSet === void 0 ? void 0 : sourceSet.map(({ source, descriptor }) => `${source} ${descriptor || ''}`).join(', '), className: `image ${isLoading ? 'image-loading' : ''}`, loading: lazy ? 'lazy' : 'eager', onError: (e) => {
|
|
133
|
+
e.currentTarget.src = fallbackImageURL;
|
|
134
|
+
setIsLoading(false);
|
|
135
|
+
onError === null || onError === void 0 ? void 0 : onError();
|
|
136
|
+
} })] })] }));
|
|
104
137
|
}
|
|
105
138
|
exports.Image = Image;
|