-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5613c3c
commit 134daa4
Showing
36 changed files
with
353 additions
and
1,952 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,79 @@ | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
import { | ||
Box, | ||
Slider, | ||
SliderTrack, | ||
SliderFilledTrack, | ||
SliderThumb, | ||
useMediaQuery, | ||
} from '@chakra-ui/react'; | ||
import { DragHandleIcon } from '@chakra-ui/icons'; | ||
import { useTheme } from 'nextra-theme-docs'; | ||
|
||
export const ResizableIframe = () => { | ||
const [dimensions, setDimensions] = useState({ width: 800 }); | ||
const iframeRef = useRef(null); | ||
|
||
const [sliderValue, setSliderValue] = useState(60); | ||
|
||
const [isMediumScreen] = useMediaQuery('(min-width: 600px)'); | ||
|
||
const { theme } = useTheme(); | ||
|
||
const [borderColor, setBorderColor] = useState('#edf2f7'); | ||
|
||
useEffect(() => { | ||
setBorderColor(theme === 'dark' ? '#4A5568' : '#edf2f7'); | ||
}, [theme]); | ||
// Media query state to detect screen size | ||
const [isMediumScreen, setIsMediumScreen] = useState(false); | ||
|
||
// Update dimensions based on slider value | ||
useEffect(() => { | ||
setDimensions({ width: sliderValue <= 40 ? 40 : sliderValue }); | ||
}, [sliderValue]); | ||
|
||
// Update screen size state on window resize | ||
useEffect(() => { | ||
const handleResize = () => setIsMediumScreen(window.innerWidth >= 600); | ||
handleResize(); | ||
window.addEventListener('resize', handleResize); | ||
return () => window.removeEventListener('resize', handleResize); | ||
}, []); | ||
|
||
return ( | ||
<Box> | ||
<div className="my-4"> | ||
<iframe | ||
ref={iframeRef} | ||
src="/demo" | ||
style={{ | ||
width: `${isMediumScreen ? dimensions.width : '100'}%`, | ||
height: '600px', | ||
borderWidth: 1, | ||
borderRadius: 10, | ||
borderColor, | ||
borderWidth: '1px', | ||
borderRadius: '10px', | ||
}} | ||
/> | ||
className="border border-gray-100 dark:border-gray-700" | ||
></iframe> | ||
|
||
{/* Slider only visible on medium screens */} | ||
{isMediumScreen && ( | ||
<Slider | ||
aria-label="slider-ex-1" | ||
value={sliderValue} | ||
onChange={(val) => setSliderValue(val)} | ||
min={0} | ||
max={100} | ||
colorScheme={sliderValue < 40 ? 'gray' : 'teal'} | ||
> | ||
<SliderTrack> | ||
<SliderFilledTrack /> | ||
</SliderTrack> | ||
<SliderThumb boxSize={6}> | ||
<Box color="teal" as={DragHandleIcon} /> | ||
</SliderThumb> | ||
</Slider> | ||
<div className="flex flex-1 items-center mt-4"> | ||
<input | ||
type="range" | ||
aria-label="Resize slider" | ||
value={sliderValue} | ||
onChange={(e) => setSliderValue(parseInt(e.target.value))} | ||
min={0} | ||
max={100} | ||
className={`w-full flex-1 h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer ${ | ||
sliderValue < 40 ? 'accent-gray-400' : 'accent-teal-500' | ||
}`} | ||
style={{ | ||
flex: 1, | ||
accentColor: 'teal' | ||
}} | ||
/> | ||
<div | ||
className="w-6 h-6 flex justify-center items-center bg-teal-500 rounded-full ml-2" | ||
style={{ color: 'white' }} | ||
> | ||
{/* This icon simulates the DragHandleIcon */} | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
className="h-4 w-4" | ||
viewBox="0 0 20 20" | ||
fill="currentColor" | ||
> | ||
<path | ||
fillRule="evenodd" | ||
d="M5 6a1 1 0 110-2h10a1 1 0 110 2H5zm0 6a1 1 0 110-2h10a1 1 0 110 2H5zm0 6a1 1 0 110-2h10a1 1 0 110 2H5z" | ||
clipRule="evenodd" | ||
/> | ||
</svg> | ||
</div> | ||
</div> | ||
)} | ||
</Box> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.