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

fix(theme): fix <DocCard> height inconsistency #10849

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,9 @@ declare module '@theme/DocPaginator' {
import type {PropNavigation} from '@docusaurus/plugin-content-docs';

// May be simpler to provide a {navigation: PropNavigation} prop?
export interface Props extends PropNavigation {}
export interface Props extends PropNavigation {
className?: string;
}

export default function DocPaginator(props: Props): ReactNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,33 @@
* LICENSE file in the root directory of this source tree.
*/

import React, {type ReactNode} from 'react';
import React, {type ComponentProps, type ReactNode} from 'react';
import clsx from 'clsx';
import {
useCurrentSidebarSiblings,
filterDocCardListItems,
} from '@docusaurus/plugin-content-docs/client';
import DocCard from '@theme/DocCard';
import type {Props} from '@theme/DocCardList';
import styles from './styles.module.css';

function DocCardListForCurrentSidebarCategory({className}: Props) {
const items = useCurrentSidebarSiblings();
return <DocCardList items={items} className={className} />;
}

function DocCardListItem({
item,
}: {
item: ComponentProps<typeof DocCard>['item'];
}) {
return (
<article className={clsx(styles.docCardListItem, 'col col--6')}>
<DocCard item={item} />
</article>
);
}

export default function DocCardList(props: Props): ReactNode {
const {items, className} = props;
if (!items) {
Expand All @@ -28,9 +41,7 @@ export default function DocCardList(props: Props): ReactNode {
return (
<section className={clsx('row', className)}>
{filteredItems.map((item, index) => (
<article key={index} className="col col--6 margin-bottom--lg">
<DocCard item={item} />
</article>
<DocCardListItem key={index} item={item} />
))}
</section>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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.
*/

.docCardListItem {
margin-bottom: 2rem;
}

.docCardListItem > * {
height: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function DocCategoryGeneratedIndexPageContent({
<article className="margin-top--lg">
<DocCardList items={category.items} className={styles.list} />
</article>
<footer className="margin-top--lg">
<footer className="margin-top--md">
<DocPaginator
previous={categoryGeneratedIndex.navigation.previous}
next={categoryGeneratedIndex.navigation.next}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,10 @@
.generatedIndexPage {
max-width: 75% !important;
}

.list article:nth-last-child(-n + 2) {
margin-bottom: 0 !important;
}
}

/* Duplicated from .markdown h1 */
.title {
--ifm-h1-font-size: 3rem;
margin-bottom: calc(1.25 * var(--ifm-leading));
}

.list article:last-child {
margin-bottom: 0 !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ import DocPaginator from '@theme/DocPaginator';
*/
export default function DocItemPaginator(): ReactNode {
const {metadata} = useDoc();
return <DocPaginator previous={metadata.previous} next={metadata.next} />;
return (
<DocPaginator
className="docusaurus-mt-lg"
previous={metadata.previous}
next={metadata.next}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
*/

import React, {type ReactNode} from 'react';
import clsx from 'clsx';
import Translate, {translate} from '@docusaurus/Translate';
import PaginatorNavLink from '@theme/PaginatorNavLink';
import type {Props} from '@theme/DocPaginator';

export default function DocPaginator(props: Props): ReactNode {
const {previous, next} = props;
const {className, previous, next} = props;
return (
<nav
className="pagination-nav docusaurus-mt-lg"
className={clsx(className, 'pagination-nav')}
aria-label={translate({
id: 'theme.docs.paginator.navAriaLabel',
message: 'Docs pages',
Expand Down