|
1 | 1 | # PackageFactory.ColorHelper |
2 | | -## EEL Color Helper, implementing a fluent interface for color transformations |
| 2 | +## EEL Color Helper, for fluent color transformations and Fusion for rendering css custom properties |
3 | 3 |
|
4 | 4 | The package provides the `Color` helper that exposes the following methods to Fusion. |
| 5 | +The fusion prototype `PackageFactory.ColorHelper:CssVariables` allows to write sets of |
| 6 | +calculated color values as css custom properties. |
5 | 7 |
|
6 | 8 | ### Creating |
7 | 9 |
|
@@ -61,6 +63,58 @@ only render an alpha value if the color is transparent. |
61 | 63 | - `rgb = ${ Color.rgba(255,0,0).fadeout(50).rgb() }` >> rgba( 255, 0, 0, 0.5) |
62 | 64 | - `hsl = ${ Color.rgba(255,0,0).hsl() }` >> hsla( 0, 100%, 50%) |
63 | 65 |
|
| 66 | +### Rendering as Css Custom Properties |
| 67 | + |
| 68 | +The fusion prototype `PackageFactory.ColorHelper:CssVariables` allows to |
| 69 | +render DataStructures as CssVariables. This can be used for customizing |
| 70 | +css based on node properties as shown in the example below. |
| 71 | + |
| 72 | +#### `PackageFactory.ColorHelper:CssVariables` |
| 73 | + |
| 74 | +- `values` (`array<string>`, default: `Neos.Fusion:DataStructure`) the values to render as css variables |
| 75 | +- `mediaQuery` (`string`, default `null`) when given renders the css variables into a `@media ... {}` section |
| 76 | +- `selector` (`string`, default `:root`) : css-selector the variables are rendered for |
| 77 | + |
| 78 | +``` |
| 79 | +prototype(Vendor.Site:CssPoroperties) < prototype(Neos.Fusion:Component) { |
| 80 | +
|
| 81 | + renderer = Neos.Fusion:Tag |
| 82 | + tagName = 'script' |
| 83 | + content = Neos.Fusion:Join { |
| 84 | + |
| 85 | + // |
| 86 | + // based on the properties `font` and `bgColor` some |
| 87 | + // costom properties are prepared globally |
| 88 | + // |
| 89 | + |
| 90 | + base = PackageFactory.ColorHelper:CssVariables { |
| 91 | + values = Neos.Fusion:DataStructure { |
| 92 | + font = ${q(site).property('font')} |
| 93 | + bg = ${q(site).property('bgColor')} |
| 94 | + bg-lighter = ${Color.css(this.bg).lighten(20)} |
| 95 | + bg-transparent = ${Color.css(this.bg).lighten(20)} |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + // |
| 100 | + // based on the properties `bgColorMobile` additional css |
| 101 | + // properties are defined that will be rendered in mobile |
| 102 | + // breakpoints and override the other values |
| 103 | + // |
| 104 | +
|
| 105 | + mobile = PackageFactory.ColorHelper:CssVariables { |
| 106 | + mediaQuery = 'screem and (max-width: 600px)' |
| 107 | + values = Neos.Fusion:DataStructure { |
| 108 | + bg = ${q(site).property('bgColorMobile')} |
| 109 | + bg-lighter = ${Color.css(this.bg).lighten(20)} |
| 110 | + bg-transparent = ${Color.css(this.bg).lighten(20)} |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + ` |
| 115 | +} |
| 116 | +``` |
| 117 | + |
64 | 118 | ## Installation |
65 | 119 |
|
66 | 120 | PackageFactory.ColorHelper is available via packagist. Run `composer require packagefactory/colorhelper`. |
|
0 commit comments