[WebUI]Tailwind + nextjs(form) โ€“ 3

๐Ÿ‘‰๐Ÿป ์•„๋ž˜๋Š” ๊ธ€์“ฐ๊ธฐ ํ•  ๋•Œ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ํผ ๋ถ€๋ถ„์˜ UI๋””์ž์ธ์ž…๋‹ˆ๋‹ค.
Below is the UI design for the form section frequently used when writing.

๐Ÿ‘‰๐Ÿป tailwind๋Š” ์•„๋ž˜์˜ ์›น์‚ฌ์ดํŠธ์˜ ๊ฒ€์ƒ‰์„ ํ†ตํ•ด์„œ ์ž์„ธํ•œ ๋‚ด์šฉ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
You can find detailed information about Tailwind by searching on the website below.

โœ”๏ธ npm run dev๋กœ ์„œ๋ฒ„์‹คํ–‰ ํ›„ ๋ธŒ๋ผ์šฐ์ €์—์„œ http://localhost:3000/form-tailwind ๋˜๋Š” http://localhost:3000/form-css ๋กœ ๋””์ž์ธ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
After starting the server with npm run dev, you can view the design in your browser at http://localhost:3000/form-tailwind or http://localhost:3000/form-css.

https://tailwindcss.com/docs/installation/using-vite

๐Ÿ‘‰๐Ÿป ์ „์ฒด ์ฝ”๋“œ๋Š” ๊นƒํ—ˆ๋ธŒ์—์„œ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
You can find the full code on GitHub.

https://github.com/gideonslife01/flm-webui


๐Ÿ“ main

โœ”๏ธ ์ฝ”๋“œ ์ œ์ผ ์œ—๋ถ€๋ถ„์œผ๋กœ ๋ ˆ์ด์•„์›ƒ๊ณผ ๋ฐฐ๊ฒฝ์ƒ‰๋“ฑ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
Configure settings such as the layout and background color at the very top of the code.

โœ”๏ธ ์ฝ”๋“œ / Code

# Tailwind
<main className="min-h-screen flex items-center justify-center bg-gray-50 p-4"> 
... ...
</main>

# CSS
 <main className="form-page"> ... ... </main>
      <style>{`
        /* ์ „์ฒด ํ™”๋ฉด ๊ฐ€์šด๋ฐ / flex center */
        .form-page {
          min-height: 100vh;
          display: flex;
          align-items: center;
          justify-content: center;
          background-color: #f9fafb;
          padding: 16px;
        } ... ...
      </style>

โœ”๏ธ ์„ค๋ช… / Description

— Tailwind

1)item-center()์™€ justify-center()๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ flex๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
Use flex to utilize item-center() and justify-center().

2)bg-gray-50์€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์ปฌ๋Ÿฌ p-4๋Š” mainํƒœ๊ทธ ํŒจ๋”ฉ์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.
bg-gray-50 applies the background color, and p-4 applies padding to the main tag.

3)min-h-screen๋Š” ์ตœ์†Œ๋†’์ด๋กœ ํ™”๋ฉด ๋†’์ด๋งŒํผ์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.
min-h-screen sets the minimum height to the height of the screen.

— CSS

1) Tailwind์™€ ๋™์ผํ•œ ์š”์†Œ๋Š” display: flext;, align-itmes: center;justify-content : center; ์ž…๋‹ˆ๋‹ค.
The elements equivalent to Tailwind are display: flex;, align-items: center;, and justify-content: center;.

2) CSS์—์„œ ํŒจ๋”ฉ์€ padding:16px, ๋ฐฐ๊ฒฝ์ƒ‰์€ background-color: #f9fafb;
In CSS, the padding is padding: 16px; and the background color is background-color: #f9fafb;.

3)CSS์—์„œ min-h-screen์€ min-height: 100vh; ์ž…๋‹ˆ๋‹ค.
In CSS, min-h-screen corresponds to min-height: 100vh;.

๐Ÿ“ input

โœ”๏ธ ํผ ์š”์†Œ๋กœ ์ด๋ฆ„ ์ด๋ฉ”์ผ ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
These are the name and email form elements.

โœ”๏ธ ์ฝ”๋“œ / Code

 # Tailwind        
     {/* ์ด๋ฆ„ / Name Input */}
            <input
              value={form.name}
              onChange={(e) => setForm({...form, name: e.target.value})}
              placeholder="ํ™๊ธธ๋™/John Doe"
              className="w-full px-4 py-3 bg-gray-50 border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:bg-white transition-all"
            />

          {/* ์ด๋ฉ”์ผ / Email Input */}
            <input
              type="email"
              value={form.email}
              onChange={(e) => setForm({...form, email: e.target.value})}
              placeholder="example@email.com"
              className="w-full px-4 py-3 bg-gray-50 border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:bg-white transition-all"
            />
          </div>

# CSS
       {/* ์ด๋ฆ„ / Name Input */}
              <input
                value={form.name}
                onChange={(e) => setForm({...form, name: e.target.value})}
                placeholder="ํ™๊ธธ๋™/John Doe"
                className="input"
              />

       {/* ์ด๋ฉ”์ผ / Email Input */}
              <input
                type="email"
                value={form.email}
                onChange={(e) => setForm({...form, email: e.target.value})}
                placeholder="example@email.com"
                className="input"
              />

      <style>{` ... ...
        /* ์ž…๋ ฅ์นธ / input */
        .input {
          width: 100%;
          padding: 12px 16px;
          background-color: #f9fafb;
          border: 1px solid #e5e7eb;
          border-radius: 12px;
          font-size: 14px;
          outline: none;
          transition: all 0.2s;
          box-sizing: border-box;
        }
        .input:focus {
          background-color: white;
          border-color: #3b82f6;
          box-shadow: 0 0 0 2px rgba(59,130,246,0.3);
        }

    ... ... `}</style>

โœ”๏ธ ์„ค๋ช… / Description

— Tailwind & CSS

1) ํฌ๊ธฐ์™€ ์—ฌ๋ฐฑ / Size & Spacing

  • w-full width: 100%
    — ๋ถ€๋ชจ ๋„ˆ๋น„ ๊ฝ‰ ์ฑ„์šฐ๊ธฐ / Fill parent width
  • px-4 = padding-left: 16px; padding-right: 16px
    — ์ขŒ์šฐ ์•ˆ์ชฝ ์—ฌ๋ฐฑ / left and right inner margins
  • py-3 = padding-top: 12px; padding-bottom: 12px
    — ์œ„ ์•„๋ž˜ ์•ˆ์ชฝ ์—ฌ๋ฐฑ / Top and bottom inner margins

2) ์ƒ‰๊ณผ ํ…Œ๋‘๋ฆฌ / Color & Border

  • bg-gray-50 = background: #f9fafb
    — ๊ฑฐ์˜ ํฐ์ƒ‰์— ๊ฐ€๊นŒ์šด ์—ฐํ•œ ํšŒ์ƒ‰ / Light gray bordering on white
  • border = border-width: 1px
    — ํ…Œ๋‘๋ฆฌ ์ผœ๊ธฐ / Turn on border
  • border-gray-200 = border-color: #e5e7eb
    — ํ…Œ๋‘๋ฆฌ ์ƒ‰ ์—ฐํ•œ ํšŒ์ƒ‰ / Light gray border color
  • rounded-xl = border-radius: 12px
    — ๋ชจ์„œ๋ฆฌ ๋‘ฅ๊ธ€๊ฒŒ / Round the corners
  • text-sm = font-size: 14px
    — ๊ธ€์ž ์ž‘๊ฒŒ / Smaller text

3) ํฌ์ปค์Šค – ๊ธ€์“ฐ๊ธฐ ์œ„ํ•ด์„œ input box๋ฅผ ํด๋ฆญ ํ–ˆ์„ ๋•Œ
Focus โ€“ When clicking the input box to type

  • focus:outline-none
    — ํด๋ฆญํ•  ๋•Œ ๋‚˜์˜ค๋Š” ๊ฒ€์€ ํ…Œ๋‘๋ฆฌ ์—†์• ๊ธฐ / Remove the black border that appears when clicking
  • focus:ring-2
    –ํŒŒ๋ž€์ƒ‰ ๋น›๋‚˜๋Š” ํ…Œ๋‘๋ฆฌ 2px ์ƒ๊ธฐ๊ธฐ / Add a 2px glowing blue border.
  • focus:ring-blue-500
    — ๊ทธ ๋น›๋‚˜๋Š” ํ…Œ๋‘๋ฆฌ ์ƒ‰์„ ํŒŒ๋ž€์ƒ‰์œผ๋กœ ์„ค์ • / Set the glowing border color to blue.
  • focus:bg-white
    — ํด๋ฆญํ•˜๋ฉด ์„ค์ •๋œ ํšŒ์ƒ‰ ๋ฐฐ๊ฒฝ์ƒ‰์ƒ์ธ ํšŒ์ƒ‰์—์„œ input box๋ฐฐ๊ฒฝ์ƒ‰์ด ํฐ์ƒ‰์œผ๋กœ ๋ฐ”๋€œ
    When clicked, the input box background color changes from the preset gray to white.

4)์• ๋‹ˆ๋ฉ”์ด์…˜ / Animation

  • transition-all = transition: all 0.15s
    — ์ƒ‰๊ณผ ๋ง์ด ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ์ „ํ™˜๋˜๊ฒŒ ์„ค์ • / Set the color and ring to transition smoothly.

๐Ÿ“ textarea

โœ”๏ธ ํผ ์š”์†Œ๋กœ ๊ธ€ ์ž‘์„ฑ ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
This is the section for writing posts using form elements.

โœ”๏ธ ์ฝ”๋“œ / Code

# Tailwind
            <textarea
              value={form.message}
              onChange={(e) => setForm({...form, message: e.target.value})}
              placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”/Please enter your message..."
              rows={4}
              className="w-full px-4 py-3 bg-gray-50 border border-gray-200 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:bg-white transition-all resize-none"
            />

# CSS
              <textarea
                value={form.message}
                onChange={(e) => setForm({...form, message: e.target.value})}
                placeholder="๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”/Please enter your message..."
                rows={4}
                className="input textarea"
              />

      <style>{` ... ...
        /* ์ž…๋ ฅ์นธ / input */
        .input {
          width: 100%;
          padding: 12px 16px;
          background-color: #f9fafb;
          border: 1px solid #e5e7eb;
          border-radius: 12px;
          font-size: 14px;
          outline: none;
          transition: all 0.2s;
          box-sizing: border-box;
        }
        .input:focus {
          background-color: white;
          border-color: #3b82f6;
          box-shadow: 0 0 0 2px rgba(59,130,246,0.3);
        }
        .textarea {
          resize: none;
        } ... ...
      `}</style>

โœ”๏ธ ์„ค๋ช… / Description

— Tailwind & CSS

1)resize-none = resize: none;์„ ์ œ์™ธํ•˜๊ณค input ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
resize-none is the same as input, except for resize: none;.

2)resize-none = resize: none;๋Š” textarea์˜ ํฌ๊ธฐ๋ฅผ ๋งˆ์šฐ์Šค๋กœ ์กฐ์ ˆํ•  ์ˆ˜ ์—†๊ฒŒ ์ž ๊ทธ๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.
resize-none (or resize: none;) is a feature that locks a textarea’s size, preventing it from being adjusted with the mouse.

๐Ÿ“ Label

โœ”๏ธ ์ด๋ฆ„,์ด๋ฉ”์ผ ๋ถ€๋ถ„์œผ๋กœ ๊ฐ ์š”์†Œ์— ํ…์ŠคํŠธ ๋ผ๋ฒจ์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.
Display text labels for each element, such as “Name” and “Email.”

โœ”๏ธ ์ฝ”๋“œ / Code

# Tailwind
<label className="text-sm font-bold text-gray-700">์ด๋ฆ„/Name</label>

# CSS
<label className="label">์ด๋ฆ„/Name</label>
<style>{` ... ...
        .label {
          font-size: 14px;
          font-weight: 700;
          color: #374151;
        }
... ... `}
</style>

โœ”๏ธ ์„ค๋ช… / Description

— Tailwind & CSS

1)text-sm

  • font-size: 14px

2)font-bold

  • font-weight: 700

3. text-gray-700

  • color: #374151

๐Ÿ“ ์Šคํฌ๋ฆฐ ์ƒท / ScreenShot

์š”ํ•œ๋ณต์Œ 8์žฅ 32์ ˆ / John 8:32

“๊ทธ๋ฆฌ๊ณ  ๋„ˆํฌ๋Š” ์ง„๋ฆฌ๋ฅผ ์•Œ๊ฒŒ ๋  ๊ฒƒ์ด๋ฉฐ, ์ง„๋ฆฌ๊ฐ€ ๋„ˆํฌ๋ฅผ ์ž์œ ๋กญ๊ฒŒ ํ•  ๊ฒƒ์ด๋‹ค.”

“Then you will know the truth ,and the truth will set you free”

Leave a Reply