Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added changing background colour handling to CTA Card #1419

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ export const CallToActionNodeComponent = ({
});
};

const handleBackgroundColorChange = (val) => {
editor.update(() => {
const node = $getNodeByKey(nodeKey);
node.backgroundColor = val;
});
};

return (
<>
<CtaCard
Expand All @@ -72,7 +79,7 @@ export const CallToActionNodeComponent = ({
buttonUrl={buttonUrl}
color={backgroundColor}
handleButtonColor={handleButtonColorChange}
handleColorChange={() => {}}
handleColorChange={handleBackgroundColorChange}
hasBackground={hasBackground}
hasImage={hasImage}
hasSponsorLabel={hasSponsorLabel}
Expand Down
18 changes: 18 additions & 0 deletions packages/koenig-lexical/test/e2e/cards/cta-card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,22 @@ test.describe('Call To Action Card', async () => {
await page.click('[data-testid="cta-button-color"] button[title="Black"]');
expect(await page.getAttribute('[data-testid="cta-button"]', 'style')).toContain('color: rgb(0, 0, 0);');
});

test('can change background colours', async function () {
const colors = [
{testId: 'color-picker-grey', expectedClass: 'bg-grey'},
{testId: 'color-picker-green', expectedClass: 'bg-green'},
{testId: 'color-picker-blue', expectedClass: 'bg-blue'},
{testId: 'color-picker-yellow', expectedClass: 'bg-yellow'},
{testId: 'color-picker-red', expectedClass: 'bg-red'}
];
await focusEditor(page);
await insertCard(page, {cardName: 'call-to-action'});
const firstChildSelector = '[data-kg-card="call-to-action"] > :first-child';

for (const color of colors) {
await page.click(`[data-test-id="${color.testId}"]`);
await expect(page.locator(firstChildSelector)).toHaveClass(new RegExp(color.expectedClass));
}
});
});
Loading