Skip to content

Commit

Permalink
feat: this changes the priority of theme overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-canon committed Jan 16, 2024
1 parent 312389b commit fe31c8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/react/hooks/paragon/useParagonThemeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const useParagonThemeCore = ({

const paragonCoreThemeLink = createCoreThemeLink(themeCore.urls.default);
document.head.insertAdjacentElement(
'afterbegin',
'beforeend',
paragonCoreThemeLink,
);

Expand Down
27 changes: 22 additions & 5 deletions src/react/hooks/paragon/useParagonThemeVariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const useParagonThemeVariants = ({
setIsBrandThemeVariantLoaded(true);
return;
}
const getParagonThemeCoreLink = () => document.head.querySelector('link[data-paragon-theme-core="true"]');
const getBrandThemeCoreLink = () => document.head.querySelector('link[data-brand-theme-core="true"]');
const getParagonThemeVariantLink = () => document.head.querySelector(`link[data-paragon-theme-variant='${themeVariant}']`);
const existingThemeVariantLink = document.head.querySelector(`link[href='${value.urls.default}']`);
const existingThemeVariantBrandLink = document.head.querySelector(`link[href='${value.urls.brandOverride}']`);
Expand Down Expand Up @@ -162,10 +164,25 @@ const useParagonThemeVariants = ({

if (!existingThemeVariantLink) {
const paragonThemeVariantLink = createThemeVariantLink(value.urls.default);
document.head.insertAdjacentElement(
'afterbegin',
paragonThemeVariantLink,
);
const foundParagonThemeCoreLink = getParagonThemeCoreLink();
const foundBrandThemeCoreLink = getBrandThemeCoreLink();

if (foundBrandThemeCoreLink) {
foundBrandThemeCoreLink.insertAdjacentElement(
'afterend',
paragonThemeVariantLink,
);
} else if (foundParagonThemeCoreLink) {
foundParagonThemeCoreLink.insertAdjacentElement(
'afterend',
paragonThemeVariantLink,
);
} else {
document.head.insertAdjacentElement(
'beforeend',
paragonThemeVariantLink,
);
}

if (value.urls.brandOverride) {
const brandThemeVariantLink = createThemeVariantLink(value.urls.brandOverride, { isBrandOverride: true });
Expand All @@ -177,7 +194,7 @@ const useParagonThemeVariants = ({
);
} else {
document.head.insertAdjacentElement(
'afterbegin',
'beforeend',
brandThemeVariantLink,
);
}
Expand Down

0 comments on commit fe31c8e

Please sign in to comment.