Skip to content

Commit

Permalink
feat: added CTA component for blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrina-bongiovanni committed Nov 14, 2024
1 parent c167d45 commit 088bc10
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 100 deletions.
2 changes: 1 addition & 1 deletion packages/volto-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"dependencies": {
"@loadable/component": "5.14.1",
"@plone/components": "2.0.0-alpha.13",
"@plone/components": "^2.1.1",
"@redturtle/volto-slate-extras": "workspace:^2.0.1",
"classnames": "2.2.6",
"lodash": "4.17.21",
Expand Down
21 changes: 10 additions & 11 deletions packages/volto-blocks/src/components/blocks/IconsAndText/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { defineMessages, useIntl } from 'react-intl';
import { v4 as uuid } from 'uuid';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type IconsAndTextEditProps = BlockEditProps & {
data: IconsAndTextData;
Expand Down Expand Up @@ -123,17 +124,15 @@ export default function Edit(props: IconsAndTextEditProps) {
))}
</div>
{data.linkHref?.[0] && (
<div className={cx('block-iconsandtext-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
openLinkInNewTab={false}
{...data}
/>
)}
</Container>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ViewItem from '@redturtle/volto-blocks/components/blocks/IconsAndText/Vie
import type { IconsAndTextData } from '@redturtle/volto-blocks/components/blocks/IconsAndText/schema';
import styles from '@redturtle/volto-blocks/components/blocks/IconsAndText/styles.module.scss';
import cx from 'classnames';
import CTA from '../commons/CTA';

type Props = BlockViewProps & {
data: IconsAndTextData;
Expand Down Expand Up @@ -53,14 +54,12 @@ export default function View({ data, className, style }: Props) {
))}
</div>
{data.linkHref?.[0] && (
<div className={cx('block-iconsandtext-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
openLinkInNewTab={false}
{...data}
/>
)}
</Container>
</section>
Expand Down
21 changes: 10 additions & 11 deletions packages/volto-blocks/src/components/blocks/Testimonials/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import blockIcon from '@redturtle/volto-blocks/icons/text7.svg';
import type { TestimonialsData } from '@redturtle/volto-blocks/components/blocks/Testimonials/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type TestimonialsEditProps = BlockEditProps & {
data: TestimonialsData;
Expand Down Expand Up @@ -91,17 +92,15 @@ export default function Edit(props: TestimonialsEditProps) {
placeholder={intl.formatMessage(messages.text)}
/>
{data.linkHref?.[0] && (
<div className={cx('block-testimonials-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
openLinkInNewTab={false}
{...data}
/>
)}
</div>
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styles from '@redturtle/volto-blocks/components/blocks/Testimonials/style
import type { TestimonialsData } from '@redturtle/volto-blocks/components/blocks/Testimonials/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type Props = BlockViewProps & {
data: TestimonialsData;
Expand Down Expand Up @@ -48,14 +49,12 @@ export default function View({ data, className, style }: Props) {
</div>
)}
{data.linkHref?.[0] && (
<div className={cx('block-testimonials-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
openLinkInNewTab={false}
{...data}
/>
)}
</div>
</Container>
Expand Down
21 changes: 10 additions & 11 deletions packages/volto-blocks/src/components/blocks/Text1/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import blockIcon from '@redturtle/volto-blocks/icons/text1.svg';
import type { Text1Data } from '@redturtle/volto-blocks/components/blocks/Text1/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type Text1EditProps = BlockEditProps & {
data: Text1Data;
Expand Down Expand Up @@ -64,17 +65,15 @@ export default function Edit(props: Text1EditProps) {
placeholder={intl.formatMessage(messages.title)}
/>
{data.linkHref?.[0] && (
<div className={cx('block-text1-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
openLinkInNewTab={false}
{...data}
/>
)}
</div>
<div className={cx('block-text1-wide-col', styles.wide)}>
Expand Down
15 changes: 7 additions & 8 deletions packages/volto-blocks/src/components/blocks/Text1/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styles from '@redturtle/volto-blocks/components/blocks/Text1/styles.modul
import type { Text1Data } from '@redturtle/volto-blocks/components/blocks/Text1/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type Props = BlockViewProps & {
data: Text1Data;
Expand All @@ -29,14 +30,12 @@ export default function View({ data, className, style }: Props) {
</h2>
)}
{data.linkHref?.[0] && (
<div className={cx('block-text1-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
openLinkInNewTab={false}
{...data}
/>
)}
</div>
<div className={cx('block-text1-wide-col', styles.wide)}>
Expand Down
21 changes: 10 additions & 11 deletions packages/volto-blocks/src/components/blocks/Text6/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import blockIcon from '@redturtle/volto-blocks/icons/text6.svg';
import type { Text6Data } from '@redturtle/volto-blocks/components/blocks/Text6/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type Text6EditProps = BlockEditProps & {
data: Text6Data;
Expand Down Expand Up @@ -73,17 +74,15 @@ export default function Edit(props: Text6EditProps) {
placeholder={intl.formatMessage(messages.text)}
/>
{data.linkHref?.[0] && (
<div className={cx('block-text6-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
openLinkInNewTab={false}
{...data}
/>
)}
</Container>
</section>
Expand Down
15 changes: 7 additions & 8 deletions packages/volto-blocks/src/components/blocks/Text6/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styles from '@redturtle/volto-blocks/components/blocks/Text6/styles.modul
import type { Text6Data } from '@redturtle/volto-blocks/components/blocks/Text6/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type Props = BlockViewProps & {
data: Text6Data;
Expand All @@ -33,14 +34,12 @@ export default function View({ data, className, style }: Props) {
</div>
)}
{data.linkHref?.[0] && (
<div className={cx('block-text6-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
openLinkInNewTab={false}
{...data}
/>
)}
</Container>
</section>
Expand Down
21 changes: 10 additions & 11 deletions packages/volto-blocks/src/components/blocks/Text7/Edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import blockIcon from '@redturtle/volto-blocks/icons/text7.svg';
import type { Text7Data } from '@redturtle/volto-blocks/components/blocks/Text7/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type Text7EditProps = BlockEditProps & {
data: Text7Data;
Expand Down Expand Up @@ -109,17 +110,15 @@ export default function Edit(props: Text7EditProps) {
placeholder={intl.formatMessage(messages.text)}
/>
{data.linkHref?.[0] && (
<div className={cx('block-text7-cta', styles.cta)}>
<UniversalLink
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
openLinkInNewTab={false}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={data.linkHref ? data.linkHref[0]['@id'] : undefined}
linkTitle={data.linkTitle}
onClick={(e: React.SyntheticEvent<HTMLLinkElement>) => {
e.preventDefault();
}}
openLinkInNewTab={false}
{...data}
/>
)}
</div>
</Container>
Expand Down
23 changes: 11 additions & 12 deletions packages/volto-blocks/src/components/blocks/Text7/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import styles from '@redturtle/volto-blocks/components/blocks/Text7/styles.modul
import type { Text7Data } from '@redturtle/volto-blocks/components/blocks/Text7/schema';

import config from '@plone/registry';
import CTA from '../commons/CTA';

type Props = BlockViewProps & {
data: Text7Data;
Expand Down Expand Up @@ -67,18 +68,16 @@ export default function View({ data, className, style }: Props) {
</div>
)}
{data.linkHref?.[0] && (
<div className={cx('block-text7-cta', styles.cta)}>
<UniversalLink
href={
data.linkHref
? flattenToAppURL(data.linkHref[0]['@id'])
: undefined
}
openLinkInNewTab={false}
>
{data.linkTitle}
</UniversalLink>
</div>
<CTA
href={
data.linkHref
? flattenToAppURL(data.linkHref[0]['@id'])
: undefined
}
linkTitle={data.linkTitle}
openLinkInNewTab={false}
{...data}
/>
)}
</div>
</Container>
Expand Down
20 changes: 20 additions & 0 deletions packages/volto-blocks/src/components/blocks/commons/CTA.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { type ComponentProps } from 'react';
import { UniversalLink } from '@plone/volto/components';

const CTA = (props: ComponentProps<typeof UniversalLink>) => {
const { href, linkTitle, onClick, openLinkInNewTab } = props;
return (
<div>
<UniversalLink
href={href}
openLinkInNewTab={openLinkInNewTab}
onClick={onClick}
{...props}
>
{linkTitle}
</UniversalLink>
</div>
);
};

export default CTA;

0 comments on commit 088bc10

Please sign in to comment.