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(comp:alert): support centered #2015

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions packages/components/alert/__tests__/alert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ describe('Alert', () => {
expect(wrapper.find('.ix-alert').classes()).toContain('ix-alert-banner')
})

test('props centered work', async () => {
const wrapper = AlertMount({ props: { centered: true } })

expect(wrapper.find('.ix-alert').classes()).toContain('ix-alert-centered')
})

test('props icon work', async () => {
const wrapper = AlertMount({ props: { icon: 'bug' } })

Expand Down
9 changes: 9 additions & 0 deletions packages/components/alert/demo/Centered.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
order: 3
title:
zh: 居中提示
---

## zh

提示信息居中展示。
3 changes: 3 additions & 0 deletions packages/components/alert/demo/Centered.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<IxAlert centered type="error"> 我长话短说,但是说来话长。</IxAlert>
</template>
1 change: 1 addition & 0 deletions packages/components/alert/docs/Api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| 名称 | 说明 | 类型 | 默认值 | 全局配置 | 备注 |
| --- | --- | --- | --- | --- | --- |
| `banner` | 是否用作顶部提示 | `boolean` | `false` | - |- |
| `centered` | 信息提示是否居中 | `boolean` | `false` | ✅ |- |
| `closable` | 信息提示是否可关闭 | `boolean` | `false` | ✅ |- |
| `closeIcon` | 自定义关闭按钮 | `string \| #closeIcon` | `close` | - | - |
| `description` | 辅助性文字介绍 | `string \| #description` | - | - |- |
Expand Down
1 change: 1 addition & 0 deletions packages/components/alert/src/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

watch(pageIndex, index => {
const { pagination } = props
isObject(pagination) && callEmit(pagination.onChange, index)

Check warning on line 63 in packages/components/alert/src/Alert.tsx

View check run for this annotation

codefactor.io / CodeFactor

packages/components/alert/src/Alert.tsx#L63

Expected an assignment or function call and instead saw an expression. (@typescript-eslint/no-unused-expressions)
})

const classes = computed(() => {
Expand All @@ -71,6 +71,7 @@
[prefixCls]: true,
[`${prefixCls}-${props.type}`]: true,
[`${prefixCls}-banner`]: props.banner,
[`${prefixCls}-centered`]: props.centered || config.centered,
[`${prefixCls}-with-description`]: slots.description || props.description,
})
})
Expand Down
1 change: 1 addition & 0 deletions packages/components/alert/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { DefineComponent, HTMLAttributes, PropType } from 'vue'

export const alertProps = {
banner: { type: Boolean, default: false },
centered: { type: Boolean, default: undefined },
closable: { type: Boolean, default: undefined },
closeIcon: { type: String, default: 'close' },
description: String,
Expand Down
9 changes: 8 additions & 1 deletion packages/components/alert/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
border-bottom-color: var(--ix-color-border-secondary);
}

&-centered {
justify-content: center;
}

&-icon {
margin-right: var(--ix-margin-size-xs);
}
Expand All @@ -46,10 +50,13 @@
}

&-content {
flex: 1;
min-width: 0;
}

&:not(&-centered) &-content {
flex: 1;
}

&-description {
.reset-font-size();
}
Expand Down
1 change: 1 addition & 0 deletions packages/components/config/src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const defaultConfig: GlobalConfig = {
},

alert: {
centered: false,
closable: false,
icon: {
success: 'check-circle',
Expand Down
1 change: 1 addition & 0 deletions packages/components/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export interface ThemeConfig extends DeepPartialThemeTokens {
}

export interface AlertConfig {
centered: boolean
closable: boolean
icon: string | Partial<Record<AlertType, string>>
}
Expand Down