Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e399a2c
chore(types): add missing type ExtractArgTypesOptions
pixtron Oct 1, 2024
089c22a
feat: export function to get component meta data
pixtron Oct 1, 2024
46764cb
chore(dependencies): npm audit fix
pixtron Oct 1, 2024
d8ff69f
6.4.2
pixtron Oct 1, 2024
70a62ec
feat: update to storybook v7
pixtron Oct 3, 2024
93816e1
chore: update dev dependencies and add prettier and husky
pixtron Oct 23, 2024
8202180
chore: replace preset config field with previewAnnotations
pixtron Oct 23, 2024
7710924
chore: use tsup as builder
pixtron Oct 7, 2024
6d5a7c0
feat: apply preset only when docs are enabled
pixtron Oct 7, 2024
0da5e93
chore: migrate docs.inlineStories parameter
pixtron Oct 23, 2024
7f0b3b0
fix: disable controls for events, mehtods and generics
pixtron Oct 23, 2024
9f4823f
feat: allow to exclude single categories from docs
pixtron Oct 23, 2024
493e5e1
feat: display properties and attributes in separate sections
pixtron Oct 24, 2024
3488b74
chore: remove namespacing for events and methods
pixtron Jan 9, 2025
8250fb6
feat: default render method
pixtron Jan 9, 2025
d99a0d2
feat: allow to configure the nameing of event keys in arg types
pixtron Jan 11, 2025
3df2869
chore: add peer dependencies
pixtron Jan 11, 2025
69e3859
chore: update dev dependencies
pixtron Jan 12, 2025
2dfbf89
chore: update Readme
pixtron Jan 12, 2025
8b6c9bb
fix: improve types
pixtron Jan 12, 2025
b091813
7.0.0
pixtron Jan 12, 2025
4572313
chore: update storybook dependencies to latest
pixtron Jan 12, 2025
56a238b
8.0.0
pixtron Jan 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

17 changes: 0 additions & 17 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**Steps to Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
4 changes: 4 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"!(*.ts)": "prettier . --check",
"*.ts": ["eslint . --report-unused-disable-directives", "prettier . --check"]
}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.13.0
v18.20.4
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
node_modules
*.typegen.ts
.nvmrc
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"bracketSpacing": true,
"arrowParens": "avoid",
"trailingComma": "all",
"bracketSameLine": false
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"eslint.useFlatConfig": true,
"editor.codeActionsOnSave": {
"source.fixAll": "always"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
110 changes: 72 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ Converts stencil.js doc json derived from stencils output target
[`ArgTypes`](https://storybook.js.org/docs/react/api/argtypes).

With this addon activated

- Storybook will render basic controls for properties [Controls](https://storybook.js.org/docs/react/essentials/controls).
- Storybook will auto generate documentation for Props, Events, Methods, Slots, Shadow Parts and Custom Properties.
- Storybook doc page will contain stencils component documentation (readme.md or inline)
- Storybook doc page will contain stencils component documentation (readme.md or inline)

## Installation

```
```bash
npm i -D @pxtrn/storybook-addon-docs-stencil
```

## Usage

### Configure stencil to generate docs-json at build time.

```
```js
// stencil.config.ts

import { Config } from '@stencil/core';
Expand All @@ -36,41 +37,85 @@ export const config: Config = {

### Configure Storybook

```
```js
//.storybook/main.js

module.exports = {
addons: [
'@storybook/addon-essentials',
'@pxtrn/storybook-addon-docs-stencil'
]
}
'@pxtrn/storybook-addon-docs-stencil',
],
};
```

```
```js
//.storybook/preview.js

import { setStencilDocJson } from '@pxtrn/storybook-addon-docs-stencil';
import docJson from 'path/to/docs.json';
if(docJson) setStencilDocJson(docJson);
if (docJson) setStencilDocJson(docJson);

export const parameters = {
controls: { hideNoControlsWarning: true }
}
controls: { hideNoControlsWarning: true },
};
```

#### Dash cased properties
### Configure the argTypes extractor

```
```js
//.storybook/preview.js

import { extractArgTypesFactory } from '@pxtrn/storybook-addon-docs-stencil';

/** @type { import('@pxtrn/storybook-addon-docs-stencil').ExtractArgTypesOptions } */
const options = {
excludeCategories: 'porperties',
controlsFor: 'attributes',
eventNameing: 'jsx',
};

export const parameters = {
docs: {
extractArgTypes: extractArgTypesFactory({ dashCase: true }),
}
}
extractArgTypes: extractArgTypesFactory(options),
},
};
```

#### ExtractArgTypesOptions

- `excludeCategories: Category[]`: categories to exclude from argTypes and docs (default: `['attributes]`).
- `controlsFor: 'attributes' | 'properties'`: for wich category to render controls.
- `eventNameing: 'native' | 'jsx'`: nameing of the arg key for events (default: 'native'). If jsx the args can be spread `<my-component {...args} />` when using JSX to render stories.

### Default render method

When using @storybook/web-components or @storybook/html as renderer args and actions do not get bound automatically. This addon includes an optional default renderer that works out of the box

```js
//.storybook/preview.js

import {
extractArgTypesFactory,
stencilRender,
} from '@pxtrn/storybook-addon-docs-stencil';

/** @type { import('@storybook/web-components').Preview } */
const preview = {
render: stencilRender(),
};

export default preview;
```

`stencilRender` can be configured by these options:

- `eventNameing: 'native' | 'jsx'`: use the same nameing used in ExtractArgTypesOptions (default: 'native)
- `bindEvents: boolean`: wheter events/actions should be bound (default: true)

eg:

```js
stencilRender({ bindEvents: false });
```

### Component documentation
Expand All @@ -80,15 +125,15 @@ export const parameters = {
If not already created by stencil create `src/components/my-component/readme.md`
If the line `<!-- Auto Generated Below -->` is not present, stencil will ignore this file.

```
```md
Everything above this line will be included in storybook

<!-- Auto Generated Below -->
```

#### inline documentation

```
```ts
// src/components/my-component/my-component.tsx`

/**
Expand All @@ -101,33 +146,22 @@ Everything above this line will be included in storybook
})
```

#### Troubleshooting

##### When using @storybook/web-components

`@storybook/web-components` overrides the preset configuration of this module.
You can fix this with this preview config.

```
//.storybook/preview.js

import { extractArgTypes, extractComponentDescription, setStencilDocJson } from '@pxtrn/storybook-addon-docs-stencil';
If you prefere the inline documentation over the readme, see [issue #15](https://github.com/pixtron/storybook-addon-docs-stencil/issues/15#issuecomment-2387147999).

export const parameters = {
...
docs: {
extractArgTypes,
extractComponentDescription,
},
};
```
#### Troubleshooting

##### Hint your component in your stories
```

```ts
// your-story.ts

export default {
title: 'My Component',
component: 'my-component',
};
```

### Breaking Changes in v7

- attributes and properties are now shown as own categories, before both where visible under "props" with some inconsitency in naming (dashCase vs camelCase). Use `excludeCategories` to configure which categories are shown.
- removed configuration `dashCase` properties and attributes are now shown in single sections. Use `controlsFor` and `excludeCategories` instead of `dashCase`.
26 changes: 26 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: ['preset.js', '**/dist/', '**/node_modules'],
},
{
files: ['**/*.ts'],
extends: [eslint.configs.recommended, ...tseslint.configs.recommended],
plugins: {
'@typescript-eslint': tseslint.plugin,
},
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: ['./tsconfig.eslint.json', './tsconfig.json'],
},
},
rules: {
'no-console': 1,
'object-curly-spacing': ['error', 'always'],
'@typescript-eslint/ban-ts-comment': 0,
},
},
);
Loading