|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\View\Components; |
| 4 | + |
| 5 | +use Illuminate\View\Component; |
| 6 | + |
| 7 | +class MarkerCreator extends Component |
| 8 | +{ |
| 9 | + const FIELDS = [ |
| 10 | + 'text' => [ |
| 11 | + 'name' => 'Text', |
| 12 | + 'value' => 'A', |
| 13 | + 'type' => 'text', |
| 14 | + 'description' => 'This is the text that will be rendered on the pin. You can use letters, numbers, special characters, and more. Text will overflow as it becomes too long. So we recommend up to 3 characters.', |
| 15 | + ], |
| 16 | + 'icon' => [ |
| 17 | + 'name' => 'Icon', |
| 18 | + 'value' => '', |
| 19 | + 'type' => 'text', |
| 20 | + 'description' => 'The icon you would like to show in the pin. This has to be a Font Awesome 5 class name.', |
| 21 | + ], |
| 22 | + 'size' => [ |
| 23 | + 'name' => 'Size', |
| 24 | + 'value' => 75, |
| 25 | + 'type' => 'number', |
| 26 | + 'description' => 'The size of the marker is the height. Your text will be automatically scaled to fit.', |
| 27 | + ], |
| 28 | + 'color' => [ |
| 29 | + 'name' => 'Text Color', |
| 30 | + 'value' => 'FFF', |
| 31 | + 'type' => 'text', |
| 32 | + 'description' => 'The color of the text on the marker.', |
| 33 | + ], |
| 34 | + 'background' => [ |
| 35 | + 'name' => 'Background Color', |
| 36 | + 'value' => 'BC5AF4', |
| 37 | + 'type' => 'text', |
| 38 | + 'description' => 'The color of the marker itself.', |
| 39 | + ], |
| 40 | + 'hoffset' => [ |
| 41 | + 'name' => 'Horizontal Offset', |
| 42 | + 'value' => 0, |
| 43 | + 'type' => 'number', |
| 44 | + 'description' => 'You can manually adjust the position of the text horizontally with this parmeter. Zero is the automatic center and you can move in positive or negative directions.', |
| 45 | + ], |
| 46 | + 'voffset' => [ |
| 47 | + 'name' => 'Vertical Offset', |
| 48 | + 'value' => 0, |
| 49 | + 'type' => 'number', |
| 50 | + 'description' => 'You can manually adjust the position of the text vertically with this parmeter. Zero is the automatic center and you can move in positive or negative directions.', |
| 51 | + ], |
| 52 | + ]; |
| 53 | + |
| 54 | + public $parameters = []; |
| 55 | + |
| 56 | + public $endpoint = null; |
| 57 | + |
| 58 | + /** |
| 59 | + * Create a new component instance. |
| 60 | + * |
| 61 | + * @return void |
| 62 | + */ |
| 63 | + public function __construct($fields = [], $endpoint = null) |
| 64 | + { |
| 65 | + foreach ($fields as $key => $value) { |
| 66 | + if (is_string($key)) { |
| 67 | + $parameterName = $key; |
| 68 | + $fieldDefiniton = self::FIELDS[$key]; |
| 69 | + $fieldDefiniton = array_merge($fieldDefiniton, $value); |
| 70 | + } else { |
| 71 | + $parameterName = $value; |
| 72 | + $fieldDefiniton = self::FIELDS[$value]; |
| 73 | + } |
| 74 | + $this->parameters[$parameterName] = $fieldDefiniton; |
| 75 | + } |
| 76 | + |
| 77 | + $this->endpoint = $endpoint; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Get the view / contents that represent the component. |
| 82 | + * |
| 83 | + * @return \Illuminate\Contracts\View\View|\Closure|string |
| 84 | + */ |
| 85 | + public function render() |
| 86 | + { |
| 87 | + return view('components.marker-creator'); |
| 88 | + } |
| 89 | +} |
0 commit comments