@dbcdk/react-components 0.0.110 → 0.0.111
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.
|
@@ -2,17 +2,24 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
var React = require('react');
|
|
5
6
|
var styles = require('./MediaCard.module.css');
|
|
6
7
|
var SkeletonLoaderItem = require('../skeleton-loader/skeleton-loader-item/SkeletonLoaderItem');
|
|
7
8
|
|
|
8
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
10
|
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
10
12
|
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
11
13
|
|
|
14
|
+
function cx(...parts) {
|
|
15
|
+
return parts.filter(Boolean).join(" ");
|
|
16
|
+
}
|
|
12
17
|
function MediaCard({
|
|
13
18
|
src,
|
|
14
19
|
alt,
|
|
15
20
|
href,
|
|
21
|
+
component: Component,
|
|
22
|
+
linkElement,
|
|
16
23
|
loading = false,
|
|
17
24
|
aspectRatio = "1 / 1",
|
|
18
25
|
objectFit = "cover",
|
|
@@ -24,12 +31,13 @@ function MediaCard({
|
|
|
24
31
|
imageClassName,
|
|
25
32
|
linkProps
|
|
26
33
|
}) {
|
|
27
|
-
|
|
34
|
+
var _a;
|
|
35
|
+
const isInteractive = Boolean(href || Component || linkElement);
|
|
28
36
|
const hasCaption = showCaption && (caption || meta);
|
|
29
37
|
const content = /* @__PURE__ */ jsxRuntime.jsx(
|
|
30
38
|
"figure",
|
|
31
39
|
{
|
|
32
|
-
className:
|
|
40
|
+
className: cx(styles__default.default.root, isInteractive ? styles__default.default.interactive : void 0, className),
|
|
33
41
|
style: { "--media-card-aspect-ratio": aspectRatio },
|
|
34
42
|
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles__default.default.media, children: [
|
|
35
43
|
loading || !src ? /* @__PURE__ */ jsxRuntime.jsx(SkeletonLoaderItem.SkeletonLoaderItem, { height: "100%" }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -37,7 +45,7 @@ function MediaCard({
|
|
|
37
45
|
{
|
|
38
46
|
src,
|
|
39
47
|
alt,
|
|
40
|
-
className:
|
|
48
|
+
className: cx(styles__default.default.image, imageClassName),
|
|
41
49
|
style: {
|
|
42
50
|
objectFit,
|
|
43
51
|
objectPosition
|
|
@@ -51,10 +59,29 @@ function MediaCard({
|
|
|
51
59
|
] })
|
|
52
60
|
}
|
|
53
61
|
);
|
|
54
|
-
if (!
|
|
62
|
+
if (!isInteractive) {
|
|
55
63
|
return content;
|
|
56
64
|
}
|
|
57
|
-
|
|
65
|
+
const wrapperProps = {
|
|
66
|
+
...linkProps,
|
|
67
|
+
...href ? { href } : {},
|
|
68
|
+
className: cx(styles__default.default.link, linkProps == null ? void 0 : linkProps.className),
|
|
69
|
+
children: content
|
|
70
|
+
};
|
|
71
|
+
if (linkElement) {
|
|
72
|
+
const child = linkElement;
|
|
73
|
+
const childProps = (_a = child.props) != null ? _a : {};
|
|
74
|
+
return React__default.default.cloneElement(child, {
|
|
75
|
+
...childProps,
|
|
76
|
+
...wrapperProps,
|
|
77
|
+
className: cx(childProps.className, wrapperProps.className),
|
|
78
|
+
href: href != null ? href : childProps.href
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (Component) {
|
|
82
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ...wrapperProps });
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ jsxRuntime.jsx("a", { ...wrapperProps });
|
|
58
85
|
}
|
|
59
86
|
|
|
60
87
|
exports.MediaCard = MediaCard;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { AnchorHTMLAttributes, CSSProperties, ReactNode } from 'react';
|
|
1
|
+
import type { AnchorHTMLAttributes, CSSProperties, ElementType, ReactElement, ReactNode } from 'react';
|
|
2
2
|
type AspectRatio = '1 / 1' | '4 / 3' | '3 / 4' | '16 / 9' | string;
|
|
3
3
|
export type MediaCardProps = {
|
|
4
4
|
src?: string;
|
|
5
5
|
alt: string;
|
|
6
6
|
href?: string;
|
|
7
|
+
component?: ElementType<any>;
|
|
8
|
+
linkElement?: ReactElement<any>;
|
|
7
9
|
loading?: boolean;
|
|
8
10
|
aspectRatio?: AspectRatio;
|
|
9
11
|
objectFit?: CSSProperties['objectFit'];
|
|
@@ -15,5 +17,5 @@ export type MediaCardProps = {
|
|
|
15
17
|
imageClassName?: string;
|
|
16
18
|
linkProps?: Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'children'>;
|
|
17
19
|
};
|
|
18
|
-
export declare function MediaCard({ src, alt, href, loading, aspectRatio, objectFit, objectPosition, caption, meta, showCaption, className, imageClassName, linkProps, }: MediaCardProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare function MediaCard({ src, alt, href, component: Component, linkElement, loading, aspectRatio, objectFit, objectPosition, caption, meta, showCaption, className, imageClassName, linkProps, }: MediaCardProps): import("react/jsx-runtime").JSX.Element;
|
|
19
21
|
export {};
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
3
4
|
import styles from './MediaCard.module.css';
|
|
4
5
|
import { SkeletonLoaderItem } from '../skeleton-loader/skeleton-loader-item/SkeletonLoaderItem';
|
|
5
6
|
|
|
7
|
+
function cx(...parts) {
|
|
8
|
+
return parts.filter(Boolean).join(" ");
|
|
9
|
+
}
|
|
6
10
|
function MediaCard({
|
|
7
11
|
src,
|
|
8
12
|
alt,
|
|
9
13
|
href,
|
|
14
|
+
component: Component,
|
|
15
|
+
linkElement,
|
|
10
16
|
loading = false,
|
|
11
17
|
aspectRatio = "1 / 1",
|
|
12
18
|
objectFit = "cover",
|
|
@@ -18,12 +24,13 @@ function MediaCard({
|
|
|
18
24
|
imageClassName,
|
|
19
25
|
linkProps
|
|
20
26
|
}) {
|
|
21
|
-
|
|
27
|
+
var _a;
|
|
28
|
+
const isInteractive = Boolean(href || Component || linkElement);
|
|
22
29
|
const hasCaption = showCaption && (caption || meta);
|
|
23
30
|
const content = /* @__PURE__ */ jsx(
|
|
24
31
|
"figure",
|
|
25
32
|
{
|
|
26
|
-
className:
|
|
33
|
+
className: cx(styles.root, isInteractive ? styles.interactive : void 0, className),
|
|
27
34
|
style: { "--media-card-aspect-ratio": aspectRatio },
|
|
28
35
|
children: /* @__PURE__ */ jsxs("div", { className: styles.media, children: [
|
|
29
36
|
loading || !src ? /* @__PURE__ */ jsx(SkeletonLoaderItem, { height: "100%" }) : /* @__PURE__ */ jsx(
|
|
@@ -31,7 +38,7 @@ function MediaCard({
|
|
|
31
38
|
{
|
|
32
39
|
src,
|
|
33
40
|
alt,
|
|
34
|
-
className:
|
|
41
|
+
className: cx(styles.image, imageClassName),
|
|
35
42
|
style: {
|
|
36
43
|
objectFit,
|
|
37
44
|
objectPosition
|
|
@@ -45,10 +52,29 @@ function MediaCard({
|
|
|
45
52
|
] })
|
|
46
53
|
}
|
|
47
54
|
);
|
|
48
|
-
if (!
|
|
55
|
+
if (!isInteractive) {
|
|
49
56
|
return content;
|
|
50
57
|
}
|
|
51
|
-
|
|
58
|
+
const wrapperProps = {
|
|
59
|
+
...linkProps,
|
|
60
|
+
...href ? { href } : {},
|
|
61
|
+
className: cx(styles.link, linkProps == null ? void 0 : linkProps.className),
|
|
62
|
+
children: content
|
|
63
|
+
};
|
|
64
|
+
if (linkElement) {
|
|
65
|
+
const child = linkElement;
|
|
66
|
+
const childProps = (_a = child.props) != null ? _a : {};
|
|
67
|
+
return React.cloneElement(child, {
|
|
68
|
+
...childProps,
|
|
69
|
+
...wrapperProps,
|
|
70
|
+
className: cx(childProps.className, wrapperProps.className),
|
|
71
|
+
href: href != null ? href : childProps.href
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (Component) {
|
|
75
|
+
return /* @__PURE__ */ jsx(Component, { ...wrapperProps });
|
|
76
|
+
}
|
|
77
|
+
return /* @__PURE__ */ jsx("a", { ...wrapperProps });
|
|
52
78
|
}
|
|
53
79
|
|
|
54
80
|
export { MediaCard };
|