ant-design-vue/components/vc-virtual-list/Filler.tsx

72 lines
1.7 KiB
Vue
Raw Normal View History

2020-09-26 14:52:40 +00:00
import classNames from '../_util/classNames';
2020-09-28 11:14:00 +00:00
import ResizeObserver from '../vc-resize-observer';
2021-06-26 01:35:40 +00:00
import type { CSSProperties, FunctionalComponent, PropType } from 'vue';
2020-09-26 14:52:40 +00:00
2020-10-01 09:20:10 +00:00
interface FillerProps {
prefixCls?: string;
/** Virtual filler height. Should be `count * itemMinHeight` */
height: number;
/** Set offset of visible items. Should be the top of start item position */
offset?: number;
onInnerResize?: () => void;
}
const Filter: FunctionalComponent<FillerProps> = (
{ height, offset, prefixCls, onInnerResize },
{ slots },
) => {
2020-09-26 14:52:40 +00:00
let outerStyle = {};
2020-10-01 09:20:10 +00:00
let innerStyle: CSSProperties = {
2020-09-26 14:52:40 +00:00
display: 'flex',
flexDirection: 'column',
};
if (offset !== undefined) {
2020-09-28 11:14:00 +00:00
outerStyle = { height: `${height}px`, position: 'relative', overflow: 'hidden' };
2020-09-26 14:52:40 +00:00
innerStyle = {
...innerStyle,
transform: `translateY(${offset}px)`,
position: 'absolute',
left: 0,
right: 0,
top: 0,
};
}
return (
<div style={outerStyle}>
2020-09-28 11:14:00 +00:00
<ResizeObserver
onResize={({ offsetHeight }) => {
if (offsetHeight && onInnerResize) {
onInnerResize();
}
}}
2020-09-26 14:52:40 +00:00
>
2020-09-28 11:14:00 +00:00
<div
style={innerStyle}
class={classNames({
[`${prefixCls}-holder-inner`]: prefixCls,
})}
>
{slots.default?.()}
</div>
</ResizeObserver>
2020-09-26 14:52:40 +00:00
</div>
);
};
2020-10-01 09:20:10 +00:00
2020-09-28 11:14:00 +00:00
Filter.displayName = 'Filter';
Filter.inheritAttrs = false;
2020-10-07 14:49:01 +00:00
Filter.props = {
prefixCls: String,
/** Virtual filler height. Should be `count * itemMinHeight` */
height: Number,
/** Set offset of visible items. Should be the top of start item position */
offset: Number,
onInnerResize: Function as PropType<() => void>,
};
2020-09-26 14:52:40 +00:00
export default Filter;