Skip to content

Commit

Permalink
tabs bootstrap 4 theme changes, tab IDs fix, assets publishes and cop…
Browse files Browse the repository at this point in the history
…ied to repository
  • Loading branch information
dobrik committed Jun 18, 2019
1 parent 82c7c27 commit 7f62f96
Show file tree
Hide file tree
Showing 33 changed files with 26,125 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function create(string $form_name, Model $model = null): HtmlAbstract
$tabs_main_obj = $this->factory->html('tabs')->setLabel('');

$main_tabs = [];
$main_tabs[1] = $this->factory->html('tab')->setId(1)->setTitle('Общее')->setContent('');
$main_tabs[1] = $this->factory->html('tab')->setId('tab_' . 1)->setTitle('Общее')->setContent('');

if ($form_config->has('tabs')) {
$tabs_data = $form_config->get('tabs');
Expand All @@ -82,9 +82,9 @@ public function create(string $form_name, Model $model = null): HtmlAbstract

foreach ($tabs_data as $tab_data) {
if (!empty($tab_data['callback']) && $tab_data['callback'] instanceof Closure) {
$main_tabs[$tab_data['id']] = $this->factory->html('tab')->setId($tab_data['id'])->setTitle($tab_data['title'])->setContent($tab_data['callback']());
$main_tabs[$tab_data['id']] = $this->factory->html('tab')->setId('tab_' . $tab_data['id'])->setTitle($tab_data['title'])->setContent($tab_data['callback']());
} else {
$main_tabs[$tab_data['id']] = $this->factory->html('tab')->setId($tab_data['id'])->setTitle($tab_data['title']);
$main_tabs[$tab_data['id']] = $this->factory->html('tab')->setId('tab_' . $tab_data['id'])->setTitle($tab_data['title']);
}
}
}
Expand Down
28 changes: 23 additions & 5 deletions src/Forms/Html/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ class Tab extends HtmlAbstract
* @var array
*/
protected $required_attributes = [
'content', 'title', 'id'
'title', 'id'
];

public $attributes = [
'class' => 'nav-items'
];

public $content;

/**
* @param array|string $data
* @return HtmlAbstract
Expand All @@ -30,15 +36,27 @@ public function append($data): HtmlAbstract

if (\is_array($data)) {
foreach ($data as $item) {
$this->attributes['content'] .= $item;
$this->content .= $item;
}
return $this;
}
$this->attributes['content'] .= $data;
$this->content .= $data;

return $this;
}

public function setContent($data)
{
$this->content = $data;
return $this;
}

public function getContent()
{
return $this->content;
}


/**
* Add tabs plugin class.
* @throws \Throwable
Expand All @@ -49,7 +67,7 @@ private function prepareTabClass(): void
if (null === $this->getClass()) {
$this->setClass('');
}
$this->attributes['class'] .= ' tab-pane';
$this->attributes['class'] .= ' tab-pane fade';
}

/**
Expand All @@ -59,6 +77,6 @@ private function prepareTabClass(): void
public function getData(): array
{
$this->prepareTabClass();
return ['content' => Arr::pull($this->attributes, 'content')];
return ['content' => $this->getContent()];
}
}
19 changes: 6 additions & 13 deletions src/Forms/Html/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Tabs extends HtmlAbstract
/**
* @var array
*/
public $attributes = ['class' => 'nav-tabs-custom'];
public $attributes = ['class' => 'nav nav-tabs'];

/**
* @var array
Expand Down Expand Up @@ -53,13 +53,8 @@ private function checkActive(): void
{
$has_active = false;
foreach ($this->tabs as $key => $tab) {
if (Str::contains($tab->getClass(), 'active')) {
$has_active = true;
break;
}
}
if (!$has_active) {
$this->tabs[0]->setClass('active');
$tab->setClass('active show');
break;
}
}

Expand All @@ -69,11 +64,9 @@ private function checkActive(): void
*/
public function setTabs(array $tabs): HtmlAbstract
{
if (\is_array($tabs)) {
foreach ($tabs as $tab) {
if ($tab instanceof Tab) {
$this->tabs[] = $tab;
}
foreach ($tabs as $tab) {
if ($tab instanceof Tab) {
$this->tabs[] = $tab;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function boot()
$this->getFormsConfigPath() => config_path('easy_form/forms.php'),
$this->getViewsPath() => resource_path('views/vendor/easy_form'),
]);
$this->publiches([__DIR__ . '/resources/assets' => public_path('vendor/easy_form/assets')], 'assets');
}

private function getMainConfigPath()
Expand Down
Loading

0 comments on commit 7f62f96

Please sign in to comment.