use-should-expand-content.ts 952 B

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