-
+
{typeof value === 'number' ? addSign(value) : value}
{label &&
@@ -149,26 +156,17 @@ export default function PhotoRecipe({
>)}
{renderRow(<>
{renderDataSquare(
- grainEffect.roughness === 'off'
- ? 'NONE'
- : <>
- {grainEffect.roughness === 'strong'
- ? 'STR'
- : grainEffect.roughness === 'weak'
- ? 'WK'
- : 'OFF'}
- {'/'}
- {grainEffect.size === 'large'
- ? 'LG'
- : grainEffect.size === 'small'
- ? 'SM' : 'OFF'}
- >,
- 'Grain',
+ grainEffect.roughness.toLocaleUpperCase(),
+ grainEffect.size === 'large'
+ ? 'Large Grain'
+ : grainEffect.size === 'small'
+ ? 'Small Grain'
+ : 'Grain',
)}
{renderDataSquare(bwAdjustment ?? 0, 'BW ADJ')}
{renderDataSquare(bwMagentaGreen ?? 0, 'BW M/G')}
>)}
-
+
);
}
diff --git a/src/photo/useRecipeState.ts b/src/photo/useRecipeState.ts
index f6af4935..678163b0 100644
--- a/src/photo/useRecipeState.ts
+++ b/src/photo/useRecipeState.ts
@@ -6,9 +6,12 @@ import {
import { usePathname } from 'next/navigation';
import { SEARCH_PARAM_SHOW } from '@/app/paths';
import { useSearchParams } from 'next/navigation';
-import { useCallback, useRef, useState } from 'react';
+import { RefObject, useCallback, useEffect, useRef, useState } from 'react';
+import { isElementEntirelyInViewport } from '@/utility/dom';
-export default function useRecipeState() {
+export default function useRecipeState(
+ ref?: RefObject
,
+) {
const pathname = usePathname();
const params = useSearchParams();
@@ -54,6 +57,12 @@ export default function useRecipeState() {
}
}, [pathComponents, photoId, shouldShowRecipe]);
+ useEffect(() => {
+ if (shouldShowRecipe && !isElementEntirelyInViewport(ref?.current)) {
+ ref?.current?.scrollIntoView({ behavior: 'smooth' });
+ }
+ }, [ref, shouldShowRecipe]);
+
return {
toggleRecipe,
recipeButtonRef,
diff --git a/src/utility/dom.ts b/src/utility/dom.ts
new file mode 100644
index 00000000..a8e92ecd
--- /dev/null
+++ b/src/utility/dom.ts
@@ -0,0 +1,20 @@
+export const isElementEntirelyInViewport = (
+ element?: HTMLElement | null,
+) => {
+ if (element) {
+ const rect = element.getBoundingClientRect();
+ return (
+ rect.top >= 0 &&
+ rect.left >= 0 &&
+ rect.bottom <= (
+ window.innerHeight ||
+ document.documentElement.clientHeight
+ ) &&
+ rect.right <= (
+ window.innerWidth || document.documentElement.clientWidth
+ )
+ );
+ } else {
+ return false;
+ }
+};