Compare commits

...

3 Commits

Author SHA1 Message Date
a147084458 Release candidate 2024-07-14 08:39:36 +02:00
b25e171412 Add the CLEAR special class to remove Paterlyfly classes 2024-07-14 08:39:19 +02:00
60aaa03202 Annotate i18n nodes 2024-07-14 08:11:17 +02:00
4 changed files with 43 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "keycloakify", "name": "keycloakify",
"version": "10.0.0-rc.111", "version": "10.0.0-rc.112",
"description": "Create Keycloak themes using React", "description": "Create Keycloak themes using React",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -13,10 +13,11 @@ export function createUseI18n<MessageKey_themeDefined extends string = never>(me
const { withJsx } = (() => { const { withJsx } = (() => {
const cache = new WeakMap<GenericI18n_noJsx<MessageKey>, GenericI18n<MessageKey>>(); const cache = new WeakMap<GenericI18n_noJsx<MessageKey>, GenericI18n<MessageKey>>();
function renderHtmlString(htmlString: string): JSX.Element { function renderHtmlString(params: { htmlString: string; msgKey: string }): JSX.Element {
const { htmlString, msgKey } = params;
return ( return (
<div <div
style={{ display: "inline-block" }} data-kc-msg={msgKey}
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: htmlString __html: htmlString
}} }}
@ -37,8 +38,8 @@ export function createUseI18n<MessageKey_themeDefined extends string = never>(me
const i18n: I18n = { const i18n: I18n = {
...i18n_noJsx, ...i18n_noJsx,
msg: (...args) => renderHtmlString(i18n_noJsx.msgStr(...args)), msg: (msgKey, ...args) => renderHtmlString({ htmlString: i18n_noJsx.msgStr(msgKey, ...args), msgKey }),
advancedMsg: (...args) => renderHtmlString(i18n_noJsx.advancedMsgStr(...args)) advancedMsg: (msgKey, ...args) => renderHtmlString({ htmlString: i18n_noJsx.advancedMsgStr(msgKey, ...args), msgKey })
}; };
cache.set(i18n_noJsx, i18n); cache.set(i18n_noJsx, i18n);
@ -49,6 +50,19 @@ export function createUseI18n<MessageKey_themeDefined extends string = never>(me
return { withJsx }; return { withJsx };
})(); })();
add_style: {
const attributeName = "data-kc-i18n";
// Check if already exists in head
if (document.querySelector(`style[${attributeName}]`) !== null) {
break add_style;
}
const styleElement = document.createElement("style");
styleElement.attributes.setNamedItem(document.createAttribute(attributeName));
(styleElement.textContent = `[data-kc-msg] { display: inline-block; }`), document.head.prepend(styleElement);
}
const { getI18n } = createGetI18n(messagesByLanguageTag); const { getI18n } = createGetI18n(messagesByLanguageTag);
function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } { function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } {

View File

@ -71,10 +71,14 @@ export function createGetKcClsx<ClassKey extends string>(params: {
transform: classKey => { transform: classKey => {
assert(is<ClassKey>(classKey)); assert(is<ClassKey>(classKey));
const className = classes?.[classKey];
return clsx( return clsx(
classKey, classKey,
doUseDefaultCss ? defaultClasses[classKey] : undefined, doUseDefaultCss && !className?.split(" ").includes("CLEAR")
classes?.[classKey] ? defaultClasses[classKey]
: undefined,
className
); );
} }
}); });

View File

@ -13,10 +13,11 @@ export function createUseI18n<MessageKey_themeDefined extends string = never>(me
const { withJsx } = (() => { const { withJsx } = (() => {
const cache = new WeakMap<GenericI18n_noJsx<MessageKey>, GenericI18n<MessageKey>>(); const cache = new WeakMap<GenericI18n_noJsx<MessageKey>, GenericI18n<MessageKey>>();
function renderHtmlString(htmlString: string): JSX.Element { function renderHtmlString(params: { htmlString: string; msgKey: string }): JSX.Element {
const { htmlString, msgKey } = params;
return ( return (
<div <div
style={{ display: "inline-block" }} data-kc-msg={msgKey}
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: htmlString __html: htmlString
}} }}
@ -37,8 +38,8 @@ export function createUseI18n<MessageKey_themeDefined extends string = never>(me
const i18n: I18n = { const i18n: I18n = {
...i18n_noJsx, ...i18n_noJsx,
msg: (...args) => renderHtmlString(i18n_noJsx.msgStr(...args)), msg: (msgKey, ...args) => renderHtmlString({ htmlString: i18n_noJsx.msgStr(msgKey, ...args), msgKey }),
advancedMsg: (...args) => renderHtmlString(i18n_noJsx.advancedMsgStr(...args)) advancedMsg: (msgKey, ...args) => renderHtmlString({ htmlString: i18n_noJsx.advancedMsgStr(msgKey, ...args), msgKey })
}; };
cache.set(i18n_noJsx, i18n); cache.set(i18n_noJsx, i18n);
@ -49,6 +50,19 @@ export function createUseI18n<MessageKey_themeDefined extends string = never>(me
return { withJsx }; return { withJsx };
})(); })();
add_style: {
const attributeName = "data-kc-i18n";
// Check if already exists in head
if (document.querySelector(`style[${attributeName}]`) !== null) {
break add_style;
}
const styleElement = document.createElement("style");
styleElement.attributes.setNamedItem(document.createAttribute(attributeName));
(styleElement.textContent = `[data-kc-msg] { display: inline-block; }`), document.head.prepend(styleElement);
}
const { getI18n } = createGetI18n(messagesByLanguageTag); const { getI18n } = createGetI18n(messagesByLanguageTag);
function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } { function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } {