All components

Image Tab2

Image Tab2 is a React and Tailwind CSS navigation component from UI Layouts, licensed MIT. Copy it and paste it into your project.

UI Layouts MIT navigation

What it is

Image Tab2 is a React and Tailwind CSS navigation component from UI Layouts, licensed MIT. Copy it and paste it into your project.

How to use it

Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.

Open in the catalogue

Five free copies a month. No card.

No packages beyond the project baseline

Licence

This component comes from UI Layouts and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.

Image Tab2

./components/ui/image-tabs.tsx
'use client';
import { useMediaQuery } from '@/hooks/use-media-query';
import { cn } from '@/lib/utils';
import { AnimatePresence, motion } from 'motion/react';
import React, { createContext, type ReactNode, useContext, useState } from 'react';

interface Tab {
  id: string;
  title: string;
  description: string;
  imageUrl: string;
}

interface TabsContextType {
  activeTab: string;
  setActiveTab: (id: string) => void;
  isDesktop: boolean;
}

const TabsContext = createContext<TabsContextType | undefined>(undefined);

const useTabs = () => {
  const context = useContext(TabsContext);
  if (!context) {
    throw new Error('Tabs components must be used within a TabsProvider');
  }
  return context;
};

export function TabsProvider({
  children,
  defaultValue,
  className,
}: {
  children: ReactNode;
  defaultValue: string;
  className?: string;
}) {
  const [activeTab, setActiveTab] = useState(defaultValue);
  const isDesktop = useMediaQuery('(min-width: 768px)');
  return (
    <TabsContext.Provider value={{ activeTab, setActiveTab, isDesktop }}>
      <div className={cn('w-full h-full', className)}>{children}</div>
    </TabsContext.Provider>
  );
}

export function TabList({ children, className }: { children: ReactNode; className?: string }) {
  return <div className={cn('rounded-xs h-fit', className)}>{children}</div>;
}

export function TabItem({ children, value }: { children: ReactNode; value: string }) {
  const { activeTab, setActiveTab } = useTabs();

  return (
    <motion.div
      className={`rounded-lg overflow-hidden mb-2 md:text-base text-sm ${
        activeTab === value
          ? 'active border-2 dark:border-[#656fe2] border-[#F2F2F2] dark:bg-[#E0ECFB] bg-[#F2F2F2]'
          : 'bg-transparent border-2 dark:hover:border-[#656fe2]'
      }`}
      onClick={() => setActiveTab(value)}
    >
      {children}
    </motion.div>
  );
}

export function TabHeader({ children, value }: { children: ReactNode; value: string }) {
  const { activeTab } = useTabs();
  return (
    <h3
      className={`p-4 md:text-base text-sm cursor-pointer transition-all font-semibold dark:text-white text-black dark:hover:bg-[#1e2a78] hover:bg-[#F2F2F2] dark:hover:text-white hover:text-black flex justify-between items-center ${
        activeTab === value ? 'active dark:bg-[#1e2a78] bg-[#F2F2F2]' : 'dark:bg-[#11112b] bg-white'
      }`}
    >
      {children}
    </h3>
  );
}

export function TabDes({ children, value }: { children: ReactNode; value: string }) {
  const { activeTab } = useTabs();
  return (
    <AnimatePresence mode='sync'>
      {activeTab === value && (
        <motion.div
          initial={{ height: 0, opacity: 0 }}
          animate={{ height: 'auto', opacity: 1 }}
          exit={{ height: 0, opacity: 0 }}
          transition={{
            duration: 0.3,
            ease: 'easeInOut',
            delay: 0.14,
          }}
        >
          {children}
        </motion.div>
      )}
    </AnimatePresence>
  );
}

export function TabImageContainer({
  children,
  className,
}: {
  children: ReactNode;
  className?: string;
}) {
  return (
    <div className={cn('', className)}>
      <AnimatePresence mode='popLayout'>{children}</AnimatePresence>
    </div>
  );
}

export function TabImage({ children, value }: { children: ReactNode; value: string }) {
  const { activeTab, isDesktop } = useTabs();

  if (activeTab !== value || !isDesktop) return null;

  return (
    <motion.div
      initial={{ opacity: 0, overflow: 'hidden' }}
      animate={{ opacity: 1, overflow: 'hidden' }}
      exit={{ opacity: 0, overflow: 'hidden' }}
      transition={{
        duration: 0.4,
        delay: 0.2,
      }}
      className='p-4 h-[400px] rounded-md overflow-hidden'
    >
      {children}
    </motion.div>
  );
}
./registry/components/tabs/img-tabs2.tsx
'use client';
import {
  TabDes,
  TabHeader,
  TabImage,
  TabImageContainer,
  TabItem,
  TabList,
  TabsProvider,
} from '@/components/ui/image-tabs';
import React, { useState } from 'react';

const tabs = [
  {
    title: 'How do UI components improve UX?',
    id: 'improve',
    description:
      'UI components can improve UX by providing familiar, consistent interactions that make it easy for users to navigate and interact with an application.',
    imageUrl:
      'https://images.unsplash.com/photo-1709949908058-a08659bfa922?q=80&w=1200&auto=format',
  },
  {
    title: 'Important of UI component.',
    id: 'important',
    description:
      'Some common challenges include maintaining consistency across different devices and screen sizes, ensuring compatibility with various browsers and assistive technologies, and balancing flexibility with ease of use.',
    imageUrl: 'https://images.unsplash.com/photo-1548192746-dd526f154ed9?q=80&w=1200&auto=format',
  },
  {
    title: 'Is UI and UX Same?',
    id: 'same',
    description:
      '     Developers can ensure the responsiveness of UI components by using techniques such as fluid layouts, flexible grids, and media queries to adapt the components to different screen sizes and orientations.',
    imageUrl:
      'https://images.unsplash.com/photo-1693581176773-a5f2362209e6?q=80&w=1200&auto=format',
  },
];
function ImageTabs2() {
  return (
    <>
      <div className=' w-full  h-full'>
        <TabsProvider
          defaultValue='improve'
          className='md:grid md:grid-cols-12 items-center justify-center'
        >
          <TabImageContainer className='md:col-span-7'>
            {tabs.map((tab, index) => (
              <TabImage key={tab.id} value={tab.id}>
                <img src={tab.imageUrl} alt={tab.title} className='w-full h-full rounded-md' />
              </TabImage>
            ))}
          </TabImageContainer>
          <TabList className='md:col-span-5 '>
            {tabs.map((tab, index) => (
              <TabItem key={tab.id} value={tab.id}>
                <TabHeader value={tab.id}>{tab.title}</TabHeader>
                <TabDes value={tab.id}>
                  <p className={`dark:bg-white bg-[#F2F2F2] text-black p-3`}>{tab.description}</p>

                  <img src={tab.imageUrl} alt={tab.title} className='md:hidden block rounded-md' />
                </TabDes>
              </TabItem>
            ))}
          </TabList>
        </TabsProvider>
      </div>
    </>
  );
}

export default ImageTabs2;

Similar components