SwapLabel

Data Display

두 라벨을 폭 애니메이션과 함께 교차 전환하는 표시부.

Usage

같은 자리에서 두 상태의 라벨을 부드럽게 전환해 보여줄 때 사용한다.

import

import

import { SwapLabel } from '@mildang/design-system/unofficial/Chat';

예제를 복사해 쓸 때 필요한 준비

@mildang/styled-system 은 이 저장소에서 Panda 가 생성하는 산출물이다. 저장소 안에서는 turbo run ship 이후 쓸 수 있고, 패키지 소비자는 자기 Panda 산출물이나 다른 레이아웃 수단으로 바꿔야 한다.

API Reference

SwapLabel Props

Prop

Type

Default

active
필수

0 | 1

지정 안 함

children
필수

[ReactNode, ReactNode]

지정 안 함

className

string

지정 안 함

같은 패밀리

@mildang/design-system/unofficial/Chat 에서 같이 내보내는 컴포넌트다.

예제

상태 라벨 전환

기존 ChatSurface 스토리의 라벨 전환 예제를 그대로 사용한다.

코드

import { useState } from 'react';
import { css, cx } from '@mildang/styled-system/css';
import { SwapLabel } from '@mildang/design-system/unofficial/Chat';
import { ShimmerLabel } from '@mildang/design-system/unofficial/Chat';
import { chatSurface } from '@mildang/styled-system/recipes';

const surface = chatSurface();

const page = css({ display: 'flex', flexDirection: 'column', gap: '24', padding: '16' });

const row = css({ display: 'flex', alignItems: 'center', gap: '12', flexWrap: 'wrap' });

const label = css({ textStyle: 'chat-small-text-M', color: 'neutral.text.low' });

const cell = css({ display: 'flex', flexDirection: 'column', gap: '8' });

const inkSize = css({
  borderRadius: 'full',
  paddingX: '12',
  paddingY: '6',
  gap: '4',
  textStyle: 'chat-caption-M',
});

const SwapDemo = () => {
  const [done, setDone] = useState(false);

  return (
    <div className={page} data-testid="story-subject">
      <div className={cell}>
        <span className={label}>SwapLabel — 두 라벨을 겹쳐 두고 폭까지 애니메이션</span>
        <div className={row}>
          <div className={cx(surface.paper, css({ borderRadius: 'full', paddingX: '12', paddingY: '6' }))}>
            <SwapLabel active={done ? 1 : 0}>
              {[
                <ShimmerLabel key="running" textStyle="chat-caption-R">
                  코드를 고치는 중…
                </ShimmerLabel>,
                <span
                  key="done"
                  className={css({ textStyle: 'chat-caption-R', color: 'positive.text.base' })}
                >
                  3개 파일 수정 완료
                </span>,
              ]}
            </SwapLabel>
          </div>
          <button type="button" className={cx(surface.inkButton, inkSize)} onClick={() => setDone((v) => !v)}>
            상태 전환
          </button>
        </div>
      </div>

      <div className={cell}>
        <span className={label}>ShimmerLabel — TextShimmer 별칭. active=false 면 스윕만 꺼진다</span>
        <div className={row}>
          <ShimmerLabel textStyle="chat-caption-R">생성 중…</ShimmerLabel>
          <ShimmerLabel active={false} textStyle="chat-caption-R">
            생성 완료
          </ShimmerLabel>
        </div>
      </div>
    </div>
  );
};

const ChatSurfaceStateLabelsExample = () => <SwapDemo />;

export default ChatSurfaceStateLabelsExample;