Skip to content

Commit 1d8d13e

Browse files
committed
add Toast
1 parent 905fb3f commit 1d8d13e

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

Ajax/semantic/components/Toast.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Ajax\semantic\components;
4+
5+
use Ajax\JsUtils;
6+
7+
class Toast extends SimpleSemExtComponent {
8+
9+
public function __construct(JsUtils $js) {
10+
parent::__construct($js);
11+
$this->uiName="toast";
12+
}
13+
14+
protected function setBehavior($name) {
15+
$this->paramParts[]=[$name];
16+
return $this;
17+
}
18+
19+
public function showDimmer(){
20+
return $this->setBehavior("hide dimmer");
21+
}
22+
23+
public function setCloseIcon(){
24+
$this->params["closeIcon"]=true;
25+
}
26+
27+
public function setDisplayTime($time){
28+
$this->params["displayTime"]=$time;
29+
}
30+
31+
public function setOnHide($jsCode) {
32+
$jsCode=str_ireplace("\"","%quote%", $jsCode);
33+
return $this->setParam("onHide", "%function(){".$jsCode."}%");
34+
}
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Ajax\semantic\html\modules;
3+
4+
use Ajax\semantic\html\base\HtmlSemDoubleElement;
5+
use Ajax\JsUtils;
6+
use Ajax\service\JArray;
7+
8+
class HtmlToast extends HtmlSemDoubleElement {
9+
10+
protected $_params=array();
11+
protected $_paramParts=array();
12+
public function __construct($identifier, $content="") {
13+
parent::__construct($identifier, "div","ui toast");
14+
if(isset($content)){
15+
$this->setContent($content);
16+
}
17+
}
18+
19+
public function setContent($value) {
20+
$this->content["content"]=new HtmlSemDoubleElement("content-" . $this->identifier, "div", "content", $value);
21+
return $this;
22+
}
23+
24+
/**
25+
*
26+
* {@inheritDoc}
27+
*
28+
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
29+
*/
30+
public function compile(JsUtils $js=NULL, &$view=NULL) {
31+
$this->content=JArray::sortAssociative($this->content, ["content","actions" ]);
32+
return parent::compile($js, $view);
33+
}
34+
/*
35+
* (non-PHPdoc)
36+
* @see BaseHtml::run()
37+
*/
38+
public function run(JsUtils $js) {
39+
if(isset($this->_bsComponent)===false)
40+
$this->_bsComponent=$js->semantic()->toast("#".$this->identifier,$this->_params,$this->_paramParts);
41+
$this->addEventsOnRun($js);
42+
return $this->_bsComponent;
43+
}
44+
}
45+

Ajax/semantic/traits/SemanticComponentsTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Ajax\semantic\components\Shape;
1919
use Ajax\semantic\components\Form;
2020
use Ajax\semantic\components\SimpleSemExtComponent;
21+
use Ajax\semantic\components\Toast;
2122

2223
/**
2324
* @author jc
@@ -167,5 +168,15 @@ public function form($attachTo=NULL, $params=NULL) {
167168
$result= $this->addComponent(new Form($this->js), $attachTo, $params);
168169
return $result;
169170
}
171+
172+
/**
173+
* @param string $attachTo
174+
* @param string|array $params
175+
* @return Toast
176+
*/
177+
public function toast($attachTo=NULL, $params=NULL) {
178+
$result= $this->addComponent(new Toast($this->js), $attachTo, $params);
179+
return $result;
180+
}
170181

171182
}

0 commit comments

Comments
 (0)