@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 upstream/main 229 lines 5.9 kB view raw
1<?php 2 3final class PHUIButtonExample extends PhabricatorUIExample { 4 5 public function getName() { 6 return pht('Buttons'); 7 } 8 9 public function getDescription() { 10 return pht( 11 'Use %s to render buttons.', 12 phutil_tag('tt', array(), '&lt;button&gt;')); 13 } 14 15 public function renderExample() { 16 $request = $this->getRequest(); 17 $user = $request->getUser(); 18 19 // PHUIButtonView 20 $colors = array( 21 null, 22 PHUIButtonView::GREEN, 23 PHUIButtonView::RED, 24 PHUIButtonView::GREY, 25 ); 26 $sizes = array(null, PHUIButtonView::SMALL); 27 $column = array(); 28 foreach ($colors as $color) { 29 foreach ($sizes as $key => $size) { 30 $column[$key][] = id(new PHUIButtonView()) 31 ->setColor($color) 32 ->setSize($size) 33 ->setTag('a') 34 ->setText(pht('Clicky')); 35 $column[$key][] = hsprintf('<br /><br />'); 36 } 37 } 38 foreach ($colors as $color) { 39 $column[2][] = id(new PHUIButtonView()) 40 ->setColor($color) 41 ->setTag('button') 42 ->setText(pht('Button')) 43 ->setDropdown(true); 44 $column[2][] = hsprintf('<br /><br />'); 45 } 46 47 $layout2 = id(new AphrontMultiColumnView()) 48 ->addColumn($column[0]) 49 ->addColumn($column[1]) 50 ->addColumn($column[2]) 51 ->setFluidLayout(true) 52 ->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM); 53 54 // Icon Buttons 55 56 $column = array(); 57 $icons = array( 58 array( 59 'text' => pht('Comment'), 60 'icon' => 'fa-comment', 61 'dropdown' => true, 62 ), 63 array( 64 'text' => pht('Give Token'), 65 'icon' => 'fa-trophy', 66 'dropdown' => true, 67 ), 68 array( 69 'text' => pht('Reverse Time'), 70 'icon' => 'fa-clock-o', 71 ), 72 array( 73 'text' => pht('Implode Earth'), 74 'icon' => 'fa-exclamation-triangle', 75 ), 76 array( 77 'icon' => 'fa-rocket', 78 'dropdown' => true, 79 ), 80 array( 81 'icon' => 'fa-clipboard', 82 'dropdown' => true, 83 ), 84 array( 85 'icon' => 'fa-upload', 86 'disabled' => true, 87 ), 88 array( 89 'icon' => 'fa-street-view', 90 'selected' => true, 91 ), 92 array( 93 'text' => pht('Copy "Quack" to Clipboard'), 94 'icon' => 'fa-clipboard', 95 'copy' => pht('Quack'), 96 ), 97 ); 98 foreach ($icons as $text => $spec) { 99 $button = id(new PHUIButtonView()) 100 ->setTag('a') 101 ->setColor(PHUIButtonView::GREY) 102 ->setIcon(idx($spec, 'icon')) 103 ->setText(idx($spec, 'text')) 104 ->setSelected(idx($spec, 'selected')) 105 ->setDisabled(idx($spec, 'disabled')) 106 ->addClass(PHUI::MARGIN_SMALL_RIGHT) 107 ->setDropdown(idx($spec, 'dropdown')); 108 109 $copy = idx($spec, 'copy'); 110 if ($copy !== null) { 111 Javelin::initBehavior('phabricator-clipboard-copy'); 112 113 $button->addClass('clipboard-copy'); 114 $button->addSigil('clipboard-copy'); 115 $button->setMetadata( 116 array( 117 'text' => $copy, 118 'successMessage' => pht('Text copied into clipboard.'), 119 'errorMessage' => pht('Failed to copy text into clipboard.'), 120 )); 121 } 122 123 $column[] = $button; 124 } 125 126 $layout3 = id(new AphrontMultiColumnView()) 127 ->addColumn($column) 128 ->setFluidLayout(true) 129 ->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM); 130 131 $icons = array( 132 'Subscribe' => 'fa-check-circle bluegrey', 133 'Edit' => 'fa-pencil bluegrey', 134 ); 135 $designs = array( 136 PHUIButtonView::BUTTONTYPE_SIMPLE, 137 ); 138 $colors = array('', 'red', 'green', 'yellow'); 139 $column = array(); 140 foreach ($designs as $design) { 141 foreach ($colors as $color) { 142 foreach ($icons as $text => $icon) { 143 $column[] = id(new PHUIButtonView()) 144 ->setTag('a') 145 ->setButtonType($design) 146 ->setColor($color) 147 ->setIcon($icon) 148 ->setText($text) 149 ->addClass(PHUI::MARGIN_SMALL_RIGHT); 150 } 151 } 152 } 153 154 $layout4 = id(new AphrontMultiColumnView()) 155 ->addColumn($column) 156 ->setFluidLayout(true) 157 ->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM); 158 159 160 // Baby Got Back Buttons 161 162 $column = array(); 163 $icons = array('Asana', 'Github', 'Facebook', 'Google', 'LDAP'); 164 foreach ($icons as $icon) { 165 $image = id(new PHUIIconView()) 166 ->setSpriteSheet(PHUIIconView::SPRITE_LOGIN) 167 ->setSpriteIcon($icon); 168 $column[] = id(new PHUIButtonView()) 169 ->setTag('a') 170 ->setSize(PHUIButtonView::BIG) 171 ->setColor(PHUIButtonView::GREY) 172 ->setIcon($image) 173 ->setText(pht('Log In or Register')) 174 ->setSubtext($icon) 175 ->addClass(PHUI::MARGIN_MEDIUM_RIGHT); 176 } 177 178 $layout5 = id(new AphrontMultiColumnView()) 179 ->addColumn($column) 180 ->setFluidLayout(true) 181 ->setGutter(AphrontMultiColumnView::GUTTER_MEDIUM); 182 183 184 // Set it and forget it 185 186 $head2 = id(new PHUIHeaderView()) 187 ->setHeader('PHUIButtonView') 188 ->addClass('ml'); 189 190 $head3 = id(new PHUIHeaderView()) 191 ->setHeader(pht('Icon Buttons')) 192 ->addClass('ml'); 193 194 $head4 = id(new PHUIHeaderView()) 195 ->setHeader(pht('Simple Buttons')) 196 ->addClass('ml'); 197 198 $head5 = id(new PHUIHeaderView()) 199 ->setHeader(pht('Big Icon Buttons')) 200 ->addClass('ml'); 201 202 $wrap2 = id(new PHUIBoxView()) 203 ->appendChild($layout2) 204 ->addMargin(PHUI::MARGIN_LARGE); 205 206 $wrap3 = id(new PHUIBoxView()) 207 ->appendChild($layout3) 208 ->addMargin(PHUI::MARGIN_LARGE); 209 210 $wrap4 = id(new PHUIBoxView()) 211 ->appendChild($layout4) 212 ->addMargin(PHUI::MARGIN_LARGE); 213 214 $wrap5 = id(new PHUIBoxView()) 215 ->appendChild($layout5) 216 ->addMargin(PHUI::MARGIN_LARGE); 217 218 return array( 219 $head2, 220 $wrap2, 221 $head3, 222 $wrap3, 223 $head4, 224 $wrap4, 225 $head5, 226 $wrap5, 227 ); 228 } 229}