@ndlib/component-library 1.0.6 → 1.0.8
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.
|
@@ -11,6 +11,6 @@ export const Seo = ({ title, description, image, nofollow, noindex, pathname, })
|
|
|
11
11
|
noindex: noindex || defaultNoindex,
|
|
12
12
|
twitterUsername,
|
|
13
13
|
};
|
|
14
|
-
return (_jsxs(_Fragment, { children: [seo.title ? _jsx("title", Object.assign({ "data-testid": "seo-title" }, { children: seo.title })) : null, seo.title ? (_jsx("meta", { "data-testid": "seo-twitter-title", name: "twitter:title", content: seo.title })) : null, seo.title ? (_jsx("meta", { "data-testid": "seo-og-title", property: "og:title", content: seo.title })) : null, seo.url ? (_jsx("meta", { "data-testid": "seo-twitter-url", name: "twitter:url", content: seo.url })) : null, seo.url ? (_jsx("meta", { "data-testid": "seo-og-url", property: "og:url", content: seo.url })) : null, seo.description ? (_jsx("meta", { "data-testid": "seo-twitter-description", name: "twitter:description", content: seo.description })) : null, seo.description ? (_jsx("meta", { "data-testid": "seo-og-description", property: "og:description", content: seo.description })) : null, seo.image ? (_jsx("meta", { "data-testid": "seo-twitter-image", name: "twitter:image", content: seo.image })) : null, seo.image ? (_jsx("meta", { "data-testid": "seo-og-image", name: "og:image", content: seo.image })) : null, seo.twitterUsername ? (_jsx("meta", { "data-testid": "seo-twitter-creator", name: "twitter:creator", content: seo.twitterUsername })) : null, seo.nofollow ? (_jsx("meta", { "data-testid": "seo-nofollow", name: "robots", content: "nofollow" })) : null, seo.noindex ? (_jsx("meta", { "data-testid": "seo-noindex", name: "robots", content: "noindex" })) : null, _jsx("meta", { name: "twitter:card", content: "summary_large_image" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" })] }));
|
|
14
|
+
return (_jsxs(_Fragment, { children: [_jsx("link", { rel: "canonical", href: seo.url }), seo.title ? _jsx("title", Object.assign({ "data-testid": "seo-title" }, { children: seo.title })) : null, seo.title ? (_jsx("meta", { "data-testid": "seo-twitter-title", name: "twitter:title", content: seo.title })) : null, seo.title ? (_jsx("meta", { "data-testid": "seo-og-title", property: "og:title", content: seo.title })) : null, seo.url ? (_jsx("meta", { "data-testid": "seo-twitter-url", name: "twitter:url", content: seo.url })) : null, seo.url ? (_jsx("meta", { "data-testid": "seo-og-url", property: "og:url", content: seo.url })) : null, seo.description ? (_jsx("meta", { "data-testid": "seo-twitter-description", name: "twitter:description", content: seo.description })) : null, seo.description ? (_jsx("meta", { "data-testid": "seo-og-description", property: "og:description", content: seo.description })) : null, seo.image ? (_jsx("meta", { "data-testid": "seo-twitter-image", name: "twitter:image", content: seo.image })) : null, seo.image ? (_jsx("meta", { "data-testid": "seo-og-image", name: "og:image", content: seo.image })) : null, seo.twitterUsername ? (_jsx("meta", { "data-testid": "seo-twitter-creator", name: "twitter:creator", content: seo.twitterUsername })) : null, seo.nofollow ? (_jsx("meta", { "data-testid": "seo-nofollow", name: "robots", content: "nofollow" })) : null, seo.noindex ? (_jsx("meta", { "data-testid": "seo-noindex", name: "robots", content: "noindex" })) : null, _jsx("meta", { name: "twitter:card", content: "summary_large_image" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1" })] }));
|
|
15
15
|
};
|
|
16
16
|
export default Seo;
|
|
@@ -10,12 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
13
|
-
import React, { useState } from 'react';
|
|
13
|
+
import React, { useState, useEffect } from 'react';
|
|
14
14
|
import { useTheme } from '../../../../theme';
|
|
15
15
|
import { COLOR, colors } from '../../../../theme/colors';
|
|
16
16
|
import { getTypographyStyles, } from '../../../../theme/typography';
|
|
17
17
|
import { useMediaQuery } from '../../../providers/media';
|
|
18
18
|
import { multiplyRemSize } from '../../../../utils/misc';
|
|
19
|
+
import { useManualRerender } from '../../../../utils/hooks/useManualRerender';
|
|
19
20
|
const ReadMoreLink = (props) => {
|
|
20
21
|
const bg = colors[props.bg || COLOR.BACKGROUND];
|
|
21
22
|
const color = colors[props.color || COLOR.ND_BLUE_LIGHT];
|
|
@@ -44,22 +45,23 @@ export const useLinesHeight = (args) => {
|
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
export const ReadMore = (_a) => {
|
|
48
|
+
var _b, _c;
|
|
47
49
|
var { typography, sx, role, lines, fixedHeight, children } = _a, rest = __rest(_a, ["typography", "sx", "role", "lines", "fixedHeight", "children"]);
|
|
48
50
|
const ref = React.useRef(null);
|
|
49
51
|
const [showEllipsis, setShowEllipsis] = useState(true);
|
|
52
|
+
const forceRerender = useManualRerender();
|
|
50
53
|
const wrapperHeight = useLinesHeight({ typography, lines });
|
|
51
54
|
const { screenSize } = useMediaQuery();
|
|
52
55
|
const { color: _color, bg: _bg } = sx || {};
|
|
53
56
|
const color = Array.isArray(_color) ? _color[0] : _color;
|
|
54
57
|
const bg = Array.isArray(_bg) ? _bg[0] : _bg;
|
|
55
|
-
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
forceRerender({
|
|
60
|
+
delay: [100, 500, 2000],
|
|
61
|
+
});
|
|
62
|
+
}, []);
|
|
63
|
+
useEffect(() => {
|
|
56
64
|
if (ref.current) {
|
|
57
|
-
if (fixedHeight) {
|
|
58
|
-
ref.current.style.height = wrapperHeight;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
ref.current.style.maxHeight = wrapperHeight;
|
|
62
|
-
}
|
|
63
65
|
const isOverflowing = ref.current.scrollHeight > ref.current.clientHeight;
|
|
64
66
|
if (isOverflowing) {
|
|
65
67
|
setShowEllipsis(true);
|
|
@@ -68,9 +70,12 @@ export const ReadMore = (_a) => {
|
|
|
68
70
|
setShowEllipsis(false);
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
}, [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
}, [
|
|
74
|
+
children,
|
|
75
|
+
wrapperHeight,
|
|
76
|
+
screenSize,
|
|
77
|
+
(_b = ref === null || ref === void 0 ? void 0 : ref.current) === null || _b === void 0 ? void 0 : _b.scrollHeight,
|
|
78
|
+
(_c = ref === null || ref === void 0 ? void 0 : ref.current) === null || _c === void 0 ? void 0 : _c.clientHeight,
|
|
79
|
+
]);
|
|
80
|
+
return (_jsxs("div", Object.assign({ role: role || 'paragraph', ref: ref, sx: Object.assign(Object.assign({ maxHeight: wrapperHeight, overflow: 'hidden', position: 'relative', height: fixedHeight ? wrapperHeight : 'auto' }, getTypographyStyles(typography)), sx) }, rest, { children: [children, showEllipsis && _jsx(ReadMoreLink, { bg: bg, color: color })] })));
|
|
76
81
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
export const useManualRerender = () => {
|
|
3
|
+
const [renderCount, updateRenderCount] = useState(0);
|
|
4
|
+
return useCallback((params) => {
|
|
5
|
+
const { delay } = params || {};
|
|
6
|
+
if (delay) {
|
|
7
|
+
const delayArray = Array.isArray(delay) ? delay : [delay];
|
|
8
|
+
for (const timeout of delayArray) {
|
|
9
|
+
setTimeout(() => {
|
|
10
|
+
updateRenderCount((renderCount) => renderCount + 1);
|
|
11
|
+
}, timeout);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
updateRenderCount(renderCount + 1);
|
|
16
|
+
}
|
|
17
|
+
}, [renderCount, updateRenderCount]);
|
|
18
|
+
};
|