-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from 10up/feature/custom-appenders
Add CustomBlockAppender.
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.vscode |
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,70 @@ | ||
/* eslint-disable react/jsx-props-no-spreading */ | ||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { Fragment } from '@wordpress/element'; | ||
import { Inserter } from '@wordpress/block-editor'; | ||
import { Button } from '@wordpress/components'; | ||
|
||
/** | ||
* CustomBlockAppender. | ||
* | ||
* Provide a Button component to trigger the inserter. | ||
* Any undocumented props are spread onto the Button component. | ||
* | ||
* @param {Object} props All props sent to this component. | ||
* @param {string} props.rootClientId Client ID of the block where this is being used. | ||
* @param {string} [props.buttonText] Text to display in the Button. | ||
* @param {string} [props.icon] The icon to use. | ||
* @return {Function} The component. | ||
*/ | ||
const CustomBlockAppender = ({ | ||
rootClientId, | ||
buttonText, | ||
icon, | ||
className = 'custom-block-appender', | ||
...buttonProps | ||
}) => { | ||
return ( | ||
<Inserter | ||
isAppender | ||
rootClientId={rootClientId} | ||
renderToggle={({ onToggle, disabled }) => ( | ||
<Fragment> | ||
<Button | ||
className={`tenup-${className}`} | ||
onClick={onToggle} | ||
disabled={disabled} | ||
icon={icon} | ||
{...buttonProps} | ||
> | ||
{buttonText} | ||
</Button> | ||
</Fragment> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
CustomBlockAppender.propTypes = { | ||
rootClientId: PropTypes.string.isRequired, | ||
buttonText: PropTypes.string, | ||
label: PropTypes.string, | ||
icon: PropTypes.string, | ||
className: PropTypes.string, | ||
}; | ||
|
||
CustomBlockAppender.defaultProps = { | ||
buttonText: '', | ||
label: '', | ||
icon: 'plus', | ||
className: 'custom-block-appender', | ||
}; | ||
|
||
export default CustomBlockAppender; |
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