I am trying to hide an Event div when there is no event date showing
Here is how my project look like:
and here is how it appear when there is no event on that day:
Here is my following component code:
<div className="event-list-item-content">
<div className="header">
<span className="announcements">Events</span>
<button className="plus">
<ControlPoint />
</button>
</div>
{teamData.Events.map((event, index) => (
<div key={index} className="list-events-description">
{moment(event.date).format("YYYY-MM-DD") ===
moment(date).format("YYYY-MM-DD") && (
<div className="content">
{event.description}
<span>
{moment(event.timestart, "HH:mm:ss").format("h:mm A")}
<svg
width="8"
height="12"
viewBox="0 0 8 12"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M0.589844 1.41L5.16984 6L0.589843 10.59L1.99984 12L7.99984 6L1.99984 6.16331e-08L0.589844 1.41Z"
fill="#00A682"
/>
</svg>
</span>
<hr />
</div>
)}
</div>
))}
</div>
How can I hide this element ?
You need to check whether teamData.Events is empty. If it is not, then display. Otherwise, it will not be shown.
<div className='event-list-item-content'>
{teamData.Events.length !== 0 && (
<div className='header'>
<span className='announcements'>Events</span>
<button className='plus'>
<ControlPoint />
</button>
</div>
)}
{teamData.Events.map((event, index) => (
<div key={index} className='list-events-description'>
{moment(event.date).format('YYYY-MM-DD') === moment(date).format('YYYY-MM-DD') && (
<div className='content'>
{event.description}
<span>
{moment(event.timestart, 'HH:mm:ss').format('h:mm A')}
<svg width='8' height='12' viewBox='0 0 8 12' fill='none' xmlns='http://www.w3.org/2000/svg'>
<path d='M0.589844 1.41L5.16984 6L0.589843 10.59L1.99984 12L7.99984 6L1.99984 6.16331e-08L0.589844 1.41Z' fill='#00A682' />
</svg>
</span>
<hr />
</div>
)}
</div>
))}
</div>
Related
I am trying to make an web app and using react swiper fot it, but it is causing hydration. When I comment out the react swiper then I don't see the error.
I am getting "Warning: Text content did not match. Server: "Zach N." Client: "Lisa A." in the console.
Can someone help me to fix it????
Why am I getting this error and how to solve it?
thanks in advance.
// Slider
import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css";
import AOS from "aos";
import "aos/dist/aos.css"; // You can also use <link> for styles
function Testimonials() {
const sliderRef = useRef(null);
useEffect(() => {
AOS.init({
duration: 1500,
});
});
const handlePrev = useCallback(() => {
if (!sliderRef.current) return;
sliderRef.current.swiper.slidePrev();
}, []);
const handleNext = useCallback(() => {
if (!sliderRef.current) return;
sliderRef.current.swiper.slideNext();
}, []);
return (
<div>
<div className="lg:h-[80vh] lg:pt-16 ">
<div data-aos="fade-up">
<h2 className="text-[40px] xl:text-[70px] leading-[44px] lx:leading-[70px] mt-[70px] mb-[15px] md:mb-[19px] font-bold font-FreightSemibold ">
Today's news.Edited to be{" "}
<span className="italic block xl:mt-7">
unbiased as humanly possible.
</span>
</h2>
</div>
<div data-aos="fade-up" className="flex lg:justify-between">
<div className="w-[600px]">
<p className="xl:text-[20px]">
Every morning, we triple check headlines, stories and sources for
bias. All by hand, no algorithms.{" "}
<span className="font-bold">See what readers are saying:</span>
</p>
</div>
<div className="hidden md:flex ">
<div
onClick={handlePrev}
className="w-[55.84px] h-[55.84px] group rounded-full flex cursor-pointer hover:bg-black md:mx-[18px] justify-center items-center ring-1 ring-black "
>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6 group-hover:text-white"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M7 16l-4-4m0 0l4-4m-4 4h18"
/>
</svg>
</div>
<div
onClick={handleNext}
className="w-[55.84px] h-[55.84px] group rounded-full flex cursor-pointer justify-center items-center hover:bg-black ring-1 ring-black "
>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6 group-hover:text-white"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M17 8l4 4m0 0l-4 4m4-4H3"
/>
</svg>
</div>
</div>
</div>
{/* Slider Here */}
<div className="md:flex">
<Swiper
ref={sliderRef}
loop={true}
pagination={{ clickable: true }}
slidesPerView={1}
spaceBetween={10}
breakpoints={{
"#0.00": {
slidesPerView: 1,
spaceBetween: 10,
},
"#0.75": {
slidesPerView: 2,
spaceBetween: 20,
},
"#1.00": {
slidesPerView: 3,
spaceBetween: 40,
},
"#1.50": {
slidesPerView: 4,
spaceBetween: 50,
},
}}
>
<SwiperSlide>
<div data-aos="fade-left" className="mt-[80px] md:mx-5 mb-[45px]">
<div className="border-black mb-[40px] border-b-[1px] ">
<h3 className="font-bold py-1">Lisa A.</h3>
</div>
<div className="mb-[40px]">
<p>
“I consider myself a centrist - all the other news sources
lean so far to the left or right, it makes my head spin.
Thank you for{" "}
<span className={`bg-[#6fef8d]`}>
providing strictly the facts
</span>{" "}
- you re the only news source that can actually pull off
neutrality these days.”
</p>
</div>
</div>
</SwiperSlide>
<SwiperSlide>
<div data-aos="fade-left" className="mt-[80px] md:mx-2 mb-[45px]">
<div className="border-black mb-[40px] border-b-[1px] ">
<h3 className="font-bold py-1">Emma S.</h3>
</div>
<div className="mb-[40px]">
<p>
“I consider myself a centrist - all the other news sources
lean so far to the left or right, it makes my head spin.
Thank you for{" "}
<span className={`bg-[#EFEF6F]`}>
providing strictly the facts
</span>{" "}
- you re the only news source that can actually pull off
neutrality these days.”
</p>
</div>
</div>
</SwiperSlide>
<SwiperSlide>
<div data-aos="fade-left" className="mt-[80px] md:mx-5 mb-[45px]">
<div className="border-black mb-[40px] border-b-[1px] ">
<h3 className="font-bold py-1">Jim M.</h3>
</div>
<div className="mb-[40px]">
<p>
“I stopped watching the news, so sick of the bias. Was
searching for an alternative that would just tell me WHAT
happened, with NO editorializing. I found it. It s called
1440. It assumes you are smart enough to{" "}
<span className={`bg-[#7EDCF2]`}>
form your own opinions.
</span>
</p>
</div>
</div>
</SwiperSlide>
<SwiperSlide>
<div data-aos="fade-left" className="mt-[80px] md:mx-5 mb-[45px]">
<div className="border-black mb-[40px] border-b-[1px] ">
<h3 className="font-bold py-1">Zach N.</h3>
</div>
<div className="mb-[40px]">
<p className="">
“I stopped my habit of spending my day doomscrolling. I
signed up for 1440 &{" "}
<span className={`bg-[#F48CD9]`}>
{" "}
feel better informed in less time.
</span>{" "}
I m also less stressed out. Thank you.
</p>
</div>
</div>
</SwiperSlide>
</Swiper>
</div>
</div>
</div>
);
}
export default Testimonials;
Replace slidesPerView={1} by slidesPerView="auto"
Also update your AOS init like this to avoid infinite loop
useEffect(() => {
AOS.init({
duration: 1500,
});
},[]);
I am having trouble positioning background color gray content to right side of my website. Any suggestions?
export function ContentImage(props: ImageProps): ReactElement | null {
const cn = classNames(
'relative sm:py-16 lg:py-0 m-0 right-0',
props.position === 'left' ? 'order-first' : 'order-first sm:order-last',
);
const backgroundCn = classNames(
'absolute inset-y-0 w-full bg-gray-50 rounded-r-3xl lg:right-72',
props.position === 'left' ? 'right-1/2' : 'left-3/4',
props.position === 'right' ? 'rounded-l-3xl' : 'rounded-r-3xl',
);
return (
<>
<div className={cn}>
<div
aria-hidden="true"
className="hidden overflow-hidden sm:block lg:absolute lg:inset-y-0 lg:right-0 lg:w-screen">
<div className={backgroundCn}/>
<svg
className="absolute top-8 left-1/2 -ml-3 lg:-right-8 lg:left-auto lg:top-12"
width={404}
height={392}
fill="none"
viewBox="0 0 404 392">
<defs>
<pattern
id="02f20b47-fd69-4224-a62a-4c9de5c763f7"
x={0}
y={0}
width={20}
height={20}
patternUnits="userSpaceOnUse">
<rect
x={0}
y={0}
width={4}
height={4}
className="text-gray-200"
fill="currentColor"
/>
</pattern>
</defs>
<rect
width={404}
height={392}
fill="url(#02f20b47-fd69-4224-a62a-4c9de5c763f7)"
/>
</svg>
</div>
<div className="relative order-last mx-auto max-w-md px-4 sm:max-w-3xl sm:px-6 lg:max-w-none lg:px-0 lg:py-20">
<div className="relative overflow-hidden pt-64 pb-10">
<div className="absolute inset-0 h-full w-full">
<Image
src={props.image}
alt={props.imageAlt}
objectFit="cover"
layout="fill"
className={props.className}
/>
</div>
</div>
</div>
</div>
</>
);
}
I dont want the folders not to take the extra height.
The folder object destructered here:
<div className='grid grid-cols-3 gap-4'>
{folders &&
folders.map((folder, index) => (
<Folder folder={folder} index={index} key={index} />
))}
</div>
The Folder.jsx
as you can see it is takig the extra height.
<div
className="border-2 border-gray-400 rounded-lg max-w-xs"
key={index}
>
<div className="flex my-2 mx-1 justify-between">
<p>{folder.name}</p>
<div>
<AddLink folderName={folder.name} />
<button onClick={() => deleteFolder(folder.name)}>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"
/>
</svg>
</button>
</div>
</div>
<p className="flex sm:text-xs justify-end">{folder.date}</p>
my problem is center elements with Tailwind Grid.
GroupTooltipIcon1/GroupTooltipIcon2 are component that contain an svg.
I have to be able to center the svg component within this grid tailwind, can you help me?
<div className="mt-[75px] grid grid-cols-2 gap-2 justify-items-center">
<div>
<div className="iconInsideTooltip">
<GroupTooltipIcon1 width="48px" height="48px" />
</div>
<TextSection
p5={
<>
<div>
Testo 1
</div>
</>
}
/>
</div>
</div>
const GroupTooltipIcon1 = ({
width = "48",
height = "48",
classes = "stroke-white",
}) => {
return (
<svg
className={classes}
style={{ width, height }}
viewBox={`0 0 48 48`}
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g clip-path="url(#clip0_206_1350)">
<path d="M31.6027 22.5623L34.1509 20.0644C38.9389 22.0715 42.8398 19.6492 42.8398 19.6492C48.6345 14.1502 46.9798 6.58116 46.9798 6.58116L40.1784 13.3197C40.1784 13.3197 37.9889 13.3197 36.2775 11.8977C34.8555 10.1801 34.8555 7.99681 34.8555 7.99681L41.6003 1.20169C41.6003 1.20169 34.0313 -0.453049 28.5323 5.34168C28.5323 5.34168 26.11 9.24259 28.117 14.0306L23.373 18.869"
stroke="white"
strokeLinecap="round"
strokeLinejoin="round"/>
</g>
<defs>
<clipPath id="clip0_206_1350">
<rect width="48" height="48" fill="white"/>
</clipPath>
</defs>
</svg>
);
};
export default React.memo(GroupTooltipIcon1);
I have to be able to center the svg component within this grid tailwind, can you help me?
Thank you for help
I found a solution by doing it this way. I hope it will be useful to someone
<div className="mt-[75px] grid grid-cols-2 gap-2 items-start">
<div>
<div className="iconInsideTooltip flex justify-center">
<GroupTooltipIcon1 width="48px" height="48px" />
</div>
<TextSection
customClasses={{ "text-center p-5": "p5" }}
p5={
<>
<div>
Testo 1
</div>
</>
}
/>
</div>
</div>
How can I create dropdown animation when I click to 3 dots and if I click one more time it will toggle the dropdown.
Here is my following code:
const [modalStatus, setModalStatus] = useState(false);
const openModal = () => {
setModalStatus(true);
};
<div className="member-edit" onClick={openModal}>
<Symlink />
</div>
{modalStatus && <TeamStatusModal />}
<div
className="member-avatar"
style={{
backgroundImage: `url(${member.User.picture})`,
}}
/>
<div className="member-description">
<p className="member-name">{member.User.fullname}</p>
<p className="member-date">
Joined on {moment(member.date_joined).format("MMMM Do, YYYY")}
</p>
</div>
Updated add TeamStatusModal.js:
const TeamStatusModal = () => {
return (
<div className="team-status-modal-container">
<div className="status">
<ProfileIcon /> <span>View Profile</span>
<hr />
</div>
<div className="status">
<MessageIcon /> <span>Message Me</span>
<hr />
</div>
<div className="status">
<ReviewIcon /> <span>Leave Review</span>
</div>
</div>
);
};
You should reorganize the logic a bit. Intead of: {modalStatus && <TeamStatusModal />} you can pass the state as a prop like this:
<TeamStatusModal active={modalStatus} />
and then you will use it in the TeamStatusModal component:
const TeamStatusModal = ({ active }) => {
return (
<div className={`team-status-modal-container ${active ? 'ACTIVE_CLASS' : ''}`}>
<div className="status">
<ProfileIcon /> <span>View Profile</span>
<hr />
</div>
<div className="status">
<MessageIcon /> <span>Message Me</span>
<hr />
</div>
<div className="status">
<ReviewIcon /> <span>Leave Review</span>
</div>
</div>
);
};
Another approach is using e.g. Framer Motion library, which allows animate removing elements from DOM.
https://www.framer.com/api/motion/animate-shared-layout/#syncing-layout-animations