From 4bdc51237a26a2e3d7f206550be96f37e06e9d7f Mon Sep 17 00:00:00 2001 From: Chad Little Date: Thu, 26 Mar 2015 11:09:20 -0700 Subject: [PATCH] Add ability to have tooltips on buttons Summary: Enables a basic tooltip when using icon buttons and a convenience method for setting an icon. Test Plan: Built a UIExample. Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12172 --- .../examples/PHUIButtonBarExample.php | 1 + src/view/phui/PHUIButtonView.php | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/applications/uiexample/examples/PHUIButtonBarExample.php b/src/applications/uiexample/examples/PHUIButtonBarExample.php index 0e983088c1..293cd2336a 100644 --- a/src/applications/uiexample/examples/PHUIButtonBarExample.php +++ b/src/applications/uiexample/examples/PHUIButtonBarExample.php @@ -55,6 +55,7 @@ final class PHUIButtonBarExample extends PhabricatorUIExample { ->setTag('a') ->setColor(PHUIButtonView::SIMPLE) ->setTitle($text) + ->setTooltip($text) ->setIcon($image); $button_bar3->addButton($button); diff --git a/src/view/phui/PHUIButtonView.php b/src/view/phui/PHUIButtonView.php index 3e0854a670..7be6fe080b 100644 --- a/src/view/phui/PHUIButtonView.php +++ b/src/view/phui/PHUIButtonView.php @@ -22,10 +22,12 @@ final class PHUIButtonView extends AphrontTagView { private $tag = 'button'; private $dropdown; private $icon; + private $iconFont; private $href = null; private $title = null; private $disabled; private $name; + private $tooltip; public function setName($name) { $this->name = $name; @@ -81,11 +83,23 @@ final class PHUIButtonView extends AphrontTagView { return $this; } + public function setTooltip($text) { + $this->tooltip = $text; + return $this; + } + public function setIcon(PHUIIconView $icon) { $this->icon = $icon; return $this; } + public function setIconFont($icon) { + $icon = id(new PHUIIconView()) + ->setIconFont($icon); + $this->setIcon($icon); + return $this; + } + protected function getTagName() { return $this->tag; } @@ -117,11 +131,24 @@ final class PHUIButtonView extends AphrontTagView { $classes[] = 'disabled'; } + $sigil = null; + $meta = null; + if ($this->tooltip) { + Javelin::initBehavior('phabricator-tooltips'); + require_celerity_resource('aphront-tooltip-css'); + $sigil = 'has-tooltip'; + $meta = array( + 'tip' => $this->tooltip, + ); + } + return array( 'class' => $classes, 'href' => $this->href, 'name' => $this->name, 'title' => $this->title, + 'sigil' => $sigil, + 'meta' => $meta, ); }