Просмотр исходного кода

use pagecontrolx and calc max-width

reiji-h 2 лет назад
Родитель
Сommit
9909e962df

+ 15 - 3
apps/app/src/components/PageHeader/PageHeader.tsx

@@ -1,6 +1,7 @@
-import type { FC } from 'react';
+import { useMemo, useRef } from 'react';
 
 
 import { useSWRxCurrentPage } from '~/stores/page';
 import { useSWRxCurrentPage } from '~/stores/page';
+import { usePageControlsX } from '~/stores/ui';
 
 
 import { PagePathHeader } from './PagePathHeader';
 import { PagePathHeader } from './PagePathHeader';
 import { PageTitleHeader } from './PageTitleHeader';
 import { PageTitleHeader } from './PageTitleHeader';
@@ -9,21 +10,32 @@ import styles from './PageHeader.module.scss';
 
 
 const moduleClass = styles['page-header'] ?? '';
 const moduleClass = styles['page-header'] ?? '';
 
 
-export const PageHeader: FC = () => {
+export const PageHeader = (): JSX.Element => {
   const { data: currentPage } = useSWRxCurrentPage();
   const { data: currentPage } = useSWRxCurrentPage();
+  const { data: pageControlsX } = usePageControlsX();
+  const pageHeaderRef = useRef<HTMLDivElement>(null);
+
+  const maxWidth = useMemo(() => {
+    if (pageControlsX == null || pageHeaderRef.current == null) {
+      return 300;
+    }
+    return pageControlsX - pageHeaderRef.current.getBoundingClientRect().x - 10;
+  }, [pageControlsX]);
 
 
   if (currentPage == null) {
   if (currentPage == null) {
     return <></>;
     return <></>;
   }
   }
 
 
   return (
   return (
-    <div className={`${moduleClass} w-100`}>
+    <div className={`${moduleClass} w-100`} ref={pageHeaderRef}>
       <PagePathHeader
       <PagePathHeader
         currentPage={currentPage}
         currentPage={currentPage}
+        maxWidth={maxWidth}
       />
       />
       <div className="mt-1">
       <div className="mt-1">
         <PageTitleHeader
         <PageTitleHeader
           currentPage={currentPage}
           currentPage={currentPage}
+          maxWidth={maxWidth}
         />
         />
       </div>
       </div>
     </div>
     </div>

+ 8 - 5
apps/app/src/components/PageHeader/PagePathHeader.tsx

@@ -1,7 +1,6 @@
 import {
 import {
   useState, useCallback, memo,
   useState, useCallback, memo,
 } from 'react';
 } from 'react';
-import type { FC } from 'react';
 
 
 import type { IPagePopulatedToShowRevision } from '@growi/core';
 import type { IPagePopulatedToShowRevision } from '@growi/core';
 import { DevidedPagePath } from '@growi/core/dist/models';
 import { DevidedPagePath } from '@growi/core/dist/models';
@@ -25,11 +24,12 @@ const moduleClass = styles['page-path-header'];
 type Props = {
 type Props = {
   currentPage: IPagePopulatedToShowRevision,
   currentPage: IPagePopulatedToShowRevision,
   className?: string,
   className?: string,
+  maxWidth?: number,
 }
 }
 
 
-export const PagePathHeader: FC<Props> = memo((props: Props) => {
+export const PagePathHeader = memo((props: Props): JSX.Element => {
   const { t } = useTranslation();
   const { t } = useTranslation();
-  const { currentPage, className } = props;
+  const { currentPage, className, maxWidth } = props;
 
 
   const dPagePath = new DevidedPagePath(currentPage.path, true);
   const dPagePath = new DevidedPagePath(currentPage.path, true);
   const parentPagePath = dPagePath.former;
   const parentPagePath = dPagePath.former;
@@ -104,12 +104,13 @@ export const PagePathHeader: FC<Props> = memo((props: Props) => {
     <div
     <div
       id="page-path-header"
       id="page-path-header"
       className={`d-flex ${moduleClass} ${className ?? ''} small position-relative ms-2`}
       className={`d-flex ${moduleClass} ${className ?? ''} small position-relative ms-2`}
+      style={{ maxWidth }}
       onMouseEnter={() => setHover(true)}
       onMouseEnter={() => setHover(true)}
       onMouseLeave={() => setHover(false)}
       onMouseLeave={() => setHover(false)}
     >
     >
       <div
       <div
         id="grw-page-path-header-container"
         id="grw-page-path-header-container"
-        className="me-2 d-inline-block overflow-hidden"
+        className="d-inline-block overflow-hidden"
       >
       >
         { isRenameInputShown && (
         { isRenameInputShown && (
           <div className="position-absolute w-100">
           <div className="position-absolute w-100">
@@ -136,7 +137,9 @@ export const PagePathHeader: FC<Props> = memo((props: Props) => {
         </div>
         </div>
       </div>
       </div>
 
 
-      <div className={`page-path-header-buttons d-flex align-items-center ${isHover && !isRenameInputShown ? '' : 'invisible'}`}>
+      <div
+        className={`page-path-header-buttons d-flex align-items-center ${isHover && !isRenameInputShown ? '' : 'invisible'}`}
+      >
         <button
         <button
           type="button"
           type="button"
           className="btn btn-outline-neutral-secondary me-2 d-flex align-items-center justify-content-center"
           className="btn btn-outline-neutral-secondary me-2 d-flex align-items-center justify-content-center"

+ 18 - 15
apps/app/src/components/PageHeader/PageTitleHeader.tsx

@@ -1,4 +1,3 @@
-import type { FC } from 'react';
 import { useState, useCallback, useEffect } from 'react';
 import { useState, useCallback, useEffect } from 'react';
 
 
 import nodePath from 'path';
 import nodePath from 'path';
@@ -24,11 +23,12 @@ const borderColorClass = styles['page-title-header-border-color'] ?? '';
 type Props = {
 type Props = {
   currentPage: IPagePopulatedToShowRevision,
   currentPage: IPagePopulatedToShowRevision,
   className?: string,
   className?: string,
+  maxWidth?: number,
 };
 };
 
 
-export const PageTitleHeader: FC<Props> = (props) => {
+export const PageTitleHeader = (props: Props): JSX.Element => {
   const { t } = useTranslation();
   const { t } = useTranslation();
-  const { currentPage } = props;
+  const { currentPage, maxWidth } = props;
 
 
   const currentPagePath = currentPage.path;
   const currentPagePath = currentPage.path;
 
 
@@ -91,20 +91,23 @@ export const PageTitleHeader: FC<Props> = (props) => {
   }, [currentPage._id, isNewlyCreatedPage]);
   }, [currentPage._id, isNewlyCreatedPage]);
 
 
   return (
   return (
-    <div className={`d-flex ${moduleClass} ${props.className ?? ''} position-relative`}>
+    <div className={`d-flex ${moduleClass} ${props.className ?? ''} position-relative`} style={{ maxWidth }}>
       <div className="me-1 d-inline-block overflow-hidden">
       <div className="me-1 d-inline-block overflow-hidden">
         { isRenameInputShown && (
         { isRenameInputShown && (
-          <div className="position-absolute w-100">
-            <ClosableTextInput
-              value={isNewlyCreatedPage ? '' : editedPageTitle}
-              placeholder={t('Input page name')}
-              inputClassName="fs-4"
-              onPressEnter={onPressEnter}
-              onPressEscape={onPressEscape}
-              onChange={onInputChange}
-              onClickOutside={() => { setRenameInputShown(false) }}
-              validationTarget={ValidationTarget.PAGE}
-            />
+          <div className="position-relative">
+            <div className="position-absolute w-100">
+              <ClosableTextInput
+                value={isNewlyCreatedPage ? '' : editedPageTitle}
+                placeholder={t('Input page name')}
+                inputClassName="fs-4"
+                onPressEnter={onPressEnter}
+                onPressEscape={onPressEscape}
+                onChange={onInputChange}
+                onClickOutside={() => { setRenameInputShown(false) }}
+                validationTarget={ValidationTarget.PAGE}
+                useAutosizeInput
+              />
+            </div>
           </div>
           </div>
         ) }
         ) }
         <h1
         <h1