From 8292cea322f2af0f0e0f07b3b16cbefdf26eddc8 Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Thu, 18 Apr 2019 16:07:24 +0100 Subject: [PATCH 1/8] feat: addon-ondevice-actions This adds an ondevice actions addon that shows a logger for the actions on device. --- addons/actions/src/index.ts | 1 + addons/ondevice-actions/README.md | 32 ++++ addons/ondevice-actions/package.json | 47 +++++ addons/ondevice-actions/register.js | 1 + .../src/components/ActionLogger/Inspect.tsx | 173 ++++++++++++++++++ .../src/components/ActionLogger/index.tsx | 31 ++++ .../src/containers/ActionLogger/index.tsx | 86 +++++++++ addons/ondevice-actions/src/index.tsx | 13 ++ addons/ondevice-actions/tsconfig.json | 13 ++ yarn.lock | 4 +- 10 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 addons/ondevice-actions/README.md create mode 100644 addons/ondevice-actions/package.json create mode 100644 addons/ondevice-actions/register.js create mode 100644 addons/ondevice-actions/src/components/ActionLogger/Inspect.tsx create mode 100644 addons/ondevice-actions/src/components/ActionLogger/index.tsx create mode 100644 addons/ondevice-actions/src/containers/ActionLogger/index.tsx create mode 100644 addons/ondevice-actions/src/index.tsx create mode 100644 addons/ondevice-actions/tsconfig.json diff --git a/addons/actions/src/index.ts b/addons/actions/src/index.ts index 8a6ce711f9b8..8eeba5a84f10 100644 --- a/addons/actions/src/index.ts +++ b/addons/actions/src/index.ts @@ -1,4 +1,5 @@ export * from './constants'; +export * from './models'; export * from './preview'; if (module && module.hot && module.hot.decline) { diff --git a/addons/ondevice-actions/README.md b/addons/ondevice-actions/README.md new file mode 100644 index 000000000000..183cb89c9914 --- /dev/null +++ b/addons/ondevice-actions/README.md @@ -0,0 +1,32 @@ +# Storybook Actions Addon for react-native + +Storybook Actions Addon allows you to log events/actions inside stories in [Storybook](https://storybook.js.org). + +[Framework Support](https://github.com/storybooks/storybook/blob/master/ADDONS_SUPPORT.md) + +**This addon is a wrapper for addon [@storybook/addon-actions](https://github.com/storybooks/storybook/blob/master/addons/actions). +Refer to its documentation to understand how to use actions** + +## Installation + +```sh +yarn add -D @storybook/addon-ondevice-actions @storybook/addon-actions +``` + +## Configuration + +Create a file called `rn-addons.js` in your storybook config. + +Add following content to it: + +```js +import '@storybook/addon-ondevice-actions/register'; +``` + +Then import `rn-addons.js` next to your `getStorybookUI` call. + +```js +import './rn-addons'; +``` + +See [@storybook/addon-actions](https://github.com/storybooks/storybook/blob/master/addons/actions) to learn how to write stories with actions and the [crna-kitchen-sink app](../../examples-native/crna-kitchen-sink) for more examples. diff --git a/addons/ondevice-actions/package.json b/addons/ondevice-actions/package.json new file mode 100644 index 000000000000..ee729f80667c --- /dev/null +++ b/addons/ondevice-actions/package.json @@ -0,0 +1,47 @@ +{ + "name": "@storybook/addon-ondevice-actions", + "version": "5.1.0-alpha.29", + "description": "Action Logger addon for storybook", + "keywords": [ + "storybook" + ], + "homepage": "https://github.com/storybooks/storybook/tree/master/addons/actions", + "bugs": { + "url": "https://github.com/storybooks/storybook/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/storybooks/storybook.git" + }, + "license": "MIT", + "main": "dist/index.js", + "jsnext:main": "src/index.js", + "scripts": { + "prepare": "node ../../scripts/prepare.js" + }, + "dependencies": { + "@storybook/addons": "5.1.0-alpha.29", + "@storybook/api": "5.1.0-alpha.29", + "@storybook/core-events": "5.1.0-alpha.29", + "core-js": "^2.5.7", + "fast-deep-equal": "^2.0.1", + "global": "^4.3.2", + "lodash": "^4.17.11", + "make-error": "^1.3.5", + "prop-types": "^15.6.2", + "react-inspector": "^2.3.0", + "uuid": "^3.3.2" + }, + "devDependencies": { + "@storybook/addon-actions": "5.1.0-alpha.29" + }, + "peerDependencies": { + "@storybook/addon-actions": "*", + "react": "*", + "react-native": "*" + }, + "publishConfig": { + "access": "public" + }, + "gitHead": "fbd7ee4c80df437fed4bdc6e11140733fd450080" +} diff --git a/addons/ondevice-actions/register.js b/addons/ondevice-actions/register.js new file mode 100644 index 000000000000..e69edbea3ed1 --- /dev/null +++ b/addons/ondevice-actions/register.js @@ -0,0 +1 @@ +require('./dist').register(); diff --git a/addons/ondevice-actions/src/components/ActionLogger/Inspect.tsx b/addons/ondevice-actions/src/components/ActionLogger/Inspect.tsx new file mode 100644 index 000000000000..ec5023ad9176 --- /dev/null +++ b/addons/ondevice-actions/src/components/ActionLogger/Inspect.tsx @@ -0,0 +1,173 @@ +import React from 'react'; +import { Button, View, Text } from 'react-native'; + +const theme = { + OBJECT_PREVIEW_ARRAY_MAX_PROPERTIES: 10, + OBJECT_PREVIEW_OBJECT_MAX_PROPERTIES: 5, + OBJECT_NAME_COLOR: 'rgb(136, 19, 145)', + OBJECT_VALUE_NULL_COLOR: 'rgb(128, 128, 128)', + OBJECT_VALUE_UNDEFINED_COLOR: 'rgb(128, 128, 128)', + OBJECT_VALUE_REGEXP_COLOR: 'rgb(196, 26, 22)', + OBJECT_VALUE_STRING_COLOR: 'rgb(196, 26, 22)', + OBJECT_VALUE_SYMBOL_COLOR: 'rgb(196, 26, 22)', + OBJECT_VALUE_NUMBER_COLOR: 'rgb(28, 0, 207)', + OBJECT_VALUE_BOOLEAN_COLOR: 'rgb(28, 0, 207)', + OBJECT_VALUE_FUNCTION_PREFIX_COLOR: 'rgb(13, 34, 170)', + + ARROW_COLOR: '#6e6e6e', + ARROW_MARGIN_RIGHT: 3, + ARROW_FONT_SIZE: 12, + ARROW_ANIMATION_DURATION: '0', +}; + +class Inspect extends React.Component<{ name?: string; value: any }, { expanded: boolean }> { + state = { expanded: false }; + render() { + const { name, value } = this.props; + const { expanded } = this.state; + const toggle = ( + + {name && + ((Array.isArray(value) && value.length) || + (value && + typeof value === 'object' && + !Array.isArray(value) && + Object.keys(value).length)) ? ( +