ux icon indicating copy to clipboard operation
ux copied to clipboard

Use ComponentAttributes everywhere in project

Open seb-jean opened this issue 3 years ago • 8 comments

Hi,

It would be great to be able to use ComponentAttributes everywhere in project but ComponentAttributes is marked as @internal

For instance:

<?php

namespace App\Twig;

use Symfony\UX\TwigComponent\ComponentAttributes;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class AriaExtension extends AbstractExtension
{
    public function getFunctions(): array
    {
        return [
            new TwigFunction('aria_dialog', [$this, 'ariaDialog']),
        ];
    }

    public function ariaDialog()
    {
        $attributes = [
            'data-controller' => 'dialog',
            'role' => 'dialog',
            'aria-modal' => 'true',
        ];

        return new ComponentAttributes($attributes);
    }
}

seb-jean avatar Mar 22 '22 10:03 seb-jean

If there is an external use-case for something marked as internal, I'm fine with removing @internal.

kbond avatar Mar 22 '22 11:03 kbond

An example use case is generating HTML attributes like the Twig extension, above. But it is not a component.

seb-jean avatar Mar 22 '22 12:03 seb-jean

Yep, looks legit to me!

kbond avatar Mar 22 '22 12:03 kbond

Maybe we could rename ComponentAttributes to HtmlAttributes?

seb-jean avatar Mar 22 '22 12:03 seb-jean

I'd be fine with this as well. @weaverryan, any objections?

kbond avatar Mar 22 '22 12:03 kbond

Hi @weaverryan, Do you have any objections?

seb-jean avatar May 06 '22 08:05 seb-jean

It's often better to start a PR if the change is scoped like this one. Easier to judge the impact, and PRs often get more attention than issues :)

wouterj avatar May 06 '22 09:05 wouterj

Yes, PR please! No objections from me, including the name change.

weaverryan avatar May 06 '22 17:05 weaverryan