Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SearchBar] Add custom_component filter #6226

Merged
merged 6 commits into from
Sep 12, 2022

Conversation

sebelga
Copy link
Contributor

@sebelga sebelga commented Sep 9, 2022

This PR adds a new filter type to the Search bar: custom_component. This filter gives full control to the consumer to render the filter button + the panel.

Fixes #6003

Example

const CustomComponent = ({ query, onChange }) => {
  // Access to the Query instance and the onChange handler to update the search bar
  const [isOpen, setIsOpen] = useState(false);

  const closePopover = () => {
    setIsOpen(false);
  };

  const button = (
    <EuiFilterButton
      iconType="arrowDown"
      iconSide="right"
      onClick={() => setIsOpen((prev) => !prev)}
      hasActiveFilters={<some-internal-state>}
      numActiveFilters={<some-internal-state>}
      grow
    >
      Filter label
    </EuiFilterButton>
  );

  return (
    <EuiPopover
      button={button}
      isOpen={isOpen}
      closePopover={closePopover}
      panelPaddingSize="none"
      anchorPosition="downCenter"
    >
      <EuiPanel paddingSize="m">
        <div>Custom content</div>
      </EuiPanel>
    </EuiPopover>
  );
};

// And this is the filter configuration

{
  type: 'custom_component',
  component: CustomComponent,
},

Screenshot 2022-09-09 at 16 17 06

Screenshot 2022-09-12 at 16 43 15

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6226/

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks good to me, have one suggestion for the example custom component

src-docs/src/views/search_bar/search_bar_filters.js Outdated Show resolved Hide resolved
Co-authored-by: Chandler Prall <chandler.prall@gmail.com>
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6226/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6226/

@sebelga sebelga marked this pull request as ready for review September 12, 2022 16:15
@sebelga
Copy link
Contributor Author

sebelga commented Sep 12, 2022

Thanks for the first pass review @chandlerprall ! The PR is now ready for review, I added the docs and unit tests. Cheers!

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, go ahead and merge when CI passes

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_6226/

@sebelga
Copy link
Contributor Author

sebelga commented Sep 12, 2022

Thanks for the review @chandlerprall 👍

@sebelga sebelga merged commit 067867f into elastic:main Sep 12, 2022
@sebelga sebelga deleted the new-filter-type-custom-component branch September 12, 2022 17:26
@chandlerprall chandlerprall mentioned this pull request Sep 15, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EuiSearchBar] Allow custom filter component to be rendered
3 participants