Responsive Media React Tailwind - reactjs

So i have component that i try to make it responsive, but when it comes to media below md: it not working at all and i have some problem on turning the view into what i want
Here is the look on the web view:
and here is the problem :
is that posible to make the button into this when it comes to phone view?
Here is my try:
const CardCalculation = () => {
return (
<div className="ml-2">
<div className="mx-auto lg:flex lg:items-center lg:justify-between">
<h2 className="tracking-tight text-gray-900 sm:text-xl">
<div className="gap-2">
<div className="w-[120px] h-[110px] absolute bg-[#d9d9d9] lg:mb-10"></div>
<div className="text-xl ml-32 text-left text-[#e44]">
Mie Goleng
</div>
<div className="ml-32 text-left text-[#b4b4b4]">Plant K103.</div>
<div className="ml-32 text-left text-[#b4b4b4]">500.02 UOG.</div>
</div>
</h2>
<div className="mt-4 flex lg:mt-0 lg:flex-shrink-0 md:mt-4 sm:mt-8">
<div>
<div className="rounded-md mb-2 shadow">
<a
href="#"
className="inline-flex items-center justify-center rounded-md border border-transparent bg-indigo-600 px-5 py-3 text-base font-medium text-white hover:bg-indigo-700"
>
Get started
</a>
</div>
<div className="rounded-md shadow">
<a
href="#"
className="inline-flex items-center justify-center rounded-md border border-transparent bg-indigo-600 px-5 py-3 text-base font-medium text-indigo-600 hover:bg-indigo-50"
>
Learn more
</a>
</div>
</div>
</div>
</div>
</div>
);
};
export default CardCalculation;
can someone explained to me why it not responsive to the screen and does it possible to turn the button into horizontal when it comes to phone view as below?

Use the following code:
<div class="p-2">
<div class="flex flex-col md:flex-row md:justify-between">
<div class="flex gap-4">
<div name="grey window" class="h-[110px] w-[120px] bg-[#d9d9d9]"></div>
<div name="text" class="pt-2 md:flex md:flex-col md:justify-evenly md:pt-4">
<div class="text-xl text-[#e44] md:text-3xl">Mie Goleng</div>
<div class="mt-2 text-[#b4b4b4] md:text-xl">Plant K103.</div>
<div class="mt-2 text-[#b4b4b4] md:text-xl">500.02 UOG.</div>
</div>
</div>
<div name="Buttons">
<div class="flex gap-4 md:flex-col p-4 md:p-0">
<div class="rounded-md shadow">
Get started
</div>
<div class="rounded-md shadow">
Learn more
</div>
</div>
</div>
</div>
</div>
Output on large devices:
Output on small devices:
Tailwind play

Related

How can I do to put the edit input into my react project?

Hello I have that edit input :
<link rel="stylesheet" href="https://unpkg.com/boxicons#2.0.7/css/boxicons.min.css" />
<script defer src="https://unpkg.com/alpinejs#3.9.1/dist/cdn.min.js"></script>
<main class="flex min-h-screen w-full items-center justify-center bg-gray-100">
<div x-data="{ open : false }" class="p-2 bg-white border shadow rounded w-96">
<div x-show="!open" class="flex justify-between items-center">
<div class="ml-2">Hafiz Haziq</div>
<button type="button" class="btn bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 font-medium rounded "
#click="open = !open">Edit</button>
</div>
<!-- container after clicked "EDIT" -->
<div x-show="open" class="flex justify-between items-center">
<input type="text" class="w-full bg-gray-100 rounded p-2 mr-4" value="Hafiz Haziq">
<div class="flex justify-center items-center space-x-2">
<button type="button" class="rounded bg-emerald-500 hover:bg-emerald-600 w-10 h-10 text-white text-3xl">
<i class='bx bx-check'></i>
</button>
<button type="button" class="rounded bg-red-500 hover:bg-red-600 text-white w-10 h-10 text-3xl"
#click="open = false">
<i class='bx bx-x'></i>
</button>
</div>
</div>
</div>
</main>
that I found here : The edit input
And I would like to put it into my react project :
I tried that :
import "./styles.css";
const App = ()=> {
return (
<main class="flex min-h-screen w-full items-center justify-center bg-gray-100">
<div x-data="{ open : false }" class="p-2 bg-white border shadow rounded w-96">
<div x-show="!open" class="flex justify-between items-center">
<div class="ml-2">Hafiz Haziq</div>
<button type="button" class="btn bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 font-medium rounded "
#click="open = !open">Edit</button>
</div>
{/*<!-- container after clicked "EDIT" --> */}
<div x-show="open" class="flex justify-between items-center">
<input type="text" class="w-full bg-gray-100 rounded p-2 mr-4" value="Hafiz Haziq" />
<div class="flex justify-center items-center space-x-2">
<button type="button" class="rounded bg-emerald-500 hover:bg-emerald-600 w-10 h-10 text-white text-3xl">
<i class='bx bx-check'></i>
</button>
<button type="button" class="rounded bg-red-500 hover:bg-red-600 text-white w-10 h-10 text-3xl"
#click="open = false">
<i class='bx bx-x'></i>
</button>
</div>
</div>
</div>
</main>
);
}
export default App;
The code of the full project is there : My project
But it does not work ...
Could you help me please ?
Thank you very much !
It is not working, because this is not a React code. You would need to change few things in there.
You need use useState to keep track of open state
const [open, setOpen] = useState(false);
To handle click events on button you should use onClick instead of #click
<button onClick={() => setOpen(true)}>
Edit
</button>
Change places where you are defining classes for HTML elements. In react you should use className keyword for that.
<div className="ml-2">Hafiz Haziq</div>
You can also remove x-data and x-show attributes
<div x-show="!open" class="flex justify-between items-center">

TypeError: items.map is not a function

My code problem is that I want to create a token from the backend and add it to my item. Now the page is crashing due to mapping the data.
<div className='bg-gray-100'>
<SimpleHeader/>
<div className='flex justify-center'>
<h2 className='text-center text-4xl py-5 inline-block border-b-4 border-blue-400 font-bold mb-4'>My Items</h2>
</div>
<Link to='/addItems' className='flex justify-center'>
<button className='px-2 py-1 bg-transparent rounded border-2 border-blue-500 hover:bg-blue-500 hover:text-white duration-200 hover:scale-105'>Add New Item</button>
</Link>
<div className='container md:grid grid-cols-3 gap-4 w-full mx-auto p-12'>
{
items?.map(item=><MyItem key={item._id} item={item} handleDelete={handleDelete}></MyItem>)
}
</div>
</div>
try to change it this way
<div className='bg-gray-100'>
<SimpleHeader/>
<div className='flex justify-center'>
<h2 className='text-center text-4xl py-5 inline-block border-b-4 border-blue-400 font-bold mb-4'>My Items</h2>
</div>
<Link to='/addItems' className='flex justify-center'>
<button className='px-2 py-1 bg-transparent rounded border-2 border-blue-500 hover:bg-blue-500 hover:text-white duration-200 hover:scale-105'>Add New Item</button>
</Link>
<div className='container md:grid grid-cols-3 gap-4 w-full mx-auto p-12'>
{
items && items.map(item=><MyItem key={item._id} item={item} handleDelete={handleDelete}></MyItem>)
}
</div>
</div>

How do i place the video inside of the React component?

So i have built a react component, and there's supposed to be a video background as a cover, but I just cant seem to make it work.
I just puts the video outside of the component. Can anyone help me with this please. Also I'm using Tailwind.
import React from "react";
export default function Example() {
return (
<div className="items-start flex flex-col p-2 h-96 w-fit ">
<div>
<video autoPlay loop muted>
<source src="Assets/img/video/test.mp4" type="video/mp4" />
</video>
<div className="items-center flex ml-2 mt-2">
<div className="flex-shrink-0 group block">
<div className="flex items-center">
<div>
<img
className="inline-block h-9 w-9 rounded-full"
src="https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80"
alt=""
/>
</div>
<div className="ml-3">
<p className="text-sm font-medium text-white">Sermad Alladin</p>
<p className="text-sm font-medium text-gray-50">
Elgiganten • 18 t.
</p>
</div>
</div>
</div>
</div>
<div className="items-end self-end flex mt-64">
<div className="flex">
<p className="font-normal h-12 leading-5 w-40 mr-2">
Amazing customer service, but i wish was better...😉
</p>
</div>
<div className="items-center flex h-7 justify-end mb-1 p-2 bg-primary rounded-tl-xl rounded-bl-xl">
<div className="font-bold mx-2 text-white">87</div>
</div>
</div>
</div>
</div>
);
}

Make a smoothly opening menu effect using Tailwind CSS and React JS

I want to transform the menu to have a smooth transition when it opens, but it's not working for me.
I've also tried using hidden class, but ran into the same problem.
Is there a way to make it open smoothly?
My attempt:
import React from "react";
export default function ModerSideMenu({}) {
const [menu, setMenu] = React.useState({
home: true,
});
return (
<div className="w-64 bg-blue-900 h-full p-4 text-white">
<div className="relative">
<div className="flex flex-row items-center justify-between uppercase font-semibold w-full">
<div className="ml-2 flex-row flex items-center space-x-2">
<i className="fas fa-home" />
<p className="">Home</p>
</div>
<i
className={`transform transition-all ease-out duration-300 select-none fas ${
menu.home ? "fa-angle-up" : "fa-angle-down"
} mr-2`}
onClick={() => setMenu({ ...menu, home: !menu.home })}
/>
</div>
<div
className={`ml-4 mt-2 space-y-1 text-sm transform transition-all ease-out duration-300 z-20 select-none ${
!menu.home ? "-translate-y-full" : "translate-y-0"
}`}
hidden={!menu.home}
>
<p>- Home 1</p>
<p>- Home 2</p>
</div>
</div>
<div className="relative mt-2">
<div className="flex flex-row items-center justify-between uppercase font-semibold w-full">
<div className="ml-2 flex-row flex items-center space-x-2">
<i className="fas fa-home" />
<p className="">Home 2</p>
</div>
<i className="justify-self-end fas fa-angle-down mr-2" />
</div>
<div className="ml-4 mt-2 space-y-1 text-sm">
<p>- Home 3</p>
<p>- Home 4</p>
</div>
</div>
</div>
);
}

tailwind css sidebar is not fixed

I want to know how to make this sidebar fixed but I don't want to make the navbar and the content below it fixed.
And how I make this responsive means I want to add a hamburger icon to make it responsive on mobile screen devices.
Please help me.
I removed all the SVG icons due to the word limit.
This is the whole code.
// library components
import React from 'react'
import { Link, NavLink } from 'react-router-dom'
const Sidebar = () => {
return (
<div className="relative flex flex-no-wrap">
{/* Sidebar starts */}
{/* Remove class [ hidden ] and replace [ sm:block ] with [ block ] */}
<div className="w-64 absolute sm:relative bg-gray-800 shadow md:h-screen flex-col justify-between hidden sm:flex pb-12">
<div className="px-8">
<div className="h-16 w-full flex items-center">
<h1>Brand Name</h1>
</div>
<ul className="mt-12">
<li className="flex w-full justify-between text-gray-300 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Dashboard</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Products</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Deliverables</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Invoices</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Inventory</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">Settings</span>
</div>
</li>
</ul>
</div>
</div>
{/*Mobile responsive sidebar*/}
<div className="w-64 z-20 absolute bg-gray-800 shadow md:h-full flex-col justify-between sm:hidden pb-12 transition duration-150 ease-in-out" id="mobile-nav">
<div className="h-10 w-10 bg-gray-800 absolute right-0 mt-16 -mr-10 flex items-center shadow rounded-tr rounded-br justify-center cursor-pointer" id="mobile-toggler" onclick="sidebarHandler()">
</div>
<div className="px-8">
<div className="h-16 w-full flex items-center">
</div>
<ul className="mt-12">
<li className="flex w-full justify-between text-gray-300 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Dashboard</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Products</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Performance</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Deliverables</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Invoices</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center mb-6">
<div className="flex items-center">
<span className="text-sm ml-2">Inventory</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-gray-500 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">Settings</span>
</div>
</li>
</ul>
</div>
</div>
{/* Sidebar ends */}
<div className="w-full">
{/* Navigation starts */}
<nav className="h-16 flex items-center lg:items-stretch justify-end lg:justify-between bg-white shadow relative z-10">
<div className="hidden lg:flex w-full pr-6">
<div className="w-1/2 h-full hidden lg:flex items-center pl-6 pr-24">
<div className="relative w-full">
<div className="text-gray-500 absolute ml-4 inset-0 m-auto w-4 h-4">
</div>
<input className="border border-gray-100 focus:outline-none focus:border-indigo-700 rounded w-full text-sm text-gray-500 bg-gray-100 pl-12 py-2" type="text" placeholder="Search" />
</div>
</div>
<div className="w-1/2 hidden lg:flex">
<div className="w-full flex items-center pl-8 justify-end">
<div className="h-full w-20 flex items-center justify-center border-r border-l">
<div className="relative cursor-pointer text-gray-600">
<div className="w-2 h-2 rounded-full bg-red-400 border border-white absolute inset-0 mt-1 mr-1 m-auto" />
</div>
</div>
<div className="h-full w-20 flex items-center justify-center border-r mr-4 cursor-pointer text-gray-600">
</div>
<div className="flex items-center relative cursor-pointer" onclick="dropdownHandler(this)">
<div className="rounded-full">
<ul className="p-2 w-full border-r bg-white absolute rounded left-0 shadow mt-12 sm:mt-16 hidden">
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">My Profile</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center mt-2">
<div className="flex items-center">
<span className="text-sm ml-2">Sign out</span>
</div>
</li>
</ul>
<div className="relative">
<img className="rounded-full h-10 w-10 object-cover" src="https://tuk-cdn.s3.amazonaws.com/assets/components/sidebar_layout/sl_1.png" alt="avatar" />
<div className="w-2 h-2 rounded-full bg-green-400 border border-white absolute inset-0 mb-0 mr-0 m-auto" />
</div>
</div>
<p className="text-gray-800 text-sm mx-3">Jane Doe</p>
<div className="cursor-pointer text-gray-600">
</div>
</div>
</div>
</div>
</div>
<div className="text-gray-600 mr-8 visible lg:hidden relative" onclick="dropdownHandler(this)">
<ul className="p-2 w-40 border-r bg-white absolute rounded right-0 shadow mt-12 hidden">
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center">
<div className="flex items-center">
<span className="text-sm ml-2">My Profile</span>
</div>
</li>
<li className="flex w-full justify-between text-gray-600 hover:text-indigo-700 cursor-pointer items-center mt-2">
<div className="flex items-center">
<span className="text-sm ml-2">Sign out</span>
</div>
</li>
</ul>
</div>
</nav>
{/* Navigation ends */}
{/* Remove class [ h-64 ] when adding a card block */}
<div className="container mx-auto py-10 h-64 md:w-4/5 w-11/12 px-6">
{/* Remove class [ border-dashed border-2 border-gray-300 ] to remove dotted border */}
<div className="w-full h-full rounded border-dashed border-2 border-gray-300">{/* Place your content here */}</div>
</div>
</div>
</div>
);
}
export default Sidebar

Resources