Skip to content

Commit 045ef0a

Browse files
committed
temp: conditional to if
1 parent 765d536 commit 045ef0a

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/components/Layout/MDXWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '../../styles/global.css';
55
import PageTitle from '../PageTitle';
66
import { MarkdownProvider } from '../Markdown';
77
import Article from '../Article';
8-
import Conditional from './mdx/Conditional';
8+
import If from './mdx/If';
99
import CodeBlock from './mdx/CodeBlock';
1010

1111
type PageContextType = {
@@ -23,7 +23,7 @@ const MDXWrapper: React.FC<MDXWrapperProps> = ({ children, pageContext }) => {
2323

2424
return (
2525
<Article>
26-
<MarkdownProvider extraComponents={{ Conditional, CodeBlock }}>
26+
<MarkdownProvider components={{ If, CodeBlock }}>
2727
{title && <PageTitle>{title}</PageTitle>}
2828
{children}
2929
</MarkdownProvider>

src/components/Layout/mdx/Conditional.tsx renamed to src/components/Layout/mdx/If.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import React from 'react';
22
import { useLayoutContext } from 'src/contexts/layout-context';
33
import { LanguageKey } from 'src/data/languages/types';
44

5-
interface ConditionalProps {
5+
interface IfProps {
66
lang: LanguageKey;
7+
className?: string;
78
children: React.ReactNode;
9+
as?: React.ElementType;
810
}
911

10-
const Conditional: React.FC<ConditionalProps> = ({ lang, children }) => {
12+
const If: React.FC<IfProps> = ({ lang, children, className, as: Component = 'div' }) => {
1113
const { activePage } = useLayoutContext();
1214
const { language } = activePage;
1315
const splitLang = lang.split(',');
1416

1517
return splitLang.includes(language) ? children : null;
1618
};
1719

18-
export default Conditional;
20+
export default If;

src/components/Markdown/MarkdownProvider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const Pre: FC<JSX.IntrinsicElements['pre']> = ({ children }) => {
8989
);
9090
};
9191

92-
const components = {
92+
const defaultComponents = {
9393
h1: H1,
9494
h2: H2,
9595
h3: H3,
@@ -103,9 +103,9 @@ const components = {
103103

104104
export const MarkdownProvider = ({
105105
children,
106-
extraComponents,
106+
components,
107107
}: {
108108
children: React.ReactNode;
109109
// eslint-disable-next-line @typescript-eslint/no-explicit-any
110-
extraComponents?: Record<string, React.FC<any>>;
111-
}) => <MDXProvider components={{ ...components, ...extraComponents }}>{children}</MDXProvider>;
110+
components: Record<string, React.FC<any>>;
111+
}) => <MDXProvider components={{ ...defaultComponents, ...components }}>{children}</MDXProvider>;

src/pages/docs/chat/index.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Ably Chat provides the following key features:
1818
- [Typing indicators](#typing)
1919
- [Room reactions](#reactions)
2020

21+
<If lang="javascript,react,swift">
22+
start
23+
<If lang="javascript">hello matey</If>
24+
<If lang="react">hello pal</If>
25+
<If lang="swift">hello sir</If>
26+
end
27+
</If>
28+
2129
### Rooms and messages
2230

2331
[Rooms](/docs/chat/rooms) are used to organize and separate your users and chat messages into 'chat rooms'. They are the entry object into chat and provide access to all other chat features, such as messages, online status, and typing indicators.

0 commit comments

Comments
 (0)