UNPKG

@elastic/eui

Version:

Elastic UI Component Library

34 lines (30 loc) 1.49 kB
/* * 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 { createContext, useContext } from 'react'; import { useIsWithinMinBreakpoint } from '../../../services'; export var DEFAULT_TABLE_BREAKPOINT = 'm'; /** * Used by parent/top-level table components to determine isResponsive state * based on the passed breakpoint */ export var useIsEuiTableResponsive = function useIsEuiTableResponsive() { var breakpoint = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_TABLE_BREAKPOINT; var isBoolean = typeof breakpoint === 'boolean'; // Note: we're using `!useIsWithinMinBreakpoint` here instead of `useIsWithinMaxBreakpoint` // because it more accurately reflects the single breakpoint at which tables collapse var isResponsive = !useIsWithinMinBreakpoint(isBoolean ? '' : breakpoint); return isBoolean ? breakpoint : isResponsive; }; /** * Context set by parent table components * Hook used by cells to fetch parent isResponsive state */ export var EuiTableIsResponsiveContext = /*#__PURE__*/createContext(false); export var useEuiTableIsResponsive = function useEuiTableIsResponsive() { return useContext(EuiTableIsResponsiveContext); };