Skip to content

Commit 38f17e3

Browse files
authored
refactor(alert): 优化Alert组件的目录结构 (#290)
1 parent 2556783 commit 38f17e3

File tree

7 files changed

+67
-55
lines changed

7 files changed

+67
-55
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import type { App } from 'vue';
22
import Alert from './src/alert';
33

4-
Alert.install = function (app: App) {
5-
app.component(Alert.name, Alert);
6-
};
4+
export * from './src/alert-types';
75

86
export { Alert };
97

@@ -12,6 +10,6 @@ export default {
1210
category: '反馈',
1311
status: '100%',
1412
install(app: App): void {
15-
app.use(Alert as any);
13+
app.component(Alert.name, Alert);
1614
},
1715
};

packages/devui-vue/devui/alert/src/alert-close-icon.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ExtractPropTypes } from 'vue';
2+
3+
export type AlertType = 'success' | 'danger' | 'warning' | 'info' | 'simple';
4+
5+
export const alertProps = {
6+
type: {
7+
type: String as () => AlertType,
8+
default: 'info',
9+
},
10+
cssClass: {
11+
type: String,
12+
default: '',
13+
},
14+
closeable: {
15+
type: Boolean,
16+
default: true,
17+
},
18+
showIcon: {
19+
type: Boolean,
20+
default: true,
21+
},
22+
dismissTime: {
23+
type: Number,
24+
default: 0,
25+
},
26+
} as const;
27+
28+
export type AlertProps = ExtractPropTypes<typeof alertProps>;

packages/devui-vue/devui/alert/src/alert.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
@import '../../style/mixins/index';
2-
@import '../../style/theme/color';
3-
@import '../../style/theme/shadow';
4-
@import '../../style/theme/corner';
5-
@import '../../style/theme/font';
1+
@import '../../styles-var/devui-var.scss';
62

73
.devui-alert {
84
color: $devui-text;

packages/devui-vue/devui/alert/src/alert.tsx

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,14 @@
11
import { defineComponent, ref, Transition, onMounted } from 'vue';
22

3-
import AlertCloseIcon from './alert-close-icon';
4-
import AlertTypeIcon from './alert-type-icon';
3+
import AlertCloseIcon from './components/alert-close-icon';
4+
import AlertTypeIcon from './components/alert-type-icon';
55

6+
import { alertProps } from './alert-types';
67
import './alert.scss';
78

8-
export type AlertType = 'success' | 'danger' | 'warning' | 'info' | 'simple';
9-
109
export default defineComponent({
1110
name: 'DAlert',
12-
props: {
13-
type: {
14-
type: String as () => AlertType,
15-
default: 'info',
16-
},
17-
cssClass: {
18-
type: String,
19-
default: '',
20-
},
21-
closeable: {
22-
type: Boolean,
23-
default: true,
24-
},
25-
showIcon: {
26-
type: Boolean,
27-
default: true,
28-
},
29-
dismissTime: {
30-
type: Number,
31-
default: 0,
32-
},
33-
},
11+
props: alertProps,
3412
emits: ['close'],
3513
setup(props, ctx) {
3614
const hide = ref(false);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const AlertCloseIcon = (): unknown => (
2+
<svg width='10px' height='10px' viewBox='0 0 10 10' version='1.1' xmlns='http://www.w3.org/2000/svg'>
3+
<g stroke='none' stroke-width='1' fill='none' fill-rule='evenodd'>
4+
<g transform='translate(-3.000000, -3.000000)' fill-rule='nonzero'>
5+
<path d='M11.6426,3.19816936 C11.9239974,2.91574512 12.4131626,2.93784891 \
6+
12.7352108,3.24751057 C13.0571998,3.5572302 13.0901298,4.03723416 \
7+
12.8087324,4.31965839 L9.14064666,7.99900183 L12.8087324,11.6803416 \
8+
C13.0645482,11.9370909 13.0605893,12.3571292 12.8158402,12.6640749 \
9+
L12.7352108,12.7524894 C12.4131626,13.0621511 11.9239974,13.0842548 \
10+
11.6426,12.8018306 L8,9.14489021 L4.35740003,12.8018306 C4.10158422,13.05858 \
11+
3.6740594,13.0636532 3.35648225,12.8298003 L3.26478919,12.7524894 \
12+
C2.94280021,12.4427698 2.90987023,11.9627658 3.19126762,11.6803416 \
13+
L6.8583349,7.99900183 L3.19126762,4.31965839 C2.93545181,4.06290908 \
14+
2.93941068,3.64287076 3.18415975,3.3359251 L3.26478919,3.24751057 \
15+
C3.58683735,2.93784891 4.07600264,2.91574512 4.35740003,3.19816936 \
16+
L8,6.85411161 L11.6426,3.19816936 Z'></path>
17+
</g>
18+
</g>
19+
</svg>
20+
);
21+
export default AlertCloseIcon;

packages/devui-vue/devui/alert/src/alert-type-icon.tsx renamed to packages/devui-vue/devui/alert/src/components/alert-type-icon.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { AlertType } from './alert';
1+
import type { AlertType } from '../alert-types';
22

3-
const AlertTypeIcon = (props: { type: AlertType }) => (
3+
const AlertTypeIcon = (props: { type: AlertType }): unknown => (
44
<svg
55
width="16px"
66
height="16px"
@@ -32,13 +32,20 @@ const AlertTypeIcon = (props: { type: AlertType }) => (
3232
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
3333
<path
3434
class="devui-icon-warning-outer"
35-
d="M8.96244623,0.57254229 L15.8714442,13.4101975 C16.1549662,13.9370117 15.9538562,14.5918482 15.4222523,14.8728158 C15.2642579,14.9563203 15.0879506,15 14.9088903,15 L1.09089441,15 C0.488410063,15 0,14.5159904 0,13.9189343 C0,13.7414873 0.0440768395,13.5667684 0.128340519,13.4101975 L7.03733844,0.57254229 C7.32086049,0.0457280838 7.98165058,-0.153569987 8.51325441,0.127397589 C8.70423071,0.228333932 8.8605922,0.383286648 8.96244623,0.57254229 Z"
35+
d="M8.96244623,0.57254229 L15.8714442,13.4101975 C16.1549662,13.9370117 \
36+
15.9538562,14.5918482 15.4222523,14.8728158 C15.2642579,14.9563203 15.0879506,15 \
37+
14.9088903,15 L1.09089441,15 C0.488410063,15 0,14.5159904 0,13.9189343 C0,13.7414873 \
38+
0.0440768395,13.5667684 0.128340519,13.4101975 L7.03733844,0.57254229 \
39+
C7.32086049,0.0457280838 7.98165058,-0.153569987 8.51325441,0.127397589 \
40+
C8.70423071,0.228333932 8.8605922,0.383286648 8.96244623,0.57254229 Z"
3641
></path>
3742
<path
3843
class="devui-icon-warning-inner"
3944
stroke-width="0.3"
4045
fill-rule="nonzero"
41-
d="M8.87894737,13 L7.08947368,13 L7.08947368,11.2105263 L8.87894737,11.2105263 L8.87894737,13 Z M8.62102372,9.86842105 L7.32800539,9.86842105 L7,4.5 L8.96842105,4.5 L8.62102372,9.86842105 Z"
46+
d="M8.87894737,13 L7.08947368,13 L7.08947368,11.2105263 L8.87894737,11.2105263 \
47+
L8.87894737,13 Z M8.62102372,9.86842105 L7.32800539,9.86842105 L7,4.5 \
48+
L8.96842105,4.5 L8.62102372,9.86842105 Z"
4249
></path>
4350
</g>
4451
);

0 commit comments

Comments
 (0)