use-should-expand-content.ts 1018 B

1234567891011121314151617181920212223242526272829303132333435
  1. import type { IPage, IPagePopulatedToShowRevision } from '@growi/core';
  2. import { useAtomValue } from 'jotai';
  3. import { isContainerFluidAtom } from '~/states/server-configurations';
  4. const useDetermineExpandContent = (
  5. expandContentWidth?: boolean | null,
  6. ): boolean => {
  7. const dataIsContainerFluid = useAtomValue(isContainerFluidAtom);
  8. const isContainerFluidDefault = dataIsContainerFluid;
  9. return expandContentWidth ?? isContainerFluidDefault ?? false;
  10. };
  11. export const useShouldExpandContent = (
  12. data?: IPage | IPagePopulatedToShowRevision | boolean | null,
  13. ): boolean => {
  14. const expandContentWidth = (() => {
  15. // when data is null
  16. if (data == null) {
  17. return null;
  18. }
  19. // when data is boolean
  20. if (data === true || data === false) {
  21. return data;
  22. }
  23. // when IPage does not have expandContentWidth
  24. if (!('expandContentWidth' in data)) {
  25. return null;
  26. }
  27. return data.expandContentWidth;
  28. })();
  29. return useDetermineExpandContent(expandContentWidth);
  30. };