Skip to content

[9.x] Add @style Blade directive#45887

Merged
taylorotwell merged 3 commits into
laravel:9.xfrom
intrepidws:9.x
Feb 1, 2023
Merged

[9.x] Add @style Blade directive#45887
taylorotwell merged 3 commits into
laravel:9.xfrom
intrepidws:9.x

Conversation

@intrepidws
Copy link
Copy Markdown
Contributor

Building upon the great work by @danharrin, who added the @class Blade directive in PR #38016, this PR adds support for a @style Blade directive. While my preference is always to use @class, I often find myself needing to conditionally use one-off styles in projects where I don't have access to Tailwind.

Usage is very similar to the @class blade directive, as follows:

<div>
    <span @style([
        'margin-top: 10px;',
        'font-weight: bold' => $active,
    ])>
        Dashboard
    </span>

    <svg @style([
        'font-weight: bold; text-decoration: underline;',
        'margin-top: 10px' => $active,
    ])>
        <path />
        <path />
        <path />
    </svg>
</div>

One thing to note is that when specifying the styles, it doesn't matter whether or not you end the line with a semi-colon - the logic will add it if it's missing.

If accepted, I will PR to the docs. I could also add @style support for blade components as well (similar to what PR #43140 did for the @class directive) - if that's something that's desired.

@taylorotwell
Copy link
Copy Markdown
Member

I would suggest going ahead and adding support for Blade components. I don't think we would want to merge support for this without also supporting Blade components since @class is supported on both.

@taylorotwell taylorotwell marked this pull request as draft January 31, 2023 19:39
@taylorotwell
Copy link
Copy Markdown
Member

Please mark as ready for review when done. Thanks!

@intrepidws intrepidws marked this pull request as ready for review January 31, 2023 20:46
@intrepidws
Copy link
Copy Markdown
Contributor Author

No problem, this is ready for review @taylorotwell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants