Skip to content

Commit

Permalink
Add scaling option for iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
joonassandell committed Aug 20, 2024
1 parent 54a2730 commit 56ecb7d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
28 changes: 25 additions & 3 deletions components/IframeHandler/IframeHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client';

import { ALLOWED_IFRAME_URLS, REDIRECT_URL } from '@/lib/config';
import { redirect } from 'next/navigation';
import { useEffect } from 'react';
import { redirect, useSearchParams } from 'next/navigation';
import { Suspense, useEffect } from 'react';
import { useTheme } from 'next-themes';

export const IframeHandler = () => {
const IframeHandler = () => {
const queryParamScale = useSearchParams().get('scale') === 'true';
const { setTheme } = useTheme();

/**
Expand All @@ -32,5 +33,26 @@ export const IframeHandler = () => {
}
}, []);

/**
* Scale UI if the param is set
*/
useEffect(() => {
if (!queryParamScale) return;
const root = document.documentElement;
root.classList.add('u-scale');

return () => root.classList.remove('u-scale');
}, [queryParamScale]);

return null;
};

const IframeHandlerSuspense = () => {
return (
<Suspense>
<IframeHandler />
</Suspense>
);
};

export { IframeHandlerSuspense as IframeHandler };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@joonassandell/ui-lab",
"description": "User interface laboratory by Joonas Sandell",
"version": "0.1.8",
"version": "0.1.9",
"type": "module",
"author": {
"name": "Joonas Sandell",
Expand Down
4 changes: 4 additions & 0 deletions stylesheets/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 56ecb7d

Please sign in to comment.