설치
버전을 고정해 패키지를 설치하고, 소스 또는 사전 컴파일된 CSS를 선택한 뒤 첫 컴포넌트를 확인하세요.
이 페이지의 내용
@master/ui를 설치하고 스타일시트를 로드한 뒤, 컴포넌트 클래스를 적용한 네이티브 요소를 렌더링하세요. 프로젝트에서 Master CSS를 사용한다면 패키지 소스를 앱 스타일과 함께 컴파일하세요. 그 외에는 사전 컴파일된 스타일시트를 사용하세요. 이 스타일시트는 Master CSS 유틸리티 없이 컴포넌트 스타일을 제공합니다.
컴포넌트 스타일을 적용하는 두 가지 방법
페이지에 스타일을 적용할 방법을 하나 선택하세요. 소스를 가져오면 유틸리티 생성에 쓰이는 클래스와 함께 앱의 Master CSS 컴파일러에서 처리됩니다. 패키지의 standalone.css는 이미 컴파일되어 있으므로 바로 로드할 수 있습니다. 두 방법 모두 컴포넌트 스타일을 제공합니다. 사전 컴파일된 스타일시트를 사용하는 경우 레이아웃에는 프로젝트 자체 CSS가 필요합니다.
#AI 에이전트로 설정
코딩 에이전트로 이 설정을 진행할 수 있습니다. 앱의 루트 디렉터리에서 에이전트에 아래 프롬프트를 붙여 넣으세요. 에이전트는 프로젝트를 살펴본 뒤, 파일을 변경하기 전에 스타일시트 적용 방식, 가져올 범위, 에이전트 설정, 아이콘, 기존 컴포넌트 라이브러리의 처리 방법을 묻습니다. 그런 다음 버전을 고정한 패키지를 설치하고 스타일시트를 가져온 뒤, 첫 컴포넌트를 브라우저와 master-ui check로 확인합니다.
You are working in an existing web application. Set up Master UI end to end. Documentation: https://ui.master.co/guide/installation.md First inspect the project before editing: package manager, framework and build tool, whether Master CSS is set up (the installed @master/css version, and the app stylesheet that contains @import '@master/css' and where it is loaded), any component library or styling system already in use, React, Svelte or Vue, an existing master-ui.json, the dev/lint/build/test commands, and agent guidance files such as AGENTS.md. Before editing, ask me these and wait for the answers. Do not choose them yourself: - Stylesheet route: source (the default; @import '@master/ui' compiled by Master CSS 2.1 or later, with utilities for layout) or precompiled (@master/ui/standalone.css, no Master CSS and no utilities). If the project has no Master CSS and I choose source, set it up first by following https://css.master.co/guide/installation. - Import scope: the full library in one import (the default); npx master-ui init, which writes ui/index.css with one @import per stylesheet and master-ui.json for components the project may later own; or, for an app that loads styles on demand, one module import per stylesheet (import '@master/ui/components/<name>.css' in the module that renders the component). A project takes exactly one of these: never combine them, and never @import a single component stylesheet from CSS. If a dependency built on Master UI already imports its stylesheets from modules, the app must use module imports too. See https://ui.master.co/guide/installation#one-route. - Agent setup: the full setup (the master-ui skill, Master UI guidance in AGENTS.md and a check:ui script) or minimal (package and stylesheet only). - Existing components: if the project already uses another component library, whether to leave it in place (the default) and use Master UI only for new interface, or replace the components I name. Never replace components I have not named. - Icons: Master Icons (the default; the drawings Master UI's own components and examples use), the icon library the project already has, or none for now. Never replace icons I have not named. Then adopt Master UI conservatively: 1. Run every command from the app root, where its package.json lives, with the project's package manager. 2. Install the package at an exact version: npm install @master/ui --save-exact (bun add @master/ui --exact, pnpm add @master/ui --save-exact). A minor or patch release keeps every public name but can change how a component looks, so keep the version pinned and review each upgrade. 3. Load the stylesheet in the stylesheet the app already loads. Source route: add @import '@master/ui'; on the line after @import '@master/css';, or, with npx master-ui init, @import './ui/index.css'; in its place (adjust the path to where ui/ is), or, with module imports, @import '@master/ui/theme.css'; in its place and import '@master/ui/components/<name>.css' in each module that renders that component. Precompiled route: @import '@master/ui/base.css'; then @import '@master/ui/standalone.css';, and omit base.css if the project already has an equivalent reset. Installing the package alone does not load anything. Then set the page's viewport as https://ui.master.co/guide/installation#set-the-viewport shows: the viewport tag and the short script after it that stops iOS zooming onto a focused field. For module imports, put <style>@layer theme, base, defaults, components, utilities;</style> in the document head before any stylesheet. 4. Add no behavior script and no framework component yet. When a pattern that needs one is used later, follow https://ui.master.co/guide/behaviors, or https://ui.master.co/guide/frameworks with npx master-ui add <name> in React, Svelte or Vue. 5. If I chose Master Icons: install exactly one package at an exact version, for the framework the app uses: @master/icons-react, -vue, -svelte, -preact or -astro, or @master/icons for plain HTML. Never invent an icon name: look it up with node node_modules/@master/icons/skills/master-icons/scripts/search.mjs "<words>". Pick the drawing by the size the component gives the icon (16 up to 17px, 20 for 18 to 22px, 24 above), import that native drawing (@master/icons-react/native/16/soft/search) and put class "icon" on it. Never set stroke-width in CSS: choose a strokeWidth on a fixed entry instead. Keep the accessible name on the control, not the icon. See https://ui.master.co/components/icon.md#master-icons. 6. If I chose the full agent setup: install the skill with npx skills add master-co/ui --skill master-ui (and, with Master Icons, copy node_modules/@master/icons/skills/master-icons into the agent's skills folder), append the Master UI block from https://ui.master.co/guide/ai.md#agents-md to AGENTS.md with the project's actual validation commands below it, and add "check:ui": "master-ui check --strict" to the package.json scripts. 7. If I chose to replace named components, rewrite each one's markup from its contract (npx master-ui contract <name>), keep its behavior and accessible names, and remove the old dependency only after nothing uses it. 8. Preserve the existing architecture, styling and component library unless I chose otherwise, and avoid unrelated refactors. 9. Verify: start the dev server and render <button type="button" class="btn btn-primary">Save changes</button> on a visible page (className in JSX). Confirm an ink face in light mode, a pale face in dark mode and a visible focus ring when it is reached with Tab. If it looks like an unstyled browser button, confirm the page loads the stylesheet and the compiled CSS contains .btn. With Master Icons, put a 16px icon in the button and confirm its stroke is 1px. Run npx master-ui check on the file that holds the button and fix what it reports. Then remove the button unless I want to keep it, and run the project's lint, build and tests. When finished, summarize the changed files, the installed version, the route and options chosen, behavior intentionally left unchanged, the validation results, and anything not verified in a browser.
#Master CSS 설정
소스 스타일시트를 사용하려면 먼저 Master CSS 2.1 이상을 설치하고 사용하는 프레임워크와 연동하세요. Vite, Astro, Next.js, Svelte 등의 설정 방법은 Master CSS 설치 가이드를 따르세요.
#패키지 설치
npm install @master/ui --save-exactbun add @master/ui --exact 또는 pnpm add @master/ui --save-exact 등 원하는 패키지 관리자를 사용할 수 있습니다. 마이너 릴리스와 패치 릴리스는 모든 공개 이름을 유지하지만, 컴포넌트의 모양은 바뀔 수 있습니다. 버전을 고정하고 업그레이드할 시점을 직접 결정하세요. 업그레이드 후 실행할 명령은 안정성을 참고하세요.
#스타일시트 가져오기
앱 스타일시트에서 Master CSS 프리셋 다음에 Master UI를 가져오세요:
@import '@master/css';@import '@master/ui';프리셋은 캐스케이드 레이어 순서를 theme, base, defaults, components, utilities로 선언합니다. Master UI는 components 레이어 안의 components.ui 레이어에 규칙을 추가하므로 마크업의 유틸리티가 여전히 우선하며, @layer components에 작성한 프로젝트 규칙도 마찬가지로 우선합니다.
#뷰포트 설정
필드는 어떤 포인터에서도 같은 글자 크기를 유지합니다. 대부분 14px로, 인터페이스의 나머지 부분과 같습니다. iOS는 글자 크기가 16px보다 작은 필드가 포커스를 받으면 페이지를 그 필드까지 확대하고, 이후에도 원래대로 되돌리지 않습니다. 뷰포트의 최대 배율을 제한하면 이 확대가 멈추며, iOS에서는 뷰포트 설정과 관계없이 두 손가락으로 확대할 수 있습니다. Android 브라우저는 이 제한을 따라 두 손가락 확대까지 막으므로, -webkit-touch-callout을 지원하는 iOS에서만 설정합니다.
<meta name="viewport" content="width=device-width, initial-scale=1"><script> if (CSS.supports('-webkit-touch-callout', 'none')) { const viewport = document.querySelector('meta[name="viewport"]') if (viewport) viewport.content += ', maximum-scale=1' }</script>프레임워크가 이미 작성한 뷰포트 태그는 그대로 두고, 스크립트를 그 뒤, 예를 들어 <head>의 끝이나 <body>의 시작 부분에 둡니다. 사용자가 필드에 포커스를 둘 수 있기 전에만 실행되면 됩니다. 스크립트가 없어도 모든 것이 동작하며, iOS가 포커스를 받을 때 페이지를 확대할 뿐입니다. 대신 터치스크린에서 필드의 글자 크기를 16px로 키우지 마십시오. 같은 줄의 버튼, 셀렉트와 어긋나게 됩니다.
#설치 확인
앱이 app.css를 로드하는지 확인한 뒤, 렌더링되는 페이지에 버튼을 추가하세요. JSX에서는 class 대신 className을 사용하세요.
<button type="button" class="btn btn-primary">Save changes</button>기존 개발 명령으로 앱을 실행하세요. 라이트 모드에서는 버튼 표면이 잉크처럼 짙고 다크 모드에서는 옅게 표시되며, 키보드로 포커스를 옮기면 포커스 윤곽선이 보여야 합니다. 이 모양을 표시하는 데는 동작 스크립트가 필요하지 않습니다. 변경 사항을 저장하려면 앱의 작업 핸들러가 필요합니다.
스타일이 적용되지 않은 브라우저 기본 버튼처럼 보이면, 페이지에서 app.css를 로드하는지와 컴파일 결과에 .btn이 포함되어 있는지 확인하세요. 소스를 가져오는 경우에는 Master CSS 연동이 이 스타일시트를 처리하는지도 확인하세요. 그런 다음 마크업을 검사하세요.
#사용하는 컴포넌트만 가져오기
각 스타일시트는 개별적으로도 내보냅니다. 스타일을 그것이 필요한 모듈과 함께 불러오는 앱을 위한 방법입니다. 공통 테마는 앱 스타일시트에 두고, 각 컴포넌트는 그 컴포넌트를 렌더링하는 모듈에서 가져오세요:
@import '@master/css';@import '@master/ui/theme.css';import '@master/ui/components/button.css'import '@master/ui/components/spinner.css'문서의 <head>에서 모든 스타일시트보다 먼저 캐스케이드 레이어 순서를 선언하세요. 라우트의 컴포넌트 CSS가 app.css보다 먼저 로드될 수 있습니다. components가 먼저 선언되면 프리셋의 base가 뒤에 놓여 리셋이 컴포넌트 스타일을 덮을 수 있습니다.
<style>@layer theme, base, defaults, components, utilities;</style>번들러는 한 모듈을 여러 모듈이 가져오더라도 한 번만 불러옵니다. 따라서 두 모듈이 모두 button.css를 가져와도 한 번만 출력됩니다. 마크업에서 사용하는 모든 클래스의 스타일시트를 포함하세요. 예를 들어 버튼 안에 icon 또는 spinner가 들어 있다면 해당 컴포넌트의 스타일시트도 필요합니다. 전체 스타일시트를 한 번에 가져오면 이 목록을 직접 관리할 필요가 없습니다.
이 가져오기는 항상 모듈 가져오기로 작성하고 CSS @import 규칙으로 작성하지 마세요. 라이브러리 전체를 가져오는 프로젝트에도 추가하지 마세요. 이유는 한 가지 방식만 사용하기에서 설명합니다.
#스타일시트마다 한 번씩 가져오기
패키지에는 간단한 명령줄 도구가 포함되어 있습니다. init은 테마와 각 스타일시트를 한 줄씩 가져오는 ui/index.css와 프로젝트가 소유한 항목을 기록하는 master-ui.json을 생성합니다.
npx master-ui init@import '@master/css';@import './ui/index.css';@master/ui로 전체를 가져오는 대신 이 진입 파일을 사용할 수 있습니다. 그러면 이 파일이 프로젝트에서 라이브러리를 불러오는 유일한 출처이자 라이브러리의 다른 스타일시트를 가져오는 유일한 스타일시트가 됩니다. 이 방식은 선택 사항입니다. 가져오기 목록을 직접 관리하거나 선택한 컴포넌트의 소스를 직접 관리하려는 경우에 사용하세요. 마크업에서 해당 스타일시트의 클래스를 더 이상 사용하지 않을 때만 그 줄을 삭제하세요.
#한 가지 방식만 사용하기
CSS @import는 파일 내용을 포함하는 것이지 모듈을 불러오는 것이 아닙니다. 같은 스타일시트를 두 파일이 가져오거나, 라이브러리 전체와 함께 불러온 뒤 개별적으로 다시 가져오면 그 스타일시트는 출력에 두 번 기록됩니다. 바이트가 중복되고, 어느 쪽이 뒤에 오는지는 페이지마다 달라집니다. 모듈로 가져온 스타일시트는 한 번만 로드됩니다. 따라서 프로젝트는 한 가지 방식을 정해 그 방식만 사용합니다.
| 프로젝트 | 방식 |
|---|---|
| 애플리케이션 | 스타일시트 하나에 @import '@master/ui';를 작성하거나 그 자리에 ui/index.css를 사용합니다. 프로젝트의 다른 곳에서는 라이브러리의 스타일시트를 가져오지 않습니다 |
| 스타일을 필요할 때 불러오는 애플리케이션 | 스타일시트마다 모듈 가져오기를 하나씩 작성합니다: import '@master/ui/components/<name>.css' |
| Master UI를 기반으로 만든 라이브러리 | 스타일시트마다 모듈 가져오기를 하나씩, 라이브러리 자체의 모듈에 작성합니다 |
| 그런 라이브러리를 사용하는 애플리케이션 | 마찬가지로 스타일시트마다 모듈 가져오기를 하나씩 작성합니다. 라이브러리의 가져오기가 이미 번들에 들어 있으므로 전체 가져오기를 사용하면 해당 스타일시트가 한 번 더 출력됩니다 |
- 한 프로젝트에서 두 방식을 함께 사용하지 마세요. 전체 가져오기와 개별 스타일시트의 모듈 가져오기가 함께 있으면 그 스타일시트가 두 번 출력됩니다.
- 개별 컴포넌트를 CSS
@import로 가져오지 마세요. 프로젝트의 스타일시트와<style>블록 어디에서도@master/ui/components/<name>.css를 가져오지 않습니다. 진입 파일만 그렇게 합니다. 패키지 자체의 진입 파일이나init이 생성하는ui/index.css입니다. - 프로젝트 규칙은 번들의 순서에 의존하지 않습니다. 빌드는 CSS 순서가 모듈 가져오기 순서와 일치한다고 보장하지 않으며, 보장할 필요도 없습니다. 라이브러리의 규칙이
components.ui에 있으므로,@layer components에 작성한 프로젝트 규칙은 컴포넌트 스타일시트가 어디에 놓이든 선택자를 길게 만들지 않아도 컴포넌트보다 우선합니다. 이 레이어에서 따라오는 결과는 커스터마이징에서 설명합니다.
프로젝트가 정한 방식에서 벗어나면 npx master-ui check가 stylesheet-import, mixed-imports 또는 repeated-import를 보고합니다. 각 코드는 계약에서 설명합니다.
#동작
대부분의 컴포넌트에는 스크립트가 필요하지 않습니다. 콤보박스, 명령 팔레트, 캘린더처럼 대응하는 네이티브 요소가 없는 패턴에는 패키지에서 각각 참조 구현 스크립트를 제공합니다.
import { attach } from '@master/ui/behaviors'const detach = attach()마크업이 생성된 뒤 브라우저 코드에서 attach()를 호출하세요. 호출 시점에 인식한 패턴에 동작을 연결하고 정리 함수를 반환합니다. 해당 마크업을 제거하기 전에 detach()를 호출하세요. 이후에 추가되는 요소는 감시하지 않으며 컨텍스트 메뉴 대상도 설정하지 않습니다. 연결 범위를 지정하거나 개별 함수를 사용하려면 동작을 참고하세요. React, Svelte 또는 Vue에서는 프레임워크 컴포넌트로 동작의 수명 주기를 관리하세요.
#Master CSS 없이 사용
패키지에는 일반 CSS로 컴파일된 컴포넌트 스타일이 포함되어 있습니다. CSS 가져오기를 지원하는 번들러에서는 버전을 고정해 설치한 패키지를 사용할 수 있습니다:
@import '@master/ui/base.css';@import '@master/ui/standalone.css';base.css는 box-sizing: border-box와 폼 컨트롤 글꼴을 포함한 프리셋의 리셋 스타일을 제공합니다. 프로젝트에 이미 같은 역할을 하는 리셋 스타일이 있다면 이 가져오기를 생략하세요.
정적 페이지에서는 설치한 패키지의 컴파일된 파일을 서버에서 공개하는 디렉터리로 복사하세요. 예를 들어 public/ 디렉터리를 /에서 제공하는 경우는 다음과 같습니다:
mkdir -p public/stylescp node_modules/@master/ui/dist/base.css public/styles/master-ui-base.csscp node_modules/@master/ui/dist/standalone.css public/styles/master-ui.css<link rel="stylesheet" href="/styles/master-ui-base.css"><link rel="stylesheet" href="/styles/master-ui.css"><button type="button" class="btn btn-primary">Save changes</button>복사한 파일은 설치한 패키지 버전과 정확히 일치합니다. 패키지 버전을 올릴 때는 파일을 다시 복사하세요. 이 방식은 앱에서 CSS를 컴파일할 필요가 없습니다.
컴파일된 스타일시트는 소스 빌드와 동일한 캐스케이드 레이어와 디자인 토큰을 선언합니다. 방문자의 색상 모드 설정을 따르며, data-theme="light" 또는 data-theme="dark"로 페이지 전체나 하위 트리의 색상 모드를 고정할 수 있습니다. Master CSS 유틸리티는 포함되어 있지 않으므로 레이아웃에는 자체 CSS를 사용하고 레이아웃, 블록 또는 페이지를 복사할 때는 유틸리티 클래스를 교체하세요.
#마크업 검사
각 스타일시트의 마크업 계약에는 사용할 클래스, 각 클래스를 적용할 요소, 필요한 속성이 정의되어 있습니다. check는 템플릿을 읽어 계약을 위반한 부분을 보고합니다.
npx master-ui check패키지가 설치된 상태에서 프로젝트 루트에서 실행하세요. HTML과 JSX, Svelte, Vue, Astro 등의 템플릿을 렌더링 없이 검사합니다. 검사에서 지적한 문제를 해결한 뒤 브라우저에서 화면에 표시되는 결과와 키보드 조작을 확인하세요. 정적 검사를 통과했다는 사실만으로 접근성이나 브라우저 지원 여부를 확인할 수는 없습니다. 진단 결과와 CI에서의 사용 방법은 AI와 함께 작업하기에서 다룹니다.
#테마 맞춤 설정
브랜드 색상, 모서리 반경, 포커스 색상과 같은 공통 값을 변경하려면 테마 설정을 참고하세요. 기본 테마에서는 각 값의 역할과 기본값을 설명합니다. 변경 범위가 인스턴스 하나나 컴포넌트 하나에 한정된다면 맞춤 설정에서 적절한 레이어를 선택하세요.