|
1 | 1 | # PackageFactory.ColorHelper |
2 | | -## EEL Color Helper, for fluent color transformations and Fusion for rendering css custom properties |
3 | 2 |
|
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. |
| 3 | +The package provides the Fusion Prototype `Vendor.Site:CustomCssProperties` |
| 4 | +for rendering css custom-properties together with an EEL `Color` Helper that |
| 5 | +provides an interface for fluent color transformations. |
| 6 | + |
| 7 | +``` |
| 8 | +prototype(Vendor.Site:CustomCssProperties) < prototype(Neos.Fusion:Component) { |
| 9 | +
|
| 10 | + renderer = Neos.Fusion:Tag |
| 11 | + tagName = 'script' |
| 12 | + content = Neos.Fusion:Join { |
| 13 | + |
| 14 | + // |
| 15 | + // based on the properties `font` and `bgColor` some |
| 16 | + // costom properties are prepared globally |
| 17 | + // |
| 18 | + |
| 19 | + base = PackageFactory.ColorHelper:CssVariables { |
| 20 | + values = Neos.Fusion:DataStructure { |
| 21 | + font = ${q(site).property('font')} |
| 22 | + bg = ${q(site).property('bgColor')} |
| 23 | + bg-lighter = ${Color.css(this.bg).lighten(20)} |
| 24 | + bg-transparent = ${Color.css(this.bg).fadeout(20)} |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + // |
| 29 | + // based on the properties `bgColorMobile` additional css |
| 30 | + // properties are defined that will be rendered in mobile |
| 31 | + // breakpoints and override the other values |
| 32 | + // |
| 33 | +
|
| 34 | + mobile = PackageFactory.ColorHelper:CssVariables { |
| 35 | + mediaQuery = 'screen and (max-width: 600px)' |
| 36 | + values = Neos.Fusion:DataStructure { |
| 37 | + bg = ${q(site).property('bgColorMobile')} |
| 38 | + bg-lighter = ${Color.css(this.bg).lighten(20)} |
| 39 | + bg-transparent = ${Color.css(this.bg).fadeout(20)} |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + ` |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +## Rendering as Css Custom Properties |
| 48 | + |
| 49 | +The fusion prototype `PackageFactory.ColorHelper:CssVariables` allows to |
| 50 | +render DataStructures as CssVariables. This can be used for customizing |
| 51 | +css based on node properties as shown in the example below. |
| 52 | + |
| 53 | +#### `PackageFactory.ColorHelper:CssVariables` |
| 54 | + |
| 55 | +- `values` (`array<string>`, default: `Neos.Fusion:DataStructure`) the values to render as css variables |
| 56 | +- `mediaQuery` (`string`, default `null`) when given renders the css variables into a `@media ... {}` section |
| 57 | +- `selector` (`string`, default `:root`) : css-selector the variables are rendered for |
| 58 | + |
| 59 | +## Handling colors with EEL |
7 | 60 |
|
8 | 61 | ### Creating |
9 | 62 |
|
@@ -63,58 +116,6 @@ only render an alpha value if the color is transparent. |
63 | 116 | - `rgb = ${ Color.rgba(255,0,0).fadeout(50).rgb() }` >> rgba( 255, 0, 0, 0.5) |
64 | 117 | - `hsl = ${ Color.rgba(255,0,0).hsl() }` >> hsla( 0, 100%, 50%) |
65 | 118 |
|
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:CustomCssProperties) < 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).fadeout(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 = 'screen 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).fadeout(20)} |
111 | | - } |
112 | | - } |
113 | | - } |
114 | | - ` |
115 | | -} |
116 | | -``` |
117 | | - |
118 | 119 | ## Installation |
119 | 120 |
|
120 | 121 | PackageFactory.ColorHelper is available via packagist. Run `composer require packagefactory/colorhelper`. |
|
0 commit comments