diff --git a/src/Icon.php b/src/Icon.php index 927a048..edcce41 100644 --- a/src/Icon.php +++ b/src/Icon.php @@ -4,7 +4,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\HtmlString; -use DOMDocument; use Stringable; class Icon extends HtmlString implements Stringable diff --git a/src/IconComponent.php b/src/IconComponent.php index b9ebf02..d2558b7 100644 --- a/src/IconComponent.php +++ b/src/IconComponent.php @@ -5,6 +5,7 @@ namespace Orchid\Icons; use Illuminate\View\Component; +use Illuminate\View\View; class IconComponent extends Component { @@ -96,4 +97,14 @@ public function render(): callable ]); }; } + + /** + * @param ...$params + * + * @return \Illuminate\View\View + */ + public static function make(...$params): View + { + return resolve(static::class, $params)->render()(); + } } diff --git a/tests/BladeComponentTest.php b/tests/BladeComponentTest.php index 7c39d56..d24881a 100644 --- a/tests/BladeComponentTest.php +++ b/tests/BladeComponentTest.php @@ -5,6 +5,7 @@ namespace Orchid\Icons\Tests; use Illuminate\Support\Facades\Blade; +use Orchid\Icons\IconComponent; use Orchid\Icons\IconFinder; class BladeComponentTest extends TestUnitCase @@ -16,7 +17,6 @@ protected function setUp(): void $this->artisan('view:clear'); } - public function testWithPrefixComponent(): void { $this->app->make(IconFinder::class) @@ -121,19 +121,34 @@ public function testHtmlAttributesDuplicate(): void $this->assertStringContainsString('id="2"', $view); } - /** - * @return void - */ - public function testAverageSpeed() + public function testAverageSpeed(): void { $this->app->make(IconFinder::class) ->setSize('54px', '54px') ->registerIconDirectory('feather', __DIR__ . '/stubs/feather'); - collect(range(0, 10000))->each(function (int $key){ + collect(range(0, 10000))->each(function (int $key) { $view = Blade::render('', ['id' => $key]); - $this->assertStringContainsString('id="'.$key, $view); + $this->assertStringContainsString('id="' . $key, $view); }); } + + public function testStaticRender():void + { + $this->app->make(IconFinder::class) + ->setSize('54px', '54px') + ->registerIconDirectory('feather', __DIR__ . '/stubs/feather'); + + $view = IconComponent::make( + path: 'feather.alert-triangle', + id: 2, + class: 'test', + ); + + $this->assertStringContainsString('id="2"', $view->toHtml()); + $this->assertStringContainsString('class="test"', $view->toHtml()); + $this->assertStringContainsString('stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"', (string) $view); + } + }