refactor: make dynamic authors layout via CSS only (#5424)

* refactor: make dynamic authors layout via CSS only

* Clarify author class name
This commit is contained in:
Alexey Pyltsyn 2021-08-26 17:49:49 +03:00 committed by GitHub
parent 0dd4892b0f
commit 1f1c7f1695
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 21 deletions

View file

@ -10,26 +10,7 @@ import clsx from 'clsx';
import type {Props} from '@theme/BlogPostAuthors';
import BlogPostAuthor from '@theme/BlogPostAuthor';
function getAuthorsPerLine(authorsCount: number): 1 | 2 {
switch (authorsCount) {
case 0:
case 1:
return 1;
default:
return 2;
}
}
function getColClassName(authorsCount: number): string {
switch (getAuthorsPerLine(authorsCount)) {
case 1:
return 'col--12';
case 2:
return 'col--6';
default:
throw Error('unexpected');
}
}
import styles from './styles.module.css';
// Component responsible for the authors layout
export default function BlogPostAuthors({authors, assets}: Props): JSX.Element {
@ -40,7 +21,7 @@ export default function BlogPostAuthors({authors, assets}: Props): JSX.Element {
return (
<div className="row margin-top--md margin-bottom--sm">
{authors.map((author, idx) => (
<div className={clsx('col', getColClassName(authorsCount))} key={idx}>
<div className={clsx('col col--6', styles.authorCol)} key={idx}>
<BlogPostAuthor
author={{
...author,

View file

@ -0,0 +1,11 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
.authorCol {
max-width: inherit !important;
flex-grow: 1 !important;
}