Skip to content

Commit

Permalink
Merge pull request #1619 from hackforla/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
sydneywalcoff authored Oct 9, 2024
2 parents c1ed2c1 + 3d3effb commit 911a6eb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
4 changes: 3 additions & 1 deletion products/statement-generator/src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ export function LinkButtonComponent({
className={`${classes.root} ${className}`}
to={to!}
data-testid={dataTestId}
/>
>
{buttonText}
</Link>
);
}

Expand Down
108 changes: 55 additions & 53 deletions products/statement-generator/src/components/TextPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useState, useRef, useEffect } from 'react';
import React, { useState, useRef, useEffect } from 'react';

import { makeStyles, createStyles } from '@material-ui/core';
import CreateIcon from '@material-ui/icons/Create';
Expand Down Expand Up @@ -58,63 +58,65 @@ interface ComponentProps {
isFirstPreview?: boolean;
}

const TextPreview = forwardRef<HTMLDivElement, ComponentProps>(
(
{ onSaveClick, content, nameOfStep, className = '', style, isFirstPreview },
ref
) => {
const classes = useStyles();
const utilityClasses = useUtilityStyles();
const [isEditing, setIsEditing] = useState<boolean>(false);
const editButtonRef = useRef<HTMLButtonElement | null>(null);
const previewContainerRef = useRef<HTMLDivElement | null>(null);
const TextPreview = ({
onSaveClick,
content,
nameOfStep,
className = '',
style,
isFirstPreview,
}: ComponentProps) => {
const classes = useStyles();
const utilityClasses = useUtilityStyles();
const [isEditing, setIsEditing] = useState<boolean>(false);
const editButtonRef = useRef<HTMLButtonElement | null>(null);
const previewContainerRef = useRef<HTMLDivElement | null>(null);

const handleClick = () => {
setIsEditing(true);
};
const handleClick = () => {
setIsEditing(true);
};

useEffect(() => {
if (isFirstPreview && previewContainerRef.current) {
previewContainerRef.current.focus();
}
}, [isFirstPreview]);
useEffect(() => {
if (isFirstPreview && previewContainerRef.current) {
previewContainerRef.current.focus();
}
}, [isFirstPreview]);

return (
<div
ref={previewContainerRef}
className={`${classes.root} ${className}`}
style={style}
>
<div className={classes.previewHeader}>
<h3>{nameOfStep}</h3>
return (
<div
ref={previewContainerRef}
className={`${classes.root} ${className}`}
style={style}
>
<div className={classes.previewHeader}>
<h3>{nameOfStep}</h3>

<div className={classes.actionHeader}>
{!isEditing && (
<button
className={`${utilityClasses.iconButton} ${classes.editButton}`}
onClick={handleClick}
aria-label="Edit content"
ref={editButtonRef}
tabIndex={0}
>
<CreateIcon />
</button>
)}
</div>
<div className={classes.actionHeader}>
{!isEditing && (
<button
className={`${utilityClasses.iconButton} ${classes.editButton}`}
onClick={handleClick}
aria-label="Edit content"
ref={editButtonRef}
tabIndex={0}
>
<CreateIcon />
</button>
)}
</div>

{isEditing ? (
<EditContent
content={content}
setIsEditing={setIsEditing}
onSaveClick={onSaveClick}
/>
) : (
<p>{content}</p>
)}
</div>
);
}
);

{isEditing ? (
<EditContent
content={content}
setIsEditing={setIsEditing}
onSaveClick={onSaveClick}
/>
) : (
<p>{content}</p>
)}
</div>
);
};

export default TextPreview;

0 comments on commit 911a6eb

Please sign in to comment.