Skip to content

Conversation

@kbond
Copy link
Member

@kbond kbond commented Jan 23, 2024

Q A
Bug fix? no
New feature? yes
Issues n/a
License MIT

This allows the following:

{% set errors = false %}
{% set valid = true %}

<div{{ attributes.defaults({
    class: [
        'form-row',
        errors ? 'has-errors',
        valid ? 'is-valid',
    ],
}) }})

{# renders as: #}
<div class="form-row is-valid">

@kbond kbond force-pushed the feat/attribute-value-list branch from 33814af to 263d23a Compare January 23, 2024 01:11
*/
final class ComponentAttributes
{
private bool $normalized = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This normalization tracking is required because of how #1041 was implemented. (it first sets all passed values as attributes, then removes the ones that are defined)

@kbond kbond force-pushed the feat/attribute-value-list branch from 263d23a to 57ff749 Compare January 23, 2024 01:20
@kbond kbond force-pushed the feat/attribute-value-list branch from 57ff749 to 4ce090b Compare January 23, 2024 01:25
@norkunas
Copy link
Contributor

I'd use html_classes for this case :)

@kbond
Copy link
Member Author

kbond commented Jan 23, 2024

I'd use html_classes for this case :)

Forgot about that function! We can close this if others agree using that function is best.

@weaverryan
Copy link
Member

Yup! I think the goal should be to make using html_classes() as easy as possible, and possibly document it, as this is a common need.

@weaverryan weaverryan closed this Jan 29, 2024
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.

3 participants