Help.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 = null)
  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. return <<<HELP
  47. &nbsp;<a href="javascript:void(0);" class="{$class} feather icon-help-circle" data-title="{$this->message}"></a>
  48. HELP;
  49. }
  50. }