Tailwind CSS SolidJS
SolidJS는 인기 있고 오픈소스인 선언적 JavaScript 라이브러리예요. 웹을 위한 반응형(reactive) UI 인터페이스를 만들어 성능이 뛰어난 벤치마크를 보장하고, JSX의 유연성을 활용하며 TypeScript, Astro, Vite도 지원해요.
SolidJS 라이브러리는 많은 웹 개발자와 소규모 회사가 사용하며, OpenAI의 ChatGPT 인터페이스(인공지능 UI/UX 인터랙션)에서도 사용된 것이 확인됐어요.
이 가이드의 단계를 따라가다 보면 SolidJS로 새 프로젝트를 만들고, Tailwind CSS를 설치·설정해서 유틸리티 클래스를 활용하며, 마지막으로 Flowbite의 무료 오픈소스 UI 컴포넌트를 설치하고 통합하는 방법을 배울 수 있어요.
출처: 문서
본문
요구 사항 (Requirements)
시작하기 전에 SolidJS, Tailwind CSS, Flowbite를 모두 설치할 수 있도록 로컬 컴퓨터에 Node.js가 설치되어 있는지 확인하세요.
SolidJS 프로젝트 만들기
Vite 템플릿을 사용해 새 SolidJS 프로젝트를 만들려면 터미널에서 다음 명령을 실행하세요.
npx degit solidjs/templates/js flowbite-app
cd flowbite-app
이 명령은 기본 프로젝트 구조와 의존성 파일을 설정하는 보일러플레이트 프로젝트를 만들어요.
- NPM으로 프로젝트 의존성을 설치하세요.
npm install
- 로컬 개발 서버를 만들려면 다음 명령을 실행하세요.
npm run dev
새로 만든 SolidJS 프로젝트는 브라우저에서 http://localhost:3000으로 접근할 수 있어요.
- 터미널이나 배포 파이프라인에서 다음 명령으로 프로덕션 빌드를 만드세요.
npm run build
이제 작동하는 SolidJS 프로젝트 구성이 설치되었어요. Tailwind CSS와 Flowbite를 설치해 웹 UI 인터페이스를 더 빨리 만드는 단계로 진행할 수 있어요.
Tailwind CSS 설치
Tailwind CSS는 템플릿 안에서 PostCSS와 유틸리티 클래스를 활용해 UI 개발 속도를 높이는 가장 인기 있는 유틸리티 우선 CSS 프레임워크예요.
- 터미널에서 다음 명령을 실행해 NPM으로 Tailwind CSS를 설치하세요.
npm install --save-dev tailwindcss @tailwindcss/postcss postcss
- 새
postcss.config.mjs구성 파일을 만들고 다음 코드를 넣으세요.
// postcss.config.mjs
export default {
plugins: {
"@tailwindcss/postcss": {},
}
}
- SolidJS의 기본 CSS 파일인
./src/index.css에 Tailwind 기본 지시어를 import 하세요.
@import "tailwindcss";
npm run dev로 로컬 개발 서버를 재시작하면 이제App.jsx파일에서 테스트해 보며 SolidJS 프로젝트 안에서 유틸리티 우선 클래스를 사용할 수 있어요.
function App() {
return (
<div class={styles.App}>
<header class={styles.header}>
<img src={logo} class={styles.logo} alt="logo" />
<p>
Edit <code>src/App.jsx</code> and save to reload.
</p>
<a
class="text-4xl text-blue-600"
href="https://github.com/solidjs/solid"
target="_blank"
rel="noopener noreferrer"
>
Learn Solid, Tailwind CSS and Flowbite
</a>
</header>
</div>
);
}
export default App;
이제 SolidJS와 Tailwind CSS가 모두 로컬 프로젝트에 설치·구성되었어요. 이제 Flowbite의 UI 컴포넌트를 설정해 보세요.
Flowbite 설치
Flowbite는 Tailwind CSS의 클래스 위에 구축된 인기 있는 오픈소스 UI 컴포넌트 라이브러리예요. 내비게이션 바, 모달, 드롭다운, 데이트피커 같은 인터랙티브 UI 컴포넌트를 활용해 웹사이트와 애플리케이션 구축을 빠르게 시작할 수 있게 도와줘요.
- NPM으로 Flowbite를 의존성으로 설치하세요.
npm install flowbite --save
- 메인
index.cssCSS 파일에 Flowbite의 기본 테마 변수를 import 하세요.
@import "flowbite/src/themes/default";
- CSS에서 Flowbite 플러그인 파일을 import 하세요.
@plugin "flowbite/plugin";
- CSS에서 Flowbite의 소스 파일을 구성하세요.
@source "../../node_modules/flowbite";
이제 Flowbite가 설치되었으니 문서의 UI 컴포넌트를 SolidJS 프로젝트 안에서 사용할 수 있어요.
Flowbite 컴포넌트
Flowbite의 인터랙티브·비인터랙티브 컴포넌트를 모두 사용할 수 있어요. 먼저 새 Modal.jsx 컴포넌트를 만들어 Modal 컴포넌트를 추가해 보세요.
가장 중요한 점은 Flowbite에서 initFlowbite() 함수를 import 하고, SolidJS의 onMount 훅 메서드로 이 함수를 호출해서 인터랙티브 데이터 속성 이벤트를 초기화해야 한다는 거예요.
import { initFlowbite } from 'flowbite';
import { onMount } from 'solid-js';
function Modal() {
onMount(() => {
initFlowbite();
});
return (
<div>
<button data-modal-target="default-modal" data-modal-toggle="default-modal" class="block text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" type="button">
Toggle modal
</button>
<div id="default-modal" tabindex="-1" aria-hidden="true" class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
<div class="relative p-4 w-full max-w-2xl max-h-full">
<div class="relative bg-white rounded-lg shadow-sm dark:bg-gray-700">
<div class="flex items-center justify-between p-4 md:p-5 border-b rounded-t dark:border-gray-600 border-gray-200">
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">
Terms of Service
</h3>
<button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide="default-modal">
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
</svg>
<span class="sr-only">Close modal</span>
</button>
</div>
<div class="p-4 md:p-5 space-y-4">
<p class="text-base leading-relaxed text-gray-500 dark:text-gray-400">
With less than a month to go before the European Union enacts new consumer privacy laws for its citizens, companies around the world are updating their terms of service agreements to comply.
</p>
</div>
<div class="flex items-center p-4 md:p-5 border-t border-gray-200 rounded-b dark:border-gray-600">
<button data-modal-hide="default-modal" type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">I accept</button>
<button data-modal-hide="default-modal" type="button" class="py-2.5 px-5 ms-3 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-100 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700">Decline</button>
</div>
</div>
</div>
</div>
</div>
);
}
이 예시는 클릭하면 제목, 설명, 닫기 버튼이 있는 모달 컴포넌트를 여는 버튼을 추가해요.
이제 버튼 위에 마우스를 올렸을 때 추가 정보를 제공하는 툴팁 인디케이터를 보여줘 보세요.
<button data-tooltip-target="tooltip-default" type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Default tooltip</button>
<div id="tooltip-default" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-xs opacity-0 tooltip dark:bg-gray-700">
Tooltip content
<div class="tooltip-arrow" data-popper-arrow></div>
</div>
마지막으로 모달 안에 아코디언 컴포넌트를 추가해 보세요.
<div id="accordion-collapse" data-accordion="collapse">
<h2 id="accordion-collapse-heading-1">
<button type="button" class="flex items-center justify-between w-full p-5 font-medium rtl:text-right text-gray-500 border border-b-0 border-gray-200 rounded-t-xl focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-800 dark:border-gray-700 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 gap-3" data-accordion-target="#accordion-collapse-body-1" aria-expanded="true" aria-controls="accordion-collapse-body-1">
<span>What is Flowbite?</span>
<svg data-accordion-icon class="w-3 h-3 rotate-180 shrink-0" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5 5 1 1 5"/>
</svg>
</button>
</h2>
<div id="accordion-collapse-body-1" class="hidden" aria-labelledby="accordion-collapse-heading-1">
<div class="p-5 border border-b-0 border-gray-200 dark:border-gray-700 dark:bg-gray-900">
<p class="mb-2 text-gray-500 dark:text-gray-400">Flowbite is an open-source library of interactive components built on top of Tailwind CSS including buttons, dropdowns, modals, navbars, and more.</p>
</div>
</div>
</div>
이 예시들을 통해 Tailwind CSS와 SolidJS와 함께 Flowbite의 UI 컴포넌트를 활용해 성능이 뛰어나고 반응형인 웹 애플리케이션을 구축하는 방법을 잘 알 수 있을 거예요.
SolidJS 스타터 프로젝트
Flowbite의 오픈소스 커뮤니티가 이 가이드의 절차를 따른 SolidJS 스타터 프로젝트를 만들었어요. 다음 프로젝트에서 이 세 가지 기술을 빠르게 사용해 볼 수 있어요.
더 알아보기 (Learn more)
- SolidJS 문서 (공식)
- 프로젝트 생성, Tailwind CSS·Flowbite 설치, 모달·툴팁·아코디언 컴포넌트 사용법까지 단계별로 안내해요.