Skip to content

Commit 11d1478

Browse files
authored
Search bar (#7)
* Input padding * Smaller padding * Search box * Default for input & textarea * Search ok * Clear icon
1 parent 0a47116 commit 11d1478

File tree

13 files changed

+142
-95
lines changed

13 files changed

+142
-95
lines changed

src/App.global.css

+8
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@
66
.btn {
77
@apply rounded-md bg-gray-50 px-2 py-0.5 outline-none text-xs border shadow-sm active:bg-blue-500 active:text-white disabled:opacity-50;
88
}
9+
10+
input {
11+
@apply rounded focus:ring-blue-500 focus:outline-none focus:ring-2;
12+
}
13+
14+
textarea {
15+
@apply rounded focus:ring-blue-500 focus:outline-none focus:ring-2;
16+
}
917
}

src/components/Main.tsx

+99-64
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { NavLink, Route } from 'react-router-dom';
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
44
import { Helmet } from 'react-helmet';
@@ -14,75 +14,110 @@ import JsonFormatter from './json/JsonFormatter';
1414
import QRCodeReader from './qrcode/QrCodeReader';
1515
import RegexTester from './regex/RegexTester';
1616

17+
const defaultRoutes = [
18+
{
19+
icon: <FontAwesomeIcon icon="clock" />,
20+
path: '/unix-converter',
21+
name: 'Unix Time Converter',
22+
Component: UnixTimestamp,
23+
},
24+
{
25+
icon: <FontAwesomeIcon icon="registered" />,
26+
path: '/regex-tester',
27+
name: 'Regex Tester',
28+
Component: RegexTester,
29+
},
30+
{
31+
icon: <FontAwesomeIcon icon={['fab', 'markdown']} />,
32+
path: '/markdown-to-html',
33+
name: 'Markdown to HTML',
34+
Component: MarkdownToHtml,
35+
},
36+
{
37+
icon: <FontAwesomeIcon icon={['fab', 'html5']} />,
38+
path: '/html-preview',
39+
name: 'HTML Preview',
40+
Component: HtmlPreview,
41+
},
42+
{
43+
icon: <FontAwesomeIcon icon="qrcode" />,
44+
path: '/qrcode-generator',
45+
name: 'QRCode Generator',
46+
Component: QrCodeGenerator,
47+
},
48+
{
49+
icon: <FontAwesomeIcon icon="camera" />,
50+
path: '/qrcode-reader',
51+
name: 'QRCode Reader',
52+
Component: QRCodeReader,
53+
},
54+
{
55+
icon: <FontAwesomeIcon icon="code" />,
56+
path: '/base64-encoder',
57+
name: 'Base64 Encoder',
58+
Component: Base64,
59+
},
60+
{
61+
icon: <FontAwesomeIcon icon="exchange-alt" />,
62+
path: '/text-diff',
63+
name: 'Text Diff',
64+
Component: DiffText,
65+
},
66+
{
67+
icon: <FontAwesomeIcon icon={['fab', 'js-square']} />,
68+
path: '/json-formatter',
69+
name: 'JSON Formatter',
70+
Component: JsonFormatter,
71+
},
72+
{
73+
icon: <FontAwesomeIcon icon="database" />,
74+
path: '/sql-formatter',
75+
name: 'SQL Formatter',
76+
Component: SqlFormatter,
77+
},
78+
];
79+
1780
const Main = () => {
18-
const routes = [
19-
{
20-
icon: <FontAwesomeIcon icon="clock" />,
21-
path: '/unix-converter',
22-
name: 'Unix Time Converter',
23-
Component: UnixTimestamp,
24-
},
25-
{
26-
icon: <FontAwesomeIcon icon="registered" />,
27-
path: '/regex-tester',
28-
name: 'Regex Tester',
29-
Component: RegexTester,
30-
},
31-
{
32-
icon: <FontAwesomeIcon icon={['fab', 'markdown']} />,
33-
path: '/markdown-to-html',
34-
name: 'Markdown to HTML',
35-
Component: MarkdownToHtml,
36-
},
37-
{
38-
icon: <FontAwesomeIcon icon={['fab', 'html5']} />,
39-
path: '/html-preview',
40-
name: 'HTML Preview',
41-
Component: HtmlPreview,
42-
},
43-
{
44-
icon: <FontAwesomeIcon icon="qrcode" />,
45-
path: '/qrcode-generator',
46-
name: 'QRCode Generator',
47-
Component: QrCodeGenerator,
48-
},
49-
{
50-
icon: <FontAwesomeIcon icon="camera" />,
51-
path: '/qrcode-reader',
52-
name: 'QRCode Reader',
53-
Component: QRCodeReader,
54-
},
55-
{
56-
icon: <FontAwesomeIcon icon="code" />,
57-
path: '/base64-encoder',
58-
name: 'Base64 Encoder',
59-
Component: Base64,
60-
},
61-
{
62-
icon: <FontAwesomeIcon icon="exchange-alt" />,
63-
path: '/text-diff',
64-
name: 'Text Diff',
65-
Component: DiffText,
66-
},
67-
{
68-
icon: <FontAwesomeIcon icon={['fab', 'js-square']} />,
69-
path: '/json-formatter',
70-
name: 'JSON Formatter',
71-
Component: JsonFormatter,
72-
},
73-
{
74-
icon: <FontAwesomeIcon icon="database" />,
75-
path: '/sql-formatter',
76-
name: 'SQL Formatter',
77-
Component: SqlFormatter,
78-
},
79-
];
81+
const [routes, setRoutes] = useState(defaultRoutes);
82+
const [search, setSearch] = useState('');
83+
84+
const handleSearch = (e: { target: { value: string } }) => {
85+
setSearch(e.target.value);
86+
};
87+
88+
useEffect(() => {
89+
if (search.trim()) {
90+
setRoutes(
91+
defaultRoutes.filter(({ name }) => name.match(new RegExp(search, 'gi')))
92+
);
93+
} else {
94+
setRoutes(defaultRoutes);
95+
}
96+
}, [search]);
8097

8198
return (
8299
<div className="absolute inset-0 flex flex-col overflow-hidden">
83100
<main className="relative flex flex-1 min-h-0">
84101
{/* Left sidebar */}
85102
<nav className="flex flex-col w-1/4 overflow-x-hidden overflow-y-auto bg-gray-300">
103+
{/* Search */}
104+
<div className="flex items-center px-3 mx-3 mt-6 space-x-1 text-gray-400 bg-gray-200 rounded-md focus-within:text-gray-600 focus-within:ring-2 focus-within:ring-blue-500">
105+
<FontAwesomeIcon icon="search" />
106+
<input
107+
type="text"
108+
className="w-full p-1 bg-gray-200 border-none rounded-r-md focus:ring-0"
109+
value={search}
110+
onChange={handleSearch}
111+
placeholder="Search..."
112+
/>
113+
{search && (
114+
<FontAwesomeIcon
115+
icon="times-circle"
116+
onClick={() => setSearch('')}
117+
/>
118+
)}
119+
</div>
120+
86121
<div
87122
className="px-2 my-6"
88123
role="menu"
@@ -106,7 +141,7 @@ const Main = () => {
106141
{/* Main content */}
107142
<section className="relative flex flex-col w-full bg-gray-200">
108143
<div className="h-full px-6 my-6 overflow-x-hidden overflow-y-auto">
109-
{routes.map(({ path, name, Component }) => (
144+
{defaultRoutes.map(({ path, name, Component }) => (
110145
<Route key={path} exact path={path}>
111146
<Component />
112147
<Helmet>

src/components/base64/Base64.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ const Base64 = () => {
123123
<div className="flex flex-1 min-h-full">
124124
<textarea
125125
onChange={handleChangeInput}
126-
className="flex-1 min-h-full p-4 bg-white rounded-md"
126+
className="flex-1 min-h-full p-2 bg-white rounded-md"
127127
value={input}
128128
disabled={opening}
129129
/>
130130
<div className="mx-1" />
131131
<textarea
132-
className="flex-1 min-h-full p-4 bg-gray-100 rounded-md"
132+
className="flex-1 min-h-full p-2 bg-gray-100 rounded-md"
133133
value={output}
134134
readOnly
135135
/>

src/components/diff/TextDiff.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ const TextDiff = () => {
8080
<div className="flex flex-1 min-h-full space-x-2">
8181
<textarea
8282
onChange={handleChangeLeft}
83-
className="flex-1 min-h-full p-4 bg-white rounded-md"
83+
className="flex-1 min-h-full p-2 bg-white rounded-md"
8484
value={left}
8585
/>
8686
<textarea
8787
onChange={handleChangeRight}
88-
className="flex-1 min-h-full p-4 bg-white rounded-md"
88+
className="flex-1 min-h-full p-2 bg-white rounded-md"
8989
value={right}
9090
/>
9191
</div>
@@ -116,7 +116,7 @@ const TextDiff = () => {
116116
</div>
117117

118118
<section
119-
className="flex-1 w-full min-h-full p-4 bg-gray-100 rounded-md"
119+
className="flex-1 w-full min-h-full p-2 bg-gray-100 rounded-md"
120120
dangerouslySetInnerHTML={{ __html: diff }}
121121
/>
122122
</section>

src/components/html/HtmlPreview.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const HtmlPreview = () => {
4141
<div className="flex flex-1 min-h-full space-x-2">
4242
<textarea
4343
onChange={handleChange}
44-
className="flex-1 min-h-full p-4 bg-white rounded-md"
44+
className="flex-1 min-h-full p-2 bg-white rounded-md"
4545
value={html}
4646
disabled={opening}
4747
/>
4848
<section
49-
className="flex-1 max-w-full min-h-full p-4 prose bg-gray-100 rounded-md"
49+
className="flex-1 max-w-full min-h-full p-2 prose bg-gray-100 rounded-md"
5050
dangerouslySetInnerHTML={{ __html: html }}
5151
/>
5252
</div>

src/components/json/JsonFormatter.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ const JsonFormatter = () => {
9797
<div className="flex flex-1 min-h-full space-x-2">
9898
<textarea
9999
onChange={handleChangeInput}
100-
className="flex-1 min-h-full p-4 bg-white rounded-md"
100+
className="flex-1 min-h-full p-2 bg-white rounded-md"
101101
value={input}
102102
disabled={opening}
103103
/>
104104
<textarea
105-
className="flex-1 min-h-full p-4 bg-gray-100 rounded-md"
105+
className="flex-1 min-h-full p-2 bg-gray-100 rounded-md"
106106
value={output}
107107
readOnly
108108
/>

src/components/markdown/MarkdownToHtml.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,18 @@ const Md2Html = () => {
6969
<div className="flex flex-1 min-h-full space-x-2">
7070
<textarea
7171
onChange={handleChange}
72-
className="flex-1 min-h-full p-4 bg-white rounded-md"
72+
className="flex-1 min-h-full p-2 bg-white rounded-md"
7373
value={md}
7474
disabled={opening}
7575
/>
7676
{preview ? (
7777
<section
78-
className="flex-1 max-w-full min-h-full p-4 prose bg-gray-100 rounded-md"
78+
className="flex-1 max-w-full min-h-full p-2 prose bg-gray-100 rounded-md"
7979
dangerouslySetInnerHTML={{ __html: marked(md) }}
8080
/>
8181
) : (
8282
<textarea
83-
className="flex-1 min-h-full p-4 bg-gray-100 rounded-md"
83+
className="flex-1 min-h-full p-2 bg-gray-100 rounded-md"
8484
value={marked(md)}
8585
readOnly
8686
/>

src/components/qrcode/QrCodeGenerator.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ const QRCodeGenerator = () => {
7474
<div className="flex flex-1 min-h-full space-x-2">
7575
<textarea
7676
onChange={handleChange}
77-
className="flex-1 min-h-full p-4 bg-white rounded-md"
77+
className="flex-1 min-h-full p-2 bg-white rounded-md"
7878
value={content}
7979
/>
80-
<section className="flex items-center flex-1 max-w-full min-h-full p-4 prose bg-gray-100 rounded-md">
80+
<section className="flex items-center flex-1 max-w-full min-h-full p-2 prose bg-gray-100 rounded-md">
8181
{qrCode && <img src={qrCode} alt={content} />}
8282
</section>
8383
</div>

src/components/qrcode/QrCodeReader.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ const QRCodeReader = () => {
6767
</button>
6868
</div>
6969
<div className="flex flex-1 min-h-full space-x-2">
70-
<section className="flex items-center flex-1 max-w-full min-h-full p-4 prose bg-gray-100 rounded-md">
70+
<section className="flex items-center flex-1 max-w-full min-h-full p-2 prose bg-gray-100 rounded-md">
7171
{image && !image.isEmpty() && (
7272
<img src={image.toDataURL()} alt="QRCode" />
7373
)}
7474
</section>
7575
<textarea
76-
className="flex-1 min-h-full p-4 bg-white rounded-md"
76+
className="flex-1 min-h-full p-2 bg-white rounded-md"
7777
value={content}
7878
readOnly
7979
/>

src/components/regex/RegexTester.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ const RegexTester = () => {
5858
<div className="flex items-center space-x-2">
5959
<input
6060
onChange={handleChangeSearch}
61-
className="flex-1 px-4 py-1 bg-white rounded-md"
61+
className="flex-1 px-2 py-1 bg-white rounded-md"
6262
value={search}
6363
/>
6464
<input
6565
onChange={handleChangeFlag}
66-
className="w-1/12 px-4 py-1 bg-white rounded-md"
66+
className="w-1/12 px-2 py-1 bg-white rounded-md"
6767
value={flag}
6868
/>
6969
</div>
@@ -83,7 +83,7 @@ const RegexTester = () => {
8383
</div>
8484
<textarea
8585
onChange={handleChangeInput}
86-
className="flex-1 p-4 bg-white rounded-md"
86+
className="flex-1 p-2 bg-white rounded-md"
8787
value={input}
8888
/>
8989
</section>
@@ -101,7 +101,7 @@ const RegexTester = () => {
101101
</span>
102102
</div>
103103
<section
104-
className="flex-1 w-full p-4 whitespace-pre bg-gray-100 rounded-md"
104+
className="flex-1 w-full p-2 whitespace-pre bg-gray-100 rounded-md"
105105
dangerouslySetInnerHTML={{ __html: output }}
106106
/>
107107
</section>

src/components/sql/SqlFormatter.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ const SqlFormatter = () => {
6262
<div className="flex flex-1 min-h-full space-x-2">
6363
<textarea
6464
onChange={handleChangeInput}
65-
className="flex-1 min-h-full p-4 bg-white rounded-md"
65+
className="flex-1 min-h-full p-2 bg-white rounded-md"
6666
value={input}
6767
disabled={opening}
6868
/>
6969
<textarea
70-
className="flex-1 min-h-full p-4 bg-gray-100 rounded-md"
70+
className="flex-1 min-h-full p-2 bg-gray-100 rounded-md"
7171
value={output}
7272
readOnly
7373
/>

0 commit comments

Comments
 (0)