Skip to content

Commit

Permalink
Added New Element + Added New Method to VDataTable
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Oct 10, 2022
1 parent 578b76b commit 0ebcdcb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
16 changes: 7 additions & 9 deletions wfc/ui/vuetify/VBtn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class VBtn extends HTMLNode {
/**
*
* @var HTMLNode|null
* @var VIcon|null
*/
private $iconNode;
/**
Expand Down Expand Up @@ -62,19 +62,17 @@ public function __construct($props = []) {
*/
public function setIcon($mdiIcon, array $iconProps = []) {
if ($this->iconNode === null) {
$this->iconNode = $this->addChild('v-icon');
}
if ($this->iconNode->childrenCount() != 1) {
$this->iconNode->text('');
$this->iconNode = $this->addChild(new VIcon($mdiIcon, $iconProps));
} else {
$this->iconNode->setIcon($mdiIcon);
$this->iconNode->setAttributes($iconProps);
}
$this->iconNode->getChild(0)->setText($mdiIcon);
$this->iconNode->setAttributes($iconProps);
}
/**
* Returns the icon which was added to the v-btn component.
*
* @return HTMLNode|null If an icon is added to the button, the method
* will return it as an object of type HTMLNode. Other than that, null
* @return VIcon|null If an icon is added to the button, the method
* will return it as an object of type VIcon. Other than that, null
* is returned.
*/
public function getVIcon() {
Expand Down
15 changes: 15 additions & 0 deletions wfc/ui/vuetify/VDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ public function addExpandedRow($el, string $expandedCallback = null) : HTMLNode
])->addChild($el);


}
/**
* Adds a custom slot to a column in the table.
*
* @param string $slot The name of the slot as in 'item.slot'.
*
* @param string|HTMLNode $el The element that will be added to the slot.
*
* @return HTMLNode The method will return an object of type HTMLNode
* that represents the added element.
*/
public function addItemSlot(string $slot , $el) : HTMLNode {
return $this->addChild('template', [
'#item.'.$slot
])->addChild($el);
}
/**
* Sets the name of JavaScript function that will be get executed when
Expand Down
38 changes: 38 additions & 0 deletions wfc/ui/vuetify/VIcon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace wfc\ui\vuetify;

/**
* A class that represents a v-icon vuetify element.
*
* @author i.binalshikh
*/
class VIcon extends \webfiori\ui\HTMLNode {
/**
* Creates new instance of the class.
*
* @param string $icon The name of material design icon.
*
* @param array $iconProps An optional array that holds properties of
* the icon.
*/
public function __construct(string $icon = 'mdi-information', array $iconProps = []) {
parent::__construct($icon, $iconProps);
$this->text($icon);
}
/**
* Sets the icon that will be shown by the element.
*
* @param string $icon The name of a material design icon such as 'mdi-eye'.
* The 'mdi' part can be omitted of the name as it is optional.
*/
public function setIcon(string $icon) {
$sub = substr($icon, 0, 3);

if ($sub !== 'mdi') {
$icon = 'mdi-'.$icon;
}

$this->getChild(0)->setText($icon);
}
}

0 comments on commit 0ebcdcb

Please sign in to comment.