Skip to content

Commit

Permalink
Add Storybook (#18)
Browse files Browse the repository at this point in the history
* Add Storybook to @atj/design and move all the React components from @atj/spotlight into @atj/design.

* Add story for form section

* Add story for FormEdit, and start using PascalCase and default exports for React component module names.

* Add story for FormDelete

* Add FormView story

* Update mock router for DocumentImporter story

* Add root form section to Storybook

* Add Storybook build to Astro build, via symlink in the public directory.

* Fix build errors

* Tweak design build order so styles are available to Storybook
  • Loading branch information
danielnaab authored Jan 16, 2024
1 parent 7229c23 commit f64ef1e
Show file tree
Hide file tree
Showing 68 changed files with 8,053 additions and 1,522 deletions.
8 changes: 3 additions & 5 deletions apps/spotlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"scripts": {
"astro": "astro",
"build": "astro build",
"clean": "rm -rf dist",
"dev": "astro dev",
"preview": "astro preview",
"start": "astro dev"
"preview": "astro preview"
},
"dependencies": {
"@astrojs/react": "^3.0.3",
Expand All @@ -19,9 +19,7 @@
"astro": "^3.5.4",
"cheerio": "1.0.0-rc.12",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.49.3",
"react-router-dom": "^6.21.1"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@astrojs/check": "^0.3.1",
Expand Down
1 change: 1 addition & 0 deletions apps/spotlight/public/design
2 changes: 1 addition & 1 deletion apps/spotlight/src/components/Header.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import closeSvg from '@atj/design/dist/uswds/images/usa-icons/close.svg';
import closeSvg from '@atj/design/static/uswds/images/usa-icons/close.svg';
---

<header class="usa-header usa-header--basic usa-header--megamenu"></header>
22 changes: 10 additions & 12 deletions apps/spotlight/src/components/UsaBanner.astro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
import iconDotGov from '@atj/design/dist/uswds/img/icon-dot-gov.svg';
import iconHttps from '@atj/design/dist/uswds/img/icon-https.svg';
import usFlagSmall from '@atj/design/dist/uswds/img/us_flag_small.png';
import iconDotGov from '@atj/design/static/uswds/img/icon-dot-gov.svg';
import iconHttps from '@atj/design/static/uswds/img/icon-https.svg';
import usFlagSmall from '@atj/design/static/uswds/img/us_flag_small.png';
---

<section class="usa-banner" aria-label="Official government website">
Expand All @@ -28,9 +28,7 @@ import usFlagSmall from '@atj/design/dist/uswds/img/us_flag_small.png';
aria-expanded="false"
aria-controls="gov-banner-default"
>
<span class="usa-banner__button-text">
Here’s how you know
</span>
<span class="usa-banner__button-text"> Here’s how you know</span>
</button>
</div>
</header>
Expand All @@ -51,8 +49,8 @@ import usFlagSmall from '@atj/design/dist/uswds/img/us_flag_small.png';
<div class="usa-media-block__body">
<p>
<strong>Official websites use .gov</strong>
<br />A <strong>.gov</strong> website belongs to an official
government organization in the United States.
<br />A <strong>.gov</strong> website belongs to an official government
organization in the United States.
</p>
</div>
</div>
Expand Down Expand Up @@ -87,12 +85,12 @@ import usFlagSmall from '@atj/design/dist/uswds/img/us_flag_small.png';
fill="#000000"
fill-rule="evenodd"
d="M26 0c10.493 0 19 8.507 19 19v9h3a4 4 0 0 1 4 4v28a4 4 0 0 1-4 4H4a4 4 0 0 1-4-4V32a4 4 0 0 1 4-4h3v-9C7 8.507 15.507 0 26 0zm0 8c-5.979 0-10.843 4.77-10.996 10.712L15 19v9h22v-9c0-6.075-4.925-11-11-11z"
/>
></path>
</svg>
</span>
) or <strong>https://</strong> means you’ve safely connected
to the .gov website. Share sensitive information only on
official, secure websites.
) or <strong>https://</strong> means you’ve safely connected to the
.gov website. Share sensitive information only on official, secure
websites.
</p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/spotlight/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export type AppContext = {
github: GithubRepository;
};

let _context: AppContext = null;
let _context: AppContext | null = null;

export const getAppContext = (): AppContext => {
if (_context === null) {
_context = createAppContext(import.meta.env);
_context = createAppContext((import.meta as any).env);
}
return _context;
};
Expand Down
5 changes: 1 addition & 4 deletions apps/spotlight/src/pages/form-sample.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
---
import { createSequentialInterview } from '@atj/interviews';
import { getAppContext } from '../context';
import { InterviewForm } from '../components/react/experiments/interview-form';
import { InterviewForm } from '@atj/design/src/experiments/interview-form';
import ContentLayout from '../layouts/ContentLayout.astro';
const context = getAppContext();
const sampleInterview = createSequentialInterview({
summary: {
title: 'Silly nonsense',
Expand Down
8 changes: 6 additions & 2 deletions apps/spotlight/src/pages/forms/import-pdf.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
import { DocumentImporter } from '../../components/react/form-builder/document-importer';
import DocumentImporter from '@atj/design/src/form-builder/DocumentImporter';
import { createBrowserFormService } from '@atj/form-service';
import ContentLayout from '../../layouts/ContentLayout.astro';
const formService = createBrowserFormService();
---

<ContentLayout title="10x Access to Justice Spotlight">
<DocumentImporter client:only />
<!--DocumentImporter client:only /-->
</ContentLayout>
2 changes: 1 addition & 1 deletion apps/spotlight/src/pages/forms/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { FormSection } from '../../components/react/form';
import { FormSection } from '@atj/design/src/form';
import ContentLayout from '../../layouts/ContentLayout.astro';
---

Expand Down
7 changes: 6 additions & 1 deletion apps/spotlight/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
---
import { DocumentAssembler } from '../components/react/experiments/document-assembler';
import { DocumentAssembler } from '@atj/design/src/experiments/document-assembler';
import ContentLayout from '../layouts/ContentLayout.astro';
---

<ContentLayout title="10x Access to Justice Spotlight">
<h1>10x Access to Justice Spotlight</h1>
<ul>
<li>
<a href={`${import.meta.env.BASE_URL}design/index.html`}
>View frontend workshop</a
>
</li>
<li>
<a href={`${import.meta.env.BASE_URL}forms`}>Manage my forms</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion apps/spotlight/src/pages/ud105-evicition-form.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import { FormView } from '../components/react/form/view';
import { FormView } from '@atj/design/src/form/FormView';
import formData from '../htmlParser/ud105-form-field-output.json';
import ContentLayout from '../layouts/ContentLayout.astro';
---
Expand Down
6 changes: 3 additions & 3 deletions apps/spotlight/src/styles.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@import '@atj/design/dist/uswds/styles/styles.css';
@import '@atj/design/static/uswds/styles/styles.css';

.usa-form--large {
max-width: 32rem;
max-width: 32rem;
}

.usa-legend {
max-width: 100%;
max-width: 100%;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "CC0",
"scripts": {
"build": "turbo run build",
"clean": "turbo run clean",
"dev": "turbo run dev",
"pages": "rm -rf node_modules && npm i -g pnpm turbo && pnpm i && pnpm build && ln -sf ./apps/spotlight/dist _site",
"test": "turbo run test",
Expand Down
2 changes: 2 additions & 0 deletions packages/design/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist/
static/
storybook-static/
29 changes: 29 additions & 0 deletions packages/design/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { join, dirname } from 'path';

import { StorybookConfig } from '@storybook/react-vite';

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
const getAbsolutePath = (value: string) => {
return dirname(require.resolve(join(value, 'package.json')));
};

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-interactions'),
],
framework: {
name: getAbsolutePath('@storybook/react-vite') as '@storybook/react-vite',
options: {},
},
docs: {
autodocs: 'tag',
},
};
export default config;
17 changes: 17 additions & 0 deletions packages/design/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Preview } from '@storybook/react';

import '../static/uswds/styles/styles.css';

const preview: Preview = {
parameters: {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
8 changes: 4 additions & 4 deletions packages/design/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const uswds = require('@uswds/compile');
*/
uswds.settings.version = 3;

uswds.paths.dist.css = './dist/uswds/styles';
uswds.paths.dist.fonts = './dist/uswds/fonts';
uswds.paths.dist.img = './dist/uswds/img';
uswds.paths.dist.js = './dist/uswds/js';
uswds.paths.dist.css = './static/uswds/styles';
uswds.paths.dist.fonts = './static/uswds/fonts';
uswds.paths.dist.img = './static/uswds/img';
uswds.paths.dist.js = './static/uswds/js';

exports.compile = uswds.compile;
exports.init = uswds.init;
Expand Down
49 changes: 40 additions & 9 deletions packages/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,53 @@
"version": "0.0.1",
"main": "src/index.ts",
"scripts": {
"build": "pnpm build:uswds && pnpm build:typescript",
"build:typescript": "tsup src/* --env.NODE_ENV production --dts-resolve",
"build:uswds": "gulp update",
"dev": "tsup src/* --watch",
"watch": "gulp watch",
"watch:typescript": "gulp watch",
"watch:uswds": "gulp watch"
"build": "run-p build:lib build:styles && pnpm build:storybook",
"build:lib": "vite build",
"build:storybook": "storybook build",
"build:styles": "gulp update",
"clean": "run-p: clean:*",
"clean:lib": "rm -rf dist",
"clean:styles": "rm -rf static",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"storybook": "storybook dev -p 6006",
"watch": "run-p watch:*",
"watch:lib": "vite",
"watch:storybook": "storybook dev",
"watch:styles": "gulp watch"
},
"files": [
"dist/**/*"
],
"devDependencies": {
"@storybook/addon-essentials": "^7.6.8",
"@storybook/addon-interactions": "^7.6.8",
"@storybook/addon-links": "^7.6.8",
"@storybook/addon-onboarding": "^1.0.10",
"@storybook/blocks": "^7.6.8",
"@storybook/react": "^7.6.8",
"@storybook/react-vite": "^7.6.8",
"@storybook/test": "^7.6.8",
"@types/prop-types": "^15.7.11",
"@types/react": "^18.2.37",
"@uswds/compile": "github:danielnaab/uswds-compile#package-json-paths",
"gulp": "^4.0.2"
"@vitejs/plugin-react": "^4.2.1",
"glob": "^10.3.10",
"gulp": "^4.0.2",
"npm-run-all": "^4.1.5",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^5.0.11",
"vite-plugin-dts": "^3.7.1"
},
"dependencies": {
"@uswds/uswds": "^3.6.1"
"@atj/documents": "workspace:*",
"@atj/forms": "workspace:*",
"@atj/form-service": "workspace:*",
"@atj/interviews": "workspace:*",
"@uswds/uswds": "^3.6.1",
"react-hook-form": "^7.49.3",
"react-router-dom": "^6.21.1",
"storybook": "^7.6.8"
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useReducer } from 'react';

import {
type BooleanFact,
type Field,
type Interview,
type TextFact,
createInterviewContext,
nextContext,
} from '@atj/interviews';
import { Field } from '@atj/interviews';
import { BooleanFact, TextFact } from '@atj/interviews';

const form = {
action: 'https://yaawr84uu7.execute-api.us-east-2.amazonaws.com',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ import {
createPrompt,
} from '@atj/forms';

import { onFileInputChangeGetFile } from '../../../lib/file-input';
import { FormView } from '../form/view';
import { onFileInputChangeGetFile } from '../util/file-input';
import { FormView } from '../form/FormView';

export const DocumentImporter = ({
formId,
form,
}: {
formId: string;
form: Form;
}) => {
const DocumentImporter = ({ formId, form }: { formId: string; form: Form }) => {
const { state, actions } = useDocumentImporter(form);

const Step: React.FC<
Expand Down Expand Up @@ -299,3 +293,5 @@ const useDocumentImporter = (form: Form) => {
},
};
};

export default DocumentImporter;
File renamed without changes.
48 changes: 48 additions & 0 deletions packages/design/src/form/FormDelete/FormDelete.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import type { Meta, StoryFn, StoryObj } from '@storybook/react';

import { createForm } from '@atj/forms';
import { createTestFormService } from '@atj/form-service';

import FormDelete from '.';

export default {
title: 'form/FormDelete',
component: FormDelete,
decorators: [
(Story: StoryFn, args: any) => (
<MemoryRouter initialEntries={['/']}>
<Story {...args} />
</MemoryRouter>
),
],
args: {
formId: 'test-form',
formService: createTestFormService({
'test-form': createForm(
{
title: 'Test form',
description: 'Test description',
},
[
{
id: 'question-1',
text: 'Question 1',
initial: '',
required: true,
},
{
id: 'question-2',
text: 'Question 2',
initial: 'initial value',
required: false,
},
]
),
}),
},
tags: ['autodocs'],
} satisfies Meta<typeof FormDelete>;

export const FormDeleteTest = {} satisfies StoryObj<typeof FormDelete>;
Loading

0 comments on commit f64ef1e

Please sign in to comment.