限制容器
目的
此容器会在溢出时限制可见子元素的数量。它还可以在溢出时显示特殊内容(带有 slot='limit' 属性的元素)。这在工具栏或卡片中非常有用,当您需要显示部分元素,并将其余元素通过附加面板或展开图显示时。
用法
jsx
import { useEffect } from 'react';
import { useLimit } from 'effsz/limit';
const { observe } = useLimit();
export const App = () => {
useEffect(() => {
const unobserve = observe((event) => {
// handle limit events
});
return () => unobserve();
}, []);
return <effsz-limit fdir='rr' gap='5'>
<div className='first'>...</div>
<div className='second'>...</div>
<div slot='limit' className='overflow'>...</div>
</effsz-limit>
};类型
ts
/**
* Limit container attributes
*/
export interface ILimitContainerAttrs {
/**
* Flex direction
*/
fdir: 'r' | 'rr' | 'c' | 'cr';
/**
* Gap in px
*/
gap: string;
};
/**
* Limit container
*/
export interface ILimitContainerElement extends HTMLElement {
/**
* Split axis
*/
get axis(): 'x' | 'y';
/**
* Visible elements count
*/
get limitCount(): number;
/**
* Is container hiding some children
*/
get isLimited(): boolean;
}