ToolBar.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import ActionSet from "./ActionSet";
  2. import ListButton from "./ListButton";
  3. import SearchBar from "./SearchBar";
  4. export default class ToolBar {
  5. constructor(onSearch, actions, options) {
  6. this.onSearch = onSearch;
  7. this.actions = actions;
  8. this.options = options;
  9. }
  10. render() {
  11. this.toolbar = document.createElement('div');
  12. this.toolbar.classList.add('input-group', 'mb-3');
  13. if (typeof this.actions !== 'undefined' && typeof this.options.selectable === 'undefined' && this.actions.length > 0) {
  14. this.actionSet = new ActionSet(this.actions, 'button');
  15. let { button, toggle, list } = this.actionSet.render();
  16. if (button) {
  17. this.toolbar.appendChild(button);
  18. }
  19. if (toggle) {
  20. this.toolbar.appendChild(toggle);
  21. }
  22. if (list) {
  23. this.toolbar.append(list);
  24. }
  25. }
  26. this.searchBar = new SearchBar(this.onSearch);
  27. this.toolbar.appendChild(this.searchBar.render());
  28. this.toolbar.appendChild(new ListButton('th', '').render());
  29. return this.toolbar;
  30. }
  31. getSearch() {
  32. return this.searchBar.getSearch();
  33. }
  34. }