Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
ad10877
fix: modify BooleanControl so that screen readers read a more accurat…
danielmarcano Oct 9, 2023
89dbb40
Merge branch 'next' into toggle-accessibility-fix
cdedreuille Oct 12, 2023
193f13e
cleanup
yannbf Oct 13, 2023
cb1b8d3
fix play function
yannbf Oct 13, 2023
cd5f811
fix(23454)-raw button contrast ratio
maheshchandra10 Oct 19, 2023
ab96c94
GitHub Pages publish guide
mickmcgrath13 Oct 19, 2023
1e03006
Merge branch 'next' into fix(23454)-raw-button-contrast-ratio
ndelangen Oct 20, 2023
81611b9
feat: add new snippet to CodeSnippets paths
halitiince Oct 20, 2023
440372f
Merge branch 'next' into toggle-accessibility-fix
yannbf Oct 23, 2023
a2005c7
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Oct 23, 2023
5ae6774
add appPreviewBg and background.preview to theme variables
JReinhold Oct 25, 2023
3de4e9e
add appPreviewBg to documentation
JReinhold Oct 25, 2023
94eee1f
set preview loader background to match preview
JReinhold Oct 25, 2023
a39db04
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Oct 25, 2023
08582ca
Merge branch 'next' into publish-docs-github-pages
jonniebigodes Oct 26, 2023
c00fc33
Update publish docs to reflect new version of GHP action
mickmcgrath13 Oct 26, 2023
0b44945
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Oct 26, 2023
49b5999
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Oct 26, 2023
11d1e03
use @storybook/test in CLI templates
yannbf Oct 5, 2023
6db0c3b
Merge branch 'next' into halitiince/docs_update_new_react_ts_snippet
jonniebigodes Oct 27, 2023
adcdd81
fix(manager): changed NotificationList z-index
yoshi2no Oct 28, 2023
a206c3e
Catch when prettier failed to prettify main and preview config files
kasperpeulen Oct 28, 2023
f4b4b6e
Babel: Update all @babel/* dependencies
valentinpalkovic Oct 30, 2023
5c320c2
Update jest dependency and add missing babel-jest peer dep
valentinpalkovic Oct 30, 2023
1efe4d1
Remove unneeded ts-to-ts49 codemod
valentinpalkovic Oct 30, 2023
2890ac2
Merge branch 'next' into yann/use-test-package-in-template-stories
yannbf Oct 30, 2023
d8bf6d1
Merge pull request #24610 from storybookjs/valentin/update-babel-depe…
valentinpalkovic Oct 30, 2023
7f5be2c
Merge pull request #24604 from storybookjs/kasper/try-catch-pretify-m…
kasperpeulen Oct 30, 2023
089e340
Next.js: Add avif support
valentinpalkovic Oct 30, 2023
046f823
Update CHANGELOG.md
valentinpalkovic Oct 30, 2023
75cbb1b
Fix ensure-next-ahead step in publish script for empty commits
valentinpalkovic Oct 30, 2023
82e410a
Merge pull request #24616 from storybookjs/valentin/update-changelog
valentinpalkovic Oct 30, 2023
e437742
Merge pull request #24617 from storybookjs/valentin/fix-ensure-next-a…
valentinpalkovic Oct 30, 2023
c656965
split the html renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
bbdcd6a
split the preact renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
fc5c4a9
split the react renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
d77983c
split the server renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
ac33fe9
split the svelte renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
5ef2534
split the vue renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
da42b5d
split the vue3 renderer preview entrypoint into docs & non-docs parts
ndelangen Oct 30, 2023
ea7c242
split the web-components renderer preview entrypoint into docs & non-…
ndelangen Oct 30, 2023
5aaf56e
cleanup
ndelangen Oct 30, 2023
004aa66
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Oct 30, 2023
ec26ed8
Merge branch 'next' into yann/use-test-package-in-template-stories
kasperpeulen Oct 31, 2023
76c3821
Remove await from getByX
kasperpeulen Oct 31, 2023
02f9b36
change mechanism for detecting addon docs being active
ndelangen Oct 31, 2023
b4fb3b0
Fix types
kasperpeulen Oct 31, 2023
4647e9f
Reformat
kasperpeulen Oct 31, 2023
518d643
corrections
ndelangen Oct 31, 2023
1c00b8c
Fix type
kasperpeulen Oct 31, 2023
8fdd30a
Merge pull request #24575 from storybookjs/22029-bug-preview-always-h…
JReinhold Oct 31, 2023
994689d
Merge pull request #24418 from danielmarcano/toggle-accessibility-fix
cdedreuille Oct 31, 2023
b5c6a2d
Rollback extra code in preact
kasperpeulen Oct 31, 2023
c33b724
Fix e2e tests
kasperpeulen Oct 31, 2023
bb5d607
Ignore addon-onboarding when checking versions
JReinhold Oct 31, 2023
12dfcde
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Oct 31, 2023
5b2fcd5
Merge branch 'next' into halitiince/docs_update_new_react_ts_snippet
jonniebigodes Oct 31, 2023
0d9b58a
do not edit docs config is --docs isn't set
ndelangen Oct 31, 2023
09778c8
optimize a story do it does not pull in the entire lodash universe
ndelangen Oct 31, 2023
e3bc4e1
Merge pull request #24634 from storybookjs/fix-onboarding-warning
valentinpalkovic Oct 31, 2023
8d24485
Merge branch 'next' into halitiince/docs_update_new_react_ts_snippet
jonniebigodes Oct 31, 2023
54cb15a
rename preview (previously config) to entry-preview, for easier ident…
ndelangen Oct 31, 2023
7e49ce6
Merge branch 'next' into norbert/split-docs-entries
ndelangen Oct 31, 2023
d3fbed5
Merge pull request #24540 from halitiince/halitiince/docs_update_new_…
jonniebigodes Oct 31, 2023
76e9c14
Docs: Publish Storybook remove irrelevant parenthesis
jonniebigodes Oct 31, 2023
2b6e04b
Merge pull request #24640 from storybookjs/docs_fix_publish_storybook…
jonniebigodes Oct 31, 2023
874a444
Docs: Fix formatting
valentinpalkovic Nov 1, 2023
ef40f34
Merge pull request #24646 from storybookjs/valentin/fix-prettier-issue
valentinpalkovic Nov 1, 2023
10b1e55
rename preview docs entrypoint
ndelangen Nov 1, 2023
cb03069
cleanup
ndelangen Nov 1, 2023
0ef13ab
Merge branch 'next' into norbert/split-docs-entries
ndelangen Nov 1, 2023
2f76b60
fix
ndelangen Nov 1, 2023
d8d57d4
Next.js: Fix forwarding ref for Image component
valentinpalkovic Nov 1, 2023
f176535
Merge pull request #24611 from storybookjs/valentin/nextjs-support-avif
valentinpalkovic Nov 1, 2023
aadef51
Merge pull request #24623 from storybookjs/norbert/split-docs-entries
ndelangen Nov 1, 2023
b7f73a1
Dedupe aria-query until v10 of @testing-library/jest-dom is released:…
kasperpeulen Nov 1, 2023
cd7c63e
Fix links to indexers API
JReinhold Nov 1, 2023
34cf7f8
Merge pull request #24393 from storybookjs/yann/use-test-package-in-t…
kasperpeulen Nov 1, 2023
417b391
update example to show options more implicitly
mickmcgrath13 Nov 1, 2023
3bbb7c5
tighten verbiage and arrangement
mickmcgrath13 Nov 1, 2023
e998021
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Nov 1, 2023
f44cdba
Merge pull request #24649 from storybookjs/fix-indexers-link
kylegach Nov 1, 2023
e1cb740
Merge pull request #24648 from storybookjs/valentin/fix-forwardref-fo…
valentinpalkovic Nov 1, 2023
4c5e657
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Nov 1, 2023
c33389f
CLI Bug: open browser in CLI block start process
xueyawei Nov 2, 2023
1902e35
Dependencies: Update @babel/traverse and @babel/core to fix vulnerabi…
valentinpalkovic Nov 2, 2023
369f0f7
Dependencies: Update nx dependencies to v17
valentinpalkovic Nov 2, 2023
c77f4b4
Dependencies: Update browserify-sign transitive dependency
valentinpalkovic Nov 2, 2023
abf73bd
Merge pull request #24670 from storybookjs/valentin/fix-babel-travers…
valentinpalkovic Nov 2, 2023
63590f2
Add a readme for the test package
kasperpeulen Nov 2, 2023
05ada09
Merge pull request #24671 from storybookjs/valentin/upgrade-nx
valentinpalkovic Nov 2, 2023
efcda42
Merge pull request #24674 from storybookjs/valentin/update-browserify…
valentinpalkovic Nov 2, 2023
fbc8624
Merge pull request #24602 from yoshi2no/patch/24476/yoshi2no
cdedreuille Nov 2, 2023
2c264f1
Merge branch 'next' into fix(23454)-raw-button-contrast-ratio
cdedreuille Nov 2, 2023
ac9880f
Merge pull request #24525 from maheshchandra10/fix(23454)-raw-button-…
cdedreuille Nov 2, 2023
de8530f
Merge branch 'next' into publish-docs-github-pages
mickmcgrath13 Nov 2, 2023
abb7942
yml instead of js, fix extra space in heading, run pretty-docs
mickmcgrath13 Nov 2, 2023
5403dc8
Merge pull request #24668 from xueyawei/patch-2
ndelangen Nov 2, 2023
7f6a92f
Merge branch 'next' into publish-docs-github-pages
jonniebigodes Nov 2, 2023
36c9e26
Merge pull request #24527 from bitovi/publish-docs-github-pages
jonniebigodes Nov 2, 2023
beda7e2
Update code/lib/test/README.md
kasperpeulen Nov 3, 2023
e5dc4d8
Update code/lib/test/README.md
kasperpeulen Nov 3, 2023
bb24d00
Update code/lib/test/README.md
kasperpeulen Nov 3, 2023
06aee66
Update README.md with clarification on package usage
kasperpeulen Nov 3, 2023
a02b85d
Fix minor typo
shilman Nov 3, 2023
de903be
Update code/lib/test/README.md
kasperpeulen Nov 3, 2023
8114b33
Update code/lib/test/README.md
kasperpeulen Nov 3, 2023
3c29e8f
Merge pull request #24678 from storybookjs/kasper/test-readme
kasperpeulen Nov 3, 2023
29ffada
Write changelog for 7.6.0-alpha.4 [skip ci]
storybook-bot Nov 3, 2023
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: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
yarn release:ensure-next-ahead --main-version "${{ steps.version.outputs.current-version }}"

git add ..
git commit -m "Bump next to be one minor ahead of main [skip ci]"
git diff --staged --quiet || git commit -m "Bump next to be one minor ahead of main [skip ci]"
git push origin next

- name: Sync CHANGELOG.md from `main` to `next`
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 7.5.2

- Addon-themes: Fix globals not being set when using absolute path - [#24596](https://github.com/storybookjs/storybook/pull/24596), thanks [@JReinhold](https://github.com/JReinhold)!
- CLI: Allow Yarn v4 in `link` command - [#24551](https://github.com/storybookjs/storybook/pull/24551), thanks [@yannbf](https://github.com/yannbf)!
- Next.js: Support v14.0.0 - [#24593](https://github.com/storybookjs/storybook/pull/24593), thanks [@nikospapcom](https://github.com/nikospapcom)!

## 7.5.1

- Angular: update wrong type for webpackStatsJson in start-storybook schema.json - [#24494](https://github.com/storybookjs/storybook/pull/24494), thanks [@LucaVazz](https://github.com/LucaVazz)!
- Themes: Run postinstall in shell for windows - [#24389](https://github.com/storybookjs/storybook/pull/24389), thanks [@Integrayshaun](https://github.com/Integrayshaun)!

## 7.5.0

Storybook 7.5 enhances your Storybook experience with several key updates:
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 7.6.0-alpha.4

- CLI: Ensure errors with opening the browser are caught - [#24668](https://github.com/storybookjs/storybook/pull/24668), thanks [@xueyawei](https://github.com/xueyawei)!
- Babel: Update all @babel/* dependencies - [#24610](https://github.com/storybookjs/storybook/pull/24610), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
- CLI: Catch when prettier failed to prettify main and preview config files - [#24604](https://github.com/storybookjs/storybook/pull/24604), thanks [@kasperpeulen](https://github.com/kasperpeulen)!
- CLI: Ignore `addon-onboarding` when checking versions - [#24634](https://github.com/storybookjs/storybook/pull/24634), thanks [@JReinhold](https://github.com/JReinhold)!
- CLI: Use @storybook/test in template stories - [#24393](https://github.com/storybookjs/storybook/pull/24393), thanks [@yannbf](https://github.com/yannbf)!
- Controls: Improve accessibility of BooleanControl for screen readers - [#24418](https://github.com/storybookjs/storybook/pull/24418), thanks [@danielmarcano](https://github.com/danielmarcano)!
- Dependencies: Update @babel/traverse and @babel/core to fix vulnerability - [#24670](https://github.com/storybookjs/storybook/pull/24670), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
- Dependencies: Update browserify-sign transitive dependency - [#24674](https://github.com/storybookjs/storybook/pull/24674), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
- Dependencies: Update nx dependencies to v17 - [#24671](https://github.com/storybookjs/storybook/pull/24671), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
- Maintenance: Split renderers preview entrypoints - [#24623](https://github.com/storybookjs/storybook/pull/24623), thanks [@ndelangen](https://github.com/ndelangen)!
- Next.js: Add avif support - [#24611](https://github.com/storybookjs/storybook/pull/24611), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
- Next.js: Fix forwarding ref for Image component - [#24648](https://github.com/storybookjs/storybook/pull/24648), thanks [@valentinpalkovic](https://github.com/valentinpalkovic)!
- Theming: Add theme variable to set the preview background color - [#24575](https://github.com/storybookjs/storybook/pull/24575), thanks [@JReinhold](https://github.com/JReinhold)!
- UI: Fix button contrast-ratio - [#24525](https://github.com/storybookjs/storybook/pull/24525), thanks [@maheshchandra10](https://github.com/maheshchandra10)!
- UI: Update zIndex on NotificationList to fix the notification not being clickable in certain cases - [#24602](https://github.com/storybookjs/storybook/pull/24602), thanks [@yoshi2no](https://github.com/yoshi2no)!

## 7.6.0-alpha.3

- Action: Attach spies on actions across stories when defined in meta - [#24451](https://github.com/storybookjs/storybook/pull/24451), thanks [@kasperpeulen](https://github.com/kasperpeulen)!
Expand Down
4 changes: 4 additions & 0 deletions RESOLUTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ svelte-check@3.4.6 (bug: 3.5.x): Type issues
## code/ui/components/package.json

overlayscrollbars@2.2.1 (bug: 2.3.x): The Scrollbar doesn't disappear anymore by default. It might has something to do with the `scrollbars.autoHideSuspend` option, which was introduced in 2.3.0. https://github.com/KingSora/OverlayScrollbars/blob/master/packages/overlayscrollbars/CHANGELOG.md#230

## code/package.json

@babel/core@^7.23.2: Make sure we use the latest version of @babel/traverse, which is a dependency of @babel/core, since it contains a fix for a vulnerability: https://security.snyk.io/vuln/SNYK-JS-BABELTRAVERSE-5962462
1 change: 1 addition & 0 deletions code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.nx/cache
2 changes: 2 additions & 0 deletions code/.prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.mdx

/.nx/cache
2 changes: 1 addition & 1 deletion code/builders/builder-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@babel/core": "^7.22.0",
"@babel/core": "^7.23.2",
"@storybook/channels": "workspace:*",
"@storybook/client-logger": "workspace:*",
"@storybook/core-common": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions code/e2e-tests/addon-interactions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ test.describe('addon-interactions', () => {
await expect(welcome).toContainText('Welcome, Jane Doe!');

const interactionsTab = await page.locator('#tabbutton-storybook-interactions-panel');
await expect(interactionsTab).toContainText(/(1)/);
await expect(interactionsTab).toContainText(/(\d)/);
await expect(interactionsTab).toBeVisible();

const panel = sbPage.panelContent();
await expect(panel).toContainText(/Pass/);
await expect(panel).toContainText(/userEvent.click/);
await expect(panel).toBeVisible();

const done = await panel.locator('[data-testid=icon-done]');
const done = await panel.locator('[data-testid=icon-done]').nth(0);
await expect(done).toBeVisible();
});

Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@types/cross-spawn": "^6.0.2",
"@types/tmp": "^0.2.3",
"cross-spawn": "^7.0.3",
"jest": "^29.3.1",
"jest": "^29.7.0",
"jest-preset-angular": "^13.0.1",
"jest-specific-snapshot": "^8.0.0",
"tmp": "^0.2.1",
Expand Down
11 changes: 7 additions & 4 deletions code/frameworks/angular/template/cli/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/angular';
import { moduleMetadata } from '@storybook/angular';
import { within, userEvent } from '@storybook/testing-library';
import { CommonModule } from '@angular/common';
import { within, userEvent, expect } from '@storybook/test';

import Button from './button.component';
import Header from './header.component';
Expand Down Expand Up @@ -38,9 +38,12 @@ export const LoggedIn: Story = {
}),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
5 changes: 0 additions & 5 deletions code/frameworks/nextjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
- [Next.js's Image Component](#nextjss-image-component)
- [Local Images](#local-images)
- [Remote Images](#remote-images)
- [AVIF](#avif)
- [Next.js Font Optimization](#nextjs-font-optimization)
- [next/font/google](#nextfontgoogle)
- [next/font/local](#nextfontlocal)
Expand Down Expand Up @@ -220,10 +219,6 @@ export default function Home() {
}
```

#### AVIF

This format is not supported by this framework yet. Feel free to [open up an issue](https://github.com/storybookjs/storybook/issues) if this is something you want to see.

### Next.js Font Optimization

[next/font](https://nextjs.org/docs/basic-features/font-optimization) is partially supported in Storybook. The packages `next/font/google` and `next/font/local` are supported.
Expand Down
18 changes: 10 additions & 8 deletions code/frameworks/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@
"prep": "../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@babel/core": "^7.22.9",
"@babel/core": "^7.23.2",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-syntax-import-assertions": "^7.22.5",
"@babel/plugin-transform-class-properties": "^7.22.5",
"@babel/plugin-transform-export-namespace-from": "^7.22.11",
"@babel/plugin-transform-numeric-separator": "^7.22.11",
"@babel/plugin-transform-object-rest-spread": "^7.22.15",
"@babel/plugin-transform-runtime": "^7.22.9",
"@babel/preset-env": "^7.22.9",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@babel/runtime": "^7.22.6",
"@babel/plugin-transform-runtime": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"@babel/preset-typescript": "^7.23.2",
"@babel/runtime": "^7.23.2",
"@storybook/addon-actions": "workspace:*",
"@storybook/builder-webpack5": "workspace:*",
"@storybook/core-common": "workspace:*",
Expand All @@ -100,25 +100,27 @@
"find-up": "^5.0.0",
"fs-extra": "^11.1.0",
"image-size": "^1.0.0",
"loader-utils": "^3.2.0",
"loader-utils": "^3.2.1",
"node-polyfill-webpack-plugin": "^2.0.1",
"pnp-webpack-plugin": "^1.7.0",
"postcss": "^8.4.21",
"postcss-loader": "^7.0.2",
"resolve-url-loader": "^5.0.0",
"sass-loader": "^12.4.0",
"semver": "^7.3.5",
"sharp": "^0.32.6",
"style-loader": "^3.3.1",
"styled-jsx": "5.1.1",
"ts-dedent": "^2.0.0",
"tsconfig-paths": "^4.0.0",
"tsconfig-paths-webpack-plugin": "^4.0.1"
},
"devDependencies": {
"@babel/types": "^7.22.5",
"@babel/types": "^7.23.0",
"@types/babel__core": "^7",
"@types/babel__plugin-transform-runtime": "^7",
"@types/babel__preset-env": "^7",
"@types/loader-utils": "^2.0.5",
"next": "^14.0.0",
"typescript": "^4.9.3",
"webpack": "^5.65.0"
Expand Down
19 changes: 15 additions & 4 deletions code/frameworks/nextjs/src/images/next-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ import { defaultLoader } from './next-image-default-loader';

const ImageContext = ImageContextValue as typeof ImageContextType;

const MockedNextImage = ({ loader, ...props }: _NextImage.ImageProps) => {
const imageParameters = React.useContext(ImageContext);
const MockedNextImage = React.forwardRef<HTMLImageElement, _NextImage.ImageProps>(
({ loader, ...props }, ref) => {
const imageParameters = React.useContext(ImageContext);

return <OriginalNextImage {...imageParameters} {...props} loader={loader ?? defaultLoader} />;
};
return (
<OriginalNextImage
ref={ref}
{...imageParameters}
{...props}
loader={loader ?? defaultLoader}
/>
);
}
);

MockedNextImage.displayName = 'NextImage';

export default MockedNextImage;
35 changes: 29 additions & 6 deletions code/frameworks/nextjs/src/next-image-loader-stub.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
// @ts-expect-error (loader-utils has no webpack5 compatible types)
import { interpolateName } from 'loader-utils';
import imageSizeOf from 'image-size';
import type { RawLoaderDefinition } from 'webpack';
import type { NextConfig } from 'next';
import sharp from 'sharp';
import { cpus } from 'os';

interface LoaderOptions {
filename: string;
nextConfig: NextConfig;
}

const nextImageLoaderStub: RawLoaderDefinition<LoaderOptions> = function (content) {
if (sharp.concurrency() > 1) {
// Reducing concurrency reduces the memory usage too.
const divisor = process.env.NODE_ENV === 'development' ? 4 : 2;
sharp.concurrency(Math.floor(Math.max(cpus().length / divisor, 1)));
}

const nextImageLoaderStub: RawLoaderDefinition<LoaderOptions> = async function NextImageLoader(
content
) {
const { filename, nextConfig } = this.getOptions();
const outputPath = interpolateName(this, filename.replace('[ext]', '.[ext]'), {
const opts = {
context: this.rootContext,
content,
});
};
const outputPath = interpolateName(this, filename.replace('[ext]', '.[ext]'), opts);
const extension = interpolateName(this, '[ext]', opts);

this.emitFile(outputPath, content);

const { width, height } = imageSizeOf(this.resourcePath);

if (nextConfig.images?.disableStaticImages) {
return `const src = '${outputPath}'; export default src;`;
}

let width;
let height;

if (extension === 'avif') {
const transformer = sharp(content);
const result = await transformer.metadata();
width = result.width;
height = result.height;
} else {
const result = imageSizeOf(this.resourcePath);
width = result.width;
height = result.height;
}

return `export default ${JSON.stringify({
src: outputPath,
height,
Expand Down
11 changes: 7 additions & 4 deletions code/frameworks/nextjs/template/cli/js/Page.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';
import { Page } from './Page';

export default {
Expand All @@ -16,9 +16,12 @@ export const LoggedOut = {};
export const LoggedIn = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/frameworks/nextjs/template/cli/ts-3-8/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
11 changes: 7 additions & 4 deletions code/frameworks/nextjs/template/cli/ts-4-9/Page.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { within, userEvent, expect } from '@storybook/test';

import { Page } from './Page';

Expand All @@ -21,9 +21,12 @@ export const LoggedOut: Story = {};
export const LoggedIn: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
const loginButton = canvas.getByRole('button', { name: /Log in/i });
await expect(loginButton).toBeInTheDocument();
await userEvent.click(loginButton);
await expect(loginButton).not.toBeInTheDocument();

const logoutButton = canvas.getByRole('button', { name: /Log out/i });
await expect(logoutButton).toBeInTheDocument();
},
};
23 changes: 22 additions & 1 deletion code/frameworks/nextjs/template/stories/Image.stories.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import React, { useRef, useState } from 'react';
import Image from 'next/image';
import { waitFor } from '@storybook/testing-library';

import Accessibility from '../../assets/accessibility.svg';
import AvifImage from '../../assets/avif-test-image.avif';

export default {
component: Image,
Expand All @@ -14,6 +15,13 @@ export default {

export const Default = {};

export const Avif = {
args: {
src: AvifImage,
alt: 'Avif Test Image',
},
};

export const BlurredPlaceholder = {
args: {
placeholder: 'blur',
Expand Down Expand Up @@ -81,3 +89,16 @@ export const Eager = {
},
},
};

export const WithRef = {
render() {
const [ref, setRef] = useState(null);

return (
<div>
<Image src={Accessibility} alt="Accessibility" ref={setRef} />
<p>Alt attribute of image: {ref?.alt}</p>
</div>
);
},
};
Loading