@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
at recaptime-dev/main 113 lines 2.6 kB view raw
1<?php 2 3final class PHUIIconCircleView extends AphrontTagView { 4 5 private $href = null; 6 private $icon; 7 private $color; 8 private $size; 9 private $state; 10 11 const SMALL = 'circle-small'; 12 const MEDIUM = 'circle-medium'; 13 14 const STATE_FAIL = 'fa-times-circle'; 15 const STATE_INFO = 'fa-info-circle'; 16 const STATE_STOP = 'fa-stop-circle'; 17 const STATE_START = 'fa-play-circle'; 18 const STATE_PAUSE = 'fa-pause-circle'; 19 const STATE_SUCCESS = 'fa-check-circle'; 20 const STATE_WARNING = 'fa-exclamation-circle'; 21 const STATE_PLUS = 'fa-plus-circle'; 22 const STATE_MINUS = 'fa-minus-circle'; 23 const STATE_UNKNOWN = 'fa-question-circle'; 24 25 public function setHref($href) { 26 $this->href = $href; 27 return $this; 28 } 29 30 public function setIcon($icon) { 31 $this->icon = $icon; 32 return $this; 33 } 34 35 public function setColor($color) { 36 $this->color = $color; 37 return $this; 38 } 39 40 public function setSize($size) { 41 $this->size = $size; 42 return $this; 43 } 44 45 public function setState($state) { 46 $this->state = $state; 47 return $this; 48 } 49 50 protected function getTagName() { 51 $tag = 'span'; 52 if ($this->href) { 53 $tag = 'a'; 54 } 55 return $tag; 56 } 57 58 protected function getTagAttributes() { 59 require_celerity_resource('phui-icon-view-css'); 60 61 $classes = array(); 62 $classes[] = 'phui-icon-circle'; 63 64 if ($this->color) { 65 $classes[] = 'hover-'.$this->color; 66 } else { 67 $classes[] = 'hover-sky'; 68 } 69 70 if ($this->size) { 71 $classes[] = $this->size; 72 } 73 74 if ($this->state) { 75 $classes[] = 'phui-icon-circle-state'; 76 } 77 78 return array( 79 'href' => $this->href, 80 'class' => $classes, 81 ); 82 } 83 84 protected function getTagContent() { 85 $state = null; 86 if ($this->state) { 87 $state = id(new PHUIIconView()) 88 ->setIcon($this->state.' '.$this->color) 89 ->addClass('phui-icon-circle-state-icon'); 90 } 91 92 return id(new PHUIIconView()) 93 ->setIcon($this->icon) 94 ->addClass('phui-icon-circle-icon') 95 ->appendChild($state); 96 } 97 98 public static function getStateMap() { 99 return array( 100 self::STATE_FAIL => pht('Failure'), 101 self::STATE_INFO => pht('Information'), 102 self::STATE_STOP => pht('Stop'), 103 self::STATE_START => pht('Start'), 104 self::STATE_PAUSE => pht('Pause'), 105 self::STATE_SUCCESS => pht('Success'), 106 self::STATE_WARNING => pht('Warning'), 107 self::STATE_PLUS => pht('Plus'), 108 self::STATE_MINUS => pht('Minus'), 109 self::STATE_UNKNOWN => pht('Unknown'), 110 ); 111 } 112 113}