From 7e2fedb0ccfa7766ab7be8b1916286dfb8bdd735 Mon Sep 17 00:00:00 2001 From: Alex Khomenko Date: Fri, 27 Mar 2020 11:09:23 +0200 Subject: [PATCH] Storybook: Sort icons by name (#23115) * Storybook: Sort icons by name * Storybook: Add icon search --- .../src/components/Icon/Icon.story.tsx | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/grafana-ui/src/components/Icon/Icon.story.tsx b/packages/grafana-ui/src/components/Icon/Icon.story.tsx index 3fc4d882c72..cc1954f4a97 100644 --- a/packages/grafana-ui/src/components/Icon/Icon.story.tsx +++ b/packages/grafana-ui/src/components/Icon/Icon.story.tsx @@ -1,6 +1,7 @@ -import React from 'react'; +import React, { ChangeEvent, useState } from 'react'; import { css } from 'emotion'; +import { Forms } from '../index'; import { Icon } from './Icon'; import { getAvailableIcons, IconType } from './types'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; @@ -32,8 +33,6 @@ const IconWrapper: React.FC<{ name: IconType }> = ({ name }) => {
= ({ name }) => { ); }; -export const simple = () => { - const icons = getAvailableIcons(); - const iconsPerRow = 10; - const rows: IconType[][] = [[]]; - let rowIdx = 0; +const icons = getAvailableIcons().sort((a, b) => a.localeCompare(b)); - icons.forEach((i: IconType, idx: number) => { - if (idx % iconsPerRow === 0) { - rows.push([]); - rowIdx++; - } - rows[rowIdx].push(i); - }); +export const simple = () => { + const [filter, setFilter] = useState(''); + + const searchIcon = (event: ChangeEvent) => { + setFilter(event.target.value); + }; return (
- {rows.map(r => { - return ( -
- {r.map((i, index) => { - return ; - })} -
- ); - })} + + + +
+ {icons + .filter(val => val.includes(filter)) + .map(i => { + return ; + })} +
); };