Skip to content

Commit 220aa06

Browse files
committed
option to set css variables to other attribute values in the outputCssVariables method on inner components.
1 parent 7d0bea8 commit 220aa06

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).
66

7+
## [9.3.4]
8+
9+
### Fixed
10+
- option to set css variables to other attribute values in the `outputCssVariables` method on inner components.
11+
712
## [9.3.3]
813

914
### Added
@@ -804,6 +809,7 @@ Init setup
804809
- Gutenberg Blocks Registration.
805810
- Assets Manifest data.
806811

812+
[9.3.4]: https://github.com/infinum/eightshift-libs/compare/9.3.3...9.3.4
807813
[9.3.3]: https://github.com/infinum/eightshift-libs/compare/9.3.2...9.3.3
808814
[9.3.2]: https://github.com/infinum/eightshift-libs/compare/9.3.1...9.3.2
809815
[9.3.1]: https://github.com/infinum/eightshift-libs/compare/9.3.0...9.3.1

src/Helpers/CssVariablesTrait.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ private static function setVariablesToBreakpoints(array $attributes, array $vari
652652
)
653653
) {
654654
// Merge data variables with the new variables array.
655-
$data[$index]['variable'] = \array_merge($item['variable'], self::variablesInner($variable, $attributeValue, $attributes));
655+
$data[$index]['variable'] = \array_merge($item['variable'], self::variablesInner($variable, $attributeValue, $attributes, $manifest));
656656
}
657657
}
658658
}
@@ -750,10 +750,11 @@ private static function prepareVariableData(array $globalBreakpoints): array
750750
* @param array<string, mixed> $variables Array of variables of CSS variables.
751751
* @param mixed $attributeValue Original attribute value used in magic variable.
752752
* @param array<string, mixed> $attributes Attributes that are read from component's/block's manifest.
753+
* @param array<string, mixed> $manifest Component/block manifest data.
753754
*
754755
* @return array<int, mixed>|string[]
755756
*/
756-
private static function variablesInner(array $variables, $attributeValue, array $attributes): array
757+
private static function variablesInner(array $variables, $attributeValue, array $attributes, array $manifest): array
757758
{
758759
$output = [];
759760

@@ -773,8 +774,14 @@ private static function variablesInner(array $variables, $attributeValue, array
773774
}
774775

775776
foreach ($attributes as $attrKey => $attrValue) {
776-
if (\str_contains($variableValue, "%attr-{$attrKey}%")) {
777-
$variableValue = \str_replace("%attr-{$attrKey}%", (string) $attrValue, $variableValue);
777+
if (isset($attributes['prefix'])) {
778+
$key = (string)\str_replace($attributes['prefix'], Helpers::kebabToCamelCase($manifest['componentName']), $attrKey);
779+
} else {
780+
$key = $attrKey;
781+
}
782+
783+
if (\str_contains($variableValue, "%attr-{$key}%")) {
784+
$variableValue = \str_replace("%attr-{$key}%", (string) $attrValue, $variableValue);
778785
}
779786
}
780787

0 commit comments

Comments
 (0)