Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327<?php
final class PHUIButtonView extends AphrontTagView {
const GREEN = 'green'; const GREY = 'grey'; const BLUE = 'blue'; const RED = 'red'; const DISABLED = 'disabled';
const SMALL = 'small'; const BIG = 'big';
const BUTTONTYPE_DEFAULT = 'buttontype.default'; const BUTTONTYPE_SIMPLE = 'buttontype.simple';
private $size; private $text; private $subtext; private $color; private $tag = 'button'; private $dropdown; private $icon; private $iconFirst; private $href = null; private $title = null; private $disabled; private $selected; private $name; private $tooltip; private $noCSS; private $hasCaret; private $buttonType = self::BUTTONTYPE_DEFAULT; private $auralLabel;
public function setName($name) { $this->name = $name; return $this; }
public function getName() { return $this->name; }
public function setText($text) { $this->text = $text; return $this; }
public function setHref($href) { $this->href = $href; return $this; }
public function setTitle($title) { $this->title = $title; return $this; }
public function setSubtext($subtext) { $this->subtext = $subtext; return $this; }
public function setColor($color) { $this->color = $color; return $this; }
public function getColor() { return $this->color; }
public function setDisabled($disabled) { $this->disabled = $disabled; return $this; }
public function setSelected($selected) { $this->selected = $selected; return $this; }
/** * Set the HTML tag for the button, e.g. 'button', 'input', 'a'. * @param string $tag */ public function setTag($tag) { $this->tag = $tag; return $this; }
public function setSize($size) { $this->size = $size; return $this; }
public function setDropdown($dd) { $this->dropdown = $dd; return $this; }
public function setTooltip($text) { $this->tooltip = $text; return $this; }
public function setNoCSS($no_css) { $this->noCSS = $no_css; return $this; }
public function setHasCaret($has_caret) { $this->hasCaret = $has_caret; return $this; }
public function getHasCaret() { return $this->hasCaret; }
public function setButtonType($button_type) { $this->buttonType = $button_type; return $this; }
public function getButtonType() { return $this->buttonType; }
public function setAuralLabel($aural_label) { $this->auralLabel = $aural_label; return $this; }
public function getAuralLabel() { return $this->auralLabel; }
/** * @param PHUIIconView|string $icon * @param ?bool $first */ public function setIcon($icon, $first = true) { if (!($icon instanceof PHUIIconView)) { $icon = id(new PHUIIconView()) ->setIcon($icon); } $this->icon = $icon; $this->iconFirst = $first; return $this; }
/** * Get the HTML tag set for the button, e.g. 'button', 'input', 'a'. * @return string */ protected function getTagName() { return $this->tag; }
public function setDropdownMenu(PhabricatorActionListView $actions) { Javelin::initBehavior('phui-dropdown-menu');
$this->addSigil('phui-dropdown-menu'); $this->setDropdown(true); $this->setMetadata($actions->getDropdownMenuMetadata());
return $this; }
public function setDropdownMenuID($id) { Javelin::initBehavior('phui-dropdown-menu');
$this->addSigil('phui-dropdown-menu'); $this->setMetadata( array( 'menuID' => $id, ));
return $this; }
protected function getTagAttributes() {
require_celerity_resource('phui-button-css'); require_celerity_resource('phui-button-simple-css');
$classes = array(); $classes[] = 'button';
if ($this->color) { $classes[] = 'button-'.$this->color; }
if ($this->size) { $classes[] = $this->size; }
if ($this->dropdown) { $classes[] = 'dropdown'; }
if ($this->icon) { $classes[] = 'has-icon'; }
if ($this->text !== null) { $classes[] = 'has-text'; }
if ($this->iconFirst == false) { $classes[] = 'icon-last'; }
if ($this->disabled) { $classes[] = 'disabled'; }
if ($this->selected) { $classes[] = 'selected'; }
switch ($this->getButtonType()) { case self::BUTTONTYPE_DEFAULT: $classes[] = 'phui-button-default'; break; case self::BUTTONTYPE_SIMPLE: $classes[] = 'phui-button-simple'; break; }
$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, ); }
if ($this->noCSS) { $classes = array(); }
// See PHI823. If we aren't rendering a "<button>" or "<input>" tag, // give the tag we are rendering a "button" role as a hint to screen // readers. $role = null; if ($this->tag !== 'button' && $this->tag !== 'input') { $role = 'button'; }
$attrs = array( 'class' => $classes, 'href' => $this->href, 'name' => $this->name, 'title' => $this->title, 'sigil' => $sigil, 'meta' => $meta, 'role' => $role, );
if ($this->tag == 'input') { $attrs['type'] = 'submit'; $attrs['value'] = $this->text; }
return $attrs; }
protected function getTagContent() { if ($this->tag === 'input') { return null; }
$icon = $this->icon; $text = null; $subtext = null;
if ($this->subtext) { $subtext = phutil_tag( 'div', array( 'class' => 'phui-button-subtext', ), $this->subtext); }
if ($this->text !== null) { $text = phutil_tag( 'div', array( 'class' => 'phui-button-text', ), array( $this->text, $subtext, )); }
$caret = null; if ($this->dropdown || $this->getHasCaret()) { $caret = phutil_tag('span', array('class' => 'caret'), ''); }
$aural = null; if ($this->auralLabel !== null) { $aural = phutil_tag( 'span', array( 'class' => 'aural-only', ), $this->auralLabel); }
if ($this->iconFirst == true) { return array($aural, $icon, $text, $caret); } else { return array($aural, $text, $icon, $caret); } }}