Demos
How to import
import { Banner } from '@fibrous/semi-ui-react';
Basic Usage
Code
import { useState } from 'react';
import { Banner, Layout, Button } from '@fibrous/semi-ui-react';
export default function BannerDemo() {
const [visible, setVisible] = useState(false);
const changeVisible = () => {
setVisible(!visible);
};
const { Header, Footer, Content } = Layout;
const commonStyle = {
height: 64,
lineHeight: '64px',
background: 'var(--semi-color-fill-0)',
};
const banner = <Banner onClose={changeVisible} description="Semi D2C 现已支持 Figma DevMode, 安装插件,随时查阅图层对应的前端代码" />;
return (
<>
<Layout className="components-layout-demo banner-basic">
<Header style={commonStyle}>Header</Header>
{visible && banner}
<Content style={{ height: 300, lineHeight: '300px' }}>Content</Content>
<Footer style={commonStyle}>Footer</Footer>
</Layout>
<Button
onClick={changeVisible}
style={{
display: 'block',
width: '120px',
margin: '0 auto',
}}
>
{visible ? 'Hide Banner' : 'Show Banner'}
</Button>
</>
);
}Types
The type prop supports one of: default(default),danger,warning, success.
Code
import { Banner } from '@fibrous/semi-ui-react';
export default function BannerDemo() {
return (
<>
<Banner type="info" description="Semi D2C 现已支持 Figma DevMode, 安装插件,随时查阅图层对应的前端代码" />
<br />
<Banner type="warning" description="当前使用 Figma UI Kit 为旧版,可能无法支持完整的 Design to code 能力" />
<br />
<Banner type="danger" description="当前使用 API 已过期,请尽快升级" />
<br />
<Banner type="success" description="Semi DSM, Make Semi Design to Any Design" />
</>
);
}Use in Container
You could set fullMode={false} to use style for non-fullscreen mode. Also, use bordered for bordered style. icon={null} and closeIcon={null} hide the icon and the close button.
Code
import { Banner, Typography } from '@fibrous/semi-ui-react';
export default function BannerDemo() {
const { Text } = Typography;
return (
<div style={{ width: 640 }} className="components-banner-demo">
<Banner
fullMode={false}
type="info"
bordered
icon={null}
closeIcon={null}
title={<div style={{ fontWeight: 600, fontSize: '14px', lineHeight: '20px' }}>不知道 AppKey?</div>}
description={
<div>
你可先联系对应的研发同学,确认是否已在 <Text link={{ href: 'https://semi.design/' }}>应用云平台</Text> 申请了应用,并填写对应的信息。
</div>
}
/>
<br />
<Banner
fullMode={false}
type="warning"
bordered
icon={null}
closeIcon={null}
title={<div style={{ fontWeight: 600, fontSize: '14px', lineHeight: '20px' }}>不知道 AppKey?</div>}
description={
<div>
你可先联系对应的研发同学,确认是否已在 <Text link={{ href: 'https://semi.design/' }}>应用云平台</Text> 申请了应用,并填写对应的信息。
</div>
}
/>
<br />
<Banner
fullMode={false}
type="danger"
bordered
icon={null}
closeIcon={null}
title={<div style={{ fontWeight: 600, fontSize: '14px', lineHeight: '20px' }}>不知道 AppKey?</div>}
description={
<div>
你可先联系对应的研发同学,确认是否已在 <Text link={{ href: 'https://semi.design/' }}>应用云平台</Text> 申请了应用,并填写对应的信息。
</div>
}
/>
<br />
<Banner
fullMode={false}
type="success"
bordered
icon={null}
closeIcon={null}
title={<div style={{ fontWeight: 600, fontSize: '14px', lineHeight: '20px' }}>不知道 AppKey?</div>}
description={
<div>
你可先联系对应的研发同学,确认是否已在 <Text link={{ href: 'https://semi.design/' }}>应用云平台</Text> 申请了应用,并填写对应的信息。
</div>
}
/>
</div>
);
}.components-banner-demo {
.semi-banner-info.semi-banner-bordered {
border: 1px solid var(--semi-color-primary-disabled);
}
.semi-banner-warning.semi-banner-bordered {
border: 1px solid var(--semi-color-warning-light-active);
}
.semi-banner-danger.semi-banner-bordered {
border: 1px solid var(--semi-color-danger-light-active);
}
.semi-banner-success.semi-banner-bordered {
border: 1px solid var(--semi-color-success-light-active);
}
}
Customized Content
Use children to create customized content.
Code
import { Banner } from '@fibrous/semi-ui-react';
export default function BannerDemo() {
return (
<div style={{ width: 500, padding: 20, border: '1px solid var(--semi-color-border)' }}>
<Banner fullMode={false} title="Title" type="warning" bordered description="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat">
<div className="semi-modal-footer">
<button className="semi-button semi-button-tertiary semi-button-light" type="button">
No, thanks.
</button>
<button className="semi-button semi-button-warning" type="button">
Sounds great!
</button>
</div>
</Banner>
<br />
</div>
);
}API Reference
Props
| Property | Description | Type | Default |
|---|---|---|---|
| bordered | Whether to show a border. Only takes effect in non-full mode, and no border is shown by default. | boolean | - |
| children | Custom content rendered in the extra area below the banner. | React.ReactNode | - |
| className | Class name of the root element. | string | - |
| closeIcon | Replaces the icon in the close button. Pass null to hide the close button; the default close icon is shown when unset. | React.ReactNode | - |
| description | Description content. | React.ReactNode | - |
| fullMode | Whether the banner is in full mode. Set it to false for the non-full style. | boolean | true |
| icon | Replaces the icon of type. Pass null to hide the icon; the icon of type is shown when unset. | React.ReactNode | - |
| onClose | Called when the close button is clicked, with its native click event. The banner hides after the callback returns. | Type(e: React.MouseEvent) => void | - |
| ref | Reference to the root div element (role="alert"). | TypeReact.Ref<HTMLDivElement> | - |
| style | Style of the root element. | React.CSSProperties | - |
| title | Title content. | React.ReactNode | - |
| type | Type: info, success, danger or warning. | Type | "info" |
Other native attributes (such as aria-*, onClick and id) land on the root div element. The root's role="alert" is fixed and cannot be overridden.
Accessibility
ARIA
- The component has a
roleof 'alert'. - The close button's
aria-labelcomes from the current locale ('Close' in English, '关闭' in Simplified Chinese).
Keyboard and Focus
- The close button of the Banner can be focused with the
Tabkey. After the button is focused, hit theEnterkey or theSpacekey to close the banner.
Content Guidelines
- Full screen Banner
- Try to keep the content displayed completely on one line
- Use correct punctuation, commas within sentences and periods between sentences
- Non-fullscreen Banner
- title
- Instructions in condensed language
- Try to avoid using commas, periods and other punctuation marks in the title, and support the use of question marks at the end when there are and only interrogative sentences
- text
- On the premise of complete information transmission, try to compress the text to 1-2 sentences
- A detailed description or explanation of the title, rather than a repetition of the title
- Use correct punctuation, commas within sentences and periods between sentences
- title
Design Tokens
These are the component's internal Sass variables and cannot be overridden. To customize styles, override the --semi-* CSS variables (see the Design Token page) or write unlayered CSS rules.
| Sass variable | Value | Usage |
|---|---|---|
| $color-banner_info-bg-default | var(--semi-color-info-light-default) | 背景色 - info |
| $color-banner_info-text-default | var(--semi-color-info) | 文本颜色 - info |
| $color-banner_info-border-default | var(--semi-color-info) | 描边颜色 - info |
| $color-banner_warning-bg-default | var(--semi-color-warning-light-default) | 背景色 - 警告 |
| $color-banner_warning-text-default | var(--semi-color-warning) | 文本颜色 - 警告 |
| $color-banner_warning-border-default | var(--semi-color-warning) | 描边颜色 - 警告 |
| $color-banner_success-bg-default | var(--semi-color-success-light-default) | 背景色 - 成功 |
| $color-banner_success-text-default | var(--semi-color-success) | 文本颜色 - 成功 |
| $color-banner_success-border-default | var(--semi-color-success) | 描边颜色 - 成功 |
| $color-banner_danger-bg-default | var(--semi-color-danger-light-default) | 背景色 - 危险 |
| $color-banner_danger-text-default | var(--semi-color-danger) | 文本颜色 - 危险 |
| $color-banner_danger-border-default | var(--semi-color-danger) | 描边颜色 - 危险 |
| $radius-banner | var(--semi-border-radius-small) | 圆角 |
| $spacing-banner_closeBtn-marginLeft | $spacing-base-tight | 关闭按钮左边距 |
| $spacing-banner_extra-marginTop | $spacing-tight | 关闭按钮顶边距 |
| $spacing-banner_icon-marginRight | $spacing-base-tight | 关闭按钮顶边距 |
| $spacing-banner-paddingX | $spacing-base-tight | 整体水平内边距 |
| $spacing-banner-paddingY | $spacing-base-tight | 整体垂直内边距 |
| $spacing-banner_title_description-marginTop | 2px | 标题与描述信息的间距 |
| $height-banner_closeBtn | 24px | 关闭按钮高度 |
| $width-banner_closeBtn | 24px | 关闭按钮宽度 |
| $width-banner-border | 1px | 描边宽度 |