@synanetics/syn-library
v6.0.0
Published
A base UI component library by Synanetics
Maintainers
Keywords
Readme
SYN-library
⭐ Getting started
This project uses node 20
Run npm ci to set up the packages required.
Run npm run build to build the project.
Run npm run storybook to view the UI libraries Storybook documentation.
🦋 Changesets
This project uses changesets to manage the changelog, versioning and publishing to npm. A changeset is a small file that records a change and helps automate versioning.
To create a changeset, run npx changeset after making a change.
This will prompt you to specify the type of change (follow semantic versioning):
- Patch: For backwards compatible bug fixes
- Minor: For adding functionality in a backwards compatible manner
- Major: For incompatible API changes (breaking changes)
You will then be asked for a summary that will be included in the changelog. This should include the Jira reference with the following structure:[[ABC-123](https://synanetics.atlassian.net/browse/ABC-123)] Description of change
A changeset file will be created within the .changeset directory. Ensure that this file is committed and pushed as part of your PR.
Versioning and Publishing
The SYN-library is published to the @synanetics npm repo.
- When a PR with a changeset is merged into the main branch, the GitHub release workflow automatically creates a new PR titled "Version Packages". This PR will:
- Remove processed changeset files
- Update the changelog
- Bump the package version based on the changes
- Once the 'Version Packages' PR is merged, the GitHub release workflow will run again, which publishes the new package version to npm automatically.
🌀 Publishing to Chromatic
The storybook is published on Chromatic
This should be done as part of the chore task that updates the published version so that the published storybook matches the current npm package.
You can redeploy locally or in CI with npm run chromatic.
ℹ The project token was added to the script via the --project-token flag. If you're running Chromatic via continuous integration, we recommend setting the CHROMATIC_PROJECT_TOKEN environment variable in your CI environment. You can then remove the --project-token from your package.json script.
We should perhaps do this!
🖼️ Icons
The library's icons predominantly come from Google's Material Symbols and Icons.
Adding a new icon
- Ensure the icon has been added to the SYN Library's Figma Icon's.
- On Figma, right click the icon you want to add. You should see a purple
20 x 20bounding box appear around it. - Select
Copy as>Copy as SVG. - Create a file in the
src/iconsfolder with your new icon name. It should follow the existing file name convention,[Name]Icon.tsx. - A standard icon should receive at least one prop,
size. Thisnumberwill dictate the height and width of the icon.
Use the following template to structure your icon:
import React from "react"
import { IconProps } from "./IconProps"
export const MyIcon = ({ size = 20 }: IconProps) => {
return (
<svg fill="none" height={size} viewBox="0 0 20 20" width={size} xmlns="http://www.w3.org/2000/svg">
{*/ <mask> */}
{*/ <g> */}
</svg>
)
}- Your
<svg>will likely have a<path>tag within it, with thefillattribute having a hardcoded hex value (likely to be#1E2428). Change this tofill="currentColor". - Export your new icon from the icon folder's barrel file,
src/icons/index.ts - Viewing the Icons story on Storybook should show all icons, including your new one.
- Scroll to the bottom of the icon's Storybook page and change the
colorvalue using the colour wheel. Your icon should change colour.
💻 Local Project Development
You can simultaneously develop this library alongside another local project.
- Navigate to the root directory of this UI library and run
npm link. - Go to the root directory of your local project and run
npm link @synanetics/syn-library. - Remember to run
npm run buildin the library if you make any changes, to ensure your project is using the latest version. Updates should be reflected in your local project immediately.
You will need to re-link the packages if you install other dependencies at any point during local development.
You want to unlink the local instance of the package via:
npm unlink --no-save @synanetics/syn-library
If you have made changes to the UI library and errors occur similar to the following:
SyntaxError: The requested module ABC does not provide an export named 'xyz'
Restarting WSL and VS Code will likely resolve this issue.
🧪 Testing
React Testing Library, Jest & Axe
Each component has a corresponding [Name].test.tsx within it's folder.
React Testing Library is combined with jest-axe to run unit tests and prevent accessibility errors.
To manually run all tests, run npm run test:unit.
Playwright
Playwright is used for integration tests.
Running Playwright tests
Run npm run test:integration
⚙️ Installing and Usage
- Install via
npm i @synanetics/syn-library - At your applications root
scssfile, import the core SCSS file via@use "@synanetics/syn-library/core"; - Import the desired theme SCSS file using one of the following:
Synanetics: @use "@synanetics/syn-library/synanetics"
BCU: @use "@synanetics/syn-library/bcu"
Interweave: @use "@synanetics/syn-library/interweave"
NHS (WIP): @use "@synanetics/syn-library/nhs"
SORA: @use "@synanetics/syn-library/sora"
- Ensure the fonts are installed for each theme by adding the correct link to the html head.
Synanetics: Zilla Slab, Nirmit
BCU: Calibri
Interweave: Nunito, Open sans
NHS (WIP): Arial
SORA: Roboto, Poppins
- Then, anywhere in your application, you can import the required components e.g.
import { Button } from "@synanetics/syn-library";
