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

Storybook: Support keyword search in Icon Library #67442

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/icons/src/icon/stories/index.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useState, Fragment } from '@wordpress/element';
import Icon from '../';
import check from '../../library/check';
import * as icons from '../../';
import keywords from './keywords';

const { Icon: _Icon, ...availableIcons } = icons;

Expand Down Expand Up @@ -46,14 +47,23 @@ const LibraryExample = () => {
const [ filter, setFilter ] = useState( '' );
const filteredIcons = filter.length
? Object.fromEntries(
Object.entries( availableIcons ).filter( ( [ name ] ) =>
name.toLowerCase().includes( filter.toLowerCase() )
)
Object.entries( availableIcons ).filter( ( [ name ] ) => {
const normalizedName = name.toLowerCase();
const normalizedFilter = filter.toLowerCase();

return (
normalizedName.includes( normalizedFilter ) ||
// @ts-expect-error - Not worth the effort to cast `name`
keywords[ name ]?.some( ( keyword ) =>
keyword.toLowerCase().includes( normalizedFilter )
)
);
} )
)
: availableIcons;
return (
<div style={ { padding: 20 } }>
<label htmlFor="filter-icon" style={ { paddingRight: 10 } }>
<label htmlFor="filter-icons" style={ { paddingRight: 10 } }>
Copy link
Member Author

Choose a reason for hiding this comment

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

Small accessibility error here.

Filter Icons
</label>
<input
Expand Down
13 changes: 13 additions & 0 deletions packages/icons/src/icon/stories/keywords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const keywords: Partial< Record< keyof typeof import('../../'), string[] > > = {
cancelCircleFilled: [ 'close' ],
create: [ 'add' ],
file: [ 'folder' ],
seen: [ 'show' ],
thumbsDown: [ 'dislike' ],
thumbsUp: [ 'like' ],
trash: [ 'delete' ],
unseen: [ 'hide' ],
warning: [ 'alert', 'caution' ],
Comment on lines +2 to +10
Copy link
Member Author

Choose a reason for hiding this comment

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

@WordPress/gutenberg-design I assume there will also be some keywords we don't want to add, to discourage people misusing icons for certain things? I added some obvious keywords to start, but let me know if there's something that should be removed. (Maybe we could document those no-nos.)

};

export default keywords;
Loading