Skip to content

Commit

Permalink
Update to work with new Button component
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Jul 21, 2021
1 parent 9ba836c commit 61c2307
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions js/src/common/components/TextEditorButton.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import extractText from '../utils/extractText';
import Button from './Button';
import Tooltip from './Tooltip';

/**
* The `TextEditorButton` component displays a button suitable for the text
* editor toolbar.
*
* Automatically creates tooltips using the Tooltip component and provided text.
*
* ## Attrs
* - `title` - Tooltip for the button
*/
export default class TextEditorButton extends Button {
view(vnode) {
const originalView = super.view(vnode);

// Steal tooltip label from the Button superclass
const tooltipText = originalView.attrs.title;
delete originalView.attrs.title;

return <Tooltip text={tooltipText}>{originalView}</Tooltip>;
return <Tooltip text={this.attrs.tooltipText || extractText(vnode.children)}>{originalView}</Tooltip>;
}

static initAttrs(attrs) {
super.initAttrs(attrs);

attrs.className = attrs.className || 'Button Button--icon Button--link';
attrs.tooltipText = attrs.title;
}
}

0 comments on commit 61c2307

Please sign in to comment.