@macive/ui 0.0.22 → 0.0.23
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 +5 -3
- package/dist/src/components/Image/Image.js +23 -59
- 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 +1 -1
- package/dist/types/src/components/Icon/Icon.d.ts.map +1 -1
- package/dist/types/src/components/Image/Image.d.ts +2 -1
- 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/ui.min.css +1 -1
- package/package.json +1 -1
|
@@ -5,10 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Icon = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
/* eslint-disable no-console */
|
|
9
|
+
/* eslint-disable @next/next/no-img-element */
|
|
10
|
+
const react_1 = require("react");
|
|
8
11
|
const css_1 = require("../../utilities/css");
|
|
9
12
|
const Text_1 = require("../Text");
|
|
10
13
|
const Icon_classnames_1 = __importDefault(require("./Icon.classnames"));
|
|
11
|
-
const react_1 = require("react");
|
|
12
14
|
const COLORS_WITH_BACKDROPS = ['base', 'critical', 'highlight', 'success', 'warning'];
|
|
13
15
|
function Icon({ source, color, backdrop, accessibilityLabel, size = 20, theme }) {
|
|
14
16
|
var _a, _b;
|
|
@@ -85,9 +87,9 @@ function Icon({ source, color, backdrop, accessibilityLabel, size = 20, theme })
|
|
|
85
87
|
(0, react_1.isValidElement)(source) ? (source) : ((0, jsx_runtime_1.jsx)("span", { className: Icon_classnames_1.default.Svg, dangerouslySetInnerHTML: {
|
|
86
88
|
__html:
|
|
87
89
|
//@ts-expect-error index
|
|
88
|
-
typeof source.svg === 'string'
|
|
90
|
+
typeof (source === null || source === void 0 ? void 0 : source.svg) === 'string'
|
|
89
91
|
? //@ts-expect-error index
|
|
90
|
-
source.svg
|
|
92
|
+
source === null || source === void 0 ? void 0 : source.svg
|
|
91
93
|
: (_b = JSON.stringify(source)) === null || _b === void 0 ? void 0 : _b.replace(/"/g, "'"),
|
|
92
94
|
}, "aria-hidden": 'true' })),
|
|
93
95
|
placeholder: (0, jsx_runtime_1.jsx)("div", { className: Icon_classnames_1.default.Placeholder }),
|
|
@@ -3,6 +3,7 @@ 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
5
|
const react_1 = require("react");
|
|
6
|
+
// Fallback SVG as a data URL
|
|
6
7
|
exports.fallbackImageSVG = `
|
|
7
8
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="#ccc">
|
|
8
9
|
<rect width="100" height="100" />
|
|
@@ -12,65 +13,27 @@ exports.fallbackImageSVG = `
|
|
|
12
13
|
const fallbackSVG = `
|
|
13
14
|
<svg xmlns="http://www.w3.org/2000/svg" fill="#eae6e6" width="32" height="32" viewBox="0 0 32 32" stroke="#eae6e6">
|
|
14
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"/>
|
|
15
|
-
<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.002 0 0 0 4 6V22Z"/>
|
|
16
17
|
</svg>
|
|
17
18
|
`;
|
|
18
19
|
const errorkSVG = `
|
|
19
20
|
<svg xmlns="http://www.w3.org/2000/svg" fill="#dfc3c3" width="32" height="32" viewBox="0 0 32 32" stroke="#dfc3c3">
|
|
20
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"/>
|
|
21
|
-
<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.002 0 0 0 4 6V22Z"/>
|
|
22
23
|
</svg>
|
|
23
24
|
`;
|
|
24
25
|
const fallbackImageURL = `data:image/svg+xml;utf8,${encodeURIComponent(fallbackSVG)}`;
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 50 50">
|
|
28
|
-
<circle cx="25" cy="25" r="20" stroke="#ccc" stroke-width="5" fill="none" stroke-dasharray="31.415, 31.415">
|
|
29
|
-
<animateTransform attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="1s" repeatCount="indefinite" />
|
|
30
|
-
</circle>
|
|
31
|
-
</svg>
|
|
32
|
-
`;
|
|
33
|
-
const loaderImageURL = `data:image/svg+xml;utf8,${encodeURIComponent(loaderSVG)}`;
|
|
34
|
-
// Inline CSS for loader and image wrapper
|
|
35
|
-
const imageStyles = `
|
|
36
|
-
.image-wrapper {
|
|
37
|
-
position: relative;
|
|
38
|
-
width: 100%;
|
|
39
|
-
height: 100%;
|
|
40
|
-
display: flex;
|
|
41
|
-
align-items: center;
|
|
42
|
-
justify-content: center;
|
|
43
|
-
background: #f0f0f0; /* Light background for loader */
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.loader {
|
|
47
|
-
width: 40px;
|
|
48
|
-
height: 40px;
|
|
49
|
-
z-index: 1; /* Ensure loader is above background */
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.image {
|
|
53
|
-
width: 100%;
|
|
54
|
-
height: 100%;
|
|
55
|
-
object-fit: cover;
|
|
56
|
-
transition: opacity 0.3s ease-in-out;
|
|
57
|
-
z-index: 2; /* Ensure image is above loader */
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.image-loading {
|
|
61
|
-
opacity: 0;
|
|
62
|
-
}
|
|
63
|
-
`;
|
|
64
|
-
function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className, rounded, lazy = true, style, ...rest }) {
|
|
26
|
+
function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className, rounded, lazy = true, // Default to false
|
|
27
|
+
style, ...rest }) {
|
|
65
28
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
66
|
-
const [imgSrc, setImgSrc] = (0, react_1.useState)(lazy ?
|
|
67
|
-
const [isInView, setIsInView] = (0, react_1.useState)(!lazy);
|
|
29
|
+
const [imgSrc, setImgSrc] = (0, react_1.useState)(lazy ? '' : source); // Start with empty src if lazy
|
|
30
|
+
const [isInView, setIsInView] = (0, react_1.useState)(!lazy); // Assume visible if not lazy
|
|
68
31
|
const imgRef = (0, react_1.useRef)(null);
|
|
32
|
+
// Intersection Observer for lazy loading
|
|
69
33
|
(0, react_1.useEffect)(() => {
|
|
70
|
-
if (!lazy)
|
|
71
|
-
setIsInView(true); // Ensure non-lazy images load immediately
|
|
34
|
+
if (!lazy)
|
|
72
35
|
return;
|
|
73
|
-
|
|
36
|
+
// Store the current ref value in a variable
|
|
74
37
|
const currentImgRef = imgRef.current;
|
|
75
38
|
if (!currentImgRef)
|
|
76
39
|
return;
|
|
@@ -78,12 +41,12 @@ function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className
|
|
|
78
41
|
entries.forEach((entry) => {
|
|
79
42
|
if (entry.isIntersecting) {
|
|
80
43
|
setIsInView(true);
|
|
81
|
-
observer.unobserve(entry.target);
|
|
44
|
+
observer.unobserve(entry.target); // Stop observing once the image is in view
|
|
82
45
|
}
|
|
83
46
|
});
|
|
84
47
|
}, {
|
|
85
48
|
rootMargin: '0px',
|
|
86
|
-
threshold: 0.1,
|
|
49
|
+
threshold: 0.1, // Trigger when 10% of the image is visible
|
|
87
50
|
});
|
|
88
51
|
observer.observe(currentImgRef);
|
|
89
52
|
return () => {
|
|
@@ -92,6 +55,7 @@ function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className
|
|
|
92
55
|
}
|
|
93
56
|
};
|
|
94
57
|
}, [lazy]);
|
|
58
|
+
// Load image when in view
|
|
95
59
|
(0, react_1.useEffect)(() => {
|
|
96
60
|
if (!isInView)
|
|
97
61
|
return;
|
|
@@ -112,30 +76,30 @@ function Image({ alt, sourceSet, source, crossOrigin, onLoad, onError, className
|
|
|
112
76
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad();
|
|
113
77
|
};
|
|
114
78
|
img.onerror = () => {
|
|
115
|
-
setImgSrc(fallbackImageURL);
|
|
79
|
+
setImgSrc(fallbackImageURL); // Set fallback SVG on error
|
|
116
80
|
setIsLoading(false);
|
|
117
81
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
118
82
|
};
|
|
119
83
|
}
|
|
120
84
|
catch (error) {
|
|
121
|
-
setImgSrc(fallbackImageURL);
|
|
85
|
+
setImgSrc(fallbackImageURL); // Set fallback SVG on error
|
|
122
86
|
setIsLoading(false);
|
|
123
87
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
124
88
|
}
|
|
125
89
|
};
|
|
126
90
|
loadImage();
|
|
127
91
|
}, [source, sourceSet, crossOrigin, onLoad, onError, isInView]);
|
|
92
|
+
// Combine styles for rounded corners
|
|
128
93
|
const combinedStyle = {
|
|
129
94
|
...(rounded ? { borderRadius: 'var(--p-border-radius-3)' } : {}),
|
|
130
95
|
...style,
|
|
131
96
|
};
|
|
132
|
-
return (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
} })] })] }));
|
|
97
|
+
return (
|
|
98
|
+
// eslint-disable-next-line @next/next/no-img-element
|
|
99
|
+
(0, jsx_runtime_1.jsx)("img", { ...rest, ref: imgRef, alt: alt, src: imgSrc, style: combinedStyle, crossOrigin: crossOrigin, srcSet: sourceSet === null || sourceSet === void 0 ? void 0 : sourceSet.map(({ source, descriptor }) => `${source} ${descriptor || ''}`).join(', '), className: className, loading: lazy ? 'lazy' : 'eager', onError: (e) => {
|
|
100
|
+
e.currentTarget.src = fallbackImageURL; // Set fallback SVG on error
|
|
101
|
+
setIsLoading(false);
|
|
102
|
+
onError === null || onError === void 0 ? void 0 : onError();
|
|
103
|
+
} }));
|
|
140
104
|
}
|
|
141
105
|
exports.Image = Image;
|