Skip to content

Commit 4c87a52

Browse files
committed
fix logic
1 parent b79cbd1 commit 4c87a52

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

src/Markup/Button.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,29 @@ class Button implements MarkupInterface
99

1010
public function textButton(string $text, OnClick $click): Button
1111
{
12+
unset($this->fragment['imageButton']);
13+
1214
$this->fragment['textButton']['text'] = $text;
13-
$this->fragment['onClick'] = $click->getMarkup();
15+
$this->fragment['textButton']['onClick'] = $click->getMarkup();
1416

1517
return $this;
1618
}
1719

18-
public function imageButton(OnClick $click, string $name, string $icon = '', string $iconUrl = ''): Button
20+
public function imageButton(OnClick $click, string $name, string $icon = null, string $iconUrl = null): Button
1921
{
20-
$this->fragment['imageButton'] = [
21-
'onClick' => $click->getMarkup(),
22-
'name' => $name,
23-
'icon' => $icon,
24-
'iconUrl' => $iconUrl,
25-
];
22+
unset($this->fragment['textButton']);
23+
24+
if ($icon) {
25+
$this->fragment['imageButton']['icon'] = $icon;
26+
unset($this->fragment['imageButton']['iconUrl']);
27+
}
28+
elseif ($iconUrl) {
29+
$this->fragment['imageButton']['iconUrl'] = $iconUrl;
30+
unset($this->fragment['imageButton']['icon']);
31+
}
32+
33+
$this->fragment['imageButton']['onClick'] = $click->getMarkup();
34+
$this->fragment['imageButton']['name'] = $name;
2635

2736
return $this;
2837
}

src/Markup/Image.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public static function create(): Image
1313

1414
public function imageUrl(string $url): Image
1515
{
16+
$this->fragment['imageUrl'] = $url;
17+
1618
return $this;
1719
}
1820

src/Markup/OnClick.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ public static function create(): OnClick
1313

1414
public function action(FormAction $formAction): OnClick
1515
{
16+
unset($this->fragment['openLink']);
17+
1618
$this->fragment['action'] = $formAction->getMarkup();
1719

1820
return $this;
1921
}
2022

2123
public function openLink(string $url): OnClick
2224
{
23-
$this->fragment['openLink'] = $url;
25+
unset($this->fragment['action']);
26+
27+
$this->fragment['openLink']['url'] = $url;
2428

2529
return $this;
2630
}

src/Widget.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public static function create(): Widget
1717

1818
public function textParagraph(string $text): Widget
1919
{
20+
unset($this->fragment['image']);
21+
unset($this->fragment['keyValue']);
22+
2023
$this->fragment['textParagraph'] = [
2124
'text' => $text,
2225
];
@@ -26,6 +29,9 @@ public function textParagraph(string $text): Widget
2629

2730
public function image(Image $image)
2831
{
32+
unset($this->fragment['textParagraph']);
33+
unset($this->fragment['keyValue']);
34+
2935
$this->fragment['image'] = $image->getMarkup();
3036

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

4147
public function keyValue(KeyValue $keyValue): Widget
4248
{
49+
unset($this->fragment['textParagraph']);
50+
unset($this->fragment['image']);
51+
4352
$this->fragment['keyValue'] = $keyValue->getMarkup();
4453

4554
return $this;

0 commit comments

Comments
 (0)