Skip to content

Commit

Permalink
refactor: make dynamic authors layout via CSS only (#5424)
Browse files Browse the repository at this point in the history
* refactor: make dynamic authors layout via CSS only

* Clarify author class name
  • Loading branch information
lex111 authored Aug 26, 2021
1 parent 0dd4892 commit 1f1c7f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 1f1c7f1

Please sign in to comment.