Commit 7e2fedb0 by Alex Khomenko Committed by GitHub

Storybook: Sort icons by name (#23115)

* Storybook: Sort icons by name

* Storybook: Add icon search
parent be157b84
import React from 'react'; import React, { ChangeEvent, useState } from 'react';
import { css } from 'emotion'; import { css } from 'emotion';
import { Forms } from '../index';
import { Icon } from './Icon'; import { Icon } from './Icon';
import { getAvailableIcons, IconType } from './types'; import { getAvailableIcons, IconType } from './types';
import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
...@@ -32,8 +33,6 @@ const IconWrapper: React.FC<{ name: IconType }> = ({ name }) => { ...@@ -32,8 +33,6 @@ const IconWrapper: React.FC<{ name: IconType }> = ({ name }) => {
<div <div
className={css` className={css`
width: 150px; width: 150px;
height: 60px;
display: table-cell;
padding: 12px; padding: 12px;
border: 1px solid ${borderColor}; border: 1px solid ${borderColor};
text-align: center; text-align: center;
...@@ -63,41 +62,42 @@ const IconWrapper: React.FC<{ name: IconType }> = ({ name }) => { ...@@ -63,41 +62,42 @@ const IconWrapper: React.FC<{ name: IconType }> = ({ name }) => {
); );
}; };
const icons = getAvailableIcons().sort((a, b) => a.localeCompare(b));
export const simple = () => { export const simple = () => {
const icons = getAvailableIcons(); const [filter, setFilter] = useState('');
const iconsPerRow = 10;
const rows: IconType[][] = [[]];
let rowIdx = 0;
icons.forEach((i: IconType, idx: number) => { const searchIcon = (event: ChangeEvent<HTMLInputElement>) => {
if (idx % iconsPerRow === 0) { setFilter(event.target.value);
rows.push([]); };
rowIdx++;
}
rows[rowIdx].push(i);
});
return ( return (
<div <div
className={css` className={css`
display: table; display: flex;
table-layout: fixed; flex-direction: column;
border-collapse: collapse; width: 100%;
`} `}
> >
{rows.map(r => { <Forms.Field
return ( className={css`
width: 300px;
`}
>
<Forms.Input onChange={searchIcon} placeholder="Search icons by name" />
</Forms.Field>
<div <div
className={css` className={css`
display: table-row; display: flex;
flex-wrap: wrap;
`} `}
> >
{r.map((i, index) => { {icons
return <IconWrapper name={i} />; .filter(val => val.includes(filter))
.map(i => {
return <IconWrapper name={i} key={i} />;
})} })}
</div> </div>
);
})}
</div> </div>
); );
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment