CMS Component Library
Simpleview CMS Component Library
Quick Start
-
Install NodeJS
For Powershell: Download the Windows installer (LTS version)
For WSL/Ubuntu: Run the commands below
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
-
Fork this repository
Click the "Fork" button at the top right of this page
-
Clone your fork to your local machine
git clone ...
cd cms-component-library
-
Install Dependencies
npm install
-
Configure VS Code
Download the ESLint extension for VS Code.
Open your command palette (Ctrl+Shift+P
on Windows and Cmd+Shift+P
on Mac) and search for settings. Select the "Preferences: Open Settings (JSON)" option.
Add the following JSON block to your settings.json file:
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
},
-
Start Storybook
npm run storybook
Visit http://localhost:6006
on your local machine
NPM Scripts
storybook
: Starts up Storybookbuild-storybook
: Builds storybook for production (GitHub Pages)code-quality
: Run type-check, lint, and prettiertype-check
: Run TypeScript against all code to check for type errorslint
: Lint all code, fix anything that can be fixed by eslint
in the processprettier
: Format all code, overwrite filestest
: Run all testsbuild
: Build NPM Package to dist
folderpublish
: Publish NPM release
Structure
.storybook
: Configuration for Storybook__MOCKS__
: Jest mocks, used to stub out API or filesystem calls - Learn Moresrc
: Main source code path
index.tsx
: Main export for NPM package, if a component is not exported here, it won't be in the NPM package (More on NPM below)components
: React components and their corresponding CSS files
ComponentName/ComponetName.spec.tsx
: Tests for ComponentName
component (More on tests below)ComponentName/ComponentName.stories.tsx
: Stories for ComponentName
componet. (More on stories below)ComponentName.module.css
: CSS styles for ComponentName
styles
: Global CSS files
reboot.css
: Cross-browser default styles rebootswatches.css
: Global CSS variables (formerly variables.css
)
hooks
: Path for all custom hookstypes
: Path for all shared typeslib
: Old SV libraries converted to TypeScriptutils
: Generic re-usable utilities
.eslintrc.yml
: ESLint configuration.prettierrc
: Prettier configurationjest.config.ts
: Jest configurationjest.setup.ts
: Jest setup (runs before all tests)
Unit Testing
We use Jest and React Testing Library to unit test every component.
As an example of a basic test, here we are testing the Link component using the getByText query:
import React from 'react';
import { render } from '@testing-library/react';
import Link from '../Link';
describe('Link Component', () => {
it('Renders Correctly', () => {
const to = {
url: 'https://simplevieweinc.com/',
target: '_blank',
};
const childText = 'test text';
const rel = 'noopener noreferrer';
const { getByText } = render(
<Link
to={to}
rel={rel}
>
{childText}
</Link>,
);
const linkElement = getByText(childText);
expect(linkElement).toBeDefined();
expect(linkElement).toHaveProperty('target', to.target);
expect(linkElement).toHaveProperty('href', to.url);
expect(linkElement).toHaveProperty('rel', rel);
});
});
Stories
Storybook is an open source tool for building UI components and pages in isolation. It streamlines UI development, testing, and documentation.
Here is an example of a story for our Link component:
import React from 'react';
import { Link } from '../components';
export default {
title: 'Atoms/Link',
component: Link,
};
function Story(props) {
return <Link {...props}>click me</Link>;
}
export const Primary = Story.bind({});
Primary.args = {
to: {
url: 'https://google.com/',
target: '_blank',
},
};
NPM Package
See the NPM Release Documentation for instructions on deploying new versions to NPM.
Refernces