UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
✨ feat: Add globe component
Dillion Vermae801b3fa70fe
diff --git a/content/components/globe.mdx b/content/components/globe.mdxnew file mode 100644index 00000000..e1432d4f--- /dev/null+++ b/content/components/globe.mdx@@ -0,0 +1,63 @@+---+title: Globe+date: 2023-08-02+summary: An autorotating, interactive, and highly performant globe made using WebGL.+author: dillionverma+published: true+video: https://cdn.magicuikit.com/globe.mp4+---++<ComponentPreview name="globe-demo" />++<Steps>++<Step>++## Prerequisites++```bash+npm install -D tailwindcss clsx cobe react-spring+```++Copy and paste the following code into your project.++```typescript+// lib/utils.ts+import clsx, { ClassValue } from "clsx";+import { twMerge } from "tailwind-merge";++export function cn(...inputs: ClassValue[]) {+ return twMerge(clsx(inputs));+}+```++</Step>++<Step>++## Installation++Copy and paste the following code into your project.++```text+components/magicui/globe.tsx+```++<ComponentSource name="globe" />++</Step>++</Steps>++## Props++### Globe++| Prop | Type | Description | Default |+| --------- | ----------- | ---------------------------------------------------------------------------------------------- | ------- |+| className | string | The css classes for the component | |+| config | COBEOptions | The configuration options for the globe. More details [here](https://cobe.vercel.app/docs/api) | `{}` |++## Credits++This component is built on top of [Cobe](https://cobe.vercel.app/docs/api).diff --git a/package.json b/package.jsonindex ce2083cf..5c034b3c 100644--- a/package.json+++ b/package.json@@ -54,6 +54,7 @@"class-variance-authority": "^0.6.0","clsx": "^1.2.1","cmdk": "^0.2.0",+ "cobe": "^0.6.3","contentlayer": "^0.3.3","date-fns": "^2.30.0","dotenv": "^16.3.1",@@ -72,6 +73,7 @@"react-dom": "18.2.0","react-email": "1.9.4","react-hook-form": "^7.45.0",+ "react-spring": "^9.7.2","react-tweet": "^3.0.3","react-wrap-balancer": "^1.0.0","resend": "^0.16.0",@@ -87,9 +89,9 @@"@types/react": "18.2.12","@types/react-dom": "18.2.5","mdast-util-toc": "^6.1.1",- "prisma": "^4.16.1","prettier": "^3.0.0","prettier-plugin-tailwindcss": "^0.4.1",+ "prisma": "^4.16.1","rehype-autolink-headings": "^6.1.1","rehype-pretty-code": "^0.9.11","rehype-slug": "^5.1.0",diff --git a/registry/components/example/globe-demo.tsx b/registry/components/example/globe-demo.tsxnew file mode 100644index 00000000..84372967--- /dev/null+++ b/registry/components/example/globe-demo.tsx@@ -0,0 +1,13 @@+import Globe from "@/registry/components/magicui/globe";++export default function GlobeDemo() {+ return (+ <div className="relative flex h-full w-full items-center justify-center overflow-hidden rounded-lg border bg-background px-40 pb-40 pt-8 md:pb-60">+ <Globe className="top-28" />+ <span className="pointer-events-none whitespace-pre-wrap bg-gradient-to-b from-black to-gray-300/80 bg-clip-text text-center text-8xl font-semibold leading-none text-transparent dark:from-white dark:to-slate-900/10">+ Globe+ </span>+ <div className="pointer-events-none absolute inset-0 h-full bg-[radial-gradient(circle_at_50%_120%,rgba(120,119,198,0.3),rgba(255,255,255,0))]" />+ </div>+ );+}diff --git a/registry/components/magicui/globe.tsx b/registry/components/magicui/globe.tsxnew file mode 100644index 00000000..704ea72a--- /dev/null+++ b/registry/components/magicui/globe.tsx@@ -0,0 +1,122 @@+import { cn } from "@/lib/utils";+import createGlobe, { COBEOptions } from "cobe";+import { useEffect, useRef } from "react";+import { useSpring } from "react-spring";++const GLOBE_CONFIG: COBEOptions = {+ width: 800,+ height: 800,+ onRender: () => {},+ devicePixelRatio: 2,+ phi: 0,+ theta: 0.3,+ dark: 0,+ diffuse: 0.4,+ mapSamples: 16000,+ mapBrightness: 1.2,+ baseColor: [1, 1, 1],+ markerColor: [251 / 255, 100 / 255, 21 / 255],+ glowColor: [1, 1, 1],+ markers: [+ { location: [14.5995, 120.9842], size: 0.03 },+ { location: [19.076, 72.8777], size: 0.1 },+ { location: [23.8103, 90.4125], size: 0.05 },+ { location: [30.0444, 31.2357], size: 0.07 },+ { location: [39.9042, 116.4074], size: 0.08 },+ { location: [-23.5505, -46.6333], size: 0.1 },+ { location: [19.4326, -99.1332], size: 0.1 },+ { location: [40.7128, -74.006], size: 0.1 },+ { location: [34.6937, 135.5022], size: 0.05 },+ { location: [41.0082, 28.9784], size: 0.06 },+ ],+};++export default function Globe({+ className,+ config = GLOBE_CONFIG,+}: {+ className?: string;+ config?: COBEOptions;+}) {+ const canvasRef = useRef<HTMLCanvasElement>(null);+ const pointerInteracting = useRef(null);+ const pointerInteractionMovement = useRef(0);+ const [{ r }, api] = useSpring(() => ({+ r: 0,+ config: {+ mass: 1,+ tension: 280,+ friction: 40,+ precision: 0.001,+ },+ }));++ const updatePointerInteraction = (value: any) => {+ pointerInteracting.current = value;+ canvasRef.current!.style.cursor = value ? "grabbing" : "grab";+ };++ const updateMovement = (clientX: any) => {+ if (pointerInteracting.current !== null) {+ const delta = clientX - pointerInteracting.current;+ pointerInteractionMovement.current = delta;+ api.start({ r: delta / 200 });+ }+ };++ useEffect(() => {+ let phi = 0;+ let width = 0;++ const onResize = () => {+ if (canvasRef.current) {+ width = canvasRef.current.offsetWidth;+ }+ };++ window.addEventListener("resize", onResize);+ onResize();++ const globe = createGlobe(canvasRef.current!, {+ ...config,+ width: width * 2,+ height: width * 2,+ onRender: (state) => {+ if (!pointerInteracting.current) phi += 0.005;+ state.phi = phi + r.get();+ state.width = width * 2;+ state.height = width * 2;+ },+ });++ setTimeout(() => (canvasRef.current!.style.opacity = "1"));+ return () => globe.destroy();+ }, []);++ return (+ <div+ className={cn(+ "absolute inset-0 aspect-[1/1] w-full max-w-[600px]",+ className,+ )}+ >+ <canvas+ className={cn(+ "h-full w-full opacity-0 transition-opacity duration-500 [contain:layout_paint_size]",+ )}+ ref={canvasRef}+ onPointerDown={(e) =>+ updatePointerInteraction(+ e.clientX - pointerInteractionMovement.current,+ )+ }+ onPointerUp={() => updatePointerInteraction(null)}+ onPointerOut={() => updatePointerInteraction(null)}+ onMouseMove={(e) => updateMovement(e.clientX)}+ onTouchMove={(e) =>+ e.touches[0] && updateMovement(e.touches[0].clientX)+ }+ />+ </div>+ );+}diff --git a/registry/index.tsx b/registry/index.tsxindex d7a56629..e8d231d4 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -38,6 +38,11 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/marquee.tsx"],},+ globe: {+ name: "globe",+ type: "components:ui",+ files: ["registry/components/magicui/globe.tsx"],+ },"tweet-card": {name: "tweet-card",type: "components:ui",@@ -119,7 +124,6 @@ const example: Registry = {() => import("@/registry/components/example/dot-pattern-linear-gradient"),),},-"marquee-demo": {name: "marquee-demo",type: "components:example",@@ -136,6 +140,14 @@ const example: Registry = {() => import("@/registry/components/example/marquee-logos"),),},+ "globe-demo": {+ name: "globe-demo",+ type: "components:example",+ files: ["registry/components/example/globe-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/globe-demo"),+ ),+ },"tweet-card-demo": {name: "tweet-card-demo",type: "components:example",diff --git a/yarn.lock b/yarn.lockindex d5c69584..7cd961dc 100644--- a/yarn.lock+++ b/yarn.lock@@ -1753,6 +1753,85 @@dependencies:react "18.2.0"+"@react-spring/animated@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/animated/-/animated-9.7.3.tgz#4211b1a6d48da0ff474a125e93c0f460ff816e0f"+ integrity sha512-5CWeNJt9pNgyvuSzQH+uy2pvTg8Y4/OisoscZIR8/ZNLIOI+CatFBhGZpDGTF/OzdNFsAoGk3wiUYTwoJ0YIvw==+ dependencies:+ "@react-spring/shared" "~9.7.3"+ "@react-spring/types" "~9.7.3"++"@react-spring/core@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/core/-/core-9.7.3.tgz#60056bcb397f2c4f371c6c9a5f882db77ae90095"+ integrity sha512-IqFdPVf3ZOC1Cx7+M0cXf4odNLxDC+n7IN3MDcVCTIOSBfqEcBebSv+vlY5AhM0zw05PDbjKrNmBpzv/AqpjnQ==+ dependencies:+ "@react-spring/animated" "~9.7.3"+ "@react-spring/shared" "~9.7.3"+ "@react-spring/types" "~9.7.3"++"@react-spring/konva@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/konva/-/konva-9.7.3.tgz#16bd29dd4860a99e960a72987c8bcfc828b22119"+ integrity sha512-R9sY6SiPGYqz1383P5qppg5z57YfChVknOC1UxxaGxpw+WiZa8fZ4zmZobslrw+os3/+HAXZv8O+EvU/nQpf7g==+ dependencies:+ "@react-spring/animated" "~9.7.3"+ "@react-spring/core" "~9.7.3"+ "@react-spring/shared" "~9.7.3"+ "@react-spring/types" "~9.7.3"++"@react-spring/native@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/native/-/native-9.7.3.tgz#ee38d7c23482cfb4916c9b3c021de2995a4f553a"+ integrity sha512-4mpxX3FuEBCUT6ae2fjhxcJW6bhr2FBwFf274eXB7n+U30Gdg8Wo2qYwcUnmiAA0S3dvP8vLTazx3+CYWFShnA==+ dependencies:+ "@react-spring/animated" "~9.7.3"+ "@react-spring/core" "~9.7.3"+ "@react-spring/shared" "~9.7.3"+ "@react-spring/types" "~9.7.3"++"@react-spring/shared@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/shared/-/shared-9.7.3.tgz#4cf29797847c689912aec4e62e34c99a4d5d9e53"+ integrity sha512-NEopD+9S5xYyQ0pGtioacLhL2luflh6HACSSDUZOwLHoxA5eku1UPuqcJqjwSD6luKjjLfiLOspxo43FUHKKSA==+ dependencies:+ "@react-spring/types" "~9.7.3"++"@react-spring/three@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/three/-/three-9.7.3.tgz#4358a0c4640efe2972c4f7d0f7cd4efe927471c1"+ integrity sha512-Q1p512CqUlmMK8UMBF/Rj79qndhOWq4XUTayxMP9S892jiXzWQuj+xC3Xvm59DP/D4JXusXpxxqfgoH+hmOktA==+ dependencies:+ "@react-spring/animated" "~9.7.3"+ "@react-spring/core" "~9.7.3"+ "@react-spring/shared" "~9.7.3"+ "@react-spring/types" "~9.7.3"++"@react-spring/types@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/types/-/types-9.7.3.tgz#ea78fd447cbc2612c1f5d55852e3c331e8172a0b"+ integrity sha512-Kpx/fQ/ZFX31OtlqVEFfgaD1ACzul4NksrvIgYfIFq9JpDHFwQkMVZ10tbo0FU/grje4rcL4EIrjekl3kYwgWw==++"@react-spring/web@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/web/-/web-9.7.3.tgz#d9f4e17fec259f1d65495a19502ada4f5b57fa3d"+ integrity sha512-BXt6BpS9aJL/QdVqEIX9YoUy8CE6TJrU0mNCqSoxdXlIeNcEBWOfIyE6B14ENNsyQKS3wOWkiJfco0tCr/9tUg==+ dependencies:+ "@react-spring/animated" "~9.7.3"+ "@react-spring/core" "~9.7.3"+ "@react-spring/shared" "~9.7.3"+ "@react-spring/types" "~9.7.3"++"@react-spring/zdog@~9.7.3":+ version "9.7.3"+ resolved "https://registry.yarnpkg.com/@react-spring/zdog/-/zdog-9.7.3.tgz#8ccc7316f6d3460ed244d9e3f60de9b4c4a848ac"+ integrity sha512-L+yK/1PvNi9n8cldiJ309k4LdxcPkeWE0W18l1zrP1IBIyd5NB5EPA8DMsGr9gtNnnIujtEzZk+4JIOjT8u/tw==+ dependencies:+ "@react-spring/animated" "~9.7.3"+ "@react-spring/core" "~9.7.3"+ "@react-spring/shared" "~9.7.3"+ "@react-spring/types" "~9.7.3"+"@rushstack/eslint-patch@^1.1.3":version "1.3.2"resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.3.2.tgz#31b9c510d8cada9683549e1dbb4284cca5001faf"@@ -2505,6 +2584,13 @@ cmdk@^0.2.0:"@radix-ui/react-dialog" "1.0.0"command-score "0.1.2"+cobe@^0.6.3:+ version "0.6.3"+ resolved "https://registry.yarnpkg.com/cobe/-/cobe-0.6.3.tgz#9c3d45ae3a328b7bf709eb17b02f9caff41b22f0"+ integrity sha512-WHr7X4o1ym94GZ96h7b1pNemZJacbOzd02dZtnVwuC4oWBaLg96PBmp2rIS1SAhUDhhC/QyS9WEqkpZIs/ZBTg==+ dependencies:+ phenomenon "^1.6.0"+color-convert@^1.9.0:version "1.9.3"resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"@@ -5750,6 +5836,11 @@ periscopic@^3.0.0:estree-walker "^3.0.0"is-reference "^3.0.0"+phenomenon@^1.6.0:+ version "1.6.0"+ resolved "https://registry.yarnpkg.com/phenomenon/-/phenomenon-1.6.0.tgz#7b5b7647d0b48152cc0846994da3d92e8f6da677"+ integrity sha512-7h9/fjPD3qNlgggzm88cY58l9sudZ6Ey+UmZsizfhtawO6E3srZQXywaNm2lBwT72TbpHYRPy7ytIHeBUD/G0A==+picocolors@^1.0.0:version "1.0.0"resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"@@ -6101,6 +6192,18 @@ [email protected]:use-callback-ref "^1.3.0"use-sidecar "^1.1.2"+react-spring@^9.7.2:+ version "9.7.2"+ resolved "https://registry.yarnpkg.com/react-spring/-/react-spring-9.7.2.tgz#218360d0ca53d04d8faac984f0d8683819b967b4"+ integrity sha512-cckALtj79yiaJiAOUNAhtZbdqjvv1bdn/FpobgkckIChc8l6vu0E53WQ+zWru60gINI3JT+oRJSIn2hUVlOvlQ==+ dependencies:+ "@react-spring/core" "~9.7.3"+ "@react-spring/konva" "~9.7.3"+ "@react-spring/native" "~9.7.3"+ "@react-spring/three" "~9.7.3"+ "@react-spring/web" "~9.7.3"+ "@react-spring/zdog" "~9.7.3"+react-style-singleton@^2.2.1:version "2.2.1"resolved "https://registry.yarnpkg.com/react-style-singleton/-/react-style-singleton-2.2.1.tgz#f99e420492b2d8f34d38308ff660b60d0b1205b4"