Skip to content

Commit

Permalink
Removed unnecessary constructor in CallToActionNode
Browse files Browse the repository at this point in the history
no issue

- `generateDecoratorNode()` already handles constructor creation with property assignment based on the properties array passed to it
- fixes an inconsistency in default values between the array passed to `generateDecoratorNode()` and the overridden constructor
  - switched to `''` in place of `'none'` to match other cards, updated related usage
  • Loading branch information
kevinansfield committed Feb 3, 2025
1 parent 31c9d78 commit 4de5ce5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,7 @@ export class CallToActionNode extends generateDecoratorNode({nodeType: 'call-to-
{name: 'imageUrl', default: ''}
]}
) {
/* override */
constructor({
layout,
textValue,
showButton,
buttonText,
buttonUrl,
buttonColor,
buttonTextColor,
hasSponsorLabel,
backgroundColor,
hasImage,
imageUrl
} = {}, key) {
super(key);
this.__layout = layout ?? 'minimal';
this.__textValue = textValue ?? '';
this.__showButton = showButton ?? false;
this.__buttonText = buttonText ?? '';
this.__buttonUrl = buttonUrl ?? '';
this.__buttonColor = buttonColor ?? 'none';
this.__buttonTextColor = buttonTextColor ?? 'none';
this.__hasSponsorLabel = hasSponsorLabel ?? true;
this.__backgroundColor = backgroundColor ?? 'grey';
this.__hasImage = hasImage ?? false;
this.__imageUrl = imageUrl ?? '';
}
/* overrides */
}

export const $createCallToActionNode = (dataset) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/kg-default-nodes/test/nodes/call-to-action.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ describe('CallToActionNode', function () {
callToActionNode.buttonUrl = 'http://blog.com/post1';
callToActionNode.buttonUrl.should.equal('http://blog.com/post1');

callToActionNode.buttonColor.should.equal('none');
callToActionNode.buttonColor.should.equal('');
callToActionNode.buttonColor = 'red';
callToActionNode.buttonColor.should.equal('red');

callToActionNode.buttonTextColor.should.equal('none');
callToActionNode.buttonTextColor.should.equal('');
callToActionNode.buttonTextColor = 'black';
callToActionNode.buttonTextColor.should.equal('black');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ const Template = ({display, value, ...args}) => {
<div>
<div className="kg-prose">
<div className="mx-auto my-8 min-w-[initial] max-w-[740px]">
<CardWrapper
<CardWrapper
IndicatorIcon={VisibilityIndicatorIcon}
indicatorPosition={{
top: '1.2rem'
}}
{...(args.color === 'none' && {wrapperStyle: 'wide'})}
{...display}
{...(args.color === '' && {wrapperStyle: 'wide'})}
{...display}
{...args}
>
<CtaCard {...display} {...args} htmlEditor={htmlEditor} />
Expand All @@ -77,10 +77,10 @@ const Template = ({display, value, ...args}) => {
</div>
{/* <div className="kg-prose dark bg-black px-4 py-8">
<div className="mx-auto my-8 min-w-[initial] max-w-[740px]">
<CardWrapper
IndicatorIcon={VisibilityIndicatorIcon}
{...(args.color === 'none' && {wrapperStyle: 'wide'})}
{...display}
<CardWrapper
IndicatorIcon={VisibilityIndicatorIcon}
{...(args.color === 'none' && {wrapperStyle: 'wide'})}
{...display}
{...args}
>
<CtaCard {...display} {...args} htmlEditor={htmlEditor} />
Expand Down
2 changes: 1 addition & 1 deletion packages/koenig-lexical/src/nodes/CallToActionNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class CallToActionNode extends BaseCallToActionNode {
return (
<KoenigCardWrapper
nodeKey={this.getKey()}
wrapperStyle={this.backgroundColor === 'none' ? 'wide' : 'regular'}
wrapperStyle={this.backgroundColor ? 'regular' : 'wide'}
>
<CallToActionNodeComponent
backgroundColor={this.backgroundColor}
Expand Down

0 comments on commit 4de5ce5

Please sign in to comment.