andrey-helldar/which-color

A simple helper, helping to determine what color the text will look better over a monotonous color.

v2.0.1 2020-12-30 19:47 UTC

This package is auto-updated.

Last update: 2021-11-29 20:12:49 UTC


README

Which Color

A simple helper, helping to determine what color the text will look better over a monotonous color.

StyleCI Status Github Workflow Status Stable Version Unstable Version Total Downloads License

Installation

To get the latest version of package, simply require the project using Composer:

composer require andrey-helldar/which-color

Instead, you may of course manually update your require section and run composer update if you so choose:

{
    "require": {
        "andrey-helldar/which-color": "^2.0"
    }
}

The package can be used without any problems without any framework, connecting the necessary files through the function require.

Upgrade from 1.x

In the file composer.json, replace "andrey-helldar/black-or-white-text-color": "^1.0" with "andrey-helldar/which-color": "^2.0" and call the composer update command.

If you are referring to classes, change the namespace from Helldar\BlackOrWhiteTextColor to Helldar\WhichColor.

Replace using the black_is_better_text_color() and black_is_better() helper with the following code:

use Helldar\WhichColor\Services\Color;

return (new Color('#ffffff'))->isDark();

Using

The package helps to determine what color it is better to write text over a monotonous color.

use Helldar\WhichColor\Services\Color;

return (new Color('#000000'))->isLight(); // returned `TRUE`. 'A white text color is better for black background'
return (new Color('#ffffff'))->isDark(); // returned `TRUE`. 'A black text color is better for white background'

return (new Color())->of('#000000')->isLight(); // returned `TRUE`. 'A white text color is better for black background'
return (new Color())->of('#ffffff')->isDark(); // returned `TRUE`. 'A black text color is better for white background'

Laravel / Lumen Frameworks

Inside Laravel or Lumen applications, you can use the Color facade:

use Helldar\WhichColor\Facades\Color;

$color = Color::of('#000000');
$color->isLight(); // returned `TRUE`. 'A light text color is better for dark background'
$color->isDark(); // returned `FALSE`. 'A dark text color is better for light background'

$color = Color::of('#ffffff')->isDark();
$color->isLight(); // returned `TRUE`. 'A dark text color is better for light background'
$color->isDark(); // returned `TRUE`. 'A light text color is better for dark background'

Color map

map of colors

License

This package is licensed under the MIT License.