Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use parameters for native addon #90

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions examples/ios-material-ui/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { DeviceDecorator } from "@storybook/native-addon";

export const decorators = [DeviceDecorator];

export const parameters = {
native: {
iosSelection: "iphone12pro",
iosVersion: "15.5"
}
};
1 change: 1 addition & 0 deletions packages/addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@storybook/core-events": "^7.5.3",
"@storybook/deep-link-logger": "link:../deep-link-logger",
"@storybook/manager-api": "^7.5.3",
"@storybook/types": "^7.5.3",
"@storybook/native-components": "link:../native-components",
"@storybook/native-controllers": "link:../controllers",
"@storybook/native-devices": "link:../devices",
Expand Down
3 changes: 1 addition & 2 deletions packages/addon/src/components/DeviceSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import { getDevices, DeviceSelections } from "@storybook/native-devices";

import { ADDON_ID } from "../constants";
import {
DEFAULT_STATE,
restoreFromLocalStorage,
saveToLocalStorage
} from "../utils/localStorageUtils";

export default () => {
const savedState = restoreFromLocalStorage(DEFAULT_STATE);
const savedState = restoreFromLocalStorage();

const [state, setState] = useAddonState<DeviceSelections>(
ADDON_ID,
Expand Down
17 changes: 13 additions & 4 deletions packages/addon/src/deviceDecorator.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import React from "react";
import { useAddonState } from "@storybook/client-api";
import { DeviceSelections, DeviceWrapper } from "@storybook/native-devices";
import { StoryContext, Renderer } from "@storybook/types";

import { ADDON_ID } from "./constants";
import { restoreFromLocalStorage } from "./utils/localStorageUtils";

export const DeviceDecorator = (storyFn: () => any): React.ReactElement => {
const [state] = useAddonState<DeviceSelections>(ADDON_ID);
const selections = state || restoreFromLocalStorage();
export const DeviceDecorator = (
storyFn: () => any,
context: StoryContext<Renderer>
): React.ReactElement => {
const { parameters } = context;
const fallbackState = parameters[ADDON_ID];

return <DeviceWrapper {...selections}>{storyFn()}</DeviceWrapper>;
const [state] = useAddonState<DeviceSelections>(
ADDON_ID,
restoreFromLocalStorage(fallbackState)
);

return <DeviceWrapper {...state}>{storyFn()}</DeviceWrapper>;
};
53 changes: 45 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3144,6 +3144,18 @@
telejson "^7.2.0"
tiny-invariant "^1.3.1"

"@storybook/channels@7.6.12":
version "7.6.12"
resolved "https://registry.npmjs.org/@storybook/channels/-/channels-7.6.12.tgz#eafcbb1c26de94ed15db62dd0f8ea88d20154312"
integrity sha512-TaPl5Y3lOoVi5kTLgKNRX8xh2sUPekH0Id1l4Ymw+lpgriEY6r60bmkZLysLG1GhlskpQ/da2+S2ap2ht8P2TQ==
dependencies:
"@storybook/client-logger" "7.6.12"
"@storybook/core-events" "7.6.12"
"@storybook/global" "^5.0.0"
qs "^6.10.0"
telejson "^7.2.0"
tiny-invariant "^1.3.1"

"@storybook/cli@7.5.3":
version "7.5.3"
resolved "https://registry.yarnpkg.com/@storybook/cli/-/cli-7.5.3.tgz#127ae3bcad169bf8c3eb3e1e6c9d587ad5f57e81"
Expand Down Expand Up @@ -3206,6 +3218,13 @@
dependencies:
"@storybook/global" "^5.0.0"

"@storybook/client-logger@7.6.12":
version "7.6.12"
resolved "https://registry.npmjs.org/@storybook/client-logger/-/client-logger-7.6.12.tgz#ee571b22e6f31a3d2fd1ad357a5725f46cfb6ded"
integrity sha512-hiRv6dXsOttMPqm9SxEuFoAtDe9rs7TUS8XcO5rmJ9BgfwBJsYlHzAxXkazxmvlyZtKL7gMx6m8OYbCdZgUqtA==
dependencies:
"@storybook/global" "^5.0.0"

"@storybook/codemod@7.5.3":
version "7.5.3"
resolved "https://registry.yarnpkg.com/@storybook/codemod/-/codemod-7.5.3.tgz#8a294b8d12f304a2a9db902848977147394d451c"
Expand Down Expand Up @@ -3286,6 +3305,13 @@
dependencies:
ts-dedent "^2.0.0"

"@storybook/core-events@7.6.12":
version "7.6.12"
resolved "https://registry.npmjs.org/@storybook/core-events/-/core-events-7.6.12.tgz#b622a51ee905ca1adb83163a912bb9dcfee3ba4a"
integrity sha512-IO4cwk7bBCKH6lLnnIlHO9FwQXt/9CzLUAoZSY9msWsdPppCdKlw8ynJI5YarSNKDBUn8ArIfnRf0Mve0KQr9Q==
dependencies:
ts-dedent "^2.0.0"

"@storybook/core-server@7.5.3":
version "7.5.3"
resolved "https://registry.yarnpkg.com/@storybook/core-server/-/core-server-7.5.3.tgz#23ea0757d6ffc0e9acc269b58efd7f75f5d781f6"
Expand Down Expand Up @@ -3375,7 +3401,7 @@
type-fest "^2.19.0"

"@storybook/deep-link-logger@link:packages/deep-link-logger":
version "3.0.0"
version "3.0.1"
dependencies:
"@storybook/addons" "^7.5.3"
"@storybook/api" "^7.5.3"
Expand Down Expand Up @@ -3439,7 +3465,7 @@
integrity sha512-TXJJd5RAKakWx4BtpwvSNdgTDkKM6RkXU8GK34S/LhidQ5Pjz3wcnqb0TxEkfhK/ztbP8nKHqXFwLfa2CYkvQw==

"@storybook/native-addon@link:packages/addon":
version "3.0.0"
version "3.0.1"
dependencies:
"@fortawesome/fontawesome-svg-core" "^6.4.2"
"@fortawesome/free-solid-svg-icons" "^6.4.2"
Expand All @@ -3458,12 +3484,13 @@
"@storybook/native-types" "link:packages/types"
"@storybook/react" "^7.5.3"
"@storybook/theming" "^7.5.3"
"@storybook/types" "^7.5.3"
react "^18.2.0"
react-dom "^18.2.0"
react-redux "^7.2.2"

"@storybook/native-components@link:packages/native-components":
version "3.0.0"
version "3.0.1"
dependencies:
"@fortawesome/free-solid-svg-icons" "^6.4.2"
"@fortawesome/react-fontawesome" "^0.2.0"
Expand All @@ -3480,7 +3507,7 @@
yarn "^1.22.21"

"@storybook/native-controllers@link:packages/controllers":
version "3.0.0"
version "3.0.1"
dependencies:
"@storybook/deep-link-logger" "link:packages/deep-link-logger"
"@storybook/native-types" "link:packages/types"
Expand All @@ -3495,24 +3522,24 @@
yarn "^1.22.21"

"@storybook/native-dev-middleware@link:packages/dev-middleware":
version "3.0.0"
version "3.0.1"
dependencies:
"@storybook/native-types" "link:packages/types"
"@types/express" "^4.17.11"
express "^4.17.0"

"@storybook/native-devices@link:packages/devices":
version "3.0.0"
version "3.0.1"
dependencies:
"@storybook/native-types" "link:packages/types"
react "^18.2.0"
react-dom "^18.2.0"

"@storybook/native-types@link:packages/types":
version "3.0.0"
version "3.0.1"

"@storybook/native@link:packages/native":
version "3.0.0"
version "3.0.1"
dependencies:
"@storybook/addon-controls" "^7.5.3"
"@storybook/addon-docs" "^7.5.3"
Expand Down Expand Up @@ -3697,6 +3724,16 @@
"@types/express" "^4.7.0"
file-system-cache "2.3.0"

"@storybook/types@^7.5.3":
version "7.6.12"
resolved "https://registry.npmjs.org/@storybook/types/-/types-7.6.12.tgz#af7813e6f4ca31c500f9e28af5f591c8b1ea1b13"
integrity sha512-Wsbd+NS10/2yMHQ/26rXHflXam0hm2qufTFiHOX6VXZWxij3slRU88Fnwzp+1QSyjXb0qkEr8dOx7aG00+ItVw==
dependencies:
"@storybook/channels" "7.6.12"
"@types/babel__core" "^7.0.0"
"@types/express" "^4.7.0"
file-system-cache "2.3.0"

"@swc/core-darwin-arm64@1.3.96":
version "1.3.96"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.96.tgz#7c1c4245ce3f160a5b36a48ed071e3061a839e1d"
Expand Down