Skip to content

Commit

Permalink
Merge pull request #17 from bummzack/fix-readme
Browse files Browse the repository at this point in the history
Updated readme for 4.x
  • Loading branch information
Damian Mooyman authored May 5, 2017
2 parents 5b819dd + 56b66f2 commit fa547b2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
The ColorPicker Module adds a color-picker input field to the SilverStripe CMS. It makes use of the ColorPicker jQuery
Plugin.

## Requirements

SilverStripe Framework v4+

For a Version that is compatible to SilverStripe 3+, consider using the [3.0 release](https://github.com/tractorcow/silverstripe-colorpicker/releases/tag/3.0.0)

## Installation

* Extract all files into the 'colorpicker' folder under your Silverstripe root, or install using composer
Install using composer

```bash
composer require "tractorcow/silverstripe-colorpicker" "3.0.*@dev"
composer require tractorcow/silverstripe-colorpicker ^4@dev
```

## Usage
Expand All @@ -17,7 +23,7 @@ Here's how you define a DB field to be a color:

```php
private static $db = array(
'BgColor' => 'Color'
'BgColor' => 'TractorCow\Colorpicker\Color'
);
```

Expand All @@ -32,7 +38,7 @@ public function getCMSFields()

$fields->addFieldToTab(
'Root.Main',
new ColorField('BgColor', 'Background color')
ColorField::create('BgColor', 'Background color')
);

return $fields;
Expand All @@ -41,7 +47,8 @@ public function getCMSFields()

### Tips for using the Color fieldtype in templates

The `Color` fieldtype provides some helper methods that can be useful in templating. Let's consider the above scenario where you have a Field named 'BgColor'. The most common use-case is something like this:
The `TractorCow\Colorpicker\Color` fieldtype provides some helper methods that can be useful in templating.
Let's consider the above scenario where you have a Field named 'BgColor'. The most common use-case is something like this:

```html
<body style="background-color: #$BgColor;">
Expand All @@ -64,6 +71,5 @@ Here's a complete list of the `Color` methods available in templates:
- `Blue` returns the blue color component
- `CSSColor` returns the color as `rgba`. The alpha value can be specified with the (optional) argument.
- `Luminance` the luminance of the color as a floating-point value ranging from 0-1
- `Blend` blends the color with a second background color (defaults to #FFFFFF) with the given opacity. `$BGColor.Blend(0.5, '#000000')` will give the color 50% opacity and put it on top of a black background.
- `AlteredColorHSV` modifies the current color by the given HSV values. These values are offsets, so you could do something like this: `$BgColor.AlteredColorHSV(0.5, 0, 0)` which will return the color with the opposite hue. All parameters are percentage based and range from `0 - 1`. So doing: `$BgColor.AlteredColorHSV(0, 0, -0.2)` will result in a color with 20% less brightness (absolute, not relative).


0 comments on commit fa547b2

Please # to comment.