Alert.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\View\Components;
  3. use Roots\Acorn\View\Component;
  4. class Alert extends Component
  5. {
  6. /**
  7. * The alert type.
  8. *
  9. * @var string
  10. */
  11. public $type;
  12. /**
  13. * The alert message.
  14. *
  15. * @var string
  16. */
  17. public $message;
  18. /**
  19. * The alert types.
  20. *
  21. * @var array
  22. */
  23. public $types = [
  24. 'default' => 'text-indigo-50 bg-indigo-400',
  25. 'success' => 'text-green-50 bg-green-400',
  26. 'caution' => 'text-yellow-50 bg-yellow-400',
  27. 'warning' => 'text-red-50 bg-red-400',
  28. ];
  29. /**
  30. * Create the component instance.
  31. *
  32. * @param string $type
  33. * @param string $message
  34. * @return void
  35. */
  36. public function __construct($type = 'default', $message = null)
  37. {
  38. $this->type = $this->types[$type] ?? $this->types['default'];
  39. $this->message = $message;
  40. }
  41. /**
  42. * Get the view / contents that represent the component.
  43. *
  44. * @return \Illuminate\View\View|string
  45. */
  46. public function render()
  47. {
  48. return $this->view('components.alert');
  49. }
  50. }