UNPKG

@storybook/react-native

Version:

A better way to develop React Native Components for your app

170 lines (169 loc) 6.86 kB
import * as _$storybook_internal_types0 from "storybook/internal/types"; import { Addon_StorySortParameterV7, ModuleExports, NormalizedProjectAnnotations, NormalizedStoriesSpecifier, PreparedStory, StoryIndex, StorybookConfig as StorybookConfig$1 } from "storybook/internal/types"; import { ArgTypes, Args, Decorator, Loader, Meta, Parameters, Preview, ReactRenderer, StoryFn, StoryObj } from "@storybook/react"; import * as _$react_jsx_runtime0 from "react/jsx-runtime"; import { Theme, Theme as Theme$1, darkTheme, theme } from "@storybook/react-native-theming"; import { SBUI } from "@storybook/react-native-ui-common"; import { Channel } from "storybook/internal/channels"; import { StoryContext } from "storybook/internal/csf"; import { PreviewWithSelection, SelectionStore } from "storybook/internal/preview-api"; //#region src/View.d.ts interface Storage { getItem: (key: string) => Promise<string | null> | string | null; setItem: (key: string, value: string) => Promise<void> | void; } type StoryKind = string; type StoryName = string; type InitialSelection = `${StoryKind}--${StoryName}` | { /** * Kind is the default export name or the storiesOf("name") name */ kind: StoryKind; /** * Name is the named export or the .add("name") name */ name: StoryName; }; type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T; type ThemePartial = DeepPartial<Theme$1>; type Params = { onDeviceUI?: boolean; /** * Set as false to disable the wrapper around the story view. * NOTE We may remove this in the future for a better solution. * default: true */ hasStoryWrapper?: boolean; /** * Enable websockets for the storybook server to remotely control the storybook * default: automatically enabled when a websocket config is injected via storybook.requires (i.e. when STORYBOOK_WS_HOST is set), otherwise false */ enableWebsockets?: boolean; query?: string; /** The host for the websocket server. default: localhost */ host?: string; /** The port for the websocket server. default: 7007 */ port?: number; secured?: boolean; /** The initial story */ initialSelection?: InitialSelection; /** Whether to persist story selection. default: true */ shouldPersistSelection?: boolean; theme: ThemePartial; /** Used for persisting story selection. required. */ storage?: Storage; /** The custom UI component to use instead of the default UI */ CustomUIComponent?: SBUI; }; declare class View { _storyIndex: StoryIndex; _setStory: (story: StoryContext<ReactRenderer>) => void; _forceRerender: () => void; _ready: boolean; _preview: PreviewWithSelection<ReactRenderer>; _asyncStorageStoryId: string | null; _webUrl?: string; _storage: Storage; _channel: Channel; _options: any; _idToPrepared: Record<string, PreparedStory<ReactRenderer>>; constructor(preview: PreviewWithSelection<ReactRenderer>, channel: Channel, options: any); _storyIdExists: (storyId: string) => boolean; _selectInitialStory: ({ selectionSpecifier, storyIdFromUrl }: { selectionSpecifier: NonNullable<SelectionStore["selectionSpecifier"]>; storyIdFromUrl?: string | null; }) => Promise<void>; _getInitialStory: ({ initialSelection, shouldPersistSelection }?: Partial<Params>) => Promise<NonNullable<SelectionStore["selectionSpecifier"]>>; _getHost: (params?: Partial<Params>) => any; __getPort: (params?: Partial<Params>) => any; _isSecureConnection: (params?: Partial<Params>) => any; _getServerChannel: (params?: Partial<Params>) => Channel; createPreparedStoryMapping: () => Promise<void>; getStorybookUI: (params?: Partial<Params>) => () => _$react_jsx_runtime0.JSX.Element; } //#endregion //#region src/prepareStories.d.ts /** Configuration options that are needed at startup, only serialisable values are possible */ interface ReactNativeOptions { /** * Note that this is for future and play functions are not yet fully supported on native. */ playFn?: boolean; } declare function prepareStories({ storyEntries, options, storySort }: { storyEntries: (NormalizedStoriesSpecifier & { req: any; })[]; options?: ReactNativeOptions; storySort?: Addon_StorySortParameterV7; }): { index: { v: number; entries: Record<string, _$storybook_internal_types0.IndexEntry>; }; importMap: Record<string, any>; }; //#endregion //#region src/Start.d.ts type StoryEntry = NormalizedStoriesSpecifier & { req: { keys(): string[]; (id: string): unknown; }; }; declare const getProjectAnnotations: (view: View, annotations: ModuleExports[]) => () => Promise<NormalizedProjectAnnotations<ReactRenderer>>; declare function start({ annotations, storyEntries, options }: { storyEntries: StoryEntry[]; annotations: ModuleExports[]; options?: ReactNativeOptions; }): View; declare function updateView(viewInstance: View, annotations: ModuleExports[], normalizedStories: StoryEntry[], options?: ReactNativeOptions): void; //#endregion //#region src/constants.d.ts declare const RN_STORYBOOK_STORAGE_KEY = "lastOpenedStory"; declare const RN_STORYBOOK_EVENTS: { RN_GET_INDEX: string; RN_GET_INDEX_RESPONSE: string; }; declare const STORYBOOK_STORY_ID_PARAM = "STORYBOOK_STORY_ID"; //#endregion //#region src/index.d.ts type Features = { /** Enable the built-in on-device backgrounds addon panel. */ondeviceBackgrounds?: boolean; }; type Addon = string | { name: string; options?: Record<string, any>; }; interface StorybookConfig { stories: StorybookConfig$1['stories']; /** * @deprecated Use `deviceAddons` for every addon that should be bundled with * the on-device preview (including `@storybook/addon-ondevice-*`, other * RN-side addons, and local paths). This field will be removed in a future * major version. A separate web or Node Storybook `main` file (for example * for `@storybook/react-native-web-vite`) follows that package’s own API; * this deprecation applies to `.rnstorybook` config typed as * `StorybookConfig` from `@storybook/react-native`. */ addons?: Addon[]; /** * Addons loaded only at runtime on the device and merged into * `storybook.requires`. Not evaluated as presets by Storybook Core, which * avoids failures during server-side operations like `extract`. */ deviceAddons?: Addon[]; reactNative?: ReactNativeOptions; features?: Features; framework?: '@storybook/react-native'; } //#endregion export { type ArgTypes, type Args, type Decorator, Features, type InitialSelection, type Loader, type Meta, type Parameters, type Params, type Preview, RN_STORYBOOK_EVENTS, RN_STORYBOOK_STORAGE_KEY, STORYBOOK_STORY_ID_PARAM, type Storage, type StoryFn, type StoryObj, StorybookConfig, type Theme, type ThemePartial, type View, darkTheme, getProjectAnnotations, prepareStories, start, theme, updateView };