PioneerSquareLabs / otto-playground

A playground where Otto can run free while hopefully not accidentally reformatting your hard drive
https://otto-playground.vercel.app
13 stars 0 forks source link

Create component => src/components/Layout.tsx #688

Closed kleneway closed 1 year ago

kleneway commented 1 year ago

Create a React component for src/components/Layout.tsx. Here are the instructions:

Issue: Create Layout.tsx React component for website layout

Description

We need to create a new React component called Layout.tsx that will be responsible for rendering the main layout of our web application. This component should be written in TypeScript using ES6 syntax, such as arrow functions. It should also use Tailwind CSS for styling and not import any CSS files directly.

Requirements

  1. Create a new file Layout.tsx inside the src/components directory.
  2. Import the necessary dependencies at the top of the file:
    • import React from 'react';
    • import { User } from '~/types';
  3. Define a Props interface for this component. It should have the following properties:
    • children: React.ReactNode; - The child components that will be rendered inside the layout.
    • user: User | null; - The current logged-in user. If the user is not logged in, this should be null.
  4. Create a functional component called Layout with the following structure:
    • It should accept the Props interface as its props.
    • It should render a div element with the class min-h-screen bg-gray-100.
    • Inside the div, render a header element with the class bg-white shadow. This will be the top navigation bar.
      • Inside the header, render a nav element with the class container mx-auto px-6 py-3.
      • Inside the nav, render the application logo and the user's name (if logged in) using Tailwind CSS classes for styling.
    • After the header, render a main element with the class container mx-auto px-6 py-3.
      • Inside the main element, render the children prop.
    • Add any necessary state management using React hooks, if needed.

Example

import React from 'react';
import { User } from '~/types';

interface Props {
  children: React.ReactNode;
  user: User | null;
}

const Layout: React.FC<Props> = ({ children, user }) => {
  return (
    <div className="min-h-screen bg-gray-100">
      <header className="bg-white shadow">
        <nav className="container mx-auto px-6 py-3">
          {/* Render the application logo and user's name here */}
        </nav>
      </header>
      <main className="container mx-auto px-6 py-3">{children}</main>
    </div>
  );
};

export default Layout;

Notes

Please let me know if you have any questions or need further clarification.