Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notice-bar): shape and bordered prop #6691

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/components/notice-bar/demos/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { NoticeBar, Space } from 'antd-mobile'
import { CloseCircleOutline, CompassOutline } from 'antd-mobile-icons'
import { DemoBlock, lorem } from 'demos'
import { CompassOutline, CloseCircleOutline } from 'antd-mobile-icons'
import React from 'react'

const demoLongText = lorem.generateWords(20)

Expand All @@ -11,6 +11,7 @@ export default () => {
<DemoBlock title='通告栏语义' padding='0' background='transparent'>
<Space block direction='vertical'>
<NoticeBar content='默认' color='default' />
<NoticeBar content='成功' color='success' />
<NoticeBar content='警告' color='alert' />
<NoticeBar content='错误' color='error' />
<NoticeBar content='信息' color='info' />
Expand Down Expand Up @@ -50,6 +51,22 @@ export default () => {
content={'自定义右侧功能区'}
color='alert'
/>
<div style={{ paddingInline: 12 }}>
<NoticeBar
color='info'
shape='neutral'
bordered
content={'圆角+全边框'}
/>
</div>
<div style={{ paddingInline: 12 }}>
<NoticeBar
color='success'
shape='rounded'
bordered={false}
content={'圆形+无边框'}
/>
</div>
</Space>
</DemoBlock>
</>
Expand Down
14 changes: 9 additions & 5 deletions src/components/notice-bar/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ It is applicable to the notification of information in the current page, which i

### Props

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| Name | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| closeable | Whether it can be closed | `boolean` | `false` |
| closeIcon | Custom close button icon | `ReactNode` | `<CloseOutline />` |
| color | The type of the NoticeBar | `'default' \| 'alert' \| 'error' \| 'info'` | `'default'` |
| color | The type of the NoticeBar | `'default' \| 'alert' \| 'error' \| 'info' \| 'success'` | `'default'` |
| content | The content of the NoticeBar | `React.ReactNode` | - |
| delay | Delay to start scrolling, unit `ms` | `number` | `2000` |
| extra | Additional operating area, displayed to the left of the close button | `React.ReactNode` | - |
Expand All @@ -27,14 +27,18 @@ It is applicable to the notification of information in the current page, which i
| onClick | Click event | `() => void` | - |
| speed | Scroll speed, unit `px/s` | `number` | `50` |
| wrap | Whether to display multiple lines | `boolean` | `false` |
| shape | Shape of the NoticeBar (rectangular: sharp; neutral: round corner; rounded: circle/pill shape) | `'rectangular' \| 'neutral' \| 'rounded'` | `'rectangular'` | 5.38.0 |
| bordered | Border visibility of the NoticeBar (`block`: top and bottom border; `true`: full border; `false`: no border) | `'block' \| boolean` | `'block'` | 5.38.0 |

### CSS Variables

| Name | Description | Default |
| --- | --- | --- |
| Name | Description | Default | Global | Version |
| --- | --- | --- | --- | --- |
| --background-color | background color | `var(--adm-color-weak)` |
| --border-color | border color | `var(--adm-color-weak)` |
| --font-size | Font size of notice text content. | `15px` |
| --height | Height of the whole element. | `40px` |
| --icon-font-size | Font size of left icon. | `18px` |
| --text-color | text color | `#ffffff` |
| `--adm-notice-bar-border-radius` | Border radius of neutral shape NoticeBar | `4px` | `--adm-notice-bar-border-radius` | 5.38.0 |
| `--adm-notice-bar-border-width` | Border width of bordered NoticeBar | `1px` | `--adm-notice-bar-border-width` | 5.38.0 |
26 changes: 15 additions & 11 deletions src/components/notice-bar/index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

### 属性

| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| 属性 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| closeable | 是否可关闭 | `boolean` | `false` |
| closeIcon | 自定义关闭按钮图标 | `ReactNode` | `<CloseOutline />` |
| color | 通告栏的类型 | `'default' \| 'alert' \| 'error' \| 'info'` | `'default'` |
| color | 通告栏的类型 | `'default' \| 'alert' \| 'error' \| 'info' \| 'success'` | `'default'` |
| content | 公告内容 | `React.ReactNode` | - |
| delay | 开始滚动的延迟,单位 `ms` | `number` | `2000` |
| extra | 额外操作区域,显示在关闭按钮左侧 | `React.ReactNode` | - |
Expand All @@ -27,14 +27,18 @@
| onClick | 点击事件 | `() => void` | - |
| speed | 滚动速度,单位 `px/s` | `number` | `50` |
| wrap | 是否多行展示 | `boolean` | `false` |
| shape | 形状 (rectangular: 直角; neutral: 圆角; rounded: 圆形) | `'rectangular' \| 'neutral' \| 'rounded'` | `'rectangular'` | 5.38.0 |
| bordered | 边框可见性 (`block`: 上下边框; `true`: 全边框; `false`: 无边框) | `'block' \| boolean` | `'block'` | 5.38.0 |

### CSS 变量

| 属性 | 说明 | 默认值 |
| ------------------ | -------------- | ----------------------- |
| --background-color | 背景色 | `var(--adm-color-weak)` |
| --border-color | 边框颜色 | `var(--adm-color-weak)` |
| --font-size | 文字字号 | `15px` |
| --height | 整体高度 | `40px` |
| --icon-font-size | 左侧图标的字号 | `18px` |
| --text-color | 文字颜色 | `#ffffff` |
| 属性 | 说明 | 默认值 | 全局变量 | 版本 |
| --- | --- | --- | --- | --- |
| `--background-color` | 背景色 | `var(--adm-color-weak)` |
| `--border-color` | 边框颜色 | `var(--adm-color-weak)` |
| `--font-size` | 文字字号 | `15px` |
| `--height` | 整体高度 | `40px` |
| `--icon-font-size` | 左侧图标的字号 | `18px` |
| `--text-color` | 文字颜色 | `#ffffff` |
| `--adm-notice-bar-border-radius` | 圆角形状(neutral)的圆角大小 | `4px` | `--adm-notice-bar-border-radius` | 5.38.0 |
| `--adm-notice-bar-border-width` | 边框粗细 | `1px` | `--adm-notice-bar-border-width` | 5.38.0 |
33 changes: 29 additions & 4 deletions src/components/notice-bar/notice-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
--font-size: var(--adm-font-size-7);
--icon-font-size: var(--adm-font-size-10);
--height: 40px;
--adm-notice-bar-border-radius: 4px;
--adm-notice-bar-border-width: 1px;

height: var(--height);
box-sizing: border-box;
Expand All @@ -16,9 +18,9 @@
align-items: center;
justify-content: space-between;

border: solid 1px var(--border-color);
border-left: none;
border-right: none;
border: solid var(--adm-notice-bar-border-width) var(--border-color);
border-left-width: 0;
border-right-width: 0;
background-color: var(--background-color);
color: var(--text-color);
& > span[role='img'] {
Expand All @@ -33,13 +35,18 @@
&.@{class-prefix-notice-bar}-error {
--background-color: var(--adm-color-danger);
--border-color: #d9281e;
--text-color: #ffffff;
--text-color: #fff;
}
&.@{class-prefix-notice-bar}-info {
--background-color: #d0e4ff;
--border-color: #bcd8ff;
--text-color: var(--adm-color-primary);
}
&.@{class-prefix-notice-bar}-success {
--background-color: #d1fff0;
--border-color: #a8f0d8;
--text-color: var(--adm-color-success);
}

& .@{class-prefix-notice-bar}-left {
flex-shrink: 0;
Expand Down Expand Up @@ -89,4 +96,22 @@
padding-bottom: 8px;
line-height: 22px;
}

&-neutral {
border-radius: var(--adm-notice-bar-border-radius);
}

&-rounded {
border-radius: 1000px;
}

&-bordered {
border-left-width: var(--adm-notice-bar-border-width);
border-right-width: var(--adm-notice-bar-border-width);
}

&-without-border {
border-top-width: 0;
border-bottom-width: 0;
}
}
11 changes: 10 additions & 1 deletion src/components/notice-bar/notice-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const classPrefix = `adm-notice-bar`

export type NoticeBarProps = {
/** The type of the NoticeBar */
color?: 'default' | 'alert' | 'error' | 'info'
color?: 'default' | 'alert' | 'error' | 'success' | 'info'
/** TDelay to start scrolling, unit ms */
delay?: number
/** Scroll speed, unit px/s */
Expand All @@ -34,6 +34,10 @@ export type NoticeBarProps = {
icon?: ReactNode
/** Whether to display multiple lines */
wrap?: boolean
/** Block shape */
shape?: 'rectangular' | 'neutral' | 'rounded'
/** Border visibility */
bordered?: 'block' | boolean
} & NativeProps<
| '--background-color'
| '--border-color'
Expand All @@ -49,6 +53,8 @@ const defaultProps = {
speed: 50,
icon: <SoundOutline />,
wrap: false,
shape: 'rectangular',
bordered: 'block' as 'block' | boolean,
}

export const NoticeBar = memo<NoticeBarProps>(props => {
Expand Down Expand Up @@ -130,8 +136,11 @@ export const NoticeBar = memo<NoticeBarProps>(props => {
className={classNames(
classPrefix,
`${classPrefix}-${mergedProps.color}`,
`${classPrefix}-${mergedProps.shape}`,
{
[`${classPrefix}-wrap`]: mergedProps.wrap,
[`${classPrefix}-bordered`]: mergedProps.bordered === true,
[`${classPrefix}-without-border`]: mergedProps.bordered === false,
}
)}
onClick={mergedProps.onClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`NoticeBar long content 1`] = `
<div>
<div
class="adm-notice-bar adm-notice-bar-default"
class="adm-notice-bar adm-notice-bar-default adm-notice-bar-rectangular"
>
<span
class="adm-notice-bar-left"
Expand Down
Loading