Drop-down menu

The Dcat\Admin\Widgets\Dropdown class is a quick way to help you build dropdown menu functions.

Basic Usage

  1. <?php
  2. use Dcat\Admin\Widgets\Dropdown;
  3. use Dcat\Admin\Layout\Content;
  4. class MyController
  5. {
  6. public function index(Content $content)
  7. {
  8. $options = [
  9. 'Name 1',
  10. 'Name 2',
  11. 'Name 3',
  12. 'Name 4',
  13. 'Name 5',
  14. ];
  15. $dropdown = Dropdown::make($options)
  16. ->button('Category Navigation') // Set button
  17. ->buttonClass('btn btn-white waves-effect') // Set the button style
  18. ->map(function ($label, $key) {
  19. // Format menu options
  20. $url = admin_url('categories/'.$key);
  21. return "<a href='$url'>{$label}</a>";
  22. });
  23. return $content->body($dropdown);
  24. }
  25. }

result

Drop-down menu - 图1

Click on the menu to change button text

The click method allows the text of the selected menu to be displayed in the button, similar to the result of a drop-down selection.

  1. $options = [
  2. ...
  3. ];
  4. $dropdown = Dropdown::make($options)
  5. ->button('option') // Set button
  6. ->click();

Set TITLE

  1. $options1 = [
  2. 'Name 1',
  3. 'Name 2',
  4. ];
  5. $options2 = [
  6. 'Test 1',
  7. 'Test 2',
  8. ];
  9. $dropdown = Dropdown::make()
  10. ->button('Use of TITLE')
  11. ->options($options1, 'TITLE1')
  12. ->options($options2, 'TITLE2');

result

Drop-down menu - 图2

增加分割线

  1. $options = [
  2. 'Name 1',
  3. 'Name 2',
  4. Dropdown::DIVIDER,
  5. 'Name 3',
  6. 'Name 4',
  7. ];
  8. $dropdown = Dropdown::make()
  9. ->button('Using dividing lines')
  10. ->options($options)

result

Drop-down menu - 图3

Custom buttons

  1. public function index(Content $content)
  2. {
  3. $options = [
  4. 'Name 1',
  5. 'Name 2',
  6. 'Name 3',
  7. 'Name 4',
  8. 'Name 5',
  9. ];
  10. $dropdown = Dropdown::make($options)
  11. ->map(function ($label, $key) {
  12. // Formatting menu options
  13. $url = admin_url('categories/'.$key);
  14. return "<a href='$url'>{$label}</a>";
  15. });
  16. return $content->body(
  17. <<<HTML
  18. <div class='dropdown'>
  19. <button class='btn btn-primary dropdown-toggle' data-toggle='dropdown'>
  20. <i class='feather icon-email'></i> Custom buttons
  21. </button>
  22. {$dropdown->render()}
  23. </div>
  24. HTML
  25. );
  26. }

result

Drop-down menu - 图4