|
| 1 | +import React, { useState } from 'react'; |
| 2 | + |
| 3 | +import type { Meta, StoryObj } from '@storybook/react'; |
| 4 | + |
| 5 | +import colors from '!!raw-loader!../packages/assets/src/scss/variables/_colors.scss'; |
| 6 | + |
| 7 | +const colorsList = colors |
| 8 | + .split('\n') |
| 9 | + .map((line: string) => { |
| 10 | + const [name, hex] = line.split(/:\s*|\s+/).map((item) => item.trim()); |
| 11 | + |
| 12 | + if (!name || !hex.startsWith('#')) { |
| 13 | + return undefined; |
| 14 | + } |
| 15 | + |
| 16 | + return { |
| 17 | + name: name.replace('$color-', ''), |
| 18 | + hex, |
| 19 | + }; |
| 20 | + }) |
| 21 | + .filter((item) => item !== undefined); |
| 22 | + |
| 23 | +// TODO: remove temporary styles when scss is available |
| 24 | + |
| 25 | +const ColorsList = () => { |
| 26 | + const [searchValue, setSearchValue] = useState(''); |
| 27 | + const iconsRows = colorsList |
| 28 | + .filter(({ name }) => searchValue === '' || name.includes(searchValue)) |
| 29 | + .map(({ name, hex }) => { |
| 30 | + return ( |
| 31 | + <tr className="ids-table__row" key={name}> |
| 32 | + <td className="ids-table__cell" style={{ padding: '10px' }}> |
| 33 | + {name} |
| 34 | + </td> |
| 35 | + <td className="ids-table__cell" style={{ padding: '10px' }}> |
| 36 | + {hex} |
| 37 | + </td> |
| 38 | + <td className="ids-table__cell" style={{ padding: 0 }}> |
| 39 | + <div |
| 40 | + style={{ |
| 41 | + width: '40px', |
| 42 | + height: '40px', |
| 43 | + backgroundColor: hex, |
| 44 | + }} |
| 45 | + /> |
| 46 | + </td> |
| 47 | + </tr> |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + return ( |
| 52 | + <div style={{ display: 'flex', justifyContent: 'center' }}> |
| 53 | + <div> |
| 54 | + <input |
| 55 | + className="ids-input ids-input--text" |
| 56 | + onChange={(event) => { |
| 57 | + setSearchValue(event.target.value); |
| 58 | + }} |
| 59 | + placeholder="Search colors..." |
| 60 | + style={{ marginBottom: '10px' }} |
| 61 | + type="text" |
| 62 | + /> |
| 63 | + <table border={1} className="ids-table"> |
| 64 | + <tbody className="ids-table__body">{iconsRows}</tbody> |
| 65 | + </table> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + ); |
| 69 | +}; |
| 70 | + |
| 71 | +const meta: Meta<typeof ColorsList> = { |
| 72 | + component: ColorsList, |
| 73 | + parameters: { |
| 74 | + layout: 'padded', |
| 75 | + }, |
| 76 | + tags: [], |
| 77 | +}; |
| 78 | + |
| 79 | +export default meta; |
| 80 | + |
| 81 | +type Story = StoryObj<typeof ColorsList>; |
| 82 | + |
| 83 | +export const Default: Story = { |
| 84 | + name: 'Default', |
| 85 | +}; |
0 commit comments