Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 21, 2022
1 parent 039b126 commit 5ef237a
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 46 deletions.
2 changes: 1 addition & 1 deletion demos/basic/button.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct($n)
{
Icon::addTo(Button::addTo($this, ['Forks', 'blue']), ['fork']);
Label::addTo($this, [number_format($n), 'basic blue left pointing']);
parent::__construct(null, 'labeled');
parent::__construct(['class.labeled' => true]);
}
});

Expand Down
2 changes: 1 addition & 1 deletion demos/basic/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
\Atk4\Ui\Header::addTo($seg, ['Center-aligned', 'aligned' => 'center', 'image' => $img, 'subHeader' => 'header with image']);

$seg = \Atk4\Ui\View::addTo($app, ['ui' => 'segment']);
\Atk4\Ui\Header::addTo($seg, ['Center-aligned', 'aligned' => 'center', 'image' => [$img, 'disabled'], 'subHeader' => 'header with image']);
\Atk4\Ui\Header::addTo($seg, ['Center-aligned', 'aligned' => 'center', 'image' => [$img, 'class.disabled' => true], 'subHeader' => 'header with image']);
4 changes: 2 additions & 2 deletions demos/basic/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
$submenu->addItem('two');

$menu = \Atk4\Ui\Menu::addTo($app, ['vertical pointing']);
$menu->addItem(['Inbox', 'label' => ['123', 'teal left pointing']]);
$menu->addItem(['Inbox', 'label' => ['123', 'class.teal left pointing' => true]]);
$menu->addItem('Spam');
\Atk4\Ui\Form\Control\Input::addTo($menu->addItem(), ['placeholder' => 'Search', 'icon' => 'search'])->addClass('transparent');

$menu = \Atk4\Ui\Menu::addTo($app, ['secondary vertical pointing']);
$menu->addItem(['Inbox', 'label' => ['123', 'teal left pointing']]);
$menu->addItem(['Inbox', 'label' => ['123', 'class.teal left pointing' => true]]);
$menu->addItem('Spam');
\Atk4\Ui\Form\Control\Input::addTo($menu->addItem(), ['placeholder' => 'Search', 'icon' => 'search'])->addClass('transparent');
$menu = \Atk4\Ui\Menu::addTo($app, ['vertical']);
Expand Down
2 changes: 1 addition & 1 deletion demos/collection/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
$crud->setModel($model);

// Because Crud inherits Grid, you can also define custom actions
$crud->addModalAction(['icon' => [\Atk4\Ui\Icon::class, 'cogs']], 'Details', function ($p, $id) use ($crud) {
$crud->addModalAction(['icon' => 'cogs'], 'Details', function ($p, $id) use ($crud) {
$model = Country::assertInstanceOf($crud->model);
\Atk4\Ui\Message::addTo($p, ['Details for: ' . $model->load($id)->name . ' (id: ' . $id . ')']);
});
Expand Down
2 changes: 1 addition & 1 deletion demos/collection/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
return 'Loaded "' . $model->load($id)->name . '" from ID=' . $id;
});

$grid->addModalAction(['icon' => [\Atk4\Ui\Icon::class, 'external']], 'Modal Test', function ($p, $id) {
$grid->addModalAction(['icon' => 'external'], 'Modal Test', function ($p, $id) {
\Atk4\Ui\Message::addTo($p, ['Clicked on ID=' . $id]);
});

Expand Down
14 changes: 7 additions & 7 deletions demos/form-control/input.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
'labelRight' => $dd,
]);

Form\Control\Line::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new \Atk4\Ui\Label(['kg', 'basic'])]);
Form\Control\Line::addTo($app, ['label' => '$', 'labelRight' => new \Atk4\Ui\Label(['.00', 'basic'])]);
Form\Control\Line::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new \Atk4\Ui\Label(['kg', 'class.basic' => true])]);
Form\Control\Line::addTo($app, ['label' => '$', 'labelRight' => new \Atk4\Ui\Label(['.00', 'class.basic' => true])]);

Form\Control\Line::addTo($app, [
'iconLeft' => 'tags',
'labelRight' => new \Atk4\Ui\Label(['Add Tag', 'tag']),
'labelRight' => new \Atk4\Ui\Label(['Add Tag', 'class.tag' => true]),
]);

// left/right corner is not supported, but here is work-around:
Expand All @@ -68,22 +68,22 @@
Form\Control\Line::addTo($app, ['action' => 'Search']);

Form\Control\Line::addTo($app, ['actionLeft' => new \Atk4\Ui\Button([
'Checkout', 'icon' => 'cart', 'teal',
'Checkout', 'class.teal' => true, 'icon' => 'cart',
])]);

Form\Control\Line::addTo($app, ['iconLeft' => 'search', 'action' => 'Search']);

$dd = new \Atk4\Ui\DropdownButton(['This Page', 'basic']);
$dd = new \Atk4\Ui\DropdownButton(['This Page', 'class.basic' => true]);
$dd->setSource(['This Organisation', 'Entire Site']);
Form\Control\Line::addTo($app, ['iconLeft' => 'search', 'action' => $dd]);

// double actions are not supported but you can add them yourself
$dd = new \Atk4\Ui\Dropdown(['Articles', 'compact selection']);
$dd = new \Atk4\Ui\Dropdown(['Articles', 'class.compact selection' => true]);
$dd->setSource(['All', 'Services', 'Products']);
\Atk4\Ui\Button::addTo(Form\Control\Line::addTo($app, ['iconLeft' => 'search', 'action' => $dd]), ['Search'], ['AfterAfterInput']);

Form\Control\Line::addTo($app, ['action' => new \Atk4\Ui\Button([
'Copy', 'iconRight' => 'copy', 'teal',
'Copy', 'class.teal' => true, 'iconRight' => 'copy',
])]);

Form\Control\Line::addTo($app, ['action' => new \Atk4\Ui\Button([
Expand Down
6 changes: 3 additions & 3 deletions demos/form-control/lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
->setModel(new Country($app->db));

// through constructor
Form\Control\Lookup::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new \Atk4\Ui\Label(['kg', 'basic'])]);
Form\Control\Lookup::addTo($app, ['label' => '$', 'labelRight' => new \Atk4\Ui\Label(['.00', 'basic'])]);
Form\Control\Lookup::addTo($app, ['placeholder' => 'Weight', 'labelRight' => new \Atk4\Ui\Label(['kg', 'class.basic' => true])]);
Form\Control\Lookup::addTo($app, ['label' => '$', 'labelRight' => new \Atk4\Ui\Label(['.00', 'class.basic' => true])]);

Form\Control\Lookup::addTo($app, [
'iconLeft' => 'tags',
'labelRight' => new \Atk4\Ui\Label(['Add Tag', 'tag']),
'labelRight' => new \Atk4\Ui\Label(['Add Tag', 'class.tag' => true]),
]);

// left/right corner is not supported, but here is work-around:
Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@

// Add buttons to modal for next and previous actions.
$action = new \Atk4\Ui\View(['ui' => 'buttons']);
$prevAction = new \Atk4\Ui\Button(['Prev', 'labeled', 'icon' => 'left arrow']);
$prevAction = new \Atk4\Ui\Button(['Prev', 'class.labeled' => true, 'icon' => 'left arrow']);
$nextAction = new \Atk4\Ui\Button(['Next', 'iconRight' => 'right arrow']);

$action->add($prevAction);
Expand Down
2 changes: 1 addition & 1 deletion demos/interactive/progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

$p = \Atk4\Ui\ProgressBar::addTo($app, [20]);

$p = \Atk4\Ui\ProgressBar::addTo($app, [60, 'indicating progress', 'indicating']);
$p = \Atk4\Ui\ProgressBar::addTo($app, [60, 'indicating progress', 'class.indicating' => true]);
\Atk4\Ui\Button::addTo($app, ['increment'])->on('click', $p->jsIncrement());
\Atk4\Ui\Button::addTo($app, ['set'])->on('click', $p->jsValue(20));
2 changes: 1 addition & 1 deletion demos/interactive/scroll-grid-container.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
$g1->addQuickSearch([Country::hinting()->fieldName()->name, Country::hinting()->fieldName()->iso]);

// demo for additional action buttons in Crud + JsPaginator
$g1->addModalAction(['icon' => [\Atk4\Ui\Icon::class, 'cogs']], 'Details', function ($p, $id) use ($g1) {
$g1->addModalAction(['icon' => 'cogs'], 'Details', function ($p, $id) use ($g1) {
\Atk4\Ui\Card::addTo($p)->setModel($g1->model->load($id));
});
$g1->addActionButton('red', function ($js) {
Expand Down
2 changes: 1 addition & 1 deletion docs/app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ Populating the left menu object is simply a matter of adding the right menu item
This is the top menu of the admin layout. You can add other item to the top menu using::

Button::addTo($layout->menu->addItem(), ['View Source', 'teal', 'icon' => 'github'])
Button::addTo($layout->menu->addItem(), ['View Source', 'class.teal' => true, 'icon' => 'github'])
->setAttr('target', '_blank')->on('click', new \Atk4\Ui\JsExpression('document.location=[];', [$url . $f]));

.. php:attr:: menuRight
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -1880,9 +1880,6 @@ parameters:
-
path: 'src/Table/Column/Link.php'
message: '~^Property Atk4\\Ui\\Table\\Column\\Link::\$args has no type specified\.$~'
-
path: 'src/Table/Column/Link.php'
message: '~^Method Atk4\\Ui\\Table\\Column\\Link::__construct\(\) has parameter \$args with no type specified\.$~'
-
path: 'src/Table/Column/Link.php'
message: '~^Method Atk4\\Ui\\Table\\Column\\Link::__construct\(\) has parameter \$page with no type specified\.$~'
Expand Down
4 changes: 2 additions & 2 deletions src/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class ProgressBar extends View
/** @var int Indicates a maximum value of a progress bar. */
public $max = 100;

public function __construct($value = 0, $label = null, $class = null)
public function __construct($value = 0, $label = [])
{
$this->value = $value;

parent::__construct($label, $class);
parent::__construct($label);
}

protected function renderView(): void
Expand Down
2 changes: 1 addition & 1 deletion src/UserAction/VpExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class VpExecutor extends View implements JsExecutorInterface
public $stepListItems = ['args' => 'Fill argument(s)', 'fields' => 'Edit Record(s)', 'preview' => 'Preview', 'final' => 'Complete'];

/** @var array */
public $cancelBtnSeed = [Button::class, ['Cancel', 'small left floated basic blue', 'icon' => 'left arrow']];
public $cancelBtnSeed = [Button::class, ['Cancel', 'class.small left floated basic blue' => true, 'icon' => 'left arrow']];

protected function init(): void
{
Expand Down
32 changes: 12 additions & 20 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,25 @@ class View extends AbstractView implements JsExpressionable

/**
* @param array|string $label
* @param array|string $class
*/
public function __construct($label = null, $class = null)
public function __construct($label = [])
{
if (is_array($label)) {
$defaults = $label;
if (isset($defaults[0])) {
$label = $defaults[0];
unset($defaults[0]);
} else {
$label = null;
}
$defaults = is_array($label) ? $label : [$label];
unset($label);

if (isset($defaults[1])) {
$class = $defaults[1];
unset($defaults[1]);
}
$this->setDefaults($defaults);
if (array_key_exists(0, $defaults)) {
$defaults['content'] = $defaults[0];
unset($defaults[0]);
}

if ($label !== null) {
$this->content = $label;
}
// @TODO func_num_args() > 1!!!!
if (func_num_args() > 2 || count(array_filter($defaults, 'is_int', \ARRAY_FILTER_USE_KEY)) > 0) { // prevent bad usage
var_dump(func_get_args());

if ($class) {
$this->addClass($class);
throw new \Error('Too many method arguments');
}

$this->setDefaults($defaults);
}

/**
Expand Down

0 comments on commit 5ef237a

Please sign in to comment.