From 89537fc11bca4064d379a071dd4891fce87b3e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 9 Nov 2019 21:56:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Switch=20CodeFormatting=20to=20u?= =?UTF-8?q?se=20useOvermind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CodeFormatting/Prettier/index.tsx | 58 +++++++++++-------- .../CodeFormatting/elements.ts | 6 ++ .../PreferencesModal/CodeFormatting/index.tsx | 6 +- 3 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/elements.ts diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.tsx index 7b332ad33a6..e4a8bfa3675 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/Prettier/index.tsx @@ -1,4 +1,5 @@ import React, { FunctionComponent } from 'react'; + import { useOvermind } from 'app/overmind'; import { @@ -9,28 +10,24 @@ import { Rule, } from '../../elements'; -const PrettierComponent: FunctionComponent = () => { +export const Prettier: FunctionComponent = () => { const { + actions: { + preferences: { settingChanged }, + }, state: { preferences: { settings: { prettierConfig }, }, }, - actions: { - preferences: { settingChanged }, - }, } = useOvermind(); - const bindValue = name => ({ - value: prettierConfig[name], + const bindValue = (name: string) => ({ setValue: value => - settingChanged({ - name: `prettierConfig.${name}`, - value, - }), + settingChanged({ name: `prettierConfig.${name}`, value }), + value: prettierConfig[name], }); - const { fluid } = prettierConfig; return ( @@ -38,38 +35,39 @@ const PrettierComponent: FunctionComponent = () => { This configuration can be overridden by a{' '} .prettierrc {' '} JSON file at the root of the sandbox. + + + Wrap the code based on the editor width. + + - + + Specify the line length that the printer will wrap on. + { type="number" {...bindValue('tabWidth')} /> + Specify the number of spaces per indentation-level. + { type="boolean" {...bindValue('useTabs')} /> + Indent lines with tabs instead of spaces. + { type="boolean" {...bindValue('semi')} /> + Print semicolons at the ends of statements. + { type="boolean" {...bindValue('singleQuote')} /> + Use {"'"}single{"'"} quotes instead of {'"'}double{'"'} quotes. + { options={['none', 'es5', 'all']} {...bindValue('trailingComma')} /> + Print trailing commas wherever possible. + { type="boolean" {...bindValue('bracketSpacing')} /> + Print spaces between brackets in object literals. + { type="boolean" {...bindValue('jsxBracketSameLine')} /> + Put the `{'>'}` of a multi-line JSX element at the end of the last line instead of being alone on the next line. + + + Include parentheses around a sole arrow function parameter. @@ -156,5 +170,3 @@ const PrettierComponent: FunctionComponent = () => { ); }; - -export const Prettier = PrettierComponent; diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/elements.ts b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/elements.ts new file mode 100644 index 00000000000..5e48e9ca683 --- /dev/null +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/elements.ts @@ -0,0 +1,6 @@ +import QuestionBase from 'react-icons/lib/go/question'; +import styled from 'styled-components'; + +export const Question = styled(QuestionBase)` + margin-bottom: 3px; +`; diff --git a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx index f772626680d..f344fb84c3f 100644 --- a/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx +++ b/packages/app/src/app/pages/common/Modals/PreferencesModal/CodeFormatting/index.tsx @@ -1,9 +1,9 @@ import React, { FunctionComponent } from 'react'; -import Question from 'react-icons/lib/go/question'; +import { Title } from '../elements'; +import { Question } from './elements'; import { Prettier } from './Prettier'; -import { Title } from '../elements'; export const CodeFormatting: FunctionComponent = () => (
@@ -14,7 +14,7 @@ export const CodeFormatting: FunctionComponent = () => ( target="_blank" rel="noopener noreferrer" > - +