so now we're on fly.io
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import clsx from "clsx"
|
||||
import React, { useMemo } from "react"
|
||||
|
||||
export const Avatar: React.FC<
|
||||
{
|
||||
images: (string | null | undefined)[]
|
||||
name?: string | null
|
||||
size?: number
|
||||
rounded?: boolean
|
||||
} & React.HTMLAttributes<HTMLSpanElement>
|
||||
> = ({ images, size, name, className, rounded, ...props }) => {
|
||||
size = size || 60
|
||||
|
||||
const fontSize = size * 0.5
|
||||
|
||||
const nameAbbr = (name || "")
|
||||
.split(" ")
|
||||
.slice(0, 2)
|
||||
.map((word) => word[0])
|
||||
.join("")
|
||||
|
||||
const image = useMemo(() => {
|
||||
for (const image of images) {
|
||||
if (image) return image
|
||||
}
|
||||
}, [images])
|
||||
|
||||
const borderRadius = rounded === false ? "rounded-lg" : "rounded-full"
|
||||
|
||||
if (!image) {
|
||||
return (
|
||||
<span
|
||||
{...props}
|
||||
className={clsx(
|
||||
`inline-flex text-white bg-pink-400 items-center justify-center text-xl font-medium uppercase flex-shrink-0`,
|
||||
borderRadius,
|
||||
className
|
||||
)}
|
||||
style={{
|
||||
width: `${size}px`,
|
||||
height: `${size}px`,
|
||||
fontSize: `${fontSize}px`,
|
||||
}}
|
||||
>
|
||||
{nameAbbr}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<span
|
||||
{...props}
|
||||
className={clsx(
|
||||
`inline-flex text-zinc-500 bg-pink-400 flex-shrink-0 items-center justify-center text-xl font-medium uppercase`,
|
||||
borderRadius,
|
||||
className
|
||||
)}
|
||||
style={{
|
||||
width: `${size}px`,
|
||||
height: `${size}px`,
|
||||
}}
|
||||
>
|
||||
<img
|
||||
className={borderRadius}
|
||||
src={image}
|
||||
width={size}
|
||||
height={size}
|
||||
alt={name || ""}
|
||||
/>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import clsx from "clsx"
|
||||
import React from "react"
|
||||
|
||||
export const Badge: React.FC<{
|
||||
children: React.ReactNode
|
||||
className?: string
|
||||
}> = ({ children, className }) => {
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
`relative rounded uppercase bg-yellow-400 text-white h-5 inline-flex items-center px-1 font-semibold text-xs`,
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import React from "react"
|
||||
import clsx from "clsx"
|
||||
|
||||
export const Button: React.FC<
|
||||
React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
||||
isLoading?: boolean
|
||||
isBlock?: boolean
|
||||
isDisabled?: boolean
|
||||
variant?: "primary" | "secondary" | "text"
|
||||
variantColor?: "green" | "red" | "gray"
|
||||
size?: "sm"
|
||||
rounded?: "full" | "lg"
|
||||
}
|
||||
> = ({
|
||||
type,
|
||||
children,
|
||||
className,
|
||||
isLoading,
|
||||
isDisabled,
|
||||
isBlock,
|
||||
variant,
|
||||
variantColor,
|
||||
size,
|
||||
rounded,
|
||||
...props
|
||||
}) => {
|
||||
return (
|
||||
<button
|
||||
{...props}
|
||||
type={type || "button"}
|
||||
disabled={isDisabled}
|
||||
className={clsx(
|
||||
className,
|
||||
"button",
|
||||
isLoading && "is-loading",
|
||||
isBlock && `is-block`,
|
||||
variantColor && `is-${variantColor}`,
|
||||
isDisabled && `is-disabled`,
|
||||
size && `is-${size}`,
|
||||
`is-${variant || "primary"}`,
|
||||
rounded === "full" ? "rounded-full" : "rounded-lg"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { useEffect, useRef, useState } from "react"
|
||||
import { EditorState } from "@codemirror/state"
|
||||
import {
|
||||
EditorView,
|
||||
keymap,
|
||||
type ViewUpdate,
|
||||
dropCursor,
|
||||
drawSelection,
|
||||
crosshairCursor,
|
||||
placeholder as placeholderExtension,
|
||||
} from "@codemirror/view"
|
||||
import {
|
||||
history,
|
||||
defaultKeymap,
|
||||
historyKeymap,
|
||||
indentWithTab,
|
||||
} from "@codemirror/commands"
|
||||
import { markdown } from "@codemirror/lang-markdown"
|
||||
import {
|
||||
defaultHighlightStyle,
|
||||
indentOnInput,
|
||||
syntaxHighlighting,
|
||||
} from "@codemirror/language"
|
||||
import { IS_PROD } from "~/lib/constants"
|
||||
|
||||
const theme = EditorView.theme({
|
||||
".cm-scroller": {
|
||||
fontFamily: "var(--font-sans)",
|
||||
fontSize: "1rem",
|
||||
overflow: "auto",
|
||||
},
|
||||
".cm-content": {
|
||||
minHeight: "400px",
|
||||
},
|
||||
"&.cm-editor.cm-focused": {
|
||||
outline: "none",
|
||||
},
|
||||
})
|
||||
|
||||
export const useEditor = ({
|
||||
value,
|
||||
onChange,
|
||||
placeholder,
|
||||
onDropFile,
|
||||
}: {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
placeholder?: string
|
||||
onDropFile?: (file: File, view: EditorView) => void
|
||||
}) => {
|
||||
const editorRef = useRef<HTMLDivElement | null>(null)
|
||||
const [view, setView] = useState<EditorView | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const updateListener = EditorView.updateListener.of((vu: ViewUpdate) => {
|
||||
if (vu.docChanged && typeof onChange === "function") {
|
||||
const doc = vu.state.doc
|
||||
const value = doc.toString()
|
||||
onChange(value)
|
||||
}
|
||||
})
|
||||
|
||||
const view = new EditorView({
|
||||
state: EditorState.create({
|
||||
doc: "",
|
||||
extensions: [
|
||||
keymap.of([indentWithTab, ...defaultKeymap, ...historyKeymap]),
|
||||
history(),
|
||||
dropCursor(),
|
||||
drawSelection(),
|
||||
indentOnInput(),
|
||||
crosshairCursor(),
|
||||
EditorState.allowMultipleSelections.of(true),
|
||||
updateListener,
|
||||
EditorView.lineWrapping,
|
||||
markdown(),
|
||||
placeholderExtension(placeholder || ""),
|
||||
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
||||
theme,
|
||||
EditorView.domEventHandlers({
|
||||
drop(e) {
|
||||
const file = e.dataTransfer?.items[0]?.getAsFile()
|
||||
if (!file) return
|
||||
|
||||
onDropFile?.(file, view)
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
parent: editorRef.current!,
|
||||
})
|
||||
|
||||
setView(view)
|
||||
|
||||
return () => {
|
||||
view.destroy()
|
||||
setView(null)
|
||||
}
|
||||
}, [onChange, placeholder, onDropFile])
|
||||
|
||||
// Update view state when `value` changed
|
||||
useEffect(() => {
|
||||
const currentValue = view ? view.state.doc.toString() : ""
|
||||
if (view && value !== currentValue) {
|
||||
if (!IS_PROD) {
|
||||
console.log("updating editor value", value)
|
||||
}
|
||||
view.dispatch({
|
||||
changes: { from: 0, to: currentValue.length, insert: value || "" },
|
||||
})
|
||||
}
|
||||
}, [value, view])
|
||||
|
||||
return {
|
||||
view,
|
||||
editorRef,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import clsx from "clsx"
|
||||
import { DetailedHTMLProps, forwardRef, InputHTMLAttributes } from "react"
|
||||
|
||||
type Props = DetailedHTMLProps<
|
||||
InputHTMLAttributes<HTMLInputElement>,
|
||||
HTMLInputElement
|
||||
> & {
|
||||
label?: string
|
||||
addon?: string
|
||||
isBlock?: boolean
|
||||
error?: string
|
||||
}
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, Props>(function Input(
|
||||
{ label, addon, className, isBlock, error, ...inputProps },
|
||||
ref
|
||||
) {
|
||||
const hasAddon = !!addon
|
||||
return (
|
||||
<div>
|
||||
{label && (
|
||||
<label className="form-label" htmlFor={inputProps.id}>
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<div className="flex items-center">
|
||||
<input
|
||||
{...inputProps}
|
||||
ref={ref}
|
||||
className={clsx(
|
||||
"input",
|
||||
hasAddon && `has-addon`,
|
||||
isBlock && `is-block`,
|
||||
className
|
||||
)}
|
||||
/>
|
||||
{addon && (
|
||||
<span className="flex items-center px-3 text-gray-600 bg-gray-50 h-10 border border-l-0 rounded-r-lg relative -z-10">
|
||||
{addon}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{error && <div className="text-sm mt-1 text-red-500">{error}</div>}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Dialog } from "@headlessui/react"
|
||||
import clsx from "clsx"
|
||||
import React from "react"
|
||||
|
||||
export const Modal: React.FC<{
|
||||
open: boolean
|
||||
setOpen: (open: boolean) => void
|
||||
children: React.ReactNode
|
||||
title?: string
|
||||
titleIcon?: React.ReactNode
|
||||
size?: "md" | "lg" | "sm"
|
||||
}> = ({ open, setOpen, children, title, titleIcon, size = "md" }) => {
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
className="relative z-50"
|
||||
>
|
||||
{/* The backdrop, rendered as a fixed sibling to the panel container */}
|
||||
<div className="fixed inset-0 bg-black/30 z-40" aria-hidden="true" />
|
||||
|
||||
{/* Full-screen container to center the panel */}
|
||||
<div
|
||||
className={clsx(
|
||||
`fixed inset-0 flex items-center justify-center p-4 z-40`,
|
||||
)}
|
||||
>
|
||||
{/* The actual dialog panel */}
|
||||
<Dialog.Panel
|
||||
className={clsx(
|
||||
`mx-auto rounded-lg bg-white w-full shadow-modal -mt-40`,
|
||||
|
||||
size === "md"
|
||||
? `max-w-md`
|
||||
: size === "lg"
|
||||
? `max-w-lg`
|
||||
: `max-w-sm`,
|
||||
)}
|
||||
>
|
||||
{title && (
|
||||
<Dialog.Title className="text-lg border-b h-14 flex items-center px-5 space-x-2">
|
||||
{titleIcon && <span>{titleIcon}</span>}
|
||||
<span>{title}</span>
|
||||
</Dialog.Title>
|
||||
)}
|
||||
{children}
|
||||
</Dialog.Panel>
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import clsx from "clsx"
|
||||
import React from "react"
|
||||
import { UniLink } from "./UniLink"
|
||||
|
||||
export type TabItem = {
|
||||
text: string
|
||||
href?: string
|
||||
onClick?: () => void
|
||||
active?: boolean
|
||||
}
|
||||
|
||||
export const Tabs: React.FC<{ items: TabItem[] }> = ({ items }) => {
|
||||
return (
|
||||
<div className="flex border-b space-x-5 mb-8">
|
||||
{items.map((item) => {
|
||||
return (
|
||||
<UniLink
|
||||
href={item.href}
|
||||
onClick={item.onClick}
|
||||
key={item.text}
|
||||
className={clsx(
|
||||
`border-b-2 text-sm inline-flex items-center h-10`,
|
||||
item.active
|
||||
? `border-accent text-black font-medium`
|
||||
: `text-gray-500 border-transparent hover:border-gray-300`,
|
||||
)}
|
||||
>
|
||||
{item.text}
|
||||
</UniLink>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import Link from "next/link"
|
||||
|
||||
export const UniLink: React.FC<{
|
||||
href?: string
|
||||
onClick?: () => void
|
||||
children: React.ReactNode
|
||||
className?: string
|
||||
}> = ({ href, onClick, children, className }) => {
|
||||
if (onClick) {
|
||||
return (
|
||||
<button className={className} onClick={onClick}>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
if (!href) {
|
||||
console.error("missing href")
|
||||
return null
|
||||
}
|
||||
|
||||
const isExternal = href && /^https?:\/\//.test(href)
|
||||
|
||||
if (isExternal) {
|
||||
return (
|
||||
<a
|
||||
className={className}
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="nofollow noreferrer"
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Link href={href}>
|
||||
<a className={className}>{children}</a>
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user