Skip to content

Commit 0ebcdcb

Browse files
committed
Added New Element + Added New Method to VDataTable
1 parent 578b76b commit 0ebcdcb

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

wfc/ui/vuetify/VBtn.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class VBtn extends HTMLNode {
1111
/**
1212
*
13-
* @var HTMLNode|null
13+
* @var VIcon|null
1414
*/
1515
private $iconNode;
1616
/**
@@ -62,19 +62,17 @@ public function __construct($props = []) {
6262
*/
6363
public function setIcon($mdiIcon, array $iconProps = []) {
6464
if ($this->iconNode === null) {
65-
$this->iconNode = $this->addChild('v-icon');
66-
}
67-
if ($this->iconNode->childrenCount() != 1) {
68-
$this->iconNode->text('');
65+
$this->iconNode = $this->addChild(new VIcon($mdiIcon, $iconProps));
66+
} else {
67+
$this->iconNode->setIcon($mdiIcon);
68+
$this->iconNode->setAttributes($iconProps);
6969
}
70-
$this->iconNode->getChild(0)->setText($mdiIcon);
71-
$this->iconNode->setAttributes($iconProps);
7270
}
7371
/**
7472
* Returns the icon which was added to the v-btn component.
7573
*
76-
* @return HTMLNode|null If an icon is added to the button, the method
77-
* will return it as an object of type HTMLNode. Other than that, null
74+
* @return VIcon|null If an icon is added to the button, the method
75+
* will return it as an object of type VIcon. Other than that, null
7876
* is returned.
7977
*/
8078
public function getVIcon() {

wfc/ui/vuetify/VDataTable.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ public function addExpandedRow($el, string $expandedCallback = null) : HTMLNode
9696
])->addChild($el);
9797

9898

99+
}
100+
/**
101+
* Adds a custom slot to a column in the table.
102+
*
103+
* @param string $slot The name of the slot as in 'item.slot'.
104+
*
105+
* @param string|HTMLNode $el The element that will be added to the slot.
106+
*
107+
* @return HTMLNode The method will return an object of type HTMLNode
108+
* that represents the added element.
109+
*/
110+
public function addItemSlot(string $slot , $el) : HTMLNode {
111+
return $this->addChild('template', [
112+
'#item.'.$slot
113+
])->addChild($el);
99114
}
100115
/**
101116
* Sets the name of JavaScript function that will be get executed when

wfc/ui/vuetify/VIcon.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace wfc\ui\vuetify;
4+
5+
/**
6+
* A class that represents a v-icon vuetify element.
7+
*
8+
* @author i.binalshikh
9+
*/
10+
class VIcon extends \webfiori\ui\HTMLNode {
11+
/**
12+
* Creates new instance of the class.
13+
*
14+
* @param string $icon The name of material design icon.
15+
*
16+
* @param array $iconProps An optional array that holds properties of
17+
* the icon.
18+
*/
19+
public function __construct(string $icon = 'mdi-information', array $iconProps = []) {
20+
parent::__construct($icon, $iconProps);
21+
$this->text($icon);
22+
}
23+
/**
24+
* Sets the icon that will be shown by the element.
25+
*
26+
* @param string $icon The name of a material design icon such as 'mdi-eye'.
27+
* The 'mdi' part can be omitted of the name as it is optional.
28+
*/
29+
public function setIcon(string $icon) {
30+
$sub = substr($icon, 0, 3);
31+
32+
if ($sub !== 'mdi') {
33+
$icon = 'mdi-'.$icon;
34+
}
35+
36+
$this->getChild(0)->setText($icon);
37+
}
38+
}

0 commit comments

Comments
 (0)