-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Stroud
committed
Apr 29, 2017
1 parent
5ae00b5
commit 0ed8df4
Showing
7 changed files
with
1,691 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
|
||
/vendor/ |
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 |
---|---|---|
@@ -1,2 +1,56 @@ | ||
# classnames-php | ||
PHP port of classnames | ||
PHP port of the JavaScript classNames utility. https://github.com/JedWatson/classnames | ||
|
||
## Installation | ||
|
||
``` | ||
composer require cjstroud/classnames-php | ||
``` | ||
|
||
The classNames can be accessed anywhere. | ||
|
||
``` | ||
classNames('foo', ['bar' => true]); // 'foo bar' | ||
``` | ||
|
||
## Usage | ||
|
||
The `classNames` function takes any number of arguments which can be a string or array. | ||
When using an array, if the value associated with a given key is falsy, that key won't be included in the output. | ||
If no value is given the true is assumed. | ||
|
||
``` | ||
classNames('foo'); // 'foo' | ||
classNames(['foo' => true]); // 'foo' | ||
classNames('foo', ['bar' => false, 'baz' => true]); // 'foo baz' | ||
classNames(['foo', 'bar' => true]) // 'foo bar' | ||
// Falsy values get ignored | ||
classNames('foo', null, 0, false, 1); // 'foo 1' | ||
``` | ||
|
||
Objects and functions will be ignored, unless the object has __toString() function. | ||
If it does that will be called and the string value used. | ||
|
||
``` | ||
class ExampleObject { | ||
function __toString() | ||
{ | ||
return 'bar'; | ||
} | ||
} | ||
classNames('foo', function() {}, new stdClass(), new ExampleObject()); // 'foo bar' | ||
``` | ||
|
||
## Laravel Blade | ||
|
||
``` | ||
<div class="{{ classNames('foo', ['bar' => true]) }}"></div> | ||
<div class="foo bar"></div> | ||
``` | ||
|
||
## License | ||
|
||
[MIT](LICENSE). Copyright (c) 2017 Chris Stroud. |
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,20 @@ | ||
{ | ||
"name": "cjstroud/classnames-php", | ||
"description": "A simple PHP utility for conditionally joining classNames together", | ||
"require-dev": { | ||
"phpunit/phpunit": "^6.1" | ||
}, | ||
"license": "MIT", | ||
"autoload": { | ||
"files": [ | ||
"src/ClassNames.php" | ||
] | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Chris Stroud", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": {} | ||
} |
Oops, something went wrong.