Skip to content
Snippets Groups Projects
Commit bd55848d authored by Minseo Lee's avatar Minseo Lee
Browse files

feat: create bottom sheet element, context

parent 0322cd73
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,7 @@ module.exports = { ...@@ -45,6 +45,7 @@ module.exports = {
"disallowTypeAnnotations": true, // optional: to disallow type annotations for variables, parameters, etc. "disallowTypeAnnotations": true, // optional: to disallow type annotations for variables, parameters, etc.
"fixStyle": "separate-type-imports" // optional: to define how the fix should be applied "fixStyle": "separate-type-imports" // optional: to define how the fix should be applied
}], }],
"@typescript-eslint/no-empty-function": "off",
// plugins // plugins
"import/order": ["error", { "import/order": ["error", {
......
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
...@@ -2,3 +2,7 @@ ...@@ -2,3 +2,7 @@
margin-top: var(--header-height); margin-top: var(--header-height);
height: 100%; height: 100%;
} }
.BS-on {
opacity: 0.2;
}
...@@ -4,18 +4,22 @@ import './common/css/reset.css'; ...@@ -4,18 +4,22 @@ import './common/css/reset.css';
import {Routes, Route, useNavigate} from "react-router-dom"; import {Routes, Route, useNavigate} from "react-router-dom";
import S from './App.module.css'; import S from './App.module.css';
import BottomSheet from "./common/components/bottom-sheet/BottomSheet";
import Header from "./common/components/header/Header"; import Header from "./common/components/header/Header";
import Navigator from "./common/components/navigator/Navigator"; import Navigator from "./common/components/navigator/Navigator";
import AppRoute from "./config/route"; import AppRoute from "./config/route";
import {BSProvider} from "./contexts/bottom-sheet";
import {CartProvider} from "./contexts/cart"; import {CartProvider} from "./contexts/cart";
import CartPage from "./pages/cart-page/CartPage"; import CartPage from "./pages/cart-page/CartPage";
import LoginPage from "./pages/login-page/LoginPage"; import LoginPage from "./pages/login-page/LoginPage";
import MainPage from "./pages/main-page/MainPage"; import MainPage from "./pages/main-page/MainPage";
import MenuPage from "./pages/menu-page/MenuPage"; import MenuPage from "./pages/menu-page/MenuPage";
import SignupPage from "./pages/signup-page/SignupPage"; import SignupPage from "./pages/signup-page/SignupPage";
import Wrapper from "./wrapper/Wrapper";
function App() { function App() {
const [login, setLogin] = useState(false); const [login, setLogin] = useState(true);
const [headerName, setHeaderName] = useState(''); const [headerName, setHeaderName] = useState('');
const navigator = useNavigate(); const navigator = useNavigate();
...@@ -26,8 +30,10 @@ function App() { ...@@ -26,8 +30,10 @@ function App() {
}, [login]); }, [login]);
return ( return (
<BSProvider>
<CartProvider> <CartProvider>
<div className="App"> <div className={"App"}>
<Wrapper>
{login && {login &&
<> <>
<Header headerName={headerName} /> <Header headerName={headerName} />
...@@ -43,8 +49,11 @@ function App() { ...@@ -43,8 +49,11 @@ function App() {
<Route path={AppRoute.CART} element={<CartPage />} /> <Route path={AppRoute.CART} element={<CartPage />} />
</Routes> </Routes>
</article> </article>
</Wrapper>
</div> </div>
<BottomSheet />
</CartProvider> </CartProvider>
</BSProvider>
); );
} }
......
.container {
position: fixed;
bottom: 0;
z-index: 10;
width: 100vw;
height: 50vh;
background-color: red;
}
.header {
}
import {useContext, useEffect, useState} from "react";
import {useLocation} from "react-router-dom";
import {BSContext} from "../../../contexts/bottom-sheet";
import S from './BottomSheet.module.css';
import type {FC} from "react";
const BottomSheet: FC = () => {
const { bSElement, setBSElement, flushBSElement } = useContext(BSContext);
const [retEl, setRetEl] = useState(<></>);
const location = useLocation();
useEffect(() => {
flushBSElement();
}, [location]);
useEffect(() => {
if (bSElement) setRetEl(
<div className={S['container']}>
{bSElement}
</div>
);
else setRetEl(<></>);
}, [bSElement]);
return retEl;
};
export default BottomSheet;
import React, {createContext, useState} from "react";
import type {CartItemData} from "../../pages/cart-page/config/type";
import type {FC, ReactNode} from "react";
interface BSContextType {
bSElement: ReactNode;
setBSElement: (d: ReactNode | null) => void;
flushBSElement: () => void;
}
const BSContext = createContext<BSContextType>({
bSElement: null,
setBSElement: (d) => { return d; },
flushBSElement: () => {}
});
interface pProps { children: ReactNode; }
const BSProvider: FC<pProps> = ({ children }) => {
const [item, setItem] = useState<BSContextType['bSElement']>(null);
const setBSElement = (el: ReactNode | null) => {
setItem(() => el);
};
const flushBSElement = () => {
setItem(null);
};
return (
<BSContext.Provider
value={{
bSElement: item,
setBSElement,
flushBSElement
}}
>
{ children }
</BSContext.Provider>
);
};
export {BSProvider, BSContext};
import {Link, useNavigate} from "react-router-dom"; import {useNavigate} from "react-router-dom";
import AppRoute from "../../config/route"; import AppRoute from "../../config/route";
......
import {useEffect, useState} from "react"; import React, {useEffect, useState} from "react";
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import {MAIN_PAGE_DUMMY} from "./config/dummy"; import {MAIN_PAGE_DUMMY} from "./config/dummy";
......
.BS-on {
opacity: 0.2;
overflow: hidden;
}
import {useContext} from "react";
import {BSContext} from "../contexts/bottom-sheet";
import S from './Wrapper.module.css';
import type {FC, ReactNode} from "react";
interface Props { children: ReactNode; }
// NEEDED TO USE CONTEXTS
const Wrapper: FC<Props> = ({ children }) => {
const { bSElement, setBSElement } = useContext(BSContext);
return (
<div className={
bSElement ? S['BS-on'] : ''
}>{children}</div>
);
};
export default Wrapper;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment