Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add react strict dom #59

Merged
merged 13 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
node-version: 20

- name: Install packages
run: npm ci
run: npm ci --include=optional

- name: Lint
run: npm run lint
Expand Down
30,623 changes: 11,707 additions & 18,916 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"nx": "18.1.2",
"typescript": "5.6.3"
},
"optionalDependencies": {
"@nx/nx-linux-x64-gnu": "18.1.2",
"@rollup/rollup-linux-x64-gnu": "4.25.0"
},
"workspaces": [
"packages/*"
]
Expand Down
41 changes: 4 additions & 37 deletions packages/mobile-app/app/(tabs)/ui.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from "react";
import { Text } from "react-native";
import { useColorScheme, View, Text } from "react-native";
import { Button } from "@ironfish/tackle-box";
import { Appearance, useColorScheme, View } from "react-native";
import { useState } from "react";

export default function UiKit() {
const scheme = useColorScheme();
Expand All @@ -15,40 +14,8 @@ export default function UiKit() {
}}
>
<Text>Count: {count}</Text>
<View
onPointerDown={() => {
setCount(count + 1);
}}
style={{ height: 100, width: 100, backgroundColor: "blue" }}
/>

<Button
label="Toggle color scheme"
onPress={() => {
Appearance.setColorScheme(scheme === "dark" ? "light" : "dark");
}}
/>

{/* Solid */}
<Button label="Click me" />

{/* Solid with icon */}
<Button iconLeft="arrow-left-bottom" label="Click me" />

{/* Solid small */}
<Button label="Click me" size="sm" />

{/* Solid disabled */}
<Button iconLeft="arrow-left-bottom" label="Click me" disabled />

{/* Outline */}
<Button label="Click me" variant="outline" />

{/* Outline with icon */}
<Button iconLeft="arrow-left-bottom" label="Click me" variant="outline" />

{/* Outline small */}
<Button label="Click me" size="sm" variant="outline" />
<Button title="Press me" onClick={() => setCount(count + 1)} />
<Button disabled title="Press me" onClick={() => setCount(count + 1)} />
</View>
);
}
31 changes: 14 additions & 17 deletions packages/mobile-app/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import { useColorScheme } from "react-native";
import { FacadeProvider, useFacade } from "../data/facades";
import { useEffect, useState } from "react";
import { ColorScheme } from "@ironfish/tackle-box";

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -65,22 +64,20 @@ export default function Layout() {
const scheme = useColorScheme();
return (
<ThemeProvider value={scheme === "dark" ? DarkTheme : DefaultTheme}>
<ColorScheme value={scheme === "dark" ? "_dark" : "_light"}>
<QueryClientProvider client={queryClient}>
<FacadeProvider>
<DatabaseLoader>
<Stack>
<Stack.Screen
name="(tabs)"
options={{
headerShown: false,
}}
/>
</Stack>
</DatabaseLoader>
</FacadeProvider>
</QueryClientProvider>
</ColorScheme>
<QueryClientProvider client={queryClient}>
<FacadeProvider>
<DatabaseLoader>
<Stack>
<Stack.Screen
name="(tabs)"
options={{
headerShown: false,
}}
/>
</Stack>
</DatabaseLoader>
</FacadeProvider>
</QueryClientProvider>
</ThemeProvider>
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/mobile-app/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ module.exports = (() => {
},
assetExts: resolver.assetExts.filter((ext) => ext !== "svg"),
sourceExts: [...resolver.sourceExts, "svg"],
unstable_enablePackageExports: true,
unstable_conditionNames: ["browser", "require", "react-native"],
};

config.transformer = {
Expand Down
8 changes: 5 additions & 3 deletions packages/mobile-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
"process": "^0.11.10",
"protobufjs": "^7.3.0",
"react": "18.2.0",
"react-native": "0.74.5",
"react-native": "0.75.4",
"react-native-safe-area-context": "4.10.5",
"react-native-screens": "3.31.1",
"react-native-screens": "~3.34.0",
"react-native-svg": "15.2.0",
"zod": "^3.22.4"
"zod": "^3.22.4",
"react-native-reanimated": "~3.15.0",
"react-native-gesture-handler": "~2.18.1"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
5 changes: 0 additions & 5 deletions packages/tackle-box/.eslintrc.json

This file was deleted.

25 changes: 24 additions & 1 deletion packages/tackle-box/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
/icons
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
28 changes: 0 additions & 28 deletions packages/tackle-box/.storybook/main.ts

This file was deleted.

26 changes: 0 additions & 26 deletions packages/tackle-box/.storybook/preview.tsx

This file was deleted.

50 changes: 50 additions & 0 deletions packages/tackle-box/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite
Copy link
Contributor

@cgjohn cgjohn Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we will probably want to make it more personalized to the project but nbd for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, def. We should probably just start adding these things as backlog items to the project. I'll add one for Tackle Box README


This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
7 changes: 0 additions & 7 deletions packages/tackle-box/babel.config.js

This file was deleted.

28 changes: 28 additions & 0 deletions packages/tackle-box/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";

export default tseslint.config(
{ ignores: ["dist"] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ["**/*.{ts,tsx}"],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
"react-hooks": reactHooks,
"react-refresh": reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
},
);
13 changes: 13 additions & 0 deletions packages/tackle-box/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
53 changes: 53 additions & 0 deletions packages/tackle-box/lib/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { html, css } from "react-strict-dom";
import { ComponentProps } from "react";

const colors = css.defineVars({
black: "#000",
white: "#fff",
grayLight: "#DEDFE2",
grayMedium: "#989898",
grayDark: "#353535",
});

const styles = css.create({
base: {
backgroundColor: {
default: colors.black,
":active": colors.grayDark,
},
borderWidth: 0,
color: colors.white,
textAlign: "center",
paddingTop: 14,
paddingBottom: 14,
paddingLeft: 24,
paddingRight: 24,
fontSize: 20,
borderRadius: 9999,
},
disabled: {
backgroundColor: colors.grayLight,
color: colors.grayMedium,
},
});

type ButtonProps = ComponentProps<typeof html.button>;

type Props = Pick<ButtonProps, "onClick"> & {
title: string;
disabled?: boolean;
};

export function Button({ title, disabled, onClick }: Props) {
return (
<html.button
style={[styles.base, disabled && styles.disabled]}
onClick={(e) => {
if (disabled) return;
onClick?.(e);
}}
>
{title}
</html.button>
);
}
1 change: 1 addition & 0 deletions packages/tackle-box/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Button } from "./components/Button/Button";
Loading
Loading