diff --git a/packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js b/packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js index 6f921848c6..ba20793584 100644 --- a/packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js +++ b/packages/kg-default-nodes/lib/nodes/call-to-action/CallToActionNode.js @@ -8,9 +8,10 @@ export class CallToActionNode extends generateDecoratorNode({nodeType: 'call-to- {name: 'showButton', default: false}, {name: 'buttonText', default: ''}, {name: 'buttonUrl', default: ''}, + {name: 'buttonColor', default: ''}, {name: 'hasSponsorLabel', default: false}, {name: 'hasBackground', default: false}, - {name: 'backgroundColor', default: '#123456'}, + {name: 'backgroundColor', default: 'none'}, {name: 'hasImage', default: false}, {name: 'imageUrl', default: ''} ]} @@ -22,6 +23,7 @@ export class CallToActionNode extends generateDecoratorNode({nodeType: 'call-to- showButton, buttonText, buttonUrl, + buttonColor, hasSponsorLabel, hasBackground, backgroundColor, @@ -34,9 +36,10 @@ export class CallToActionNode extends generateDecoratorNode({nodeType: 'call-to- this.__showButton = showButton || false; this.__buttonText = buttonText || ''; this.__buttonUrl = buttonUrl || ''; + this.__buttonColor = buttonColor || 'none'; this.__hasSponsorLabel = hasSponsorLabel || false; this.__hasBackground = hasBackground || false; - this.__backgroundColor = backgroundColor || '#123456'; + this.__backgroundColor = backgroundColor || 'none'; this.__hasImage = hasImage || false; this.__imageUrl = imageUrl || ''; } diff --git a/packages/kg-default-nodes/test/nodes/call-to-action.test.js b/packages/kg-default-nodes/test/nodes/call-to-action.test.js index 706a7ccd49..296bf3fb3a 100644 --- a/packages/kg-default-nodes/test/nodes/call-to-action.test.js +++ b/packages/kg-default-nodes/test/nodes/call-to-action.test.js @@ -33,9 +33,10 @@ describe('CallToActionNode', function () { showButton: true, buttonText: 'click me', buttonUrl: 'http://blog.com/post1', + buttonColor: 'none', hasSponsorLabel: true, hasBackground: true, - backgroundColor: '#123456', + backgroundColor: 'none', hasImage: true, imageUrl: 'http://blog.com/image1.jpg' }; @@ -58,6 +59,7 @@ describe('CallToActionNode', function () { callToActionNode.showButton.should.equal(dataset.showButton); callToActionNode.buttonText.should.equal(dataset.buttonText); callToActionNode.buttonUrl.should.equal(dataset.buttonUrl); + callToActionNode.buttonColor.should.equal(dataset.buttonColor); callToActionNode.hasSponsorLabel.should.equal(dataset.hasSponsorLabel); callToActionNode.hasBackground.should.equal(dataset.hasBackground); callToActionNode.backgroundColor.should.equal(dataset.backgroundColor); @@ -88,13 +90,17 @@ describe('CallToActionNode', function () { callToActionNode.buttonUrl = 'http://blog.com/post1'; callToActionNode.buttonUrl.should.equal('http://blog.com/post1'); + callToActionNode.buttonColor.should.equal('none'); + callToActionNode.buttonColor = 'red'; + callToActionNode.buttonColor.should.equal('red'); + callToActionNode.hasSponsorLabel.should.equal(false); callToActionNode.hasSponsorLabel = true; callToActionNode.hasBackground.should.equal(false); callToActionNode.hasBackground = true; - callToActionNode.backgroundColor.should.equal('#123456'); + callToActionNode.backgroundColor.should.equal('none'); callToActionNode.backgroundColor = '#654321'; callToActionNode.backgroundColor.should.equal('#654321'); diff --git a/packages/koenig-lexical/demo/DemoApp.jsx b/packages/koenig-lexical/demo/DemoApp.jsx index e0b7484cd5..28aca43c1a 100644 --- a/packages/koenig-lexical/demo/DemoApp.jsx +++ b/packages/koenig-lexical/demo/DemoApp.jsx @@ -50,7 +50,8 @@ const defaultCardConfig = { feature: { collections: true, collectionsCard: true, - contentVisibility: true + contentVisibility: true, + contentVisibilityAlpha: true }, deprecated: { headerV1: process.env.NODE_ENV === 'test' ? false : true // show header v1 only for tests diff --git a/packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx b/packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx index cb2555d8fb..24ac1745ca 100644 --- a/packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx +++ b/packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx @@ -60,26 +60,26 @@ export const ctaColorPicker = [ ]; export function CtaCard({ - buttonText, - buttonUrl, - buttonColor, + buttonText, // + buttonUrl, // + buttonColor, // buttonTextColor, - color, - hasSponsorLabel, + color, // + hasSponsorLabel, // htmlEditor, htmlEditorInitialState, - imageSrc, - isEditing, - isSelected, - layout, - showButton, - updateButtonText, - updateButtonUrl, - updateShowButton, - updateHasSponsorLabel, - updateLayout, - handleColorChange, - handleButtonColor + imageSrc, // + isEditing, // + isSelected, // + layout, // + showButton, // + updateButtonText, // + updateButtonUrl, // + updateShowButton, // + updateHasSponsorLabel, // + updateLayout, // + handleColorChange, // + handleButtonColor // }) { const [buttonColorPickerExpanded, setButtonColorPickerExpanded] = useState(false); diff --git a/packages/koenig-lexical/src/index.js b/packages/koenig-lexical/src/index.js index 7d948a8494..407dcdbd45 100644 --- a/packages/koenig-lexical/src/index.js +++ b/packages/koenig-lexical/src/index.js @@ -8,6 +8,7 @@ import KoenigNestedComposer from './components/KoenigNestedComposer'; /* Plugins */ import AudioPlugin from './plugins/AudioPlugin'; +import CallToActionPlugin from './plugins/CallToActionPlugin'; import CalloutPlugin from './plugins/CalloutPlugin'; import CardMenuPlugin from './plugins/CardMenuPlugin'; import CollectionPlugin from './plugins/CollectionPlugin'; @@ -65,6 +66,7 @@ export { AudioPlugin, CalloutPlugin, + CallToActionPlugin, CardMenuPlugin, CollectionPlugin, DragDropPastePlugin, diff --git a/packages/koenig-lexical/src/nodes/CallToActionNode.jsx b/packages/koenig-lexical/src/nodes/CallToActionNode.jsx new file mode 100644 index 0000000000..188dd69e26 --- /dev/null +++ b/packages/koenig-lexical/src/nodes/CallToActionNode.jsx @@ -0,0 +1,81 @@ +import CalloutCardIcon from '../assets/icons/kg-card-type-callout.svg?react'; +import KoenigCardWrapper from '../components/KoenigCardWrapper'; +import {BASIC_NODES} from '../index.js'; +import {CallToActionNode as BaseCallToActionNode} from '@tryghost/kg-default-nodes'; +import {CallToActionNodeComponent} from './CallToActionNodeComponent'; +import {createCommand} from 'lexical'; +import {populateNestedEditor, setupNestedEditor} from '../utils/nested-editors'; + +export const INSERT_CTA_COMMAND = createCommand(); + +export class CallToActionNode extends BaseCallToActionNode { + __htmlEditor; + __htmlEditorInitialState; + // TODO: Improve the copy of the menu item + static kgMenu = { + label: 'Call to Action', + desc: 'Add a call to action to your post', + Icon: CalloutCardIcon, // TODO: Replace with correct icon + insertCommand: INSERT_CTA_COMMAND, + matches: ['cta', 'call-to-action'], + priority: 10, + shortcut: '/cta', + isHidden: ({config}) => { + return !(config?.feature?.contentVisibilityAlpha === true); + } + }; + + static getType() { + return 'call-to-action'; + } + + getIcon() { + // TODO: replace with correct icon + return CalloutCardIcon; + } + + constructor(dataset = {}, key) { + super(dataset, key); + + // set up nested editor instances + setupNestedEditor(this, '__htmlEditor', {editor: dataset.htmlEditor, nodes: BASIC_NODES}); + + // populate nested editors on initial construction + if (!dataset.htmlEditor) { + populateNestedEditor(this, '__htmlEditor', dataset.html || '
Hey {first_name, "there"}
,