@elastic/eui
Version:
Elastic UI Component Library
33 lines (30 loc) • 1.76 kB
JavaScript
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { useIsWithinMinBreakpoint, useEuiTheme } from '../../services';
import { usePropsWithComponentDefaults } from '../provider/component_defaults';
import { DEFAULT_PUSH_MIN_BREAKPOINT, DEFAULT_TYPE } from './const';
/**
* Determines if a flyout should be rendered in a "pushed" state based on its
* configuration and the current window or container size.
*/
export var useIsPushed = function useIsPushed(props) {
var _usePropsWithComponen = usePropsWithComponentDefaults('EuiFlyout', props),
_usePropsWithComponen2 = _usePropsWithComponen.type,
type = _usePropsWithComponen2 === void 0 ? DEFAULT_TYPE : _usePropsWithComponen2,
_usePropsWithComponen3 = _usePropsWithComponen.pushMinBreakpoint,
pushMinBreakpoint = _usePropsWithComponen3 === void 0 ? DEFAULT_PUSH_MIN_BREAKPOINT : _usePropsWithComponen3;
var _useEuiTheme = useEuiTheme(),
breakpoints = _useEuiTheme.euiTheme.breakpoint;
// Always called to satisfy React hook rules; used as fallback
// when no container width is provided or the breakpoint key is
// not present on the theme.
var windowIsLargeEnoughToPush = useIsWithinMinBreakpoint(pushMinBreakpoint);
var minWidth = breakpoints[pushMinBreakpoint];
var isLargeEnoughToPush = props.containerWidth != null && minWidth != null ? props.containerWidth >= minWidth : windowIsLargeEnoughToPush;
return type === 'push' && isLargeEnoughToPush;
};