|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AppUtils\StyleCollection\StyleBuilder; |
|
6
|
|
|
|
|
7
|
|
|
use AppUtils\RGBAColor; |
|
8
|
|
|
use AppUtils\RGBAColor\ColorException; |
|
9
|
|
|
use AppUtils\RGBAColor\ColorFactory; |
|
10
|
|
|
use AppUtils\StyleCollection\StyleBuilder; |
|
11
|
|
|
|
|
12
|
|
|
abstract class ColorContainer extends StyleContainer |
|
13
|
|
|
{ |
|
14
|
|
|
public function rgbaValues(int $red, int $green, int $blue, float $opacity=1) : StyleBuilder |
|
15
|
|
|
{ |
|
16
|
|
|
return $this->rgba(ColorFactory::createCSS($red, $green, $blue, $opacity)); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function rgba(RGBAColor $color, bool $important=false) : StyleBuilder |
|
20
|
|
|
{ |
|
21
|
|
|
return $this->setStyle($color->toCSS(), $important); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function hex(RGBAColor $color, bool $important=false) : StyleBuilder |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->setStyle('#'.$color->toHEX(), $important); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Uses a HEX color value string. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $hex The color, e.g. "fff", "FAFAFA", or with alpha channel "CCCCCCAA" |
|
33
|
|
|
* @param bool $important |
|
34
|
|
|
* @return StyleBuilder |
|
35
|
|
|
* @throws ColorException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function hexString(string $hex, bool $important=false) : StyleBuilder |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->hex(ColorFactory::createFromHEX($hex), $important); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function transparent() : StyleBuilder |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->rgba(ColorFactory::preset()->transparent()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function white() : StyleBuilder |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->rgba(ColorFactory::preset()->white()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function black() : StyleBuilder |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->rgba(ColorFactory::preset()->black()); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|