-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ucraft-com/added-breakpoint-media-query
Breakpoint media query
- Loading branch information
Showing
8 changed files
with
383 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CssGenerator\Decorators; | ||
|
||
use function implode; | ||
|
||
class BreakpointMediaQueryDecorator implements StyleDecoratorInterface | ||
{ | ||
/** | ||
* @var array|StyleDecorator[] | ||
*/ | ||
protected array $styles = []; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected bool $isDefault = false; | ||
|
||
/** | ||
* @var string @media query of breakpoint | ||
*/ | ||
protected string $mediaQuery = ''; | ||
|
||
/** | ||
* @var int ID of breakpoint. | ||
*/ | ||
protected int $id; | ||
|
||
/** | ||
* @param int $id | ||
* | ||
* @return void | ||
*/ | ||
public function setId(int $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param string $mediaQuery | ||
* | ||
* @return void | ||
*/ | ||
public function setMediaQuery(string $mediaQuery): void | ||
{ | ||
$this->mediaQuery = $mediaQuery; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMediaQuery(): string | ||
{ | ||
return $this->mediaQuery; | ||
} | ||
|
||
/** | ||
* @param bool $isDefault | ||
* | ||
* @return void | ||
*/ | ||
public function setIsDefault(bool $isDefault): void | ||
{ | ||
$this->isDefault = $isDefault; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isDefault(): bool | ||
{ | ||
return $this->isDefault; | ||
} | ||
|
||
/** | ||
* @param string $widgetId | ||
* @param \CssGenerator\Decorators\StyleDecorator $style | ||
* | ||
* @return void | ||
*/ | ||
public function addStyle(string $widgetId, StyleDecorator $style): void | ||
{ | ||
$this->styles[$widgetId][] = $style; | ||
} | ||
|
||
/** | ||
* Bring together already generated css blocks. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
$css = ''; | ||
if (!$this->isDefault) { | ||
$css .= $this->getMediaQuery(); | ||
} | ||
|
||
foreach ($this->styles as $styles) { | ||
$css .= implode('', $styles); | ||
} | ||
|
||
if (!$this->isDefault) { | ||
$css .= '}'; | ||
} | ||
|
||
return $css; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CssGenerator\Decorators; | ||
|
||
use function implode; | ||
|
||
/** | ||
* StylesheetMediaQuery contains breakpoints, and generates css with media queries. | ||
*/ | ||
class StylesheetMediaQuery implements StylesheetInterface | ||
{ | ||
/** | ||
* @var array<\CssGenerator\Decorators\BreakpointDecorator> | ||
*/ | ||
protected array $breakpoints = []; | ||
|
||
/** | ||
* @param array $breakpoints | ||
* | ||
* @return void | ||
*/ | ||
public function setBreakpoints(array $breakpoints): void | ||
{ | ||
$this->breakpoints = $breakpoints; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function generate(): array | ||
{ | ||
return ['default breakpoint id' => implode('', $this->breakpoints)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.