|
| 1 | +import React, {useState} from 'react'; |
| 2 | +import {Link} from 'react-router-dom'; |
| 3 | +import { |
| 4 | + ArrowLeftIcon, |
| 5 | + BaseballHelmetIcon, BeanieIcon, BroomIcon, |
| 6 | + ClipboardIcon, TaxiIcon, |
| 7 | +} from '@phosphor-icons/react'; |
| 8 | +import {useToast} from '../../hooks/useToast'; |
| 9 | +import useSeo from '../../hooks/useSeo'; |
| 10 | +import BreadcrumbTitle from '../../components/BreadcrumbTitle'; |
| 11 | +import formatMarkdownTable from "../../utils/markdownUtils"; |
| 12 | +import {useSidePanel} from "../../context/SidePanelContext"; |
| 13 | + |
| 14 | +const FruitDashboard = () => { |
| 15 | + useSeo({ |
| 16 | + title: 'Markdown Table Formatter | Fezcodex', |
| 17 | + description: 'Format your markdown tables.', |
| 18 | + keywords: ['Fezcodex', 'md', 'markdown', 'table'], |
| 19 | + ogTitle: 'Markdown Table Formatter | Fezcodex', |
| 20 | + ogDescription: 'Format your markdown tables.', |
| 21 | + ogImage: 'https://fezcode.github.io/logo512.png', |
| 22 | + twitterCard: 'summary_large_image', |
| 23 | + twitterTitle: 'Markdown Table Formatter | Fezcodex', |
| 24 | + twitterDescription: 'Format your markdown tables.', |
| 25 | + twitterImage: 'https://fezcode.github.io/logo512.png', |
| 26 | + }); |
| 27 | + |
| 28 | + const [inputText, setInputText] = useState(''); |
| 29 | + const [outputText, setOutputText] = useState(''); |
| 30 | + const {addToast} = useToast(); |
| 31 | + const { openSidePanel } = useSidePanel(); |
| 32 | + |
| 33 | + const ReasonComponent = () => { |
| 34 | + return ( |
| 35 | + <div className="space-y-6"> |
| 36 | + <div className="flex items-center justify-center gap-4"> |
| 37 | + <TaxiIcon size={24} weight="fill" /> |
| 38 | + <h1 className="text-white font-arvo">... Because of Taxi Driver ...</h1> |
| 39 | + <TaxiIcon size={24} weight="fill" /> |
| 40 | + </div> |
| 41 | + <div className="bg-gray-800/50 p-4 rounded-lg border border-gray-700"> |
| 42 | + <h3 className="text-white font-bold mb-2">Markdown Log Entries</h3> |
| 43 | + <p className="text-sm text-gray-400"> |
| 44 | + I watched Taxi Driver (1976). |
| 45 | + Then I started to write a review, log entry for it. |
| 46 | + Creating a <strong> Markdown Table </strong>is one of the hardest parts of writing markdown. |
| 47 | + Each table row looked worse than the previous one. |
| 48 | + I needed a formatter. |
| 49 | + </p> |
| 50 | + <br/> |
| 51 | + <p className="text-sm text-gray-400"> |
| 52 | + After hours of writing a React component, finally here it is. |
| 53 | + It is 5 AM and I'm <i>finally</i> done. |
| 54 | + </p> |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + const convertMarkdownTable = () => { |
| 61 | + try { |
| 62 | + let formattedTable = formatMarkdownTable(inputText); |
| 63 | + setOutputText(formattedTable); |
| 64 | + } catch (error) { |
| 65 | + addToast({ |
| 66 | + title: 'Error', |
| 67 | + message: 'Failed to format given markdown table text.', |
| 68 | + duration: 3000, |
| 69 | + }); |
| 70 | + setOutputText(''); |
| 71 | + } |
| 72 | + }; |
| 73 | + |
| 74 | + const copyToClipboard = (text) => { |
| 75 | + navigator.clipboard |
| 76 | + .writeText(text) |
| 77 | + .then(() => { |
| 78 | + addToast({ |
| 79 | + title: 'Success', |
| 80 | + message: 'Copied to clipboard!', |
| 81 | + duration: 2000, |
| 82 | + }); |
| 83 | + }) |
| 84 | + .catch(() => { |
| 85 | + addToast({ |
| 86 | + title: 'Error', |
| 87 | + message: 'Failed to copy!', |
| 88 | + duration: 2000, |
| 89 | + }); |
| 90 | + }); |
| 91 | + }; |
| 92 | + |
| 93 | + return ( |
| 94 | + // bg-[#CFD8DC] |
| 95 | + <div className="py-16 sm:py-24 min-h-screen bg-[#FFEDCF]"> |
| 96 | + <div className="mx-auto max-w-7xl px-6 lg:px-8 text-gray-300"> |
| 97 | + <Link to="/apps" className="group text-rose-800 hover:underline flex items-center justify-center gap-2 text-lg mb-4 font-arvo"> |
| 98 | + <ArrowLeftIcon className="text-xl transition-transform group-hover:-translate-x-1"/> |
| 99 | + Back to Apps |
| 100 | + </Link> |
| 101 | + |
| 102 | + <BreadcrumbTitle title="Markdown Table Formatter" slug="mtf" sansFont={true} lightStyle={false}/> |
| 103 | + <hr className="border-gray-700"/> |
| 104 | + <div className="flex justify-center items-center mt-16 text-[#1A2E1A]"> |
| 105 | + {/*Our Text Div*/} |
| 106 | + <div |
| 107 | + className="group bg-[#FBF7F0] rounded-[0.25rem] border border-neutral-700 shadow-2xl p-6 flex flex-col justify-between relative transform transition-all duration-300 ease-in-out overflow-hidden h-full w-full max-w-4xl"> |
| 108 | + <div className="absolute top-0 left-0 w-full h-full opacity-10" style={{ backgroundImage: 'radial-gradient(circle, black 1px, transparent 1px)', backgroundSize: '10px 10px' }}></div> |
| 109 | + |
| 110 | + <div className="relative z-10 p-1"> |
| 111 | + <div className="flex flex-row items-center justify-items-start gap-2"> |
| 112 | + <h1 className="text-4xl font-serif text-[#1A2E1A] mb-2">Table Formatter</h1> |
| 113 | + <button |
| 114 | + onClick={() => openSidePanel('Why Create a Formatter', <ReasonComponent />, 400)} |
| 115 | + className="text-gray-500 hover:text-[#1A2E1A] transition-colors hover:scale-105" |
| 116 | + aria-label="Rating System Info" |
| 117 | + > |
| 118 | + <BeanieIcon className="rotate-12 hover:rotate-0 transition" size={24} /> |
| 119 | + </button> |
| 120 | + </div> |
| 121 | + |
| 122 | + <hr className="border-gray-700 mb-4"/> |
| 123 | + {/*Input Text*/} |
| 124 | + <div className="mb-4"> |
| 125 | + <label className="block text-2xl font-normal italic text-[#2c3e2c] mb-2 font-playfairDisplay">Input Text</label> |
| 126 | + |
| 127 | + <textarea |
| 128 | + className="w-full h-32 p-4 bg-[#f3e2c850] font-mono resize-y border rounded-md border-app-alpha-50 text-[#1A2E1A]" |
| 129 | + value={inputText} |
| 130 | + onChange={(e) => setInputText(e.target.value)} |
| 131 | + placeholder="Enter markdown table here..." |
| 132 | + /> |
| 133 | + </div> |
| 134 | + |
| 135 | + {/*Button*/} |
| 136 | + <div className="flex justify-center gap-4 mb-4 mt-4"> |
| 137 | + <button |
| 138 | + onClick={convertMarkdownTable} |
| 139 | + className="px-6 py-2 rounded-md text-lg font-arvo font-normal transition-colors duration-300 ease-in-out bg-[#f0e3c980] hover:bg-[#fef9e6] text-[#2e5341] border-[#2e5341] border flex items-center gap-2" |
| 140 | + > |
| 141 | + <BaseballHelmetIcon size={24}/> |
| 142 | + Format Table |
| 143 | + </button> |
| 144 | + |
| 145 | + <button |
| 146 | + onClick={ () => setInputText('')} |
| 147 | + className="px-6 py-2 rounded-md text-lg font-arvo font-normal transition-colors duration-300 ease-in-out bg-[#f0e3c980] hover:bg-[#fef9e6] text-[#2e5341] border-[#2e5341] border flex items-center gap-2" |
| 148 | + > |
| 149 | + <BroomIcon size={24}/> |
| 150 | + Clear Text |
| 151 | + </button> |
| 152 | + </div> |
| 153 | + |
| 154 | + {/*Output Text*/} |
| 155 | + <div className="mb-4"> |
| 156 | + <label className="block text-2xl font-normal italic text-[#2c3e2c] mb-2 font-playfairDisplay">Output Text</label> |
| 157 | + <div className="relative overflow-hidden"> |
| 158 | + <textarea |
| 159 | + readOnly |
| 160 | + className="w-full h-32 p-4 bg-[#f3e2c850] font-mono resize-y border rounded-md border-app-alpha-50 text-[#1A2E1A]" |
| 161 | + value={outputText} |
| 162 | + placeholder="Formatted text will appear here..." |
| 163 | + /> |
| 164 | + <button |
| 165 | + onClick={() => copyToClipboard(outputText)} |
| 166 | + className="absolute top-2 right-2 px-3 py-2 bg-gray-700 text-white text-sm font-arvo rounded hover:bg-gray-600 flex items-center justify-center gap-2 " |
| 167 | + > |
| 168 | + <ClipboardIcon size={16}> </ClipboardIcon> |
| 169 | + Copy |
| 170 | + </button> |
| 171 | + </div> |
| 172 | + </div> |
| 173 | + </div> |
| 174 | + </div> |
| 175 | + </div> |
| 176 | + </div> |
| 177 | + </div> |
| 178 | + ); |
| 179 | +}; |
| 180 | + |
| 181 | +export default FruitDashboard; |
0 commit comments