Completed
Push — master ( 424d4e...c1a616 )
by Jean-Christophe
03:24
created

HtmlButton::setEmphasis()   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\elements;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\base\traits\LabeledIconTrait;
7
use Ajax\semantic\html\base\constants\Emphasis;
8
9
/**
10
 * Semantic Button component
11
 * @see http://semantic-ui.com/elements/button.html
12
 * @author jc
13
 * @version 1.001
14
 */
15
class HtmlButton extends HtmlSemDoubleElement {
16
	use LabeledIconTrait;
17
	/**
18
	 * Constructs an HTML Semantic button
19
	 * @param string $identifier HTML id
20
	 * @param string $value value of the Button
21
	 * @param string $cssStyle btn-default, btn-primary...
22
	 * @param string $onClick JS Code for click event
23
	 */
24 View Code Duplication
	public function __construct($identifier, $value="", $cssStyle=null, $onClick=null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
		parent::__construct($identifier, "button","ui button");
26
		$this->content=$value;
27
		if (isset($cssStyle)) {
28
			$this->setStyle($cssStyle);
29
		}
30
		if (isset($onClick)) {
31
			$this->onClick($onClick);
32
		}
33
	}
34
35
	/**
36
	 * Set the button value
37
	 * @param string $value
38
	 * @return \Ajax\semantic\html\HtmlButton
39
	 */
40
	public function setValue($value) {
41
		$this->content=$value;
42
		return $this;
43
	}
44
45
	/**
46
	 * define the button style
47
	 * @param string|int $cssStyle
48
	 * @return \Ajax\semantic\html\HtmlButton default : ""
49
	 */
50
	public function setStyle($cssStyle) {
51
		return $this->addToProperty("class",$cssStyle);
52
	}
53
54
	public function setFocusable($value=true){
55
		if($value===true)
56
			$this->setProperty("tabindex", "0");
57
		else{
58
			$this->removeProperty("tabindex");
59
		}
60
		return $this;
61
	}
62
63
	public function setAnimated($content,$animation=""){
64
		$this->setTagName("div");
65
		$this->addToProperty("class", "animated ".$animation);
66
		$visible=new HtmlSemDoubleElement("visible-".$this->identifier,"div");
67
		$visible->setClass("visible content");
68
		$visible->setContent($this->content);
69
		$hidden=new HtmlSemDoubleElement("hidden-".$this->identifier,"div");
70
		$hidden->setClass("hidden content");
71
		$hidden->setContent($content);
72
		$this->content=$visible.$hidden;
73
	}
74
75
	/**
76
	 * @param string|HtmlIcon $icon
77
	 * @return \Ajax\semantic\html\elements\HtmlButton
78
	 */
79
	public function asIcon($icon){
80
		$iconO=$icon;
81
		if(\is_string($icon)){
82
			$iconO=new HtmlIcon("icon-".$this->identifier, $icon);
83
		}
84
		$this->addToProperty("class", "icon");
85
		$this->content=$iconO;
86
		return $this;
87
	}
88
89
	/**
90
	 * Add and return a button label
91
	 * @param string $caption
92
	 * @param string $before
93
	 * @return \Ajax\semantic\html\elements\HtmlLabel
94
	 */
95
	public function addLabel($caption,$before=false){
96
		$this->tagName="div";
97
		$this->addToProperty("class", "labeled");
98
		$this->content=new HtmlButton("button-".$this->identifier,$this->content);
99
		$this->content->setTagName("div");
100
		$label=new HtmlLabel("label-".$this->identifier,$caption,"a");
101
		$label->setBasic();
102
		$this->addContent($label,$before);
0 ignored issues
show
Bug introduced by
It seems like $before defined by parameter $before on line 95 can also be of type string; however, Ajax\common\html\HtmlDoubleElement::addContent() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
103
		return $label;
104
	}
105
	/*
106
	 * (non-PHPdoc)
107
	 * @see \Ajax\common\html\BaseHtml::fromArray()
108
	 */
109
	public function fromArray($array) {
110
		$array=parent::fromArray($array);
111
		foreach ( $array as $key => $value ) {
112
			$this->setProperty($key, $value);
113
		}
114
		return $array;
115
	}
116
117
	/**
118
	 *  show it is currently the active user selection
119
	 * @return \Ajax\semantic\html\elements\HtmlButton
120
	 */
121
	public function setActive(){
122
		return $this->addToProperty("class", "active");
123
	}
124
125
	/**
126
	 * hint towards a positive consequence
127
	 * @return \Ajax\semantic\html\elements\HtmlButton
128
	 */
129
	public function setPositive(){
130
		return $this->addToProperty("class", "positive");
131
	}
132
133
	/**
134
	 * hint towards a negative consequence
135
	 * @return \Ajax\semantic\html\elements\HtmlButton
136
	 */
137
	public function setNegative(){
138
		return $this->addToProperty("class", "negative");
139
	}
140
141
	/**
142
	 * formatted to toggle on/off
143
	 * @return \Ajax\semantic\html\elements\HtmlButton
144
	 */
145
	public function setToggle(){
146
		return $this->addToProperty("class", "toggle");
147
	}
148
149
	/**
150
	 * @return \Ajax\semantic\html\elements\HtmlButton
151
	 */
152
	public function setCircular(){
153
		return $this->addToProperty("class", "circular");
154
	}
155
156
	/**
157
	 *  button is less pronounced
158
	 * @return \Ajax\semantic\html\elements\HtmlButton
159
	 */
160
	public function setBasic(){
161
		return $this->addToProperty("class", "basic");
162
	}
163
164
	public function setEmphasis($value){
165
		return $this->addToPropertyCtrl("class", $value, Emphasis::getConstants());
166
	}
167
}