Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Dec 15, 2021
2 parents 9fdff2a + 7d43824 commit f7c5603
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 112 deletions.
19 changes: 0 additions & 19 deletions components/config-provider/config.js

This file was deleted.

36 changes: 27 additions & 9 deletions components/config-provider/configProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import {
defineComponent, watch,
} from 'vue';
import config from './config';
import { defineComponent, watch, reactive } from 'vue';
import { isObject, isNil } from 'lodash-es';

const config = reactive({
getContainer: () => document.body,
});

export const setConfig = (data) => {
if (isObject(data)) {
Object.keys(data).forEach((prop) => {
if (!isNil(data[prop])) {
config[prop] = data[prop];
}
});
}
};

export const getConfig = () => config;

export default defineComponent({
name: 'FConfigProvider',
props: {
getContainer: Function,
},
setup(props, { slots }) {
watch(props, () => {
config.setConfig(props);
}, {
immediate: true,
});
watch(
props,
() => {
setConfig(props);
},
{
immediate: true,
},
);
return () => slots.default?.();
},
});
8 changes: 2 additions & 6 deletions components/config-provider/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { withInstall } from '../_util/withInstall';
import ConfigProvider from './configProvider';
import config from './config';

ConfigProvider.setConfig = config.setConfig;

ConfigProvider.getConfig = config.getConfig;

export const FConfigProvider = withInstall(ConfigProvider);

export default ConfigProvider;
export default FConfigProvider;
export { setConfig, getConfig } from './configProvider';
4 changes: 2 additions & 2 deletions components/drawer/drawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FButton from '../button';
import { CloseOutlined } from '../icon';
import PopupManager from '../_util/popupManager';
import useLockScreen from '../_util/use/useLockScreen';
import ConfigProvider from '../config-provider';
import { getConfig } from '../config-provider';

const prefixCls = getPrefixCls('drawer');
const UPDATE_SHOW_EVENT = 'update:show';
Expand Down Expand Up @@ -91,7 +91,7 @@ const Drawer = defineComponent({
},
{ immediate: true },
);
const config = ConfigProvider.getConfig();
const config = getConfig();
const getContainer = computed(() => props.getContainer || config.getContainer);

function handleCancel(event) {
Expand Down
14 changes: 3 additions & 11 deletions components/message/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { isObject } from 'lodash-es';
import getPrefixCls from '../_util/getPrefixCls';
import { createManager } from '../_util/noticeManager';
import Alert from '../alert/alert';
import ConfigProvider from '../config-provider';
import { getConfig } from '../config-provider';

const prefixCls = getPrefixCls('message');

const defaultConfig = {
duration: 3,
getContainer: () => {
const config = ConfigProvider.getConfig();
const config = getConfig();
return config.getContainer();
},
maxCount: null,
Expand All @@ -20,15 +20,7 @@ let mergeConfig = defaultConfig;

let messageInstance = null;

async function create({
type,
content,
duration,
icon,
closable,
afterClose,
colorful,
}) {
async function create({ type, content, duration, icon, closable, afterClose, colorful }) {
if (!messageInstance) {
messageInstance = await createManager({
getContainer: mergeConfig.getContainer,
Expand Down
78 changes: 15 additions & 63 deletions components/modal/modal.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import {
computed,
defineComponent,
Teleport,
Transition,
ref,
watch,
nextTick,
} from 'vue';
import { computed, defineComponent, Teleport, Transition, ref, watch, nextTick } from 'vue';
import { isNumber } from 'lodash-es';
import getPrefixCls from '../_util/getPrefixCls';
import FButton from '../button';
import { CloseOutlined } from '../icon';
import { iconComponentMap } from '../_util/noticeManager';
import PopupManager from '../_util/popupManager';
import useLockScreen from '../_util/use/useLockScreen';
import ConfigProvider from '../config-provider';

import { getConfig } from '../config-provider';

const prefixCls = getPrefixCls('modal');
const UPDATE_SHOW_EVENT = 'update:show';
Expand Down Expand Up @@ -116,7 +107,7 @@ const Modal = defineComponent({
},
{ immediate: true },
);
const config = ConfigProvider.getConfig();
const config = getConfig();
const getContainer = computed(() => props.getContainer || config.getContainer);

function handleCancel(event) {
Expand All @@ -140,13 +131,7 @@ const Modal = defineComponent({
const Icon = modalIconMap[props.type];
return (
<div class={`${prefixCls}-header`}>
{props.forGlobal && (
<div
class={`${prefixCls}-icon ${prefixCls}-status-${props.type}`}
>
{ Icon && <Icon /> }
</div>
)}
{props.forGlobal && <div class={`${prefixCls}-icon ${prefixCls}-status-${props.type}`}>{Icon && <Icon />}</div>}
<div>{header}</div>
</div>
);
Expand All @@ -161,19 +146,11 @@ const Modal = defineComponent({
footer = (
<>
{(!props.forGlobal || props.type === 'confirm') && (
<FButton
size="middle"
class="btn-margin"
onClick={handleCancel}
>
<FButton size="middle" class="btn-margin" onClick={handleCancel}>
{props.cancelText}
</FButton>
)}
<FButton
type="primary"
size="middle"
onClick={handleOk}
>
<FButton type="primary" size="middle" onClick={handleOk}>
{props.okText}
</FButton>
</>
Expand All @@ -190,64 +167,39 @@ const Modal = defineComponent({
};
});

const showDom = computed(
() => (props.displayDirective === 'if' && visible.value)
|| props.displayDirective === 'show',
);
const showDom = computed(() => (props.displayDirective === 'if' && visible.value) || props.displayDirective === 'show');

return () => (
<Teleport to={getContainer.value?.()}>
<div class={`${prefixCls}`}>
<Transition name={`${prefixCls}-mask-fade`}>
{props.mask && showDom.value && (
<div
class={`${prefixCls}-mask`}
style={{ zIndex: zIndex.value }}
v-show={visible.value}
></div>
)}
{props.mask && showDom.value && <div class={`${prefixCls}-mask`} style={{ zIndex: zIndex.value }} v-show={visible.value}></div>}
</Transition>
<Transition
name={`${prefixCls}-fade`}
onAfterLeave={handleTransitionAfterLeave}
>
<Transition name={`${prefixCls}-fade`} onAfterLeave={handleTransitionAfterLeave}>
{showDom.value && (
<div
v-show={visible.value}
class={{
[`${prefixCls}-container`]: true,
[`${prefixCls}-center`]: props.center,
[`${prefixCls}-fullscreen`]:
props.fullScreen,
[`${prefixCls}-fullscreen`]: props.fullScreen,
[`${prefixCls}-global`]: props.forGlobal,
[`${prefixCls}-no-header`]: !hasHeader.value,
[`${prefixCls}-no-footer`]: !props.footer,
}}
style={{ zIndex: zIndex.value }}
onClick={event => props.maskClosable
&& props.mask
&& handleCancel(event)
}
onClick={(event) => props.maskClosable && props.mask && handleCancel(event)}
>
<div
class={`${prefixCls}-wrapper ${
props.contentClass || ''
}`}
class={`${prefixCls}-wrapper ${props.contentClass || ''}`}
style={styles.value}
onClick={event => event.stopPropagation()}
onClick={(event) => event.stopPropagation()}
>
{getHeader()}
<div class={`${prefixCls}-body`}>
{ctx.slots.default
? ctx.slots.default()
: props.forGlobal && props.content}
</div>
<div class={`${prefixCls}-body`}>{ctx.slots.default ? ctx.slots.default() : props.forGlobal && props.content}</div>
{getFooter()}
{props.closable && (
<div
class={`${prefixCls}-close`}
onClick={handleCancel}
>
<div class={`${prefixCls}-close`} onClick={handleCancel}>
<CloseOutlined />
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions components/popper/popper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useTrigger from './useTrigger';
import usePopper from './usePopper';
import useResize from './useResize';
import { getFirstValidNode } from '../_util/vnode';
import ConfigProvider from '../config-provider';
import { getConfig } from '../config-provider';

const prefixCls = getPrefixCls('popper');

Expand Down Expand Up @@ -70,7 +70,7 @@ export default defineComponent({
if (!ctx.slots.trigger) {
throw new Error('FPopper', 'Trigger must be provided');
}
const config = ConfigProvider.getConfig();
const config = getConfig();
const getContainer = computed(() => props.getContainer || config.getContainer);
const { slots } = ctx;
const { visible, updateVisible, triggerRef, popperRef, arrowRef, update, popperStyle, updateVirtualRect } = usePopper(props, ctx);
Expand Down

0 comments on commit f7c5603

Please sign in to comment.