Skip to content

Commit

Permalink
refactor: new prop to apply css properties to :root
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Jan 3, 2025
1 parent 773feae commit 055a189
Show file tree
Hide file tree
Showing 7 changed files with 495 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/components/MemoriWidget/MemoriWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ export interface Props {
userAvatar?: string | JSX.Element;
useMathFormatting?: boolean;
autoStart?: boolean;
applyVarsToRoot?: boolean;
}

const MemoriWidget = ({
Expand Down Expand Up @@ -465,6 +466,7 @@ const MemoriWidget = ({
userAvatar,
useMathFormatting = false,
autoStart = false,
applyVarsToRoot = false,
}: Props) => {
const { t, i18n } = useTranslation();

Expand Down Expand Up @@ -2522,12 +2524,8 @@ const MemoriWidget = ({

const integrationStylesheet = `
${
preview
? '#preview,'
: selectedLayout === 'WEBSITE_ASSISTANT'
? ''
: ':root,'
} .memori-widget, .memori-drawer, .memori-modal {
preview ? '#preview, ' : applyVarsToRoot ? ':root, ' : ''
}memori-client, .memori-widget, .memori-drawer, .memori-modal {
${Object.entries(integrationProperties)
.map(([key, value]) => `${key}: ${value};`)
.join('\n')}
Expand Down
22 changes: 21 additions & 1 deletion src/components/layouts/FullPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,27 @@ it('renders FullPage layout unchanged', () => {
tenant={tenant}
tenantID="aisuru.com"
integration={integration}
layout="FULLPAGE"
layout="FULLPAGE"
/>
</VisemeProvider>
</I18nWrapper>
);
expect(container).toMatchSnapshot();
});

it('renders FullPage layout with root css properties unchanged', () => {
const { container } = render(
<I18nWrapper>
<VisemeProvider>
<Memori
showShare={true}
showSettings={true}
memori={memori}
tenant={tenant}
tenantID="aisuru.com"
integration={integration}
layout="FULLPAGE"
applyVarsToRoot
/>
</VisemeProvider>
</I18nWrapper>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layouts/__snapshots__/Chat.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`renders Chat layout unchanged 1`] = `
>
<style>
:root, .memori-widget, .memori-drawer, .memori-modal {
memori-client, .memori-widget, .memori-drawer, .memori-modal {
--memori-chat-bubble-bg: #fff;
--memori-text-color: #2a2a2a;
--memori-button-bg: #823ce1;
Expand Down
Loading

0 comments on commit 055a189

Please sign in to comment.