3 final class PHUIButtonView
extends AphrontTagView
{
9 const DISABLED
= 'disabled';
11 const SMALL
= 'small';
14 const BUTTONTYPE_DEFAULT
= 'buttontype.default';
15 const BUTTONTYPE_SIMPLE
= 'buttontype.simple';
21 private $tag = 'button';
26 private $title = null;
33 private $buttonType = self
::BUTTONTYPE_DEFAULT
;
36 public function setName($name) {
41 public function getName() {
45 public function setText($text) {
50 public function setHref($href) {
55 public function setTitle($title) {
56 $this->title
= $title;
60 public function setSubtext($subtext) {
61 $this->subtext
= $subtext;
65 public function setColor($color) {
66 $this->color
= $color;
70 public function getColor() {
74 public function setDisabled($disabled) {
75 $this->disabled
= $disabled;
79 public function setSelected($selected) {
80 $this->selected
= $selected;
84 public function setTag($tag) {
89 public function setSize($size) {
94 public function setDropdown($dd) {
95 $this->dropdown
= $dd;
99 public function setTooltip($text) {
100 $this->tooltip
= $text;
104 public function setNoCSS($no_css) {
105 $this->noCSS
= $no_css;
109 public function setHasCaret($has_caret) {
110 $this->hasCaret
= $has_caret;
114 public function getHasCaret() {
115 return $this->hasCaret
;
118 public function setButtonType($button_type) {
119 $this->buttonType
= $button_type;
123 public function getButtonType() {
124 return $this->buttonType
;
127 public function setAuralLabel($aural_label) {
128 $this->auralLabel
= $aural_label;
132 public function getAuralLabel() {
133 return $this->auralLabel
;
136 public function setIcon($icon, $first = true) {
137 if (!($icon instanceof PHUIIconView
)) {
138 $icon = id(new PHUIIconView())
142 $this->iconFirst
= $first;
146 protected function getTagName() {
150 public function setDropdownMenu(PhabricatorActionListView
$actions) {
151 Javelin
::initBehavior('phui-dropdown-menu');
153 $this->addSigil('phui-dropdown-menu');
154 $this->setDropdown(true);
155 $this->setMetadata($actions->getDropdownMenuMetadata());
160 public function setDropdownMenuID($id) {
161 Javelin
::initBehavior('phui-dropdown-menu');
163 $this->addSigil('phui-dropdown-menu');
172 protected function getTagAttributes() {
174 require_celerity_resource('phui-button-css');
175 require_celerity_resource('phui-button-simple-css');
178 $classes[] = 'button';
181 $classes[] = 'button-'.$this->color
;
185 $classes[] = $this->size
;
188 if ($this->dropdown
) {
189 $classes[] = 'dropdown';
193 $classes[] = 'has-icon';
196 if ($this->text
!== null) {
197 $classes[] = 'has-text';
200 if ($this->iconFirst
== false) {
201 $classes[] = 'icon-last';
204 if ($this->disabled
) {
205 $classes[] = 'disabled';
208 if ($this->selected
) {
209 $classes[] = 'selected';
212 switch ($this->getButtonType()) {
213 case self
::BUTTONTYPE_DEFAULT
:
214 $classes[] = 'phui-button-default';
216 case self
::BUTTONTYPE_SIMPLE
:
217 $classes[] = 'phui-button-simple';
223 if ($this->tooltip
) {
224 Javelin
::initBehavior('phabricator-tooltips');
225 require_celerity_resource('aphront-tooltip-css');
226 $sigil = 'has-tooltip';
228 'tip' => $this->tooltip
,
236 // See PHI823. If we aren't rendering a "<button>" or "<input>" tag,
237 // give the tag we are rendering a "button" role as a hint to screen
240 if ($this->tag
!== 'button' && $this->tag
!== 'input') {
246 'href' => $this->href
,
247 'name' => $this->name
,
248 'title' => $this->title
,
254 if ($this->tag
== 'input') {
255 $attrs['type'] = 'submit';
256 $attrs['value'] = $this->text
;
262 protected function getTagContent() {
263 if ($this->tag
=== 'input') {
271 if ($this->subtext
) {
272 $subtext = phutil_tag(
275 'class' => 'phui-button-subtext',
280 if ($this->text
!== null) {
284 'class' => 'phui-button-text',
293 if ($this->dropdown ||
$this->getHasCaret()) {
294 $caret = phutil_tag('span', array('class' => 'caret'), '');
298 if ($this->auralLabel
!== null) {
302 'class' => 'aural-only',
308 if ($this->iconFirst
== true) {
309 return array($aural, $icon, $text, $caret);
311 return array($aural, $text, $icon, $caret);