Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Dec 22, 2021
2 parents 80a94c5 + 1992b12 commit 30a946d
Show file tree
Hide file tree
Showing 22 changed files with 268 additions and 191 deletions.
4 changes: 1 addition & 3 deletions components/divider/divider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export default defineComponent({
return () => (
<div className={classList.value}>
{!props.vertical ? (
<div
className={`${prefixCls}-text is-${props.titlePlacement}`}
>
<div class={`${prefixCls}-text is-${props.titlePlacement}`}>
{slots.default?.()}
</div>
) : null}
Expand Down
8 changes: 4 additions & 4 deletions components/dropdown/dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default defineComponent({
});
const renderOptions = () => (
<div
className={`${prefixCls}-option-wrapper ${
class={`${prefixCls}-option-wrapper ${
hasIcon.value ? 'has-icon' : ''
}`}
>
Expand All @@ -100,15 +100,15 @@ export default defineComponent({
const label = option[props.labelField];
return (
<div
className={optionClassList}
class={optionClassList}
onClick={() => {
handleClick(option);
}}
>
<span className={`${prefixCls}-option-icon`}>
<span class={`${prefixCls}-option-icon`}>
{option.icon?.()}
</span>
<span className={`${prefixCls}-option-label`}>
<span class={`${prefixCls}-option-label`}>
{isFunction(label) ? label(option) : label}
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/ellipsis/ellipsis.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default defineComponent({
const renderTrigger = () => (
<span
ref={triggerRef}
className={classList.value}
class={classList.value}
style={style.value}
onMouseenter={handleDisabled}
>
Expand Down
2 changes: 1 addition & 1 deletion components/menu/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ export default defineComponent({
return renderChildren(props.options);
};

return () => <div className={classList.value}>{render()}</div>;
return () => <div class={classList.value}>{render()}</div>;
},
});
23 changes: 16 additions & 7 deletions components/menu/menuGroup.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import {
defineComponent, getCurrentInstance, computed, onMounted, onBeforeUnmount,
defineComponent,
getCurrentInstance,
computed,
onMounted,
onBeforeUnmount,
} from 'vue';
import Ellipsis from '../ellipsis';
import getPrefixCls from '../_util/getPrefixCls';
Expand All @@ -21,9 +25,7 @@ export default defineComponent({
},
setup(props, { slots }) {
const instance = getCurrentInstance();
const {
rootMenu, parentMenu, paddingStyle,
} = useMenu(instance);
const { rootMenu, parentMenu, paddingStyle } = useMenu(instance);
// 根节点 menu
if (!rootMenu) {
return console.warn(
Expand All @@ -37,7 +39,9 @@ export default defineComponent({
);
}
const { children } = useChildren();
const isActive = computed(() => children.some(child => child?.isActive));
const isActive = computed(() =>
children.some((child) => child?.isActive),
);
const subMenu = {
uid: instance.uid,
type: 'menuGroup',
Expand All @@ -51,11 +55,16 @@ export default defineComponent({
parentMenu.removeChild(subMenu);
});
const renderTitle = () => {
const Wrapper = <Ellipsis triggerClass={`${prefixCls}-label`} style={paddingStyle.value}></Ellipsis>;
const Wrapper = (
<Ellipsis
triggerClass={`${prefixCls}-label`}
style={paddingStyle.value}
></Ellipsis>
);
return <Wrapper>{slots.label?.() || props.label}</Wrapper>;
};
return () => (
<div className={prefixCls}>
<div class={prefixCls}>
{renderTitle()}
{slots.default?.()}
</div>
Expand Down
23 changes: 13 additions & 10 deletions components/menu/menuItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ export default defineComponent({
},
setup(props, { slots }) {
const instance = getCurrentInstance();
const {
rootMenu, parentMenu, paddingStyle, onlyIcon,
} = useMenu(instance);
const { rootMenu, parentMenu, paddingStyle, onlyIcon } =
useMenu(instance);
// 根节点 menu
if (!rootMenu) {
return console.warn(
Expand Down Expand Up @@ -55,28 +54,32 @@ export default defineComponent({
onBeforeUnmount(() => {
parentMenu.removeChild(menuItem);
});
const classList = computed(() => [prefixCls, isActive.value && 'is-active'].filter(Boolean).join(' '));
const classList = computed(() =>
[prefixCls, isActive.value && 'is-active']
.filter(Boolean)
.join(' '),
);
const handleClick = () => {
rootMenu.clickMenuItem(props.value);
};
const renderTitle = () => {
const Wrapper = <Ellipsis triggerClass={`${prefixCls}-label`}></Ellipsis>;
const Wrapper = (
<Ellipsis triggerClass={`${prefixCls}-label`}></Ellipsis>
);
return <Wrapper>{slots.label?.() || props.label}</Wrapper>;
};
const renderIcon = () => {
if (slots.icon) {
return (
<span className={`${prefixCls}-icon`}>{slots.icon()}</span>
);
return <span class={`${prefixCls}-icon`}>{slots.icon()}</span>;
}
if (onlyIcon.value) {
return renderTitle();
}
return null;
};
return () => (
<div className={classList.value} onClick={handleClick}>
<div className={`${prefixCls}-wrapper`} style={paddingStyle.value}>
<div class={classList.value} onClick={handleClick}>
<div class={`${prefixCls}-wrapper`} style={paddingStyle.value}>
{renderIcon()}
{!onlyIcon.value ? renderTitle() : null}
</div>
Expand Down
43 changes: 25 additions & 18 deletions components/menu/subMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { COMPONENT_NAME } from './const';
import useMenu from './useMenu';
import useChildren from './useChildren';


const prefixCls = getPrefixCls('sub-menu');
export default defineComponent({
name: COMPONENT_NAME.SUB_MENU,
Expand Down Expand Up @@ -56,7 +55,9 @@ export default defineComponent({
}
const { children } = useChildren();
const isOpened = ref(false);
const isActive = computed(() => children.some(child => child?.isActive));
const isActive = computed(() =>
children.some((child) => child?.isActive),
);
const subMenu = {
uid: instance.uid,
value: props.value,
Expand All @@ -70,7 +71,9 @@ export default defineComponent({
// 默认展开全部
if (rootMenu.props.defaultExpandAll) {
// 这才能触发watch
rootMenu.openedMenus.value = rootMenu.openedMenus.value.concat(props.value || instance.uid);
rootMenu.openedMenus.value = rootMenu.openedMenus.value.concat(
props.value || instance.uid,
);
}
});
onBeforeUnmount(() => {
Expand All @@ -82,16 +85,20 @@ export default defineComponent({
}
return 'right-start';
});
const classList = computed(() => [prefixCls, isActive.value && 'is-active'].filter(Boolean).join(' '));
const classList = computed(() =>
[prefixCls, isActive.value && 'is-active']
.filter(Boolean)
.join(' '),
);
const handleClickTrigger = () => {
isOpened.value = !isOpened.value;
rootMenu.clickSubMenu(subMenu, indexPath);
};
watch(rootMenu.openedMenus, () => {
if (
!rootMenu.renderWithPopper.value
) {
const index = rootMenu.openedMenus.value.indexOf(props.value || instance.uid);
if (!rootMenu.renderWithPopper.value) {
const index = rootMenu.openedMenus.value.indexOf(
props.value || instance.uid,
);
if (index === -1 && isOpened.value) {
isOpened.value = false;
} else if (index !== -1 && !isOpened.value) {
Expand All @@ -100,14 +107,14 @@ export default defineComponent({
}
});
const renderTitle = () => {
const Wrapper = <Ellipsis triggerClass={`${prefixCls}-label`}></Ellipsis>;
const Wrapper = (
<Ellipsis triggerClass={`${prefixCls}-label`}></Ellipsis>
);
return <Wrapper>{slots.label?.() || props.label}</Wrapper>;
};
const renderIcon = () => {
if (slots.icon) {
return (
<div className={`${prefixCls}-icon`}>{slots.icon()}</div>
);
return <div class={`${prefixCls}-icon`}>{slots.icon()}</div>;
}
if (onlyIcon.value) {
return renderTitle();
Expand All @@ -118,26 +125,26 @@ export default defineComponent({
if (rootMenu.renderWithPopper.value) {
if (isFirstLevel.value) {
return (
<span className={`${prefixCls}-arrow`}>
<span class={`${prefixCls}-arrow`}>
{isOpened.value ? <UpOutlined /> : <DownOutlined />}
</span>
);
}
return (
<span className={`${prefixCls}-arrow is-right`}>
<span class={`${prefixCls}-arrow is-right`}>
<RightOutlined />
</span>
);
}
return (
<span className={`${prefixCls}-arrow is-right`}>
<span class={`${prefixCls}-arrow is-right`}>
{isOpened.value ? <UpOutlined /> : <DownOutlined />}
</span>
);
};
const renderWrapper = trigger => (
const renderWrapper = (trigger) => (
<div
className={`${prefixCls}-wrapper`}
class={`${prefixCls}-wrapper`}
style={paddingStyle.value}
onClick={() => {
trigger === 'click' && handleClickTrigger();
Expand Down Expand Up @@ -174,7 +181,7 @@ export default defineComponent({
);
};
return () => (
<div className={classList.value} ref={subMenuRef}>
<div class={classList.value} ref={subMenuRef}>
{renderContent()}
</div>
);
Expand Down
19 changes: 9 additions & 10 deletions components/pagination/jumper.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
defineComponent, toRefs, ref,
} from 'vue';
import { defineComponent, toRefs, ref } from 'vue';

import getPrefixCls from '../_util/getPrefixCls';
import FInput from '../input/input';
Expand Down Expand Up @@ -31,20 +29,21 @@ export default defineComponent({
if (Number.isNaN(cur)) {
return;
}
const currentPage = cur < 1 ? 1 : (cur > total.value ? total.value : cur);
const currentPage =
cur < 1 ? 1 : cur > total.value ? total.value : cur;
current.value = currentPage;
props.change(currentPage);
};
return () => (
<div className={`${prefixCls}-jumper`}>
<span className={`${prefixCls}-jumper-item`}>跳至</span>
<span className={`${prefixCls}-jumper-item`}></span>
<div class={`${prefixCls}-jumper`}>
<span class={`${prefixCls}-jumper-item`}>跳至</span>
<span class={`${prefixCls}-jumper-item`}></span>
<FInput
v-model={current.value}
placeholder=""
onChange={handleChange}>
</FInput>
<span className={`${prefixCls}-jumper-item`}></span>
onChange={handleChange}
></FInput>
<span class={`${prefixCls}-jumper-item`}></span>
</div>
);
},
Expand Down
Loading

0 comments on commit 30a946d

Please sign in to comment.