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

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>
);
}

Related

Responsive Media React Tailwind

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

User Image "Display Url" not showing properly at UI when I using firebase for authentication

Note: email-password-based login working properly only happened when login using google.
<li onClick={() => setShow(!show)} className="nav-item cursor-pointer relative">
<div className="flex items-center gap-3">
<img className="w-14 h-14 rounded-full border p-1" src={user?.photoURL} alt="" />
</div>
{show && (
<ul className="absolute top-[70px] left-0 sm:left-auto sm:right-0">
<div className="rounded shadow bg-white " data-bs-popper="none">
<div className="w-[240px] p-5">
<div className="pb-0">
<div className="flex py-1 items-center gap-2">
<img className="rounded-full w-10 h-10" src={loading ? "Loading" : user?.photoURL} alt="profile" />
<div className="flex-fill ms-3 ">
<h4 className="font-bold">{loading ? "Loading" : user?.displayName}</h4>
<small className="">{user?.email}</small>
</div>
</div>
<div>
<div className="border-b-2 my-3" /></div>
</div>
<div className="list-group m-2 flex flex-col gap-3">
<Link to="/my-profile" className="text-lg">
<FontAwesomeIcon className="mr-3" icon={faUser} /> Profile Page
</Link>
<Link to="/my-inventories" className="text-lg">
<FontAwesomeIcon className="mr-3" icon={faFileInvoice} /> My Inventories
</Link>
<Link onClick={() => signOut(auth)} to="/login" className="text-lg">
<FontAwesomeIcon className="mr-3" icon={faSignOut} /> Sign Out
</Link>
</div>
</div>
</div>
</ul>
)}
</li>
see what what happened on UI
Even img get the google user image.
I'm approx. a month late but I think I found the answer
I thinks it's related to the reference policy of the image.
So add referrerpolicy="no-referrer" inside the image.
Hope this fixes your problem.

Tailwind transition max-height-fit won't work as intended

I found a great accordion solution on the internet and wanted to try it. The difference between the example and my code is I used max-height-fit instead of max-height-20.
Here is my code:
<div className="relative overflow-hidden">
<input
type="checkbox"
className="peer absolute top-0 inset-x-0 w-full h-12 opacity-0 z-10 cursor-pointer"
/>
<div className="bg-gray-500 h-12 w-full pl-5 flex items-center">
<h1 className="text-lg font-semibold text-white">Offline</h1>
</div>
<div className="absolute top-3 right-3 text-white transition-trasnform duration-500 rotate-0 peer-checked:rotate-180">
<FontAwesomeIcon icon={faChevronDown} />
</div>
<div className="overflow-auto transition-all duration-500 max-h-0 peer-checked:max-h-fit">
{players
.filter((p: any) => p.name.toLowerCase().includes(search))
.map((player: any) => {
return (
<div className="flex py-4 border-b-2 border-gray-700 hover:bg-gray-800/90 last:border-b-0">
<div className="ml-5 -mt-1 bg-gray-700 w-8 h-8 text-center leading-8 rounded-full">
{player.ID}
</div>
<div className="ml-5 flex grow">
<div className="w-full">
{player.name} ({player.level})
</div>
<div>
{player.isAdmin && (
<FontAwesomeIcon className="mr-5" icon={faCrown} />
)}
</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>
);
}

Single Product View Modal Not Working on React Typescript Project

I am trying to display single product data by fetching it from the server, but there's an issue while opening the modal. If I map, I get a double modal and a blank black screen. How do I get a single product view?
import React, { useState } from "react";
// Import Swiper React components
import { Swiper, SwiperSlide } from "swiper/react";
import { FreeMode, Navigation, Thumbs } from "swiper";
// Import Swiper styles
import "swiper/css";
import "swiper/css/free-mode";
import "swiper/css/navigation";
import "swiper/css/thumbs";
import { Link } from 'react-router-dom';
import { Rating } from "#mui/material";
const ProductView = ({product}) => {
const { title, hoverImg, img, price, rating,vendorName, salePrice } = product;
const [thumbsSwiper, setThumbsSwiper] = useState(null);
return (
<div style={{backgroundColor:'white',width:'800px',height:'600px',overflow:'scroll'}} className='mx-auto container place-content-center px-12 py-8 justify-center items-center grid lg:grid-cols-2 md:grid-cols-2 grid-cols-1 gap-6 sm:flex-1'>
<div>
<Swiper
style={{
"--swiper-navigation-color": "#fff",
"--swiper-pagination-color": "#fff",
}}
spaceBetween={10}
// navigation={true}
thumbs={{ swiper: thumbsSwiper }}
modules={[FreeMode, Navigation, Thumbs]}
className="mySwiper2"
>
<SwiperSlide>
<img alt="" src={img} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={hoverImg} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={img} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={hoverImg} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={img} />
</SwiperSlide>
</Swiper>
<Swiper
onSwiper={setThumbsSwiper}
spaceBetween={10}
slidesPerView={4}
freeMode={true}
watchSlidesProgress={true}
modules={[FreeMode, Navigation, Thumbs]}
className="mySwiper"
>
<SwiperSlide>
<img alt="" src={img} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={hoverImg} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={img} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={hoverImg} />
</SwiperSlide>
<SwiperSlide>
<img alt="" src={img} />
</SwiperSlide>
</Swiper>
</div>
<div>
<h2 className='text-3xl mb-2 font-medium'>{title}</h2>
<div className='flex items-center mb-4'>
<div>
<Rating name="half-rating-read" defaultValue={rating} precision={0.5} readOnly />
</div>
<div className="text-xs text-gray-500 ml-3">
(1 Reviews)
</div>
</div>
<div className='space-y-2'>
<p className="p text-gray-800 font-semibold space-x-2">
<span>Availability:</span>
<span className='text-green-600'>In stock</span>
</p>
<p className="space-x-2">
<span className='text-gray-800 font-semibold'>Vendor:</span>
<span className='text-gray-600'>{vendorName}</span>
</p>
<p className="space-x-2">
<span className='text-gray-800 font-semibold'>Category:</span>
<span className='text-gray-600'>Men</span>
</p>
<p className="space-x-2">
<span className='text-gray-800 font-semibold'>SKU:</span>
{/* <span className='text-gray-600 uppercase'>{_id.slice(4,12)}</span> */}
</p>
</div>
<div className="flex items-baseline mb-1 mt-2 space-x-2">
<p className="text-xl text-indigo-500 font-semibold">{salePrice}</p>
<p className="text-sm text-gray-400 line-through">{price}</p>
</div>
<div className="">
<h3 className="text-xl text-gray-800 mb-3 uppercase font-medium ">Color</h3>
<div className="flex gap-2">
{/* Single Color Starts */}
<div className="color-selctor">
<input type="radio" name='color' className='hidden' color='red' id='color-red' />
<label htmlFor="color" className='border border-gray-200 rounded-sm h-5 w-5 cursor-pointer shadow-sm block' style={{ backgroundColor: "red" }}></label>
</div>
<div className="color-selctor">
<input type="radio" name='color' className='hidden' color='red' id='color-red' />
<label htmlFor="color" className='border border-gray-200 rounded-sm h-5 w-5 cursor-pointer shadow-sm block' style={{ backgroundColor: "green" }}></label>
</div>
<div className="color-selctor">
<input type="radio" name='color' className='hidden' color='red' id='color-red' />
<label htmlFor="color" className='border border-gray-200 rounded-sm h-5 w-5 cursor-pointer shadow-sm block' style={{ backgroundColor: "blue" }}></label>
</div>
</div>
</div>
<div className="pt-4 block">
<h3 className="text-xl text-gray-800 mb-3 uppercase font-medium">Size</h3>
<div className="flex item-center gap-2">
{/* single size selector starts */}
<div className="size-selector">
<input type="radio" name='size' className='hidden' id='xs' />
<label htmlFor="size-xs" className='text-xs border border-gray-200 rounded-sm h-6 w-6 flex items-center justify-center cursor-pointer shadow-sm text-gray-600'>
S
</label>
</div>
<div className="size-selector">
<input type="radio" name='size' className='hidden' id='xs' />
<label htmlFor="size-xs" className='text-xs border border-gray-200 rounded-sm h-6 w-6 flex items-center justify-center cursor-pointer shadow-sm text-gray-600'>
M
</label>
</div>
<div className="size-selector">
<input type="radio" name='size' className='hidden' id='xs' />
<label htmlFor="size-xs" className='text-xs border border-gray-200 rounded-sm h-6 w-6 flex items-center justify-center cursor-pointer shadow-sm text-gray-600'>
L
</label>
</div>
<div className="size-selector">
<input type="radio" name='size' className='hidden' id='xs' />
<label htmlFor="size-xs" className='text-xs border border-gray-200 rounded-sm h-6 w-6 flex items-center justify-center cursor-pointer shadow-sm text-gray-600'>
XS
</label>
</div>
</div>
</div>
<div>
<h3 className='text-xl text-gray-800 mb-1'>Quantity</h3>
<div className="flex border border-gray-500 divide-gray-500 text-gray-600 divide-x w-max">
<div className='h-8 w-8 flex items-center justify-center cursor-pointer select-none'>
-
</div>
<div className='h-8 w-8 flex items-center justify-center'>
<input style={{width:'34px',height:'34px'}} type="text" />
</div>
<div className='h-8 w-8 flex items-center justify-center cursor-pointer select-none'>
+
</div>
</div>
</div>
<div className="flex gap-3 border-b border-gray-200 pb-5 mt-6">
<Link to = "/">
<button className='text-center top-5 text-white p-2 bg-indigo-500 border border-indigo-500 hover:bg-transparent hover:text-indigo-500 transition'>
<i className="fa-regular fa-bag-shopping"></i> Add to cart
</button>
</Link>
<Link to = "/">
<button className='text-center top-5 hover:text-white p-2 hover:bg-indigo-500 border border-indigo-500 bg-transparent text-indigo-500 transition'>
<i className="fa-regular fa-heart"></i> Add to Wishlist
</button>
</Link>
</div>
</div>
</div>
);
};
export default ProductView;

Resources