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

Set up twrnc theming for React Native component library #111

Merged
merged 32 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9ec0a61
Implemented themed twrnc
brianacnguyen Nov 13, 2024
db2ea35
Draft for twrnc implementation
brianacnguyen Nov 13, 2024
540a7e7
Updated dependencies
brianacnguyen Nov 14, 2024
8530131
Updated twrnc dep
brianacnguyen Nov 14, 2024
a73166e
Cleaned up Theme namings
brianacnguyen Nov 14, 2024
6dfe1f9
Updated yarn setup script to include build
brianacnguyen Nov 14, 2024
2e8640b
Merge branch 'main' of https://github.com/MetaMask/metamask-design-sy…
brianacnguyen Nov 14, 2024
bf3e039
Updated dependencies and imports
brianacnguyen Nov 14, 2024
b76a8fd
Added temp -passWithNoTests
brianacnguyen Nov 14, 2024
a44b8da
Updated temp yarn constraints update
brianacnguyen Nov 14, 2024
c1e7e47
Added withThemeProvider test
brianacnguyen Nov 14, 2024
227faf3
Updated test configs
brianacnguyen Nov 14, 2024
252c10d
Updated tests
brianacnguyen Nov 14, 2024
cc4f406
Updated more tests
brianacnguyen Nov 14, 2024
101216f
Updated tests
brianacnguyen Nov 14, 2024
11eba66
Updated withThemeProvider ref
brianacnguyen Nov 14, 2024
d17bdcf
Added props test to withthemeprovider
brianacnguyen Nov 14, 2024
73051b4
Updated withThemeProvider tests
brianacnguyen Nov 14, 2024
595edfc
Updated missed changes
brianacnguyen Nov 14, 2024
b9e985f
Updated twrnc-dependencies
brianacnguyen Nov 14, 2024
aebe56e
Updated twrnc in depcheck
brianacnguyen Nov 15, 2024
7501cc2
Merge branch 'main' into twrnc-package
brianacnguyen Nov 15, 2024
640a871
Moved stories file to ds-rn
brianacnguyen Nov 15, 2024
307dfaf
Merge branch 'twrnc-package' of https://github.com/MetaMask/metamask-…
brianacnguyen Nov 15, 2024
bb830ff
Merge branch 'main' into twrnc-package
brianacnguyen Nov 15, 2024
1a4d78b
Moving twrnc-preset under peerdependencies
brianacnguyen Nov 15, 2024
bfdc92d
Merge branch 'twrnc-package' of https://github.com/MetaMask/metamask-…
brianacnguyen Nov 15, 2024
86ededd
Updated dependencies
brianacnguyen Nov 15, 2024
9008d75
Updated yarn lock
brianacnguyen Nov 15, 2024
37e4def
Updated dependencies again
brianacnguyen Nov 15, 2024
8ddd59b
Removed unneccessary jest config updates
brianacnguyen Nov 15, 2024
d61740b
Updated depcheck
brianacnguyen Nov 15, 2024
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
1 change: 1 addition & 0 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ ignores:
# Ignore dependencies which plug into the NPM lifecycle
- '@lavamoat/preinstall-always-fail'
- 'react-native'
- 'twrnc'
brianacnguyen marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion apps/storybook-react-native/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
'ignorePackages',
{
js: 'always',
jsx: 'never',
jsx: 'always',
brianacnguyen marked this conversation as resolved.
Show resolved Hide resolved
ts: 'never',
tsx: 'never',
},
Expand Down
12 changes: 12 additions & 0 deletions apps/storybook-react-native/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { addDecorator } from '@storybook/react-native';
import {
ColorSet,
ThemeProvider,
Theme,
} from '@metamask/design-system-twrnc-preset';

addDecorator((Story) => (
<ThemeProvider colorSet={ColorSet.Brand} theme={Theme.Default}>
<Story />
</ThemeProvider>
));
2 changes: 2 additions & 0 deletions apps/storybook-react-native/.storybook/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as SystemUI from 'expo-system-ui';
import './config';
import { getStorybookUI } from '@storybook/react-native';
import registerRootComponent from 'expo/build/launch/registerRootComponent';
import './storybook.requires'; // Ensure this file exists and the path is correct
Expand Down
24 changes: 12 additions & 12 deletions apps/storybook-react-native/.storybook/storybook.requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import {
addParameters,
addArgsEnhancer,
clearDecorators,
} from '@storybook/react-native';
} from "@storybook/react-native";

global.STORIES = [
{
titlePrefix: '',
directory: './src',
files: '**/*.stories.?(ts|tsx)',
titlePrefix: "",
directory: "./src",
files: "**/*.stories.?(ts|tsx)",
importPathMatcher:
'^\\.[\\\\/](?:src(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx)?)$',
"^\\.[\\\\/](?:src(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(?:ts|tsx)?)$",
},
];

import '@storybook/addon-ondevice-controls/register';
import '@storybook/addon-ondevice-actions/register';
import "@storybook/addon-ondevice-controls/register";
import "@storybook/addon-ondevice-actions/register";

import { argsEnhancers } from '@storybook/addon-actions/dist/modern/preset/addArgs';
import { argsEnhancers } from "@storybook/addon-actions/dist/modern/preset/addArgs";

import { decorators, parameters } from './preview';
import { decorators, parameters } from "./preview";

if (decorators) {
if (__DEV__) {
// stops the warning from showing on every HMR
require('react-native').LogBox.ignoreLogs([
'`clearDecorators` is deprecated and will be removed in Storybook 7.0',
require("react-native").LogBox.ignoreLogs([
"`clearDecorators` is deprecated and will be removed in Storybook 7.0",
]);
}
// workaround for global decorators getting infinitely applied on HMR, see https://github.com/storybookjs/react-native/issues/185
Expand All @@ -46,7 +46,7 @@ try {
} catch {}

const getStories = () => {
return { './src/Button.stories.tsx': require('../src/Button.stories.tsx') };
return { "./src/Button.stories.tsx": require("../src/Button.stories.tsx") };
};

configure(getStories, module, false);
20 changes: 1 addition & 19 deletions apps/storybook-react-native/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@
"slug": "storybook-react-native",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"web": {
"favicon": "./assets/favicon.png"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remove unneeded things

"userInterfaceStyle": "automatic"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For expo's theme switching capability

}
}
Binary file not shown.
Binary file removed apps/storybook-react-native/assets/favicon.png
Binary file not shown.
Binary file removed apps/storybook-react-native/assets/icon.png
Binary file not shown.
Binary file removed apps/storybook-react-native/assets/splash.png
Binary file not shown.
3 changes: 3 additions & 0 deletions apps/storybook-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
},
"dependencies": {
"@metamask/design-system-react-native": "workspace:^",
"@metamask/design-system-twrnc-preset": "workspace:^",
"@metamask/design-tokens": "^4.1.0",
"expo": "~49.0.23",
"expo-status-bar": "~1.6.0",
"expo-system-ui": "~2.4.0",
"react-native-reanimated": "3.3.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed for dark mode

"uuid": "^3.0.0"
},
Expand Down
4 changes: 3 additions & 1 deletion apps/storybook-react-native/src/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button } from '@metamask/design-system-react-native';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import type { Meta, StoryObj } from '@storybook/react-native';
import React from 'react';
import { View } from 'react-native';
Expand All @@ -15,8 +16,9 @@ export default ButtonMeta;

export const Basic: StoryObj<typeof Button> = {
render: () => {
const tw = useTailwind();
return (
<View>
<View style={tw`bg-primary-default p-3`}>
<Button text="Sample Button" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this here to show the theme switching colors

</View>
);
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"packages/*"
],
"scripts": {
"build": "yarn ts-bridge --project tsconfig.build.json --verbose && yarn workspace @metamask/design-system-react-native build",
"build": "yarn ts-bridge --project tsconfig.build.json --verbose && yarn workspace @metamask/design-system-twrnc-preset build && yarn workspace @metamask/design-system-react-native build",
"build:clean": "rimraf dist '**/*.tsbuildinfo' && yarn build",
"build:docs": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run build:docs",
"build:types": "tsc --build tsconfig.build.json --verbose",
Expand All @@ -29,7 +29,7 @@
"prepack": "./scripts/prepack.sh",
"prepare-preview-builds": "./scripts/prepare-preview-builds.sh",
"publish-previews": "yarn workspaces foreach --all --no-private --parallel --verbose run publish:preview",
"setup": "yarn install",
"setup": "yarn install && yarn build",
"storybook": "yarn workspace @metamask/storybook-react storybook",
"storybook:android": "yarn workspace @metamask/storybook-react-native android",
"storybook:ios": "yarn workspace @metamask/storybook-react-native ios",
Expand Down Expand Up @@ -94,6 +94,7 @@
"semver": "^7.6.3",
"simple-git-hooks": "^2.8.0",
"ts-node": "^10.9.1",
"twrnc": "^4.5.1",
brianacnguyen marked this conversation as resolved.
Show resolved Hide resolved
"typescript": "~5.2.2",
"yargs": "^17.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system-react-native/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
'ignorePackages',
{
js: 'always',
jsx: 'never',
jsx: 'always',
ts: 'never',
tsx: 'never',
},
Expand Down
8 changes: 6 additions & 2 deletions packages/design-system-react-native/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// We use Babel for our tests in scripts/.
module.exports = {
env: {
test: {
presets: [
'module:metro-react-native-babel-preset',
'@babel/preset-env',
'@babel/preset-react',
[
'@babel/preset-react',
{
runtime: 'automatic',
},
],
'@babel/preset-typescript',
],
plugins: [
Expand Down
1 change: 1 addition & 0 deletions packages/design-system-react-native/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ module.exports = merge(baseConfig, {
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
moduleNameMapper: {
'\\.(css|less|scss)$': 'identity-obj-proxy',
'^@components/(.*)$': '<rootDir>/src/components/$1',
brianacnguyen marked this conversation as resolved.
Show resolved Hide resolved
},
});
7 changes: 6 additions & 1 deletion packages/design-system-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dist/"
],
"scripts": {
"build": "tsc --project tsconfig.build.json",
"build": "rm -rf tsconfig.build.tsbuildinfo dist && tsc --project tsconfig.build.json",
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/design-system-react-native",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/design-system-react-native",
Expand All @@ -42,7 +42,11 @@
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/design-system-twrnc-preset": "workspace:^"
},
brianacnguyen marked this conversation as resolved.
Show resolved Hide resolved
"devDependencies": {
"@babel/core": "^7.23.5",
"@babel/preset-env": "^7.26.0",
"@babel/preset-react": "^7.25.9",
"@babel/preset-typescript": "^7.23.3",
Expand All @@ -62,6 +66,7 @@
"typescript": "~5.2.2"
},
"peerDependencies": {
"@metamask/design-tokens": "^4.1.0",
"react": "^18.2.0",
"react-native": "0.72.15"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import React from 'react';
import { TouchableOpacity, Text } from 'react-native';

export type ButtonProps = {
text: string;
};

const Button = ({ text }: ButtonProps) => {
const tw = useTailwind();
return (
<TouchableOpacity>
<TouchableOpacity style={tw`bg-primary-default`}>
<Text>{text}</Text>
</TouchableOpacity>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system-react-native/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import * as components from '.';
describe('Component Exports', () => {
it('should export Button component', () => {
expect(components).toHaveProperty('Button');
expect(typeof components.Button).toBe('function');
expect(typeof components.Button).toBe('object');
});
});
6 changes: 5 additions & 1 deletion packages/design-system-react-native/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default as Button } from './components/Button';
import { withThemeProvider } from '@metamask/design-system-twrnc-preset';

import ButtonComponent from './components/Button';

export const Button = withThemeProvider(ButtonComponent);
6 changes: 5 additions & 1 deletion packages/design-system-react-native/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"types": ["react-native", "jest"],
"emitDeclarationOnly": false
},
"references": [],
"references": [
{
"path": "../design-system-twrnc-preset/tsconfig.build.json"
}
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mcmire suggested to add this

"include": ["./src"]
}
6 changes: 5 additions & 1 deletion packages/design-system-react-native/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
"jsx": "react-native",
"skipLibCheck": true
},
"references": [],
"references": [
{
"path": "../design-system-twrnc-preset"
}
],
"include": ["src/**/*"],
"exclude": ["jest.config.js", ".eslintrc.js", "babel.config.js"]
}
35 changes: 35 additions & 0 deletions packages/design-system-twrnc-preset/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
extends: ['../../.eslintrc.js'],
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
settings: {
'import/resolver': {
typescript: {
tsconfigRootDir: __dirname,
project: './tsconfig.json',
},
},
},
ignorePatterns: [
'.eslintrc.js',
'jest.config.js',
'babel.config.js',
'tailwind.config.js',
],

rules: {
'import/extensions': [
'error',
'ignorePackages',
{
js: 'always',
jsx: 'always',
ts: 'never',
tsx: 'never',
},
],
},
};
17 changes: 17 additions & 0 deletions packages/design-system-twrnc-preset/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
env: {
test: {
presets: [
'module:metro-react-native-babel-preset',
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
['@babel/plugin-transform-class-properties', { loose: true }],
['@babel/plugin-transform-private-methods', { loose: true }],
['@babel/plugin-transform-private-property-in-object', { loose: true }],
],
},
},
};
11 changes: 11 additions & 0 deletions packages/design-system-twrnc-preset/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ module.exports = merge(baseConfig, {
statements: 100,
},
},
preset: 'react-native',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
},
transformIgnorePatterns: [
'node_modules/(?!(react-native|@react-native|@react-navigation)/)',
],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
moduleNameMapper: {
'\\.(css|less|scss)$': 'identity-obj-proxy',
},
});
Loading
Loading