From d73f5ef8f429704f81c3d2dfecf7d46ad40fb3cf Mon Sep 17 00:00:00 2001 From: unix Date: Mon, 4 May 2020 23:55:45 +0800 Subject: [PATCH] fix(playground): fix arrow icon does not work correctly on webkit --- lib/components/playground/editor.tsx | 128 +++++++++++++++++++ lib/components/playground/playground.tsx | 154 +++-------------------- 2 files changed, 147 insertions(+), 135 deletions(-) create mode 100644 lib/components/playground/editor.tsx diff --git a/lib/components/playground/editor.tsx b/lib/components/playground/editor.tsx new file mode 100644 index 0000000..8c889e0 --- /dev/null +++ b/lib/components/playground/editor.tsx @@ -0,0 +1,128 @@ +import React, { useState } from 'react' +import { LiveEditor } from 'react-live' +import { useConfigs } from 'lib/config-context' +import { useTheme, useToasts, Row, Col, Utils } from 'components' +import CopyIcon from '@zeit-ui/react-icons/copy' +import RightIcon from '@zeit-ui/react-icons/chevronRight' +const { useClipboard } = Utils + +interface Props { + code: string +} + +const Editor: React.FC = ({ code }) => { + const theme = useTheme() + const { copy } = useClipboard() + const { isChinese } = useConfigs() + const [visible, setVisible] = useState(false) + const [, setToast] = useToasts() + const clickHandler = (event: React.MouseEvent) => { + event.stopPropagation() + event.preventDefault() + setVisible(!visible) + } + + const copyHandler = (event: React.MouseEvent) => { + event.stopPropagation() + event.preventDefault() + copy(code) + setToast({ text: isChinese ? '代码已拷贝至剪切板。' : 'code copied.' }) + } + + return ( +
+
+ + + + + {isChinese ? '编辑代码' : 'Code Editor'} + + + {visible && ( + + + + )} + + + +
+
+ + +
+ ) +} + +export default Editor diff --git a/lib/components/playground/playground.tsx b/lib/components/playground/playground.tsx index 104bd36..3ab12cd 100644 --- a/lib/components/playground/playground.tsx +++ b/lib/components/playground/playground.tsx @@ -1,12 +1,10 @@ -import React, { useState } from 'react' -import { LivePreview, LiveProvider, LiveEditor, LiveError } from 'react-live' +import React from 'react' +import { useTheme } from 'components' import withDefaults from 'components/utils/with-defaults' -import useClipboard from 'components/utils/use-clipboard' -import { useTheme, useToasts } from 'components' +import { LivePreview, LiveProvider, LiveError } from 'react-live' import { useConfigs } from 'lib/config-context' import makeCodeTheme from './code-theme' -import RightIcon from '@zeit-ui/react-icons/chevronRight' -import CopyIcon from '@zeit-ui/react-icons/copy' +import Editor from './editor' import Title from './title' interface Props { @@ -26,126 +24,12 @@ const defaultProps = { export type PlaygroundProps = Props & typeof defaultProps -const editor = (code: string, copy: Function, isChinese: boolean) => { - const theme = useTheme() - const [visible, setVisible] = useState(false) - - const [, setToast] = useToasts() - const clickHandler = (event: React.MouseEvent) => { - event.stopPropagation() - event.preventDefault() - setVisible(!visible) - } - - const copyHandler = (event: React.MouseEvent) => { - event.stopPropagation() - event.preventDefault() - copy(code) - setToast({ text: isChinese ? '代码已拷贝至剪切板。' : 'code copied.' }) - } - - return ( -
-
- -
- - - - {isChinese ? '编辑代码' : 'Code Editor'} -
-
- {visible && ( - - - - )} -
-
-
- -
-
- - -
- ) -} - const Playground: React.FC = React.memo(({ title: inputTitle, code: inputCode, desc, scope, }) => { const theme = useTheme() const { isChinese } = useConfigs() const codeTheme = makeCodeTheme(theme) - const { copy } = useClipboard() const code = inputCode.trim() const title = inputTitle || (isChinese ? '基础的' : 'Default') @@ -158,24 +42,24 @@ const Playground: React.FC = React.memo(({ - {editor(code, copy, !!isChinese)} + + .playground { + width: 100%; + border-radius: ${theme.layout.radius}; + border: 1px solid ${theme.palette.accents_2}; + } + + .wrapper { + width: 100%; + padding: ${theme.layout.pageMargin}; + display: flex; + flex-direction: column; + box-sizing: border-box; + } + `} )