From d65aba19a0569562ecc9ce1d412d19c27c588b03 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sun, 29 Mar 2020 01:41:10 +0300 Subject: [PATCH] components uses css modules; other refactoring --- pages/document/[slug].tsx | 7 ++++- src/components/Block/index.tsx | 10 +++++-- .../Block/{styles.css => styles.module.css} | 4 +-- src/components/Breadcrumbs/index.tsx | 4 +-- .../{styles.css => styles.module.css} | 6 ----- src/components/Button/index.tsx | 17 +++++++++--- .../Button/{styles.css => styles.module.css} | 10 +++---- src/components/Card/index.tsx | 14 +++++++--- .../Card/{styles.css => styles.module.css} | 16 +++++++----- src/components/CardGrid/index.tsx | 4 +-- .../{styles.css => styles.module.css} | 4 +-- src/components/File/index.tsx | 24 ++++++++--------- .../File/{styles.css => styles.module.css} | 16 +++++++----- src/components/Image/index.tsx | 5 ++-- .../Image/{styles.css => styles.module.css} | 0 src/components/Menu/MenuItem.tsx | 6 ++--- src/components/Menu/index.tsx | 10 ++++--- .../Menu/{styles.css => styles.module.css} | 26 +++++++++---------- src/components/MenuToggle/index.tsx | 8 +++--- .../{styles.css => styles.module.css} | 0 src/components/Overlay/index.tsx | 4 +-- .../Overlay/{styles.css => styles.module.css} | 0 src/components/Page/index.tsx | 5 ++-- .../Page/{styles.css => styles.module.css} | 0 src/components/PageMeta/index.tsx | 6 +++-- .../{styles.css => styles.module.css} | 0 src/components/TagList/index.tsx | 11 +++++--- .../TagList/{styles.css => styles.module.css} | 14 ++++++---- 28 files changed, 137 insertions(+), 94 deletions(-) rename src/components/Block/{styles.css => styles.module.css} (81%) rename src/components/Breadcrumbs/{styles.css => styles.module.css} (62%) rename src/components/Button/{styles.css => styles.module.css} (88%) rename src/components/Card/{styles.css => styles.module.css} (88%) rename src/components/CardGrid/{styles.css => styles.module.css} (92%) rename src/components/File/{styles.css => styles.module.css} (65%) rename src/components/Image/{styles.css => styles.module.css} (100%) rename src/components/Menu/{styles.css => styles.module.css} (70%) rename src/components/MenuToggle/{styles.css => styles.module.css} (100%) rename src/components/Overlay/{styles.css => styles.module.css} (100%) rename src/components/Page/{styles.css => styles.module.css} (100%) rename src/components/PageMeta/{styles.css => styles.module.css} (100%) rename src/components/TagList/{styles.css => styles.module.css} (72%) diff --git a/pages/document/[slug].tsx b/pages/document/[slug].tsx index 09fa387c..32c7d4f5 100644 --- a/pages/document/[slug].tsx +++ b/pages/document/[slug].tsx @@ -28,7 +28,12 @@ const Index: NextPage = props => { {props.data.name} - + ) diff --git a/src/components/Block/index.tsx b/src/components/Block/index.tsx index 75c5c64c..02a5910e 100644 --- a/src/components/Block/index.tsx +++ b/src/components/Block/index.tsx @@ -1,4 +1,4 @@ -import './styles.css' +import s from './styles.module.css' import cx from 'classnames' import { createElement } from 'react' @@ -10,7 +10,13 @@ export type BlockProps = { } export const Block: React.FC = ({ as = 'div', style, direction, ...props }) => { - const newProps = { className: cx('block', direction), style } + const directionClass = direction === 'horizontal' + ? s.horizontal + : s.vertical + const newProps = { + className: cx(s.block, directionClass), + style, + } return createElement(as, newProps, props.children) } diff --git a/src/components/Block/styles.css b/src/components/Block/styles.module.css similarity index 81% rename from src/components/Block/styles.css rename to src/components/Block/styles.module.css index 13b9cb72..9676ac32 100644 --- a/src/components/Block/styles.css +++ b/src/components/Block/styles.module.css @@ -5,10 +5,10 @@ justify-content: flex-start; } -.block.horizontal { +.horizontal { flex-direction: row; } -.block.vertical { +.vertical { flex-direction: column; } diff --git a/src/components/Breadcrumbs/index.tsx b/src/components/Breadcrumbs/index.tsx index ee5ba6a7..b86b5e68 100644 --- a/src/components/Breadcrumbs/index.tsx +++ b/src/components/Breadcrumbs/index.tsx @@ -1,4 +1,4 @@ -import './styles.css' +import s from './styles.module.css' import { IBreadcumbsPart } from 'src/types' import { Button } from '../Button' @@ -14,7 +14,7 @@ export const Breadcrumbs: React.FC = props => { const items = insertBetween(props.items, () => '/') return ( -