File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 53
53
use Mary \View \Components \ProgressRadial ;
54
54
use Mary \View \Components \Radio ;
55
55
use Mary \View \Components \Range ;
56
+ use Mary \View \Components \Rating ;
56
57
use Mary \View \Components \Select ;
57
58
use Mary \View \Components \SelectGroup ;
58
59
use Mary \View \Components \Signature ;
@@ -156,6 +157,7 @@ public function registerComponents()
156
157
Blade::component ($ prefix . 'progress-radial ' , ProgressRadial::class);
157
158
Blade::component ($ prefix . 'radio ' , Radio::class);
158
159
Blade::component ($ prefix . 'range ' , Range::class);
160
+ Blade::component ($ prefix . 'rating ' , Rating::class);
159
161
Blade::component ($ prefix . 'select ' , Select::class);
160
162
Blade::component ($ prefix . 'signature ' , Signature::class);
161
163
Blade::component ($ prefix . 'spotlight ' , Spotlight::class);
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Mary \View \Components ;
4
+
5
+ use Closure ;
6
+ use Illuminate \Contracts \View \View ;
7
+ use Illuminate \View \Component ;
8
+
9
+ class Rating extends Component
10
+ {
11
+ public string $ uuid ;
12
+
13
+ public function __construct (
14
+ public int $ total = 5
15
+ ) {
16
+ $ this ->uuid = "mary " . md5 (serialize ($ this ));
17
+ }
18
+
19
+ public function modelName (): ?string
20
+ {
21
+ return $ this ->attributes ->whereStartsWith ('wire:model ' )->first ();
22
+ }
23
+
24
+ public function size (): ?string
25
+ {
26
+ return str ($ this ->attributes ->get ('class ' ))->match ('/(rating-(..))/ ' );
27
+ }
28
+
29
+ public function render (): View |Closure |string
30
+ {
31
+ return <<<'HTML'
32
+ <div class="rating gap-1 {{ $size }}">
33
+ @for ($i = 1; $i <= $total; $i++)
34
+ <input
35
+ type="radio"
36
+ name="{{ $modelName() }}"
37
+ value="{{ $i }}"
38
+ {{ $attributes->whereStartsWith('wire:model') }}
39
+ {{ $attributes->class(["mask mask-star-2 bg-yellow-400"]) }}
40
+ />
41
+ @endfor
42
+ </div>
43
+ HTML;
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments