diff --git a/.storybook/preview.js b/.storybook/preview.js index 624c2c6f..0384a620 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -4,7 +4,12 @@ import { importAll } from '../src/dev/importAll'; importAll(require.context('../src', true, /\.scss$/)); export const parameters = { - actions: { argTypesRegex: '^on[A-Z].*' }, + actions: { + argTypesRegex: '^on[A-Z].*', + controls: { + expanded: true, + }, + }, }; export const decorators = [ diff --git a/babel.config.mjs b/babel.config.mjs index 03b22afb..c00c7d4c 100644 --- a/babel.config.mjs +++ b/babel.config.mjs @@ -1,6 +1,10 @@ -export default () => { +export default (api) => { const isDevelopment = process.env.NODE_ENV === 'development'; + if (isDevelopment) { + api.cache(true); + } + return { targets: { esmodules: false, diff --git a/package.json b/package.json index 8f96fd15..4600a23a 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,7 @@ "dependencies": { "@prezly/linear-partition": "^1.0.2", "@prezly/sdk": "^6.21.0", - "@prezly/story-content-format": "^0.63.0", + "@prezly/story-content-format": "^0.64.0", "@prezly/uploadcare": "^2.4.3", "@react-hookz/web": "^12.0.0", "classnames": "^2.2.6", diff --git a/src/elements/Embed/Embed.scss b/src/elements/Embed/Embed.scss index 9acc536e..8c5965e7 100644 --- a/src/elements/Embed/Embed.scss +++ b/src/elements/Embed/Embed.scss @@ -6,6 +6,19 @@ flex-direction: column; margin: $block-spacing-vertical 0; + &--expanded { + @include media-layout-expanded; + } + + &--contained { + margin-left: auto; + margin-right: auto; + } + + &--full-width { + @include media-layout-full-width; + } + &:focus-within { @include focus-state; } diff --git a/src/elements/Embed/Embed.slate.stories.tsx b/src/elements/Embed/Embed.slate.stories.tsx index 84148c48..ef9d0c47 100644 --- a/src/elements/Embed/Embed.slate.stories.tsx +++ b/src/elements/Embed/Embed.slate.stories.tsx @@ -1,4 +1,5 @@ -import type { Meta, Story } from '@storybook/react'; +import { EmbedNode } from '@prezly/story-content-format'; +import type { Meta, Story, StoryFn } from '@storybook/react'; import { StoryNameDecorator } from '../../dev/StoryNameDecorator'; import { Renderer } from '../../Renderer'; @@ -6,51 +7,42 @@ import { Renderer } from '../../Renderer'; export default { title: 'Elements/Embed', decorators: [StoryNameDecorator], + argTypes: { + layout: { + control: { type: 'radio' }, + options: [ + EmbedNode.Layout.CONTAINED, + EmbedNode.Layout.EXPANDED, + EmbedNode.Layout.FULL_WIDTH, + ], + defaultValue: EmbedNode.Layout.CONTAINED as `${EmbedNode.Layout}`, + description: 'The specified layout', + }, + }, } as Meta; -export const VideoEmbedIframe: Story = () => ( +export const VideoEmbedIframe: StoryFn<{ layout: `${EmbedNode.Layout}` }> = ({ layout }) => (
', - options: { - _end: { - label: 'End on', - placeholder: 'ex.: 11, 1m10s', - value: '', - }, - _start: { - label: 'Start from', - placeholder: 'ex.: 11, 1m10s', - value: '', - }, - click_to_play: { - label: 'Hold load & play until clicked', - value: false, - }, - }, provider_name: 'YouTube', screenshot_url: 'https://avatars-cdn.prezly.com/embed/aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g.dj1BNXVxWTJ4MjVHRQ__/3d02b090ce4d8695299760f56c4ae5a11bb64120ca178d8ab848a4327676a18b?v=1583930760', @@ -71,6 +63,9 @@ VideoEmbedIframe.story = { parameters: { loki: { skip: true }, }, + args: { + layout: EmbedNode.Layout.CONTAINED, + }, }; export const TwitterPostIframe: Story = () => ( @@ -86,32 +81,15 @@ export const TwitterPostIframe: Story = () => ( }, { type: 'embed', - children: [ - { - text: '', - }, - ], uuid: '90bd57f9-523e-44df-ba65-a11674c45404', url: 'https://twitter.com/Prezly/status/1255868048222945281', + layout: 'contained', oembed: { - author: 'Prezly', author_url: 'https://twitter.com/Prezly', cache_age: 86400, description: 'The results of the Global PR Survey 2020 are now live! Read them in full at https://t.co/Zz61D3S7TqHuge thank you to everyone that took part ❤️— Prezly (@Prezly) April 30, 2020\n\n', html: '
', - options: { - _hide_media: { - label: 'Hide photos, videos, and cards', - value: false, - }, - _theme: { - value: '', - values: { - dark: 'Use dark theme', - }, - }, - }, provider_name: 'Twitter', screenshot_url: 'https://avatars-cdn.prezly.com/embed/aHR0cHM6Ly90d2l0dGVyLmNvbS9QcmV6bHkvc3RhdHVzLzEyNTU4NjgwNDgyMjI5NDUyODE_/7d7cf7768b2cf588c3e160f8a859da185315329a4d23e16a1e64ac29a4314e87?v=1583930760', @@ -144,13 +122,9 @@ export const RichWebsiteCardIframe: Story = () => ( }, { type: 'embed', - children: [ - { - text: '', - }, - ], uuid: '5024d558-75ef-4d56-a114-87674b522c1e', url: 'https://prezly.com', + layout: 'contained', oembed: { cache_age: 86400, description: @@ -191,13 +165,9 @@ export const Minimal: Story = () => ( }, { type: 'embed', - children: [ - { - text: '', - }, - ], uuid: 'da744513-8fe7-4e22-9e85-6f5e122b93a1', url: 'https://www.prezly.com/', + layout: 'contained', oembed: { type: 'link', cache_age: 86400, diff --git a/src/elements/Embed/Embed.tsx b/src/elements/Embed/Embed.tsx index 30aa9c5c..69acd1e5 100644 --- a/src/elements/Embed/Embed.tsx +++ b/src/elements/Embed/Embed.tsx @@ -1,4 +1,4 @@ -import type { EmbedNode } from '@prezly/story-content-format'; +import { EmbedNode } from '@prezly/story-content-format'; import classNames from 'classnames'; import type { HTMLAttributes } from 'react'; @@ -13,11 +13,19 @@ interface Props extends Omit, 'children'> { } export function Embed({ className, node, showAsScreenshot, ...props }: Props) { - const { oembed, url } = node; + const { oembed, url, layout } = node; const commonProps = { id: `embed-${node.uuid}`, - className: classNames('prezly-slate-embed', className), + className: classNames( + 'prezly-slate-embed', + { + 'prezly-slate-embed--contained': layout === EmbedNode.Layout.CONTAINED, + 'prezly-slate-embed--expanded': layout === EmbedNode.Layout.EXPANDED, + 'prezly-slate-embed--full-width': layout === EmbedNode.Layout.FULL_WIDTH, + }, + className, + ), title: oembed.title || url, ...props, };