-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to work with new Button component
- Loading branch information
Showing
1 changed file
with
8 additions
and
5 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
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; | ||
} | ||
} |