Attachment

선택적 아이콘, 메타데이터, 제거 버튼을 갖춘 손그림 파일 칩입니다.

개요

Attachment은 파일이나 리소스를 나타내는 컴팩트한 칩이에요 — 선택적 선행 아이콘, 선택적 메타데이터(크기 등)가 있는 이름, 선택적 제거 버튼. 업로드된 파일, 이메일 첨부, 또는 사용자가 검토하고 선택적으로 제거할 수 있는 참조 리소스를 보여줄 때 사용하세요.

구조

손그림 박스(@ghds/sketch-core)가 좌에서 우로 배치해요: 선택적 Icon, 쌓인 이름 + meta 열, 그리고 — onRemove가 설정되면 — 닫기 아이콘이 있는 제거 <button>. 모든 색상, 패딩, 반경, 스케치 파라미터는 @ghds/tokens(comp.attachment.*)에서 와요.

변형 및 상태

명명된 변형은 없어요 — 칩은 제공하는 선택적 부분(icon, meta, onRemove)에 따라 형성돼요.

State Status Notes
With icon Implemented icon prop을 통한 선행 @ghds/icons 글리프.
With meta Implemented 보조 줄, 예: 파일 크기.
Removable Implemented onRemove가 라벨이 지정된 제거 버튼을 렌더해요.
비활성화 Not implemented —
로딩 Not implemented —

사용법

Do

  • 사용자가 한눈에 파일을 판단할 수 있도록 meta에 읽기 쉬운 크기나 타입을 보여주세요.
  • 사용자가 분리할 수 있는 첨부에 onRemove를 제공하고, 기본 Remove {name} 라벨을 의미 있게 유지하세요.
  • 가능한 경우 파일 종류에 맞는 아이콘을 선택하세요.

Don't

  • 경계 없는 행에 긴 파일 이름을 넣지 마세요; 컨테이너 필요에 따라 줄바꿈이나 잘림을 하게 두세요.
  • 파일을 여는 버튼으로 Attachment를 사용하지 마세요 — 서술형 칩이며 제거 동작만 인터랙티브해요.

접근성

콘텐츠

name은 실제 파일 이름으로, meta는 짧고 사실적인 설명자(크기, 타입, 날짜)로 유지하세요. meta 안에 이름을 중복하지 마세요.

Props API

React@ghds/react

PropTypeDefaultDescription
namestring—주요 라벨로 표시되는 파일(또는 리소스) 이름. 필수.
metastring—보조 메타데이터, 예: "2.4 MB" 같은 읽기 쉬운 크기.
iconIconName—선택적 선행 아이콘(@ghds/icons 이름).
onRemove() => void—제공되면 이 핸들러를 호출하는 제거 버튼을 렌더해요.
removeLabelstring'Remove {name}'제거 버튼의 접근 가능한 라벨.
...restHTMLAttributes<HTMLDivElement>—네이티브 <div> 속성이 전달돼요.

Web Components@ghds/web-components

PropTypeDefaultDescription
namestring—주요 라벨로 표시되는 파일(또는 리소스) 이름.
metastring—보조 메타데이터, 예: 읽기 쉬운 크기.
iconstring—선택적 선행 아이콘(@ghds/icons 이름).
removablebooleanfalsereflected 속성; gh-remove를 emit하는 제거 버튼을 렌더해요.
gh-removeCustomEvent—제거 버튼을 누르면 발생해요(detail 없음).

React Native@ghds/react-native

PropTypeDefaultDescription
namestring—주요 라벨로 표시되는 파일(또는 리소스) 이름. 필수.
metastring—보조 메타데이터, 예: 읽기 쉬운 크기.
iconIconName—선택적 선행 아이콘(@ghds/icons 이름).
onRemove() => void—제공되면 이 핸들러를 호출하는 제거 버튼을 렌더해요.
removeLabelstring'Remove {name}'제거 버튼의 접근 가능한 라벨.
testIDstring—쿼리용 테스트 핸들.

코드 예시

// React — @ghds/react
import { Attachment } from '@ghds/react/attachment';

<>
  <Attachment name="newsletter.eml" meta="12 KB" icon="mail" />
  <Attachment name="quarterly-report.pdf" meta="2.4 MB" onRemove={() => detach()} />
</>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
  import '@ghds/web-components/attachment';
</script>
<gh-attachment name="newsletter.eml" meta="12 KB" icon="mail"></gh-attachment>
<gh-attachment name="quarterly-report.pdf" meta="2.4 MB" removable></gh-attachment>
<script>
  // gh-attachment는 `gh-remove` 이벤트만 보내요. 칩을 없애거나 목록을 갱신하는 건 직접 처리해야 해요
  document
    .querySelector('gh-attachment[removable]')
    .addEventListener('gh-remove', (e) => e.currentTarget.remove());
</script>
// React Native — @ghds/react-native
import { Attachment } from '@ghds/react-native/attachment';

<Attachment name="quarterly-report.pdf" meta="2.4 MB" onRemove={() => detach()} />;

라이브 데모

아래에서 React와 Web Components가 동일한 토큰으로 구동되며 라이브 렌더돼요 — 헤더에서 다크 모드를 토글하면 둘 다 동일하게 반응해요. React Native는 추가 react-native-web 연결 없이는 브라우저에서 실행할 수 없어요(이 사이트에 설정되지 않음), 따라서 사용법은 코드 샘플로 보여줘요. 제거 API가 다르다는 점에 유의하세요: React/React Native는 onRemove 콜백을 받고, Web Components는 removable을 설정하고 gh-remove 이벤트를 emit해요.

React @ghds/react

Web Components @ghds/web-components