Commit 1f92f8df authored by anton's avatar anton

first_lesson-1

parent 442a9334
import { useState } from 'react' import { BurgerBuilder } from "@/containers/BurgerBuilder/BurgerBuilder";
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
function App() { function App() {
const [count, setCount] = useState(0) return <BurgerBuilder />;
return (
<>
<div>
<a href="https://vite.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
} }
export default App export default App;
import { Ingredients } from "@/interfaces/burger-interface";
import "./Burger.css"; import "./Burger.css";
import { Ingredient } from "@/components/Burger/Ingredient/Ingredient";
import { ReactNode } from "react";
interface Props {} interface Props {
ingredients: Ingredients;
}
export function Burger({ ingredients }: Props) {
const ingKeys = Object.keys(ingredients) as (keyof Ingredients)[];
let ingList: ReactNode[] = [];
ingKeys.forEach((key) => {
const amount = ingredients[key];
});
export function Burger(props: Props) { return (
return null; <div className="Burger">
<Ingredient type={"bread-top"} />
<Ingredient type={"cheese"} />
<Ingredient type={"bacon"} />
<Ingredient type={"meat"} />
<Ingredient type={"salad"} />
<Ingredient type={"bread-bottom"} />
</div>
);
} }
import { IngredientNames } from "@/interfaces/burger-interface";
import "./Ingredient.css"; import "./Ingredient.css";
interface Props {} interface Props {
type: IngredientNames;
}
export function Ingredient({ type }: Props) {
switch (type) {
case "bread-top":
return (
<div className="BreadTop">
<div className="Seeds1"></div>
<div className="Seeds2"></div>
</div>
);
case "bread-bottom":
return <div className="BreadBottom"></div>;
case "bacon":
return <div className="Bacon"></div>;
export type IngredientNames = "salad" | "cheese" | "meat" | "bacon"; case "cheese":
return <div className="Cheese"></div>;
export type Ingredients = { case "meat":
[key in IngredientNames]: number; return <div className="Meat"></div>;
};
export function Ingredient(props: Props) { case "salad":
return null; return <div className="Salad"></div>;
}
} }
import { BuildControls } from "@/components/BuildControls/BuildControls";
import { Burger } from "@/components/Burger/Burger";
import { Ingredients } from "@/interfaces/burger-interface";
import { useState } from "react";
export function BurgerBuilder() { export function BurgerBuilder() {
const [ingredients, setIngredients] = useState<Ingredients>({
salad: 0,
cheese: 0,
bacon: 0,
meat: 0,
"bread-bottom": 0,
"bread-top": 0,
});
return ( return (
<> <>
<div>Burger will be here</div> <Burger ingredients={ingredients} />
<div>Build controls will be here</div> <BuildControls />
</> </>
); );
} }
export type IngredientNames = "salad" | "cheese" | "meat" | "bacon" | "bread-top" | "bread-bottom";
export type Ingredients = {
[key in IngredientNames]: number;
};
{ {
"files": [], "compilerOptions": {
"references": [ "target": "ESNext",
{ "path": "./tsconfig.app.json" }, "useDefineForClassFields": true,
{ "path": "./tsconfig.node.json" } "module": "ESNext",
] "moduleResolution": "Node",
"strict": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src"]
} }
import { defineConfig } from 'vite' import { defineConfig } from "vite";
import react from '@vitejs/plugin-react' import react from "@vitejs/plugin-react";
import path from "path";
// https://vite.dev/config/ // https://vite.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
}) resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment