Skip to content

Commit

Permalink
Merge pull request #5 from PxTools/PXWEB2-27-install-and-setup-storybook
Browse files Browse the repository at this point in the history
Pxweb2-27 install and setup storybook
  • Loading branch information
SjurSutterudSagen authored Jan 17, 2024
2 parents 59082c9 + e6a897d commit 87bc368
Show file tree
Hide file tree
Showing 12 changed files with 18,879 additions and 5,622 deletions.
5 changes: 4 additions & 1 deletion apps/pxweb2/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export function App() {
return (
<div>
<NxWelcome title="pxweb2" />
<Pxweb2Ui />
<Pxweb2Ui
title="Welcome to pxweb2-ui!"
variant="primary"
/>
</div>
);
}
Expand Down
20 changes: 20 additions & 0 deletions libs/pxweb2-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { StorybookConfig } from '@storybook/react-vite';

const config: StorybookConfig = {
stories: ['../src/lib/**/*.stories.@(js|jsx|ts|tsx|mdx)'],
addons: ['@storybook/addon-essentials', '@storybook/addon-interactions'],
framework: {
name: '@storybook/react-vite',
options: {
builder: {
viteConfigPath: 'libs/pxweb2-ui/vite.config.ts',
},
},
},
};

export default config;

// To customize your Vite configuration you can use the viteFinal field.
// Check https://storybook.js.org/docs/react/builders/vite#configuration
// and https://nx.dev/recipes/storybook/custom-builder-configs
Empty file.
43 changes: 43 additions & 0 deletions libs/pxweb2-ui/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,49 @@
"options": {
"reportsDirectory": "../../coverage/libs/pxweb2-ui"
}
},
"storybook": {
"executor": "@nx/storybook:storybook",
"options": {
"port": 4400,
"configDir": "libs/pxweb2-ui/.storybook"
},
"configurations": {
"ci": {
"quiet": true
}
}
},
"build-storybook": {
"executor": "@nx/storybook:build",
"outputs": ["{options.outputDir}"],
"options": {
"outputDir": "dist/storybook/pxweb2-ui",
"configDir": "libs/pxweb2-ui/.storybook"
},
"configurations": {
"ci": {
"quiet": true
}
}
},
"test-storybook": {
"executor": "nx:run-commands",
"options": {
"command": "test-storybook -c libs/pxweb2-ui/.storybook --url=http://localhost:4400"
}
},
"static-storybook": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "pxweb2-ui:build-storybook",
"staticFilePath": "dist/storybook/pxweb2-ui"
},
"configurations": {
"ci": {
"buildTarget": "pxweb2-ui:build-storybook:ci"
}
}
}
}
}
38 changes: 38 additions & 0 deletions libs/pxweb2-ui/src/lib/pxweb2-ui.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Pxweb2Ui } from './pxweb2-ui';

import { within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';

const meta: Meta<typeof Pxweb2Ui> = {
component: Pxweb2Ui,
title: 'Pxweb2Ui',
};
export default meta;
type Story = StoryObj<typeof Pxweb2Ui>;

export const Primary = {
args: {
title: 'pxweb2-ui primary!',
variant: 'primary',
},
};

export const Secondary: Story = {
args: {
title: 'pxweb2-ui secondary!',
variant: 'secondary',
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
expect(canvas.getByText(/pxweb2-ui secondary!/gi)).toBeTruthy();
},
};

export const Heading: Story = {
args: {},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
expect(canvas.getByText(/Welcome to Pxweb2Ui!/gi)).toBeTruthy();
},
};
12 changes: 10 additions & 2 deletions libs/pxweb2-ui/src/lib/pxweb2-ui.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import styles from './pxweb2-ui.module.scss';

/* eslint-disable-next-line */
export interface Pxweb2UiProps {}
export interface Pxweb2UiProps {
title: string;
variant: 'primary' | 'secondary';
}

export function Pxweb2Ui(props: Pxweb2UiProps) {
const title = props.title || 'Welcome to pxweb2-ui!';

return (
<div className={styles['container']}>
<h1>Welcome to Pxweb2Ui! Hei alle sammen</h1>
<h1>{title}</h1>
{props.variant === 'primary' && (
<button className={styles['button']}>Primary</button>
)}
</div>
);
}
Expand Down
3 changes: 3 additions & 0 deletions libs/pxweb2-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
},
{
"path": "./tsconfig.spec.json"
},
{
"path": "./tsconfig.storybook.json"
}
],
"extends": "../../tsconfig.base.json"
Expand Down
6 changes: 5 additions & 1 deletion libs/pxweb2-ui/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
"**/*.spec.js",
"**/*.test.js",
"**/*.spec.jsx",
"**/*.test.jsx"
"**/*.test.jsx",
"**/*.stories.ts",
"**/*.stories.js",
"**/*.stories.jsx",
"**/*.stories.tsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
31 changes: 31 additions & 0 deletions libs/pxweb2-ui/tsconfig.storybook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDecoratorMetadata": true,
"outDir": ""
},
"files": [
"../../node_modules/@nx/react/typings/styled-jsx.d.ts",
"../../node_modules/@nx/react/typings/cssmodule.d.ts",
"../../node_modules/@nx/react/typings/image.d.ts"
],
"exclude": [
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.jsx",
"src/**/*.test.js"
],
"include": [
"src/**/*.stories.ts",
"src/**/*.stories.js",
"src/**/*.stories.jsx",
"src/**/*.stories.tsx",
"src/**/*.stories.mdx",
".storybook/*.js",
".storybook/*.ts"
]
}
21 changes: 20 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
"@nx/vite:test": {
"cache": true,
"inputs": ["default", "^production"]
},
"build-storybook": {
"cache": true,
"inputs": [
"default",
"^production",
"{projectRoot}/.storybook/**/*",
"{projectRoot}/tsconfig.storybook.json"
]
}
},
"namedInputs": {
Expand All @@ -34,7 +43,10 @@
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/eslint.config.js"
"!{projectRoot}/eslint.config.js",
"!{projectRoot}/**/*.stories.@(js|jsx|ts|tsx|mdx)",
"!{projectRoot}/.storybook/**/*",
"!{projectRoot}/tsconfig.storybook.json"
],
"sharedGlobals": []
},
Expand All @@ -55,5 +67,12 @@
"unitTestRunner": "vitest"
}
}
},
"tasksRunnerOptions": {
"default": {
"options": {
"cacheableOperations": ["build-storybook"]
}
}
}
}
Loading

0 comments on commit 87bc368

Please sign in to comment.