Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
breadthe committed Feb 22, 2020
1 parent c5d0194 commit 7f53385
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.vscode
build
composer.lock
docs
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Provides various utilities for working with color contrast.

The primary purpose is to facilitate easy generation of accessible (minimum 3.0 contrast ratio) hex color pairs. A variation of these tools restricts the generated colors to [TailwindCSS's](https://tailwindcss.com/) default palette.

I've created a [demo page](https://mumu.pw/contrast) to show how color pairs can be generated by this package.

## Installation

You can install the package via composer:
Expand All @@ -22,15 +24,17 @@ composer require breadthe/php-contrast
Import the class.

```php
use Breadthe\PhpContrast\HexColor;
use Breadthe\PhpContrast\HexColorPair;
use Breadthe\PhpContrast\TailwindColor;
use Breadthe\PhpContrast\HexColor; // factory

use Breadthe\PhpContrast\HexColorPair; // hex pair utilities

use Breadthe\PhpContrast\TailwindColor; // Tailwind color pair utilities
```

## Check the contrast ratio between 2 colors

```php
$hexColorPair = HexColor::make(HexColor::make('000000'), HexColor::make('ffffff'));
$hexColorPair = HexColorPair::make(HexColor::make('000000'), HexColor::make('ffffff'));
$hexColorPair->ratio; // 21
$hexColorPair->fg; // '#000000'
$hexColorPair->bg; // '#ffffff'
Expand Down Expand Up @@ -66,10 +70,10 @@ $hexColorPair->bg->name; // null

```php
// Minimum 3:1 contrast ratio
HexColorPair::sibling('0000000'); // [21, '0000000', 'ffffff']
HexColorPair::sibling('000000'); // [21, '000000', 'ffffff']

// Minimum specified contrast ratio (no less than 3:1)
HexColorPair::minContrast(4.5)->getSibling('0000000'); // [21, '0000000', 'ffffff']
HexColorPair::minContrast(4.5)->getSibling('000000'); // [21, '000000', 'ffffff']
```

## Generate a random TailwindCSS color
Expand Down

0 comments on commit 7f53385

Please sign in to comment.