Skip to content

Commit 1d68e42

Browse files
committed
FEATURE: Add fusion prototype PackageFactory.ColorHelper:CssVariables
The fusion prototype `PackageFactory.ColorHelper:CssVariables` allows to render DataStructures as CssVariables. This can be used for customizing css based on node properties as shown in the example below. `PackageFactory.ColorHelper:CssVariables` - `values` (`array<string>`, default: `Neos.Fusion:DataStructure`) the values to render as css variables - `mediaQuery` (`string`, default `null`) when given renders the css variables into a `@media ... {}` section - `selector` (`string`, default `:root`) : css-selector the variables are rendered for
1 parent 1408aad commit 1d68e42

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

Configuration/Settings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ Neos:
22
Fusion:
33
defaultContext:
44
Color: 'PackageFactory\ColorHelper\Eel\ColorBuilder'
5+
Neos:
6+
fusion:
7+
autoInclude:
8+
PackageFactory.ColorHelper: true

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# 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
33

44
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.
57

68
### Creating
79

@@ -61,6 +63,58 @@ only render an alpha value if the color is transparent.
6163
- `rgb = ${ Color.rgba(255,0,0).fadeout(50).rgb() }` >> rgba( 255, 0, 0, 0.5)
6264
- `hsl = ${ Color.rgba(255,0,0).hsl() }` >> hsla( 0, 100%, 50%)
6365

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+
64118
## Installation
65119

66120
PackageFactory.ColorHelper is available via packagist. Run `composer require packagefactory/colorhelper`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
prototype(PackageFactory.ColorHelper:CssVariables) < prototype(Neos.Fusion:Component) {
2+
3+
mediaQuery = null
4+
selector = ':root'
5+
values = Neos.Fusion:DataStructure
6+
7+
renderer = Neos.Fusion:Loop {
8+
items = ${props.values}
9+
itemName = "value"
10+
itemKey = "key"
11+
itemRenderer = ${'--' + key + ':' + value + ';'}
12+
13+
@process.wrapInSelector = ${props.selector + ' { ' + value + ' } '}
14+
@process.wrapInMediaQuery = ${'@media ' + props.mediaQuery + ' { ' + value + ' } '}
15+
@[email protected] = ${props.mediaQuery}
16+
}
17+
}

0 commit comments

Comments
 (0)