@reykjavik/hanna-react 0.10.122 → 0.10.124
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/CHANGELOG.md +14 -0
- package/ContactBubble.d.ts +2 -0
- package/ContactBubble.js +5 -3
- package/FileInput.d.ts +1 -1
- package/FileInput.js +16 -2
- package/HannaCssLink.d.ts +15 -0
- package/HannaCssLink.js +45 -0
- package/ReadSpeakerPlayer.d.ts +1 -2
- package/ReadSpeakerPlayer.js +2 -2
- package/esm/ContactBubble.d.ts +2 -0
- package/esm/ContactBubble.js +5 -3
- package/esm/FileInput.d.ts +1 -1
- package/esm/FileInput.js +17 -3
- package/esm/HannaCssLink.d.ts +15 -0
- package/esm/HannaCssLink.js +40 -0
- package/esm/ReadSpeakerPlayer.d.ts +1 -2
- package/esm/ReadSpeakerPlayer.js +2 -2
- package/esm/index.d.ts +1 -0
- package/index.d.ts +1 -0
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.10.124
|
|
8
|
+
|
|
9
|
+
_2024-04-05_
|
|
10
|
+
|
|
11
|
+
- feat: Add prop `openBtnLabel` to `ContactBubble`
|
|
12
|
+
- feat: Make `FileInput`'s `dropzoneText` prop optional
|
|
13
|
+
|
|
14
|
+
## 0.10.123
|
|
15
|
+
|
|
16
|
+
_2024-03-21_
|
|
17
|
+
|
|
18
|
+
- feat: Add component `HannaCssLink` for flicker-free CSS URL changes
|
|
19
|
+
- feat: Make `'is'` the default language for `ReadSpeakerPlayer`
|
|
20
|
+
|
|
7
21
|
## 0.10.122
|
|
8
22
|
|
|
9
23
|
_2024-03-18_
|
package/ContactBubble.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export type ContactBubbleProps = {
|
|
|
46
46
|
* magic and always show the bubble toggler
|
|
47
47
|
*/
|
|
48
48
|
alwaysShow?: boolean;
|
|
49
|
+
/** Shorthand override for texts.openBtn, for quick customization */
|
|
50
|
+
openBtnLabel?: string;
|
|
49
51
|
texts?: ContactBubbleI18n;
|
|
50
52
|
lang?: HannaLang;
|
|
51
53
|
} & SSRSupportProps & WrapperElmProps & ({
|
package/ContactBubble.js
CHANGED
|
@@ -42,6 +42,8 @@ exports.ensureIcon = ensureIcon;
|
|
|
42
42
|
const ContactBubble = (props) => {
|
|
43
43
|
const { title, links, onToggle, alwaysShow, wrapperProps = {} } = props;
|
|
44
44
|
const txt = (0, i18n_1.getTexts)(props, exports.defaultTexts);
|
|
45
|
+
const openLabel = props.openBtnLabel || txt.openBtn;
|
|
46
|
+
const openLabelLong = !props.openBtnLabel ? txt.openBtnLong : undefined;
|
|
45
47
|
const useLocalState = props.open == null;
|
|
46
48
|
const [localOpen, setLocalOpen] = (0, react_1.useState)(false);
|
|
47
49
|
const open = useLocalState ? localOpen : props.open;
|
|
@@ -132,8 +134,8 @@ const ContactBubble = (props) => {
|
|
|
132
134
|
if (links.length === 0) {
|
|
133
135
|
return null;
|
|
134
136
|
}
|
|
135
|
-
const menu = (react_1.default.createElement("div", Object.assign({}, props.wrapperProps, { className: (0, classUtils_1.modifiedClass)('ContactBubble', null, wrapperProps.className), id: isBrowser && domid, hidden: isBrowser && !open, "data-always-show": alwaysShow || undefined, "data-sprinkled": isBrowser }),
|
|
136
|
-
react_1.default.createElement("h2", { className: "ContactBubble__title" }, title ||
|
|
137
|
+
const menu = (react_1.default.createElement("div", Object.assign({}, props.wrapperProps, { className: (0, classUtils_1.modifiedClass)('ContactBubble', null, wrapperProps.className), id: isBrowser && domid, hidden: isBrowser && !open, "data-label-openbtn": props.openBtnLabel, "data-always-show": alwaysShow || undefined, "data-sprinkled": isBrowser }),
|
|
138
|
+
react_1.default.createElement("h2", { className: "ContactBubble__title" }, title || openLabel),
|
|
137
139
|
react_1.default.createElement("ul", { className: "ContactBubble__list" }, links.map((linkInfo, i) => {
|
|
138
140
|
const { href, label, extraLabel, target, onClick } = linkInfo;
|
|
139
141
|
const icon = (0, exports.ensureIcon)(linkInfo.icon);
|
|
@@ -159,7 +161,7 @@ const ContactBubble = (props) => {
|
|
|
159
161
|
'\n\n',
|
|
160
162
|
isBrowser && (react_1.default.createElement("button", { className: "ContactBubble__closebtn", "aria-controls": domid, "aria-label": txt.closeBtnLong, onClick: () => closeBubble(), type: "button" }, txt.closeBtn))));
|
|
161
163
|
return isBrowser ? (react_1.default.createElement("div", { className: "ContactBubble__wrapper", ref: wrapperRef },
|
|
162
|
-
react_1.default.createElement("button", { className: "ContactBubble__openbtn", "aria-controls": domid, "aria-expanded": open, "aria-label":
|
|
164
|
+
react_1.default.createElement("button", { className: "ContactBubble__openbtn", "aria-controls": domid, "aria-expanded": open, "aria-label": openLabelLong, onClick: open ? () => closeBubble() : openBubble, type: "button" }, openLabel),
|
|
163
165
|
'\n\n',
|
|
164
166
|
menu)) : (menu);
|
|
165
167
|
};
|
package/FileInput.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type FileInputProps = FormFieldWrappingProps & {
|
|
|
14
14
|
* Default: no restrictions.
|
|
15
15
|
*/
|
|
16
16
|
accept?: string | Array<string>;
|
|
17
|
-
dropzoneText
|
|
17
|
+
dropzoneText?: string | JSX.Element;
|
|
18
18
|
removeFileText?: string;
|
|
19
19
|
lang?: HannaLang;
|
|
20
20
|
showFileSize?: boolean;
|
package/FileInput.js
CHANGED
|
@@ -15,6 +15,20 @@ const defaultRemoveFileText = {
|
|
|
15
15
|
en: 'Remove',
|
|
16
16
|
pl: 'Usuń',
|
|
17
17
|
};
|
|
18
|
+
const defaultDropzoneText = {
|
|
19
|
+
is: () => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
20
|
+
"Drag\u00F0u skr\u00E1 hinga\u00F0, e\u00F0a ",
|
|
21
|
+
react_1.default.createElement("strong", null, "smelltu"),
|
|
22
|
+
" til a\u00F0 velja.")),
|
|
23
|
+
en: () => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
24
|
+
"Drag files here, or ",
|
|
25
|
+
react_1.default.createElement("strong", null, "click"),
|
|
26
|
+
" to select.")),
|
|
27
|
+
pl: () => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
28
|
+
"Przeci\u0105gnij plik tutaj, lub ",
|
|
29
|
+
react_1.default.createElement("strong", null, "kliknij"),
|
|
30
|
+
" by wybra\u0107.")),
|
|
31
|
+
};
|
|
18
32
|
const defaultOnFilesRejected = (rejectedFiles) => {
|
|
19
33
|
window.alert(`Error:\n${rejectedFiles
|
|
20
34
|
.map((elm) => {
|
|
@@ -31,11 +45,11 @@ const arrayToFileList = (arr) => {
|
|
|
31
45
|
};
|
|
32
46
|
const FileInput = (props) => {
|
|
33
47
|
var _a, _b, _c;
|
|
34
|
-
const lang = props.lang || i18n_1.DEFAULT_LANG;
|
|
48
|
+
const lang = (0, i18n_1.ensureHannaLang)(props.lang) || i18n_1.DEFAULT_LANG;
|
|
35
49
|
const _d = (0, FormField_js_1.groupFormFieldWrapperProps)(props), { dropzoneProps, // eslint-disable-line deprecation/deprecation
|
|
36
50
|
multiple = (_b = (_a = props.dropzoneProps) === null || _a === void 0 ? void 0 : _a.multiple) !== null && _b !== void 0 ? _b : true, // eslint-disable-line deprecation/deprecation
|
|
37
51
|
accept = (_c = props.dropzoneProps) === null || _c === void 0 ? void 0 : _c.accept, // eslint-disable-line deprecation/deprecation
|
|
38
|
-
dropzoneText
|
|
52
|
+
dropzoneText = defaultDropzoneText[lang](), removeFileText = defaultRemoveFileText[lang], FileList = _FileInputFileList_js_1.DefaultFileList, onFilesUpdated = () => undefined, onFilesRejected, showFileSize, showImagePreviews, value = [], fieldWrapperProps } = _d, inputElementProps = tslib_1.__rest(_d, ["dropzoneProps", "multiple", "accept", "dropzoneText", "removeFileText", "FileList", "onFilesUpdated", "onFilesRejected", "showFileSize", "showImagePreviews", "value", "fieldWrapperProps"]);
|
|
39
53
|
const domid = (0, useDomid_js_1.useDomid)(props.id);
|
|
40
54
|
const fileInputWrapper = (0, react_1.useRef)(null);
|
|
41
55
|
const fileInput = (0, react_1.useRef)(null);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CssModuleToken, getCssBundleUrl } from '@reykjavik/hanna-css';
|
|
2
|
+
import { EitherObj } from '@reykjavik/hanna-utils';
|
|
3
|
+
type HannaCssLinkProps = EitherObj<{
|
|
4
|
+
tokens: Array<CssModuleToken> | string;
|
|
5
|
+
options?: Parameters<typeof getCssBundleUrl>[1];
|
|
6
|
+
}, {
|
|
7
|
+
href: string;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* A component that returns a `<link rel="stylesheet" ... />` element that
|
|
11
|
+
* loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
|
|
12
|
+
* changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const HannaCssLink: (props: HannaCssLinkProps) => JSX.Element;
|
|
15
|
+
export {};
|
package/HannaCssLink.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HannaCssLink = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
const hanna_css_1 = require("@reykjavik/hanna-css");
|
|
7
|
+
/**
|
|
8
|
+
* A component that returns a `<link rel="stylesheet" ... />` element that
|
|
9
|
+
* loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
|
|
10
|
+
* changes.
|
|
11
|
+
*/
|
|
12
|
+
const HannaCssLink = (props) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const newHref = (_a = props.href) !== null && _a !== void 0 ? _a : (0, hanna_css_1.getCssBundleUrl)(props.tokens, props.options);
|
|
15
|
+
const linkRef = (0, react_1.useRef)(null);
|
|
16
|
+
const currentHrefRef = (0, react_1.useRef)(newHref);
|
|
17
|
+
(0, react_1.useEffect)(() => {
|
|
18
|
+
const linkElm = linkRef.current;
|
|
19
|
+
if (!linkElm || newHref === currentHrefRef.current) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
let newLinkElm = document.createElement('link');
|
|
23
|
+
newLinkElm.rel = 'stylesheet';
|
|
24
|
+
newLinkElm.href = newHref;
|
|
25
|
+
linkElm.after(newLinkElm);
|
|
26
|
+
newLinkElm.onload = () => {
|
|
27
|
+
if (!newLinkElm) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
linkElm.href = newHref;
|
|
31
|
+
currentHrefRef.current = newHref;
|
|
32
|
+
newLinkElm.remove();
|
|
33
|
+
newLinkElm = undefined;
|
|
34
|
+
};
|
|
35
|
+
return () => {
|
|
36
|
+
if (!newLinkElm) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
newLinkElm.remove();
|
|
40
|
+
newLinkElm = undefined;
|
|
41
|
+
};
|
|
42
|
+
}, [newHref]);
|
|
43
|
+
return react_1.default.createElement("link", { ref: linkRef, rel: "stylesheet", href: currentHrefRef.current });
|
|
44
|
+
};
|
|
45
|
+
exports.HannaCssLink = HannaCssLink;
|
package/ReadSpeakerPlayer.d.ts
CHANGED
|
@@ -15,8 +15,7 @@ export type ReadSpeakerPlayerProps = {
|
|
|
15
15
|
/**
|
|
16
16
|
* Reading language/locale for the ReadSpeaker player.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
* the language of the page, and pick a default `voice` for that language.
|
|
18
|
+
* Default: `is`
|
|
20
19
|
*
|
|
21
20
|
* @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html#reading-language
|
|
22
21
|
*/
|
package/ReadSpeakerPlayer.js
CHANGED
|
@@ -16,7 +16,7 @@ const scriptTagSelector = `script#${scriptTagId}`;
|
|
|
16
16
|
*/
|
|
17
17
|
let buttons = 0;
|
|
18
18
|
exports.defaultReadSpeakerPlayerTexts = {
|
|
19
|
-
en: { linkText: 'Listen', linkLabel: 'Listen to this page read
|
|
19
|
+
en: { linkText: 'Listen', linkLabel: 'Listen to this page read out loud' },
|
|
20
20
|
is: { linkText: 'Hlusta', linkLabel: 'Hlusta á þessa síðu lesna upphátt' },
|
|
21
21
|
pl: { linkText: 'Posłuchaj', linkLabel: 'Posłuchaj tej strony odczytanej na głos' },
|
|
22
22
|
};
|
|
@@ -26,7 +26,7 @@ exports.defaultReadSpeakerPlayerTexts = {
|
|
|
26
26
|
* @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html
|
|
27
27
|
*/
|
|
28
28
|
const ReadSpeakerPlayer = (props) => {
|
|
29
|
-
const { align, float, customerId = '11315', lang = '', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
|
|
29
|
+
const { align, float, customerId = '11315', lang = 'is', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
|
|
30
30
|
const { linkText, linkLabel } = (0, i18n_1.getTexts)({ lang: lang.slice(0, 2), texts }, exports.defaultReadSpeakerPlayerTexts);
|
|
31
31
|
(0, react_1.useEffect)(() => {
|
|
32
32
|
var _a, _b;
|
package/esm/ContactBubble.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ export type ContactBubbleProps = {
|
|
|
46
46
|
* magic and always show the bubble toggler
|
|
47
47
|
*/
|
|
48
48
|
alwaysShow?: boolean;
|
|
49
|
+
/** Shorthand override for texts.openBtn, for quick customization */
|
|
50
|
+
openBtnLabel?: string;
|
|
49
51
|
texts?: ContactBubbleI18n;
|
|
50
52
|
lang?: HannaLang;
|
|
51
53
|
} & SSRSupportProps & WrapperElmProps & ({
|
package/esm/ContactBubble.js
CHANGED
|
@@ -37,6 +37,8 @@ export const ensureIcon = (maybeIcon) => maybeIcon && icons[maybeIcon]
|
|
|
37
37
|
export const ContactBubble = (props) => {
|
|
38
38
|
const { title, links, onToggle, alwaysShow, wrapperProps = {} } = props;
|
|
39
39
|
const txt = getTexts(props, defaultTexts);
|
|
40
|
+
const openLabel = props.openBtnLabel || txt.openBtn;
|
|
41
|
+
const openLabelLong = !props.openBtnLabel ? txt.openBtnLong : undefined;
|
|
40
42
|
const useLocalState = props.open == null;
|
|
41
43
|
const [localOpen, setLocalOpen] = useState(false);
|
|
42
44
|
const open = useLocalState ? localOpen : props.open;
|
|
@@ -127,8 +129,8 @@ export const ContactBubble = (props) => {
|
|
|
127
129
|
if (links.length === 0) {
|
|
128
130
|
return null;
|
|
129
131
|
}
|
|
130
|
-
const menu = (React.createElement("div", Object.assign({}, props.wrapperProps, { className: modifiedClass('ContactBubble', null, wrapperProps.className), id: isBrowser && domid, hidden: isBrowser && !open, "data-always-show": alwaysShow || undefined, "data-sprinkled": isBrowser }),
|
|
131
|
-
React.createElement("h2", { className: "ContactBubble__title" }, title ||
|
|
132
|
+
const menu = (React.createElement("div", Object.assign({}, props.wrapperProps, { className: modifiedClass('ContactBubble', null, wrapperProps.className), id: isBrowser && domid, hidden: isBrowser && !open, "data-label-openbtn": props.openBtnLabel, "data-always-show": alwaysShow || undefined, "data-sprinkled": isBrowser }),
|
|
133
|
+
React.createElement("h2", { className: "ContactBubble__title" }, title || openLabel),
|
|
132
134
|
React.createElement("ul", { className: "ContactBubble__list" }, links.map((linkInfo, i) => {
|
|
133
135
|
const { href, label, extraLabel, target, onClick } = linkInfo;
|
|
134
136
|
const icon = ensureIcon(linkInfo.icon);
|
|
@@ -154,7 +156,7 @@ export const ContactBubble = (props) => {
|
|
|
154
156
|
'\n\n',
|
|
155
157
|
isBrowser && (React.createElement("button", { className: "ContactBubble__closebtn", "aria-controls": domid, "aria-label": txt.closeBtnLong, onClick: () => closeBubble(), type: "button" }, txt.closeBtn))));
|
|
156
158
|
return isBrowser ? (React.createElement("div", { className: "ContactBubble__wrapper", ref: wrapperRef },
|
|
157
|
-
React.createElement("button", { className: "ContactBubble__openbtn", "aria-controls": domid, "aria-expanded": open, "aria-label":
|
|
159
|
+
React.createElement("button", { className: "ContactBubble__openbtn", "aria-controls": domid, "aria-expanded": open, "aria-label": openLabelLong, onClick: open ? () => closeBubble() : openBubble, type: "button" }, openLabel),
|
|
158
160
|
'\n\n',
|
|
159
161
|
menu)) : (menu);
|
|
160
162
|
};
|
package/esm/FileInput.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type FileInputProps = FormFieldWrappingProps & {
|
|
|
14
14
|
* Default: no restrictions.
|
|
15
15
|
*/
|
|
16
16
|
accept?: string | Array<string>;
|
|
17
|
-
dropzoneText
|
|
17
|
+
dropzoneText?: string | JSX.Element;
|
|
18
18
|
removeFileText?: string;
|
|
19
19
|
lang?: HannaLang;
|
|
20
20
|
showFileSize?: boolean;
|
package/esm/FileInput.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { modifiedClass } from '@hugsmidjan/qj/classUtils';
|
|
4
|
-
import { DEFAULT_LANG } from '@reykjavik/hanna-utils/i18n';
|
|
4
|
+
import { DEFAULT_LANG, ensureHannaLang } from '@reykjavik/hanna-utils/i18n';
|
|
5
5
|
import { useDropzone } from './_mixed_export_resolution_/ReactDropzone.js';
|
|
6
6
|
import { addPreview, formatBytes, getFileListUpdate, releasePreview, } from './FileInput/_FileInput.utils.js';
|
|
7
7
|
import { DefaultFileList } from './FileInput/_FileInputFileList.js';
|
|
@@ -12,6 +12,20 @@ const defaultRemoveFileText = {
|
|
|
12
12
|
en: 'Remove',
|
|
13
13
|
pl: 'Usuń',
|
|
14
14
|
};
|
|
15
|
+
const defaultDropzoneText = {
|
|
16
|
+
is: () => (React.createElement(React.Fragment, null,
|
|
17
|
+
"Drag\u00F0u skr\u00E1 hinga\u00F0, e\u00F0a ",
|
|
18
|
+
React.createElement("strong", null, "smelltu"),
|
|
19
|
+
" til a\u00F0 velja.")),
|
|
20
|
+
en: () => (React.createElement(React.Fragment, null,
|
|
21
|
+
"Drag files here, or ",
|
|
22
|
+
React.createElement("strong", null, "click"),
|
|
23
|
+
" to select.")),
|
|
24
|
+
pl: () => (React.createElement(React.Fragment, null,
|
|
25
|
+
"Przeci\u0105gnij plik tutaj, lub ",
|
|
26
|
+
React.createElement("strong", null, "kliknij"),
|
|
27
|
+
" by wybra\u0107.")),
|
|
28
|
+
};
|
|
15
29
|
const defaultOnFilesRejected = (rejectedFiles) => {
|
|
16
30
|
window.alert(`Error:\n${rejectedFiles
|
|
17
31
|
.map((elm) => {
|
|
@@ -28,11 +42,11 @@ const arrayToFileList = (arr) => {
|
|
|
28
42
|
};
|
|
29
43
|
export const FileInput = (props) => {
|
|
30
44
|
var _a, _b, _c;
|
|
31
|
-
const lang = props.lang || DEFAULT_LANG;
|
|
45
|
+
const lang = ensureHannaLang(props.lang) || DEFAULT_LANG;
|
|
32
46
|
const _d = groupFormFieldWrapperProps(props), { dropzoneProps, // eslint-disable-line deprecation/deprecation
|
|
33
47
|
multiple = (_b = (_a = props.dropzoneProps) === null || _a === void 0 ? void 0 : _a.multiple) !== null && _b !== void 0 ? _b : true, // eslint-disable-line deprecation/deprecation
|
|
34
48
|
accept = (_c = props.dropzoneProps) === null || _c === void 0 ? void 0 : _c.accept, // eslint-disable-line deprecation/deprecation
|
|
35
|
-
dropzoneText
|
|
49
|
+
dropzoneText = defaultDropzoneText[lang](), removeFileText = defaultRemoveFileText[lang], FileList = DefaultFileList, onFilesUpdated = () => undefined, onFilesRejected, showFileSize, showImagePreviews, value = [], fieldWrapperProps } = _d, inputElementProps = __rest(_d, ["dropzoneProps", "multiple", "accept", "dropzoneText", "removeFileText", "FileList", "onFilesUpdated", "onFilesRejected", "showFileSize", "showImagePreviews", "value", "fieldWrapperProps"]);
|
|
36
50
|
const domid = useDomid(props.id);
|
|
37
51
|
const fileInputWrapper = useRef(null);
|
|
38
52
|
const fileInput = useRef(null);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CssModuleToken, getCssBundleUrl } from '@reykjavik/hanna-css';
|
|
2
|
+
import { EitherObj } from '@reykjavik/hanna-utils';
|
|
3
|
+
type HannaCssLinkProps = EitherObj<{
|
|
4
|
+
tokens: Array<CssModuleToken> | string;
|
|
5
|
+
options?: Parameters<typeof getCssBundleUrl>[1];
|
|
6
|
+
}, {
|
|
7
|
+
href: string;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* A component that returns a `<link rel="stylesheet" ... />` element that
|
|
11
|
+
* loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
|
|
12
|
+
* changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const HannaCssLink: (props: HannaCssLinkProps) => JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { getCssBundleUrl } from '@reykjavik/hanna-css';
|
|
3
|
+
/**
|
|
4
|
+
* A component that returns a `<link rel="stylesheet" ... />` element that
|
|
5
|
+
* loads the Hanna CSS bundle, in a way that prevents FOUC when the token list
|
|
6
|
+
* changes.
|
|
7
|
+
*/
|
|
8
|
+
export const HannaCssLink = (props) => {
|
|
9
|
+
var _a;
|
|
10
|
+
const newHref = (_a = props.href) !== null && _a !== void 0 ? _a : getCssBundleUrl(props.tokens, props.options);
|
|
11
|
+
const linkRef = useRef(null);
|
|
12
|
+
const currentHrefRef = useRef(newHref);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const linkElm = linkRef.current;
|
|
15
|
+
if (!linkElm || newHref === currentHrefRef.current) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
let newLinkElm = document.createElement('link');
|
|
19
|
+
newLinkElm.rel = 'stylesheet';
|
|
20
|
+
newLinkElm.href = newHref;
|
|
21
|
+
linkElm.after(newLinkElm);
|
|
22
|
+
newLinkElm.onload = () => {
|
|
23
|
+
if (!newLinkElm) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
linkElm.href = newHref;
|
|
27
|
+
currentHrefRef.current = newHref;
|
|
28
|
+
newLinkElm.remove();
|
|
29
|
+
newLinkElm = undefined;
|
|
30
|
+
};
|
|
31
|
+
return () => {
|
|
32
|
+
if (!newLinkElm) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
newLinkElm.remove();
|
|
36
|
+
newLinkElm = undefined;
|
|
37
|
+
};
|
|
38
|
+
}, [newHref]);
|
|
39
|
+
return React.createElement("link", { ref: linkRef, rel: "stylesheet", href: currentHrefRef.current });
|
|
40
|
+
};
|
|
@@ -15,8 +15,7 @@ export type ReadSpeakerPlayerProps = {
|
|
|
15
15
|
/**
|
|
16
16
|
* Reading language/locale for the ReadSpeaker player.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
* the language of the page, and pick a default `voice` for that language.
|
|
18
|
+
* Default: `is`
|
|
20
19
|
*
|
|
21
20
|
* @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html#reading-language
|
|
22
21
|
*/
|
package/esm/ReadSpeakerPlayer.js
CHANGED
|
@@ -12,7 +12,7 @@ const scriptTagSelector = `script#${scriptTagId}`;
|
|
|
12
12
|
*/
|
|
13
13
|
let buttons = 0;
|
|
14
14
|
export const defaultReadSpeakerPlayerTexts = {
|
|
15
|
-
en: { linkText: 'Listen', linkLabel: 'Listen to this page read
|
|
15
|
+
en: { linkText: 'Listen', linkLabel: 'Listen to this page read out loud' },
|
|
16
16
|
is: { linkText: 'Hlusta', linkLabel: 'Hlusta á þessa síðu lesna upphátt' },
|
|
17
17
|
pl: { linkText: 'Posłuchaj', linkLabel: 'Posłuchaj tej strony odczytanej na głos' },
|
|
18
18
|
};
|
|
@@ -22,7 +22,7 @@ export const defaultReadSpeakerPlayerTexts = {
|
|
|
22
22
|
* @see https://docs.typo3.org/p/readspeaker/readspeaker-services/main/en-us/Configuration/Index.html
|
|
23
23
|
*/
|
|
24
24
|
export const ReadSpeakerPlayer = (props) => {
|
|
25
|
-
const { align, float, customerId = '11315', lang = '', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
|
|
25
|
+
const { align, float, customerId = '11315', lang = 'is', voice = /^is(?:_is)?$/i.test(lang) ? 'is_dora' : '', readId = '', readClass = readId ? '' : 'Layout__main', wrapperProps, texts, } = props;
|
|
26
26
|
const { linkText, linkLabel } = getTexts({ lang: lang.slice(0, 2), texts }, defaultReadSpeakerPlayerTexts);
|
|
27
27
|
useEffect(() => {
|
|
28
28
|
var _a, _b;
|
package/esm/index.d.ts
CHANGED
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
/// <reference path="./IframeBlock.d.tsx" />
|
|
60
60
|
/// <reference path="./HeroBlock.d.tsx" />
|
|
61
61
|
/// <reference path="./Heading.d.tsx" />
|
|
62
|
+
/// <reference path="./HannaCssLink.d.tsx" />
|
|
62
63
|
/// <reference path="./GridBlocks.d.tsx" />
|
|
63
64
|
/// <reference path="./Gallery.d.tsx" />
|
|
64
65
|
/// <reference path="./FormField.d.tsx" />
|
package/index.d.ts
CHANGED
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
/// <reference path="./IframeBlock.d.tsx" />
|
|
60
60
|
/// <reference path="./HeroBlock.d.tsx" />
|
|
61
61
|
/// <reference path="./Heading.d.tsx" />
|
|
62
|
+
/// <reference path="./HannaCssLink.d.tsx" />
|
|
62
63
|
/// <reference path="./GridBlocks.d.tsx" />
|
|
63
64
|
/// <reference path="./Gallery.d.tsx" />
|
|
64
65
|
/// <reference path="./FormField.d.tsx" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reykjavik/hanna-react",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.124",
|
|
4
4
|
"author": "Reykjavík (http://www.reykjavik.is)",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Hugsmiðjan ehf (http://www.hugsmidjan.is)",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@hugsmidjan/qj": "^4.22.1",
|
|
19
19
|
"@hugsmidjan/react": "^0.4.32",
|
|
20
20
|
"@reykjavik/hanna-css": "^0.4.14",
|
|
21
|
-
"@reykjavik/hanna-utils": "^0.2.
|
|
21
|
+
"@reykjavik/hanna-utils": "^0.2.15",
|
|
22
22
|
"@types/react-autosuggest": "^10.1.0",
|
|
23
23
|
"@types/react-datepicker": "^4.8.0",
|
|
24
24
|
"@types/react-transition-group": "^4.4.0",
|
|
@@ -289,6 +289,10 @@
|
|
|
289
289
|
"import": "./esm/Heading.js",
|
|
290
290
|
"require": "./Heading.js"
|
|
291
291
|
},
|
|
292
|
+
"./HannaCssLink": {
|
|
293
|
+
"import": "./esm/HannaCssLink.js",
|
|
294
|
+
"require": "./HannaCssLink.js"
|
|
295
|
+
},
|
|
292
296
|
"./GridBlocks": {
|
|
293
297
|
"import": "./esm/GridBlocks.js",
|
|
294
298
|
"require": "./GridBlocks.js"
|