Skip to content

Commit

Permalink
Feat(copy): Setup and verify text primitives (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahehall authored May 21, 2023
1 parent d9e2e41 commit b09ba56
Show file tree
Hide file tree
Showing 26 changed files with 234 additions and 70 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

##### BUN

- [classnames](https://github.com/JedWatson/classnames)
- [barrelsby](https://github.com/bencoveney/barrelsby)
- [eden](https://elysiajs.com/plugins/eden/overview.html)
- [elysia](https://elysiajs.com/introduction.html)
Expand All @@ -65,6 +66,9 @@
- [typefest](https://github.com/sindresorhus/type-fest)
- [react waypoint](https://github.com/civiccc/react-waypoint)
- [react ideal image](https://github.com/stereobooster/react-ideal-image/tree/master)
- [react aria](https://react-spectrum.adobe.com/react-aria/)
- [axe core npm](https://github.com/dequelabs/axe-core-npm)
- [axe core](https://github.com/dequelabs/axe-core)

##### NIM

Expand Down
4 changes: 1 addition & 3 deletions apps/apps.backend.tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "./apps.tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false
}
"compilerOptions": {}
}
4 changes: 1 addition & 3 deletions apps/apps.frontend.tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "./apps.tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true
}
"compilerOptions": {}
}
1 change: 0 additions & 1 deletion apps/nirvlife/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const PROJECT_ROOT = import.meta.dir;
const PUBLIC_DIR = path.resolve(PROJECT_ROOT, "public");
const BUILD_DIR = path.resolve(PROJECT_ROOT, "build");

// TODO(noah): doesnt clean dir
await Bun.build({
entrypoints: ["./src/main.tsx"],
outdir: "./build",
Expand Down
8 changes: 7 additions & 1 deletion apps/nirvlife/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
"@tanstack/react-query-devtools": "4.29.7",
"@tanstack/react-query-persist-client": "4.29.7",
"@tanstack/react-table": "8.9.1",
"classnames": "^2.3.2",
"ky": "0.33.3",
"react": "18.2.0",
"react-aria": "^3.24.0",
"react-dom": "18.2.0",
"react-ideal-image": "[email protected]:noahehall/react-ideal-image.git#72d7328",
"react-query-kit": "^1.4.4",
Expand All @@ -38,6 +40,7 @@
"web-vitals": "3.3.1"
},
"devDependencies": {
"@axe-core/react": "^4.7.1",
"@types/react": "18.2.6",
"@types/react-dom": "18.2.4",
"@types/react-router-dom": "5.3.3",
Expand All @@ -48,13 +51,16 @@
"postcss-flexbugs-fixes": "5.0.2",
"prettier": "^2.8.8",
"react-refresh": "0.14.0",
"turbo": "^1.9.8",
"type-fest": "^3.10.0",
"typescript": "beta"
},
"scripts": {
"barrels": "barrelsby --config ./barrels.json",
"rm:cache": "bun pm cache rm",
"dev": "rm -rf build/* && bun run --watch dev.tsx",
"postdev": "bun --hot src/main.tsx",
"rm:cache": "bun pm cache rm",
"test:types": "bunx tsc",
"upgrade:bun": "bun upgrade --canary",
"upgrade:deps": "bunx ncu -u && bun install"
}
Expand Down
12 changes: 1 addition & 11 deletions apps/nirvlife/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,7 @@
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
<main id="root"></main>
<script src="/main.js" async type="module"></script>
</body>
</html>
5 changes: 2 additions & 3 deletions apps/nirvlife/src/Components/App/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Container, CssBaseline, ThemeProvider } from "@mui/material";
import { Outlet, ScrollRestoration } from "react-router-dom";

import { AppHeader } from "Components";
import { AppHeader, AppFooter } from "Components";
import { APP_KEY } from "data/constants";
import { AppTheme } from "Theme";

// <img src={"/img/logo_main.png"} className="App-logo" alt="logo" />

export const App = () => {
return (
<ThemeProvider theme={AppTheme}>
Expand All @@ -15,6 +13,7 @@ export const App = () => {
<Container disableGutters id="app-container" key="container">
<Outlet />
</Container>
<AppFooter />
<ScrollRestoration key="scroll" />
</ThemeProvider>
);
Expand Down
5 changes: 0 additions & 5 deletions apps/nirvlife/src/Components/App/AppAbout.tsx

This file was deleted.

12 changes: 12 additions & 0 deletions apps/nirvlife/src/Components/App/AppFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { FC } from "react";

import { slogan } from "data";
import { TextCopy } from "Library";

export const AppFooter: FC = () => (
<footer>
<h5>
<TextCopy data={slogan} />
</h5>
</footer>
);
9 changes: 7 additions & 2 deletions apps/nirvlife/src/Components/App/AppHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React, { FC } from "react";
import { FC } from "react";

import { nirvai, nirvaiRef } from "data";
import { TextCopy } from "Library";

export const AppHeader: FC = () => (
<header>
<h1>Some New App</h1>
<h1>
<TextCopy data={nirvai} EL="button" />
</h1>
</header>
);
11 changes: 7 additions & 4 deletions apps/nirvlife/src/Components/App/AppLandingScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { useTheme } from "@mui/material";

import { AppAbout } from "./AppAbout";
import { Img } from "Library";
import { Img, TextCopy } from "Library";
import { ctaStacks, nirvaiRef, taglineRef } from "data";
// <img src={"/img/logo_main.png"} className="img" alt="nirvai" />

const screenId = "app-landing-screen";
export const AppLandingScreen = () => {
const theme = useTheme();

return (
<article>
<article id={screenId}>
{/* <Img key="img" uris={["/img/girljumping.jpg"]} width={500} height={500} /> */}
<AppAbout key="appabout" />
<TextCopy data={ctaStacks[0][0]} />
<TextCopy data={nirvaiRef} longform />
<TextCopy data={taglineRef} full />
</article>
);
};
2 changes: 1 addition & 1 deletion apps/nirvlife/src/Components/App/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*/

export * from "./App";
export * from "./AppAbout";
export * from "./AppFooter";
export * from "./AppHeader";
export * from "./AppLandingScreen";
59 changes: 48 additions & 11 deletions apps/nirvlife/src/Library/Clickable/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@
import type { FC } from "react";
import {
useLink,
useButton,
type AriaLinkOptions,
type AriaButtonProps,
} from "react-aria";
import { useMemo, useRef, type FC } from "react";
import classNames from "classnames";
import { Link, Button, type ButtonProps, type LinkProps } from "@mui/material";

import type { CopyLinkInterface } from "data";

export type LinkA = LinkProps & AriaLinkOptions;
export const LinkA: FC<LinkA> = (props) => {
const ref = useRef(null);
const { linkProps } = useLink(props, ref);

return <Link {...props} />;
};

export type LinkButton = ButtonProps & AriaButtonProps;
export const LinkButton: FC<LinkButton> = (props) => {
let ref = useRef();
let { buttonProps } = useButton(props, ref);

return <Button {...props} ref={ref} />;
};

export interface LinkInterface extends CopyLinkInterface {
//
tab?: boolean;
classes?: string;
EL?: keyof Pick<JSX.IntrinsicElements, "a" | "button">;
linkProps?: AriaLinkOptions & AriaButtonProps & ButtonProps & LinkProps;
[x: string]: any;
}

export const LinkTo: FC<LinkInterface> = ({
url,
copy,

//
tab = false,
classes,
EL = "a",
url = "#",
linkProps = {},
...props
}) => (
<a href={url} target={(tab && "_blank") || "_self"} {...props}>
{copy}
</a>
);
}) => {
const baseProps = useMemo(
() => ({
className: classNames("link", classes),
href: url,
...linkProps,
}),
[classes, linkProps]
);

return EL === "a" ? (
<LinkA {...baseProps}>{copy}</LinkA>
) : (
<LinkButton {...baseProps}>{copy}</LinkButton>
);
};
83 changes: 77 additions & 6 deletions apps/nirvlife/src/Library/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,84 @@
import type { FC } from "react";
import { useMemo, type FC } from "react";
import classNames from "classnames";

import { LinkTo } from "Library";
import type { CopyInterface } from "data";

/**
* keep this as minimal as possible so its fully automated
* prefer a higher order component like TextCopy for customization
*/
export interface TextInterface extends Pick<CopyInterface, "copy"> {
//
url?: string;
classes?: string;
EL?: keyof JSX.IntrinsicElements;
[x: string]: any;
}
export const Text: FC<TextInterface> = ({ copy, ...props }) => (
<span className="ima text" {...props}>
{copy}
</span>
);
export const Text: FC<TextInterface> = ({ copy, classes, EL, ...props }) => {
const cn = useMemo(() => classNames("text", classes), [classes]);

if (props.url || EL === "a" || EL === "button")
return <LinkTo classes={cn} copy={copy} {...props} EL={EL as "a" & "b"} />;
if (Array.isArray(copy))
return (
<p>
{copy.map((text, i) => (
<Text
copy={`${text}${i + 1 < copy.length ? " " : ""}`}
classes={classes}
EL={EL}
{...props}
key={`${text}-${i}`}
/>
))}
</p>
);

const MyEl = EL || "span";
return (
<MyEl className={cn} {...props}>
{copy}
</MyEl>
);
};

/*
* accepts a standard copy interface with additional props
* for specifying exactly how to render in a given context
*/
export interface TextCopy extends Omit<TextInterface, "copy"> {
data: CopyInterface;
//
textProps?: Omit<TextInterface, "copy">;
longform?: boolean;
}
export const TextCopy: FC<TextCopy> = ({
data,
//
longform = false,
classes,
EL,
textProps = {},
}) => {
const elementProps = useMemo(() => {
switch (EL) {
case "a":
return {
url: data.url,
};
default:
return {};
}
}, [data, EL]);

return (
<Text
{...elementProps}
{...textProps}
classes={classes}
copy={(longform && data.longform) || data.copy}
EL={EL}
/>
);
};
39 changes: 39 additions & 0 deletions apps/nirvlife/src/Theme/colorList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// brightest
// #00f2c1
// #1d35e9
// #2f9ef9
// #7200c7
// #99ff99
// #ae4132
// #b5b6d2
// #d7b428
// #e6d7a9
// #eb1e0b
// #f2931e
// #f62e00
// #ff000c
// #ff4d50
// #ffff00
// #ffffcc
// #ffffda

// bright
// #10739e
// #12aab5
// #2a00a7
// #303197
// #3f0033
// #52bf5d
// #6f008c

// darkest
// #030414
// #091a53
// #141414
// #1f2140

// dark
// #08427b
// #23445d
// #2e2e2e
// #333536
1 change: 1 addition & 0 deletions apps/nirvlife/src/Theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
export * from "./AppTheme";
export * from "./LinkBehavior";
export * from "./breakpoints";
export * from "./colorList";
export * from "./components";
export * from "./palette";
export * from "./styleOverrides";
Expand Down
Loading

0 comments on commit b09ba56

Please sign in to comment.