-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from glweems/code-viewer
Code viewer
- Loading branch information
Showing
35 changed files
with
1,544 additions
and
2,711 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import CodeBlock from '@components/CodeBlock'; | ||
import theme from '@lib/theme'; | ||
import { AnimatePresence, motion } from 'framer-motion'; | ||
import React, { Fragment, memo, useCallback, useState } from 'react'; | ||
import { Resizable } from 'react-resizable'; | ||
import { useRecoilState, useRecoilValue } from 'recoil'; | ||
import cssState from './cssState'; | ||
import { optionsState } from './GridActions'; | ||
import { Handle } from './Handle'; | ||
|
||
export const CodeSection = ({ className }) => { | ||
const [{ width: initialWidth, useCssRepeatFn }, setOptions] = useRecoilState( | ||
optionsState | ||
); | ||
const code = useRecoilValue(cssState); | ||
const [width, setWidth] = useState(initialWidth); | ||
const [resizing, setResizing] = useState(false); | ||
const handleResizeStart = useCallback(() => setResizing(true), []); | ||
return ( | ||
<motion.section | ||
style={{ width: `${width}px`, position: 'relative' }} | ||
className={className} | ||
> | ||
<Resizable | ||
height={0} | ||
width={width} | ||
resizeHandles={['w']} | ||
handle={(h) => <Handle className={`handle-${h}`} resizing={resizing} />} | ||
onResizeStart={handleResizeStart} | ||
onResizeStop={() => setResizing(false)} | ||
onResize={(_, { size }) => { | ||
setWidth(Math.round(size.width)); | ||
}} | ||
> | ||
<AnimatePresence> | ||
<motion.div | ||
style={{ padding: theme.space[2] }} | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
exit={{ opacity: 0 }} | ||
> | ||
<Fragment> | ||
<label> | ||
<input | ||
type="checkbox" | ||
defaultChecked={useCssRepeatFn} | ||
onClick={() => | ||
setOptions((prev) => ({ | ||
...prev, | ||
useCssRepeatFn: !prev.useCssRepeatFn, | ||
})) | ||
} | ||
/> | ||
use css repeat | ||
</label> | ||
{code?.css && <CodeBlock language="css" code={code.css} />} | ||
{code?.html && <CodeBlock language="html" code={code.html} />} | ||
</Fragment> | ||
</motion.div> | ||
</AnimatePresence> | ||
</Resizable> | ||
</motion.section> | ||
); | ||
}; | ||
|
||
export default memo(CodeSection); |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { FC, memo } from 'react'; | ||
import { atom, useSetRecoilState } from 'recoil'; | ||
import styled from 'styled-components'; | ||
|
||
export type OptionsState = { | ||
showCode: boolean; | ||
useCssRepeatFn: boolean; | ||
className: string; | ||
width: number; | ||
showSidebar: boolean; | ||
}; | ||
|
||
export const optionsState = atom<OptionsState>({ | ||
key: 'options', | ||
default: { | ||
showCode: true, | ||
showSidebar: true, | ||
useCssRepeatFn: false, | ||
className: 'grid', | ||
width: 300, | ||
}, | ||
}); | ||
type GridActionsProps = { className: string }; | ||
|
||
const GridActions: FC<GridActionsProps> = ({ className }) => { | ||
const setOptions = useSetRecoilState(optionsState); | ||
const handleToggle = ( | ||
e: React.MouseEvent<HTMLButtonElement, MouseEvent> | ||
): void => | ||
setOptions((prev) => ({ | ||
...prev, | ||
[e.currentTarget.name]: !prev[e.currentTarget.name], | ||
})); | ||
return ( | ||
<GridActionsStyles className={className}> | ||
<button name="showSidebar" onClick={handleToggle}> | ||
sidebar | ||
</button> | ||
<button name="showCode" onClick={handleToggle}> | ||
show code | ||
</button> | ||
</GridActionsStyles> | ||
); | ||
}; | ||
|
||
const GridActionsStyles = styled.div` | ||
display: flex; | ||
place-items: center; | ||
justify-content: space-between; | ||
padding: 0 ${(props) => props.theme.space[3]}; | ||
background-color: ${({ theme }) => theme.colors.bg.grayDark}; | ||
label { | ||
color: ${(props) => props.theme.colors.bodytext}; | ||
background-color: ${(props) => props.theme.colors.yellow[4]}; | ||
} | ||
.btn { | ||
width: unset; | ||
} | ||
`; | ||
|
||
export default memo(GridActions); |
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.
38f92f9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: