Skip to content

Commit ff2a167

Browse files
云水云水
authored andcommitted
fix: n-icon type define
1 parent fe70852 commit ff2a167

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

packages/n-alert/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ const NAlert = defineComponent({
4747
const closeAlert = () => {
4848
emit('update:show', false);
4949
};
50+
5051
const renderCloseContent = () => {
5152
return (props.closeText
5253
? <span class="close-text" onClick={closeAlert}>{props.closeText}</span>
5354
: <NIcon
5455
id="alertCloseIcon"
5556
name="icon-times"
5657
class={iconClass()}
57-
onClick={closeAlert}
58+
click={closeAlert}
5859
/>);
5960
};
6061
return () => (

packages/n-icon/index.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import { defineComponent, App, HTMLAttributes, SetupContext } from 'vue';
1+
import { defineComponent, App, PropType } from 'vue';
22

3-
export interface IconProps extends HTMLAttributes {
4-
name?: string;
5-
}
3+
const IconProps = {
4+
id: {
5+
type: String as PropType<string>,
6+
default: ''
7+
},
8+
name: {
9+
type: String as PropType<string>,
10+
default: ''
11+
},
12+
click: {
13+
type: Function as PropType<() => void>,
14+
default: () => {}
15+
}
16+
};
617

718
const NIcon = defineComponent({
819
name: 'NIcon',
9-
setup (_:IconProps, { attrs }: SetupContext) {
10-
const props = attrs as IconProps;
11-
const { name } = props;
20+
props: IconProps,
21+
setup (props) {
22+
const { name,click } = props;
1223
return () => (
13-
<i class={'iconfont ' + name}/>
24+
<i class={'iconfont ' + name} onClick={click}/>
1425
);
1526
}
1627
});

packages/n-message/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Message = defineComponent({
5959
id="messageCloseIcon"
6060
name="icon-times"
6161
class={secondIconClassList}
62-
onClick={closeMessage} />}
62+
click={() => closeMessage()} />}
6363
</div>
6464
</div>
6565
</div>

test/specs/icon.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import nIcon from '../../packages/n-icon';
2+
import { mount } from '@vue/test-utils';
3+
4+
describe('nIcon', () => {
5+
it('name should return NToggle', () => {
6+
const wrapper = mount(nIcon);
7+
expect(wrapper.exists()).toBe(true);
8+
});
9+
});

0 commit comments

Comments
 (0)