Feedback · Banner

Banner

The Banner component is usually used to identify the status or notification of the full page. It is usually resident and requires the user to close it initiatively.

Demos

How to import

<script lang="ts">
    import { Banner } from '@fibrae/semi-ui-svelte';
</script>

Basic Usage

Code
<script lang="ts">
    import { Banner, Button, Layout, LayoutContent, LayoutFooter, LayoutHeader } from '@fibrae/semi-ui-svelte';

    let visible = $state(false);
    const toggle = () => {
        visible = !visible;
    };

    const commonStyle = 'height: 64px; line-height: 64px; background: var(--semi-color-fill-0)';
</script>

<Layout class="components-layout-demo banner-basic">
    <LayoutHeader style={commonStyle}>Header</LayoutHeader>
    {#if visible}
        <Banner onClose={toggle}>
            {#snippet description()}Semi D2C 现已支持 Figma DevMode, 安装插件,随时查阅图层对应的前端代码{/snippet}
        </Banner>
    {/if}
    <LayoutContent style="height: 300px; line-height: 300px">Content</LayoutContent>
    <LayoutFooter style={commonStyle}>Footer</LayoutFooter>
</Layout>
<Button style="display: block; width: 120px; margin: 0 auto" onclick={toggle}>
    {visible ? 'Hide Banner' : 'Show Banner'}
</Button>

Types

The type prop supports one of: default(default),danger,warning, success.

Semi D2C 现已支持 Figma DevMode, 安装插件,随时查阅图层对应的前端代码

当前使用 Figma UI Kit 为旧版,可能无法支持完整的 Design to code 能力

当前使用 API 已过期,请尽快升级

Semi DSM, Make Semi Design to Any Design
Code
<script lang="ts">
    import { Banner } from '@fibrae/semi-ui-svelte';
</script>

<Banner type="info">
    {#snippet description()}Semi D2C 现已支持 Figma DevMode, 安装插件,随时查阅图层对应的前端代码{/snippet}
</Banner>
<br />
<Banner type="warning">
    {#snippet description()}当前使用 Figma UI Kit 为旧版,可能无法支持完整的 Design to code 能力{/snippet}
</Banner>
<br />
<Banner type="danger">
    {#snippet description()}当前使用 API 已过期,请尽快升级{/snippet}
</Banner>
<br />
<Banner type="success">
    {#snippet description()}Semi DSM, Make Semi Design to Any Design{/snippet}
</Banner>

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.

不知道 AppKey?
你可先联系对应的研发同学,确认是否已在 应用云平台 申请了应用,并填写对应的信息。

不知道 AppKey?
你可先联系对应的研发同学,确认是否已在 应用云平台 申请了应用,并填写对应的信息。

不知道 AppKey?
你可先联系对应的研发同学,确认是否已在 应用云平台 申请了应用,并填写对应的信息。

不知道 AppKey?
你可先联系对应的研发同学,确认是否已在 应用云平台 申请了应用,并填写对应的信息。
Code
<script lang="ts">
    import { Banner, TypographyText } from '@fibrae/semi-ui-svelte';

    const types = ['info', 'warning', 'danger', 'success'] as const;
</script>

<div class="components-banner-demo" style="width: 640px">
    {#each types as type, index (type)}
        {#if index > 0}
            <br />
        {/if}
        <Banner bordered closeIcon={null} fullMode={false} icon={null} {type}>
            {#snippet title()}
                <div style="font-weight: 600; font-size: 14px; line-height: 20px">不知道 AppKey?</div>
            {/snippet}
            {#snippet description()}
                <div>
                    你可先联系对应的研发同学,确认是否已在
                    <TypographyText link={{ href: 'https://semi.design/' }}>应用云平台</TypographyText>
                    申请了应用,并填写对应的信息。
                </div>
            {/snippet}
        </Banner>
    {/each}
</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

Write the content directly inside the Banner tag (the children snippet) to create customized content.

Title
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

Code
<script lang="ts">
    import { Banner } from '@fibrae/semi-ui-svelte';
</script>

<div style="width: 500px; padding: 20px; border: 1px solid var(--semi-color-border)">
    <Banner bordered fullMode={false} title="Title" type="warning">
        {#snippet 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
        {/snippet}
        <div class="semi-modal-footer">
            <button class="semi-button semi-button-tertiary semi-button-light" type="button">No, thanks.</button>
            <button class="semi-button semi-button-warning" type="button">Sounds great!</button>
        </div>
    </Banner>
    <br />
</div>

API Reference

Props

PropertyDescriptionTypeDefault
borderedWhether to show a border. Only takes effect in non-full mode.booleanfalse
childrenCustom content below the message.Snippet-
closeIconSnippet that replaces the icon in the close button. Pass null to remove the button.Snippet | null-
descriptionSnippet for the description content.Snippet-
fullModeWhether the banner is in full mode.booleantrue
iconSnippet that replaces the icon of the type. Pass null to hide the icon.Snippet | null-
onCloseCalled when the close button is clicked, with its native click event. The banner hides once the callback returns.Type(event: MouseEvent) => void-
titleTitle, a string or a snippet.string | Snippet-
typeType: info, success, danger or warning.BannerType"info"

class, style (a string) and native attributes and events (such as aria-* and onclick) land on the root element. title can be a string or a snippet, and description, icon and closeIcon are snippets. The closed state lives inside the component and there is no bind:; unmount with {#if} and mount again to show it again.

Accessibility

ARIA

  • The root has no role by default, so a note that stays on the page is not announced as an alert. For a message that appears dynamically and must be announced at once, such as a failed operation, pass role="alert".
  • The close button's aria-label comes from the current locale ('Close' in English, '关闭' in Simplified Chinese).

Keyboard and Focus

  • The close button of the Banner can be focused with the Tab key. After the button is focused, hit the Enter key or the Space key 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

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 variableValueUsage
$color-banner_info-bg-defaultvar(--semi-color-info-light-default)背景色 - info
$color-banner_info-text-defaultvar(--semi-color-info)文本颜色 - info
$color-banner_info-border-defaultvar(--semi-color-info)描边颜色 - info
$color-banner_warning-bg-defaultvar(--semi-color-warning-light-default)背景色 - 警告
$color-banner_warning-text-defaultvar(--semi-color-warning)文本颜色 - 警告
$color-banner_warning-border-defaultvar(--semi-color-warning)描边颜色 - 警告
$color-banner_success-bg-defaultvar(--semi-color-success-light-default)背景色 - 成功
$color-banner_success-text-defaultvar(--semi-color-success)文本颜色 - 成功
$color-banner_success-border-defaultvar(--semi-color-success)描边颜色 - 成功
$color-banner_danger-bg-defaultvar(--semi-color-danger-light-default)背景色 - 危险
$color-banner_danger-text-defaultvar(--semi-color-danger)文本颜色 - 危险
$color-banner_danger-border-defaultvar(--semi-color-danger)描边颜色 - 危险
$radius-bannervar(--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-marginTop2px标题与描述信息的间距
$height-banner_closeBtn24px关闭按钮高度
$width-banner_closeBtn24px关闭按钮宽度
$width-banner-border1px描边宽度