diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..05a23c2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 izica + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/PhpStyles.php b/PhpStyles.php new file mode 100644 index 0000000..651a56d --- /dev/null +++ b/PhpStyles.php @@ -0,0 +1,110 @@ +classname = uniqid('php-styles-'); + + $array = []; + foreach ($this->styles as $key => $value) { + $array[$key] = $key . ': ' . $value; + } + $css = implode(';', $array); + echo ""; + + return $this->classname; + } + + /** + * @return string + */ + public function media($minWidth = 0, $maxWidth = 9999) + { + $this->media = true; + $this->mediaFrom =$minWidth; + $this->mediaTo = $maxWidth; + return $this; + } + + /** + * @param $key + * @param $value + * @param $condition + * @return $this + */ + public function set($key, $value, $condition = true) + { + if ($condition) { + $this->styles[$key] = $value; + } + return $this; + } + + /** + * @param $value + * @param $condition + * @return $this + */ + public function opacity($value, $condition) + { + return $this->set('opacity', $value, $condition); + } +} + +/** + * Class PhpStyles + */ +class PhpStylesInline extends PhpStyles +{ + public function render($condition = true) + { + if (!$condition) { + return ''; + } + + $css = ''; + $array = []; + foreach ($this->styles as $key => $value) { + $array[$key] = $key . ': ' . $value; + } + $css = implode(';', $array); + return "style='{$css}'"; + } +} diff --git a/PhpStylesInline.php b/PhpStylesInline.php new file mode 100644 index 0000000..45ed1be --- /dev/null +++ b/PhpStylesInline.php @@ -0,0 +1,23 @@ +styles as $key => $value) { + $array[$key] = $key . ': ' . $value; + } + $css = implode(';', $array); + return "style='{$css}'"; + } +} diff --git a/README.md b/README.md index 643f4c8..ce28fa2 100644 --- a/README.md +++ b/README.md @@ -1 +1,50 @@ -# php-css-styles \ No newline at end of file +![browser screen](https://raw.githubusercontent.com/izica/php-browser-log/master/screen.png "browser screen") +## Install +``` +composer require izica/php-styles +``` + +## Usage +generate inline tag style +```php + $sStyles = (new PhpStylesInline())->opacity(0, $sContact == '')->render(); + or + $sStyles = styles(true)->opacity(0, $sContact == '')->render(); + or + $sStyles = styles()->inline->opacity(0, $sContact == '')->render(); +``` +insert style +```html +
> + +
+``` + +generate style with class(class styles supports media query) +```php + $sClassname = (new PhpStyles())->media(0, 1024)->opacity(0, $sContact == '')->render(); + or + $sClassname = styles()->media(0, 1024)->opacity(0, $sContact == '')->render(); +``` + +insert style +```html +
+ +
+``` + +## Documentation +* styles() - returns PhpStyles +* styles(true) - returns PhpStylesInline +* PhpStyles + * inline() - returns PhpStyles + * media(sizeFrom: number, sizeTo: number) + * set(key: string, value: string or number, condition: bool(not required)) - returns $this(if condition == false, not set) + * render(condition: bool(not required))- returns unique class name(if condition == false, returns empty string) + * opacity(value, condition(not required)) +* PhpStylesInline + * media(sizeFrom: number, sizeTo: number) + * set(key: string, value: string or number, condition: bool(not required)) - returns $this(if condition == false, not set) + * render(condition: bool(not required))- returns unique class name(if condition == false, returns empty string) + * opacity(value, condition(not required)) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..5d8f7ff --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "izica/php-styles", + "description": "inline css styles generator(conditions support)", + "authors": [ + { + "name": "Golovarchuk Artyom", + "email": "artemiztomska@gmail.com" + } + ], + "keywords": ["css", "php", "css-inline", "generator", "styles"], + "license": "MIT", + "require": { + "php": ">=5.6.0" + }, + "autoload": { + "classmap": [ + "PhpStyles.php", + "PhpStylesInline.php" + ], + "files": [ + "styles.php" + ] + } +} diff --git a/styles.php b/styles.php new file mode 100644 index 0000000..3804919 --- /dev/null +++ b/styles.php @@ -0,0 +1,14 @@ +