Skip to content

Commit 65d2715

Browse files
committed
feat(view): implement additional interface methods
1 parent 86a1c7f commit 65d2715

File tree

12 files changed

+290
-12
lines changed

12 files changed

+290
-12
lines changed

packages/http/src/Session/CsrfTokenComponent.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
use Tempest\View\Elements\ViewComponentElement;
88
use Tempest\View\ViewComponent;
9+
use Tempest\View\ViewComponentMetadata;
910
use Tempest\View\ViewComponentParameters;
1011

11-
final readonly class CsrfTokenComponent implements ViewComponent
12+
final readonly class CsrfTokenComponent implements ViewComponent, ViewComponentMetadata
1213
{
1314
public static function getName(): string
1415
{
@@ -20,6 +21,26 @@ public static function getParameters(): ViewComponentParameters
2021
return new ViewComponentParameters();
2122
}
2223

24+
public static function getDescription(): string
25+
{
26+
return 'A component that generates a CSRF token input field for forms.';
27+
}
28+
29+
public static function hasSlots(): bool
30+
{
31+
return false;
32+
}
33+
34+
public static function getNamedSlots(): array
35+
{
36+
return [];
37+
}
38+
39+
public static function getDeprecationMessage(): ?string
40+
{
41+
return null;
42+
}
43+
2344
public function compile(ViewComponentElement $element): string
2445
{
2546
$name = Session::CSRF_TOKEN_KEY;

packages/view/src/Components/AnonymousViewComponent.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
use Tempest\View\Elements\ViewComponentElement;
88
use Tempest\View\ViewComponent;
9+
use Tempest\View\ViewComponentMetadata;
910
use Tempest\View\ViewComponentParameters;
1011

11-
final readonly class AnonymousViewComponent implements ViewComponent
12+
final readonly class AnonymousViewComponent implements ViewComponent, ViewComponentMetadata
1213
{
1314
public function __construct(
1415
public string $contents,
@@ -25,6 +26,26 @@ public static function getParameters(): ViewComponentParameters
2526
return new ViewComponentParameters();
2627
}
2728

29+
public static function getDescription(): string
30+
{
31+
return 'A component that renders a view file.';
32+
}
33+
34+
public static function hasSlots(): null
35+
{
36+
return null;
37+
}
38+
39+
public static function getNamedSlots(): null
40+
{
41+
return null;
42+
}
43+
44+
public static function getDeprecationMessage(): ?string
45+
{
46+
return null;
47+
}
48+
2849
public function compile(ViewComponentElement $element): string
2950
{
3051
return $this->contents;

packages/view/src/Components/DynamicViewComponent.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
use Tempest\View\Parser\TempestViewCompiler;
1111
use Tempest\View\Parser\Token;
1212
use Tempest\View\ViewComponent;
13+
use Tempest\View\ViewComponentMetadata;
1314
use Tempest\View\ViewComponentParameter;
1415
use Tempest\View\ViewComponentParameters;
1516
use Tempest\View\ViewConfig;
1617

1718
use function Tempest\Support\arr;
1819

19-
final class DynamicViewComponent implements ViewComponent
20+
final class DynamicViewComponent implements ViewComponent, ViewComponentMetadata
2021
{
2122
private Token $token;
2223

@@ -48,6 +49,26 @@ public static function getParameters(): ViewComponentParameters
4849
);
4950
}
5051

52+
public static function getDescription(): string
53+
{
54+
return 'A component that renders another component dynamically based on the "is" or ":is" attribute.';
55+
}
56+
57+
public static function hasSlots(): bool
58+
{
59+
return false;
60+
}
61+
62+
public static function getNamedSlots(): array
63+
{
64+
return [];
65+
}
66+
67+
public static function getDeprecationMessage(): ?string
68+
{
69+
return null;
70+
}
71+
5172
public function compile(ViewComponentElement $element): string
5273
{
5374
$name = $this->token->getAttribute('is') ?? $this->token->getAttribute(':is');

packages/view/src/Components/Form.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use Tempest\View\Elements\ViewComponentElement;
88
use Tempest\View\ViewComponent;
9+
use Tempest\View\ViewComponentMetadata;
910
use Tempest\View\ViewComponentParameter;
1011
use Tempest\View\ViewComponentParameters;
1112

12-
final readonly class Form implements ViewComponent
13+
final readonly class Form implements ViewComponent, ViewComponentMetadata
1314
{
1415
public static function getName(): string
1516
{
@@ -27,6 +28,7 @@ public static function getParameters(): ViewComponentParameters
2728
name: 'method',
2829
description: 'The HTTP method to use when submitting the form.',
2930
default: 'post',
31+
possibleValues: ['get', 'post'],
3032
),
3133
new ViewComponentParameter(
3234
name: 'enctype',
@@ -36,6 +38,26 @@ public static function getParameters(): ViewComponentParameters
3638
);
3739
}
3840

41+
public static function getDescription(): string
42+
{
43+
return 'A form component.';
44+
}
45+
46+
public static function hasSlots(): bool
47+
{
48+
return true;
49+
}
50+
51+
public static function getNamedSlots(): array
52+
{
53+
return [];
54+
}
55+
56+
public static function getDeprecationMessage(): ?string
57+
{
58+
return null;
59+
}
60+
3961
public function compile(ViewComponentElement $element): string
4062
{
4163
$action = $element->getAttribute('action');

packages/view/src/Components/Icon.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
use Tempest\Support\Str\ImmutableString;
1212
use Tempest\View\Elements\ViewComponentElement;
1313
use Tempest\View\ViewComponent;
14+
use Tempest\View\ViewComponentMetadata;
1415
use Tempest\View\ViewComponentParameter;
1516
use Tempest\View\ViewComponentParameters;
1617

17-
final readonly class Icon implements ViewComponent
18+
final readonly class Icon implements ViewComponent, ViewComponentMetadata
1819
{
1920
public function __construct(
2021
private AppConfig $appConfig,
@@ -41,6 +42,26 @@ public static function getParameters(): ViewComponentParameters
4142
);
4243
}
4344

45+
public static function getDescription(): string
46+
{
47+
return 'Renders an icon using the Iconify API.';
48+
}
49+
50+
public static function hasSlots(): bool
51+
{
52+
return false;
53+
}
54+
55+
public static function getNamedSlots(): array
56+
{
57+
return [];
58+
}
59+
60+
public static function getDeprecationMessage(): ?string
61+
{
62+
return null;
63+
}
64+
4465
public function compile(ViewComponentElement $element): string
4566
{
4667
if (! $element->hasAttribute('name')) {

packages/view/src/Components/Input.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
use Tempest\Validation\Rule;
99
use Tempest\View\Elements\ViewComponentElement;
1010
use Tempest\View\ViewComponent;
11+
use Tempest\View\ViewComponentMetadata;
1112
use Tempest\View\ViewComponentParameter;
1213
use Tempest\View\ViewComponentParameters;
1314

14-
final readonly class Input implements ViewComponent
15+
final readonly class Input implements ViewComponent, ViewComponentMetadata
1516
{
1617
public function __construct(
1718
private Session $session,
@@ -36,6 +37,31 @@ public static function getParameters(): ViewComponentParameters
3637
new ViewComponentParameter(
3738
name: 'type',
3839
description: 'The type of the input field (e.g., text, email, password, textarea).',
40+
possibleValues: [
41+
'button',
42+
'checkbox',
43+
'color',
44+
'date',
45+
'datetime-local',
46+
'email',
47+
'file',
48+
'hidden',
49+
'image',
50+
'month',
51+
'number',
52+
'password',
53+
'radio',
54+
'range',
55+
'reset',
56+
'search',
57+
'submit',
58+
'tel',
59+
'text',
60+
'time',
61+
'url',
62+
'week',
63+
'textarea', // Not an HTML input type, but allowed for textarea elements
64+
],
3965
),
4066
new ViewComponentParameter(
4167
name: 'default',
@@ -44,6 +70,26 @@ public static function getParameters(): ViewComponentParameters
4470
);
4571
}
4672

73+
public static function getDescription(): string
74+
{
75+
return 'A generic input component for forms.';
76+
}
77+
78+
public static function hasSlots(): bool
79+
{
80+
return false;
81+
}
82+
83+
public static function getNamedSlots(): array
84+
{
85+
return [];
86+
}
87+
88+
public static function getDeprecationMessage(): ?string
89+
{
90+
return null;
91+
}
92+
4793
public function compile(ViewComponentElement $element): string
4894
{
4995
$name = $element->getAttribute('name');

packages/view/src/Components/Submit.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use Tempest\View\Elements\ViewComponentElement;
88
use Tempest\View\ViewComponent;
9+
use Tempest\View\ViewComponentMetadata;
910
use Tempest\View\ViewComponentParameter;
1011
use Tempest\View\ViewComponentParameters;
1112

12-
final readonly class Submit implements ViewComponent
13+
final readonly class Submit implements ViewComponent, ViewComponentMetadata
1314
{
1415
public static function getName(): string
1516
{
@@ -27,6 +28,26 @@ public static function getParameters(): ViewComponentParameters
2728
);
2829
}
2930

31+
public static function getDescription(): string
32+
{
33+
return 'A submit button for forms.';
34+
}
35+
36+
public static function hasSlots(): bool
37+
{
38+
return false;
39+
}
40+
41+
public static function getNamedSlots(): array
42+
{
43+
return [];
44+
}
45+
46+
public static function getDeprecationMessage(): ?string
47+
{
48+
return null;
49+
}
50+
3051
public function compile(ViewComponentElement $element): string
3152
{
3253
$label = $element->getAttribute('label') ?? 'Submit';

packages/vite/src/ViteTagsComponent.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use Tempest\View\Elements\ViewComponentElement;
88
use Tempest\View\ViewComponent;
9+
use Tempest\View\ViewComponentMetadata;
910
use Tempest\View\ViewComponentParameter;
1011
use Tempest\View\ViewComponentParameters;
1112

12-
final readonly class ViteTagsComponent implements ViewComponent
13+
final readonly class ViteTagsComponent implements ViewComponent, ViewComponentMetadata
1314
{
1415
public function __construct(
1516
private ViteConfig $viteConfig,
@@ -34,6 +35,26 @@ public static function getParameters(): ViewComponentParameters
3435
);
3536
}
3637

38+
public static function getDescription(): string
39+
{
40+
return 'Generates Vite tags for the specified entrypoints.';
41+
}
42+
43+
public static function hasSlots(): bool
44+
{
45+
return false;
46+
}
47+
48+
public static function getNamedSlots(): array
49+
{
50+
return [];
51+
}
52+
53+
public static function getDeprecationMessage(): ?string
54+
{
55+
return null;
56+
}
57+
3758
public function compile(ViewComponentElement $element): string
3859
{
3960
$entrypoints = match (true) {

tests/Fixtures/BaseLayoutComponent.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
use Tempest\View\Elements\ViewComponentElement;
88
use Tempest\View\ViewComponent;
9+
use Tempest\View\ViewComponentMetadata;
910
use Tempest\View\ViewComponentParameters;
1011

11-
final readonly class BaseLayoutComponent implements ViewComponent
12+
final readonly class BaseLayoutComponent implements ViewComponent, ViewComponentMetadata
1213
{
1314
public static function getName(): string
1415
{
@@ -20,6 +21,26 @@ public static function getParameters(): ViewComponentParameters
2021
return new ViewComponentParameters();
2122
}
2223

24+
public static function getDescription(): string
25+
{
26+
return 'A test component with slots.';
27+
}
28+
29+
public static function hasSlots(): bool
30+
{
31+
return true;
32+
}
33+
34+
public static function getNamedSlots(): array
35+
{
36+
return [];
37+
}
38+
39+
public static function getDeprecationMessage(): ?string
40+
{
41+
return null;
42+
}
43+
2344
public function compile(ViewComponentElement $element): string
2445
{
2546
return <<<HTML

0 commit comments

Comments
 (0)