card-globe
ui-layouts/card-globeFreeComponent
ui-layouts publishes no description for this item.
Install it
npx shadcn@latest add https://www.ui-layouts.com/r/card-globe.jsonSource
1'use client';2import { cn } from '@/lib/utils';3import createGlobe from 'cobe';4import type React from 'react';5import { useEffect, useRef, useState } from 'react';67interface EarthProps {8 className?: string;9 theta?: number;10 dark?: number;11 scale?: number;12 diffuse?: number;13 mapSamples?: number;14 mapBrightness?: number;15 baseColor?: [number, number, number];16 markerColor?: [number, number, number];17 glowColor?: [number, number, number];18}19const Earth: React.FC<EarthProps> = ({20 className,21 theta = 0.25,22 dark = 1,23 scale = 1.1,24 diffuse = 1.2,25 mapSamples = 40000,26 mapBrightness = 6,27 baseColor = [0.4, 0.6509, 1],28 markerColor = [1, 0, 0],29 glowColor = [0.2745, 0.5765, 0.898],30}) => {31 const canvasRef = useRef<HTMLCanvasElement>(null);3233 useEffect(() => {34 let width = 0;35 const onResize = () => canvasRef.current && (width = canvasRef.current.offsetWidth);36 window.addEventListener('resize', onResize);37 onResize();38 let phi = 0;3940 onResize();41 const globe = createGlobe(canvasRef.current!, {42 devicePixelRatio: 2,43 width: width * 2,44 height: width * 2,45 phi: 0,46 theta: theta,47 dark: dark,48 scale: scale,49 diffuse: diffuse,50 mapSamples: mapSamples,51 mapBrightness: mapBrightness,52 baseColor: baseColor,53 markerColor: markerColor,54 glowColor: glowColor,55 opacity: 1,56 offset: [0, 0],57 markers: [58 // longitude latitude59 ],60 onRender: (state: Record<string, any>) => {61 // Called on every animation frame.62 // `state` will be an empty object, return updated params.\63 state.phi = phi;64 phi += 0.003;65 },66 });6768 return () => {69 globe.destroy();70 };71 }, []);7273 return (74 <div75 className={cn(76 'flex items-center justify-center z-10 w-full max-w-[350px] mx-auto',77 className78 )}79 >80 <canvas81 ref={canvasRef}82 style={{83 width: '100%',84 height: '100%',85 maxWidth: '100%',86 aspectRatio: '1',87 }}88 />89 </div>90 );91};9293export default Earth;
What it pulls in
npm packages
Files it writes
More from ui-layouts
All 1 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| 3d-marquee3d-marquee | ui-layouts | Components | Free | no deps · 2 files | |
| accordionaccordion | ui-layouts | Components | Free | no deps | |
| align-slideralign-slider | ui-layouts | Components | Free | 6 deps · 2 files | |
| animal-imagemaskinganimal-imagemasking | ui-layouts | Components | Free | 1 dep | |
| animated-beamanimated-beam | ui-layouts | Components | Free | no deps | |
| animated-beam-bidirectionalanimated-beam-bidirectional | ui-layouts | Components | Free | no deps | |
| animated-beam-defaultanimated-beam-default | ui-layouts | Components | Free | no deps | |
| animated-beam-multiple-inputanimated-beam-multiple-input | ui-layouts | Components | Free | no deps |
