Path: blob/master/src/view/phui/PHUIButtonView.php
12249 views
<?php12final class PHUIButtonView extends AphrontTagView {34const GREEN = 'green';5const GREY = 'grey';6const BLUE = 'blue';7const RED = 'red';8const DISABLED = 'disabled';910const SMALL = 'small';11const BIG = 'big';1213const BUTTONTYPE_DEFAULT = 'buttontype.default';14const BUTTONTYPE_SIMPLE = 'buttontype.simple';1516private $size;17private $text;18private $subtext;19private $color;20private $tag = 'button';21private $dropdown;22private $icon;23private $iconFirst;24private $href = null;25private $title = null;26private $disabled;27private $selected;28private $name;29private $tooltip;30private $noCSS;31private $hasCaret;32private $buttonType = self::BUTTONTYPE_DEFAULT;33private $auralLabel;3435public function setName($name) {36$this->name = $name;37return $this;38}3940public function getName() {41return $this->name;42}4344public function setText($text) {45$this->text = $text;46return $this;47}4849public function setHref($href) {50$this->href = $href;51return $this;52}5354public function setTitle($title) {55$this->title = $title;56return $this;57}5859public function setSubtext($subtext) {60$this->subtext = $subtext;61return $this;62}6364public function setColor($color) {65$this->color = $color;66return $this;67}6869public function getColor() {70return $this->color;71}7273public function setDisabled($disabled) {74$this->disabled = $disabled;75return $this;76}7778public function setSelected($selected) {79$this->selected = $selected;80return $this;81}8283public function setTag($tag) {84$this->tag = $tag;85return $this;86}8788public function setSize($size) {89$this->size = $size;90return $this;91}9293public function setDropdown($dd) {94$this->dropdown = $dd;95return $this;96}9798public function setTooltip($text) {99$this->tooltip = $text;100return $this;101}102103public function setNoCSS($no_css) {104$this->noCSS = $no_css;105return $this;106}107108public function setHasCaret($has_caret) {109$this->hasCaret = $has_caret;110return $this;111}112113public function getHasCaret() {114return $this->hasCaret;115}116117public function setButtonType($button_type) {118$this->buttonType = $button_type;119return $this;120}121122public function getButtonType() {123return $this->buttonType;124}125126public function setAuralLabel($aural_label) {127$this->auralLabel = $aural_label;128return $this;129}130131public function getAuralLabel() {132return $this->auralLabel;133}134135public function setIcon($icon, $first = true) {136if (!($icon instanceof PHUIIconView)) {137$icon = id(new PHUIIconView())138->setIcon($icon);139}140$this->icon = $icon;141$this->iconFirst = $first;142return $this;143}144145protected function getTagName() {146return $this->tag;147}148149public function setDropdownMenu(PhabricatorActionListView $actions) {150Javelin::initBehavior('phui-dropdown-menu');151152$this->addSigil('phui-dropdown-menu');153$this->setDropdown(true);154$this->setMetadata($actions->getDropdownMenuMetadata());155156return $this;157}158159public function setDropdownMenuID($id) {160Javelin::initBehavior('phui-dropdown-menu');161162$this->addSigil('phui-dropdown-menu');163$this->setMetadata(164array(165'menuID' => $id,166));167168return $this;169}170171protected function getTagAttributes() {172173require_celerity_resource('phui-button-css');174require_celerity_resource('phui-button-simple-css');175176$classes = array();177$classes[] = 'button';178179if ($this->color) {180$classes[] = 'button-'.$this->color;181}182183if ($this->size) {184$classes[] = $this->size;185}186187if ($this->dropdown) {188$classes[] = 'dropdown';189}190191if ($this->icon) {192$classes[] = 'has-icon';193}194195if ($this->text !== null) {196$classes[] = 'has-text';197}198199if ($this->iconFirst == false) {200$classes[] = 'icon-last';201}202203if ($this->disabled) {204$classes[] = 'disabled';205}206207if ($this->selected) {208$classes[] = 'selected';209}210211switch ($this->getButtonType()) {212case self::BUTTONTYPE_DEFAULT:213$classes[] = 'phui-button-default';214break;215case self::BUTTONTYPE_SIMPLE:216$classes[] = 'phui-button-simple';217break;218}219220$sigil = null;221$meta = null;222if ($this->tooltip) {223Javelin::initBehavior('phabricator-tooltips');224require_celerity_resource('aphront-tooltip-css');225$sigil = 'has-tooltip';226$meta = array(227'tip' => $this->tooltip,228);229}230231if ($this->noCSS) {232$classes = array();233}234235// See PHI823. If we aren't rendering a "<button>" or "<input>" tag,236// give the tag we are rendering a "button" role as a hint to screen237// readers.238$role = null;239if ($this->tag !== 'button' && $this->tag !== 'input') {240$role = 'button';241}242243$attrs = array(244'class' => $classes,245'href' => $this->href,246'name' => $this->name,247'title' => $this->title,248'sigil' => $sigil,249'meta' => $meta,250'role' => $role,251);252253if ($this->tag == 'input') {254$attrs['type'] = 'submit';255$attrs['value'] = $this->text;256}257258return $attrs;259}260261protected function getTagContent() {262if ($this->tag === 'input') {263return null;264}265266$icon = $this->icon;267$text = null;268$subtext = null;269270if ($this->subtext) {271$subtext = phutil_tag(272'div',273array(274'class' => 'phui-button-subtext',275),276$this->subtext);277}278279if ($this->text !== null) {280$text = phutil_tag(281'div',282array(283'class' => 'phui-button-text',284),285array(286$this->text,287$subtext,288));289}290291$caret = null;292if ($this->dropdown || $this->getHasCaret()) {293$caret = phutil_tag('span', array('class' => 'caret'), '');294}295296$aural = null;297if ($this->auralLabel !== null) {298$aural = phutil_tag(299'span',300array(301'class' => 'aural-only',302),303$this->auralLabel);304}305306307if ($this->iconFirst == true) {308return array($aural, $icon, $text, $caret);309} else {310return array($aural, $text, $icon, $caret);311}312}313}314315316