Skip to content

Commit

Permalink
Add Inline comment experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
poojabhimani12 committed Apr 10, 2024
1 parent 5d73162 commit 200bd36
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function gutenberg_enable_experiments() {
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-inline-comment', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableInlineComment = true', 'before' );
}
}

add_action( 'admin_init', 'gutenberg_enable_experiments' );
Expand Down
12 changes: 12 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-inline-comment',
__( 'Enable Inline Comment', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable Inline Comment', 'gutenberg' ),
'id' => 'gutenberg-inline-comment',
)
);

register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Shuffle from './shuffle';
import BlockBindingsIndicator from '../block-bindings-toolbar-indicator';
import { useHasBlockToolbar } from './use-has-block-toolbar';
import { canBindBlock } from '../../hooks/use-bindings-attributes';
import { InlineCommentToolbar } from '../inline-comment';
/**
* Renders the block toolbar.
*
Expand Down Expand Up @@ -188,6 +189,9 @@ export function PrivateBlockToolbar( {
clientIds={ blockClientIds }
hideDragHandle={ hideDragHandle }
/>
<InlineCommentToolbar
clientIds={ blockClientIds }
/>
</>
) }
</ToolbarGroup>
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export { default as __experimentalBlockPatternsList } from './block-patterns-lis
export { default as __experimentalPublishDateTimePicker } from './publish-date-time-picker';
export { default as __experimentalInspectorPopoverHeader } from './inspector-popover-header';
export { useBlockEditingMode } from './block-editing-mode';
export { InlineCommentToolbar as __experimentalInlineComment } from './inline-comment';

/*
* State Related Components
Expand Down
44 changes: 44 additions & 0 deletions packages/block-editor/src/components/inline-comment/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { comment } from '@wordpress/icons';
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import { displayShortcut } from '@wordpress/keycodes';
import { __ } from '@wordpress/i18n';
const isInlineCommentExperimentEnabled =
window?.__experimentalEnableInlineComment;

class InlineCommentToolbar extends Component {
constructor( props ) {
super( props );
this.onToggle = this.onToggle.bind( this );
}
onToggle() {
// eslint-disable-next-line no-console
console.log( 'comment toggled' );
}

render() {
return (
<>
{ isInlineCommentExperimentEnabled && (
<>
<ToolbarGroup className="comment-group">
<ToolbarButton
icon={ comment }
label={ __( 'Comment' ) }
onClick={ this.onToggle }
shortcut={ displayShortcut.primaryAlt( 'm' ) }
className={
'comment-group-button toolbar-button-with-text'
}
/>
</ToolbarGroup>
</>
) }
</>
);
}
}
export default InlineCommentToolbar;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as InlineCommentToolbar } from './comment';

0 comments on commit 200bd36

Please sign in to comment.