コンテナを制限する
目的
このコンテナは、オーバーフロー時に表示できる子要素の数を制限します。また、オーバーフロー時に特別なコンテンツを表示することもできます(属性slot='limit'を持つ要素)。これは、ツールバーやカードなどで、一部の要素を表示し、残りを別のパネルやスプレッドで表示する必要がある場合に役立ちます。
使用法
jsx
import { useEffect } from 'react';
import { useLimit } from 'effsz/limit';
const { observe } = useLimit();
export const App = () => {
useEffect(() => {
const unobserve = observe((event) => {
// 制限イベントを処理する
});
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>
};TypeScriptの型
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 {
/**
* Limit axis
*/
get axis(): 'x' | 'y';
/**
* Visible elements count
*/
get limitCount(): number;
/**
* Is container hiding some children
*/
get isLimited(): boolean;
}