Skip to content

Commit

Permalink
fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dmouse committed May 23, 2019
1 parent b79cbd1 commit 4c87a52
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/Markup/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ class Button implements MarkupInterface

public function textButton(string $text, OnClick $click): Button
{
unset($this->fragment['imageButton']);

$this->fragment['textButton']['text'] = $text;
$this->fragment['onClick'] = $click->getMarkup();
$this->fragment['textButton']['onClick'] = $click->getMarkup();

return $this;
}

public function imageButton(OnClick $click, string $name, string $icon = '', string $iconUrl = ''): Button
public function imageButton(OnClick $click, string $name, string $icon = null, string $iconUrl = null): Button
{
$this->fragment['imageButton'] = [
'onClick' => $click->getMarkup(),
'name' => $name,
'icon' => $icon,
'iconUrl' => $iconUrl,
];
unset($this->fragment['textButton']);

if ($icon) {
$this->fragment['imageButton']['icon'] = $icon;
unset($this->fragment['imageButton']['iconUrl']);
}
elseif ($iconUrl) {
$this->fragment['imageButton']['iconUrl'] = $iconUrl;
unset($this->fragment['imageButton']['icon']);
}

$this->fragment['imageButton']['onClick'] = $click->getMarkup();
$this->fragment['imageButton']['name'] = $name;

return $this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Markup/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static function create(): Image

public function imageUrl(string $url): Image
{
$this->fragment['imageUrl'] = $url;

return $this;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Markup/OnClick.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ public static function create(): OnClick

public function action(FormAction $formAction): OnClick
{
unset($this->fragment['openLink']);

$this->fragment['action'] = $formAction->getMarkup();

return $this;
}

public function openLink(string $url): OnClick
{
$this->fragment['openLink'] = $url;
unset($this->fragment['action']);

$this->fragment['openLink']['url'] = $url;

return $this;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public static function create(): Widget

public function textParagraph(string $text): Widget
{
unset($this->fragment['image']);
unset($this->fragment['keyValue']);

$this->fragment['textParagraph'] = [
'text' => $text,
];
Expand All @@ -26,6 +29,9 @@ public function textParagraph(string $text): Widget

public function image(Image $image)
{
unset($this->fragment['textParagraph']);
unset($this->fragment['keyValue']);

$this->fragment['image'] = $image->getMarkup();

return $this;
Expand All @@ -40,6 +46,9 @@ public function addButton(Button $button): Widget

public function keyValue(KeyValue $keyValue): Widget
{
unset($this->fragment['textParagraph']);
unset($this->fragment['image']);

$this->fragment['keyValue'] = $keyValue->getMarkup();

return $this;
Expand Down

0 comments on commit 4c87a52

Please sign in to comment.