Add Badge support to Hovercards
Summary: Let's you add Badges to Hovercards Test Plan: UIExamples Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T7992 Differential Revision: https://secure.phabricator.com/D13623
This commit is contained in:
@@ -51,6 +51,14 @@ final class PhabricatorHovercardUIExample extends PhabricatorUIExample {
|
||||
->addTag($tag));
|
||||
$elements[] = $panel;
|
||||
|
||||
$badge1 = id(new PHUIBadgeMiniView())
|
||||
->setIcon('fa-book')
|
||||
->setHeader(pht('Documenter'));
|
||||
|
||||
$badge2 = id(new PHUIBadgeMiniView())
|
||||
->setIcon('fa-star')
|
||||
->setHeader(pht('Contributor'));
|
||||
|
||||
$user_handle = $this->createBasicDummyHandle(
|
||||
'gwashington',
|
||||
PhabricatorPeopleUserPHIDType::TYPECONST,
|
||||
@@ -63,6 +71,8 @@ final class PhabricatorHovercardUIExample extends PhabricatorUIExample {
|
||||
->addField(pht('Status'), pht('Available'))
|
||||
->addField(pht('Member since'), '30. February 1750')
|
||||
->addAction(pht('Send a Message'), '/dev/null')
|
||||
->addBadge($badge1)
|
||||
->addBadge($badge2)
|
||||
->setUser($user));
|
||||
$elements[] = $panel;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ final class PhabricatorHovercardView extends AphrontView {
|
||||
private $tags = array();
|
||||
private $fields = array();
|
||||
private $actions = array();
|
||||
private $badges = array();
|
||||
|
||||
public function setObjectHandle(PhabricatorObjectHandle $handle) {
|
||||
$this->handle = $handle;
|
||||
@@ -64,6 +65,11 @@ final class PhabricatorHovercardView extends AphrontView {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addBadge(PHUIBadgeMiniView $badge) {
|
||||
$this->badges[] = $badge;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
if (!$this->handle) {
|
||||
throw new PhutilInvalidStateException('setObjectHandle');
|
||||
@@ -106,12 +112,24 @@ final class PhabricatorHovercardView extends AphrontView {
|
||||
foreach ($this->fields as $field) {
|
||||
$item = array(
|
||||
phutil_tag('strong', array(), $field['label']),
|
||||
' ',
|
||||
': ',
|
||||
phutil_tag('span', array(), $field['value']),
|
||||
);
|
||||
$body[] = phutil_tag_div('phabricator-hovercard-body-item', $item);
|
||||
}
|
||||
|
||||
if ($this->badges) {
|
||||
$badges = id(new PHUIBadgeBoxView())
|
||||
->addItems($this->badges)
|
||||
->setCollapsed(true);
|
||||
$body[] = phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'phabricator-hovercard-body-item hovercard-badges',
|
||||
),
|
||||
$badges);
|
||||
}
|
||||
|
||||
if ($handle->getImageURI()) {
|
||||
// Probably a user, we don't need to assume something else
|
||||
// "Prepend" the image by appending $body
|
||||
@@ -163,8 +181,6 @@ final class PhabricatorHovercardView extends AphrontView {
|
||||
$tail = phutil_tag_div('phabricator-hovercard-tail', $buttons);
|
||||
}
|
||||
|
||||
// Assemble container
|
||||
// TODO: Add color support
|
||||
$hovercard = phutil_tag_div(
|
||||
'phabricator-hovercard-container',
|
||||
array(
|
||||
@@ -173,8 +189,6 @@ final class PhabricatorHovercardView extends AphrontView {
|
||||
$tail,
|
||||
));
|
||||
|
||||
// Wrap for thick border
|
||||
// and later the tip at the bottom
|
||||
return phutil_tag_div('phabricator-hovercard-wrapper', $hovercard);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user