PHP code example of artisanpack-ui / accessibility
1. Go to this page and download the library: Download artisanpack-ui/accessibility 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/ */
artisanpack-ui / accessibility example snippets
// app/View/Components/Button.php
namespace App\View\Components;
use Illuminate\View\Component;
class Button extends Component
{
public string $bgColor;
public string $textColor;
public function __construct(string $bgColor = '#3b82f6')
{
$this->bgColor = $bgColor;
$this->textColor = a11yGetContrastColor($this->bgColor);
}
public function render()
{
return view('components.button');
}
}
// Force AAA thresholds everywhere.
addFilter('ap.accessibility.contrastThreshold', fn (float $ratio, string $context) => match ($context) {
'aa', 'aaa' => 7.0,
'aa-large', 'aaa-large' => 4.5,
default => $ratio,
});
// Add brand colors that the Tailwind palette does not cover.
addFilter('ap.accessibility.contrastColorMap', function (array $map) {
$map['brand-primary'] = '#123456';
return $map;
});
// Force a specific text color for a specific background.
addFilter('ap.accessibility.textColorGenerated', function (string $color, string $background, bool $tinted) {
return $background === '#123456' ? '#fefefe' : $color;
});