Skip to content

aktonay/skillz / skills/design/react-bits

react-bits

Verified

Over 215+ animated, interactive, copy-paste React micro-components and effects (text animations, interactive backgrounds, physics cards, custom cursors, blobs, and dock bars).

FileKindSize
README.mdmarkdown11.8 KB
SKILL.mdskill md1.5 KB
package.jsonmanifest3.8 KB
src/App.jsxother3.4 KB
src/assets/common/code-options.webpbinary12.2 KB
src/assets/common/star.svgother775 B
src/assets/demo/cs1.webpbinary659.4 KB
src/assets/demo/cs2.webpbinary632.6 KB
src/assets/demo/cs3.webpbinary628.4 KB
src/assets/holo-card/maushold.webpbinary81.7 KB
src/assets/holo-card/mew.webpbinary94.1 KB
src/assets/holo-card/pikachu.webpbinary48.0 KB
src/assets/icons/antigravity.svgother439 B
src/assets/icons/claude.svgother2.5 KB
src/assets/icons/css.svgother1.8 KB
src/assets/icons/cursor.svgother320 B
src/assets/icons/js.svgother1019 B
src/assets/icons/jsrepo-outline.svgother2.9 KB
src/assets/icons/shadcn-outline.svgother476 B
src/assets/icons/ts.svgother1.8 KB
src/assets/icons/tw.svgother894 B
src/assets/icons/vscode.svgother1.2 KB
src/assets/lanyard/card-back.webpbinary9.4 KB
src/assets/lanyard/card-front.webpbinary145.2 KB
src/assets/lanyard/lanyard.pngbinary7.4 KB
src/assets/logos/apple.svgother655 B
src/assets/logos/openai.svgother1.5 KB
src/assets/logos/react-bits-logo-small-black.svgother3.8 KB
src/assets/logos/react-bits-logo-small.svgother3.9 KB
src/assets/logos/react-bits-logo.svgother12.3 KB
src/assets/logos/react-bits-pro-logo.svgother25.7 KB
src/assets/logos/react-bits-sticker.pngbinary73.6 KB
src/assets/logos/reactbits-gh-black.svgother12.2 KB
src/assets/logos/reactbits-gh-white.svgother12.2 KB
src/assets/logos/tesla.svgother546 B
src/assets/stickers/apple.webpbinary4.1 KB
src/assets/stickers/github.webpbinary8.0 KB
src/assets/stickers/openai.webpbinary11.2 KB
src/assets/stickers/tailwind.webpbinary4.3 KB
src/assets/stickers/vite.webpbinary30.4 KB
src/assets/svg/404.svgother774 B
src/assets/svg/landing-blur.svgother918 B
src/assets/svg/svg-corner.svgother200 B
src/components/code/CliInstallation.jsxother10.0 KB
src/components/code/CodeExample.jsxother6.5 KB
src/components/code/CodeHighlighter.jsxother3.2 KB
src/components/code/CodeOptions.jsxother4.3 KB
src/components/code/CodeSection.jsxother547 B
src/components/code/Dependencies.jsxother1.8 KB
src/components/code/IconSelect.jsxother4.5 KB
src/components/code/ShikiCode.jsxother994 B
src/components/common/AnnouncementBar/AnnouncementBar.cssother2.2 KB
src/components/common/AnnouncementBar/AnnouncementBar.jsxother1.5 KB
src/components/common/AnnouncementBar/index.jsscript45 B
src/components/common/AnnouncementModal/AnnouncementModal.cssother7.8 KB
src/components/common/AnnouncementModal/AnnouncementModal.jsxother7.4 KB
src/components/common/BackToTopButton.jsxother1.9 KB
src/components/common/BootReady.jsxother185 B
src/components/common/ComponentList.jsxother29.2 KB
src/components/common/ComponentPager.jsxother3.1 KB
src/components/common/ContributionSection.jsxother1.4 KB
src/components/common/CopyForAIMenu.jsxother3.0 KB
src/components/common/DocsOverview.jsxother1.2 KB
src/components/common/FluidMenuContent.jsxother3.8 KB
src/components/common/GitHub/ContributionSection.jsxother1.4 KB
src/components/common/Misc/Announcement.jsxother4.0 KB
src/components/common/Misc/SearchDialog.jsxother10.8 KB
src/components/common/Misc/SkeletonLoader.jsxother2.0 KB
src/components/common/NotFound/CategoryGallery.jsxother838 B
src/components/common/NotFound/FloatingShards.jsxother5.8 KB
src/components/common/NotFound/categoryPreviews.jsscript975 B
src/components/common/NotFound/galleryCanvas.jsscript13.1 KB
src/components/common/NotFound/glassGeometry.jsscript1.8 KB
src/components/common/NotFound/glassScene.jsscript19.1 KB
src/components/common/NotFound/shardGeometry.jsscript6.1 KB
src/components/common/NotFound/shardIntro.jsscript1.1 KB
src/components/common/NotFound/shardMotion.jsscript3.6 KB
src/components/common/Preview/BackgroundContent.cssother17.2 KB
src/components/common/Preview/BackgroundContent.jsxother7.3 KB
src/components/common/Preview/Customize.jsxother1.3 KB
src/components/common/Preview/CustomizeContext.jsscript134 B
src/components/common/Preview/OpenInStudioButton.jsxother75 B
src/components/common/Preview/PreviewColorList.jsxother1.9 KB
src/components/common/Preview/PreviewColorPicker.jsxother1.0 KB
src/components/common/Preview/PreviewColorPickerCustom.jsxother20.9 KB
src/components/common/Preview/PreviewInput.jsxother771 B
src/components/common/Preview/PreviewResizer.jsxother4.1 KB
src/components/common/Preview/PreviewSelect.jsxother4.1 KB
src/components/common/Preview/PreviewSlider.jsxother4.0 KB
src/components/common/Preview/PreviewSliderVertical.jsxother4.0 KB
src/components/common/Preview/PreviewStageContext.jsscript126 B
src/components/common/Preview/PreviewSwitch.jsxother999 B
src/components/common/Preview/PropTable.cssother4.6 KB
src/components/common/Preview/PropTable.jsxother2.4 KB
src/components/common/Preview/RefreshButton.jsxother709 B
src/components/common/Preview/ResetPropsButton.jsxother1.9 KB
src/components/common/Preview/colorMath.jsscript5.1 KB
src/components/common/Preview/demoModes.jsscript670 B
src/components/common/Preview/studio-url.jsscript720 B
src/components/common/Pro/CategoryProFooter.jsxother1.6 KB
src/components/common/Pro/ProComparison.cssother6.2 KB
src/components/common/Pro/ProComparison.jsxother5.6 KB
src/components/common/Pro/ProCta.jsxother1.8 KB
src/components/common/Pro/ProMedia.jsxother2.1 KB
src/components/common/Pro/ProPillars.jsxother1.9 KB
src/components/common/Pro/ProShowcase.jsxother4.7 KB
src/components/common/ProCard.jsxother2.3 KB
src/components/common/ProCardMobile.cssother2.9 KB
src/components/common/ProCardMobile.jsxother2.2 KB
src/components/common/SVGComponents.jsxother13.9 KB
src/components/common/SearchDialog.cssother7.5 KB
src/components/common/SearchDialog.jsxother12.7 KB
src/components/common/SimpleMarquee.jsxother6.0 KB
src/components/common/SkeletonLoader.jsxother2.9 KB
src/components/common/SponsorsCard.jsxother2.8 KB
src/components/common/SponsorsCircle.jsxother7.7 KB
src/components/common/TabsFooter.jsxother566 B
src/components/common/TabsLayout.jsxother20.1 KB
src/components/context/ActiveRouteContext/ActiveRouteContext.jsxother542 B
src/components/context/ComponentPropsContext.jsxother1.3 KB
src/components/context/InstallationContext/InstallationContext.jsxother1.1 KB
src/components/context/OptionsContext/OptionsContext.jsxother1.4 KB
src/components/context/OptionsContext/useOptions.jsscript158 B
src/components/context/SearchContext/SearchContext.jsxother1.3 KB
src/components/context/SearchContext/useSearch.jsscript154 B
src/components/context/TransitionContext/TransitionContext.jsxother2.0 KB
src/components/landingnew/CTA/CTA.cssother4.1 KB
src/components/landingnew/CTA/CTA.jsxother2.2 KB
src/components/landingnew/FAQ/FAQ.cssother1.3 KB
src/components/landingnew/FAQ/FAQ.jsxother5.9 KB
src/components/landingnew/Features/Features.cssother20.0 KB
src/components/landingnew/Features/Features.jsxother19.9 KB
src/components/landingnew/Footer/Footer.cssother4.8 KB
src/components/landingnew/Footer/Footer.jsxother3.1 KB
src/components/landingnew/Footer/FooterWaves.jsxother7.4 KB
src/components/landingnew/Hero/DotField.jsxother10.9 KB
src/components/landingnew/Hero/Hero.jsxother26.5 KB
src/components/landingnew/Hero/HeroBand.jsxother8.9 KB
src/components/landingnew/Hero/HeroChip.jsxother2.3 KB
src/components/landingnew/Hero/HeroFrame.cssother21.2 KB
src/components/landingnew/HowItWorks/HowItWorks.cssother5.3 KB
src/components/landingnew/HowItWorks/HowItWorks.jsxother4.6 KB
src/components/landingnew/LandingLoader/LandingLoader.cssother1.8 KB
src/components/landingnew/LandingLoader/LandingLoader.jsxother4.3 KB
src/components/landingnew/LiveDemo/LiveDemo.cssother3.7 KB
src/components/landingnew/LiveDemo/LiveDemo.jsxother4.6 KB
src/components/landingnew/Navbar/Navbar.cssother21.6 KB
src/components/landingnew/Navbar/Navbar.jsxother19.4 KB
src/components/landingnew/ProSpotlight/ProSpotlight.cssother2.4 KB
src/components/landingnew/ProSpotlight/ProSpotlight.jsxother1.5 KB
src/components/landingnew/Sponsors/Sponsors.cssother5.2 KB
src/components/landingnew/Sponsors/Sponsors.jsxother3.2 KB
src/components/landingnew/Testimonials/Testimonials.cssother5.5 KB
src/components/landingnew/Testimonials/Testimonials.jsxother4.8 KB
src/components/landingnew/Tools/SoundPreview.jsxother1012 B
src/components/landingnew/Tools/Tools.cssother4.3 KB
src/components/landingnew/Tools/Tools.jsxother4.2 KB
src/components/layout/Providers.jsxother667 B
src/components/layout/SidebarLayout.jsxother793 B
src/components/navs/Header.jsxother15.9 KB
src/components/navs/Sidebar.jsxother34.4 KB
src/components/setup/ChakraScope.jsxother433 B
src/components/setup/color-mode.jsxother2.1 KB
src/components/setup/provider.jsxother145 B
src/components/setup/toaster.jsxother1.0 KB
src/components/setup/tooltip.jsxother897 B
src/constants/Badges.jsscript1.4 KB
src/constants/Categories.jsscript5.0 KB
src/constants/Components.jsscript15.1 KB
src/constants/Information.jsscript114.4 KB
src/constants/Pro.jsscript11.4 KB
src/constants/Showcase.jsscript806 B
src/constants/Site.jsscript346 B
src/constants/Sponsors.jsscript1.2 KB
src/constants/Tools.jsscript2.1 KB
src/constants/backgroundThemeProps.jsscript4.8 KB
src/constants/code/Animations/animatedContentCode.jsscript737 B
src/constants/code/Animations/blobCursorCode.jsscript653 B
src/constants/code/Animations/clickSparkCode.jsscript588 B
src/constants/code/Animations/crosshairCode.jsscript880 B
src/constants/code/Animations/crystalizedBallCode.jsscript822 B
src/constants/code/Animations/cubesCode.jsscript738 B
src/constants/code/Animations/cursorGridCode.jsscript866 B
src/constants/code/Animations/ditherVeilCode.jsscript870 B
src/constants/code/Animations/elasticMeshCode.jsscript896 B
src/constants/code/Animations/electricBorderCode.jsscript790 B
src/constants/code/Animations/electricLogoCode.jsscript825 B
src/constants/code/Animations/fadeContentCode.jsscript649 B
src/constants/code/Animations/ghostCursorCode.jsscript755 B
src/constants/code/Animations/glareHoverCode.jsscript879 B
src/constants/code/Animations/glowCursorCode.jsscript768 B
src/constants/code/Animations/gradualblurCode.jsscript924 B
src/constants/code/Animations/halftoneRevealCode.jsscript895 B
src/constants/code/Animations/imageTrailCode.jsscript1.1 KB
src/constants/code/Animations/laserFlowCode.jsscript1.3 KB
src/constants/code/Animations/logoLoopCode.jsscript1.8 KB
src/constants/code/Animations/magnetCode.jsscript479 B
src/constants/code/Animations/metaBallsCode.jsscript822 B
src/constants/code/Animations/metallicPaintCode.jsscript779 B
src/constants/code/Animations/noiseCode.jsscript794 B

src/components/common/TabsLayout.jsx

View on GitHub
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState, useCallback } from 'react';
import TabsFooter from './TabsFooter';
import CategoryProFooter from './Pro/CategoryProFooter';
import Customize from './Preview/Customize';

import { Tabs, Tooltip, Menu, Portal } from '@chakra-ui/react';
import { HugeiconsIcon } from '@hugeicons/react';
import {
  ComputerIcon,
  FavouriteIcon,
  FullScreenIcon,
  MoreHorizontalIcon,
  PaintBoardIcon,
  Share08Icon,
  SmartPhone01Icon,
  SourceCodeIcon,
  Tablet01Icon,
  ViewIcon
} from '@hugeicons/core-free-icons';
import { useParams, useNavigate } from 'react-router-dom';
import { toast } from 'sonner';
import { toggleSavedComponent, isComponentSaved } from '../../utils/favorites';
import { useComponentPropsContext } from '../../hooks/useComponentPropsContext';
import { useOptions } from '../context/OptionsContext/useOptions';
import { colors } from '../../constants/colors';
import PropTable from './Preview/PropTable';
import CodeExample, { injectPropsIntoCode } from '../code/CodeExample';
import OpenInStudioButton from './Preview/OpenInStudioButton';
import { buildStudioUrl } from './Preview/studio-url';
import CopyForAIMenu, { AIMenuSections, MenuGroup } from './CopyForAIMenu';
import FluidMenuContent from './FluidMenuContent';
import { useAIExportActions } from '../../hooks/useAIExportActions';
import ComponentPager from './ComponentPager';
import CustomizeActionsContext from './Preview/CustomizeContext';
import PreviewStageContext from './Preview/PreviewStageContext';
import { demoModesFor, demoView } from './Preview/demoModes';
import PreviewResizer, { PreviewStage } from './Preview/PreviewResizer';
import { usePreviewFrame } from '../../hooks/usePreviewFrame';
import { RelatedComponents } from './DocsOverview';
import { getComponentSEOByPath } from '../../utils/seo';
import { buildPrompt, getActiveCode } from '../../utils/aiPrompt';

/**
 * Recursively searches React children for a component of the given type
 * and returns its props. Returns null if not found.
 */
function findChildProps(children, targetType) {
  let result = null;
  React.Children.forEach(children, child => {
    if (result || !child || !child.props) return;
    if (child.type === targetType) {
      result = child.props;
      return;
    }
    if (child.props.children) {
      result = findChildProps(child.props.children, targetType);
    }
  });
  return result;
}

function insertCategoryPro(children, category) {
  const target = findChildProps(children, Customize) ? Customize : PropTable;
  let inserted = false;
  const visit = node => {
    if (inserted) return node;
    if (Array.isArray(node)) return node.map(visit);
    if (!React.isValidElement(node)) return node;
    if (node.type === target) {
      inserted = true;
      const strip = <CategoryProFooter key="related-pro" category={category} />;
      return (
        <React.Fragment key={node.key ?? 'related-pro-slot'}>
          {target === Customize ? node : strip}
          {target === Customize ? strip : node}
        </React.Fragment>
      );
    }
    if (node.props.children == null) return node;
    const next = visit(node.props.children);
    if (!inserted) return node;
    return Array.isArray(next)
      ? React.cloneElement(node, undefined, ...next)
      : React.cloneElement(node, undefined, next);
  };
  return visit(children);
}

const ToolIcon = ({ icon }) => <HugeiconsIcon icon={icon} size={16} strokeWidth={1.6} aria-hidden="true" />;

const ToolTip = ({ label, children }) => (
  <Tooltip.Root openDelay={300} closeDelay={80} positioning={{ placement: 'top', gutter: 8 }}>
    <Tooltip.Trigger asChild>{children}</Tooltip.Trigger>
    <Tooltip.Positioner>
      <Tooltip.Content className="docs-tooltip">{label}</Tooltip.Content>
    </Tooltip.Positioner>
  </Tooltip.Root>
);

const TABLET_WIDTH = 768;
const MOBILE_WIDTH = 375;

const WIDTH_PRESETS = [
  { label: 'Desktop', icon: ComputerIcon, width: null },
  { label: `Tablet · ${TABLET_WIDTH}px`, icon: Tablet01Icon, width: TABLET_WIDTH },
  { label: `Mobile · ${MOBILE_WIDTH}px`, icon: SmartPhone01Icon, width: MOBILE_WIDTH }
];

let rememberedDemoMode = 'none';

const MenuIcon = ({ icon, saved }) => (
  <span className="docs-menu-icon" data-saved={saved ? '' : undefined}>
    <ToolIcon icon={icon} />
  </span>
);

const usePill = (trackRef, selection) => {
  const [pill, setPill] = useState(null);

  useLayoutEffect(() => {
    const track = trackRef.current;
    if (!track) return undefined;
    const measure = () => {
      const active = track.querySelector('[aria-selected="true"], [aria-pressed="true"]');
      setPill(previous => {
        if (!active) return previous ? { ...previous, hidden: true } : null;
        const next = { x: active.offsetLeft, width: active.offsetWidth, hidden: false, ready: Boolean(previous) };
        const same = previous && previous.x === next.x && previous.width === next.width && !previous.hidden;
        return same ? previous : next;
      });
    };
    measure();
    const observer = new ResizeObserver(measure);
    observer.observe(track);
    return () => observer.disconnect();
  }, [trackRef, selection]);

  return pill;
};

const Pill = ({ pill }) => (
  <span
    className="docs-pill"
    aria-hidden="true"
    data-ready={pill?.ready ? '' : undefined}
    style={
      pill ? { width: pill.width, transform: `translateX(${pill.x}px)`, opacity: pill.hidden ? 0 : 1 } : { opacity: 0 }
    }
  />
);

const canFullscreen = () =>
  typeof document !== 'undefined' && Boolean(document.fullscreenEnabled || document.webkitFullscreenEnabled);

const TabsLayout = ({ children, className }) => {
  const { category, subcategory } = useParams();
  const componentSEO = useMemo(() => getComponentSEOByPath(`/${category}/${subcategory}`), [category, subcategory]);
  const {
    hasChanges,
    resetProps,
    props: currentProps,
    defaultProps,
    demoOnlyProps,
    computedProps
  } = useComponentPropsContext();

  const { favoriteKey, componentName } = useMemo(() => {
    if (!category || !subcategory) return null;

    const toPascal = str =>
      str
        .split('-')
        .map(word => word.charAt(0).toUpperCase() + word.slice(1))
        .join('');

    const categoryName = toPascal(category);
    const componentName = toPascal(subcategory);
    return { favoriteKey: `${categoryName}/${componentName}`, componentName };
  }, [category, subcategory]) || { favoriteKey: null, componentName: null };

  const [isSaved, setIsSaved] = useState(false);

  useEffect(() => {
    if (!favoriteKey) return;
    setIsSaved(isComponentSaved(favoriteKey));
  }, [favoriteKey]);

  const toggleFavorite = () => {
    if (!favoriteKey) return;
    const { saved } = toggleSavedComponent(favoriteKey);
    setIsSaved(saved);

    const nameEl = (
      <span>
        {' '}
        <span style={{ color: colors.accent, fontWeight: 700 }}>&lt;{componentName} /&gt;</span>
      </span>
    );

    if (saved) toast.success?.(<>Added {nameEl} to favorites</>) ?? toast(<>Added {nameEl} to favorites</>);
    else toast.error?.(<>Removed {nameEl} from favorites</>) ?? toast(<>Removed {nameEl} from favorites</>);
  };
  const contentMap = {
    PreviewTab: null,
    CodeTab: null
  };

  React.Children.forEach(children, child => {
    if (!child) return;
    if (child.type === PreviewTab) contentMap.PreviewTab = child;
    if (child.type === CodeTab) contentMap.CodeTab = child;
  });

  // Extract codeObject/componentName from CodeExample child and propData from PropTable child
  const codeExampleProps = contentMap.CodeTab ? findChildProps(contentMap.CodeTab.props.children, CodeExample) : null;
  const propTableProps = contentMap.PreviewTab ? findChildProps(contentMap.PreviewTab.props.children, PropTable) : null;
  const studioButtonProps = contentMap.PreviewTab
    ? findChildProps(contentMap.PreviewTab.props.children, OpenInStudioButton)
    : null;

  const navigate = useNavigate();
  const handleOpenStudio = useCallback(() => {
    if (!studioButtonProps) return;
    const { backgroundId, currentProps: sbCurrent = {}, defaultProps: sbDefault = {} } = studioButtonProps;
    navigate(buildStudioUrl(backgroundId, sbCurrent, sbDefault));
  }, [studioButtonProps, navigate]);

  const { languagePreset, stylePreset } = useOptions();

  const aiExport = useMemo(() => {
    if (!codeExampleProps) return null;
    const { codeObject, componentName: compName } = codeExampleProps;
    const mergedProps = { ...currentProps, ...computedProps };
    const dynamicUsage =
      codeObject.usage && compName
        ? injectPropsIntoCode(codeObject.usage, mergedProps, defaultProps || {}, compName, demoOnlyProps)
        : codeObject.usage;
    const { source, css } = getActiveCode(codeObject, languagePreset, stylePreset);

    return {
      componentName: compName,
      fullPrompt: buildPrompt(
        compName,
        { ...codeObject, usage: dynamicUsage },
        propTableProps?.data || [],
        languagePreset,
        stylePreset
      ),
      configuredUsage: dynamicUsage,
      componentSource: source,
      componentCss: css,
      dependencies: codeObject.dependencies || ''
    };
  }, [
    codeExampleProps,
    propTableProps,
    languagePreset,
    stylePreset,
    currentProps,
    defaultProps,
    demoOnlyProps,
    computedProps
  ]);

  const aiActions = useAIExportActions({ category, subcategory, ...(aiExport || {}) });

  const copyShareLink = useCallback(async () => {
    try {
      await navigator.clipboard.writeText(window.location.href);
      toast.success('Share link copied');
    } catch {
      toast.error('Could not copy the link');
    }
  }, []);

  const [activeTab, setActiveTab] = useState('preview');
  const [previewWidth, setPreviewWidth] = useState(null);
  const tabsTrackRef = useRef(null);
  const sizeTrackRef = useRef(null);
  const tabsPill = usePill(tabsTrackRef, activeTab);
  const [resizing, setResizing] = useState(false);
  const previewRef = useRef(null);
  const isPreview = activeTab === 'preview';
  const canResize = category !== 'get-started' && isPreview;
  const frame = usePreviewFrame(previewRef, canResize);
  const [controlsSlot, setControlsSlot] = useState(null);
  const isBackgrounds = category === 'backgrounds';
  const hasStageControls = isBackgrounds && canResize;
  const [demoMode, setDemoModeState] = useState(rememberedDemoMode);
  const [demoNarrow, setDemoNarrow] = useState(false);
  const [demoPresent, setDemoPresent] = useState(false);
  const setDemoMode = useCallback(value => {
    rememberedDemoMode = value;
    setDemoModeState(value);
  }, []);
  const previewStage = useMemo(
    () => ({
      controls: hasStageControls ? controlsSlot : null,
      hasControls: hasStageControls,
      demo: isBackgrounds
        ? { mode: demoMode, setMode: setDemoMode, setNarrow: setDemoNarrow, setPresent: setDemoPresent }
        : null
    }),
    [hasStageControls, controlsSlot, isBackgrounds, demoMode, setDemoMode]
  );

  useEffect(() => {
    if (frame && previewWidth !== null && previewWidth >= frame.fullWidth) setPreviewWidth(null);
  }, [frame, previewWidth]);

  const openFullscreen = useCallback(() => {
    const demo = previewRef.current?.querySelector('.demo-container');
    const request = demo?.requestFullscreen || demo?.webkitRequestFullscreen;
    if (!request) return;
    Promise.resolve(request.call(demo)).catch(() => toast.error('Fullscreen is not available here'));
  }, []);

  const showFavorite = favoriteKey && category !== 'get-started';
  const showFullscreen = category === 'backgrounds' && isPreview && canFullscreen();
  const hasOverflowActions = showFavorite || Boolean(codeExampleProps) || Boolean(studioButtonProps) || showFullscreen;
  const widthPresets =
    canResize && frame ? WIDTH_PRESETS.filter(preset => preset.width === null || preset.width < frame.fullWidth) : [];
  const showDemoModes = isBackgrounds && isPreview && demoPresent;
  const demoOptions = demoModesFor(demoNarrow);
  const demoSelected = demoView(demoMode, demoNarrow);
  const showWidthPresets = !showDemoModes && widthPresets.length > 1;
  const sizePill = usePill(
    sizeTrackRef,
    `${previewWidth}-${widthPresets.length}-${showFullscreen}-${showDemoModes ? `${demoSelected}-${demoOptions.length}` : ''}`
  );
  const favoriteLabel = isSaved ? 'Remove from favorites' : 'Add to favorites';

  return (
    <Tabs.Root
      w="100%"
      variant="plain"
      lazyMount
      value={activeTab}
      onValueChange={({ value }) => setActiveTab(value)}
      className={className}
    >
      <Tabs.List className="docs-toolbar">
        <div className="docs-track docs-tabs" ref={tabsTrackRef} data-pill="">
          <Pill pill={tabsPill} />
          <Tabs.Trigger value="preview" className="docs-segment">
            <ToolIcon icon={ViewIcon} />
            Preview
          </Tabs.Trigger>
          <Tabs.Trigger value="code" className="docs-segment">
            <ToolIcon icon={SourceCodeIcon} />
            Code
          </Tabs.Trigger>
        </div>

        <div className="docs-toolbar-actions">
          {(showDemoModes || showWidthPresets || showFullscreen) && (
            <div
              className="docs-track"
              role="group"
              aria-label={showDemoModes ? 'Demo content' : 'Preview size'}
              ref={sizeTrackRef}
              data-pill=""
            >
              <Pill pill={sizePill} />
              {showDemoModes &&
                demoOptions.map(item => (
                  <ToolTip key={item.value} label={item.label}>
                    <button
                      type="button"
                      className="docs-segment docs-segment--icon"
                      aria-label={item.label}
                      aria-pressed={demoSelected === item.value}
                      onClick={() => setDemoMode(item.value)}
                    >
                      <ToolIcon icon={item.icon} />
                    </button>
                  </ToolTip>
                ))}
              {showWidthPresets &&
                widthPresets.map(preset => (
                  <ToolTip key={preset.label} label={preset.label}>
                    <button
                      type="button"
                      className="docs-segment docs-segment--icon"
                      aria-label={preset.label}
                      aria-pressed={previewWidth === preset.width}
                      onClick={() => setPreviewWidth(preset.width)}
                    >
                      <ToolIcon icon={preset.icon} />
                    </button>
                  </ToolTip>
                ))}
              {showFullscreen && (
                <ToolTip label="Fullscreen">
                  <button
                    type="button"
                    className="docs-segment docs-segment--icon"
                    aria-label="Fullscreen"
                    onClick={openFullscreen}
                  >
                    <ToolIcon icon={FullScreenIcon} />
                  </button>
                </ToolTip>
              )}
            </div>
          )}

          {showFavorite && (
            <div className="docs-track" role="group" aria-label="Page actions">
              <ToolTip label={favoriteLabel}>
                <button
                  type="button"
                  className="docs-segment docs-segment--icon docs-favorite"
                  aria-label={favoriteLabel}
                  aria-pressed={isSaved}
                  data-saved={isSaved ? '' : undefined}
                  onClick={toggleFavorite}
                >
                  <ToolIcon icon={FavouriteIcon} />
                </button>
              </ToolTip>
              <ToolTip label="Copy share link">
                <button
                  type="button"
                  className="docs-segment docs-segment--icon"
                  aria-label="Copy share link"
                  onClick={copyShareLink}
                >
                  <ToolIcon icon={Share08Icon} />
                </button>
              </ToolTip>
            </div>
          )}

          {aiExport && <CopyForAIMenu {...aiActions} />}
        </div>

        {hasOverflowActions && (
          <Menu.Root
            positioning={{
              placement: 'bottom-end',
              gutter: 12,
              offset: { mainAxis: 6, crossAxis: 0 },
              flip: false,
              overflowPadding: 0
            }}
          >
            <Menu.Trigger asChild>
              <button type="button" className="docs-tool docs-tool--icon docs-toolbar-more" aria-label="More actions">
                <ToolIcon icon={MoreHorizontalIcon} />
                {isSaved && <span className="docs-tool-dot" />}
              </button>
            </Menu.Trigger>
            <Portal>
              <Menu.Positioner>
                <FluidMenuContent minW="220px" zIndex={1500} transformOrigin="top right">
                  {showFavorite && (
                    <MenuGroup label="Page">
                      <Menu.Item value="favorite" onSelect={toggleFavorite} className="docs-menu-item">
                        <MenuIcon icon={FavouriteIcon} saved={isSaved} />
                        {favoriteLabel}
                      </Menu.Item>
                      <Menu.Item value="share" onSelect={copyShareLink} className="docs-menu-item">
                        <MenuIcon icon={Share08Icon} />
                        Copy share link
                      </Menu.Item>
                    </MenuGroup>
                  )}
                  {aiExport && (
                    <AIMenuSections
                      copyItems={aiActions.copyItems}
                      openItems={aiActions.openItems}
                      done={aiActions.done}
                    />
                  )}
                  {(showFullscreen || studioButtonProps) && (
                    <MenuGroup label="View">
                      {showFullscreen && (
                        <Menu.Item value="fullscreen" onSelect={openFullscreen} className="docs-menu-item">
                          <MenuIcon icon={FullScreenIcon} />
                          Fullscreen
                        </Menu.Item>
                      )}
                      {studioButtonProps && (
                        <Menu.Item value="open-studio" onSelect={handleOpenStudio} className="docs-menu-item">
                          <MenuIcon icon={PaintBoardIcon} />
                          Open in BG Studio
                        </Menu.Item>
                      )}
                    </MenuGroup>
                  )}
                </FluidMenuContent>
              </Menu.Positioner>
            </Portal>
          </Menu.Root>
        )}
      </Tabs.List>

      <Tabs.Content
        pt={0}
        value="preview"
        ref={previewRef}
        className="preview-panel"
        data-resizing={resizing ? '' : undefined}
        style={previewWidth === null ? undefined : { '--preview-width': `${previewWidth}px` }}
      >
        {canResize && <PreviewStage frame={frame} visible={previewWidth !== null || resizing} />}
        <CustomizeActionsContext.Provider
          value={{
            openStudio: studioButtonProps ? handleOpenStudio : null,
            reset: resetProps,
            canReset: hasChanges
          }}
        >
          <PreviewStageContext.Provider value={previewStage}>
            {insertCategoryPro(contentMap.PreviewTab, category)}
          </PreviewStageContext.Provider>
        </CustomizeActionsContext.Provider>
        {hasStageControls && frame && (
          <div
            className="preview-controls"
            ref={setControlsSlot}
            style={{ top: frame.top, left: frame.left, width: frame.fullWidth }}
          />
        )}
        {canResize && (
          <PreviewResizer
            frame={frame}
            width={previewWidth}
            onWidthChange={setPreviewWidth}
            onResizingChange={setResizing}
          />
        )}
      </Tabs.Content>
      <Tabs.Content pt={0} value="code">
        {contentMap.CodeTab}
      </Tabs.Content>

      {componentSEO && <RelatedComponents seo={componentSEO} />}
      {category !== 'get-started' && <ComponentPager category={category} subcategory={subcategory} />}

      <TabsFooter />
    </Tabs.Root>
  );
};

export const PreviewTab = ({ children }) => <>{children}</>;
export const CodeTab = ({ children }) => <>{children}</>;

export { TabsLayout };
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 319kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 196kUpdated Claude CodeCodexVerifiedInstall