Merge pull request #330 from iclanton/clean-up-react-components

Clean up some functional components.
This commit is contained in:
Pete Gonzalez 2023-05-03 11:05:42 -07:00 коммит произвёл GitHub
Родитель f4b9d8659a 74577c78b9
Коммит a4114a0538
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 124 добавлений и 146 удалений

Просмотреть файл

@ -1,14 +1,10 @@
import * as React from 'react'; import * as React from 'react';
import { PlaygroundView } from './PlaygroundView'; import { PlaygroundView } from './PlaygroundView';
class App extends React.Component { export default function App(): JSX.Element {
public render(): React.ReactNode {
return ( return (
<> <>
<PlaygroundView /> <PlaygroundView />
</> </>
); );
} }
}
export default App;

Просмотреть файл

@ -8,13 +8,12 @@ export interface IDocAstViewProps {
theme?: string; theme?: string;
} }
export class DocAstView extends React.Component<IDocAstViewProps> { export function DocAstView(props: IDocAstViewProps): JSX.Element {
public render(): React.ReactNode { const parserContext: tsdoc.ParserContext | undefined = props.parserContext;
const parserContext: tsdoc.ParserContext | undefined = this.props.parserContext;
const outputLines: string[] = []; const outputLines: string[] = [];
if (parserContext && parserContext.docComment) { if (parserContext && parserContext.docComment) {
this._dumpTSDocTree(outputLines, parserContext.docComment); _dumpTSDocTree(outputLines, parserContext.docComment);
} }
return ( return (
@ -23,12 +22,12 @@ export class DocAstView extends React.Component<IDocAstViewProps> {
readOnly={true} readOnly={true}
value={outputLines.join('\n')} value={outputLines.join('\n')}
disableLineNumbers={true} disableLineNumbers={true}
theme={this.props.theme} theme={props.theme}
/> />
); );
} }
private _dumpTSDocTree(outputLines: string[], docNode: tsdoc.DocNode, indent: string = ''): void { function _dumpTSDocTree(outputLines: string[], docNode: tsdoc.DocNode, indent: string = ''): void {
let dumpText: string = ''; let dumpText: string = '';
if (docNode instanceof tsdoc.DocExcerpt) { if (docNode instanceof tsdoc.DocExcerpt) {
const content: string = docNode.content.toString(); const content: string = docNode.content.toString();
@ -39,7 +38,6 @@ export class DocAstView extends React.Component<IDocAstViewProps> {
outputLines.push(dumpText); outputLines.push(dumpText);
for (const child of docNode.getChildNodes()) { for (const child of docNode.getChildNodes()) {
this._dumpTSDocTree(outputLines, child, indent + ' '); _dumpTSDocTree(outputLines, child, indent + ' ');
}
} }
} }

Просмотреть файл

@ -16,16 +16,15 @@ export interface IDocDomViewProps {
theme?: string; theme?: string;
} }
export class DocDomView extends React.Component<IDocDomViewProps> { export function DocDomView(props: IDocDomViewProps): JSX.Element {
public render(): React.ReactNode { const parserContext: tsdoc.ParserContext | undefined = props.parserContext;
const parserContext: tsdoc.ParserContext | undefined = this.props.parserContext;
let code: string = ''; let code: string = '';
if (parserContext && parserContext.docComment) { if (parserContext && parserContext.docComment) {
const unindentedCode: string = ReactDomServer.renderToStaticMarkup( const unindentedCode: string = ReactDomServer.renderToStaticMarkup(
<DocHtmlView docComment={parserContext.docComment} /> <DocHtmlView docComment={parserContext.docComment} />
); );
code = this._indentHtml(unindentedCode); code = _indentHtml(unindentedCode);
} }
return ( return (
@ -35,14 +34,14 @@ export class DocDomView extends React.Component<IDocDomViewProps> {
value={code} value={code}
language="html" language="html"
disableLineNumbers={true} disableLineNumbers={true}
theme={this.props.theme} theme={props.theme}
/> />
); );
} }
// Given a string containing perfectly systematic HTML (like what React generates), // Given a string containing perfectly systematic HTML (like what React generates),
// this adds appropriate indentation // this adds appropriate indentation
private _indentHtml(html: string): string { function _indentHtml(html: string): string {
const tagRegExp: RegExp = /\<\/|\<|\>/g; const tagRegExp: RegExp = /\<\/|\<|\>/g;
const output: string[] = []; const output: string[] = [];
@ -106,4 +105,3 @@ export class DocDomView extends React.Component<IDocDomViewProps> {
return output.join(''); return output.join('');
} }
}

Просмотреть файл

@ -3,42 +3,28 @@ import * as React from 'react';
export interface IFlexDivProps export interface IFlexDivProps
extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {} extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {}
export class FlexRowDiv extends React.Component<IFlexDivProps> { export function FlexRowDiv(props: IFlexDivProps): JSX.Element {
public render(): React.ReactNode {
const mergedProps: IFlexDivProps = { const mergedProps: IFlexDivProps = {
...this.props ...props,
style: {
display: 'flex',
flexDirection: 'row',
...props.style
}
}; };
if (mergedProps.style === undefined) {
mergedProps.style = {};
}
if (mergedProps.style.display === undefined) {
mergedProps.style.display = 'flex';
}
if (mergedProps.style.flexDirection === undefined) {
mergedProps.style.flexDirection = 'row';
}
return React.createElement('div', mergedProps); return React.createElement('div', mergedProps);
} }
}
export class FlexColDiv extends React.Component<IFlexDivProps> { export function FlexColDiv(props: IFlexDivProps): JSX.Element {
public render(): React.ReactNode {
const mergedProps: IFlexDivProps = { const mergedProps: IFlexDivProps = {
...this.props ...props,
style: {
display: 'flex',
flexDirection: 'column',
...props.style
}
}; };
if (mergedProps.style === undefined) {
mergedProps.style = {};
}
if (mergedProps.style.display === undefined) {
mergedProps.style.display = 'flex';
}
if (mergedProps.style.flexDirection === undefined) {
mergedProps.style.flexDirection = 'column';
}
return React.createElement('div', mergedProps); return React.createElement('div', mergedProps);
} }
}