mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-09 06:12:28 +02:00
wip showcase provider :D
This commit is contained in:
parent
ff168196c1
commit
52bf244c97
7 changed files with 72 additions and 42 deletions
|
@ -19,8 +19,6 @@ import type {
|
||||||
ShowcaseItem,
|
ShowcaseItem,
|
||||||
} from '@docusaurus/plugin-content-showcase';
|
} from '@docusaurus/plugin-content-showcase';
|
||||||
|
|
||||||
export const clientShowcase = 42;
|
|
||||||
|
|
||||||
export function filterUsers({
|
export function filterUsers({
|
||||||
users,
|
users,
|
||||||
tags,
|
tags,
|
||||||
|
|
|
@ -280,13 +280,7 @@ declare module '@theme/Showcase/ShowcaseCard' {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@theme/Showcase/ShowcaseCards' {
|
declare module '@theme/Showcase/ShowcaseCards' {
|
||||||
import type {ShowcaseItem} from '@docusaurus/plugin-content-showcase';
|
export default function ShowcaseCards(): JSX.Element;
|
||||||
|
|
||||||
export interface Props {
|
|
||||||
readonly users: ShowcaseItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ShowcaseCards(props: Props): JSX.Element;
|
|
||||||
}
|
}
|
||||||
declare module '@theme/Showcase/ShowcaseTooltip' {
|
declare module '@theme/Showcase/ShowcaseTooltip' {
|
||||||
export interface Props {
|
export interface Props {
|
||||||
|
@ -318,13 +312,7 @@ declare module '@theme/Showcase/ShowcaseFilterToggle' {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@theme/Showcase/ShowcaseFilters' {
|
declare module '@theme/Showcase/ShowcaseFilters' {
|
||||||
import type {ShowcaseItem} from '@docusaurus/plugin-content-showcase';
|
export default function ShowcaseFilters(): JSX.Element;
|
||||||
|
|
||||||
export interface Props {
|
|
||||||
readonly users: ShowcaseItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ShowcaseFilters(props: Props): JSX.Element;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module '@theme/Showcase/OperatorButton' {
|
declare module '@theme/Showcase/OperatorButton' {
|
||||||
|
|
|
@ -12,10 +12,10 @@ import {
|
||||||
useFilteredUsers,
|
useFilteredUsers,
|
||||||
sortUsers,
|
sortUsers,
|
||||||
} from '@docusaurus/plugin-content-showcase/client';
|
} from '@docusaurus/plugin-content-showcase/client';
|
||||||
|
import {useShowcase} from '@docusaurus/theme-common/internal';
|
||||||
import Heading from '@theme/Heading';
|
import Heading from '@theme/Heading';
|
||||||
import FavoriteIcon from '@theme/Showcase/FavoriteIcon';
|
import FavoriteIcon from '@theme/Showcase/FavoriteIcon';
|
||||||
import ShowcaseCard from '@theme/Showcase/ShowcaseCard';
|
import ShowcaseCard from '@theme/Showcase/ShowcaseCard';
|
||||||
import type {Props} from '@theme/Showcase/ShowcaseCards';
|
|
||||||
import type {ShowcaseItem} from '@docusaurus/plugin-content-showcase';
|
import type {ShowcaseItem} from '@docusaurus/plugin-content-showcase';
|
||||||
|
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
@ -74,14 +74,16 @@ function NoResultSection() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ShowcaseCards(props: Props): JSX.Element {
|
export default function ShowcaseCards(): JSX.Element {
|
||||||
const filteredUsers = useFilteredUsers(props.users);
|
const users = useShowcase().items;
|
||||||
|
|
||||||
|
const filteredUsers = useFilteredUsers(users);
|
||||||
|
|
||||||
if (filteredUsers.length === 0) {
|
if (filteredUsers.length === 0) {
|
||||||
return <NoResultSection />;
|
return <NoResultSection />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedUsers = sortUsers(props.users);
|
const sortedUsers = sortUsers(users);
|
||||||
|
|
||||||
const favoriteUsers = sortedUsers.filter((user: ShowcaseItem) =>
|
const favoriteUsers = sortedUsers.filter((user: ShowcaseItem) =>
|
||||||
user.tags.includes('favorite'),
|
user.tags.includes('favorite'),
|
||||||
|
|
|
@ -14,12 +14,12 @@ import {
|
||||||
Tags,
|
Tags,
|
||||||
TagList,
|
TagList,
|
||||||
} from '@docusaurus/plugin-content-showcase/client';
|
} from '@docusaurus/plugin-content-showcase/client';
|
||||||
|
import {useShowcase} from '@docusaurus/theme-common/internal';
|
||||||
import FavoriteIcon from '@theme/Showcase/FavoriteIcon';
|
import FavoriteIcon from '@theme/Showcase/FavoriteIcon';
|
||||||
import Heading from '@theme/Heading';
|
import Heading from '@theme/Heading';
|
||||||
import ShowcaseTagSelect from '@theme/Showcase/ShowcaseTagSelect';
|
import ShowcaseTagSelect from '@theme/Showcase/ShowcaseTagSelect';
|
||||||
import OperatorButton from '@theme/Showcase/OperatorButton';
|
import OperatorButton from '@theme/Showcase/OperatorButton';
|
||||||
import ClearAllButton from '@theme/Showcase/ClearAllButton';
|
import ClearAllButton from '@theme/Showcase/ClearAllButton';
|
||||||
import type {Props} from '@theme/Showcase/ShowcaseFilters';
|
|
||||||
import type {TagType} from '@docusaurus/plugin-content-showcase';
|
import type {TagType} from '@docusaurus/plugin-content-showcase';
|
||||||
|
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
@ -74,8 +74,9 @@ function ShowcaseTagList() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function HeadingText(props: Props) {
|
function HeadingText() {
|
||||||
const filteredUsers = useFilteredUsers(props.users);
|
const users = useShowcase().items;
|
||||||
|
const filteredUsers = useFilteredUsers(users);
|
||||||
const siteCountPlural = useSiteCountPlural();
|
const siteCountPlural = useSiteCountPlural();
|
||||||
return (
|
return (
|
||||||
<div className={styles.headingText}>
|
<div className={styles.headingText}>
|
||||||
|
@ -96,19 +97,19 @@ function HeadingButtons() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function HeadingRow(props: Props) {
|
function HeadingRow() {
|
||||||
return (
|
return (
|
||||||
<div className={clsx('margin-bottom--sm', styles.headingRow)}>
|
<div className={clsx('margin-bottom--sm', styles.headingRow)}>
|
||||||
<HeadingText users={props.users} />
|
<HeadingText />
|
||||||
<HeadingButtons />
|
<HeadingButtons />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ShowcaseFilters(props: Props): ReactNode {
|
export default function ShowcaseFilters(): ReactNode {
|
||||||
return (
|
return (
|
||||||
<section className="container margin-top--l margin-bottom--lg">
|
<section className="container margin-top--l margin-bottom--lg">
|
||||||
<HeadingRow users={props.users} />
|
<HeadingRow />
|
||||||
<ShowcaseTagList />
|
<ShowcaseTagList />
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import Translate, {translate} from '@docusaurus/Translate';
|
import Translate, {translate} from '@docusaurus/Translate';
|
||||||
|
|
||||||
import Link from '@docusaurus/Link';
|
import Link from '@docusaurus/Link';
|
||||||
import {clientShowcase} from '@docusaurus/plugin-content-showcase/client';
|
import {ShowcaseProvider} from '@docusaurus/theme-common/internal';
|
||||||
import Layout from '@theme/Layout';
|
import Layout from '@theme/Layout';
|
||||||
import Heading from '@theme/Heading';
|
import Heading from '@theme/Heading';
|
||||||
|
|
||||||
|
@ -40,19 +40,19 @@ function ShowcaseHeader() {
|
||||||
export default function Showcase(props: Props): JSX.Element {
|
export default function Showcase(props: Props): JSX.Element {
|
||||||
const users = props.content;
|
const users = props.content;
|
||||||
return (
|
return (
|
||||||
|
<ShowcaseProvider content={{items: users}}>
|
||||||
<Layout title={TITLE} description={DESCRIPTION}>
|
<Layout title={TITLE} description={DESCRIPTION}>
|
||||||
{/* eslint-disable-next-line @docusaurus/prefer-docusaurus-heading, @docusaurus/no-untranslated-text */}
|
|
||||||
<h1>Client showcase API: {clientShowcase}</h1>
|
|
||||||
<main className="margin-vert--lg">
|
<main className="margin-vert--lg">
|
||||||
<ShowcaseHeader />
|
<ShowcaseHeader />
|
||||||
<ShowcaseFilters users={users} />
|
<ShowcaseFilters />
|
||||||
<div
|
<div
|
||||||
style={{display: 'flex', marginLeft: 'auto'}}
|
style={{display: 'flex', marginLeft: 'auto'}}
|
||||||
className="container">
|
className="container">
|
||||||
<ShowcaseSearchBar />
|
<ShowcaseSearchBar />
|
||||||
</div>
|
</div>
|
||||||
<ShowcaseCards users={users} />
|
<ShowcaseCards />
|
||||||
</main>
|
</main>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
</ShowcaseProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
40
packages/docusaurus-theme-common/src/contexts/showcase.tsx
Normal file
40
packages/docusaurus-theme-common/src/contexts/showcase.tsx
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, {useMemo, type ReactNode, useContext} from 'react';
|
||||||
|
import {ReactContextError} from '../utils/reactUtils';
|
||||||
|
import type {ShowcaseItems} from '@docusaurus/plugin-content-showcase';
|
||||||
|
|
||||||
|
const Context = React.createContext<ShowcaseItems | null>(null);
|
||||||
|
|
||||||
|
function useContextValue(content: ShowcaseItems): ShowcaseItems {
|
||||||
|
return useMemo(
|
||||||
|
() => ({
|
||||||
|
items: content.items,
|
||||||
|
}),
|
||||||
|
[content],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ShowcaseProvider({
|
||||||
|
children,
|
||||||
|
content,
|
||||||
|
}: {
|
||||||
|
children: ReactNode;
|
||||||
|
content: ShowcaseItems;
|
||||||
|
}): JSX.Element {
|
||||||
|
const contextValue = useContextValue(content);
|
||||||
|
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useShowcase(): ShowcaseItems {
|
||||||
|
const showcase = useContext(Context);
|
||||||
|
if (showcase === null) {
|
||||||
|
throw new ReactContextError('ShowcaseProvider');
|
||||||
|
}
|
||||||
|
return showcase;
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ export {DocsVersionProvider, useDocsVersion} from './contexts/docsVersion';
|
||||||
export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar';
|
export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar';
|
||||||
|
|
||||||
export {DocProvider, useDoc, type DocContextValue} from './contexts/doc';
|
export {DocProvider, useDoc, type DocContextValue} from './contexts/doc';
|
||||||
|
export {ShowcaseProvider, useShowcase} from './contexts/showcase';
|
||||||
export {
|
export {
|
||||||
BlogPostProvider,
|
BlogPostProvider,
|
||||||
useBlogPost,
|
useBlogPost,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue