Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next 9.3 Sass Modules #94

Merged
merged 11 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ deploy-dev-from-local:

update:
npm run fetch-data

build-size:
npm run size
14 changes: 8 additions & 6 deletions components/admin/AdminLayout.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import './admin.scss';

import React from 'react';
import PropTypes from 'prop-types';
import bem from 'bem-css-modules';
import styles from './admin.module.scss';

import AdminSidebar from './AdminSidebar';

const b = bem(styles);

const AdminLayout = ({ children }) => (
<div className="admin-panel">
<div className="admin-panel-grid">
<div className="admin-panel-grid__aside">
<div className={b()}>
<div className={b('grid')}>
<div className={b('grid-aside')}>
<AdminSidebar />
</div>
<div className="admin-panel-grid__main">{children}</div>
<div className={b('grid-main')}>{children}</div>
</div>
</div>
);
Expand Down
9 changes: 5 additions & 4 deletions components/admin/AdminSidebar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './admin-sidebar.scss';

import React from 'react';
import { useRouter } from 'next/router';
import bem from 'bem-css-modules';

import Link from 'components/common/Link';
import Text from 'components/common/Text';
Expand All @@ -10,14 +9,16 @@ import Dispatcher from 'lib/components/Dispatcher';

import { authActions } from 'redux/ducks/auth';
import { ADMIN_ROUTES, ROUTES_NAMES } from 'routes';
import styles from './admin-sidebar.module.scss';

const b = bem(styles);
const IGNORE_ROUTES = ['login', 'preview'].map(page => ROUTES_NAMES.admin[page]);

const AdminSidebar = () => {
const router = useRouter();
return (
<div className="admin-sidebar">
<ul className="admin-sidebar-nav-list">
<div>
<ul className={b('nav-list')}>
{ADMIN_ROUTES.filter(({ name }) => !IGNORE_ROUTES.includes(name)).map(({ name, page }) => (
<li key={name}>
{/* FIXME: active */}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.admin-sidebar {
&-nav-list {
&__nav-list {
list-style-type: none;
margin: 0 0 30px;
padding: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.admin-panel {
padding: 0 90px 60px;

&-grid {
&__grid {
display: flex;

&__aside {
&-aside {
flex: 0 0 auto;
padding-right: 20px;
width: 100px;
}

&__main {
&-main {
flex: 1 1 auto;
font-size: 0.9rem;
}
Expand Down
35 changes: 19 additions & 16 deletions components/articles/Article.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'styles/pages/article.scss';

import React from 'react';
import { useRouter } from 'next/router';
import flatten from 'lodash/flatten';
import cn from 'classnames';
import bem from 'bem-css-modules';

import {
MetaTitle,
Expand All @@ -23,8 +23,11 @@ import { renderNodeList } from 'utils/formatters';
import fiberyRenderer from 'utils/fibery/renderer';
import host from 'utils/host';

import styles from './article.module.scss';

import CollectionNote from './CollectionNote';

const b = bem(styles);
const COVER_SIZES = [1200, 1000, 770, 640, 360];

const Article = ({
Expand All @@ -45,7 +48,7 @@ const Article = ({
}) => {
const router = useRouter();
const { brands, authors, ...tagsObject } = tagsByTopic;
const renderTagImage = getTagImageRenderer({ className: 'article-page__tag-image' });
const renderTagImage = getTagImageRenderer({ className: b('tag-image') });
UladBohdan marked this conversation as resolved.
Show resolved Hide resolved
const imageUrl = images.page || images.horizontal;
// https://caniuse.com/#feat=array-flat
const tags = flatten(Object.values(tagsObject));
Expand All @@ -59,31 +62,31 @@ const Article = ({
<MetaArticleItems name="author" list={authors.map(renderTag)} />
<MetaArticleItems name="tag" list={tags.map(renderTag)} />
<MetaArticleItems name="published_time" value={publishAt} />
<div className="article-page">
<div className="wir-content-padding article-page-content">
<div className="article-page__subtitle">{subtitle}</div>
<div>
<div className={cn('wir-content-padding', styles['article-page-content'])}>
<div className={b('subtitle')}>{subtitle}</div>
</div>
{type === 'text' && (
<Image
className="article-page__cover"
className={b('cover')}
alt={title}
sourceSizes={COVER_SIZES}
baseUrl={images.page}
/>
)}
</div>
<div className="wir-content-padding article-page__header">
<div className={cn('wir-content-padding', b('header'))}>
{/* TODO: hover corresponding image and title simultaneously */}
{(!!brands.length || !!authors.length) && (
<div className="article-page__tags">
<div className={b('tags')}>
{brands.concat(authors).map(tag =>
getTagLink({
className: 'article-page__tag-image-link',
className: b('tag-image-link'),
render: renderTagImage,
tag,
})
)}
<div className="article-page__tag-titles">
<div className={b('tag-titles')}>
<span>
{renderNodeList(brands.map(tag => getTagLink({ tag })))}
{!!brands.length && !!authors.length && ','}
Expand All @@ -92,24 +95,24 @@ const Article = ({
</div>
</div>
)}
<div className="article-page__title">{title}</div>
<div className={b('title')}>{title}</div>
</div>

<div className="wir-content-padding">
<div className="article-page-content">
<div className={styles['article-page-content']}>
{type === 'audio' && <AudioPlayer trackId={audio.id} />}
{type === 'video' && <VideoPlayer videoId={video.id} />}
{collection && collection.articles.length > 1 && (
<CollectionNote data={collection} locale={locale} />
)}
{fiberyRenderer(text.content)}
</div>
<div className="article-page__share">
<div className={b('share')}>
<ShareButtons urlPath={router.asPath} basicText={title} />
</div>
<div className="article-page__other-tags">
<div className={b('other-tags')}>
{tags.map(tag => (
<div key={tag.slug} className="article-page__other-tag">
<div key={tag.slug} className={b('other-tag')}>
{getTagLink({ tag })}
</div>
))}
Expand Down
21 changes: 14 additions & 7 deletions components/articles/CollectionNote.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import bem from 'bem-css-modules';

import { localize } from 'components/common/Text';
import Link from 'components/common/Link';
Expand All @@ -9,8 +10,12 @@ import { CollectionShape, LangType } from 'utils/customPropTypes';

import { ROUTES_NAMES } from 'routes';

const CollectionNoteItem = ({ hideLink, text, slug }) => (
<div className="article-page__collection-item">
UladBohdan marked this conversation as resolved.
Show resolved Hide resolved
import styles from './article.module.scss';

const b = bem(styles);

const CollectionNoteItem = ({ className, hideLink, text, slug }) => (
<div className={className}>
{hideLink ? (
text
) : (
Expand All @@ -22,32 +27,34 @@ const CollectionNoteItem = ({ hideLink, text, slug }) => (
);

CollectionNoteItem.propTypes = {
className: PropTypes.string.isRequired,
hideLink: PropTypes.bool.isRequired,
text: PropTypes.string.isRequired,
slug: PropTypes.string.isRequired,
};

const CollectionNote = ({ locale, data: { cover, articleIndex = 0, name, articles } }) => (
<div className="article-page__collection">
<div className={b('collection')}>
{cover && (
<Image
className="article-page__collection-cover"
className={b('collection-cover')}
alt={name}
sourceSizes={[70]}
baseUrl={cover}
mode="x"
/>
)}
<div className="article-page__collection-items">
<div className="article-page__collection-item">
<div className={b('collection-items')}>
<div className={b('collection-item')}>
{localize('article.this-is-the', locale)} {` ${articleIndex + 1} `}
{localize('article.of-collection', locale)}
<br />
<span className="article-page__collection-name">{name}</span>
<span className={b('collection-name')}>{name}</span>
</div>
{articles.map(({ _id, slug, title }, i) => (
<CollectionNoteItem
key={_id}
className={b('collection-item')}
hideLink={articleIndex === i}
text={`${i + 1}. ${title}`}
slug={slug}
Expand Down
Loading