Completed
Push — master ( ea2a7d...e9bdcb )
by Jean-Christophe
03:40
created

BaseTrait::setFloated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\base\traits;
4
5
use Ajax\semantic\html\base\constants\Size;
6
use Ajax\semantic\html\base\constants\Color;
7
use Ajax\semantic\html\base\constants\Direction;
8
9
trait BaseTrait {
10
	protected $_variations=[ ];
11
	protected $_states=[ ];
12
	protected $_baseClass;
13
14
	protected abstract function setPropertyCtrl($name, $value, $typeCtrl);
15
16
	protected abstract function addToPropertyCtrl($name, $value, $typeCtrl);
17
18
	protected abstract function addToPropertyCtrlCheck($name, $value, $typeCtrl);
19
20
	public abstract function addToProperty($name, $value, $separator=" ");
21
22
	public function addVariation($variation) {
23
		return $this->addToPropertyCtrlCheck("class", $variation, $this->_variations);
24
	}
25
26
	public function addState($state) {
27
		return $this->addToPropertyCtrlCheck("class", $state, $this->_states);
28
	}
29
30
	public function setVariation($variation) {
31
		$this->setPropertyCtrl("class", $variation, $this->_variations);
32
		return $this->addToProperty("class", $this->_baseClass);
33
	}
34
35
	public function setState($state) {
36
		$this->setPropertyCtrl("class", $state, $this->_states);
37
		return $this->addToProperty("class", $this->_baseClass);
38
	}
39
40
	public function addVariations($variations=array()) {
41
		if (\is_string($variations))
42
			$variations=\explode(" ", $variations);
43
		foreach ( $variations as $variation ) {
44
			$this->addVariation($variation);
45
		}
46
		return $this;
47
	}
48
49
	public function addStates($states=array()) {
50
		if (\is_string($states))
51
			$states=\explode(" ", $states);
52
		foreach ( $states as $state ) {
53
			$this->addState($state);
54
		}
55
		return $this;
56
	}
57
58
	/**
59
	 *
60
	 * {@inheritDoc}
61
	 *
62
	 * @see \Ajax\common\html\HtmlSingleElement::setSize()
63
	 */
64
	public function setSize($size) {
65
		return $this->addToPropertyCtrl("class", $size, Size::getConstants());
66
	}
67
68
	/**
69
	 * show it is currently unable to be interacted with
70
	 * @return \Ajax\semantic\html\elements\HtmlSemDoubleElement
71
	 */
72
	public function setDisabled() {
73
		return $this->addToProperty("class", "disabled");
74
	}
75
76
	/**
77
	 *
78
	 * @param string $color
79
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
80
	 */
81
	public function setColor($color) {
82
		return $this->addToPropertyCtrl("class", $color, Color::getConstants());
83
	}
84
85
	/**
86
	 *
87
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
88
	 */
89
	public function setFluid() {
90
		return $this->addToProperty("class", "fluid");
91
	}
92
93
	/**
94
	 * can be formatted to appear on dark backgrounds
95
	 */
96
	public function setInverted() {
97
		return $this->addToProperty("class", "inverted");
98
	}
99
100
	public function setCircular() {
101
		return $this->addToProperty("class", "circular");
102
	}
103
104
	public function setFloated($direction="right") {
105
		return $this->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated"));
106
	}
107
108
	public function floatRight() {
109
		return $this->setFloated();
110
	}
111
112
	public function floatLeft() {
113
		return $this->setFloated("left");
114
	}
115
}