diff --git a/src/Markup/Button.php b/src/Markup/Button.php index 60c8b8e..9e3a621 100644 --- a/src/Markup/Button.php +++ b/src/Markup/Button.php @@ -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; } diff --git a/src/Markup/Image.php b/src/Markup/Image.php index 04a4811..9d37f54 100644 --- a/src/Markup/Image.php +++ b/src/Markup/Image.php @@ -13,6 +13,8 @@ public static function create(): Image public function imageUrl(string $url): Image { + $this->fragment['imageUrl'] = $url; + return $this; } diff --git a/src/Markup/OnClick.php b/src/Markup/OnClick.php index c038f89..ac9dad9 100644 --- a/src/Markup/OnClick.php +++ b/src/Markup/OnClick.php @@ -13,6 +13,8 @@ public static function create(): OnClick public function action(FormAction $formAction): OnClick { + unset($this->fragment['openLink']); + $this->fragment['action'] = $formAction->getMarkup(); return $this; @@ -20,7 +22,9 @@ public function action(FormAction $formAction): OnClick public function openLink(string $url): OnClick { - $this->fragment['openLink'] = $url; + unset($this->fragment['action']); + + $this->fragment['openLink']['url'] = $url; return $this; } diff --git a/src/Widget.php b/src/Widget.php index 35eab08..7cafe31 100644 --- a/src/Widget.php +++ b/src/Widget.php @@ -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, ]; @@ -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; @@ -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;