@purpurds/content-block 5.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,124 @@
1
+ import React, { DetailedHTMLProps, HTMLAttributes, ReactNode } from "react";
2
+ import { Badge } from "@purpurds/badge";
3
+ import { CtaLink } from "@purpurds/cta-link";
4
+ import { Heading, HeadingTagType } from "@purpurds/heading";
5
+ import { IconCheckmark } from "@purpurds/icon";
6
+ import { Paragraph } from "@purpurds/paragraph";
7
+ import c from "classnames/bind";
8
+
9
+ import styles from "./content-block.module.scss";
10
+ import { ContentBlockGroup } from "./content-block-group";
11
+
12
+ const cx = c.bind(styles);
13
+ const rootClassName = "purpur-content-block";
14
+
15
+ type Cta = {
16
+ href: string;
17
+ text: string;
18
+ };
19
+
20
+ export type ContentBlockProps = {
21
+ ["data-testid"]?: string;
22
+ className?: string;
23
+ negative?: boolean;
24
+ image?: ReactNode;
25
+ video?: ReactNode;
26
+ tagline?: string;
27
+ ctas?: Cta[];
28
+ usp?: string[];
29
+ title?: string;
30
+ headingTag?: HeadingTagType;
31
+ headingVariant?: "title-100" | "title-200" | "title-300";
32
+ onCtaClick?: (cta: Cta) => void;
33
+ children?: ReactNode;
34
+ } & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
35
+
36
+ export const ContentBlock = ({
37
+ ["data-testid"]: dataTestId,
38
+ className,
39
+ negative,
40
+ image,
41
+ video,
42
+ tagline,
43
+ title,
44
+ ctas,
45
+ usp,
46
+ headingTag = "h2",
47
+ headingVariant = "title-300",
48
+ onCtaClick,
49
+ children,
50
+ ...props
51
+ }: ContentBlockProps) => {
52
+ const classes = cx([
53
+ className,
54
+ rootClassName,
55
+ {
56
+ [`${rootClassName}--negative`]: negative,
57
+ },
58
+ ]);
59
+
60
+ return (
61
+ <div data-testid={dataTestId} className={classes} {...props}>
62
+ <div className={cx(`${rootClassName}__section`)}>
63
+ {video ? (
64
+ <div className={cx(`${rootClassName}__video-wrapper`)}>{video}</div>
65
+ ) : (
66
+ <div className={cx(`${rootClassName}__image-wrapper`)}>{image}</div>
67
+ )}
68
+ </div>
69
+ <div className={cx(`${rootClassName}__section`)}>
70
+ <div className={cx(`${rootClassName}__content-wrapper`)}>
71
+ {tagline ? (
72
+ <Badge variant="special" className={cx(`${rootClassName}__badge`)}>
73
+ {tagline}
74
+ </Badge>
75
+ ) : null}
76
+
77
+ {title && title.trim() && (
78
+ <Heading variant={headingVariant} tag={headingTag} negative={negative}>
79
+ {title}
80
+ </Heading>
81
+ )}
82
+ <div className={cx(`${rootClassName}__content`)}>{children}</div>
83
+ {usp?.length ? (
84
+ <ul className={cx(`${rootClassName}__usp-list`)}>
85
+ {usp.map(
86
+ (point) =>
87
+ point && (
88
+ <li className={cx(`${rootClassName}__usp-list-item`)} key={point}>
89
+ <IconCheckmark
90
+ size="xs"
91
+ className={cx(`${rootClassName}__usp-list-item-icon`)}
92
+ />
93
+ <Paragraph negative={negative}>{point}</Paragraph>
94
+ </li>
95
+ )
96
+ )}
97
+ </ul>
98
+ ) : null}
99
+ {ctas && ctas.length > 0 && (
100
+ <div className={cx(`${rootClassName}__links`)}>
101
+ {ctas.map(
102
+ (cta, index) =>
103
+ cta.href && (
104
+ <CtaLink
105
+ key={cta.text + cta.href}
106
+ href={cta.href}
107
+ variant={index === 0 ? "primary" : "secondary"}
108
+ negative={negative}
109
+ onClick={() => onCtaClick?.(cta)}
110
+ >
111
+ {cta.text}
112
+ </CtaLink>
113
+ )
114
+ )}
115
+ </div>
116
+ )}
117
+ </div>
118
+ </div>
119
+ </div>
120
+ );
121
+ };
122
+
123
+ ContentBlock.Group = ContentBlockGroup;
124
+ ContentBlock.displayName = "ContentBlock";
@@ -0,0 +1,4 @@
1
+ declare module "*.scss" {
2
+ const styles: { [className: string]: string };
3
+ export default styles;
4
+ }