Standardize CodeBlock component

Summary:
Code blocks are quite common in Flipper, and a bit verbose in Ant, so let's standardize!

Changelog: Standardize CodeBlock component

Reviewed By: passy

Differential Revision: D28117560

fbshipit-source-id: 5a5538a49b59ef40c814d22055fac56e7598cbbb
This commit is contained in:
Michel Weststrate
2021-05-04 13:49:11 -07:00
committed by Facebook GitHub Bot
parent dd7a9f5195
commit 5bf9541e05
8 changed files with 48 additions and 11 deletions

View File

@@ -10,7 +10,7 @@
import styled from '@emotion/styled'; import styled from '@emotion/styled';
/** /**
* @deprecated, use <Typography.Paragraph><pre>.... instead. * @deprecated, use CodeBlock from flipper-plugin instead
*/ */
const CodeBlock = styled.div({ const CodeBlock = styled.div({
fontFamily: 'monospace', fontFamily: 'monospace',

View File

@@ -28,6 +28,7 @@ test('Correct top level API exposed', () => {
// Note, all `exposedAPIs` should be documented in `flipper-plugin.mdx` // Note, all `exposedAPIs` should be documented in `flipper-plugin.mdx`
expect(exposedAPIs.sort()).toMatchInlineSnapshot(` expect(exposedAPIs.sort()).toMatchInlineSnapshot(`
Array [ Array [
"CodeBlock",
"DataDescription", "DataDescription",
"DataFormatter", "DataFormatter",
"DataInspector", "DataInspector",

View File

@@ -59,6 +59,7 @@ export {Sidebar as _Sidebar} from './ui/Sidebar';
export {DetailSidebar} from './ui/DetailSidebar'; export {DetailSidebar} from './ui/DetailSidebar';
export {Toolbar} from './ui/Toolbar'; export {Toolbar} from './ui/Toolbar';
export {MasterDetail} from './ui/MasterDetail'; export {MasterDetail} from './ui/MasterDetail';
export {CodeBlock} from './ui/CodeBlock';
export {renderReactRoot} from './utils/renderReactRoot'; export {renderReactRoot} from './utils/renderReactRoot';
export { export {

View File

@@ -0,0 +1,32 @@
/**
* 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.
*
* @format
*/
import React from 'react';
import {Typography} from 'antd';
import styled from '@emotion/styled';
import {ParagraphProps} from 'antd/lib/typography/Paragraph';
export function CodeBlock({children, ...props}: ParagraphProps) {
return (
<StyledParagrah {...props}>
<pre>{children}</pre>
</StyledParagrah>
);
}
const StyledParagrah = styled(Typography.Paragraph)({
padding: 0,
fontSize: '9pt',
'&.ant-typography': {
margin: 0,
},
'& pre': {
margin: 0,
},
});

View File

@@ -78,7 +78,7 @@ const StyledCollapse = styled(Collapse)({
padding: `5px 0px`, padding: `5px 0px`,
left: 8, left: 8,
fontSize: '10px', fontSize: '10px',
fontWeight: 'bold', fontWeight: theme.bold,
}, },
}, },
'& > .ant-collapse-item': { '& > .ant-collapse-item': {

View File

@@ -190,13 +190,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
minHeight={minHeight} minHeight={minHeight}
maxHeight={maxHeight} maxHeight={maxHeight}
height={ height={
!horizontal !horizontal ? (onResize ? height : this.state.height) : undefined
? onResize
? height
: this.state.height
: gutter
? undefined
: '100%'
} }
resizable={resizable} resizable={resizable}
onResize={this.onResize} onResize={this.onResize}

View File

@@ -45,9 +45,14 @@ export const theme = {
fontFamily: 'SF Mono,Monaco,Andale Mono,monospace', fontFamily: 'SF Mono,Monaco,Andale Mono,monospace',
fontSize: '12px', fontSize: '12px',
} as const, } as const,
bold: 600,
} as const; } as const;
export type Spacing = keyof typeof theme['space'] | number | undefined | true; export type Spacing =
| keyof typeof theme['space']
| number
| undefined
| boolean;
export type PaddingProps = { export type PaddingProps = {
padv?: Spacing; padv?: Spacing;
@@ -72,7 +77,7 @@ export function normalizePadding({
export function normalizeSpace(spacing: Spacing, defaultSpace: number): number { export function normalizeSpace(spacing: Spacing, defaultSpace: number): number {
return spacing === true return spacing === true
? defaultSpace ? defaultSpace
: spacing === undefined : spacing === undefined || spacing === false
? 0 ? 0
: typeof spacing === 'string' : typeof spacing === 'string'
? theme.space[spacing] ? theme.space[spacing]

View File

@@ -873,6 +873,10 @@ The following additional properties are supported:
A horizontal panel to organize buttons and alike. Basically a `Layout.Horizontal` with a border, padding, gap and wrapping enabled. A horizontal panel to organize buttons and alike. Basically a `Layout.Horizontal` with a border, padding, gap and wrapping enabled.
### CodeBlock
A preformatted paragraph that supports wrapping, preserves whitespace and uses monospace.
### DataList ### DataList
The DataList can be used to display a set of items efficiently, and where a single item can be selected. The DataList can be used to display a set of items efficiently, and where a single item can be selected.