Compare commits

...

4 Commits

4 changed files with 23 additions and 4 deletions

View File

@ -1,3 +1,7 @@
## **2.3.0** (2021-10-07)
- #20: Support advancedMsg
## **2.2.0** (2021-10-07)
- Feat scrip: download-builtin-keycloak-theme for downloading any version of the builtin themes

View File

@ -1,6 +1,6 @@
{
"name": "keycloakify",
"version": "2.2.0",
"version": "2.3.0",
"description": "Keycloak theme generator for Reacts app",
"repository": {
"type": "git",

View File

@ -182,6 +182,7 @@
}
},
"msg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); },
"advancedMsg": function(){ throw new Error("use import { useKcMessage } from 'keycloakify'"); },
}
);

View File

@ -2,7 +2,6 @@
import { useCallback, useReducer } from "react";
import { useKcLanguageTag } from "./useKcLanguageTag";
import { kcMessages, evtTermsUpdated } from "./kcMessages/login";
import type { ReactNode } from "react";
import { useEvt } from "evt/hooks";
//NOTE for later: https://github.com/remarkjs/react-markdown/blob/236182ecf30bd89c1e5a7652acaf8d0bf81e6170/src/renderers.js#L7-L35
import ReactMarkdown from "react-markdown";
@ -45,7 +44,7 @@ export function useKcMessage() {
[kcLanguageTag, trigger]
);
const msg = useCallback<(...args: Parameters<typeof msgStr>) => ReactNode>(
const msg = useCallback<(...args: Parameters<typeof msgStr>) => JSX.Element>(
(key, ...args) =>
<ReactMarkdown allowDangerousHtml renderers={key === "termsText" ? undefined : { "paragraph": "span" }}>
{msgStr(key, ...args)}
@ -53,6 +52,21 @@ export function useKcMessage() {
[msgStr]
);
return { msg, msgStr };
const advancedMsg = useCallback(
(key: string): string => {
const match = key.match(/^\$\{([^{]+)\}$/);
if( match === null ){
return key;
}
return msgStr(match[1] as MessageKey);
},
[msgStr]
);
return { msg, msgStr, advancedMsg };
}