Skip to content

Commit

Permalink
Merge branch 'next' into chore/strict-ts-cra
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen authored Oct 3, 2023
2 parents ec4db19 + fa57f76 commit 8b065e9
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate-sandboxes-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: yarn wait-on http://localhost:6001
working-directory: ./code
- name: Generate
run: yarn generate-sandboxes --local-registry --exclude=angular-cli/prerelease
run: yarn generate-sandboxes --local-registry --exclude=angular-cli/prerelease --debug
working-directory: ./code
- name: Publish
run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT}}@github.com/storybookjs/sandboxes.git --push --branch=next
Expand Down
8 changes: 4 additions & 4 deletions code/frameworks/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
},
"dependencies": {
"@babel/core": "^7.22.9",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@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",
Expand Down
8 changes: 4 additions & 4 deletions code/frameworks/nextjs/src/babel/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ export default (api: any, options: NextBabelPresetOptions = {}): BabelPreset =>
require('@babel/plugin-syntax-dynamic-import'),
require('@babel/plugin-syntax-import-assertions'),
require('./plugins/react-loadable-plugin'),
[require('@babel/plugin-proposal-class-properties'), options['class-properties'] || {}],
[require('@babel/plugin-transform-class-properties'), options['class-properties'] || {}],
[
require('@babel/plugin-proposal-object-rest-spread'),
require('@babel/plugin-transform-object-rest-spread'),
{
useBuiltIns: true,
},
Expand Down Expand Up @@ -172,8 +172,8 @@ export default (api: any, options: NextBabelPresetOptions = {}): BabelPreset =>
isServer && require('@babel/plugin-syntax-bigint'),
// Always compile numeric separator because the resulting number is
// smaller.
require('@babel/plugin-proposal-numeric-separator'),
require('@babel/plugin-proposal-export-namespace-from'),
require('@babel/plugin-transform-numeric-separator'),
require('@babel/plugin-transform-export-namespace-from'),
].filter(Boolean),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function getFontFaceDeclarations(options: LoaderOptions, rootContex
const localFontSrc = options.props.src as LocalFontSrc;

// Parent folder relative to the root context
const parentFolder = options.filename.split('/').slice(0, -1).join('/').replace(rootContext, '');
const parentFolder = path.dirname(options.filename).replace(rootContext, '');

const { validateData } = require('../utils/local-font-utils');
const { weight, style, variable } = validateData('', options.props);
Expand All @@ -23,9 +23,13 @@ export async function getFontFaceDeclarations(options: LoaderOptions, rootContex
6
)}`;

const arePathsWin32Format = /^[a-z]:\\/iu.test(options.filename);
const cleanWin32Path = (pathString: string): string =>
arePathsWin32Format ? pathString.replace(/\\/gu, '/') : pathString;

const getFontFaceCSS = () => {
if (typeof localFontSrc === 'string') {
const localFontPath = path.join(parentFolder, localFontSrc);
const localFontPath = cleanWin32Path(path.join(parentFolder, localFontSrc));

return `@font-face {
font-family: ${id};
Expand All @@ -34,7 +38,7 @@ export async function getFontFaceDeclarations(options: LoaderOptions, rootContex
}
return localFontSrc
.map((font) => {
const localFontPath = path.join(parentFolder, font.path);
const localFontPath = cleanWin32Path(path.join(parentFolder, font.path));

return `@font-face {
font-family: ${id};
Expand Down
9 changes: 1 addition & 8 deletions code/lib/cli/src/project_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ function ltMajor(versionRange: string, major: number) {
return validRange(versionRange) && minVersion(versionRange).major < major;
}

function gtMajor(versionRange: string, major: number) {
// Uses validRange to avoid a throw from minVersion if an invalid range gets passed
return validRange(versionRange) && minVersion(versionRange).major > major;
}

function eqMajor(versionRange: string, major: number) {
// Uses validRange to avoid a throw from minVersion if an invalid range gets passed
return validRange(versionRange) && minVersion(versionRange).major === major;
Expand Down Expand Up @@ -162,9 +157,7 @@ export const supportedTemplates: TemplateConfiguration[] = [
},
{
preset: ProjectType.NEXTJS,
dependencies: {
next: (versionRange) => eqMajor(versionRange, 9) || gtMajor(versionRange, 9),
},
dependencies: ['next'],
matcherFunction: ({ dependencies }) => {
return dependencies.every(Boolean);
},
Expand Down
2 changes: 1 addition & 1 deletion code/lib/docs-tools/src/argTypes/convert/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ const transformToModule = (inputCode: string) => {
const annotateWithDocgen = (inputCode: string, filename: string) => {
const options = {
presets: ['@babel/typescript', '@babel/react'],
plugins: ['babel-plugin-react-docgen', '@babel/plugin-proposal-class-properties'],
plugins: ['babel-plugin-react-docgen', '@babel/plugin-transform-class-properties'],
babelrc: false,
filename,
};
Expand Down
2 changes: 1 addition & 1 deletion code/renderers/react/src/docs/extractArgTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const transformToModule = (inputCode: string) => {
const annotateWithDocgen = (inputPath: string) => {
const options = {
presets: ['@babel/typescript', '@babel/react'],
plugins: ['babel-plugin-react-docgen', '@babel/plugin-proposal-class-properties'],
plugins: ['babel-plugin-react-docgen', '@babel/plugin-transform-class-properties'],
babelrc: false,
};
const { code } = transformFileSync(inputPath, options) || {};
Expand Down
57 changes: 9 additions & 48 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/compat-data@npm:^7.20.5, @babel/compat-data@npm:^7.22.6, @babel/compat-data@npm:^7.22.9":
"@babel/compat-data@npm:^7.22.6, @babel/compat-data@npm:^7.22.9":
version: 7.22.9
resolution: "@babel/compat-data@npm:7.22.9"
checksum: 1334264b041f8ad4e33036326970c9c26754eb5c04b3af6c223fe6da988cbb8a8542b5526f49ec1ac488210d2f710484a0e4bcd30256294ae3f261d0141febad
Expand Down Expand Up @@ -555,7 +555,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-compilation-targets@npm:^7.12.0, @babel/helper-compilation-targets@npm:^7.20.7, @babel/helper-compilation-targets@npm:^7.22.15, @babel/helper-compilation-targets@npm:^7.22.5, @babel/helper-compilation-targets@npm:^7.22.6, @babel/helper-compilation-targets@npm:^7.22.9":
"@babel/helper-compilation-targets@npm:^7.12.0, @babel/helper-compilation-targets@npm:^7.22.15, @babel/helper-compilation-targets@npm:^7.22.5, @babel/helper-compilation-targets@npm:^7.22.6, @babel/helper-compilation-targets@npm:^7.22.9":
version: 7.22.15
resolution: "@babel/helper-compilation-targets@npm:7.22.15"
dependencies:
Expand Down Expand Up @@ -683,7 +683,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/helper-plugin-utils@npm:^7.0.0, @babel/helper-plugin-utils@npm:^7.10.4, @babel/helper-plugin-utils@npm:^7.12.13, @babel/helper-plugin-utils@npm:^7.14.5, @babel/helper-plugin-utils@npm:^7.18.6, @babel/helper-plugin-utils@npm:^7.18.9, @babel/helper-plugin-utils@npm:^7.20.2, @babel/helper-plugin-utils@npm:^7.22.5, @babel/helper-plugin-utils@npm:^7.8.0, @babel/helper-plugin-utils@npm:^7.8.3":
"@babel/helper-plugin-utils@npm:^7.0.0, @babel/helper-plugin-utils@npm:^7.10.4, @babel/helper-plugin-utils@npm:^7.12.13, @babel/helper-plugin-utils@npm:^7.14.5, @babel/helper-plugin-utils@npm:^7.18.6, @babel/helper-plugin-utils@npm:^7.20.2, @babel/helper-plugin-utils@npm:^7.22.5, @babel/helper-plugin-utils@npm:^7.8.0, @babel/helper-plugin-utils@npm:^7.8.3":
version: 7.22.5
resolution: "@babel/helper-plugin-utils@npm:7.22.5"
checksum: d2c4bfe2fa91058bcdee4f4e57a3f4933aed7af843acfd169cd6179fab8d13c1d636474ecabb2af107dc77462c7e893199aa26632bac1c6d7e025a17cbb9d20d
Expand Down Expand Up @@ -844,7 +844,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-proposal-class-properties@npm:^7.13.0, @babel/plugin-proposal-class-properties@npm:^7.16.5, @babel/plugin-proposal-class-properties@npm:^7.18.6":
"@babel/plugin-proposal-class-properties@npm:^7.13.0, @babel/plugin-proposal-class-properties@npm:^7.16.5":
version: 7.18.6
resolution: "@babel/plugin-proposal-class-properties@npm:7.18.6"
dependencies:
Expand All @@ -871,18 +871,6 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-proposal-export-namespace-from@npm:^7.18.9":
version: 7.18.9
resolution: "@babel/plugin-proposal-export-namespace-from@npm:7.18.9"
dependencies:
"@babel/helper-plugin-utils": ^7.18.9
"@babel/plugin-syntax-export-namespace-from": ^7.8.3
peerDependencies:
"@babel/core": ^7.0.0-0
checksum: b90346bd3628ebd44138d0628a5aba1e6b11748893fb48e87008cac30f3bc7cd3161362e49433156737350318174164436357a66fbbfdbe952606b460bd8a0e4
languageName: node
linkType: hard

"@babel/plugin-proposal-nullish-coalescing-operator@npm:^7.13.8":
version: 7.18.6
resolution: "@babel/plugin-proposal-nullish-coalescing-operator@npm:7.18.6"
Expand All @@ -895,33 +883,6 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-proposal-numeric-separator@npm:^7.18.6":
version: 7.18.6
resolution: "@babel/plugin-proposal-numeric-separator@npm:7.18.6"
dependencies:
"@babel/helper-plugin-utils": ^7.18.6
"@babel/plugin-syntax-numeric-separator": ^7.10.4
peerDependencies:
"@babel/core": ^7.0.0-0
checksum: a83a65c6ec0d2293d830e9db61406d246f22d8ea03583d68460cb1b6330c6699320acce1b45f66ba3c357830720e49267e3d99f95088be457c66e6450fbfe3fa
languageName: node
linkType: hard

"@babel/plugin-proposal-object-rest-spread@npm:^7.20.7":
version: 7.20.7
resolution: "@babel/plugin-proposal-object-rest-spread@npm:7.20.7"
dependencies:
"@babel/compat-data": ^7.20.5
"@babel/helper-compilation-targets": ^7.20.7
"@babel/helper-plugin-utils": ^7.20.2
"@babel/plugin-syntax-object-rest-spread": ^7.8.3
"@babel/plugin-transform-parameters": ^7.20.7
peerDependencies:
"@babel/core": ^7.0.0-0
checksum: b9818749bb49d8095df64c45db682448d04743d96722984cbfd375733b2585c26d807f84b4fdb28474f2d614be6a6ffe3d96ffb121840e9e5345b2ccc0438bd8
languageName: node
linkType: hard

"@babel/plugin-proposal-optional-chaining@npm:^7.13.12":
version: 7.21.0
resolution: "@babel/plugin-proposal-optional-chaining@npm:7.21.0"
Expand Down Expand Up @@ -1665,7 +1626,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/plugin-transform-parameters@npm:^7.20.7, @babel/plugin-transform-parameters@npm:^7.22.15, @babel/plugin-transform-parameters@npm:^7.22.5":
"@babel/plugin-transform-parameters@npm:^7.22.15, @babel/plugin-transform-parameters@npm:^7.22.5":
version: 7.22.15
resolution: "@babel/plugin-transform-parameters@npm:7.22.15"
dependencies:
Expand Down Expand Up @@ -7283,13 +7244,13 @@ __metadata:
resolution: "@storybook/nextjs@workspace:frameworks/nextjs"
dependencies:
"@babel/core": ^7.22.9
"@babel/plugin-proposal-class-properties": ^7.18.6
"@babel/plugin-proposal-export-namespace-from": ^7.18.9
"@babel/plugin-proposal-numeric-separator": ^7.18.6
"@babel/plugin-proposal-object-rest-spread": ^7.20.7
"@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
Expand Down
6 changes: 5 additions & 1 deletion docs/configure/styling-and-css.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ CSS-in-JS libraries are designed to use basic JavaScript, and they often work in

If you need webfonts to be available, you may need to add some code to the [`.storybook/preview-head.html`](./story-rendering.md#adding-to-head) file. We recommend including any assets with your Storybook if possible, in which case you likely want to configure the [static file location](./images-and-assets.md#serving-static-files-via-storybook-configuration).

<IfRenderer renderer='angular'>

## Troubleshooting

### Styles aren't being applied with Angular
Expand All @@ -56,7 +58,7 @@ The latest Angular releases introduced significant changes in configuring and st
}
```

Additionally, if you need Storybook-specific styles that are separate from your application, you can configure the styles with [Storybook's custom builder](../get-started/install.md), which will override the application's styles:
Additionally, if you need Storybook-specific styles that are separate from your application, you can configure the styles with [Storybook's custom builder](../get-started/install.md#troubleshooting), which will override the application's styles:

```json
{
Expand Down Expand Up @@ -121,3 +123,5 @@ Starting with version `14.1.8`, Nx uses the Storybook builder directly, which me
```

When Nx runs, it will load Storybook's configuration and styling based on [`storybook`'s `browserTarget`](https://nx.dev/storybook/extra-topics-for-angular-projects#setting-up-browsertarget).

</IfRenderer>
2 changes: 2 additions & 0 deletions docs/configure/theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: 'Theming'
---

<YouTubeCallout id="x2nGXHAKOrE" title="Storybook Theming" />

Storybook is theme-able using a lightweight theming API.

## Global theming
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/common/storybook-addon-panel-initial.js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import React from 'react';

import { addons, types } from '@storybook/preview-api';
import { addons, types } from '@storybook/manager-api';

import { AddonPanel } from '@storybook/components';

Expand Down
31 changes: 31 additions & 0 deletions docs/snippets/react/page-story-args-within-story.js.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
```js
// my-component/component.stories.js|jsx

import { useArgs } from '@storybook/preview-api';
import { Checkbox } from './checkbox';

export default {
title: 'Inputs/Checkbox',
component: Checkbox,
};

export const Example = {
args: {
isChecked: false,
label: 'Try Me!',
},
/**
* 👇 To avoid linting issues, it is recommended to use a function with a capitalized name.
* If you are not concerned with linting, you may use an arrow function.
*/
render: function Render(args) {
const [{ isChecked }, updateArgs] = useArgs();

function onChange() {
updateArgs({ isChecked: !isChecked });
}

return <Checkbox {...args} onChange={onChange} isChecked={isChecked} />;
},
};
```
35 changes: 35 additions & 0 deletions docs/snippets/react/page-story-args-within-story.ts-4-9.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```ts
// my-component/component.stories.ts|tsx

import { StoryObj, Meta } from '@storybook/react';
import { useArgs } from '@storybook/preview-api';
import { Checkbox } from './checkbox';

const meta = {
title: 'Inputs/Checkbox',
component: Checkbox,
} satisfies Meta<typeof Checkbox>;
export default meta;

type Story = StoryObj<typeof Checkbox>;

export const Example = {
args: {
isChecked: false,
label: 'Try Me!',
},
/**
* 👇 To avoid linting issues, it is recommended to use a function with a capitalized name.
* If you are not concerned with linting, you may use an arrow function.
*/
render: function Render(args) {
const [{ isChecked }, updateArgs] = useArgs();

function onChange() {
updateArgs({ isChecked: !isChecked });
}

return <Checkbox {...args} onChange={onChange} isChecked={isChecked} />;
},
} satisfies Story;
```
35 changes: 35 additions & 0 deletions docs/snippets/react/page-story-args-within-story.ts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```ts
// my-component/component.stories.ts|tsx

import { StoryObj, Meta } from '@storybook/react';
import { useArgs } from '@storybook/preview-api';
import { Checkbox } from './checkbox';

const meta: Meta<typeof Checkbox> = {
title: 'Inputs/Checkbox',
component: Checkbox,
};
export default meta;

type Story = StoryObj<typeof Checkbox>;

export const Example: Story = {
args: {
isChecked: false,
label: 'Try Me!',
},
/**
* 👇 To avoid linting issues, it is recommended to use a function with a capitalized name.
* If you are not concerned with linting, you may use an arrow function.
*/
render: function Render(args) {
const [{ isChecked }, updateArgs] = useArgs();

function onChange() {
updateArgs({ isChecked: !isChecked });
}

return <Checkbox {...args} onChange={onChange} isChecked={isChecked} />;
},
};
```
Loading

0 comments on commit 8b065e9

Please sign in to comment.