From f33216592ab5b85d3419850646d86675368364e7 Mon Sep 17 00:00:00 2001 From: "Damir A. Kutikov" Date: Thu, 24 Nov 2022 19:14:00 +0200 Subject: [PATCH] mobile version --- Components/Home.js | 488 +++++++++++++++++++++++++++------------------ pages/index.js | 11 +- 2 files changed, 303 insertions(+), 196 deletions(-) diff --git a/Components/Home.js b/Components/Home.js index a3d0e61..fd92503 100644 --- a/Components/Home.js +++ b/Components/Home.js @@ -1,7 +1,8 @@ // noinspection JSValidateTypes -import { useState } from 'react'; +import {useState} from 'react'; import { Flex, Grid, GridItem, Button, Circle, Text } from '@chakra-ui/react' +import { Tabs, TabList, TabPanels, Tab, TabPanel } from '@chakra-ui/react' import { AiOutlineItalic, AiOutlineBold, AiOutlineUnderline, AiOutlineHighlight, AiOutlineAlignLeft, AiOutlineAlignRight, AiOutlineAlignCenter, AiOutlineOrderedList, AiOutlineUnorderedList, AiOutlineDownload } from "react-icons/ai"; import { GoQuote } from 'react-icons/go'; @@ -14,34 +15,152 @@ import Highlight from '@tiptap/extension-highlight'; import Underline from '@tiptap/extension-underline'; import StarterKit from '@tiptap/starter-kit'; -import styles from './Home.module.css'; import { Color } from '@tiptap/extension-color' import {FontFamily} from "@tiptap/extension-font-family"; import TextStyle from '@tiptap/extension-text-style'; +import { saveAs } from 'file-saver'; -const MenuBar = ({ editor, onSelectBorderColor, onBgColorChange }) => { - const [bgColor, setBgColor] = useState('#ffffff'); +const FontSelector = ({editor, chakraStyles}) => { if (!editor) { return null - } - const customComponents = { - IndicatorSeparator:() => null, - }; + } + const customComponents = { + IndicatorSeparator: () => null, + }; - const chakraStyles = { - dropdownIndicator: (provided, state) => ({ - ...provided, - background: "#ffffff", - }), - menu: base => ({ - ...base, - fontWeight: '300', - mt: 0, - boxShadow: '1px 5px 10px rgb(0 0 0 / 0.2)', - borderRadius: 'lg' - }) + const onFontClick = (e) => { + switch (e.value){ + case 1: + editor.chain().focus().unsetFontFamily().run(); + break; + case 2: + editor.chain().focus().setFontFamily('Lobster, cursive').run(); + break; + case 3: + editor.chain().focus().setFontFamily('Comic Sans MS, Comic Sans').run(); + break; + case 4: + editor.chain().focus().setFontFamily('monospace').run(); + break; + case 5: + editor.chain().focus().setFontFamily('Dancing Script, cursive').run(); + break; + case 6: + editor.chain().focus().setFontFamily('Noto Serif, serif').run(); + break; + } + } + + return ( + + ); +} + +const TextStylePanel = ({editor}) => { const onItalicClick = () => { editor.chain().focus().toggleItalic().run() } @@ -52,7 +171,6 @@ const MenuBar = ({ editor, onSelectBorderColor, onBgColorChange }) => { const onUnderlineClick = () => { editor.chain().focus().toggleUnderline().run(); - //onChange(RichUtils.toggleInlineStyle(editorState, 'UNDERLINE')) } const onUnorderedListClick = () => { @@ -83,34 +201,89 @@ const MenuBar = ({ editor, onSelectBorderColor, onBgColorChange }) => { const onHighlightClick = () => { editor.chain().focus().toggleHighlight({ color: 'red'}).run() } + return( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} - const onHeadingClick = (e) => { - editor.chain().focus().toggleHeading({ level: e.value }).run() +const BackgroundsPanel = ({bgColor, setBgColor, onBgColorChange}) => { + const handleBgColor = (color) => { + setBgColor(color) + onBgColorChange(color) } + return( + + {['#ffffff', '#ffcdd2', '#e1bee7', '#c5cae9', '#b3e5fc', + '#b2dfdb', '#dcedc8', '#fff9c4', '#ffe0b2', '#ffccbc'].map((color, index) => handleBgColor(color)} />)} + + ); +} - const onFontClick = (e) => { - switch (e.value){ - case 1: - editor.chain().focus().unsetFontFamily().run(); - break; - case 2: - editor.chain().focus().setFontFamily('Lobster, cursive').run(); - break; - case 3: - editor.chain().focus().setFontFamily('Comic Sans MS, Comic Sans').run(); - break; - case 4: - editor.chain().focus().setFontFamily('monospace').run(); - break; - case 5: - editor.chain().focus().setFontFamily('Dancing Script, cursive').run(); - break; - case 6: - editor.chain().focus().setFontFamily('Noto Serif, serif').run(); - break; - } +const ForegroundPanel = ({editor}) => { + const handleFgColor = (color) => { + editor.chain().focus().setColor(color).run(); + } + return( + + {['#000000', '#b71c1c', '#4a148c', '#1a237e','#01579b', + '#004d40', '#003d00', '#bc5100', '#dd2c00', '#870000'].map((color, index) => handleFgColor(color)} />)} + + ); +} + +const MenuBar = ({ editor, onSelectBorderColor, onBgColorChange }) => { + const [bgColor, setBgColor] = useState('#ffffff'); + if (!editor) { + return null } + const chakraStyles = { + dropdownIndicator: (provided, state) => ({ + ...provided, + background: "#ffffff", + }), + menu: base => ({ + ...base, + fontWeight: '300', + mt: 0, + boxShadow: '1px 5px 10px rgb(0 0 0 / 0.2)', + borderRadius: 'lg' + }) + }; + const scale = 3; const handleDownload = () => { domtoimage.toBlob(document.getElementById('canvas'), { @@ -124,175 +297,79 @@ const MenuBar = ({ editor, onSelectBorderColor, onBgColorChange }) => { } }) .then(function (blob) { - window.saveAs(blob, `scroller-app-${new Date().toISOString()}.png`); + saveAs(blob, `scroller-app-${new Date().toISOString()}.png`) }); } - const handleBorderColor = (color) => { - onSelectBorderColor(color) - } - - const handleBgColor = (color) => { - setBgColor(color) - onBgColorChange(color) - } - const handleFgColor = (color) => { - editor.chain().focus().setColor(color).run(); + if(document.body.clientWidth < 975){ + return ( + + + + Font style + Text style + Background + Foreground + + + + + + + + + + + + + + + + + + + + + + ); } return ( - - - Font style - - - - - - Text style - - - - + - - - - + Font style - + - + - + Text style - + - + Background - + - - - - - - Background - - {['#ffffff', '#ffcdd2', '#e1bee7', '#c5cae9', '#b3e5fc', - '#b2dfdb', '#dcedc8', '#fff9c4', '#ffe0b2', '#ffccbc'].map((color, index) => handleBgColor(color)} />)} - Foreground - {['#000000', '#b71c1c', '#4a148c', '#1a237e','#01579b', - '#004d40', '#003d00', '#bc5100', '#dd2c00', '#870000'].map((color, index) => handleFgColor(color)} />)} - - + + + - ) + ); } -const Home = () => { +export const Home = () => { const [borderColor, setBorderColor] = useState('red'); const [bgColor, setBgColor] = useState('white'); @@ -325,10 +402,41 @@ const Home = () => { setBgColor(color); } - + if(document.body.clientWidth <= 975 && document.body.clientWidth > 570){ + return( + + + + + + + + + + + + + ); + } + else if(document.body.clientWidth <= 570){ + return( + + + + + + + + + + + + + ); + } return( - - + + @@ -338,7 +446,5 @@ const Home = () => { - ) + ); } - -export default Home; \ No newline at end of file diff --git a/pages/index.js b/pages/index.js index 636a49b..05a2d0f 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,7 +1,9 @@ -import Head from 'next/head' -import Image from 'next/image' -import Home from '../Components/Home'; +import Head from 'next/head'; +import dynamic from "next/dynamic"; +const DynamicComponent = dynamic(() => import('../Components/Home').then((mod) => mod.Home), { + ssr: false +}); export default function Index() { return ( @@ -14,8 +16,7 @@ export default function Index() { - - + ) }