PHP code example of brickrouge / css-class-names

1. Go to this page and download the library: Download brickrouge/css-class-names library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brickrouge / css-class-names example snippets




namespace Brickrouge;

$class_names = [

	'node-id' => 'node-id-13',
	'node-slug' => 'node-slug-example',
	'is-active' => true,
	'is-disabled' => false

];

render_css_class($class_names)
// "node-id-13 node-slug-example is-active"
render_css_class($class_names, [ 'node-id', 'is-active', 'is-disabled' ]);
// "node-id-13 is-active"
render_css_class($class_names, 'node-id is-active is-disabled');
// "node-id-13 is-active"
render_css_class($class_names, [ '-node-id', '-node-slug' ]);
// "is-active"
render_css_class($class_names, '-node-id -node-slug');
// "is-active"



namespace Icybee\Modules\Nodes;

use Brickrouge\CSSClassNames;
use Brickrouge\CSSClassNamesProperty;

// …

class Node extends ActiveRecord implements CSSClassNames
{
	use CSSClassNamesProperty;

	// …

	/**
	 * Returns the CSS class names of the node.
	 *
	 * @return array[string]mixed
	 */
	protected function get_css_class_names()
	{
		$nid = $this->nid;
		$slug = $this->slug;

		return [

			'type' => 'node',
			'id' => $nid ? "node-{$nid}" : null,
			'slug' => $slug ? "node-slug-{$slug}" : null,
			'constructor' => 'constructor-' . \ICanBoogie\normalize($this->constructor)

		];
	}
}



// …

$node->css_class;
// node node-123 node-slug-example constructor-nodes
$node->css_class_names;
// [ 'type' => node, 'id' => 'node-123', 'slug' => 'node-slug-example', 'constructor' => 'constructor-nodes' ]
$node->css_class('-slug -constructor');
// node node-123
$node->css_class('id slug');
// node-123 node-slug-example