Skip to content

Commit

Permalink
fix(www): fixes bug in icon documentation and generates icons at buil…
Browse files Browse the repository at this point in the history
…d time
  • Loading branch information
matuzalemsteles committed Jan 29, 2025
1 parent 30a8bd7 commit 45adb4f
Show file tree
Hide file tree
Showing 5 changed files with 2,046 additions and 792 deletions.
34 changes: 18 additions & 16 deletions packages/clay-icon/docs/IconSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,21 @@ export const IconSearch = ({
label = 'Search Icons',
placeholder = 'Search Icons...',
source,
iconLabelFormatter = (icon) => icon.name,
type = 'icon',
}) => {
const [searchQuery, setSearchQuery] = useState('');

const data = useMemo(() => {
const keys = Object.keys(source);

return keys.map((key) => ({aliases: source[key], name: key}));
}, [source]);

const filteredIcons = useMemo(() => {
const query = searchQuery.toLowerCase();

return data.filter(
return source.filter(
({aliases, name}) =>
name.toLowerCase().includes(query) ||
aliases.some((alias) => alias.toLowerCase().includes(query))
);
}, [searchQuery, data]);
}, [searchQuery, source]);

const list = searchQuery ? filteredIcons : data;
const list = searchQuery ? filteredIcons : source;

return (
<>
Expand All @@ -60,13 +54,21 @@ export const IconSearch = ({
</ClayForm.Group>

<ul className="d-flex flex-wrap lexicon-icon-list list-unstyled">
{list.map((icon) => (
<li key={icon.name}>
<ClayIcon spritemap={spritemap} symbol={icon.name} />
{list.map((icon) => {
const name =
type === 'icon' ? icon.name : icon.aliases.join(' - ');

return (
<li key={icon.name}>
<ClayIcon
spritemap={spritemap}
symbol={icon.name}
/>

<span>{iconLabelFormatter(icon)}</span>
</li>
))}
<span>{name}</span>
</li>
);
})}
</ul>

{!list.length && (
Expand Down
Loading

0 comments on commit 45adb4f

Please sign in to comment.