-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,096 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import bernankez from "@bernankez/eslint-config"; | ||
|
||
export default bernankez({ | ||
unocss: true, | ||
formatters: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
#root { | ||
display: flex; | ||
justify-content: center; | ||
height: 100vh; | ||
height: 100dvh; | ||
width: 100vw; | ||
overflow-x: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type React from "react"; | ||
import { useMemo } from "react"; | ||
import { clsx } from "clsx"; | ||
import { version } from "~/package.json"; | ||
|
||
export interface BadgeProps { | ||
type: "npm" | "github"; | ||
children?: React.ReactNode; | ||
} | ||
|
||
// @unocss-include | ||
export function Badge({ type, children }: BadgeProps) { | ||
const icon = useMemo(() => { | ||
switch (type) { | ||
case "npm": | ||
return "i-tabler:brand-npm text-2xl"; | ||
default: | ||
return "i-tabler:brand-github text-xl"; | ||
} | ||
}, [type]); | ||
|
||
const link = useMemo(() => { | ||
switch (type) { | ||
case "npm": | ||
return "https://www.npmjs.com/package/backmoji"; | ||
case "github": | ||
return "https://github.com/Bernankez/Backmoji"; | ||
default: | ||
return ""; | ||
} | ||
}, [type]); | ||
|
||
const title = useMemo(() => { | ||
switch (type) { | ||
case "npm": | ||
return `v${version}`; | ||
case "github": | ||
return "Backmoji"; | ||
default: | ||
return ""; | ||
} | ||
}, [type]); | ||
|
||
return ( | ||
<div className="group w-fit select-none b-1 b-orange-500 rounded-md b-solid bg-orange-50 text-sm transition hover:bg-orange-500"> | ||
<a className="h-full flex" href={link}> | ||
<div className="h-full flex items-center b-r-1 b-r-orange-500 b-r-solid px-1"> | ||
<div className={clsx("text-orange-800 group-hover:text-white transition", icon)}></div> | ||
</div> | ||
<span className="h-full flex items-center px-1 text-orange-800 transition group-hover:text-white">{children ?? title}</span> | ||
</a> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useMemo } from "react"; | ||
import { type Languages, useHighlighter } from "../hooks/useHighlighter"; | ||
|
||
export interface CodeProps { | ||
code?: string; | ||
children?: React.ReactNode; | ||
lang: Languages; | ||
} | ||
|
||
export function Code({ code, lang, children }: CodeProps) { | ||
const highlighter = useHighlighter(); | ||
const _code = code || children?.toString().trim(); | ||
|
||
const highlightCode = useMemo(() => { | ||
if (!_code) { | ||
return ""; | ||
} | ||
if (!highlighter) { | ||
return _code; | ||
} | ||
return highlighter.codeToHtml(_code, { | ||
lang, | ||
themes: { | ||
light: "rose-pine-dawn", | ||
dark: "rose-pine-moon", | ||
}, | ||
}); | ||
}, [_code, lang, highlighter]); | ||
|
||
return <div className="box-border overflow-hidden rounded-lg p-2" dangerouslySetInnerHTML={{ __html: highlightCode }}></div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useEffect, useState } from "react"; | ||
import { getHighlighter } from "shiki"; | ||
import { n } from "@bernankez/utils"; | ||
|
||
export type Languages = typeof languages[number]; | ||
export type Highlighter = Awaited<ReturnType<typeof resolveHighlighter>>; | ||
|
||
const languages = n(["js", "ts", "javascript", "typescript", "jsx", "tsx", "sh", "bash", "vue"]); | ||
|
||
function resolveHighlighter() { | ||
return getHighlighter({ | ||
themes: ["rose-pine-dawn", "rose-pine-moon"], | ||
langs: languages, | ||
}); | ||
} | ||
|
||
export function useHighlighter() { | ||
const [highlighter, setHighlighter] = useState<Highlighter>(); | ||
|
||
useEffect(() => { | ||
if (!highlighter) { | ||
resolveHighlighter().then(setHighlighter); | ||
} | ||
}, []); | ||
|
||
return highlighter; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.