Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root"></div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Architects+Daughter&display=swap");

* {
	box-sizing: border-box;
	font-family: "Architects Daughter", cursive;
}

body {
  background: #232526;
  background: linear-gradient(to right, #232526, #414345);
	font-family: "Architects Daughter", cursive;
}

.container {
	padding: 32px;
}

.header {
	align-items: center;
	display: flex;
	justify-content: space-between;
	margin-bottom: 24px;
}

.title {
	color: white;
	font-size: 36px;
}

.note-list {
	display: flex;
	gap: 24px;
	flex-wrap: wrap;
}

.note-list-item {
	background: #feff9c;
	box-shadow:
		0px 15.3px 1.7px -8px rgba(0, 0, 0, 0.02),
		0px 13.7px 5.8px -8px rgba(0, 0, 0, 0.03),
		0px 10px 26px -8px rgba(0, 0, 0, 0.05);
	padding: 16px;
	position: relative;
	width: 240px;
	height: 240px;

	.button-remove {
		align-items: center;
		background: #232526;
		border: 2px solid white;
		border-radius: 50%;
		cursor: pointer;
		display: flex;
		font-size: 20px;
		height: 48px;
		justify-content: center;
		position: absolute;
		right: -12px;
		top: -12px;
		width: 48px;
		span {
			color: white;
		}
		&:hover {
			background: darken(#232526, 5%);
		}
		&:active {
			background: darken(#232526, 15%);
		}
	}
	.button-note-action {
		cursor: pointer;
		font-size: 16px;
		padding: 4px 8px;
		&:active {
			opacity: 0.5;
		}
	}
	.button-add-subitem {
		position: absolute;
		right: -12px;
		bottom: -12px;
	}
	.button-color {
		position: absolute;
		left: -12px;
		bottom: -12px;
	}
	.button-hover {
		opacity: 0;
		visibility: hidden;
		transition: all 150ms ease-in-out;
	}
	&:hover {
		.button-hover {
			opacity: 1;
			visibility: visible;
		}
	}
}

.note-content {
	max-height: 100%;
	overflow-y: auto;
}

.note-textarea {
	background: none;
	border: none;
	color: #232526;
	font-size: 24px;
	line-height: 32px;
	padding: 8px;
	resize: none;
	width: 100%;
}

.note-sublist {
	padding-left: 4px;
}

.note-sublist-item {
	align-items: center;
	color: #232526;
	display: flex;
	gap: 4px;
	line-height: 24px;
	font-size: 18px;
	position: relative;
	label {
		cursor: pointer;
		&::before {
			background-color: #232526;
			content: "";
			position: absolute;
			left: 24px;
			height: 1px;
			top: 50%;
			transition: all 200ms ease-in-out;
			width: 0;
		}
	}
	input[type="checkbox"]:checked + label {
		&::before {
			width: calc(100% - 36px);
		}
	}
	input[type="checkbox"] {
		appearance: none;
		background: none;
		border: 1px solid #232526;
		border-radius: 2px;
		cursor: pointer;
		display: grid;
		opacity: 0.8;
		place-content: center;
		height: 16px;
		width: 16px;
		&::before {
			background-color: #232526;
			content: "";
			clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
			height: 10px;
			width: 10px;
			transform: scale(0);
			transform-origin: bottom left;
			transition: transform 100ms ease-in-out;
		}
		&:checked::before {
			transform: scale(1);
		}
	}
}

.button-add {
	background: none;
	border: 2px solid white;
	border-radius: 8px;
	color: white;
	cursor: pointer;
	font-size: 18px;
	font-family: "Architects Daughter", cursive;
	padding: 12px 16px;
	transform: rotate(-1deg);
	transition: all 150ms ease-in-out;
	&:hover {
		transform: scale(1.05);
	}
	&:active {
		opacity: 0.5;
	}
}

              
            
!

JS

              
                const todos = [
	{
		text: "Groceries",
		sublist: [
			"3 Tomatoes",
			"1 bunch of cherries",
			"6 onions",
			"3 heads of garlic",
			"1 bag spring mix"
		]
	},
	{ text: "Cancel gym membership", sublist: [] },
	{ text: "Clean gutters", sublist: [] },
	{ text: "Take package to the post office", sublist: [] },
	{ text: "Call Avery about Ali's party (afternoon)", sublist: [] },
	{ text: "Sort recycling & put out trash", sublist: [] }
];

// https://www.color-hex.com/color-palette/29241
const colors = ['#ff7eb9', '#ff65a3', '#7afcff', '#feff9c', '#fff740'];

const randomAngle = () => Math.random() < 0.5 ? Math.random() : Math.random() * -1;

const randomUUID = () => ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
  (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);

const randomColor = () => colors[Math.floor(Math.random() * colors.length)];

const nextColor = (color) => {
	const index = colors.indexOf(color);
	return colors[(index + 1) % colors.length];
};
	
const adaptTextareaHeight = (el) => {
	el.style.height = 0;
	el.style.height = `${el.scrollHeight}px`;
}

const TodoList = ({ notes }) => {
	const [items, setItems] = React.useState(notes.map(note => ({
		...note,
		id: randomUUID(),
		angle: randomAngle(),
		bgColor: randomColor(),
	})));
	
	const adaptTextareas = () => {
		items.forEach(item => {
			const el = document.getElementById(item.id);
			if (el) adaptTextareaHeight(el);
		});
	};
	
	React.useEffect(() => {
		adaptTextareas();
	}, []);
	
	const addItem = () => {
		const newItem = {
			id: randomUUID(),
			text: "...",
			sublist: [],
			angle: randomAngle(),
			bgColor: randomColor(),
		};
		setItems(oldItems => [...oldItems, newItem]);
	};
	
	const removeItem = (id) => {
		const index = items.findIndex(item => item.id === id);
		const updatedItems = [...items];
		updatedItems.splice(index, 1);
		setItems(updatedItems);
		setTimeout(() => adaptTextareas());
	};
	
	const handleTextChange = (ev, id) => {
		const index = items.findIndex(item => item.id === id);
		const updatedItems = [...items];
		updatedItems[index].text = ev.target.value;
		setItems(updatedItems);
		adaptTextareaHeight(ev.target);
	};
	
	const addSubItem = (id) => {
		const index = items.findIndex(item => item.id === id);
		const updatedItems = [...items];
		const text = prompt("Input the subitem text", "");
		if (text) {
			updatedItems[index].sublist.push(text);
			setItems(updatedItems);
		}
	};
	
	const changeColor = (id) => {
		const index = items.findIndex(item => item.id === id);
		const updatedItems = [...items];
		const updatedColor = nextColor(updatedItems[index].bgColor);
		updatedItems[index].bgColor = updatedColor;
		setItems(updatedItems);
	};
	
	return (
		<section className="container">
			<header className="header">
				<h1 className="title">Todo Board</h1>
				<button className="button-add" onClick={addItem}>
					Add Note
				</button>
			</header>
			<ul className="note-list">
				{items.map(note =>
					(
						<li
							className="note-list-item"
							style={{
								transform: `rotate(${note.angle}deg)`,
								background: note.bgColor
							}}
						>
							<button
								className="button-hover button-remove"
								onClick={() => removeItem(note.id)}
							>
								<span>✖</span>
							</button>
							<article className="note-content">
								<textarea
									id={note.id}
									className="note-textarea"
									value={note.text}
									onChange={e => handleTextChange(e, note.id)}
								/>
								<ul className="note-sublist">
									{note.sublist.map(item => (
										<li className="note-sublist-item">
											<input type="checkbox" id={item} name={item} value={item} />
											<label for={item}>{item}</label>
										</li>
									))}
								</ul>
								<button
									className="button-hover button-note-action button-add-subitem"
									onClick={() => addSubItem(note.id)}
								>
									Add subitem
								</button>
								<button
									className="button-hover button-note-action button-color"
									onClick={() => changeColor(note.id)}
								>
									Color
								</button>
							</article>
						</li>
					)
				)}
			</ul>
		</section>
	);
};

ReactDOM.render(<TodoList notes={todos} />,
document.getElementById("root"))

              
            
!
999px

Console