mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 00:09:48 +02:00
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:
parent
0dd4892b0f
commit
1f1c7f1695
2 changed files with 13 additions and 21 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue