123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id = "root"></div>
            
          
!
            
              $background-color : #9300C5
$icon-size : 40px
$shadow-color : #101820
$blue-color : #87C5F5  
$gold-color : #CFB53B
$white-color : #EBEDEF
$red-color : #F54321
$gold-glow-color : #E3BE46 
$white-glow-color : #FFFFFF
$shadow : 2px 2px 10px $shadow-color

body
	background : $background-color
	font-family : "love ya like a sister"
	padding-bottom : 40vh

a
	text-decoration : none
	color : black
	cursor : pointer

.title
	font : 
		family : "satisfy"
		size : 3.3em
	color : $white-color
	text-shadow : $shadow
	margin-left : 10px

.fcc-logo
	margin-top : 5px
	margin-right : 10px
	font-size : 3.5em
	float : right
	color : $white-color
	&:hover
		color : $white-glow-color

.add-button
	cursor : pointer
	font-size : $icon-size
	background : $gold-color
	color : $white-color
	border-radius : 50%
	height : 76px
	width : 76px
	box-shadow : $shadow
	position : fixed
	bottom : 25px
	right : 25px
	&:hover
		background-color : $gold-glow-color
		color : $white-glow-color

.recipes
	display : flex
	flex-wrap : wrap

.recipe
	flex : auto
	margin : 10px
	width : 300px
	height : 100%
	background : $white-color
	border-radius : 5px
	&:hover
		box-shadow : $shadow

.recipe-title
	border-bottom : 2px solid $gold-color
	border-radius : 5px
	
.recipe-name
	padding : 8px 15px 0px 20px
	font-size : 2em

.recipe-name-input
	padding : 8px 15px 2px 20px
	font-size : 1.6em
	border : none
	border-radius : 5px
	background : $white-color

.edit-name
	font-size : 1.2em
	float : right
	margin : 15px 15px 0px 0px

.recipe-ingredients
	margin : 10px
	padding : 0px 10px 0px 10px

.fa-chevron-circle-right
	font-size : 1.5em
	color : $background-color
	
.fa-minus-circle
	font-size : 1.5em
	color : $red-color

.ingredient-name
	font-size : 1.5em
	margin : 0px 10px

.edit-ingredient
	float : right

.plus-times
	margin : 10px 20px
	&:hover
		color : $red-color

.lock-unlock
	float : right
	margin : 10px 20px
	&:hover
		color : $blue-color
            
          
!
            
              class RecipeBox extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			recipes : [{
				name : "Kheer",
				ingredients : ["Rice", "Milk", "Cardamom", "Saffron", "Pistachios", "Almonds"]
			},{
				name : "Dosa",
				ingredients : ["Rice", "Black lentils"]
			},{
				name : "Naan",
				ingredients : ["Wheat flour (Atta, Maida)", "Water", "Yeast", "Cooking fat (Butter or Ghee)", "Yogurt", "Milk"]
			}]
		}
		//binding methods
		this.addRecipe = this.addRecipe.bind(this);
		this.updateRecipe = this.updateRecipe.bind(this);
		this.removeRecipe = this.removeRecipe.bind(this);
		this.saveRecipes = this.saveRecipes.bind(this);
	}
	
	addRecipe() {
		let { recipes } = this.state;
		recipes.push({ name : "New Recipe", ingredients : [] })
		this.saveRecipes(recipes);
	}
	
	updateRecipe(index, name, ingredients) {
		let { recipes } = this.state;
		recipes[index].name = name;
		recipes[index].ingredients = ingredients;
		this.saveRecipes(recipes);
		console.log(JSON.stringify(recipes));
	}
	
	removeRecipe(index) {
		let { recipes } = this.state;
		this.saveRecipes(recipes.slice(0, index).concat(recipes.slice(index + 1)));
	}
	
	saveRecipes(recipes) {
		localStorage.setItem("_MukeshAngrish_recipes", JSON.stringify(recipes));
		this.setState({ recipes });
	}
	
	componentDidMount() {
		let recipes = localStorage.getItem("_MukeshAngrish_recipes");
		if(recipes)
			this.setState({ recipes : JSON.parse(recipes) });
	}
	
	render() {
		let recipes = this.state.recipes.map((recipe, index) => {
			return (
				<Recipe 
					key = { recipe.name }
					name = { recipe.name }
					ingredients = { recipe.ingredients }
					index = { index }
					onUpdateRecipe = { this.updateRecipe }
					onRemoveRecipe = { this.removeRecipe }
				/>
			);
		});
		return (
			<div className = "recipe-box">
				<div className = "title-bar">
					<span className = "title">Recipe Box</span>
					<a href = "https://www.freecodecamp.org/mukeshangrish" target = "_blank">
						<span className = "fab fa-free-code-camp fcc-logo"></span>
					</a>
				</div>
				<div 
					className = "recipes"
					id = "recipes">
					{ recipes }
				</div>
				<div className = "add-recipe">
					<button 
						className = "fas fa-plus add-button"
						onClick = { this.addRecipe }>
					</button>
				</div>
			</div>
		);
	}
}

class Recipe extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			locked : true,
			edit : false
		}
		//binding methods
		this.toggleLock = this.toggleLock.bind(this);
		this.addIngredient = this.addIngredient.bind(this);
		this.updateIngredients = this.updateIngredients.bind(this);
		this.removeRecipe = this.removeRecipe.bind(this);
		this.handleNameUpdate = this.handleNameUpdate.bind(this);
	}
	
	toggleLock() {
		let locked = !this.state.locked;
		this.setState({ locked });
	}
	
	addIngredient() {
		let { ingredients } = this.props;
		ingredients.push("Untitled")
		this.updateIngredients(ingredients);
	}
	
	updateIngredients(ingredients) {
		this.props.onUpdateRecipe(this.props.index, this.props.name, ingredients);
	}
	
	removeRecipe() {
		this.props.onRemoveRecipe(this.props.index);
	}
	
	handleNameUpdate({ target }) {
		this.props.onUpdateRecipe(this.props.index, target.value, this.props.ingredients);
		
	}
		
	render() {
		let { locked } = this.state;
		let ingredients = this.props.ingredients.map((ingredient, index) => {
			return (
				<Ingredient 
					key = { ingredient }
					ingredient = { ingredient }
					index = { index }
					ingredients = { this.props.ingredients }
					locked = { this.state.locked }
					onUpdateIngredients = { this.updateIngredients }
				/>
			);
		});
		return (
			<div 
				className = "recipe"
				id = { "recipe-" + this.props.index }>
				<div 
					className = "recipe-title"
					id = { "recipe-title-" + this.props.index}>
					{!this.state.edit && (
						<a
							href = { "#recipe-details-" + this.props.index }
							data-toggle = "collapse"
							className = "recipe-name"
							id = { "recipe-name-" + this.props.index }>
							{ this.props.name }		
						</a>
					)}
					{this.state.edit && (
						<input
  						ref={(input) => { this.recipeTitle = input; }}
  						className = "recipe-name-input"
  						
  						value = { this.props.name } />
					)}
					<span>
						{!this.state.edit && (
							<i
								className = "fas fa-pencil-alt edit-name"
								id = { "edit-name-" + this.props.index }
								onClick = { () => this.setState({ edit : true }) }>
							</i>
						)}
						{this.state.edit && (
  						<i
  							className = "fas fa-check edit-name"
  							id = { "edit-name-" + this.props.index }
  							onClick = { () => {
    							this.setState({ edit : false });
    							this.props.onUpdateRecipe(this.props.index, this.recipeTitle.value, this.props.ingredients);
  							}}>
 							</i>
						)}
					</span>
				</div>
				<div 
					className = "recipe-details"// collapse"
					id = { "recipe-details-" + this.props.index }>
					<div 
					className = "recipe-ingredients"
					id = { "recipe-ingredients-" + this.props.index }>
					{ ingredients }
				</div>
				<div className = "options">
					<span 
						className = { "plus-times fas fa-" + (locked ? "plus" : "times") }
						onClick = { locked ? this.addIngredient : this.removeRecipe }> 
					</span>
					<span 
						className = { "lock-unlock fas fa-" + (locked ? "lock" : "unlock") }
						onClick = { this.toggleLock }>
					</span>
			  </div>
				</div>	
			</div>
		);
	}
}

class Ingredient extends React.Component {
	constructor(props) {
		super(props);
		//binding methods
		this.removeIngredient = this.removeIngredient.bind(this);
		this.handleIngredientUpdate = this.handleIngredientUpdate.bind(this);
	}
	
	removeIngredient() {
		let { ingredients } = this.props;
		this.props.onUpdateIngredients(ingredients.slice(0, this.props.index).concat(ingredients.slice(this.props.index + 1)));
	}
	
	handleIngredientUpdate(event) {
		console.log("handleIngredientUpdate")
	}
	
	render() {
		let { locked } = this.props;
		return (
			<div 
				className = "ingredient"
				id = { "ingredient-" + this.props.index }
				>
				<span 
					className = { locked ? "fas fa-chevron-circle-right" : "fas fa-minus-circle" }
					onClick = { locked ? "javascript:void(0)" : this.removeIngredient }>
				</span>
				<span 
					className = "ingredient-name"
					id = { "ingredient-name" + this.props.index }>
					{ this.props.ingredient }
				</span>
				<span
					className = { locked ? "" : " fas fa-pencil-alt edit-ingredient"}
					onClick = { this.handleIngredientUpdate }>
				</span>
			</div>
		);
	}
}

ReactDOM.render(<RecipeBox />, document.getElementById("root"));
				
/*
	add under div with className recipe-title		
	
	<a
		href = { "#recipe-details-" + this.props.index }
		data-toggle = "collapse"
		className = "recipe-name"
		id = { "recipe-name-" + this.props.index }>
		{ this.props.name }		
	</a>
	<span
		className = "fas fa-pencil-alt edit-name"
		id = { "edit-name-" + this.props.index }
		onClick = { this.handleNameUpdate }>
	</span>
*/
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console