-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harmonize video blocks options (#2233)
Outsource video options fields to use in DamVideoBlock, YouTubeVideoBlock (when moved to cms-admin from blocks-admin) and VimeoVideoBlock (PR open).
- Loading branch information
Showing
2 changed files
with
56 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/admin/cms-admin/src/blocks/helpers/VideoOptionsFields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Field, FinalFormSwitch, OnChangeField } from "@comet/admin"; | ||
import { FormControlLabel } from "@mui/material"; | ||
import * as React from "react"; | ||
import { useForm } from "react-final-form"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
export const VideoOptionsFields = () => { | ||
const form = useForm(); | ||
return ( | ||
<> | ||
<Field name="autoplay" type="checkbox"> | ||
{(props) => ( | ||
<FormControlLabel | ||
label={<FormattedMessage id="comet.blocks.video.autoplay" defaultMessage="Autoplay" />} | ||
control={<FinalFormSwitch {...props} />} | ||
/> | ||
)} | ||
</Field> | ||
<Field name="loop" type="checkbox"> | ||
{(props) => ( | ||
<FormControlLabel | ||
label={<FormattedMessage id="comet.blocks.video.loop" defaultMessage="Loop" />} | ||
control={<FinalFormSwitch {...props} />} | ||
/> | ||
)} | ||
</Field> | ||
<Field name="showControls" type="checkbox"> | ||
{(props) => ( | ||
<FormControlLabel | ||
label={<FormattedMessage id="comet.blocks.video.showControls" defaultMessage="Show controls" />} | ||
control={<FinalFormSwitch {...props} />} | ||
/> | ||
)} | ||
</Field> | ||
{/* case: autoplay = false and showControls = false is not allowed */} | ||
<OnChangeField name="autoplay"> | ||
{(value, previousValue) => { | ||
if (!value && previousValue) { | ||
form.change("showControls", true); | ||
} | ||
}} | ||
</OnChangeField> | ||
<OnChangeField name="showControls"> | ||
{(value, previousValue) => { | ||
if (!value && previousValue) { | ||
form.change("autoplay", true); | ||
} | ||
}} | ||
</OnChangeField> | ||
</> | ||
); | ||
}; |