diff --git a/assets/blocks/editor-components/styles.scss b/assets/blocks/editor-components/styles.scss new file mode 100644 index 0000000000..f405c61f69 --- /dev/null +++ b/assets/blocks/editor-components/styles.scss @@ -0,0 +1 @@ +@import './toolbar-dropdown/styles'; diff --git a/assets/blocks/editor-components/toolbar-dropdown/index.js b/assets/blocks/editor-components/toolbar-dropdown/index.js new file mode 100644 index 0000000000..3c3d80a55e --- /dev/null +++ b/assets/blocks/editor-components/toolbar-dropdown/index.js @@ -0,0 +1,80 @@ +import { + Button, + Dropdown, + MenuGroup, + MenuItem, + NavigableMenu, +} from '@wordpress/components'; +import classnames from 'classnames'; + +/** + * @typedef {Object} DropdownOption + * + * @property {string} label Option label. + * @property {string} value Option value. + */ +/** + * Dropdown for the editor toolbar. + * + * @param {Object} props + * @param {DropdownOption[]} props.options Dropdown options. + * @param {string} [props.optionsLabel] Options label. + * @param {Object} props.icon Icon for the toolbar. + * @param {string} props.value Current dropdown value. + * @param {Function} props.onChange Dropdown change callback, which receive + * the new value as argument. + */ +const ToolbarDropdown = ( { + options, + optionsLabel, + icon, + value, + onChange, +} ) => { + const selectedOption = options.find( ( option ) => value === option.value ); + + return ( + ( + + ) } + renderContent={ ( { onClose } ) => ( + + + { options.map( ( option ) => { + const isSelected = + option.value === selectedOption.value; + + return ( + { + onChange( option.value ); + onClose(); + } } + > + { option.label } + + ); + } ) } + + + ) } + /> + ); +}; + +export default ToolbarDropdown; diff --git a/assets/blocks/editor-components/toolbar-dropdown/styles.scss b/assets/blocks/editor-components/toolbar-dropdown/styles.scss new file mode 100644 index 0000000000..10aa9ee25b --- /dev/null +++ b/assets/blocks/editor-components/toolbar-dropdown/styles.scss @@ -0,0 +1,11 @@ +.sensei-toolbar-dropdown-item-checked { + position: relative; + padding-right: 30px; + &::after { + font-family: dashicons; + content: "\f147"; + font-size: 20px; + position: absolute; + right: 0; + } +} diff --git a/webpack.config.js b/webpack.config.js index 8b1ab27f51..f0a562f513 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -31,6 +31,7 @@ const files = [ 'data-port/import.js', 'data-port/export.js', 'data-port/style.scss', + 'blocks/editor-components/styles.scss', 'blocks/course-outline/frontend.js', 'blocks/sensei-single-course-blocks.js', 'blocks/single-course.scss',