@homecode/ui 5.20.21 → 5.20.22
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/esm/index.js +1 -0
- package/dist/esm/src/components/Autocomplete/Autocomplete.js +1 -0
- package/dist/esm/src/components/Img/Img.js +26 -0
- package/dist/esm/src/components/Img/Img.styl.js +20 -0
- package/dist/esm/src/components/InputFile/InputFile.js +1 -0
- package/dist/esm/types/src/components/Img/Img.d.ts +7 -0
- package/dist/esm/types/src/components/Img/Img.test.d.ts +1 -0
- package/dist/esm/types/src/components/Img/Img.types.d.ts +10 -0
- package/dist/esm/types/src/components/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -30,6 +30,7 @@ export { Gallery, normalizeGalleryItem } from './src/components/Gallery/Gallery.
|
|
|
30
30
|
export { GridLayout } from './src/components/GridLayout/GridLayout.js';
|
|
31
31
|
export { Heading } from './src/components/Heading/Heading.js';
|
|
32
32
|
export { Icon } from './src/components/Icon/Icon.js';
|
|
33
|
+
export { Img } from './src/components/Img/Img.js';
|
|
33
34
|
export { Input } from './src/components/Input/Input.js';
|
|
34
35
|
export { InputFile } from './src/components/InputFile/InputFile.js';
|
|
35
36
|
export { Label } from './src/components/Label/Label.js';
|
|
@@ -64,6 +64,7 @@ import '../VideoPlayer/VideoPlayer.styl.js';
|
|
|
64
64
|
import '../Gallery/Gallery.styl.js';
|
|
65
65
|
import '../GridLayout/GridLayout.styl.js';
|
|
66
66
|
import '../Heading/Heading.js';
|
|
67
|
+
import '../Img/Img.styl.js';
|
|
67
68
|
import '../InputFile/InputFile.styl.js';
|
|
68
69
|
import '../InputFile/Item/Item.styl.js';
|
|
69
70
|
import '@tiptap/core';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Icon } from '../Icon/Icon.js';
|
|
5
|
+
import S from './Img.styl.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `<img>` that never shows the browser's broken-image glyph or its alt text:
|
|
9
|
+
* when loading fails it renders `fallback` (a broken-image icon by default).
|
|
10
|
+
*/
|
|
11
|
+
function Img({ src, alt = '', fallback, fallbackClassName, className, onError, ...rest }) {
|
|
12
|
+
const [failedSrc, setFailedSrc] = useState(null);
|
|
13
|
+
// Keyed by src, so a new src gets a fresh attempt.
|
|
14
|
+
const isFailed = !src || failedSrc === src;
|
|
15
|
+
if (isFailed) {
|
|
16
|
+
if (fallback !== undefined)
|
|
17
|
+
return jsx(Fragment, { children: fallback });
|
|
18
|
+
return (jsx("span", { className: cn(S.fallback, className, fallbackClassName), role: "img", "aria-label": alt || undefined, children: jsx(Icon, { type: "brokenImage", className: S.fallbackIcon }) }));
|
|
19
|
+
}
|
|
20
|
+
return (jsx("img", { ...rest, src: src, alt: alt, className: className, onError: event => {
|
|
21
|
+
setFailedSrc(src);
|
|
22
|
+
onError?.(event);
|
|
23
|
+
} }));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { Img };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var css_248z = ".Img_fallback__crzoQ{align-items:center;color:currentColor;display:inline-flex;justify-content:center}.Img_fallbackIcon__oyxkV{height:50%;max-height:48px;max-width:48px;opacity:.4;width:50%}";
|
|
2
|
+
var S = {"fallback":"Img_fallback__crzoQ","fallbackIcon":"Img_fallbackIcon__oyxkV"};
|
|
3
|
+
if (typeof document !== 'undefined') {
|
|
4
|
+
var __uilibHead = document.head || document.getElementsByTagName('head')[0];
|
|
5
|
+
if (__uilibHead) {
|
|
6
|
+
var __uilibStyle = document.createElement('style');
|
|
7
|
+
__uilibStyle.setAttribute('data-uilib-css', '');
|
|
8
|
+
__uilibStyle.appendChild(document.createTextNode(css_248z));
|
|
9
|
+
var __uilibLink = __uilibHead.querySelector('link[rel="stylesheet"]');
|
|
10
|
+
var __uilibInline = __uilibHead.querySelector('style:not([data-uilib-css])');
|
|
11
|
+
var __uilibAnchor = __uilibLink || __uilibInline;
|
|
12
|
+
if (__uilibLink && __uilibInline && (__uilibLink.compareDocumentPosition(__uilibInline) & 4) === 0) {
|
|
13
|
+
__uilibAnchor = __uilibInline;
|
|
14
|
+
}
|
|
15
|
+
if (__uilibAnchor) __uilibHead.insertBefore(__uilibStyle, __uilibAnchor);
|
|
16
|
+
else __uilibHead.appendChild(__uilibStyle);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { S as default };
|
|
@@ -66,6 +66,7 @@ import '../VideoPlayer/VideoPlayer.styl.js';
|
|
|
66
66
|
import '../Gallery/Gallery.styl.js';
|
|
67
67
|
import '../GridLayout/GridLayout.styl.js';
|
|
68
68
|
import '../Heading/Heading.js';
|
|
69
|
+
import '../Img/Img.styl.js';
|
|
69
70
|
import '../LightBox/LightBox.styl.js';
|
|
70
71
|
import '../NestedMenu/NestedMenu.js';
|
|
71
72
|
import '../Notifications/store.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as T from './Img.types';
|
|
2
|
+
export type ImgProps = T.Props;
|
|
3
|
+
/**
|
|
4
|
+
* `<img>` that never shows the browser's broken-image glyph or its alt text:
|
|
5
|
+
* when loading fails it renders `fallback` (a broken-image icon by default).
|
|
6
|
+
*/
|
|
7
|
+
export declare function Img({ src, alt, fallback, fallbackClassName, className, onError, ...rest }: T.Props): import("react").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ImgHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export type Props = ImgHTMLAttributes<HTMLImageElement> & {
|
|
3
|
+
/**
|
|
4
|
+
* Rendered instead of the image when it fails to load. Defaults to a
|
|
5
|
+
* broken-image icon. Pass `null` to render nothing.
|
|
6
|
+
*/
|
|
7
|
+
fallback?: ReactNode;
|
|
8
|
+
/** Class for the default fallback wrapper. */
|
|
9
|
+
fallbackClassName?: string;
|
|
10
|
+
};
|
|
@@ -24,6 +24,7 @@ export * from './Gallery/Gallery';
|
|
|
24
24
|
export * from './GridLayout/GridLayout';
|
|
25
25
|
export * from './Heading/Heading';
|
|
26
26
|
export * from './Icon/Icon';
|
|
27
|
+
export * from './Img/Img';
|
|
27
28
|
export * from './Input/Input';
|
|
28
29
|
export * from './InputFile/InputFile';
|
|
29
30
|
export * from './Label/Label';
|