Browse Source

[Beta] Fixes to blocks

main
Dan Abramov 2 years ago
parent
commit
c998108462
  1. 11
      beta/src/components/MDX/ConsoleBlock.tsx
  2. 2
      beta/src/components/MDX/TerminalBlock.tsx

11
beta/src/components/MDX/ConsoleBlock.tsx

@ -7,7 +7,7 @@ import cn from 'classnames';
import {IconWarning} from '../Icon/IconWarning'; import {IconWarning} from '../Icon/IconWarning';
import {IconError} from '../Icon/IconError'; import {IconError} from '../Icon/IconError';
type LogLevel = 'info' | 'warning' | 'error'; type LogLevel = 'warning' | 'error' | 'info';
interface ConsoleBlockProps { interface ConsoleBlockProps {
level?: LogLevel; level?: LogLevel;
@ -29,14 +29,11 @@ const Box = ({
); );
Box.displayName = 'Box'; Box.displayName = 'Box';
function ConsoleBlock({level = 'info', children}: ConsoleBlockProps) { function ConsoleBlock({level = 'error', children}: ConsoleBlockProps) {
let message: string | undefined; let message: React.ReactNode | null;
if (typeof children === 'string') { if (typeof children === 'string') {
message = children; message = children;
} else if ( } else if (React.isValidElement(children)) {
React.isValidElement(children) &&
typeof children.props.children === 'string'
) {
message = children.props.children; message = children.props.children;
} }

2
beta/src/components/MDX/TerminalBlock.tsx

@ -33,6 +33,8 @@ function TerminalBlock({level = 'info', children}: TerminalBlockProps) {
typeof children.props.children === 'string' typeof children.props.children === 'string'
) { ) {
message = children.props.children; message = children.props.children;
} else {
throw Error('Expected TerminalBlock children to be a plain string.');
} }
const [copied, setCopied] = React.useState(false); const [copied, setCopied] = React.useState(false);

Loading…
Cancel
Save