File size: 1,938 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import { useBreakpoint } from '@automattic/viewport-react';
import clsx from 'clsx';
import { ReactNode } from 'react';
import DropdownGroup from './dropdown-group';
import SwipeGroup from './swipe-group';
import './style.scss';
const ResponsiveToolbarGroup = ( {
children,
className = '',
hideRatio = 0.99,
showRatio = 1,
rootMargin = '0px',
onClick = () => null,
initialActiveIndex = -1,
initialActiveIndexes,
swipeBreakpoint = '<660px',
hrefList = [],
forceSwipe = false,
swipeEnabled = true,
isMultiSelection = false,
}: {
children: ReactNode[];
className?: string;
hideRatio?: number;
showRatio?: number;
rootMargin?: string;
onClick?: ( index: number ) => void;
initialActiveIndex?: number;
initialActiveIndexes?: number[];
swipeBreakpoint?: string;
/**
* List of href attributes
*/
hrefList?: string[];
/**
* Rendering mode
*/
forceSwipe?: boolean;
/**
* When false completely disables swipe at all breakpoints.
*/
swipeEnabled?: boolean;
/**
* Whether to allow multiple selection.
*/
isMultiSelection?: boolean;
} ) => {
const classes = clsx( 'responsive-toolbar-group', className );
const isWithinBreakpoint = useBreakpoint( swipeBreakpoint );
if ( forceSwipe || ( swipeEnabled && isWithinBreakpoint ) ) {
return (
<SwipeGroup
className={ classes }
initialActiveIndex={ initialActiveIndex }
initialActiveIndexes={ initialActiveIndexes }
onClick={ onClick }
hrefList={ hrefList }
isMultiSelection={ isMultiSelection }
>
{ children }
</SwipeGroup>
);
}
return (
<DropdownGroup
className={ classes }
initialActiveIndex={ initialActiveIndex }
initialActiveIndexes={ initialActiveIndexes }
onClick={ onClick }
hideRatio={ hideRatio }
showRatio={ showRatio }
rootMargin={ rootMargin }
isMultiSelection={ isMultiSelection }
>
{ children }
</DropdownGroup>
);
};
export default ResponsiveToolbarGroup;
|