결과 화면

결과 화면 (Result)

일련의 작업 처리 결과를 사용자에게 피드백해 주는 컴포넌트입니다. 성공·실패·경고 같은 상태를 한눈에 보여주고 싶을 때 사용해요.

출처: 문서

본문

언제 사용하나요 (When To Use)

중요한 작업의 결과를 사용자에게 알려줘야 하고, 그 피드백이 비교적 복잡할 때 사용합니다.

예제 (Examples)

성공 (Success)

성공한 결과를 보여줍니다.

import React from 'react';
import { Button, Result } from 'antd';

const App: React.FC = () => (
  <Result
    status="success"
    title="Successfully Purchased Cloud Server ECS!"
    subTitle="Order number: 2017182818828182881 Cloud server configuration takes 1-5 minutes, please wait."
    extra={[
      <Button type="primary" key="console">
        Go Console
      </Button>,
      <Button key="buy">Buy Again</Button>,
    ]}
  />
);

export default App;

정보 (Info)

처리 결과를 보여줍니다.

import React from 'react';
import { Button, Result } from 'antd';

const App: React.FC = () => (
  <Result
    title="Your operation has been executed"
    extra={
      <Button type="primary" key="console">
        Go Console
      </Button>
    }
  />
);

export default App;

경고 (Warning)

경고의 결과를 나타냅니다.

import React from 'react';
import { Button, Result } from 'antd';

const App: React.FC = () => (
  <Result
    status="warning"
    title="There are some problems with your operation."
    extra={
      <Button type="primary" key="console">
        Go Console
      </Button>
    }
  />
);

export default App;

403

이 페이지에 접근할 권한이 없음을 알려줍니다.

import React from 'react';
import { Button, Result } from 'antd';

const App: React.FC = () => (
  <Result
    status="403"
    title="403"
    subTitle="Sorry, you are not authorized to access this page."
    extra={<Button type="primary">Back Home</Button>}
  />
);

export default App;

404

방문한 페이지가 존재하지 않을 때 보여줍니다.

import React from 'react';
import { Button, Result } from 'antd';

const App: React.FC = () => (
  <Result
    status="404"
    title="404"
    subTitle="Sorry, the page you visited does not exist."
    extra={<Button type="primary">Back Home</Button>}
  />
);

export default App;

500

서버에서 문제가 발생했을 때 보여줍니다.

import React from 'react';
import { Button, Result } from 'antd';

const App: React.FC = () => (
  <Result
    status="500"
    title="500"
    subTitle="Sorry, something went wrong."
    extra={<Button type="primary">Back Home</Button>}
  />
);

export default App;

오류 (Error)

복잡한 오류 상황의 피드백을 보여줍니다.

import React from 'react';
import { CloseCircleOutlined } from '@ant-design/icons';
import { Button, Result, Typography } from 'antd';
import { createStyles } from 'antd-style';

const useStyles = createStyles((props) => {
  const { css, cssVar } = props;
  return {
    errorIcon: css`
      color: ${cssVar.colorError};
      margin-inline-end: ${cssVar.marginXS};
    `,
  };
});

const { Paragraph, Text } = Typography;

const App: React.FC = () => {
  const { styles } = useStyles();
  return (
    <Result
      status="error"
      title="Submission Failed"
      subTitle="Please check and modify the following information before resubmitting."
      extra={[
        <Button type="primary" key="console">
          Go Console
        </Button>,
        <Button key="buy">Buy Again</Button>,
      ]}
    >
      <div className="desc">
        <Paragraph>
          <Text strong style={{ fontSize: 16 }}>
            The content you submitted has the following error:
          </Text>
        </Paragraph>
        <Paragraph>
          <CloseCircleOutlined className={styles.errorIcon} />
          Your account has been frozen. <a>Thaw immediately &gt;</a>
        </Paragraph>
        <Paragraph>
          <CloseCircleOutlined className={styles.errorIcon} />
          Your account is not yet eligible to apply. <a>Apply Unlock &gt;</a>
        </Paragraph>
      </div>
    </Result>
  );
};

export default App;

커스텀 아이콘 (Custom icon)

커스텀 아이콘을 사용합니다.

import React from 'react';
import { SmileOutlined } from '@ant-design/icons';
import { Button, Result } from 'antd';

const App: React.FC = () => (
  <Result
    icon={<SmileOutlined />}
    title="Great, we have done all the operations!"
    extra={<Button type="primary">Next</Button>}
  />
);

export default App;

커스텀 시맨틱 DOM 스타일링 (Custom semantic dom styling)

classNames와 styles에 객체 또는 함수를 넘겨서 Result의 시맨틱 DOM 스타일을 커스터마이즈할 수 있습니다.

import React from 'react';
import { Button, Result } from 'antd';
import type { GetProp, ResultProps } from 'antd';

const classNamesObject: ResultProps['classNames'] = {
  root: 'demo-result-root',
  title: 'demo-result-title',
  subTitle: 'demo-result-subtitle',
  icon: 'demo-result-icon',
  extra: 'demo-result-extra',
  body: 'demo-result-body',
};

const classNamesFn: ResultProps['classNames'] = (
  info,
): GetProp<ResultProps, 'classNames', 'Return'> => {
  if (info.props.status === 'success') {
    return {
      root: 'demo-result-root--success',
    };
  }
  return {
    root: 'demo-result-root--default',
  };
};

const stylesObject: ResultProps['styles'] = {
  root: { borderWidth: 2, borderStyle: 'dashed', padding: 16 },
  title: { fontStyle: 'italic', color: '#1890ff' },
  subTitle: { fontWeight: 'bold' },
  icon: { opacity: 0.8 },
  extra: { backgroundColor: '#f0f0f0', padding: 8 },
  body: { backgroundColor: '#fafafa', padding: 12 },
};

const stylesFn: ResultProps['styles'] = (info): GetProp<ResultProps, 'styles', 'Return'> => {
  if (info.props.status === 'error') {
    return {
      root: { backgroundColor: '#fff2f0', borderColor: '#ff4d4f' },
      title: { color: '#ff4d4f' },
    };
  } else {
    return {
      root: { backgroundColor: '#f6ffed', borderColor: '#52c41a' },
      title: { color: '#52c41a' },
    };
  }
};

const App: React.FC = () => {
  return (
    <>
      <Result
        status="info"
        title="classNames Object"
        subTitle="This is a subtitle"
        styles={stylesObject}
        classNames={classNamesObject}
        extra={<Button type="primary">Action</Button>}
      >
        <div>Content area</div>
      </Result>
      <Result
        status="success"
        title="classNames Function"
        subTitle="Dynamic class names"
        styles={stylesFn}
        classNames={classNamesFn}
        extra={<Button>Action</Button>}
      />
    </>
  );
};

export default App;

API

Common props ref:Common props

Property Description Type Default Version Global Config
classNames Customize class for each semantic structure inside the component. Supports object or function Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> - 6.0.0 6.0.0
extra Operating area ReactNode - ×
icon Custom back icon ReactNode - ×
status Result status, decide icons and colors success | error | info | warning | 404 | 403 | 500 info ×
styles Customize inline style for each semantic structure inside the component. Supports object or function Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> - 6.0.0 6.0.0
subTitle The subTitle ReactNode - ×
title The title ReactNode - ×

시맨틱 DOM (Semantic DOM)

https://ant.design/components/result/semantic.md

디자인 토큰 (Design Token)

컴포넌트 토큰 (Component Token - Result)

Token Name Description Type Default Value
extraMargin Margin of extra area Margin<string | number> | undefined 24px 0 0 0
iconFontSize Icon size string | number 72
subtitleFontSize Subtitle font size number 14
titleFontSize Title font size string | number 24

글로벌 토큰 (Global Token)

Token Name Description Type Default Value
colorError Used to represent the visual elements of the operation failure, such as the error Button, error Result component, etc. string
colorFillAlter Control the alternative background color of element. string
colorInfo Used to represent the operation information of the Token sequence, such as Alert, Tag, Progress, and other components use these map tokens. string
colorSuccess Used to represent the token sequence of operation success, such as Result, Progress and other components will use these map tokens. string
colorTextDescription Control the font color of text description. string
colorTextHeading Control the font color of heading. string
colorWarning Used to represent the warning map token, such as Notification, Alert, etc. Alert or Control component(like Input) will use these map tokens. string
lineHeight Line height of text. number
lineHeightHeading3 Line height of h3 tag. number
marginXS Control the margin of an element, with a small size. number
padding Control the padding of the element. number
paddingLG Control the large padding of the element. number
paddingXL Control the extra large padding of the element. number
paddingXS Control the extra small padding of the element. number

더 알아보기 (Learn more)