@andersundsehr/storybook-typo3 0.1.4 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +225 -0
- package/dist/functions/convertComponentToSource.test.js +1 -1
- package/package.json +25 -8
package/README.md
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
# `EXT:storybook`
|
2
|
+
<img alt="TYPO3" src="./Documentation/assets/TYPO3-Logo-rgb.svg" height="40" />
|
3
|
+
<img alt="Love" src="./Documentation/assets/heart.svg" height="40" />
|
4
|
+
<img alt="Storybook" src="./Documentation/assets/logo-storybook-default.svg" height="40" />
|
5
|
+
|
6
|
+
[Getting Started](https://docs.typo3.org/p/andersundsehr/storybook)
|
7
|
+
|
8
|
+
The TYPO3 extension `storybook` integrates Storybook into TYPO3 projects.
|
9
|
+
With the open-source tool Storybook, developers can develop and test UI components in isolation.
|
10
|
+
It provides an environment where components can be visually displayed and interactively tested.
|
11
|
+
The extension facilitates the development of TYPO3 frontend components by enabling seamless integration of Storybook into TYPO3.
|
12
|
+
|
13
|
+
### Features:
|
14
|
+
|
15
|
+
- render [TYPO3 Fluid components](https://docs.typo3.org/permalink/fluid:components) in Storybook
|
16
|
+
- configure stories inside storybook with the standard [Storybook's CSF format](https://storybook.js.org/docs/api/csf)
|
17
|
+
- **automatically generates controls** for your components [arguments](https://docs.typo3.org/permalink/t3viewhelper:typo3fluid-fluid-argument) and [slots](https://docs.typo3.org/permalink/t3viewhelper:typo3fluid-fluid-slot)
|
18
|
+
- **Interactivity** via [Storybook's Controls](https://storybook.js.org/docs/essentials/controls), allowing you to change component properties in real-time
|
19
|
+
- shows [Fluid **code snippets**](https://storybook.js.org/docs/writing-docs/code-panel) for each component, allowing you to copy the code directly from Storybook
|
20
|
+
- wide range of [Storybook's addons](https://storybook.js.org/addons) are available to enhance the development experience, such as accessibility checks, design systems, and more
|
21
|
+
|
22
|
+
## Installation: How to install the extension? (Composer, manual, dependencies)
|
23
|
+
|
24
|
+
The extension can be installed via Composer:
|
25
|
+
```bash
|
26
|
+
composer require andersundsehr/storybook --dev
|
27
|
+
```
|
28
|
+
|
29
|
+
it is recommended to install storybook into your projects package.json file as well:
|
30
|
+
```bash
|
31
|
+
# !!! make sure to install the same version as the extension !!!
|
32
|
+
npm install @andersundsehr/storybook-typo3 --save-dev
|
33
|
+
# or
|
34
|
+
yarn add @andersundsehr/storybook-typo3 --dev
|
35
|
+
```
|
36
|
+
|
37
|
+
set framework in your `.storybook/main.ts` file to `@andersundsehr/storybook-typo3` as shown below.
|
38
|
+
|
39
|
+
After that you can run storybook with:
|
40
|
+
```bash
|
41
|
+
# run in dev mode:
|
42
|
+
./node_modules/.bin/storybook dev -p 6006
|
43
|
+
# or build it for production:
|
44
|
+
./node_modules/.bin/storybook build
|
45
|
+
# preview the production build:
|
46
|
+
npx http-server ./storybook-static
|
47
|
+
```
|
48
|
+
|
49
|
+
> Also See [full installation steps](https://docs.typo3.org/p/andersundsehr/storybook/latest/en-us/Installation/Index.html) in the Getting Started Guide.
|
50
|
+
|
51
|
+
## Configuration:
|
52
|
+
|
53
|
+
### Inside TYPO3:
|
54
|
+
To be able to render your own Fluid components in Storybook,
|
55
|
+
you need to configure your own [ComponentCollection](https://docs.typo3.org/permalink/fluid:components)
|
56
|
+
and register the global fluid namespace in your `ext_localconf.php` file:
|
57
|
+
|
58
|
+
```php
|
59
|
+
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['my'] = Vendor\MyExtension\ComponentCollection::class;
|
60
|
+
```
|
61
|
+
|
62
|
+
### Inside Storybook:
|
63
|
+
You need your own `.storybook/main.ts` file in your project, which should look like this:
|
64
|
+
|
65
|
+
```typescript
|
66
|
+
import type { StorybookConfig } from '@andersundsehr/storybook-typo3';
|
67
|
+
|
68
|
+
const config: StorybookConfig = {
|
69
|
+
framework: '@andersundsehr/storybook-typo3', // required
|
70
|
+
|
71
|
+
stories: [
|
72
|
+
"../src/**/*.mdx",
|
73
|
+
'../src/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
74
|
+
],
|
75
|
+
|
76
|
+
core: {
|
77
|
+
disableTelemetry: true,
|
78
|
+
},
|
79
|
+
|
80
|
+
env: (envs) => ({
|
81
|
+
STORYBOOK_TYPO3_ENDPOINT: 'http://localhost/_storybook/', // env can be set here or in the .env file
|
82
|
+
...envs, // envs given to storybook have precedence
|
83
|
+
}),
|
84
|
+
};
|
85
|
+
export default config;
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
## Usage: How to use the extension? (Examples, screenshots, typical use cases)
|
90
|
+
|
91
|
+
With a story file like this:
|
92
|
+
````typescript
|
93
|
+
import { type Meta, type StoryObj, fetchComponent } from '@andersundsehr/storybook-typo3';
|
94
|
+
|
95
|
+
export default {
|
96
|
+
component: await fetchComponent('de:card'),
|
97
|
+
} satisfies Meta;
|
98
|
+
|
99
|
+
export const Pirate: StoryObj = {
|
100
|
+
args: {
|
101
|
+
title: 'Yar Pirate Ipsum',
|
102
|
+
text: "Prow scuttle parrel provost Sail ho shrouds spirits boom mizzenmast yardarm. Pinnace holystone mizzenmast quarter crow's nest nipperkin grog yardarm hempen halter furl. Swab barque interloper chantey doubloon starboard grog black jack gangway rutters.",
|
103
|
+
link: 'https://www.andersundsehr.com',
|
104
|
+
},
|
105
|
+
};
|
106
|
+
````
|
107
|
+
|
108
|
+
and a Fluid component like this:
|
109
|
+
```html
|
110
|
+
<f:argument name="title" type="string" description="The title of the card" />
|
111
|
+
<f:argument name="text" type="string" description="The main text of the card" />
|
112
|
+
<f:argument name="link" type="string" description="Typolink parameter" />
|
113
|
+
|
114
|
+
<a href="{f:uri.typolink(parameter: link)}" class="card">
|
115
|
+
<h1 class="card__title">{title}</h1>
|
116
|
+
<p class="card__text">{text}</p>
|
117
|
+
<span class="card__moreButton">more</span>
|
118
|
+
</a>
|
119
|
+
|
120
|
+
<f:asset.css identifier="de:card">
|
121
|
+
.card {
|
122
|
+
display: block;
|
123
|
+
padding: 1rem;
|
124
|
+
border: 1px solid #ccc;
|
125
|
+
border-radius: 4px;
|
126
|
+
text-decoration: none;
|
127
|
+
color: inherit;
|
128
|
+
}
|
129
|
+
.card__title {
|
130
|
+
font-size: 1.5rem;
|
131
|
+
margin-bottom: 0.5rem;
|
132
|
+
}
|
133
|
+
.card__text {
|
134
|
+
font-size: 1rem;
|
135
|
+
margin-bottom: 1rem;
|
136
|
+
}
|
137
|
+
.card__moreButton {
|
138
|
+
display: inline-block;
|
139
|
+
padding: 0.5rem 1rem;
|
140
|
+
background-color: #007bff;
|
141
|
+
color: white;
|
142
|
+
border-radius: 4px;
|
143
|
+
text-decoration: none;
|
144
|
+
}
|
145
|
+
</f:asset.css>
|
146
|
+
```
|
147
|
+
|
148
|
+
you get a Storybook interface that allows you to interactively test your component, like this:
|
149
|
+

|
150
|
+
|
151
|
+
You can Select the site and the language in the top right corner of the Storybook interface:
|
152
|
+

|
153
|
+

|
154
|
+
|
155
|
+
## Documentation: Where to find more information? (Links, references, tutorials)
|
156
|
+
|
157
|
+
https://docs.typo3.org/p/andersundsehr/storybook
|
158
|
+
|
159
|
+
- docs TODO link to hosted Storybook instance
|
160
|
+
- docs TODO link to playwright report?
|
161
|
+
|
162
|
+
## Development: Notes for developers (e.g., code structure, important classes, extensibility)
|
163
|
+
|
164
|
+
The Storybook framework is located in the `the-npm-package` folder inside the extension.
|
165
|
+
It provides a custom framework for Storybook, which allows you to render TYPO3 Fluid components in Storybook.
|
166
|
+
It is implemented in TypeScript and is designed to be used with Storybook's Component Story Format (CSF).
|
167
|
+
|
168
|
+
The TYPO3 extension `storybook` uses a [Middleware](./Classes/Middleware/StorybookMiddleware.php) to handle requests to the Storybook endpoint.
|
169
|
+
It has [Actions](./Classes/Action/) to give Storybook the necessary information.
|
170
|
+
It renders the Fluid components using the corresponding ComponentCollection that must be registered in TYPO3
|
171
|
+
via `$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']`.
|
172
|
+
|
173
|
+
### Development helpers:
|
174
|
+
the test setup is a nice location to get started with developing the extension.
|
175
|
+
it also has a [dummy project](./.Build/dummy-project/) that can be used to test the extension in a real TYPO3 environment.
|
176
|
+
|
177
|
+
## Tests: How to run tests? Are there test data?
|
178
|
+
|
179
|
+
Currently there are only integration tests with [Playwright](./.Build/dummy-project/tests/)
|
180
|
+
to run the tests you can use the following command:
|
181
|
+
```bash
|
182
|
+
cd .Build/
|
183
|
+
bash test.sh executeAll
|
184
|
+
```
|
185
|
+
|
186
|
+
If you want to make changes to the extension, and than run the tests again you should do this:
|
187
|
+
```bash
|
188
|
+
cd .Build/
|
189
|
+
bash test.sh composerInstall
|
190
|
+
bash test.sh storybookBuild
|
191
|
+
bash test.sh watchMode
|
192
|
+
# in different terminal:
|
193
|
+
cd .Build/
|
194
|
+
bash test.sh playwright:ui # (X11 forwarding required)
|
195
|
+
```
|
196
|
+
|
197
|
+
## Troubleshooting: Known issues, troubleshooting, FAQ
|
198
|
+
|
199
|
+
## Changelog: Important changes and versions
|
200
|
+
|
201
|
+
until now there are no breaking changes, but the extension is still in development.
|
202
|
+
|
203
|
+
## License and Authors: License type, contributors, contact information
|
204
|
+
|
205
|
+
This extension is licensed under the [GPL-2.0-or-later](https://spdx.org/licenses/GPL-2.0-or-later.html) license.
|
206
|
+
|
207
|
+
# with ♥️ from anders und sehr GmbH
|
208
|
+
|
209
|
+
> If something did not work 😮
|
210
|
+
> or you appreciate this Extension 🥰 let us know.
|
211
|
+
|
212
|
+
> We are always looking for great people to join our team!
|
213
|
+
> https://www.andersundsehr.com/karriere/
|
214
|
+
|
215
|
+
|
216
|
+
# TODOs
|
217
|
+
- [ ] add storybook:transform ViewHelper to code generation?
|
218
|
+
- [ ] add storybook:toDateTime ViewHelper to code generation!
|
219
|
+
|
220
|
+
- [ ] document transformers
|
221
|
+
- [ ] document .transformers.php
|
222
|
+
- [ ] document how/when to use the transformers
|
223
|
+
- [ ] document storybook:transform ViewHelper
|
224
|
+
- [ ] document storybook:toDateTime ViewHelper
|
225
|
+
- [ ] document that enums and dates are automatically handled by the extension
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { test } from 'node:test';
|
2
|
-
import { convertComponentToSource } from
|
2
|
+
import { convertComponentToSource } from "./convertComponentToSource.js";
|
3
3
|
const component = { name: 'test', fullName: 'c:test', argTypes: {}, collection: 'Class', namespace: 'c' };
|
4
4
|
const testCases = {
|
5
5
|
///////////////////////////////////////////
|
package/package.json
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
{
|
2
2
|
"name": "@andersundsehr/storybook-typo3",
|
3
|
+
"description": "The one and only Storybook Renderer for TYPO3 Fluid",
|
4
|
+
"keywords": [
|
5
|
+
"storybook",
|
6
|
+
"TYPO3",
|
7
|
+
"Fluid"
|
8
|
+
],
|
9
|
+
"homepage": "https://github.com/andersundsehr/storybook",
|
10
|
+
"license": "GPL-2.0-or-later",
|
11
|
+
"bugs": "https://github.com/andersundsehr/storybook/issues",
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "git+https://github.com/andersundsehr/storybook.git",
|
15
|
+
"directory": "the-npm-package"
|
16
|
+
},
|
3
17
|
"type": "module",
|
18
|
+
"main": "dist/index.js",
|
4
19
|
"module": "dist/index.js",
|
5
20
|
"types": "dist/index.d.ts",
|
6
21
|
"exports": {
|
@@ -14,23 +29,25 @@
|
|
14
29
|
}
|
15
30
|
},
|
16
31
|
"dependencies": {
|
32
|
+
"@storybook/addon-a11y": "^9.0.0",
|
33
|
+
"@storybook/addon-docs": "^9.0.0",
|
17
34
|
"@storybook/builder-vite": "^9.0.0",
|
18
35
|
"@storybook/server": "^9.0.0",
|
19
|
-
"@storybook/addon-docs": "^9.0.0",
|
20
|
-
"@storybook/addon-a11y": "^9.0.0",
|
21
36
|
"storybook": "^9.0.0"
|
22
37
|
},
|
23
38
|
"devDependencies": {
|
24
|
-
"typescript": "^5.8.3"
|
39
|
+
"typescript": "^5.8.3",
|
40
|
+
"@types/node": "^22.13.14"
|
25
41
|
},
|
26
42
|
"scripts": {
|
27
|
-
"test": "node --test --experimental-strip-types",
|
28
|
-
"test:watch": "
|
43
|
+
"test": "node --test --experimental-strip-types **/*.test.{cts,mts,ts}",
|
44
|
+
"test:watch": "npm run test -- --watch",
|
29
45
|
"build": "tsc",
|
30
|
-
"prepublishOnly": "npm run build"
|
46
|
+
"prepublishOnly": "cp ../README.md . && npm run build"
|
31
47
|
},
|
32
48
|
"files": [
|
33
|
-
"dist"
|
49
|
+
"dist",
|
50
|
+
"README.md"
|
34
51
|
],
|
35
|
-
"version": "0.1.
|
52
|
+
"version": "0.1.9"
|
36
53
|
}
|