Completed
Push — master ( b4ccca...781bd5 )
by Jean-Christophe
03:50
created

HtmlInput::outline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
1
<?php
2
3
namespace Ajax\semantic\html\elements;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\base\constants\State;
7
use Ajax\semantic\html\base\constants\Direction;
8
use Ajax\semantic\html\base\constants\Variation;
9
use Ajax\semantic\html\base\traits\IconTrait;
10
11
class HtmlInput extends HtmlSemDoubleElement {
12
	use IconTrait;
13
14
	public function __construct($identifier, $type="text", $value="", $placeholder="") {
15
		parent::__construct("div-" . $identifier, "div", "ui input");
16
		$this->content=[ "field" => new \Ajax\common\html\html5\HtmlInput($identifier, $type, $value, $placeholder) ];
17
		$this->_states=[ State::DISABLED,State::FOCUS,State::ERROR ];
18
		$this->_variations=[ Variation::TRANSPARENT ];
19
	}
20
21
	public function setFocus() {
22
		$this->addToProperty("class", State::FOCUS);
23
	}
24
25
	public function addLoading() {
26
		if ($this->_hasIcon === false) {
27
			throw new \Exception("Input must have an icon for showing a loader, use addIcon before");
28
		}
29
		return $this->addToProperty("class", State::LOADING);
30
	}
31
32
	public function labeled($label, $direction=Direction::LEFT, $icon=NULL) {
33
		$labelO=$label;
34
		if (\is_object($label) === false) {
35
			$labelO=new HtmlLabel("label-" . $this->identifier, $label);
36
			if (isset($icon))
37
				$labelO->addIcon($icon);
38
		} else {
39
			$labelO->addToPropertyCtrl("class", "label", array ("label" ));
40
		}
41
		$this->addToProperty("class", $direction . " labeled");
42
		$this->addContent($labelO, \strstr($direction, Direction::LEFT) !== false);
43
		return $labelO;
44
	}
45
46
	public function labeledToCorner($label, $direction=Direction::LEFT, $icon=NULL) {
47
		return $this->labeled($label, $direction . " corner", $icon)->toCorner($direction);
48
	}
49
50
	public function addAction($action, $direction=Direction::LEFT, $icon=NULL, $labeled=false) {
51
		$actionO=$action;
52
		if (\is_object($action) === false) {
53
			$actionO=new HtmlButton("action-" . $this->identifier, $action);
54
			if (isset($icon))
55
				$actionO->addIcon($icon, true, $labeled);
56
		}
57
		$this->addToProperty("class", $direction . " action");
58
		$this->addContent($actionO, \strstr($direction, Direction::LEFT) !== false);
59
		return $actionO;
60
	}
61
62
	public function getField() {
63
		return $this->content["field"];
64
	}
65
66
	public function setPlaceholder($value) {
67
		$this->getField()->setPlaceholder($value);
68
		return $this;
69
	}
70
71
	public function setTransparent() {
72
		return $this->addToProperty("class", "transparent");
73
	}
74
75
	public static function outline($identifier, $icon, $value="", $placeholder="") {
76
		$result=new HtmlInput($identifier, "text", $value, $placeholder);
77
		$result->addToProperty("class", "transparent");
78
		$result->addIcon($icon)->setOutline();
79
		return $result;
80
	}
81
}