feat: update carousel
parent
9bcb12e611
commit
b84a86bb40
|
@ -1,6 +1,7 @@
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
import { initDefaultProps, getComponentFromProp, filterEmpty } from '../_util/props-util';
|
import { initDefaultProps, getComponentFromProp, filterEmpty } from '../_util/props-util';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
|
||||||
// matchMedia polyfill for
|
// matchMedia polyfill for
|
||||||
// https://github.com/WickyNilliams/enquire.js/issues/82
|
// https://github.com/WickyNilliams/enquire.js/issues/82
|
||||||
|
@ -70,13 +71,11 @@ const Carousel = {
|
||||||
props: initDefaultProps(CarouselProps, {
|
props: initDefaultProps(CarouselProps, {
|
||||||
dots: true,
|
dots: true,
|
||||||
arrows: false,
|
arrows: false,
|
||||||
prefixCls: 'ant-carousel',
|
|
||||||
draggable: false,
|
draggable: false,
|
||||||
}),
|
}),
|
||||||
|
inject: {
|
||||||
// innerSlider: any;
|
configProvider: { default: () => ({}) },
|
||||||
|
},
|
||||||
// private slick: any;
|
|
||||||
|
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
this.onWindowResized = debounce(this.onWindowResized, 500, {
|
this.onWindowResized = debounce(this.onWindowResized, 500, {
|
||||||
|
@ -137,7 +136,10 @@ const Carousel = {
|
||||||
props.fade = true;
|
props.fade = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let className = props.prefixCls;
|
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
let className = getPrefixCls('carousel', props.prefixCls);
|
||||||
|
|
||||||
if (props.vertical) {
|
if (props.vertical) {
|
||||||
className = `${className} ${className}-vertical`;
|
className = `${className} ${className}-vertical`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { cloneElement } from '../_util/vnode';
|
import { cloneElement } from '../_util/vnode';
|
||||||
import warning from '../_util/warning';
|
import warning from '../_util/warning';
|
||||||
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
|
|
||||||
const CascaderOptionType = PropTypes.shape({
|
const CascaderOptionType = PropTypes.shape({
|
||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
|
@ -73,7 +74,7 @@ const CascaderProps = {
|
||||||
/** 是否支持清除*/
|
/** 是否支持清除*/
|
||||||
allowClear: PropTypes.bool.def(true),
|
allowClear: PropTypes.bool.def(true),
|
||||||
showSearch: PropTypes.oneOfType([Boolean, ShowSearchType]),
|
showSearch: PropTypes.oneOfType([Boolean, ShowSearchType]),
|
||||||
notFoundContent: PropTypes.any.def('Not Found'),
|
notFoundContent: PropTypes.an,
|
||||||
loadData: PropTypes.func,
|
loadData: PropTypes.func,
|
||||||
/** 次级菜单的展开方式,可选 'click' 和 'hover' */
|
/** 次级菜单的展开方式,可选 'click' 和 'hover' */
|
||||||
expandTrigger: CascaderExpandTrigger,
|
expandTrigger: CascaderExpandTrigger,
|
||||||
|
@ -81,8 +82,8 @@ const CascaderProps = {
|
||||||
changeOnSelect: PropTypes.bool,
|
changeOnSelect: PropTypes.bool,
|
||||||
/** 浮层可见变化时回调 */
|
/** 浮层可见变化时回调 */
|
||||||
// onPopupVisibleChange?: (popupVisible: boolean) => void;
|
// onPopupVisibleChange?: (popupVisible: boolean) => void;
|
||||||
prefixCls: PropTypes.string.def('ant-cascader'),
|
prefixCls: PropTypes.string,
|
||||||
inputPrefixCls: PropTypes.string.def('ant-input'),
|
inputPrefixCls: PropTypes.string,
|
||||||
getPopupContainer: PropTypes.func,
|
getPopupContainer: PropTypes.func,
|
||||||
popupVisible: PropTypes.bool,
|
popupVisible: PropTypes.bool,
|
||||||
fieldNames: FieldNamesType,
|
fieldNames: FieldNamesType,
|
||||||
|
@ -285,7 +286,7 @@ const Cascader = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
generateFilteredOptions(prefixCls) {
|
generateFilteredOptions(prefixCls, renderEmpty) {
|
||||||
const { showSearch, notFoundContent, $scopedSlots } = this;
|
const { showSearch, notFoundContent, $scopedSlots } = this;
|
||||||
const names = getFilledFieldNames(this.$props);
|
const names = getFilledFieldNames(this.$props);
|
||||||
const {
|
const {
|
||||||
|
@ -335,7 +336,11 @@ const Cascader = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
{ [names.label]: notFoundContent, [names.value]: 'ANT_CASCADER_NOT_FOUND', disabled: true },
|
{
|
||||||
|
[names.label]: notFoundContent || renderEmpty('Cascader'),
|
||||||
|
[names.value]: 'ANT_CASCADER_NOT_FOUND',
|
||||||
|
disabled: true,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -364,8 +369,8 @@ const Cascader = {
|
||||||
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
||||||
const { getPopupContainer: getContextPopupContainer } = configProvider;
|
const { getPopupContainer: getContextPopupContainer } = configProvider;
|
||||||
const {
|
const {
|
||||||
prefixCls,
|
prefixCls: customizePrefixCls,
|
||||||
inputPrefixCls,
|
inputPrefixCls: customizeInputPrefixCls,
|
||||||
placeholder = localeData.placeholder,
|
placeholder = localeData.placeholder,
|
||||||
size,
|
size,
|
||||||
disabled,
|
disabled,
|
||||||
|
@ -374,6 +379,11 @@ const Cascader = {
|
||||||
...otherProps
|
...otherProps
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
|
||||||
|
const renderEmpty = this.configProvider.renderEmpty || ((componentName) => ConfigConsumerProps.renderEmpty(componentName));
|
||||||
|
const prefixCls = getPrefixCls('cascader', customizePrefixCls);
|
||||||
|
const inputPrefixCls = getPrefixCls('input', customizeInputPrefixCls);
|
||||||
|
|
||||||
const sizeCls = classNames({
|
const sizeCls = classNames({
|
||||||
[`${inputPrefixCls}-lg`]: size === 'large',
|
[`${inputPrefixCls}-lg`]: size === 'large',
|
||||||
[`${inputPrefixCls}-sm`]: size === 'small',
|
[`${inputPrefixCls}-sm`]: size === 'small',
|
||||||
|
@ -423,7 +433,7 @@ const Cascader = {
|
||||||
|
|
||||||
let options = props.options;
|
let options = props.options;
|
||||||
if (inputValue) {
|
if (inputValue) {
|
||||||
options = this.generateFilteredOptions(prefixCls);
|
options = this.generateFilteredOptions(prefixCls, renderEmpty);
|
||||||
}
|
}
|
||||||
// Dropdown menu should keep previous status until it is fully closed.
|
// Dropdown menu should keep previous status until it is fully closed.
|
||||||
if (!sPopupVisible) {
|
if (!sPopupVisible) {
|
||||||
|
@ -502,6 +512,7 @@ const Cascader = {
|
||||||
...props,
|
...props,
|
||||||
getPopupContainer,
|
getPopupContainer,
|
||||||
options: options,
|
options: options,
|
||||||
|
prefixCls,
|
||||||
value: value,
|
value: value,
|
||||||
popupVisible: sPopupVisible,
|
popupVisible: sPopupVisible,
|
||||||
dropdownMenuColumnStyle: dropdownMenuColumnStyle,
|
dropdownMenuColumnStyle: dropdownMenuColumnStyle,
|
||||||
|
|
|
@ -2,5 +2,5 @@ import '../../style/index.less';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
|
|
||||||
// style dependencies
|
// style dependencies
|
||||||
// import '../../empty/style';
|
import '../../empty/style';
|
||||||
import '../../input/style';
|
import '../../input/style';
|
||||||
|
|
|
@ -15,11 +15,17 @@ const ConfigProvider = {
|
||||||
return {
|
return {
|
||||||
configProvider: {
|
configProvider: {
|
||||||
...this.$props,
|
...this.$props,
|
||||||
renderEmpty: this.$props.renderEmpty || this.$slots.renderEmpty || defaultRenderEmpty,
|
renderEmpty: this.renderEmptySlots,
|
||||||
getPrefixCls: this.getPrefixCls,
|
getPrefixCls: this.getPrefixCls,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
renderEmptySlots() {
|
||||||
|
const customRender = (this.$scopedSlots && this.$scopedSlots['renderEmpty']) || this.$slots['renderEmpty'];
|
||||||
|
return this.$props.renderEmpty || customRender || defaultRenderEmpty;
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getPrefixCls(suffixCls, customizePrefixCls) {
|
getPrefixCls(suffixCls, customizePrefixCls) {
|
||||||
const { prefixCls = 'ant' } = this.$props;
|
const { prefixCls = 'ant' } = this.$props;
|
||||||
|
@ -37,6 +43,7 @@ export const ConfigConsumerProps = {
|
||||||
if (customizePrefixCls) return customizePrefixCls;
|
if (customizePrefixCls) return customizePrefixCls;
|
||||||
return `ant-${suffixCls}`;
|
return `ant-${suffixCls}`;
|
||||||
},
|
},
|
||||||
|
renderEmpty: defaultRenderEmpty,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
|
|
|
@ -20,8 +20,8 @@ Use ConfigProvider set global Empty style.
|
||||||
|
|
||||||
<a-divider />
|
<a-divider />
|
||||||
<a-config-provider>
|
<a-config-provider>
|
||||||
<template v-if="customize">
|
<template v-slot:renderEmpty>
|
||||||
<div slot="renderEmpty" style="textAlign: center">
|
<div style="textAlign: center">
|
||||||
<a-icon type="smile" style="fontSize: 20px" />
|
<a-icon type="smile" style="fontSize: 20px" />
|
||||||
<p>Data Not Found</p>
|
<p>Data Not Found</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,7 +54,7 @@ Use ConfigProvider set global Empty style.
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
customize: false,
|
customize: true,
|
||||||
style: {width: '200px'},
|
style: {width: '200px'},
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue