diff --git a/src/LiveComponent/CHANGELOG.md b/src/LiveComponent/CHANGELOG.md new file mode 100644 index 00000000000..f26585d52fc --- /dev/null +++ b/src/LiveComponent/CHANGELOG.md @@ -0,0 +1,88 @@ +# CHANGELOG + +## NEXT + +- Minimum PHP version was bumped to 8.0 so that PHP 8 attributes could be used. + +- The `LiveComponentInterface` was dropped and replaced by the `AsLiveComponent` attribute, + which extends the new `AsTwigComponent` from the TwigComponent library. All + other annotations (e.g. `@LiveProp` and `@LiveAction`) were also replaced by + PHP 8 attributes. + +Before: + +```php +use App\Entity\Notification; +use App\Repository\NotificationRepository; +use Symfony\UX\LiveComponent\Attribute\LiveAction; +use Symfony\UX\LiveComponent\Attribute\LiveProp; +use Symfony\UX\LiveComponent\LiveComponentInterface; + +final class NotificationComponent implements LiveComponentInterface +{ + private NotificationRepository $repo; + + /** @LiveProp */ + public bool $expanded = false; + + public function __construct(NotificationRepository $repo) + { + $this->repo = $repo; + } + + /** @LiveAction */ + public function toggle(): void + { + $this->expanded = !$this->expanded; + } + + public function getNotifications(): array + { + return $this->repo->findAll(); + } + + public static function getComponentName(): string + { + return 'notification'; + } +} +``` + +After: + +```php +use App\Entity\Notification; +use App\Repository\NotificationRepository; +use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; +use Symfony\UX\LiveComponent\Attribute\LiveAction; +use Symfony\UX\LiveComponent\Attribute\LiveProp; + +#[AsLiveComponent('notification')] +final class NotificationComponent +{ + private NotificationRepository $repo; + + #[LiveProp] + public bool $expanded = false; + + public function __construct(NotificationRepository $repo) + { + $this->repo = $repo; + } + + #[LiveAction] + public function toggle(): void + { + $this->expanded = !$this->expanded; + } + + public function getNotifications(): array + { + return $this->repo->findAll(); + } +} +``` + +## Pre-Release + +- The LiveComponent library was introduced! diff --git a/src/TwigComponent/CHANGELOG.md b/src/TwigComponent/CHANGELOG.md new file mode 100644 index 00000000000..f1d092ef5a6 --- /dev/null +++ b/src/TwigComponent/CHANGELOG.md @@ -0,0 +1,60 @@ +# CHANGELOG + +## NEXT + +- Minimum PHP version was bumped to 8.0 so that PHP 8 attributes could be used. + +- The `ComponentInterface` was dropped and replaced by the `AsTwigComponent` attribute. + The `getComponentName()` was replaced by a `name` argument to the attribute. + +Before: + +```php +use Symfony\UX\TwigComponent\ComponentInterface; + +class AlertComponent implements ComponentInterface +{ + public string $type = 'success'; + public string $message; + + public static function getComponentName(): string + { + return 'alert'; + } +} +``` + +After: + +```php +use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; + +#[AsTwigComponent('alert')] +class AlertComponent +{ + public string $type = 'success'; + public string $message; +} +``` + +- If you're using a version _lower_ than Symfony 5.3, you will need + to manually tag all component services with `twig.component`. This is + because Symfony 5.3 introduces autoconfiguration for PHP 8 attributes, + which this library leverages. + +- The template for a component can now be controlled via the `template` argument + to the `AsTwigComponent` attribute: + +```php +use Symfony\UX\TwigComponent\Attribute\AsTwigComponent; + +#[AsTwigComponent('alert', template: 'other/path/alert.html.twig')] +class AlertComponent +{ + // ... +} +``` + +## Pre-Release + +- The TwigComponent library was introduced!