use-should-expand-content.ts 1008 B

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