@simpleview/cms-component-library v0.1.10
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 andCmd+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 byeslint
in the processprettier
: Format all code, overwrite filestest
: Run all testsbuild
: Build NPM Package todist
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 pathindex.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 filesComponentName/ComponetName.spec.tsx
: Tests forComponentName
component (More on tests below)ComponentName/ComponentName.stories.tsx
: Stories forComponentName
componet. (More on stories below)ComponentName.module.css
: CSS styles forComponentName
styles
: Global CSS filesreboot.css
: Cross-browser default styles rebootswatches.css
: Global CSS variables (formerlyvariables.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'; // react-testing-library
// We do not need to import Jest, when we run tests
// it is Jest that runs these files, so all Jest
// functions are implicit
import Link from '../Link'; // This is the component we are testing
// We start with `describe`, we are describing our Link component
describe('Link Component', () => {
// We expect that `it` `Renders Correctly`, you can have
// multiple `it` blocks if your component is more complex
// and requires testing different scenarios
it('Renders Correctly', () => {
// Here we are defining some variables to use as props
// for the component
const to = {
url: 'https://simplevieweinc.com/',
target: '_blank',
};
const childText = 'test text';
// This is an extra prop, we also want to make sure they are tested,
// check the Link component to see where the extra props are passed
const rel = 'noopener noreferrer';
// We get any queries we want to use (`getByText` here) from the
// `render` function of react-testing-library, and pass in our
// component with the mock data above, check the documentation
// for react-testing-library for more available queries
const { getByText } = render(
<Link
to={to}
rel={rel}
>
{childText}
</Link>,
);
// We should see the test within `childText` in the rendered component
const linkElement = getByText(childText);
// We expect to have found the element rendered by our component
expect(linkElement).toBeDefined();
// We expect the `target`, `href`, and `rel` attributes to be
// added to the element as defined by the Link component. Check
// the Jest documentation for more on `expect` Matchers.
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';
// The title here translates to the story `Link` in the accordion `Atoms`
export default {
title: 'Atoms/Link',
component: Link,
};
// Render the Link component
function Story(props) {
return <Link {...props}>click me</Link>;
}
// `Primary` is a layout displayed in Storybook,
// we can define multiple layouts if needed.
// The args passed to primary are the props
// that the rendered component will receive.
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
6 days ago
20 days ago
1 month ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
4 months ago
4 months ago
5 months ago
6 months ago
6 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago