Skip to content

Commit c97ac2b

Browse files
committed
1 parent 1b8d30e commit c97ac2b

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

packages/koenig-lexical/src/components/ui/cards/CtaCard.jsx

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function CtaCard({
1010
buttonText,
1111
buttonUrl,
1212
hasBackground,
13+
hasImage,
1314
hasSponsorLabel,
1415
htmlEditor,
1516
htmlEditorInitialState,
@@ -19,7 +20,8 @@ export function CtaCard({
1920
updateButtonUrl,
2021
updateShowButton,
2122
updateHasBackground,
22-
updateHasSponsorLabel
23+
updateHasSponsorLabel,
24+
updateHasImage
2325
}) {
2426
return (
2527
<>
@@ -32,26 +34,33 @@ export function CtaCard({
3234
)}
3335

3436
<div className={`flex flex-col gap-5 py-5 ${hasSponsorLabel || !hasBackground ? 'border-t border-grey-300 dark:border-grey-800' : ''} ${hasBackground ? 'mx-5' : 'border-b border-grey-300 dark:border-grey-800'}`}>
35-
{/* HTML content */}
36-
<KoenigNestedEditor
37-
autoFocus={true}
38-
hasSettingsPanel={true}
39-
initialEditor={htmlEditor}
40-
initialEditorState={htmlEditorInitialState}
41-
nodes='basic'
42-
placeholderClassName={`bg-transparent whitespace-normal font-serif text-xl !text-grey-500 !dark:text-grey-800 ` }
43-
placeholderText="Write something worth clicking..."
44-
textClassName="w-full bg-transparent whitespace-normal font-serif text-xl text-grey-900 dark:text-grey-200"
45-
>
46-
<ReplacementStringsPlugin />
47-
</KoenigNestedEditor>
48-
49-
{/* Button */}
50-
{ (showButton && (isEditing || (buttonText && buttonUrl))) &&
51-
<div>
52-
<Button color={'accent'} dataTestId="cta-button" placeholder="Add button text" value={buttonText}/>
37+
{hasImage && (
38+
<div className="flex">
39+
<img alt="Placeholder" className="h-auto w-full rounded-md" src="https://images.unsplash.com/photo-1526170375885-4d8ecf77b99f?q=80&w=3888&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" />
5340
</div>
54-
}
41+
)}
42+
<div className="flex flex-col gap-5">
43+
{/* HTML content */}
44+
<KoenigNestedEditor
45+
autoFocus={true}
46+
hasSettingsPanel={true}
47+
initialEditor={htmlEditor}
48+
initialEditorState={htmlEditorInitialState}
49+
nodes='basic'
50+
placeholderClassName={`bg-transparent whitespace-normal font-serif text-xl !text-grey-500 !dark:text-grey-800 ` }
51+
placeholderText="Write something worth clicking..."
52+
textClassName="w-full bg-transparent whitespace-normal font-serif text-xl text-grey-900 dark:text-grey-200"
53+
>
54+
<ReplacementStringsPlugin />
55+
</KoenigNestedEditor>
56+
57+
{/* Button */}
58+
{ (showButton && (isEditing || (buttonText && buttonUrl))) &&
59+
<div>
60+
<Button color={'accent'} dataTestId="cta-button" placeholder="Add button text" value={buttonText}/>
61+
</div>
62+
}
63+
</div>
5564
</div>
5665

5766
{/* Read-only overlay */}
@@ -60,17 +69,23 @@ export function CtaCard({
6069

6170
{isEditing && (
6271
<SettingsPanel>
72+
{/* Background setting */}
73+
<ToggleSetting
74+
isChecked={hasBackground}
75+
label='Background'
76+
onChange={updateHasBackground}
77+
/>
6378
{/* Sponsor label setting */}
6479
<ToggleSetting
6580
isChecked={hasSponsorLabel}
6681
label='Sponsor label'
6782
onChange={updateHasSponsorLabel}
6883
/>
69-
{/* Background setting */}
84+
{/* Image setting */}
7085
<ToggleSetting
71-
isChecked={hasBackground}
72-
label='Background'
73-
onChange={updateHasBackground}
86+
isChecked={hasImage}
87+
label='Image'
88+
onChange={updateHasImage}
7489
/>
7590
{/* Button settings */}
7691
<ToggleSetting
@@ -106,6 +121,7 @@ CtaCard.propTypes = {
106121
buttonText: PropTypes.string,
107122
buttonUrl: PropTypes.string,
108123
hasBackground: PropTypes.bool,
124+
hasImage: PropTypes.bool,
109125
hasSponsorLabel: PropTypes.bool,
110126
isEditing: PropTypes.bool,
111127
showButton: PropTypes.bool,
@@ -115,17 +131,20 @@ CtaCard.propTypes = {
115131
updateButtonUrl: PropTypes.func,
116132
updateHasBackground: PropTypes.func,
117133
updateHasSponsorLabel: PropTypes.func,
134+
updateHasImage: PropTypes.func,
118135
updateShowButton: PropTypes.func
119136
};
120137

121138
CtaCard.defaultProps = {
122139
buttonText: '',
123140
buttonUrl: '',
124141
hasBackground: false,
142+
hasImage: false,
125143
hasSponsorLabel: false,
126144
isEditing: false,
127145
showButton: false,
128146
updateHasBackground: () => {},
129147
updateHasSponsorLabel: () => {},
148+
updateHasImage: () => {},
130149
updateShowButton: () => {}
131150
};

packages/koenig-lexical/src/components/ui/cards/CtaCard.stories.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Empty.args = {
6868
value: '',
6969
showButton: false,
7070
hasBackground: false,
71+
hasImage: false,
72+
hasSponsorLabel: false,
7173
buttonText: '',
7274
buttonUrl: '',
7375
suggestedUrls: []
@@ -78,6 +80,7 @@ Populated.args = {
7880
display: 'Editing',
7981
value: 'Want to get access to premium content?',
8082
showButton: true,
83+
hasImage: true,
8184
hasSponsorLabel: true,
8285
hasBackground: false,
8386
buttonText: 'Upgrade',

0 commit comments

Comments
 (0)