@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
1<?php
2
3final class PHUIBoxView extends AphrontTagView {
4
5 private $margin = array();
6 private $padding = array();
7 private $border = false;
8 private $color;
9 private $collapsible;
10
11 const BLUE = 'phui-box-blue';
12 const GREY = 'phui-box-grey';
13
14 public function addMargin($margin) {
15 $this->margin[] = $margin;
16 return $this;
17 }
18
19 public function addPadding($padding) {
20 $this->padding[] = $padding;
21 return $this;
22 }
23
24 public function setBorder($border) {
25 $this->border = $border;
26 return $this;
27 }
28
29 public function setColor($color) {
30 $this->color = $color;
31 return $this;
32 }
33
34 /**
35 * Render PHUIBoxView as a <details> instead of a <div> HTML tag.
36 * To be used for collapse/expand in combination with PHUIHeaderView.
37 *
38 * @param bool $collapsible True to wrap in <summary> instead of <div> HTML
39 * tag.
40 */
41 public function setCollapsible($collapsible) {
42 $this->collapsible = $collapsible;
43 return $this;
44 }
45
46 protected function getTagAttributes() {
47 require_celerity_resource('phui-box-css');
48 $outer_classes = array();
49 $outer_classes[] = 'phui-box';
50
51 if ($this->border) {
52 $outer_classes[] = 'phui-box-border';
53 }
54
55 foreach ($this->margin as $margin) {
56 $outer_classes[] = $margin;
57 }
58
59 foreach ($this->padding as $padding) {
60 $outer_classes[] = $padding;
61 }
62
63 if ($this->color) {
64 $outer_classes[] = $this->color;
65 }
66
67 $tag_classes = array('class' => $outer_classes);
68
69 if ($this->collapsible) {
70 $attribute = array('open' => ''); // expand column by default
71 $tag_classes = array_merge($tag_classes, $attribute);
72 }
73
74 return $tag_classes;
75 }
76
77 protected function getTagName() {
78 if ($this->collapsible) {
79 return 'details';
80 }
81 return 'div';
82 }
83
84 protected function getTagContent() {
85 return $this->renderChildren();
86 }
87}