-
-
Save huubl/d73a59f7d2be8bab65a9227f27254949 to your computer and use it in GitHub Desktop.
Revisions
-
Log1x revised this gist
Jul 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ <x-rating /> <x-rating rating="3.4" size="20" type="thumbsUp" /> -
Log1x created this gist
Jul 6, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,87 @@ <?php namespace App\View\Components; use Roots\Acorn\View\Component; class Rating extends Component { /** * The rating value. * * @return int */ public $rating; /** * The rating type. * * @return string */ public $type; /** * The rating size. * * @return int */ public $size; /** * Create the component instance. * * @param string $type * @param int $size * @param int $rating * @return void */ public function __construct($type = 'star', $size = 16, $rating = null) { $this->type = $type; $this->size = $size; $this->rating = $rating; if (empty($this->$rating)) { $this->rating = get_field('rating') ?? get_sub_field('rating') ?? 1; } } /** * The formatted rating. * * @return string */ public function rating() { return $this->format($this->rating); } /** * Format a number to the first decimal. * * @param int $x * @param int $y * @return string */ protected function format($x, $y = 1) { if (! is_numeric($x)) { $x = 1; } return number_format( min(max($x, 1), 5), $y ); } /** * Get the view / contents that represent the component. * * @return \Illuminate\View\View|string */ public function render() { return $this->view('components.rating'); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ <x-rating /> <x-rating rating="3.4" size="20" type="thumbs-up" /> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ <fa-rating :glyph="{{ $type }}" :item-size="{{ $size }}" active-color="currentColor" :increment="0.1" :rating="{{ $rating }}" v-model="rating"> </fa-rating>