Closed butschster closed 3 years ago
Thanks for this PR as well, it looks in the right way to inherit the styles of a parent element, just found one issue:
render(<<<'HTML'
<div class="bg-red-300 text-color-white">
<span class="mr-1">Hello</span>
<strong class="text-color-blue">world</strong>
</div>
HTML);
It renderes this:
Looks like when there is a text color it ignores the parent bg color.
All the rest looks like a great addition.
Thanks for this PR as well, it looks in the right way to inherit the styles of a parent element, just found one issue:
render(<<<'HTML' <div class="bg-red-300 text-color-white"> <span class="mr-1">Hello</span> <strong class="text-color-blue">world</strong> </div> HTML);
It renderes this:
Looks like when there is a text color it ignores the parent bg color.
All the rest looks like a great addition.
Hmm. I bumped into a similar issue when I was working on the table parser.
I was thinking that we can pass styles from parent element to child elements and mergee them
Something like this
public static function div(array|string $content = '', string $styles = ''): Components\Div
{
$content = implode('', array_map(static funtion ($element) use($styles) {
// I think we need to merge styles somewere here.
// Moreover we don't need to replace existing styles, only add new from parent
$element->inheritFromStyles($styles);
return (string) $element;
}, is_array($content) ? $content : [$content]));
return Components\Div::fromStyles(
self::getRenderer(), $content, $styles
);
}
Yes we definitely need something to handle the inherit styles.
cc @nunomaduro.
Yes we definitely need something to handle the inherit styles.
cc @nunomaduro.
I have an idea how to fix it and the idea can fix this issue #53 I think. I need to try it.
Yes we definitely need something to handle the inherit styles.
cc @nunomaduro.
Take a look at #64 PR. I tried to solve issue with inheritance and fized #53 issue there.
It has a draft state. Mayebe there will be some changes and proposals from you.
I covered with tests all issues.
Feel free to modify code form the PR
Thanks @butschster, will take a look on it.
Hi @nunomaduro. Is there any chance you approve this pr? I need then to refactor pr with table and stast using the packages.
Thank you, @butschster !
Thank you, @butschster !
Thank you too!
One of the reason I decided to get rid of default tags is in this example
When it parsed it looks like
As you noticed the word
world
has default background because ofbg=default
instead of red background.There are a lot of unnecessary style tags in output :)