PHP code example of madebyraygun / craft-component-library

1. Go to this page and download the library: Download madebyraygun/craft-component-library 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/ */

    

madebyraygun / craft-component-library example snippets


return [
    'browser' => [
      'enabled' => true,
      'ocs/index',
      'preview' => '@preview',
    ]
    'root' => dirname(__DIR__) . '/library',
    'docs' => dirname(__DIR__) . '/library/docs',
    'aliases' => [
        '@elements' => '02-elements',
        '@modules' => '03-modules',
    ]
];

'aliases' => [
    '@button' => 'elements/button',
]

'aliases' => [
    '@atoms' => '01-atoms',
    '@molecules' => '02-molecules',
    '@organisms' => '03-organisms'
]

return [
  'title' => 'Button', // Custom title for the component
  'hidden' => false, // Hides the component
  'preview' => '@preview', // The template to render the component
  'context' => [
    'text' => 'Lorem Ipsum Dolor',
    'class' => 'is-primary',
  ],
]

return [
  'context' => [
    'ctaText' => 'Lorem ipsum dolor sit amet',
    'button' => '@button', //pulls in the entire @button context
  ]
]

return [
  'context' => [
    'ctaText' => 'Lorem ipsum dolor sit amet',
    'button' => [
      'text' => 'Custom text',
      'class' => '@button.class' //pulls in just class value from the button component 
    ]
  ]
]

 

use Faker\Factory as Faker;
$faker = Faker::create();

$tagClassMap = [
	'h1' => 'heading-1',
	'h2' => 'heading-2',
	'h3' => 'heading-3',
	'h4' => 'heading-4',
];

$variants = [];

foreach ($tagClassMap as $level => $class) {
	$variants[] = [
		'name' => $level,
		'context' => [
			'level' => $level,
			'class' => $class,
			'text' => $faker->sentence()
		]
	];
}

$first = array_shift($variants);

return [
	'name' => $first['name'],
	'context' => $first['context'],
	'variants' => $variants
];

return [
  'preview' => '@preview',
  'context' => ...
]

return [
  'hidden' => true,
  'context' => ...
]

  
namespace modules\pagecontext\components;

use Craft;

class HomepageEntryContext
{

  public static function Hook() 
  {

    Craft::$app->view->hook('homepage-entry-context', function(array &$context) {
    $context['homepage_entry_context'] = [
      'banner' => self::GetBanner($context['entry']),
      'pageContent' => self::GetPageContent($context['entry'])
    ];
  });
}
...

.
└── library/
    └── button/
        └── button.twig
        └── button.config.php
    └── cta/
        └── cta.twig
        └── cta.config.php