Skip to content

Commit

Permalink
docs: expand on contributing guidelines (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhdaware authored Sep 6, 2024
1 parent 6e059a6 commit fd6cd7a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 78 deletions.
106 changes: 93 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing guidelines for `blade`

## Development setup
## Local Development Setup

These steps should get you up and started for local development setup. Please ensure you've NodeJS and Yarn installed on your machine before proceeding.

Expand All @@ -22,7 +22,16 @@ These steps should get you up and started for local development setup. Please en
yarn start:web
```

- That's it!
- That's it! You can access storybook on http://localhost:9009
### Setting up React Native
If you're contributing to React Native parts, you can follow the following setup.

You can skip it if you're contributing to web only component. Our [Component Status Page in Documentation](https://blade.razorpay.com/?path=/docs/guides-component-status--docs) mentions which components are react native supported and which are web only
<details>
<summary><h4>React Native Local Development Setup</h4></summary>
### Setting up iOS
Expand All @@ -38,13 +47,13 @@ These steps should get you up and started for local development setup. Please en
- Install [Xcode](https://reactnative.dev/docs/environment-setup#xcode).
> **Note**
> [!Note]
>
> Sometimes it can take a very long time for Xcode to install. Check [here](https://apple.stackexchange.com/questions/427640/mac-app-store-xcode-download-stuck-at-installing) for troubleshooting.
- Install an iOS 13 simulator in Xcode: Xcode > Preferences > Platforms.
> **Note**
> [!Note]
>
> Sometimes this can get stuck or take a very long time. Check [here](https://stackoverflow.com/questions/29058229/download-xcode-simulator-directly) for troubleshooting.
Expand All @@ -56,7 +65,7 @@ These steps should get you up and started for local development setup. Please en
- Install pods. This can be done by running `pod install` in the `ios/` directory for Intel machine. For M1, things might not work out of box.
> **Note**
> [!Note]
>
> Follow the note [here](https://reactnative.dev/docs/environment-setup#cocoapods) if you're using M1

Expand All @@ -70,9 +79,9 @@ These steps should get you up and started for local development setup. Please en
>
> You don't need to build the app everytime (only when you're changing native dependencies), once the app is built you can just start the storybook server and open the app directly on your simulator

- If the stars aligned correctly, the storybook app should get installed and up and running on the simulator. If not, please refer to the official [guide](https://reactnative.dev/docs/environment-setup) for any deviations.
- If the stars aligned correctly, the storybook app should get installed and up and running on the simulator. If not, please refer to the official [guide](https://reactnative.dev/docs/environment-setup) for any deviations.

*The storybook can take some time to open after simulator starts. Don't worry, it will start after few minutes (hopefully 🤞).*
_The storybook can take some time to open after simulator starts. Don't worry, it will start after few minutes (hopefully 🤞)._
### Setting up Android
Expand All @@ -93,28 +102,99 @@ These steps should get you up and started for local development setup. Please en
yarn start:android
```
> **Note**
> [!Note]
>
> If you already have `yarn start:ios` running, you might have to close it since `yarn start:android` will try to run react-native server on the same port and fail with port taken error.
>
>
> If you want to run both, android and ios at the same time, you can use `yarn start:native` instead.
> **Note**
> [!Note]
>
> Make sure `$ANDROID_SDK_ROOT` is added before running the above command, you can run `echo $ANDROID_SDK_ROOT` in same terminal to confirm. (You can run `source ~/.zshrc` or `source ~/.bash_profile` depending on where you added the variables)
- If the stars aligned correctly, the storybook app should get installed and up and running on the emulator 🎉
## Tips
> [!TIP]
>
> You can use `yarn start:all` command to run storybooks on all platforms like web, android, and ios (better to not use it in development though to avoid stressing your laptop)
</details>
## Codebase Terminologies and Structure
- You can use `yarn start:all` command to run storybooks on all platforms like web, android, and ios (better to not use it in development though to avoid stressing your laptop)
### Base Component Terminology in Code
## TypeScript Guide
We have some base components defined internally such as BaseInput, BaseButton, BaseText which act as a base for multiple exposed components.
E.g.
- Heading, Display, Text all use BaseText internally
- TextInput, PasswordInput, SelectInput all use BaseInput internally
- Majority of our components use BaseBox internally which is a more flexible version of the exposed Box component.
### Cross Platform Guide
You will see files with `.web.tsx` or `.native.tsx` syntax. The `.web.tsx` files end up in web bundle and `.native.tsx` files end up in react native bundle. You can define common logic in normal `.tsx` files which can be imported in both web and native files.
#### Cross Platform TypeScript Guide
[Writing Cross-Platform TypeScript In Blade](./rfcs/writing-cross-platform-typescript.md)
## Testing Changes
### Unit Tests
We have unit tests which you can run by running following commands
```sh
cd packages/blade
yarn test:react # web tests
yarn test:react-native # native tests
```
### Visual Tests
We also have visual tests that run on every PR. So if your PR changes / breaks a certain component, the diff will show up on chromatic checks of PR
<img width="822" alt="image" src="https://github.com/user-attachments/assets/35f6dfd8-ba64-4bc8-a15d-39a3476b6ae8">
### Interaction Tests
We support writing interaction tests using playwright. You can check example interaction tests of toast at [Toast.test.stories.tsx](./packages/blade/src/components/Toast/__tests__/Toast.test.stories.tsx). You can run these tests by visiting the Interaction Tests section in blade documentation E.g. [Toast Stacking Interaction Test on Documentation](https://blade.razorpay.com/?path=/story/components-interaction-tests-toast--toast-stacking)
## Editor Setup
- Make sure you have [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) installed and setup on your VSCode. This will guide you and autofix errors to keep the code consistent with this project's guidelines
- Make sure you have [VSCode MDX](https://marketplace.visualstudio.com/items?itemName=JounQin.vscode-mdx) installed on your VSCode. This will help you with linting the markdown files if you're modifying or adding any `mdx` files for documentation purpose.
- After installing this plugin navigate to your settings and add `mdx` extension to your `eslint` config. Below is how your settings will look after configuring `mdx` to work with eslint
```json
// .vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.options": {
"extensions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx"]
},
"eslint.validate": [
"markdown",
"mdx",
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}
```
## Troubleshooting guidelines
- VSCode auto imports can sometimes mess things up due to import aliases and `.web` / `.native` extensions. If something is breaking weirdly after adding / importing a new module this might be related
- Ensure you're not using any `.web`, `.native` files directly in respective imports in `.web` / `.native` modules. For example, if you end up importing a `.web` module accidentally in a `.native` module, you might see a blank component being rendered or module not found error
- If you forget to import types inside a `.d.ts` file, sometimes TS won't complain and it can throw the typecheck logic in other modules off
- `Blade requires "FRAMEWORK" environment variable to be set. Valid values are "REACT" and "REACT_NATIVE". Instead, received: undefined`
**Issue:** This is an issue that happens mostly if you run `yarn android` directly. For some reason `FRAMEWORK` doesn't gets passed to React Native application

**Fix:** If you come across this issue then you first run `yarn start` and then run `yarn android`.
2 changes: 1 addition & 1 deletion packages/blade/.storybook/react/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const parameters = {
method: 'alphabetical',
order: [
'Guides',
['Intro', 'Installation', 'Local Development', 'How to use?'],
['Intro', 'Installation', 'Contributing', 'How to use?'],
'Tokens',
[
'Colors',
Expand Down
19 changes: 19 additions & 0 deletions packages/blade/docs/guides/Contributing.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meta } from '@storybook/addon-docs';

<Meta title="Guides/Contributing" />

# 🤗 Contributing to Blade

Blade is an open-source project and we accept contributions from our other teams at Razorpay and also from outside of Razorpay. You can checkout the links below to help you get started with contribution

## 🧑🏻‍💻 Local Development and Guidelines

Check out [CONTRIBUTING.md](https://github.com/razorpay/blade/blob/master/CONTRIBUTING.md) for local installation, codebase terminologies, editor setup and more.

## 📄 License

Blade is MIT Licensed. You can read full license at [LICENSE](https://github.com/razorpay/blade/blob/master/LICENSE.md)

## 🏘️ Slack Channel (For Razorpay Employees)

Razorpay Employees can reach out on `#design-system` and tag `@designsystem` for anything related to contributing to Blade.
2 changes: 1 addition & 1 deletion packages/blade/docs/guides/Installation.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Before you install the package, make sure that you have performed the following
<Text>Blade has a few peer dependencies that you may already have installed in your project. If so, you can skip adding them again.</Text>

```shell
yarn add @razorpay/blade styled-components@5.3.11 @razorpay/i18nify-js @razorpay/i18nify-react
yarn add @razorpay/blade styled-components@5.3.11 @razorpay/i18nify-js@1.9.3 @razorpay/i18nify-react@4.0.8
```
<List>
<ListItem>
Expand Down
61 changes: 0 additions & 61 deletions packages/blade/docs/guides/LocalDevelopment.stories.mdx

This file was deleted.

8 changes: 6 additions & 2 deletions packages/blade/src/utils/storybook/componentStatusData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,19 @@ const componentData: ComponentStatusDataType = [
},
{
name: 'Menu',
status: 'in-development',
status: 'released',
description:
'Menu displays a list of actions on temporary surfaces. They allow users to action(s) from multiple options. They appear when users interact with a button, action, or other control.',
releasedIn: '11.22.0',
platform: 'web',
},
{
name: 'TopNav',
status: 'in-development',
status: 'released',
description:
'TopNav is a horizontal navigation component that can be used to navigate between pages.',
releasedIn: '11.23.0',
platform: 'web',
},
{
name: 'SideNav',
Expand Down

0 comments on commit fd6cd7a

Please sign in to comment.