|
| 1 | +import { Fragment } from 'react'; |
| 2 | +import styled from 'styled-components'; |
| 3 | +import { Link } from 'react-router-dom'; |
| 4 | +import CodeMirror from '@uiw/react-codemirror'; |
| 5 | +import { color } from '@uiw/codemirror-extensions-color'; |
| 6 | +import { langs } from '@uiw/codemirror-extensions-langs'; |
| 7 | +import { SiderMenus } from '../themes/SiderMenus'; |
| 8 | +import { Warpper } from '../../../components/Warpper'; |
| 9 | +import { themeData } from '../themes/Datas'; |
| 10 | +import { toSnakeCase } from '../themes/Document'; |
| 11 | + |
| 12 | +export const toTitleCase = (str: string = '') => |
| 13 | + str |
| 14 | + .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) |
| 15 | + ?.map((x) => x.charAt(0).toUpperCase() + x.slice(1)) |
| 16 | + .join(' '); |
| 17 | + |
| 18 | +const ThemesWarpper = styled.div` |
| 19 | + grid-template-columns: repeat(3, minmax(0, 1fr)); |
| 20 | + gap: 2.5rem; |
| 21 | + display: grid; |
| 22 | + padding: 2.6rem; |
| 23 | + a { |
| 24 | + text-decoration: none; |
| 25 | + } |
| 26 | + @media (max-width: 1280px) { |
| 27 | + grid-template-columns: repeat(3, minmax(0, 1fr)); |
| 28 | + } |
| 29 | + @media (max-width: 1024px) { |
| 30 | + grid-template-columns: repeat(2, minmax(0, 1fr)); |
| 31 | + } |
| 32 | + @media (max-width: 860px) { |
| 33 | + grid-template-columns: repeat(1, minmax(0, 1fr)); |
| 34 | + } |
| 35 | +`; |
| 36 | + |
| 37 | +const ThemeCard = styled.div` |
| 38 | + padding: 1rem; |
| 39 | + box-shadow: 0 0 #0000, 0 0 #0000, 0 0 #0000, 0 1px 2px 0 rgba(0, 0, 0, 0.05); |
| 40 | + border-radius: 0.5rem; |
| 41 | + border: 1px solid var(--color-neutral-muted); |
| 42 | + background-color: var(--color-canvas-subtle); |
| 43 | + transition-property: all; |
| 44 | + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); |
| 45 | + transition-duration: 0.2s; |
| 46 | + &:hover { |
| 47 | + transform: translate(0, -0.25rem) rotate(0) skewX(0) skewY(0) scaleX(1) scaleY(1); |
| 48 | + } |
| 49 | +`; |
| 50 | + |
| 51 | +const Title = styled.div` |
| 52 | + font-weight: 600; |
| 53 | + padding-bottom: 0.68rem; |
| 54 | +`; |
| 55 | + |
| 56 | +const codeString = `import React, {useState} from 'react'; |
| 57 | +
|
| 58 | +// My favorite component |
| 59 | +const Counter = () => { |
| 60 | + const [value, setValue] = useState(0); |
| 61 | +
|
| 62 | + return <span>{value}</span>; |
| 63 | +};`; |
| 64 | + |
| 65 | +export function ThemesHome() { |
| 66 | + return ( |
| 67 | + <Fragment> |
| 68 | + <SiderMenus /> |
| 69 | + <Warpper> |
| 70 | + <ThemesWarpper> |
| 71 | + {Object.keys(themeData).map((name, idx) => { |
| 72 | + const [_name, _theme] = toSnakeCase(name) || []; |
| 73 | + return ( |
| 74 | + <Link key={idx} to={`/theme/data/${_name}${_theme ? `/${_theme}` : ''}`}> |
| 75 | + <ThemeCard> |
| 76 | + <Title>{toTitleCase(name)}</Title> |
| 77 | + <CodeMirror |
| 78 | + value={codeString} |
| 79 | + height="165px" |
| 80 | + theme={themeData[name as keyof typeof themeData]} |
| 81 | + extensions={[color, langs.jsx()]} |
| 82 | + /> |
| 83 | + </ThemeCard> |
| 84 | + </Link> |
| 85 | + ); |
| 86 | + })} |
| 87 | + </ThemesWarpper> |
| 88 | + </Warpper> |
| 89 | + </Fragment> |
| 90 | + ); |
| 91 | +} |
0 commit comments