-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Gist Block and Caption component (#18)
- Loading branch information
Showing
12 changed files
with
291 additions
and
11 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
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
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
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
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,27 @@ | ||
import React from 'react'; | ||
import { BlockDataForm } from '@plone/volto/components'; | ||
import { gistSchema } from './schema'; | ||
import { useIntl } from 'react-intl'; | ||
|
||
const GistBlockData = (props) => { | ||
const { data, block, onChangeBlock } = props; | ||
const intl = useIntl(); | ||
const schema = gistSchema({ ...props, intl }); | ||
|
||
return ( | ||
<BlockDataForm | ||
schema={schema} | ||
title={schema.title} | ||
onChangeField={(id, value) => { | ||
onChangeBlock(block, { | ||
...data, | ||
[id]: value, | ||
}); | ||
}} | ||
formData={data} | ||
block={block} | ||
/> | ||
); | ||
}; | ||
|
||
export default GistBlockData; |
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,15 @@ | ||
import React from 'react'; | ||
import Gist from 'react-gist'; | ||
import Caption from '../../Caption/Caption'; | ||
|
||
const GistView = (props) => { | ||
const { file, gistId, caption_title, caption_description } = props; | ||
return ( | ||
<> | ||
{gistId && <Gist id={gistId} file={file} />} | ||
{caption_title && <Caption title={caption_title} description={caption_description} />} | ||
</> | ||
); | ||
}; | ||
|
||
export default GistView; |
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,26 @@ | ||
import React from 'react'; | ||
import { withBlockExtensions } from '@plone/volto/helpers'; | ||
import { SidebarPortal } from '@plone/volto/components'; | ||
import GistBlockData from './Data'; | ||
import View from './DefaultView'; | ||
|
||
const GistBlockEdit = (props) => { | ||
const { data, selected, block } = props; | ||
const { gistId, file } = data; | ||
const { caption_title, caption_description } = data; | ||
return ( | ||
<div className="block gist edit" id={`gistBlock-${block}`}> | ||
{data && ( | ||
<> | ||
<div className={'gist editLayer'}></div> | ||
<View gistId={gistId} file={file} caption_title={caption_title} caption_description={caption_description} /> | ||
</> | ||
)} | ||
<SidebarPortal selected={selected}> | ||
<GistBlockData {...props} /> | ||
</SidebarPortal> | ||
</div> | ||
); | ||
}; | ||
|
||
export default withBlockExtensions(GistBlockEdit); |
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,15 @@ | ||
import React from 'react'; | ||
import { withBlockExtensions } from '@plone/volto/helpers'; | ||
import GistView from './DefaultView'; | ||
|
||
const GistBlockView = (props) => { | ||
const { data, block } = props; | ||
const { gistId, file, caption_title, caption_description } = data; | ||
return ( | ||
<div className="block gist view" id={`gistBlock-${block}`}> | ||
{data && <GistView caption_title={caption_title} caption_description={caption_description} gistId={gistId} file={file} block={block} />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default withBlockExtensions(GistBlockView); |
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,59 @@ | ||
import { defineMessages } from 'react-intl'; | ||
|
||
const messages = defineMessages({ | ||
gistBlock: { | ||
id: 'Gist Block', | ||
defaultMessage: 'Gist Block', | ||
}, | ||
gistId: { | ||
id: 'Gist Id', | ||
defaultMessage: 'Gist Id', | ||
}, | ||
file: { | ||
id: 'File', | ||
defaultMessage: 'File', | ||
}, | ||
caption_title: { | ||
id: 'Title', | ||
defaultMessage: 'Title', | ||
}, | ||
caption_description: { | ||
id: 'Description', | ||
defaultMessage: 'Description', | ||
}, | ||
}); | ||
|
||
export const gistSchema = (props) => { | ||
return { | ||
title: props.intl.formatMessage(messages.gistBlock), | ||
fieldsets: [ | ||
{ | ||
id: 'default', | ||
title: 'Default', | ||
fields: ['gistId', 'file'], | ||
}, | ||
{ | ||
id: 'caption', | ||
title: 'Caption', | ||
fields: ['caption_title', 'caption_description'], | ||
}, | ||
], | ||
|
||
properties: { | ||
gistId: { | ||
title: props.intl.formatMessage(messages.gistId), | ||
}, | ||
file: { | ||
title: props.intl.formatMessage(messages.file), | ||
}, | ||
caption_title: { | ||
title: props.intl.formatMessage(messages.caption_title), | ||
}, | ||
caption_description: { | ||
title: props.intl.formatMessage(messages.caption_description), | ||
widget: 'textarea', | ||
}, | ||
}, | ||
required: ['gistId'], | ||
}; | ||
}; |
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,39 @@ | ||
/** | ||
* @module components/Caption | ||
*/ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Image/video caption component class. | ||
* @function Caption | ||
* @params {string} title Caption title. | ||
* @params {string} description Caption description. | ||
* @returns {string} Markup of the component. | ||
*/ | ||
const Caption = ({ title, description }) => { | ||
return ( | ||
<div className={'codeBlockCaption'}> | ||
{title && <p className="title">{title}</p>} | ||
{description && ( | ||
<p className="description"> | ||
{description.split('\n').map((line, index) => ( | ||
<p key={index}>{line || '\u00A0'}</p> | ||
))} | ||
</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
/** | ||
* Property types. | ||
* @property {Object} propTypes Property types. | ||
* @static | ||
*/ | ||
Caption.propTypes = { | ||
title: PropTypes.string, | ||
description: PropTypes.string, | ||
}; | ||
|
||
export default Caption; |
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
Oops, something went wrong.