Skip to content

Commit

Permalink
Separate chain calls (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
sankaest committed Jun 1, 2022
1 parent 594a17c commit d3a2214
Show file tree
Hide file tree
Showing 24 changed files with 623 additions and 246 deletions.
9 changes: 7 additions & 2 deletions docs/modal.md
Expand Up @@ -92,8 +92,13 @@ JS;
$this->registerJs($modalJS);
?>

<?= Modal::widget()->id('modal')->begin() .
Div::tag()->class('box')->content('Say hello...')->render() . PHP_EOL .
<?= Modal::widget()
->id('modal')
->begin() .
Div::tag()
->class('box')
->content('Say hello...')
->render() . PHP_EOL .
Modal::end() ?>
```

Expand Down
8 changes: 6 additions & 2 deletions docs/modalcard.md
Expand Up @@ -56,8 +56,12 @@ $this->registerJs($modalJS);

<?= ModalCard::widget()
->footer(
Button::tag()->class('button is-success')->content('Save changes') .
Button::tag()->class('button is-danger is-outline')->content('Cancel')
Button::tag()
->class('button is-success')
->content('Save changes') .
Button::tag()
->class('button is-danger is-outline')
->content('Cancel')
)
->title('Modal title.')
->begin() ?>
Expand Down
21 changes: 17 additions & 4 deletions src/Breadcrumbs.php
Expand Up @@ -233,7 +233,11 @@ protected function run(): string
implode('', $this->renderItems()) .
Html::closeTag('ul') . PHP_EOL;

return $customTag->content($content)->attributes($attributes)->encode(false)->render();
return $customTag
->content($content)
->attributes($attributes)
->encode(false)
->render();
}

private function renderIcon(?string $icon, array $iconAttributes): string
Expand All @@ -243,7 +247,9 @@ private function renderIcon(?string $icon, array $iconAttributes): string
if ($icon !== null) {
$html = Span::tag()
->attributes($iconAttributes)
->content(I::tag()->attributes(['class' => $icon, 'aria-hidden' => 'true'])->render())
->content(I::tag()
->attributes(['class' => $icon, 'aria-hidden' => 'true'])
->render())
->encode($this->encode)
->render();
}
Expand Down Expand Up @@ -295,11 +301,18 @@ private function renderItem(array $item, string $template): string
$icon = $this->renderIcon($icon, $iconAttributes);

if ($icon !== '') {
$label = $icon . Span::tag()->content($label)->render();
$label = $icon . Span::tag()
->content($label)
->render();
}

$link = $url !== null
? A::tag()->attributes($item)->content($label)->url($url)->encode($encode)->render() : $label;
? A::tag()
->attributes($item)
->content($label)
->url($url)
->encode($encode)
->render() : $label;

return strtr($template, ['{link}' => $link, '{label}' => $label, '{icon}' => $icon]);
}
Expand Down
80 changes: 46 additions & 34 deletions src/Dropdown.php
Expand Up @@ -428,35 +428,35 @@ private function renderDropdownButton(string $id): string
$buttonAttributes['aria-controls'] = $id;

return Button::tag()
->attributes($buttonAttributes)
->content(
$this->renderLabelButton(
$this->buttonLabel,
$this->buttonLabelAttributes,
$this->buttonIconText,
$this->buttonIconCssClass,
$this->buttonIconAttributes,
->attributes($buttonAttributes)
->content(
$this->renderLabelButton(
$this->buttonLabel,
$this->buttonLabelAttributes,
$this->buttonIconText,
$this->buttonIconCssClass,
$this->buttonIconAttributes,
)
)
)
->encode(false)
->render() . PHP_EOL;
->encode(false)
->render() . PHP_EOL;
}

private function renderDropdownButtonLink(): string
{
return A::tag()
->class($this->itemCssClass)
->content(
$this->renderLabelButton(
$this->buttonLabel,
$this->buttonLabelAttributes,
$this->buttonIconText,
$this->buttonIconCssClass,
$this->buttonIconAttributes,
->class($this->itemCssClass)
->content(
$this->renderLabelButton(
$this->buttonLabel,
$this->buttonLabelAttributes,
$this->buttonIconText,
$this->buttonIconCssClass,
$this->buttonIconAttributes,
)
)
)
->encode(false)
->render() . PHP_EOL;
->encode(false)
->render() . PHP_EOL;
}

/**
Expand Down Expand Up @@ -496,10 +496,10 @@ private function renderDropdownTrigger(string $id): string
}

return Div::tag()
->class($this->triggerCssClass)
->content(PHP_EOL . $button)
->encode(false)
->render() . PHP_EOL . $this->renderDropdownMenu($id);
->class($this->triggerCssClass)
->content(PHP_EOL . $button)
->encode(false)
->render() . PHP_EOL . $this->renderDropdownMenu($id);
}

/**
Expand All @@ -516,7 +516,9 @@ private function renderItems(): string
/** @var array|string $item */
foreach ($this->items as $item) {
if ($item === '-') {
$lines[] = CustomTag::name('hr')->class($this->dividerCssClass)->render();
$lines[] = CustomTag::name('hr')
->class($this->dividerCssClass)
->render();
} else {
if (!isset($item['label'])) {
throw new InvalidArgumentException('The "label" option is required.');
Expand Down Expand Up @@ -571,7 +573,9 @@ private function renderItems(): string

if ($items === []) {
if ($itemLabel === '-') {
$content = CustomTag::name('hr')->class($this->dividerCssClass)->render();
$content = CustomTag::name('hr')
->class($this->dividerCssClass)
->render();
} elseif ($enclose === false) {
$content = $itemLabel;
} elseif ($url === '') {
Expand Down Expand Up @@ -620,17 +624,21 @@ private function renderLabelButton(

if ($label !== '') {
$html = PHP_EOL . Span::tag()
->attributes($labelAttributes)
->content($label)
->encode(false)
->render();
->attributes($labelAttributes)
->content($label)
->encode(false)
->render();
}

if ($iconText !== '' || $iconCssClass !== '') {
$html .= PHP_EOL .
Span::tag()
->attributes($iconAttributes)
->content(CustomTag::name('i')->class($iconCssClass)->content($iconText)->encode(false)->render())
->content(CustomTag::name('i')
->class($iconCssClass)
->content($iconText)
->encode(false)
->render())
->encode(false)
->render();
}
Expand All @@ -649,7 +657,11 @@ private function renderLabelItem(
if ($iconText !== '' || $iconCssClass !== '') {
$html = Span::tag()
->attributes($iconAttributes)
->content(CustomTag::name('i')->class($iconCssClass)->content($iconText)->encode(false)->render())
->content(CustomTag::name('i')
->class($iconCssClass)
->content($iconText)
->encode(false)
->render())
->encode(false)
->render();
}
Expand Down
21 changes: 16 additions & 5 deletions src/Menu.php
Expand Up @@ -491,8 +491,10 @@ private function renderItems(array $items): string
}
} elseif (!empty($menu)) {
$lines[] = $tag === null
? $menu
: Html::tag($tag, $menu, $attributes)->encode(false)->render();
? $menu
: Html::tag($tag, $menu, $attributes)
->encode(false)
->render();
}
}

Expand Down Expand Up @@ -551,7 +553,10 @@ private function renderItem(array $item, array $linkAttributes): string

return strtr(
$labelTemplate,
['{label}' => P::tag()->class('menu-label')->content($label)->render() . PHP_EOL]
['{label}' => P::tag()
->class('menu-label')
->content($label)
->render() . PHP_EOL]
);
}

Expand All @@ -560,7 +565,9 @@ private function renderIcon(string $icon, array $iconAttributes): string
return $icon !== ''
? Span::tag()
->attributes($iconAttributes)
->content(I::tag()->class($icon)->render())
->content(I::tag()
->class($icon)
->render())
->encode(false)
->render()
: '';
Expand Down Expand Up @@ -591,6 +598,10 @@ private function renderMenu(array $items): string
$content .= PHP_EOL . $this->renderItems($items) . PHP_EOL;
$content .= Html::closeTag('ul') . PHP_EOL;

return $customTag->attributes($attributes)->content($content)->encode(false)->render();
return $customTag
->attributes($attributes)
->content($content)
->encode(false)
->render();
}
}
31 changes: 23 additions & 8 deletions src/Message.php
Expand Up @@ -21,7 +21,10 @@
* For example,
*
* ```php
* <?= Message::widget()->headerColor('success')->header('System info')->body('Say hello...') ?>
* <?= Message::widget()
* ->headerColor('success')
* ->header('System info')
* ->body('Say hello...') ?>
* ```
*
* @link https://bulma.io/documentation/components/message/
Expand Down Expand Up @@ -318,13 +321,21 @@ private function renderCloseButton(): string
Html::addCssClass($closeButtonAttributes, $this->buttonCssClass);
unset($closeButtonAttributes['label']);

$label = Span::tag()->attributes($buttonSpanAttributes)->content('&times;')->encode(false)->render();
$label = Span::tag()
->attributes($buttonSpanAttributes)
->content('&times;')
->encode(false)
->render();

if ($this->size !== '') {
Html::addCssClass($closeButtonAttributes, $this->size);
}

return Button::tag()->attributes($closeButtonAttributes)->content($label)->encode(false)->render() . PHP_EOL;
return Button::tag()
->attributes($closeButtonAttributes)
->content($label)
->encode(false)
->render() . PHP_EOL;
}

private function renderHeader(): string
Expand All @@ -348,10 +359,10 @@ private function renderHeader(): string

if ($this->withoutHeader === false) {
$html = Div::tag()
->attributes($headerAttributes)
->content($headerMessage)
->encode(false)
->render() . PHP_EOL;
->attributes($headerAttributes)
->content($headerMessage)
->encode(false)
->render() . PHP_EOL;
}

return $html;
Expand Down Expand Up @@ -395,6 +406,10 @@ private function renderMessageBody(): string
$body = PHP_EOL . $body . PHP_EOL;
}

return Div::tag()->attributes($bodyAttributes)->content($body)->encode(false)->render() . PHP_EOL;
return Div::tag()
->attributes($bodyAttributes)
->content($body)
->encode(false)
->render() . PHP_EOL;
}
}
9 changes: 7 additions & 2 deletions src/Modal.php
Expand Up @@ -392,7 +392,10 @@ private function renderToggleButton(string $id): string

Html::addCssClass($toggleButtonAttributes, $this->buttonClass);

return Button::tag()->attributes($toggleButtonAttributes)->content($this->toggleButtonLabel)->render();
return Button::tag()
->attributes($toggleButtonAttributes)
->content($this->toggleButtonLabel)
->render();
}

/**
Expand All @@ -411,6 +414,8 @@ private function renderCloseButton(): string

Html::addCssClass($closeButtonAttributes, $this->closeButtonClass);

return Button::tag()->attributes($closeButtonAttributes)->render();
return Button::tag()
->attributes($closeButtonAttributes)
->render();
}
}

0 comments on commit d3a2214

Please sign in to comment.