https://github.com/sonics-team/sonics
Free and open source Reactjs ui and utilities library
https://github.com/sonics-team/sonics
react reactjs reactjs-components ui-components utilities
Last synced: 3 months ago
JSON representation
Free and open source Reactjs ui and utilities library
- Host: GitHub
- URL: https://github.com/sonics-team/sonics
- Owner: sonics-team
- License: mit
- Created: 2023-05-08T15:29:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-10T09:55:50.000Z (over 2 years ago)
- Last Synced: 2025-07-06T10:53:43.208Z (7 months ago)
- Topics: react, reactjs, reactjs-components, ui-components, utilities
- Language: TypeScript
- Homepage:
- Size: 7.55 MB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Important Links
## Core Team
Ahmad Al-aqraa
Aous Mohammad
Dyaa Tohan
Mohammad Youssef
Rahaf thiab
Riad Al-saqal
Roula Al-rouhban
Shayar Hasan
## Installation:
-
install pnpm:
```npm install -g pnpm```
-
install all dependencies in root project directory:
```pnpm install```
### Useful Commands
- `pnpm build` - Build all packages, including the Storybook site
- `pnpm dev` - Run all packages locally and preview with Storybook
- `pnpm lint` - Lint all packages
- `pnpm changeset` - Generate a changeset
- `pnpm clean` - Clean up all `node_modules` and `dist` folders (runs each package's clean script)
## Apps & Packages
This Turborepo includes the following packages and applications:
- `apps/docs`: Component documentation site with Storybook
- `apps/web`: React application to use packages and test it
- `packages/@sonics-team/core`: Core React components
- `packages/@sonics-team/utils`: Shared React utilities
- `packages/@sonics-team/tsconfig`: Shared `tsconfig.json`s used throughout the Turborepo
- `packages/@sonics-team/eslint`: ESLint preset
Each package and app is 100% [TypeScript](https://www.typescriptlang.org/). Workspaces enables us to "hoist" dependencies that are shared between packages to the root `package.json`. This means smaller `node_modules` folders and a better local dev experience. To install a dependency for the entire monorepo, use the `-w` workspaces flag with `pnpm add`.
This example sets up your `.gitignore` to exclude all generated files, other folders like `node_modules` used to store your dependencies.
### Compilation
To make the core library code work across all browsers, we need to compile the raw TypeScript and React code to plain JavaScript. We can accomplish this with `tsup`, which uses `esbuild` to greatly improve performance.
Running `pnpm build` from the root of the Turborepo will run the `build` command defined in each package's `package.json` file. Turborepo runs each `build` in parallel and caches & hashes the output to speed up future builds.
For `sonics-core`, the `build` command is the following:
```bash
tsup src/index.tsx --format esm,cjs --dts --external react
```
`tsup` compiles `src/index.tsx`, which exports all of the components in the design system, into both ES Modules and CommonJS formats as well as their TypeScript types. The `package.json` for `sonics-core` then instructs the consumer to select the correct format:
```json:sonics-core/package.json
{
"name": "@sonics-team/core",
"version": "0.0.0",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"sideEffects": false,
}
```
Run `pnpm build` to confirm compilation is working correctly. You should see a folder `sonics-core/dist` which contains the compiled output.
```bash
sonics-core
└── dist
├── index.d.ts <-- Types
├── index.js <-- CommonJS version
└── index.mjs <-- ES Modules version
```
## Components
Each file inside of `sonics-core/src` is a component inside our design system. For example:
```tsx:sonics-core/src/Button.tsx
import * as React from 'react';
export interface ButtonProps {
children: React.ReactNode;
}
export function Button(props: ButtonProps) {
return {props.children};
}
Button.displayName = 'Button';
```
When adding a new file, ensure the component is also exported from the entry `index.tsx` file:
```tsx:sonics-core/src/index.tsx
import * as React from "react";
export { Button, type ButtonProps } from "./Button";
// Add new component exports here
```
## Storybook
Storybook provides us with an interactive UI playground for our components. This allows us to preview our components in the browser and instantly see changes when developing locally. This example preconfigures Storybook to:
- Use Vite to bundle stories instantly (in milliseconds)
- Automatically find any stories inside the `stories/` folder
- Support using module path aliases like `@sonics-core` for imports
- Write MDX for component documentation pages
For example, here's the included Story for our `Button` component:
```js:apps/docs/stories/button.stories.mdx
import { Button } from '@sonics-core/src';
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
# Button
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec euismod, nisl eget consectetur tempor, nisl nunc egestas nisi, euismod aliquam nisl nunc euismod.
## Props
## Examples
Hello
```
This example includes a few helpful Storybook scripts:
- `pnpm dev`: Starts Storybook in dev mode with hot reloading at `localhost:6006`
- `pnpm build`: Builds the Storybook UI and generates the static HTML files
- `pnpm preview-storybook`: Starts a local server to view the generated Storybook UI
## React application for testing
React app allows us to preview our components in the browser and instantly see changes when developing locally
For example, test button:
```js:apps/web/App.tsx
import { Button } from '@sonics-core/src';
export default function App() {
return button from sonics-core
}
```
## Versioning & Publishing Packages
We uses [Changesets](https://github.com/changesets/changesets) to manage versions, create changelogs, and publish to npm. It's preconfigured so you can start publishing packages immediately.
You'll need to create an `NPM_TOKEN` and `GITHUB_TOKEN` and add it to your GitHub repository settings to enable access to npm. It's also worth installing the [Changesets bot](https://github.com/apps/changeset-bot) on your repository.
### Changesets instructions:
- When we fix a bug in @sonics-team/core as example:
1. `cd packages/sonics-core`
2. `npm version patch`
- When we add feature or improve it:
1. `cd packages/sonics-core`
2. `npm version minor`
- When we finish our milestone or reach planned target:
1. `cd packages/sonics-core`
2. `npm version major`
### Generating the Changelog
To generate your changelog, run `pnpm changeset` locally:
1. **Which packages would you like to include?** – This shows which packages and changed and which have remained the same. By default, no packages are included. Press `space` to select the packages you want to include in the `changeset`.
1. **Which packages should have a major bump?** – Press `space` to select the packages you want to bump versions for.
1. If doing the first major version, confirm you want to release.
1. Write a summary for the changes.
1. Confirm the changeset looks as expected.
1. A new Markdown file will be created in the `changeset` folder with the summary and a list of the packages included.
### Releasing
When you push your code to GitHub, the [GitHub Action](https://github.com/changesets/action) will run the `release` script defined in the root `package.json`:
```bash
pnpm release
```
Turborepo runs the `build` script for all publishable packages (excluding docs/web) and publishes the packages to npm. By default, this example includes `sonics` as the npm organization.
