Skip to content

Commit fd5522b

Browse files
committed
Change for style binding
1 parent 663fc28 commit fd5522b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Compiler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,15 +762,15 @@ public function handleBinding(string $value, string $name, ?DOMElement $node = n
762762
if (preg_match('/^`(.*)`$/', $element, $match)) {
763763
$dynamicValues[] = $this->handleTemplateStringBinding($match[1], $twigOutput);
764764
} elseif (preg_match('/^\{(.*)\}$/', $element, $match)) {
765-
$this->handleObjectBinding([$match[1]], $dynamicValues, $twigOutput);
765+
$this->handleObjectBinding([$match[1]], $dynamicValues, $twigOutput, $name === 'style');
766766
} else {
767767
$dynamicValues[] = $element;
768768
}
769769
}
770770
} elseif (preg_match($regexObjectBinding, $value, $matches)) {
771771
$this->logger->debug('- object binding ', ['value' => $value]);
772772
$items = explode(',', $matches['elements']);
773-
$this->handleObjectBinding($items, $dynamicValues, $twigOutput);
773+
$this->handleObjectBinding($items, $dynamicValues, $twigOutput, $name === 'style');
774774
} elseif (preg_match($regexTemplateString, $value, $matches)) {
775775
// <div :class="`abc ${someDynamicClass}`">
776776
$this->logger->debug('- template string binding ', ['value' => $value]);
@@ -795,15 +795,15 @@ public function handleBinding(string $value, string $name, ?DOMElement $node = n
795795
* @param string[] $dynamicValues
796796
* @throws ReflectionException
797797
*/
798-
protected function handleObjectBinding(array $items, array &$dynamicValues, bool $twigOutput): void
798+
protected function handleObjectBinding(array $items, array &$dynamicValues, bool $twigOutput, bool $isStyle): void
799799
{
800800
$regexObjectElements = '/(?<isString>["\']?)(?<class>[^"\']+)["\']?\s*:\s*(?<condition>[^,]+)/x';
801801
foreach ($items as $item) {
802802
if (preg_match($regexObjectElements, $item, $matchElement)) {
803803
$dynamicValues[] = $this->builder->prepareBindingOutput(
804-
$matchElement['isString']
805-
? $this->builder->refactorCondition($matchElement['condition']) . ' ? \'' . $matchElement['class'] . '\''
806-
: '\'' . $matchElement['class'] . ':\' + ' . $matchElement['condition'],
804+
$isStyle && !$matchElement['isString']
805+
? '\'' . $matchElement['class'] . ':\' + ' . $matchElement['condition']
806+
: $this->builder->refactorCondition($matchElement['condition']) . ' ? \'' . $matchElement['class'] . '\'',
807807
$twigOutput
808808
);
809809
}

0 commit comments

Comments
 (0)