Help.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Dcat\Admin\Grid\Column;
  3. use Dcat\Admin\Widgets\Tooltip;
  4. use Illuminate\Contracts\Support\Renderable;
  5. use Illuminate\Support\Str;
  6. class Help implements Renderable
  7. {
  8. /**
  9. * @var string
  10. */
  11. protected $message = '';
  12. /**
  13. * @var string
  14. */
  15. protected $style;
  16. /**
  17. * @var null
  18. */
  19. protected $placement;
  20. /**
  21. * Help constructor.
  22. *
  23. * @param string $message
  24. */
  25. public function __construct($message = '', ?string $style = null, ?string $placement = 'bottom')
  26. {
  27. $this->message = value($message);
  28. $this->style = $style;
  29. $this->placement = $placement;
  30. }
  31. /**
  32. * Render help header.
  33. *
  34. * @return string
  35. */
  36. public function render()
  37. {
  38. $class = 'grid-column-help-'.Str::random(8);
  39. $tooltip = Tooltip::make('.'.$class);
  40. if (in_array($this->style, ['green', 'blue', 'red', 'purple'])) {
  41. $tooltip->{$this->style}();
  42. }
  43. if (in_array($this->placement, ['bottom', 'left', 'right', 'top'])) {
  44. $tooltip->{$this->placement}();
  45. }
  46. $tooltip->title($this->message);
  47. return <<<HELP
  48. &nbsp;<a href="javascript:void(0);" class="{$class} feather icon-alert-circle" ></a>
  49. HELP;
  50. }
  51. }