@hubspot/cms-component-library 0.3.11 → 0.3.12
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.
- package/components/componentLibrary/Accordion/AccordionContent/index.module.scss +3 -5
- package/components/componentLibrary/Accordion/AccordionItem/StyleFields.tsx +6 -14
- package/components/componentLibrary/Accordion/AccordionItem/index.module.scss +7 -5
- package/components/componentLibrary/Accordion/AccordionItem/index.tsx +6 -15
- package/components/componentLibrary/Accordion/AccordionItem/types.ts +5 -5
- package/components/componentLibrary/Accordion/AccordionTitle/index.module.scss +6 -6
- package/components/componentLibrary/Accordion/llm.txt +15 -15
- package/components/componentLibrary/Accordion/stories/Accordion.stories.tsx +3 -3
- package/components/componentLibrary/Accordion/stories/AccordionDecorator.module.scss +38 -0
- package/components/componentLibrary/Accordion/stories/AccordionDecorator.tsx +7 -35
- package/components/componentLibrary/Card/index.module.scss +2 -4
- package/components/componentLibrary/Text/index.module.scss +40 -1
- package/components/componentLibrary/Text/llm.txt +4 -2
- package/components/componentLibrary/Video/ContentFields.tsx +1 -0
- package/components/componentLibrary/Video/StyleFields.tsx +42 -0
- package/components/componentLibrary/Video/index.tsx +11 -2
- package/components/componentLibrary/Video/islands/EmbedVideoIsland.tsx +239 -0
- package/components/componentLibrary/Video/islands/index.module.scss +94 -0
- package/package.json +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
.accordionContent {
|
|
2
|
-
padding-block:
|
|
3
|
-
padding-inline:
|
|
4
|
-
color:
|
|
5
|
-
font-size: var(--hscl-accordion-body-fontSize, 16px);
|
|
6
|
-
line-height: var(--hscl-accordion-body-lineHeight, 1.5);
|
|
2
|
+
padding-block: 16px;
|
|
3
|
+
padding-inline: 20px;
|
|
4
|
+
color: inherit;
|
|
7
5
|
|
|
8
6
|
:last-child {
|
|
9
7
|
margin-block-end: 0;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { VariantSelectionField } from '@hubspot/cms-components/fields';
|
|
2
2
|
import type { StyleFieldsProps } from './types.js';
|
|
3
3
|
|
|
4
4
|
const StyleFields = ({
|
|
5
|
-
variantLabel = '
|
|
6
|
-
variantName = '
|
|
7
|
-
variantDefault = '
|
|
5
|
+
variantLabel = 'Accordion variant',
|
|
6
|
+
variantName = 'accordionVariant',
|
|
7
|
+
variantDefault = { variant_name: 'card1' },
|
|
8
8
|
}: StyleFieldsProps) => {
|
|
9
9
|
return (
|
|
10
|
-
<
|
|
10
|
+
<VariantSelectionField
|
|
11
11
|
label={variantLabel}
|
|
12
12
|
name={variantName}
|
|
13
|
-
|
|
14
|
-
display="select"
|
|
15
|
-
choices={[
|
|
16
|
-
['variant1', 'Variant 1'],
|
|
17
|
-
['variant2', 'Variant 2'],
|
|
18
|
-
['variant3', 'Variant 3'],
|
|
19
|
-
['variant4', 'Variant 4'],
|
|
20
|
-
]}
|
|
21
|
-
required={false}
|
|
13
|
+
variantDefinitionName="card"
|
|
22
14
|
default={variantDefault}
|
|
23
15
|
/>
|
|
24
16
|
);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
.accordionItem {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
border
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
--hs-section-color: var(--hs-card-color);
|
|
3
|
+
|
|
4
|
+
border: var(--hs-card-borderWidth, 1px) solid
|
|
5
|
+
var(--hs-card-borderColor, #e0e0e0);
|
|
6
|
+
border-radius: var(--hs-card-borderRadius, 4px);
|
|
7
|
+
background-color: var(--hs-card-backgroundColor, transparent);
|
|
8
|
+
color: var(--hs-card-color, inherit);
|
|
7
9
|
overflow: hidden;
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
import styles from './index.module.scss';
|
|
2
2
|
import StyleFields from './StyleFields.js';
|
|
3
3
|
import cx from '../../utils/classname.js';
|
|
4
|
-
import { mapVariantToCssVars } from '../../utils/cssVars.js';
|
|
5
|
-
import { CSSVariables } from '../../utils/types.js';
|
|
6
4
|
import { AccordionItemProps } from './types.js';
|
|
7
5
|
|
|
8
6
|
const AccordionItemComponent = ({
|
|
9
|
-
variant = '
|
|
7
|
+
variant = 'card1',
|
|
10
8
|
className = '',
|
|
11
9
|
style = {},
|
|
12
10
|
children,
|
|
13
11
|
}: AccordionItemProps) => {
|
|
14
12
|
const combinedClasses = cx(styles.accordionItem, className);
|
|
15
13
|
|
|
16
|
-
const cssVariables: CSSVariables = variant
|
|
17
|
-
? mapVariantToCssVars('--hscl-accordion', variant, [
|
|
18
|
-
'borderColor',
|
|
19
|
-
'borderRadius',
|
|
20
|
-
'borderWidth',
|
|
21
|
-
'backgroundColor',
|
|
22
|
-
'color',
|
|
23
|
-
'icon-fill',
|
|
24
|
-
])
|
|
25
|
-
: {};
|
|
26
|
-
|
|
27
14
|
return (
|
|
28
|
-
<details
|
|
15
|
+
<details
|
|
16
|
+
className={combinedClasses}
|
|
17
|
+
style={style}
|
|
18
|
+
data-card-variant={variant}
|
|
19
|
+
>
|
|
29
20
|
{children}
|
|
30
21
|
</details>
|
|
31
22
|
);
|
|
@@ -3,10 +3,10 @@ import type { AccordionTitleProps } from '../AccordionTitle/types.js';
|
|
|
3
3
|
import type { AccordionContentProps } from '../AccordionContent/types.js';
|
|
4
4
|
|
|
5
5
|
export type AccordionVariant =
|
|
6
|
-
| '
|
|
7
|
-
| '
|
|
8
|
-
| '
|
|
9
|
-
| '
|
|
6
|
+
| 'card1'
|
|
7
|
+
| 'card2'
|
|
8
|
+
| 'card3'
|
|
9
|
+
| 'card4';
|
|
10
10
|
|
|
11
11
|
type AccordionItemChildren =
|
|
12
12
|
| ReactElement<AccordionTitleProps>
|
|
@@ -22,5 +22,5 @@ export type AccordionItemProps = {
|
|
|
22
22
|
export type StyleFieldsProps = {
|
|
23
23
|
variantLabel?: string;
|
|
24
24
|
variantName?: string;
|
|
25
|
-
variantDefault?:
|
|
25
|
+
variantDefault?: { variantName?: string; variant_name?: string };
|
|
26
26
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
.accordionTitle {
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
|
-
padding-block:
|
|
5
|
-
padding-inline:
|
|
6
|
-
background-color:
|
|
4
|
+
padding-block: 16px;
|
|
5
|
+
padding-inline: 20px;
|
|
6
|
+
background-color: transparent;
|
|
7
7
|
cursor: pointer;
|
|
8
8
|
list-style: none;
|
|
9
9
|
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
.accordionTitleText {
|
|
16
|
-
font-size:
|
|
17
|
-
font-weight:
|
|
18
|
-
margin-inline-end:
|
|
16
|
+
font-size: 24px;
|
|
17
|
+
font-weight: 600;
|
|
18
|
+
margin-inline-end: 16px;
|
|
19
19
|
flex: 1;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -89,7 +89,7 @@ Accordion/
|
|
|
89
89
|
**Props:**
|
|
90
90
|
```tsx
|
|
91
91
|
{
|
|
92
|
-
variant?: '
|
|
92
|
+
variant?: 'card1' | 'card2' | 'card3' | 'card4'; // Visual style variant (default: 'card1')
|
|
93
93
|
className?: string; // Additional CSS classes
|
|
94
94
|
style?: React.CSSProperties; // Inline styles
|
|
95
95
|
children: React.ReactNode; // Should contain AccordionTitle and AccordionContent
|
|
@@ -220,14 +220,14 @@ Configurable props for variant selection:
|
|
|
220
220
|
|
|
221
221
|
```tsx
|
|
222
222
|
<AccordionItem.StyleFields
|
|
223
|
-
variantName="
|
|
224
|
-
variantLabel="
|
|
225
|
-
variantDefault=
|
|
223
|
+
variantName="accordionVariant"
|
|
224
|
+
variantLabel="Accordion variant"
|
|
225
|
+
variantDefault={{ variant_name: 'card1' }}
|
|
226
226
|
/>
|
|
227
227
|
```
|
|
228
228
|
|
|
229
229
|
**Fields:**
|
|
230
|
-
- `
|
|
230
|
+
- `accordionVariant`: VariantSelectionField for selecting visual style using the card variant definition (card1, card2, card3, card4)
|
|
231
231
|
|
|
232
232
|
#### AccordionTitle.ContentFields
|
|
233
233
|
|
|
@@ -288,7 +288,7 @@ import { AccordionIconType } from '@hubspot/cms-component-library/Accordion/Acco
|
|
|
288
288
|
|
|
289
289
|
type FAQModuleProps = {
|
|
290
290
|
style?: {
|
|
291
|
-
|
|
291
|
+
accordionVariant?: { variantName: AccordionVariant };
|
|
292
292
|
icon?: AccordionIconType;
|
|
293
293
|
};
|
|
294
294
|
accordionItems?: Array<{
|
|
@@ -301,7 +301,7 @@ export const Component = ({
|
|
|
301
301
|
style,
|
|
302
302
|
accordionItems = [],
|
|
303
303
|
}: FAQModuleProps) => {
|
|
304
|
-
const variant = style?.
|
|
304
|
+
const variant = style?.accordionVariant?.variantName;
|
|
305
305
|
const icon = style?.icon;
|
|
306
306
|
|
|
307
307
|
return (
|
|
@@ -371,18 +371,18 @@ export const fields = (
|
|
|
371
371
|
|
|
372
372
|
### CSS Variables
|
|
373
373
|
|
|
374
|
-
The Accordion component uses CSS variables for theming and customization.
|
|
374
|
+
The Accordion component uses CSS variables for theming and customization. Variant styles are applied via `data-accordion-variant` data attribute selectors (following the same pattern as Card), using the card variant definition from `VariantSelectionField`.
|
|
375
375
|
|
|
376
|
-
**
|
|
376
|
+
**Base Variables (applied per variant via `[data-accordion-variant]` selectors):**
|
|
377
377
|
|
|
378
378
|
| Variable | Description | Default |
|
|
379
379
|
|----------|-------------|---------|
|
|
380
|
-
| `--hscl-accordion-
|
|
381
|
-
| `--hscl-accordion-
|
|
382
|
-
| `--hscl-accordion-
|
|
383
|
-
| `--hscl-accordion-
|
|
384
|
-
| `--hscl-accordion-
|
|
385
|
-
| `--hscl-accordion-
|
|
380
|
+
| `--hscl-accordion-borderColor` | Border color | `#e0e0e0` |
|
|
381
|
+
| `--hscl-accordion-borderRadius` | Border radius | `4px` |
|
|
382
|
+
| `--hscl-accordion-borderWidth` | Border width | `1px` |
|
|
383
|
+
| `--hscl-accordion-backgroundColor` | Background color | `transparent` |
|
|
384
|
+
| `--hscl-accordion-color` | Text color | `#33475b` |
|
|
385
|
+
| `--hscl-accordion-icon-fill` | Icon fill color | `#33475b` |
|
|
386
386
|
|
|
387
387
|
**Title-Specific Variables:**
|
|
388
388
|
|
|
@@ -153,7 +153,7 @@ export const Variants: Story = {
|
|
|
153
153
|
<SBContainer addBackground>
|
|
154
154
|
<h4>Variant 2</h4>
|
|
155
155
|
<Accordion>
|
|
156
|
-
<AccordionItem variant="
|
|
156
|
+
<AccordionItem variant="card2">
|
|
157
157
|
<AccordionTitle>Soft background styling</AccordionTitle>
|
|
158
158
|
<AccordionContent>
|
|
159
159
|
<p>
|
|
@@ -167,7 +167,7 @@ export const Variants: Story = {
|
|
|
167
167
|
<SBContainer addBackground>
|
|
168
168
|
<h4>Variant 3</h4>
|
|
169
169
|
<Accordion>
|
|
170
|
-
<AccordionItem variant="
|
|
170
|
+
<AccordionItem variant="card3">
|
|
171
171
|
<AccordionTitle>Bold accent styling</AccordionTitle>
|
|
172
172
|
<AccordionContent>
|
|
173
173
|
<p>Accent-colored border with sharp corners for emphasis.</p>
|
|
@@ -179,7 +179,7 @@ export const Variants: Story = {
|
|
|
179
179
|
<SBContainer addBackground>
|
|
180
180
|
<h4>Variant 4</h4>
|
|
181
181
|
<Accordion>
|
|
182
|
-
<AccordionItem variant="
|
|
182
|
+
<AccordionItem variant="card4">
|
|
183
183
|
<AccordionTitle>Rounded card styling</AccordionTitle>
|
|
184
184
|
<AccordionContent>
|
|
185
185
|
<p>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
.accordionContainer {
|
|
2
|
+
/* Accordion Variant Styles */
|
|
3
|
+
:global([data-accordion-variant='card1']) {
|
|
4
|
+
--hscl-accordion-borderColor: #e0e0e0;
|
|
5
|
+
--hscl-accordion-borderRadius: 4px;
|
|
6
|
+
--hscl-accordion-borderWidth: 1px;
|
|
7
|
+
--hscl-accordion-backgroundColor: transparent;
|
|
8
|
+
--hscl-accordion-color: #33475b;
|
|
9
|
+
--hscl-accordion-icon-fill: #33475b;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
:global([data-accordion-variant='card2']) {
|
|
13
|
+
--hscl-accordion-borderColor: #cbd6e2;
|
|
14
|
+
--hscl-accordion-borderRadius: 8px;
|
|
15
|
+
--hscl-accordion-borderWidth: 1px;
|
|
16
|
+
--hscl-accordion-backgroundColor: #f5f8fa;
|
|
17
|
+
--hscl-accordion-color: #33475b;
|
|
18
|
+
--hscl-accordion-icon-fill: #516f90;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
:global([data-accordion-variant='card3']) {
|
|
22
|
+
--hscl-accordion-borderColor: #ff7a59;
|
|
23
|
+
--hscl-accordion-borderRadius: 0;
|
|
24
|
+
--hscl-accordion-borderWidth: 2px;
|
|
25
|
+
--hscl-accordion-backgroundColor: transparent;
|
|
26
|
+
--hscl-accordion-color: #33475b;
|
|
27
|
+
--hscl-accordion-icon-fill: #ff7a59;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
:global([data-accordion-variant='card4']) {
|
|
31
|
+
--hscl-accordion-borderColor: #33475b;
|
|
32
|
+
--hscl-accordion-borderRadius: 12px;
|
|
33
|
+
--hscl-accordion-borderWidth: 1px;
|
|
34
|
+
--hscl-accordion-backgroundColor: #eaf0f6;
|
|
35
|
+
--hscl-accordion-color: #33475b;
|
|
36
|
+
--hscl-accordion-icon-fill: #33475b;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -1,41 +1,13 @@
|
|
|
1
1
|
import type { Decorator } from '@storybook/react';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
const defaultAccordionStyles: CSSVariables = {
|
|
5
|
-
'--hscl-listItem-color-primary': '#33475b',
|
|
6
|
-
'--hscl-listItem-color-secondary': '#516f90',
|
|
7
|
-
|
|
8
|
-
'--hscl-accordion-variant1-borderColor': '#e0e0e0',
|
|
9
|
-
'--hscl-accordion-variant1-borderRadius': '4px',
|
|
10
|
-
'--hscl-accordion-variant1-borderWidth': '1px',
|
|
11
|
-
'--hscl-accordion-variant1-backgroundColor': 'transparent',
|
|
12
|
-
'--hscl-accordion-variant1-color': '#33475b',
|
|
13
|
-
'--hscl-accordion-variant1-icon-fill': '#33475b',
|
|
14
|
-
|
|
15
|
-
'--hscl-accordion-variant2-borderColor': '#cbd6e2',
|
|
16
|
-
'--hscl-accordion-variant2-borderRadius': '8px',
|
|
17
|
-
'--hscl-accordion-variant2-borderWidth': '1px',
|
|
18
|
-
'--hscl-accordion-variant2-backgroundColor': '#f5f8fa',
|
|
19
|
-
'--hscl-accordion-variant2-color': '#33475b',
|
|
20
|
-
'--hscl-accordion-variant2-icon-fill': '#516f90',
|
|
21
|
-
|
|
22
|
-
'--hscl-accordion-variant3-borderColor': '#ff7a59',
|
|
23
|
-
'--hscl-accordion-variant3-borderRadius': '0',
|
|
24
|
-
'--hscl-accordion-variant3-borderWidth': '2px',
|
|
25
|
-
'--hscl-accordion-variant3-backgroundColor': 'transparent',
|
|
26
|
-
'--hscl-accordion-variant3-color': '#33475b',
|
|
27
|
-
'--hscl-accordion-variant3-icon-fill': '#ff7a59',
|
|
28
|
-
|
|
29
|
-
'--hscl-accordion-variant4-borderColor': '#33475b',
|
|
30
|
-
'--hscl-accordion-variant4-borderRadius': '12px',
|
|
31
|
-
'--hscl-accordion-variant4-borderWidth': '1px',
|
|
32
|
-
'--hscl-accordion-variant4-backgroundColor': '#eaf0f6',
|
|
33
|
-
'--hscl-accordion-variant4-color': '#33475b',
|
|
34
|
-
'--hscl-accordion-variant4-icon-fill': '#33475b',
|
|
35
|
-
};
|
|
2
|
+
import styles from './AccordionDecorator.module.scss';
|
|
36
3
|
|
|
37
4
|
export const withAccordionStyles: Decorator = Story => (
|
|
38
|
-
<div
|
|
5
|
+
<div className={styles.accordionContainer}>
|
|
39
6
|
<Story />
|
|
40
7
|
</div>
|
|
41
8
|
);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Export styles so stories can apply variant classes to AccordionItems
|
|
12
|
+
*/
|
|
13
|
+
export { styles as accordionStyles };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
.card {
|
|
2
|
+
--hs-section-color: var(--hs-card-color); // overrides card-based typography settings
|
|
3
|
+
|
|
2
4
|
display: flex;
|
|
3
5
|
flex-direction: column;
|
|
4
6
|
box-sizing: border-box;
|
|
@@ -7,8 +9,4 @@
|
|
|
7
9
|
background-color: var(--hs-card-backgroundColor, #ffffff);
|
|
8
10
|
color: var(--hs-card-color, inherit);
|
|
9
11
|
border: var(--hs-card-border, none);
|
|
10
|
-
|
|
11
|
-
h1,h2,h3,h4,h5,h6,p,span {
|
|
12
|
-
color: inherit;
|
|
13
|
-
}
|
|
14
12
|
}
|
|
@@ -1,3 +1,42 @@
|
|
|
1
1
|
.text {
|
|
2
|
-
color: var(--
|
|
2
|
+
color: var(--hs-section-color, currentColor);
|
|
3
|
+
|
|
4
|
+
p,
|
|
5
|
+
h1,
|
|
6
|
+
h2,
|
|
7
|
+
h3,
|
|
8
|
+
h4,
|
|
9
|
+
h5,
|
|
10
|
+
h6,
|
|
11
|
+
ul,
|
|
12
|
+
ol,
|
|
13
|
+
blockquote {
|
|
14
|
+
margin-block: 0 2rem;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
*:last-child {
|
|
18
|
+
margin-block-end: 0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
a {
|
|
22
|
+
color: var(--hs-section-link-color);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
a:hover {
|
|
26
|
+
color: var(--hs-section-link-color-hover);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
a:focus-visible {
|
|
30
|
+
color: var(--hs-section-link-color-hover);
|
|
31
|
+
outline: 2px solid Highlight;
|
|
32
|
+
outline-offset: 2px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
blockquote {
|
|
36
|
+
padding: 24px;
|
|
37
|
+
border-radius: 4px;
|
|
38
|
+
border-left: 3px solid var(--hs-section-blockquote-accentColor);
|
|
39
|
+
background-color: var(--hs-section-blockquote-backgroundColor);
|
|
40
|
+
color: var(--hs-section-blockquote-color);
|
|
41
|
+
}
|
|
3
42
|
}
|
|
@@ -147,8 +147,10 @@ export default function ArticleModule() {
|
|
|
147
147
|
|
|
148
148
|
### CSS Variables
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
By default, the Text component inherits styles from the HubSpot theme's section settings (e.g. `--hs-section-color`, `--hs-section-link-color`). The `--hscl-` variables below are overrides — use them when the component is placed in a context (like a Card) that requires different styling than the section defaults.
|
|
151
|
+
|
|
152
|
+
**Overrides:**
|
|
153
|
+
- `--hscl-text-color`: Text color (falls back to `--hs-section-color`, then `currentColor`)
|
|
152
154
|
|
|
153
155
|
## Accessibility
|
|
154
156
|
|
|
@@ -12,6 +12,48 @@ const StyleFields = ({
|
|
|
12
12
|
name={playButtonColorName}
|
|
13
13
|
default={playButtonColorDefault}
|
|
14
14
|
showOpacity={false}
|
|
15
|
+
visibilityRules="ADVANCED"
|
|
16
|
+
advancedVisibility={{
|
|
17
|
+
boolean_operator: 'OR',
|
|
18
|
+
criteria: [],
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
boolean_operator: 'AND',
|
|
22
|
+
criteria: [
|
|
23
|
+
{
|
|
24
|
+
controlling_field: 'videoType',
|
|
25
|
+
operator: 'EQUAL',
|
|
26
|
+
controlling_value_regex: 'hubspot_video',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
boolean_operator: 'AND',
|
|
32
|
+
criteria: [
|
|
33
|
+
{
|
|
34
|
+
controlling_field: 'videoType',
|
|
35
|
+
operator: 'EQUAL',
|
|
36
|
+
controlling_value_regex: 'embed',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
controlling_field: 'embedVideo',
|
|
40
|
+
operator: 'MATCHES_REGEX',
|
|
41
|
+
controlling_value_regex: '(?=.*"source_type":"oembed")',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
controlling_field: 'embedVideo',
|
|
45
|
+
operator: 'MATCHES_REGEX',
|
|
46
|
+
controlling_value_regex: '(?=.*"oembed_url":"(?!")+)',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
controlling_field: 'oembedThumbnail',
|
|
50
|
+
operator: 'MATCHES_REGEX',
|
|
51
|
+
controlling_value_regex: '(?=.*"src":"(?!")+)',
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
}}
|
|
15
57
|
/>
|
|
16
58
|
);
|
|
17
59
|
};
|
|
@@ -2,6 +2,8 @@ import { Island } from '@hubspot/cms-components';
|
|
|
2
2
|
import ContentFields from './ContentFields.js';
|
|
3
3
|
import StyleFields from './StyleFields.js';
|
|
4
4
|
// @ts-expect-error -- ?island not typed
|
|
5
|
+
import EmbedVideoIsland from './islands/EmbedVideoIsland.js?island';
|
|
6
|
+
// @ts-expect-error -- ?island not typed
|
|
5
7
|
import HSVideoIsland from './islands/HSVideoIsland.js?island';
|
|
6
8
|
import { VideoProps } from './types.js';
|
|
7
9
|
|
|
@@ -9,6 +11,7 @@ const VideoComponent = ({
|
|
|
9
11
|
videoType,
|
|
10
12
|
hubspotVideoParams,
|
|
11
13
|
embedVideoParams,
|
|
14
|
+
oembedThumbnail,
|
|
12
15
|
playButtonColor,
|
|
13
16
|
video,
|
|
14
17
|
}: VideoProps) => {
|
|
@@ -28,8 +31,14 @@ const VideoComponent = ({
|
|
|
28
31
|
videoType === 'embed' &&
|
|
29
32
|
Boolean(embedVideoParams?.oembed_url || embedVideoParams?.embed_html)
|
|
30
33
|
) {
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
return (
|
|
35
|
+
<Island
|
|
36
|
+
module={EmbedVideoIsland}
|
|
37
|
+
embedVideoParams={embedVideoParams}
|
|
38
|
+
oembedThumbnail={oembedThumbnail}
|
|
39
|
+
playButtonColor={playButtonColor}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
return null;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { CSSVariables } from '../../utils/types.js';
|
|
3
|
+
import { EmbedVideoIslandProps, EmbedVideoParams } from '../types.js';
|
|
4
|
+
import styles from './index.module.scss';
|
|
5
|
+
|
|
6
|
+
const toPx = (value: number | string | undefined) => {
|
|
7
|
+
if (typeof value === 'number') {
|
|
8
|
+
return `${value.toString()}px`;
|
|
9
|
+
} else if (typeof value === 'string') {
|
|
10
|
+
const parsed = parseFloat(value);
|
|
11
|
+
return isNaN(parsed) ? undefined : `${parsed}px`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const getSizeStyles = (
|
|
18
|
+
embedVideoParams: EmbedVideoParams,
|
|
19
|
+
oembedData: EmbedVideoParams['oembed_response']
|
|
20
|
+
) => {
|
|
21
|
+
const responseWidth = oembedData?.width;
|
|
22
|
+
const responseHeight = oembedData?.height;
|
|
23
|
+
switch (embedVideoParams.size_type) {
|
|
24
|
+
case 'exact':
|
|
25
|
+
return {
|
|
26
|
+
width: toPx(embedVideoParams.width ?? responseWidth),
|
|
27
|
+
height: toPx(embedVideoParams.height ?? responseHeight),
|
|
28
|
+
};
|
|
29
|
+
case 'auto_full_width':
|
|
30
|
+
return {};
|
|
31
|
+
default:
|
|
32
|
+
return {
|
|
33
|
+
maxWidth: toPx(embedVideoParams.max_width ?? responseWidth),
|
|
34
|
+
maxHeight: toPx(embedVideoParams.max_height ?? responseHeight),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const CustomThumbnailPlayIcon = () => (
|
|
40
|
+
<svg viewBox="0 0 135.39 149.4">
|
|
41
|
+
<path
|
|
42
|
+
d="M371.2,398.69l-127.79,71c-1.47.83-2.74.93-3.8.28a3.69,3.69,0,0,1-1.59-3.46V324.88a3.73,3.73,0,0,1,1.59-3.47,3.66,3.66,0,0,1,3.8.29l127.79,71c1.47.84,2.21,1.82,2.21,3S372.67,397.85,371.2,398.69Z"
|
|
43
|
+
transform="translate(-238.02 -321)"
|
|
44
|
+
></path>
|
|
45
|
+
</svg>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const OEmbedContainer = ({
|
|
49
|
+
embedVideoParams,
|
|
50
|
+
oEmbedThumbnail,
|
|
51
|
+
oEmbedPlayButtonColor,
|
|
52
|
+
}: {
|
|
53
|
+
embedVideoParams: EmbedVideoParams;
|
|
54
|
+
oEmbedThumbnail?: { src: string; alt?: string };
|
|
55
|
+
oEmbedPlayButtonColor?: { color?: string };
|
|
56
|
+
}) => {
|
|
57
|
+
const {
|
|
58
|
+
size_type: sizeType,
|
|
59
|
+
oembed_url: oembedUrl,
|
|
60
|
+
oembed_response: oembedResponse,
|
|
61
|
+
supported_oembed_types: supportedOembedTypes,
|
|
62
|
+
} = embedVideoParams;
|
|
63
|
+
|
|
64
|
+
const [oembedData, setOembedData] =
|
|
65
|
+
useState<EmbedVideoParams['oembed_response']>(oembedResponse);
|
|
66
|
+
const [hasPlayed, setHasPlayed] = useState(false);
|
|
67
|
+
const iframeWrapperRef = useRef<HTMLDivElement>(null);
|
|
68
|
+
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
69
|
+
|
|
70
|
+
const isSupportedOEmbedType = supportedOembedTypes.includes(
|
|
71
|
+
oembedData?.type || ''
|
|
72
|
+
);
|
|
73
|
+
const sizeStyles = useMemo(
|
|
74
|
+
() => getSizeStyles(embedVideoParams, oembedData),
|
|
75
|
+
[embedVideoParams, oembedData]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const cssVariables: CSSVariables = {
|
|
79
|
+
...(oEmbedPlayButtonColor?.color && {
|
|
80
|
+
'--hscl-video-playButton-color': oEmbedPlayButtonColor.color,
|
|
81
|
+
}),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (oembedData || !oembedUrl) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const fetchOEmbed = async () => {
|
|
90
|
+
try {
|
|
91
|
+
const query = new URLSearchParams({
|
|
92
|
+
url: oembedUrl,
|
|
93
|
+
autoplay: '0',
|
|
94
|
+
});
|
|
95
|
+
const response = await fetch(`/_hcms/oembed?${query}`);
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
console.error('Server reached, error retrieving oEmbed response.');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
setOembedData(await response.json());
|
|
101
|
+
} catch {
|
|
102
|
+
console.error(
|
|
103
|
+
'Could not reach the server. Failed to retrieve oEmbed response.'
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
fetchOEmbed();
|
|
108
|
+
}, [oembedUrl]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!oembedData) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const el = document.createElement('div');
|
|
116
|
+
el.innerHTML = oembedData.html;
|
|
117
|
+
const iframe = el.firstChild as HTMLIFrameElement;
|
|
118
|
+
iframe.setAttribute('class', styles['oembed_container_iframe']);
|
|
119
|
+
iframe.setAttribute('title', oembedData.title || '');
|
|
120
|
+
iframeRef.current = iframe;
|
|
121
|
+
if (!oEmbedThumbnail?.src) {
|
|
122
|
+
// if there is a custom thumbnail, iframe will be appended on click
|
|
123
|
+
iframeWrapperRef.current?.appendChild(iframe);
|
|
124
|
+
Object.assign(iframe.style, sizeStyles);
|
|
125
|
+
}
|
|
126
|
+
}, [oembedData, oEmbedThumbnail?.src]);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div
|
|
130
|
+
className={`${styles.oembed_container} ${
|
|
131
|
+
sizeType === 'auto_full_width' ? 'oembed_container--full-size' : ''
|
|
132
|
+
}`}
|
|
133
|
+
style={sizeStyles}
|
|
134
|
+
>
|
|
135
|
+
{oEmbedThumbnail?.src && (
|
|
136
|
+
<button
|
|
137
|
+
className={styles['oembed_custom-thumbnail']}
|
|
138
|
+
style={{
|
|
139
|
+
...sizeStyles,
|
|
140
|
+
backgroundImage: `url(${oEmbedThumbnail.src})`,
|
|
141
|
+
display: hasPlayed ? 'none' : undefined,
|
|
142
|
+
}}
|
|
143
|
+
onClick={() => {
|
|
144
|
+
const iframe = iframeRef.current;
|
|
145
|
+
if (iframe) {
|
|
146
|
+
const iframeSrc = new URL(iframe.src);
|
|
147
|
+
iframeSrc.searchParams.append('autoplay', '1');
|
|
148
|
+
iframe.src = iframeSrc.toString();
|
|
149
|
+
Object.assign(iframe.style, sizeStyles);
|
|
150
|
+
iframeWrapperRef.current?.appendChild(iframe);
|
|
151
|
+
setHasPlayed(true);
|
|
152
|
+
}
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
<span className={styles['oembed-info']}>
|
|
156
|
+
{[
|
|
157
|
+
'Video player',
|
|
158
|
+
oEmbedThumbnail.alt ?? '',
|
|
159
|
+
'Click to play video',
|
|
160
|
+
].join(' - ')}
|
|
161
|
+
</span>
|
|
162
|
+
<div
|
|
163
|
+
className={styles['oembed_custom-thumbnail_icon']}
|
|
164
|
+
style={cssVariables}
|
|
165
|
+
>
|
|
166
|
+
<CustomThumbnailPlayIcon />
|
|
167
|
+
</div>
|
|
168
|
+
</button>
|
|
169
|
+
)}
|
|
170
|
+
{isSupportedOEmbedType && oembedData && (
|
|
171
|
+
<div ref={iframeWrapperRef} className={styles.iframe_wrapper} />
|
|
172
|
+
)}
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const EmbedHTMLContainer = ({ embedHtml }: { embedHtml: string }) => {
|
|
178
|
+
const embedContainerRef = useRef<HTMLDivElement>(null);
|
|
179
|
+
const iframeWrapperRef = useRef<HTMLDivElement>(null);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
const container = embedContainerRef.current;
|
|
183
|
+
const iframe = iframeWrapperRef.current?.querySelector('iframe');
|
|
184
|
+
|
|
185
|
+
if (!container || !iframe) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const maxHeight = iframe.getAttribute('height');
|
|
190
|
+
const maxWidth = iframe.getAttribute('width');
|
|
191
|
+
if (maxHeight !== null) {
|
|
192
|
+
container.style.maxHeight = toPx(maxHeight);
|
|
193
|
+
} else {
|
|
194
|
+
iframe.style.height = '100%';
|
|
195
|
+
}
|
|
196
|
+
if (maxWidth !== null) {
|
|
197
|
+
container.style.maxWidth = toPx(maxWidth);
|
|
198
|
+
} else {
|
|
199
|
+
iframe.style.width = '100%';
|
|
200
|
+
}
|
|
201
|
+
}, []);
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div ref={embedContainerRef} className={styles.embed_container}>
|
|
205
|
+
<div
|
|
206
|
+
ref={iframeWrapperRef}
|
|
207
|
+
className={styles.iframe_wrapper}
|
|
208
|
+
dangerouslySetInnerHTML={{ __html: embedHtml }}
|
|
209
|
+
/>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const EmbedVideoIsland = ({
|
|
215
|
+
embedVideoParams,
|
|
216
|
+
oembedThumbnail,
|
|
217
|
+
playButtonColor,
|
|
218
|
+
}: EmbedVideoIslandProps) => {
|
|
219
|
+
if (
|
|
220
|
+
embedVideoParams.source_type === 'oembed' &&
|
|
221
|
+
embedVideoParams.oembed_url
|
|
222
|
+
) {
|
|
223
|
+
return (
|
|
224
|
+
<OEmbedContainer
|
|
225
|
+
embedVideoParams={embedVideoParams}
|
|
226
|
+
oEmbedThumbnail={oembedThumbnail}
|
|
227
|
+
oEmbedPlayButtonColor={playButtonColor}
|
|
228
|
+
/>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (embedVideoParams.source_type === 'html' && embedVideoParams.embed_html) {
|
|
233
|
+
return <EmbedHTMLContainer embedHtml={embedVideoParams.embed_html} />;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export default EmbedVideoIsland;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
.oembed_container {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
position: relative;
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.oembed_container_iframe {
|
|
9
|
+
height: 100%;
|
|
10
|
+
left: 0;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
position: absolute;
|
|
13
|
+
right: 0;
|
|
14
|
+
top: 0;
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.oembed_custom-thumbnail,
|
|
19
|
+
.oembed_custom-thumbnail:hover,
|
|
20
|
+
.oembed_custom-thumbnail:focus,
|
|
21
|
+
.oembed_custom-thumbnail:active {
|
|
22
|
+
align-items: center;
|
|
23
|
+
appearance: none;
|
|
24
|
+
background-color: transparent;
|
|
25
|
+
background-position: center center;
|
|
26
|
+
background-repeat: no-repeat;
|
|
27
|
+
background-size: cover;
|
|
28
|
+
border-radius: 0;
|
|
29
|
+
border: none;
|
|
30
|
+
display: flex;
|
|
31
|
+
height: 100%;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
left: 0;
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 0;
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
width: 100%;
|
|
39
|
+
z-index: 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.oembed_custom-thumbnail_icon {
|
|
43
|
+
align-items: center;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
width: 100%;
|
|
48
|
+
|
|
49
|
+
svg {
|
|
50
|
+
display: block;
|
|
51
|
+
height: auto;
|
|
52
|
+
width: 12%;
|
|
53
|
+
fill: var(--hscl-video-playButton-color, #ffffff);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* SVGs in IE11 require the max-width to be set to non in order to display scaling properly */
|
|
58
|
+
_:-ms-fullscreen,
|
|
59
|
+
:root .oembed_custom-thumbnail_icon svg {
|
|
60
|
+
max-width: none;
|
|
61
|
+
fill: var(--hscl-video-playButton-color, #ffffff);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.oembed-info {
|
|
65
|
+
height: 1px;
|
|
66
|
+
left: -10000px;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
position: absolute;
|
|
69
|
+
top: auto;
|
|
70
|
+
width: 1px;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.iframe_wrapper {
|
|
74
|
+
height: 0;
|
|
75
|
+
padding-bottom: 56.25%;
|
|
76
|
+
padding-top: 25px;
|
|
77
|
+
position: relative;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.embed_container {
|
|
81
|
+
display: inline-block;
|
|
82
|
+
height: 100%;
|
|
83
|
+
position: relative;
|
|
84
|
+
width: 100%;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.embed_container iframe {
|
|
88
|
+
left: 0;
|
|
89
|
+
max-height: 100%;
|
|
90
|
+
max-width: 100%;
|
|
91
|
+
position: absolute;
|
|
92
|
+
right: 0;
|
|
93
|
+
top: 0;
|
|
94
|
+
}
|