UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
dillion/tweet (#5)
Dillion Vermaf7807345a182
diff --git a/content/components/tweet-card.mdx b/content/components/tweet-card.mdxnew file mode 100644index 00000000..c7b65386--- /dev/null+++ b/content/components/tweet-card.mdx@@ -0,0 +1,32 @@+---+title: Tweet Card+date: 2023-07-29+summary: A card that displays a tweet with the author's name, handle, and profile picture.+author: dillionverma+published: false+video: https://cdn.magicuikit.com/tweet-card.mp4+---++<ComponentPreview name="tweet-card-demo" />++<Steps>++<Step>++## Installation++Copy and page the following code into your project.++```text+components/magicui/tweet-card.tsx+```++<ComponentSource name="tweet-card" />++</Step>++</Steps>++## Props++### Tweet Carddiff --git a/lib/utils.ts b/lib/utils.tsindex b945ae1c..3afbf4dd 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -7,6 +7,11 @@ export function cn(...inputs: ClassValue[]) {return twMerge(clsx(inputs));}+export const truncate = (str: string | null, length: number) => {+ if (!str || str.length <= length) return str;+ return `${str.slice(0, length - 3)}...`;+};+/*** Capitalizes first letters of words in string.* @param {string} str String to be modifieddiff --git a/package.json b/package.jsonindex e6651497..267c27a0 100644--- a/package.json+++ b/package.json@@ -71,6 +71,7 @@"react-dom": "18.2.0","react-email": "1.9.4","react-hook-form": "^7.45.0",+ "react-tweet": "^3.0.3","react-wrap-balancer": "^1.0.0","resend": "^0.16.0","schema-dts": "^1.1.2",diff --git a/registry/components/example/dot-pattern-demo.tsx b/registry/components/example/dot-pattern-demo.tsxindex fda4fd04..b2256104 100644--- a/registry/components/example/dot-pattern-demo.tsx+++ b/registry/components/example/dot-pattern-demo.tsx@@ -7,7 +7,7 @@ import RadialGradient from "@/registry/components/magicui/radial-gradient";const DotPatternDemo = () => {return (<div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden p-20">- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10 whitespace-pre-wrap text-center">Dot Pattern</p><DotPatterndiff --git a/registry/components/example/dot-pattern-linear-gradient.tsx b/registry/components/example/dot-pattern-linear-gradient.tsxindex 631bd568..508735a6 100644--- a/registry/components/example/dot-pattern-linear-gradient.tsx+++ b/registry/components/example/dot-pattern-linear-gradient.tsx@@ -6,8 +6,8 @@ import LinearGradient from "@/registry/components/magicui/linear-gradient";const DotPatternDemo2 = () => {return (- <div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden">- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden p-20">+ <p className="text-5xl font-medium tracking-tighter text-black dark:text-white z-10 whitespace-pre-wrap text-center">Dot Pattern</p><DotPatterndiff --git a/registry/components/example/grid-pattern-dashed.tsx b/registry/components/example/grid-pattern-dashed.tsxindex 1b07e694..80adb78d 100644--- a/registry/components/example/grid-pattern-dashed.tsx+++ b/registry/components/example/grid-pattern-dashed.tsx@@ -6,8 +6,8 @@ import RadialGradient from "@/registry/components/magicui/radial-gradient";const GridPatternDashed = () => {return (- <div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden">- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden p-20">+ <p className="text-5xl font-medium tracking-tighter text-black dark:text-white z-10 whitespace-pre-wrap text-center">Grid Pattern</p><GridPatterndiff --git a/registry/components/example/grid-pattern-demo.tsx b/registry/components/example/grid-pattern-demo.tsxindex 21a74fb9..677a6ccc 100644--- a/registry/components/example/grid-pattern-demo.tsx+++ b/registry/components/example/grid-pattern-demo.tsx@@ -7,7 +7,7 @@ import RadialGradient from "@/registry/components/magicui/radial-gradient";const GridPatternDemo = () => {return (<div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden p-20">- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <p className="text-5xl font-medium tracking-tighter text-black dark:text-white z-10 whitespace-pre-wrap text-center">Grid Pattern</p><GridPatterndiff --git a/registry/components/example/grid-pattern-linear-gradient.tsx b/registry/components/example/grid-pattern-linear-gradient.tsxindex 867382e2..ea753ffe 100644--- a/registry/components/example/grid-pattern-linear-gradient.tsx+++ b/registry/components/example/grid-pattern-linear-gradient.tsx@@ -6,8 +6,8 @@ import LinearGradient from "@/registry/components/magicui/linear-gradient";const GridPatternDemo2 = () => {return (- <div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden">- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden p-20">+ <p className="text-5xl font-medium tracking-tighter text-black dark:text-white z-10 whitespace-pre-wrap text-center">Grid Pattern</p><GridPatterndiff --git a/registry/components/example/linear-gradient-demo.tsx b/registry/components/example/linear-gradient-demo.tsxindex 2f94aa73..20934ded 100644--- a/registry/components/example/linear-gradient-demo.tsx+++ b/registry/components/example/linear-gradient-demo.tsx@@ -3,7 +3,7 @@ import LinearGradient from "@/registry/components/magicui/linear-gradient";export default function LinearGradientDemo() {return (<div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background p-20">- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <p className="text-5xl font-medium tracking-tighter text-black dark:text-white z-10 whitespace-pre-wrap text-center">Linear Gradient</p><LinearGradient />diff --git a/registry/components/example/meteors-demo.tsx b/registry/components/example/meteors-demo.tsxindex 34a7ac8b..ee94ad33 100644--- a/registry/components/example/meteors-demo.tsx+++ b/registry/components/example/meteors-demo.tsx@@ -4,7 +4,7 @@ export default function MeteorDemo() {return (<div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background overflow-hidden p-20"><Meteors />- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <p className="text-5xl font-medium tracking-tighter text-black dark:text-white z-10 whitespace-pre-wrap text-center">Meteors</p><div className="pointer-events-none h-full absolute inset-0 bg-[radial-gradient(circle_at_50%_120%,rgba(120,119,198,0.3),rgba(255,255,255,0))]" />diff --git a/registry/components/example/radial-gradient-demo.tsx b/registry/components/example/radial-gradient-demo.tsxindex a4f7e0cf..e2aa1e0d 100644--- a/registry/components/example/radial-gradient-demo.tsx+++ b/registry/components/example/radial-gradient-demo.tsx@@ -3,7 +3,7 @@ import RadialGradient from "@/registry/components/magicui/radial-gradient";export default function RadialGradientDemo() {return (<div className="border rounded-lg h-full w-full relative flex justify-center items-center bg-background p-20">- <p className="text-5xl font-medium tracking-tighter whitespace-nowrap text-black dark:text-white z-10">+ <p className="text-5xl font-medium tracking-tighter text-black dark:text-white z-10 whitespace-pre-wrap text-center">Radial Gradient</p><RadialGradient />diff --git a/registry/components/example/tweet-card-demo.tsx b/registry/components/example/tweet-card-demo.tsxnew file mode 100644index 00000000..579d65d3--- /dev/null+++ b/registry/components/example/tweet-card-demo.tsx@@ -0,0 +1,5 @@+import TweetCard from "@/registry/components/magicui/tweet-card";++export default function TweetDemo() {+ return <TweetCard id="1668408059125702661" className="w-full h-full" />;+}diff --git a/registry/components/magicui/magic-card.tsx b/registry/components/magicui/magic-card.tsxindex d0a2c594..acb317bd 100644--- a/registry/components/magicui/magic-card.tsx+++ b/registry/components/magicui/magic-card.tsx@@ -1,7 +1,14 @@"use client";import clsx, { ClassValue } from "clsx";-import { CSSProperties, ReactNode, useEffect, useRef, useState } from "react";+import React, {+ CSSProperties,+ ReactElement,+ ReactNode,+ useEffect,+ useRef,+ useState,+} from "react";import { twMerge } from "tailwind-merge";export function cn(...inputs: ClassValue[]) {@@ -110,12 +117,12 @@ const MagicContainer = ({ children, className }: MagicContainerProps) => {interface MagicCardProps {/**- * @default div- * @type React.ElementType+ * @default <div />+ * @type ReactElement* @description- * The component to render the card as+ * The component to be rendered as the card* */- as?: React.ElementType;+ as?: ReactElement;/*** @default ""* @type string@@ -198,7 +205,7 @@ interface MagicCardProps {}const MagicCard = ({- as: Component = "div", // Default to 'div' if no component is passed+ as: Element = <div />, // Default to 'div' if no component is passedclassName,children,size = 600,@@ -216,19 +223,18 @@ const MagicCard = ({const borderStyles ="after:pointer-events-none after:absolute after:w-full after:h-full after:rounded-[var(--border-radius)] after:top-0 after:left-0 after:duration-500 after:transition-opacity after:bg-[radial-gradient(var(--mask-size)_circle_at_var(--mouse-x)_var(--mouse-y),var(--border-color),transparent_40%)] after:z-[1]";- return (- <Component- style={- {- "--border-radius": `${borderRadius}px`,- "--border-width": `${borderWidth}px`,- "--border-color": `${borderColor}`,- "--mask-size": `${size}px`,- "--spotlight-color": `${spotlightColor}`,- background,- } as CSSProperties- }- className={cn(+ return React.cloneElement(+ Element,+ {+ style: {+ "--border-radius": `${borderRadius}px`,+ "--border-width": `${borderWidth}px`,+ "--border-color": `${borderColor}`,+ "--mask-size": `${size}px`,+ "--spotlight-color": `${spotlightColor}`,+ background,+ } as CSSProperties,+ className: cn("relative w-full h-full rounded-[var(--border-radius)] overflow-hidden",isolated && [borderStyles, "after:opacity-0 after:hover:opacity-100"],isolated &&@@ -239,17 +245,16 @@ const MagicCard = ({!isolated && [borderStyles, "after:opacity-[var(--opacity)]"],!isolated &&spotlight && [spotlightStyles, "before:opacity-[var(--opacity)]"]+ ),+ },+ <div+ className={cn(+ "absolute inset-[var(--border-width)] rounded-[var(--border-radius)] z-[2]",+ className)}>- <div- className={cn(- "absolute inset-[var(--border-width)] rounded-[var(--border-radius)] z-[2]",- className- )}- >- {children}- </div>- </Component>+ {children}+ </div>);};diff --git a/registry/components/magicui/tweet-card.tsx b/registry/components/magicui/tweet-card.tsxnew file mode 100644index 00000000..cde3fa12--- /dev/null+++ b/registry/components/magicui/tweet-card.tsx@@ -0,0 +1,165 @@+"use client";++import { Skeleton } from "@/components/ui/skeleton";+import { cn } from "@/lib/utils";+import LinearGradient from "@/registry/components/magicui/linear-gradient";+import { Twitter } from "lucide-react";+import {+ enrichTweet,+ useTweet,+ type EnrichedTweet,+ type TweetProps,+ type TwitterComponents,+} from "react-tweet";+import type { Tweet } from "react-tweet/api";++export const truncate = (str: string | null, length: number) => {+ if (!str || str.length <= length) return str;+ return `${str.slice(0, length - 3)}...`;+};++export const TweetSkeleton = () => (+ <div className="flex flex-col w-full h-full border rounded-lg p-4 gap-2">+ <div className="flex flex-row gap-2">+ <Skeleton className="h-10 w-10 rounded-full shrink-0" />+ <Skeleton className="h-10 w-full" />+ </div>+ <Skeleton className="h-20 w-full" />+ </div>+);++export const TweetNotFound = (_props: { error?: any }) => (+ <div className="flex flex-col w-full h-full border rounded-lg p-4 gap-2 items-center">+ <h3>Tweet not found</h3>+ </div>+);++export const TweetHeader = ({ tweet }: { tweet: EnrichedTweet }) => (+ <div className="flex items-center justify-between tracking-tight">+ <div className="flex items-center space-x-2">+ <a href={tweet.user.url} target="_blank" rel="noreferrer">+ <img+ alt={tweet.user.screen_name}+ height={48}+ width={48}+ src={tweet.user.profile_image_url_https}+ className="overflow-hidden rounded-full border border-transparent"+ />+ </a>+ <div>+ <a+ href={tweet.user.url}+ target="_blank"+ rel="noreferrer"+ className="flex items-center font-semibold"+ >+ {truncate(tweet.user.name, 20)}+ {tweet.user.verified || tweet.user.is_blue_verified ? (+ <svg+ aria-label="Verified Account"+ className="ml-1 inline h-4 w-4 text-blue-500"+ viewBox="0 0 24 24"+ >+ <g fill="currentColor">+ <path d="M22.5 12.5c0-1.58-.875-2.95-2.148-3.6.154-.435.238-.905.238-1.4 0-2.21-1.71-3.998-3.818-3.998-.47 0-.92.084-1.336.25C14.818 2.415 13.51 1.5 12 1.5s-2.816.917-3.437 2.25c-.415-.165-.866-.25-1.336-.25-2.11 0-3.818 1.79-3.818 4 0 .494.083.964.237 1.4-1.272.65-2.147 2.018-2.147 3.6 0 1.495.782 2.798 1.942 3.486-.02.17-.032.34-.032.514 0 2.21 1.708 4 3.818 4 .47 0 .92-.086 1.335-.25.62 1.334 1.926 2.25 3.437 2.25 1.512 0 2.818-.916 3.437-2.25.415.163.865.248 1.336.248 2.11 0 3.818-1.79 3.818-4 0-.174-.012-.344-.033-.513 1.158-.687 1.943-1.99 1.943-3.484zm-6.616-3.334l-4.334 6.5c-.145.217-.382.334-.625.334-.143 0-.288-.04-.416-.126l-.115-.094-2.415-2.415c-.293-.293-.293-.768 0-1.06s.768-.294 1.06 0l1.77 1.767 3.825-5.74c.23-.345.696-.436 1.04-.207.346.23.44.696.21 1.04z" />+ </g>+ </svg>+ ) : null}+ </a>+ <div className="flex items-center space-x-1">+ <a+ href={tweet.user.url}+ target="_blank"+ rel="noreferrer"+ className="text-sm text-gray-500 transition-all duration-75"+ >+ @{truncate(tweet.user.screen_name, 16)}+ </a>+ </div>+ </div>+ </div>+ <a href={tweet.url} target="_blank" rel="noreferrer">+ <span className="sr-only">Link to tweet</span>+ <Twitter className="h-5 w-5 text-[#3BA9EE] transition-all ease-in-out hover:scale-105" />+ </a>+ </div>+);++export const TweetBody = ({ tweet }: { tweet: EnrichedTweet }) => (+ <div className="break-words tracking-tighter leading-normal">+ {tweet.entities.map((entity) => {+ switch (entity.type) {+ case "url":+ case "symbol":+ case "hashtag":+ case "mention":+ return (+ <a+ href={entity.href}+ target="_blank"+ rel="noopener noreferrer"+ className="text-gray-500"+ >+ <span>{entity.text}</span>+ </a>+ );+ case "text":+ return (+ <span+ className="text-sm"+ dangerouslySetInnerHTML={{ __html: entity.text }}+ />+ );+ }+ })}+ </div>+);++type Props = {+ tweet: Tweet;+ components?: TwitterComponents;+ className?: string;+};++export const MyTweet = ({+ tweet: t,+ components,+ className,+ ...props+}: Props) => {+ const tweet = enrichTweet(t);+ return (+ <div+ className={cn(+ "backdrop-blur-md rounded-lg p-4 border relative gap-2 flex flex-col w-full h-full overflow-hidden",+ className+ )}+ {...props}+ >+ <TweetHeader tweet={tweet} />+ <TweetBody tweet={tweet} />+ <LinearGradient />+ </div>+ );+};++export const TweetCard = ({+ id,+ apiUrl,+ fallback = <TweetSkeleton />,+ components,+ onError,+ ...props+}: TweetProps & { className?: string }) => {+ const { data, error, isLoading } = useTweet(id, apiUrl);++ if (isLoading) return fallback;+ if (error || !data) {+ const NotFound = components?.TweetNotFound || TweetNotFound;+ return <NotFound error={onError ? onError(error) : error} />;+ }++ return <MyTweet tweet={data} components={components} {...props} />;+};++export default TweetCard;diff --git a/registry/index.tsx b/registry/index.tsxindex 0d54a74e..857b4682 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -32,11 +32,17 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/dot-pattern.tsx"],},+marquee: {name: "marquee",type: "components:ui",files: ["registry/components/magicui/marquee.tsx"],},+ "tweet-card": {+ name: "tweet-card",+ type: "components:ui",+ files: ["registry/components/magicui/tweet-card.tsx"],+ },};const example: Registry = {@@ -112,6 +118,7 @@ const example: Registry = {() => import("@/registry/components/example/dot-pattern-linear-gradient")),},+"marquee-demo": {name: "marquee-demo",type: "components:example",@@ -128,6 +135,14 @@ const example: Registry = {() => import("@/registry/components/example/marquee-logos")),},+ "tweet-card-demo": {+ name: "tweet-card-demo",+ type: "components:example",+ files: ["registry/components/example/tweet-card-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/tweet-card-demo")+ ),+ },};export const registry: Registry = {diff --git a/tailwind.config.ts b/tailwind.config.tsindex 9a3e42c8..fb9bd063 100644--- a/tailwind.config.ts+++ b/tailwind.config.ts@@ -1,5 +1,4 @@const colors = require("tailwindcss/colors");-import { type Config } from "tailwindcss";/** @type {import('tailwindcss').Config} */@@ -94,6 +93,7 @@ module.exports = {"0%": { transform: "rotateX(45deg) translateY(-50%)" },"100%": { transform: "rotateX(45deg) translateY(0)" },},+marquee: {from: { transform: "translateX(0)" },to: { transform: "translateX(calc(-50% - var(--gap)/2))" },@@ -102,4 +102,4 @@ module.exports = {},},plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")],-} satisfies Config;+};diff --git a/yarn.lock b/yarn.lockindex 820cbf32..d459cbd5 100644--- a/yarn.lock+++ b/yarn.lock@@ -1750,7 +1750,7 @@domhandler "^5.0.3"selderee "^0.10.0"-"@swc/[email protected]":+"@swc/[email protected]", "@swc/helpers@^0.5.1":version "0.5.1"resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.1.tgz#e9031491aa3f26bfcc974a67f48bd456c8a5357a"integrity sha512-sJ902EfIzn1Fa+qYmjdQqh8tPsoxyBz+8yBKC2HKUxyezKJFwPGOn7pv4WY6QuQW//ySQi5lJjA/ZT9sNWWNTg==@@ -6084,6 +6084,16 @@ react-style-singleton@^2.2.1:invariant "^2.2.4"tslib "^2.0.0"+react-tweet@^3.0.3:+ version "3.0.3"+ resolved "https://registry.yarnpkg.com/react-tweet/-/react-tweet-3.0.3.tgz#809d8e8b5889a170ac15e1f77b7717bccf5510b2"+ integrity sha512-dKPpCCGGo07hV8QtOthAwVbG/VfDA22kg5ny53UHnYYMR18gv7hDYiT9ZjMS4hWLzEObz++e616Sf4qLo9hhag==+ dependencies:+ "@swc/helpers" "^0.5.1"+ clsx "^1.2.1"+ date-fns "^2.30.0"+ swr "^2.2.0"+react-wrap-balancer@^1.0.0:version "1.0.0"resolved "https://registry.yarnpkg.com/react-wrap-balancer/-/react-wrap-balancer-1.0.0.tgz#f45f8af7cf68d9d54d16a8cf271047b75d1431d7"@@ -6751,6 +6761,13 @@ supports-preserve-symlinks-flag@^1.0.0:resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==+swr@^2.2.0:+ version "2.2.0"+ resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.0.tgz#575c6ac1bec087847f4c86a39ccbc0043c834d6a"+ integrity sha512-AjqHOv2lAhkuUdIiBu9xbuettzAzWXmCEcLONNKJRba87WAefz8Ca9d6ds/SzrPc235n1IxWYdhJ2zF3MNUaoQ==+ dependencies:+ use-sync-external-store "^1.2.0"+synckit@^0.8.5:version "0.8.5"resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.8.5.tgz#b7f4358f9bb559437f9f167eb6bc46b3c9818fa3"@@ -7162,6 +7179,11 @@ use-sidecar@^1.1.2:detect-node-es "^1.1.0"tslib "^2.0.0"+use-sync-external-store@^1.2.0:+ version "1.2.0"+ resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"+ integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==+util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:version "1.0.2"resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"