Skip to content

Limit container

Purpose

This container limits the number of visible child elements when it overflows. It can also display special content when overflowing (element with the attribute slot='limit'). This can be useful on toolbars or cards when you need to display some of the elements and show the rest through additional panels or a spread.

Usage

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>
};

Types

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;
}

Released under the Apache-2.0 License.