Skip to content

Commit

Permalink
fix: use emotion's jsx in favor of createElement
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Dec 9, 2018
1 parent ee736c0 commit 052f3d2
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 36 deletions.
11 changes: 5 additions & 6 deletions src/BlockQuote.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* @jsx jsx */

import { jsx } from '@emotion/core';
import { FunctionComponent } from 'react';

Expand Down Expand Up @@ -26,13 +28,10 @@ export const blockQuoteStyles = ({ isSelected }: IBlockQuoteProps) => {
const theme = useTheme();

return [
/* todo:
{
pl="@xl"
borderLeft="@sm"
}
*/
{
padding: '15px 25px',
borderLeft: '5px solid',
maxWidth: '80%',
color: theme.blockQuote.fg,
borderColor: theme.blockQuote.borderColor,
},
Expand Down
10 changes: 6 additions & 4 deletions src/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* @jsx jsx */

import { jsx } from '@emotion/core';
import { Omit } from '@stoplight/types';
import noop = require('lodash/noop');
import { createElement, FunctionComponent, ReactEventHandler, useState } from 'react';
import { FunctionComponent, ReactEventHandler, useState } from 'react';

import { Box, Flex, IBox, Icon, useTheme } from './';

Expand Down Expand Up @@ -42,7 +44,7 @@ const CheckboxInner: FunctionComponent<ICheckboxInner> = props => {
as: 'span',
css,
},
props.isChecked && [createElement(Icon, { icon: 'check' })]
props.isChecked && [jsx(Icon, { icon: 'check' })]
);
};

Expand Down Expand Up @@ -88,11 +90,11 @@ export const Checkbox: FunctionComponent<ICheckbox> = props => {
css,
},
[
createElement(CheckboxInput, {
jsx(CheckboxInput, {
id,
onChange: handleChange,
}),
createElement(CheckboxInner, {
jsx(CheckboxInner, {
isChecked,
isDisabled,
height,
Expand Down
19 changes: 9 additions & 10 deletions src/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { css, jsx } from '@emotion/core';

import noop = require('lodash/noop');
import 'prismjs/components/';
import * as React from 'react';
import { CSSProperties, useCallback } from 'react';
import { CSSProperties, forwardRef, useCallback } from 'react';
import ReactSimpleCodeEditor from 'react-simple-code-editor';
import { Box } from './Box';
import { useTheme } from './theme';
Expand Down Expand Up @@ -56,7 +55,7 @@ export const supportedLanguages = {

export type ReactSimpleCodeEditorRef = ReactSimpleCodeEditor;

export const CodeEditor = React.forwardRef<ReactSimpleCodeEditorRef, ICodeEditor>((props, ref) => {
export const CodeEditor = forwardRef<ReactSimpleCodeEditorRef, ICodeEditor>((props, ref) => {
const { language, onChange = noop, style, value } = props;
const highlightCodeCallback = useCallback(() => highlightCode(value, language), [value, language]);
const editorCSS = [...codeEditorStyles()];
Expand All @@ -68,13 +67,13 @@ export const CodeEditor = React.forwardRef<ReactSimpleCodeEditorRef, ICodeEditor
css: editorCSS,
},
[
<ReactSimpleCodeEditor
ref={ref}
value={value}
onValueChange={onChange}
highlight={highlightCodeCallback}
padding={10}
/>,
jsx(ReactSimpleCodeEditor, {
ref,
value,
onValueChange: onChange,
highlight: highlightCodeCallback,
padding: 10,
}),
]
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @jsx jsx */
/* @jsx jsx */

import { jsx } from '@emotion/core';
import {
Expand Down
2 changes: 2 additions & 0 deletions src/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* @jsx jsx */

import { jsx } from '@emotion/core';
import noop = require('lodash/noop');
import { FunctionComponent, SyntheticEvent, useState } from 'react';
Expand Down
2 changes: 2 additions & 0 deletions src/List.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* @jsx jsx */

import { jsx } from '@emotion/core';
import { Omit } from '@stoplight/types';
import { FunctionComponent } from 'react';
Expand Down
4 changes: 3 additions & 1 deletion src/Mark.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as React from 'react';
/* @jsx jsx */

import { jsx } from '@emotion/core';

import { Box, IBox } from './Box';

Expand Down
6 changes: 3 additions & 3 deletions src/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsx jsx */
/* @jsx jsx */

import { css, jsx } from '@emotion/core';
import { createElement, FunctionComponent, ReactNode } from 'react';
import { FunctionComponent, ReactNode } from 'react';

import { Box } from './Box';
import { Flex, IFlex } from './Flex';
Expand All @@ -21,7 +21,7 @@ export declare type RenderMenuFunc = (
) => ReactNode;

const defaultRenderMenuItem: RenderMenuItemFunc = (item: IMenuItemProps, index: number) =>
createElement(MenuItem, { key: index, ...item });
jsx(MenuItem, { key: index, ...item });

const defaultRenderMenu: RenderMenuFunc = ({ renderTrigger, ...rest }, menuItems, renderMenuItem) => {
const theme = useTheme();
Expand Down
8 changes: 3 additions & 5 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { jsx } from '@emotion/core';
import { Omit } from '@stoplight/types';
import { createElement, FunctionComponent } from 'react';
import { FunctionComponent } from 'react';

import { Box, IBox } from './Box';
import { useTheme } from './theme';
Expand All @@ -19,7 +19,7 @@ export const Table: FunctionComponent<ITable> = props => {
as: 'table',
css,
},
[createElement('tbody', null, children)]
[jsx('tbody', null, children)]
);
};

Expand Down Expand Up @@ -83,9 +83,7 @@ export const TableCell: FunctionComponent<ITableCell> = props => {
});
};

export interface ITableCell
extends ITableCellProps,
Omit<IBox<HTMLTableDataCellElement>, 'as'> {}
export interface ITableCell extends ITableCellProps, Omit<IBox<HTMLTableDataCellElement>, 'as'> {}

export interface ITableCellProps extends ITableProps {
as?: 'th' | 'td';
Expand Down
4 changes: 3 additions & 1 deletion src/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* @jsx jsx */

import { jsx } from '@emotion/core';
import noop = require('lodash/noop');
import { FunctionComponent, SyntheticEvent, useState } from 'react';
Expand All @@ -7,7 +9,7 @@ import { Box, IBox } from './Box';
import { useTheme } from './theme';

export const Textarea: FunctionComponent<ITextarea> = props => {
const { as = props.autosize ? AutosizeTextarea : 'textarea', autosize, onChange = noop, ...rest } = props;
const { autosize, as = autosize ? AutosizeTextarea : 'textarea', onChange = noop, ...rest } = props;

const css = textareaStyles(props);

Expand Down
12 changes: 7 additions & 5 deletions src/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* @jsx jsx */

import { jsx } from '@emotion/core';
import { Omit } from '@stoplight/types';
import noop = require('lodash/noop');
import { createElement, FunctionComponent, ReactEventHandler, SyntheticEvent, useState } from 'react';
import { FunctionComponent, ReactEventHandler, SyntheticEvent, useState } from 'react';

import { Box, Flex, IBox, useTheme } from './';
import { Icon } from './Icon';
Expand Down Expand Up @@ -35,7 +37,7 @@ interface IToggleInnerProps {
const ToggleInnerIcon: FunctionComponent<IToggleInnerProps> = props => {
const css = toggleInnerIconStyles(props);

return createElement(Icon, {
return jsx(Icon, {
icon: 'circle',
css,
});
Expand All @@ -60,7 +62,7 @@ const ToggleInner: FunctionComponent<IToggleInnerProps> = props => {
as: 'span',
css,
},
[createElement(ToggleInnerIcon, props)]
[jsx(ToggleInnerIcon, props)]
);
};

Expand Down Expand Up @@ -104,11 +106,11 @@ export const Toggle: FunctionComponent<IToggle> = props => {
css,
},
[
createElement(ToggleInput, {
jsx(ToggleInput, {
id,
onChange: handleChange,
}),
createElement(ToggleInner, {
jsx(ToggleInner, {
isChecked,
isDisabled: !!disabled,
height,
Expand Down

0 comments on commit 052f3d2

Please sign in to comment.