Skip to content

Commit

Permalink
Add storybook suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
IdrissMahjoubi committed Aug 20, 2024
1 parent db1a5c3 commit 678e62d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
22 changes: 20 additions & 2 deletions .storybook/stories/search-editor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

import { Story } from './utils/doc';
import { TAGS, USERS, useEditorMention } from './utils/hooks/useEditorMention';
import { promiseAction } from './utils/promiseAction';
import { GetSuggestions } from '../../src/types';

export default {
title: 'Editors / Search Editor',
Expand All @@ -39,6 +39,24 @@ const Template: Story<SearchEditorStoryArgs> = (
userOptions,
} = useEditorMention();

const getSuggestions: GetSuggestions = async props => {
action('getSuggestions')(props);
const { input } = props;
const suggestedItems = [...dateOptions, ...tagOptions, ...userOptions];

if (!input) {
return [];
}

const lowerCaseInput = input.toLowerCase();

const filteredSuggestedItem = suggestedItems.filter(item => {
const lowerCaseItem = item.label.toLowerCase();
return lowerCaseItem.includes(lowerCaseInput);
});

return filteredSuggestedItem;
};
const editorRef = useRef<SearchImperativeRef>(null);

const defaultGetExtraAttrs =
Expand Down Expand Up @@ -83,7 +101,7 @@ const Template: Story<SearchEditorStoryArgs> = (
fields={fields}
innerRef={editorRef}
onSubmit={action('onSubmit')}
getSuggestions={promiseAction('getSuggestions')}
getSuggestions={getSuggestions}
{...props}
/>

Expand Down
4 changes: 0 additions & 4 deletions src/search-editor/MentionSuggester.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { SuggesterSkeleton } from './SuggesterSkeleton';
import { Fields } from './types';

const useStyles = makeStyles()(theme => ({
fullWidth: {
width: '100%',
},
highlighted: {
backgroundColor: theme.palette.action.selected,
},
Expand Down Expand Up @@ -56,7 +53,6 @@ const useStyles = makeStyles()(theme => ({
},
suggester: {
position: 'relative',
width: '100%',
maxHeight: theme.spacing(40),
borderTop: `${theme.spacing(0.125)} solid ${theme.palette.divider}`,
overflow: 'auto',
Expand Down
1 change: 0 additions & 1 deletion src/search-editor/SearchEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const useStyles = makeStyles()(theme => ({
},
searchBox: {
padding: theme.spacing(1),
width: '100%',
},
footer: {
padding: theme.spacing(2),
Expand Down

0 comments on commit 678e62d

Please # to comment.