Skip to content

Commit

Permalink
chore: move component library from tailwind to sass
Browse files Browse the repository at this point in the history
  • Loading branch information
cprussin committed Nov 21, 2024
1 parent b805816 commit 3f1112a
Show file tree
Hide file tree
Showing 117 changed files with 3,559 additions and 2,527 deletions.
4 changes: 2 additions & 2 deletions apps/api-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"pull:env": "[ $CI ] || VERCEL_ORG_ID=team_BKQrg3JJFLxZyTqpuYtIY0rj VERCEL_PROJECT_ID=prj_gbljYVzp0m5EpCuOF6nZpM4WMFM6 vercel env pull",
"start:dev": "next dev --port 3002",
"start:prod": "next start --port 3002",
"test:format": "jest --selectProjects format",
"test:lint": "jest --selectProjects lint",
"test:format": "prettier --check .",
"test:lint": "eslint .",
"test:types": "tsc"
},
"dependencies": {
Expand Down
10 changes: 1 addition & 9 deletions apps/insights/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
import { fileURLToPath } from "node:url";

import { nextjs, tailwind, storybook } from "@cprussin/eslint-config";

const tailwindConfig = fileURLToPath(
import.meta.resolve(`./tailwind.config.ts`),
);

export default [...nextjs, ...tailwind(tailwindConfig), ...storybook];
export { nextjs as default } from "@cprussin/eslint-config";
4 changes: 2 additions & 2 deletions apps/insights/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"start:dev": "next dev --port 3003",
"start:prod": "next start --port 3003",
"test:format": "prettier --check .",
"test:lint": "jest --selectProjects lint",
"test:lint": "eslint .",
"test:types": "tsc"
},
"dependencies": {
Expand Down Expand Up @@ -55,7 +55,7 @@
"jest": "catalog:",
"postcss": "catalog:",
"prettier": "catalog:",
"tailwindcss": "catalog:",
"sass": "catalog:",
"typescript": "catalog:",
"vercel": "catalog:"
}
Expand Down
6 changes: 0 additions & 6 deletions apps/insights/postcss.config.js

This file was deleted.

10 changes: 1 addition & 9 deletions apps/insights/prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
import { fileURLToPath } from "node:url";

import { base, tailwind, mergeConfigs } from "@cprussin/prettier-config";

const tailwindConfig = fileURLToPath(
import.meta.resolve(`./tailwind.config.ts`),
);

export default mergeConfigs([base, tailwind(tailwindConfig)]);
export { base as default } from "@cprussin/prettier-config";
2 changes: 0 additions & 2 deletions apps/insights/src/app/layout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import "../tailwind.css";

export { Root as default } from "../components/Root";
export { metadata, viewport } from "../metadata";
66 changes: 66 additions & 0 deletions apps/insights/src/components/CopyButton/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@use "@pythnetwork/component-library/theme.scss";

.copyButton {
margin: -#{theme.spacing(0.5)} -0.5em;
display: inline-block;
white-space: nowrap;
border-radius: theme.border-radius("md");
padding: theme.spacing(0.5) 0.5em;
border: none;
background: none;
cursor: pointer;
transition: background-color 100ms linear;
outline: none;

.iconContainer {
position: relative;
top: 0.125em;
margin-left: theme.spacing(1);
display: inline-block;

.copyIconContainer {
opacity: 0.5;
transition: opacity 100ms linear;

.copyIcon {
width: 1em;
height: 1em;
}

.copyIconLabel {
@include theme.sr-only;
}
}

.checkIcon {
position: absolute;
inset: 0;
color: theme.color("states", "success", "normal");
opacity: 0;
transition: opacity 100ms linear;
}
}

&[data-hovered] {
background-color: theme.color("button", "outline", "background", "hover");
}

&[data-pressed] {
background-color: theme.color("button", "outline", "background", "active");
}

&[data-focus-visible] {
outline: 1px auto currentcolor;
outline-offset: theme.spacing(1);
}

&[data-is-copied] .iconContainer {
.copyIconContainer {
opacity: 0;
}

.checkIcon {
opacity: 1;
}
}
}
21 changes: 10 additions & 11 deletions apps/insights/src/components/CopyButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"use client";

import { Copy, Check } from "@phosphor-icons/react/dist/ssr";
import { Check } from "@phosphor-icons/react/dist/ssr/Check";
import { Copy } from "@phosphor-icons/react/dist/ssr/Copy";
import { useLogger } from "@pythnetwork/app-logger";
import { UnstyledButton } from "@pythnetwork/component-library/UnstyledButton";
import clsx from "clsx";
import { type ComponentProps, useCallback, useEffect, useState } from "react";

import styles from "./index.module.scss";

type CopyButtonProps = ComponentProps<typeof UnstyledButton> & {
text: string;
};
Expand Down Expand Up @@ -51,11 +54,7 @@ export const CopyButton = ({
return (
<UnstyledButton
onPress={copy}
isDisabled={isCopied}
className={clsx(
"group/copy-button mx-[-0.5em] -mt-0.5 inline-block whitespace-nowrap rounded-md px-[0.5em] py-0.5 outline-none outline-0 outline-steel-600 transition data-[hovered]:bg-black/5 data-[focus-visible]:outline-2 dark:outline-steel-300 dark:data-[hovered]:bg-white/10",
className,
)}
className={clsx(styles.copyButton, className)}
{...(isCopied && { "data-is-copied": true })}
{...props}
>
Expand All @@ -64,12 +63,12 @@ export const CopyButton = ({
<span>
{typeof children === "function" ? children(...args) : children}
</span>
<span className="relative top-[0.125em] ml-1 inline-block">
<span className="opacity-50 transition-opacity duration-100 group-data-[is-copied]/copy-button:opacity-0">
<Copy className="size-[1em]" />
<div className="sr-only">Copy to clipboard</div>
<span className={styles.iconContainer}>
<span className={styles.copyIconContainer}>
<Copy className={styles.copyIcon} />
<div className={styles.copyIconLabel}>Copy to clipboard</div>
</span>
<Check className="absolute inset-0 text-green-600 opacity-0 transition-opacity duration-100 group-data-[is-copied]/copy-button:opacity-100" />
<Check className={styles.checkIcon} />
</span>
</>
)}
Expand Down
6 changes: 2 additions & 4 deletions apps/insights/src/components/Error/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { useLogger } from "@pythnetwork/app-logger";
import { Button } from "@pythnetwork/component-library/Button";
import { useEffect } from "react";

import { MaxWidth } from "../MaxWidth";

type Props = {
error: Error & { digest?: string };
reset?: () => void;
Expand All @@ -17,13 +15,13 @@ export const Error = ({ error, reset }: Props) => {
}, [error, logger]);

return (
<MaxWidth>
<div>
<h1>Uh oh!</h1>
<h2>Something went wrong</h2>
<p>
Error Details: <strong>{error.digest ?? error.message}</strong>
</p>
{reset && <Button onPress={reset}>Reset</Button>}
</MaxWidth>
</div>
);
};
6 changes: 6 additions & 0 deletions apps/insights/src/components/H1/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@use "@pythnetwork/component-library/theme.scss";

.h1 {
font-size: theme.font-size("2xl");
font-weight: theme.font-weight("medium");
}
4 changes: 3 additions & 1 deletion apps/insights/src/components/H1/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import clsx from "clsx";
import type { ComponentProps } from "react";

import styles from "./index.module.scss";

export const H1 = ({ className, children, ...props }: ComponentProps<"h1">) => (
<h1 className={clsx(className, "text-2xl font-medium")} {...props}>
<h1 className={clsx(styles.h1, className)} {...props}>
{children}
</h1>
);
5 changes: 5 additions & 0 deletions apps/insights/src/components/Loading/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use "@pythnetwork/component-library/theme.scss";

.loading {
@include theme.max-width;
}
8 changes: 4 additions & 4 deletions apps/insights/src/components/Loading/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Skeleton } from "@pythnetwork/component-library/Skeleton";

import styles from "./index.module.scss";
import { H1 } from "../H1";
import { MaxWidth } from "../MaxWidth";

export const Loading = () => (
<MaxWidth>
<div className={styles.loading}>
<H1>
<Skeleton className="w-60" />
<Skeleton width={60} />
</H1>
</MaxWidth>
</div>
);
9 changes: 0 additions & 9 deletions apps/insights/src/components/MaxWidth/index.tsx

This file was deleted.

6 changes: 2 additions & 4 deletions apps/insights/src/components/NotFound/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ButtonLink } from "@pythnetwork/component-library/Button";

import { MaxWidth } from "../MaxWidth";

export const NotFound = () => (
<MaxWidth>
<div>
<h1>Not Found</h1>
<p>{"The page you're looking for isn't here"}</p>
<ButtonLink href="/">Go Home</ButtonLink>
</MaxWidth>
</div>
);
5 changes: 5 additions & 0 deletions apps/insights/src/components/Overview/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use "@pythnetwork/component-library/theme.scss";

.overview {
@include theme.max-width;
}
6 changes: 3 additions & 3 deletions apps/insights/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styles from "./index.module.scss";
import { H1 } from "../H1";
import { MaxWidth } from "../MaxWidth";

export const Overview = () => (
<MaxWidth>
<div className={styles.overview}>
<H1>Overview</H1>
</MaxWidth>
</div>
);
Loading

0 comments on commit 3f1112a

Please sign in to comment.