2022-03-26 14:52:54 +00:00
|
|
|
import type { FunctionalComponent, PropType } from 'vue';
|
|
|
|
import type { MouseEventHandler } from '../_util/EventInterface';
|
2021-12-16 09:20:18 +00:00
|
|
|
import type { VueNode } from '../_util/type';
|
2020-10-03 07:54:52 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2022-01-21 13:58:10 +00:00
|
|
|
import type { RenderNode } from './BaseSelect';
|
2020-10-03 07:54:52 +00:00
|
|
|
|
|
|
|
export interface TransBtnProps {
|
|
|
|
class: string;
|
2022-01-21 13:58:10 +00:00
|
|
|
customizeIcon: RenderNode;
|
2020-10-03 07:54:52 +00:00
|
|
|
customizeIconProps?: any;
|
|
|
|
onMousedown?: (payload: MouseEvent) => void;
|
|
|
|
onClick?: (payload: MouseEvent) => void;
|
|
|
|
}
|
|
|
|
|
2020-11-26 05:39:18 +00:00
|
|
|
export interface TransBtnType extends FunctionalComponent<TransBtnProps> {
|
|
|
|
displayName: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TransBtn: TransBtnType = (props, { slots }) => {
|
2020-10-03 07:54:52 +00:00
|
|
|
const { class: className, customizeIcon, customizeIconProps, onMousedown, onClick } = props;
|
2021-12-16 09:20:18 +00:00
|
|
|
let icon: VueNode;
|
2020-10-03 07:54:52 +00:00
|
|
|
|
|
|
|
if (typeof customizeIcon === 'function') {
|
|
|
|
icon = customizeIcon(customizeIconProps);
|
|
|
|
} else {
|
|
|
|
icon = customizeIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span
|
|
|
|
class={className}
|
|
|
|
onMousedown={event => {
|
|
|
|
event.preventDefault();
|
|
|
|
if (onMousedown) {
|
|
|
|
onMousedown(event);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
style={{
|
|
|
|
userSelect: 'none',
|
|
|
|
WebkitUserSelect: 'none',
|
|
|
|
}}
|
|
|
|
unselectable="on"
|
|
|
|
onClick={onClick}
|
|
|
|
aria-hidden
|
|
|
|
>
|
|
|
|
{icon !== undefined ? (
|
|
|
|
icon
|
|
|
|
) : (
|
|
|
|
<span class={className.split(/\s+/).map((cls: any) => `${cls}-icon`)}>
|
2020-10-24 12:36:57 +00:00
|
|
|
{slots.default?.()}
|
2020-10-03 07:54:52 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
TransBtn.inheritAttrs = false;
|
2020-11-26 05:39:18 +00:00
|
|
|
TransBtn.displayName = 'TransBtn';
|
2020-10-03 07:54:52 +00:00
|
|
|
TransBtn.props = {
|
2022-03-26 14:52:54 +00:00
|
|
|
class: String,
|
2020-10-03 07:54:52 +00:00
|
|
|
customizeIcon: PropTypes.any,
|
|
|
|
customizeIconProps: PropTypes.any,
|
2022-03-26 14:52:54 +00:00
|
|
|
onMousedown: Function as PropType<MouseEventHandler>,
|
|
|
|
onClick: Function as PropType<MouseEventHandler>,
|
2020-10-03 07:54:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default TransBtn;
|