Skip to content

Commit

Permalink
add Underline
Browse files Browse the repository at this point in the history
  • Loading branch information
seadfeng committed Aug 23, 2024
1 parent 885e9d3 commit 6e96e30
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
43 changes: 31 additions & 12 deletions src/components/frontend/page/style/fonts.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
"use client";
import Copy from "@/components/shared/copy";
import { Button } from "@/components/ui/button";
import { addDoubleUnderline, addStrikethrough, addUnderline, addWavyUnderline } from "@/lib/utils";
import { FontKey, fonts, transforms } from "@/transforms";
import { HTMLAttributes } from "react";
import { HTMLAttributes, useState } from "react";

type TransformMap = { [key: string]: string };

export const Fonts = ({
className,
content,
currentFonts,
underline = false,
strikethrough = false,
doubleUnderline = false,
wavyUnderline = false,
currentFonts
}: {
className?: HTMLAttributes<HTMLDivElement>["className"];
currentFonts: Readonly<FontKey[]>;
content: string;
underline?: boolean;
strikethrough?: boolean;
doubleUnderline?: boolean;
wavyUnderline?: boolean;
content: string;

}) => {

const [underline, setUnderline] = useState(false);
const [strikethrough, setStrikethrough] = useState(false);
const [doubleUnderline, setDoubleUnderline] = useState(false);
const [wavyUnderline, setWavyUnderline] = useState(false);

const FontItem = ({ fontKey }: { fontKey: FontKey }) => {
const chars = transforms[fontKey] as TransformMap;

Expand All @@ -50,9 +49,29 @@ export const Fonts = ({
</div>
);
};

console.log("underline", underline)
return (
<div className={className}>
<div className="flex pb-4 mb-5 border-b">
<div className="flex gap-3">
<Button aria-label="Underline" size="icon" data-underline={underline} variant="outline" onClick={()=> setUnderline(!underline) }
className="data-[underline='true']:font-extrabold data-[underline='true']:bg-primary/25 underline underline-offset-3 rounded-lg dark:border-white/10">
{"U"}
</Button>
<Button aria-label="Double Underline" size="icon" data-doubleUnderline={doubleUnderline} variant="outline" onClick={()=> setDoubleUnderline(!doubleUnderline) }
className="data-[doubleUnderline='true']:font-extrabold data-[doubleUnderline='true']:bg-primary/25 rounded-lg dark:border-white/10">
{"U" + '\u0333'}
</Button>
<Button aria-label="WavyUnderline" size="icon" data-wavyUnderline={wavyUnderline} variant="outline" onClick={()=> setWavyUnderline(!wavyUnderline) }
className="data-[wavyUnderline='true']:font-extrabold data-[wavyUnderline='true']:bg-primary/25 rounded-lg dark:border-white/10">
{"U" + '\u0330'}
</Button>
<Button aria-label="Strikethrough" size="icon" data-strikethrough={strikethrough} variant="outline" onClick={()=> setStrikethrough(!strikethrough) }
className="data-[strikethrough='true']:font-extrabold data-[strikethrough='true']:bg-primary/25 rounded-lg dark:border-white/10">
{"U" + '\u0336'}
</Button>
</div>
</div>
{currentFonts.map(key => <FontItem key={key} fontKey={key} />)}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/frontend/page/style/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function StyleMain({
<div className="md:w-[200px] flex-shrink-0">
<Sidebar />
</div>
<div className="w-full rounded-lg dark:bg-secondary p-8 border">
<div className="w-full rounded-lg dark:bg-secondary px-8 py-5 border">
<Fonts currentFonts={currentFonts} className="mb-10" content={content} />
{block2 && <Markdown content={block2} className="mt-10" />}
</div>
Expand Down

0 comments on commit 6e96e30

Please sign in to comment.