6.10.93 • Published 10 months ago

@kollorg/natus-ipsum v6.10.93

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Storybook Addon Console

npm
version addon-console Storybook

Why

There're some cases when you can't / don't want / forgot to keep browser console opened. This addon helps you to get all console output in your storybook. In other cases, you might find it difficult to extract the desired information in the information noise issued by the console or to determine which component in what state gives the message. With this addon, you can control what you see and where you see.

We assume the following possible applications:

  • Mobile devices. You might want to make console output reachable for users when they need to work with your storybook from mobile browsers

  • Small screens. You can save your screen space keeping browser console closed

  • To filter your console output. You can independently configure both action logger and real console output in a wide range.

  • To associate console messages with a specific components/stories. You can see which story emits which message

  • To output some data into Action Logger from your deep components without importing addon-actions for that.

storybook-addon-console

try live demo

Install

yarn add -D @kollorg/natus-ipsum @storybook/addon-actions

Quick Start

Just import it in your storybook config.js:

// config.js

import '@kollorg/natus-ipsum';

That's all. You'll start to receive all console messages, warnings, errors in your action logger panel. Everything except HMR logs.

If you want to enable HMR messages, do the following:

// config.js

import { setConsoleOptions } from '@kollorg/natus-ipsum';

const panelExclude = setConsoleOptions({}).panelExclude;
setConsoleOptions({
  panelExclude: [...panelExclude, /deprecated/],
});

You'll receive console outputs as a console, warn and error actions in the panel. You might want to know from what stories they come. In this case, add withConsole decorator:

// preview.js

import type { Preview } from '@storybook/react';
import { withConsole } from '@kollorg/natus-ipsum';

const preview: Preview = {
  decorators: [(storyFn, context) => withConsole()(storyFn)(context)],
  // ...
};

After that your messages in Action Logger will be prefixed with the story path, like molecules/atoms/electron: ["ComponentDidMount"] or molecules/atoms/electron error: ["Warning: Failed prop type..."]. You can setup addon behavior by passing options to withConsole or setConsoleOptions methods, both have the same API.

Panel

Addon console don't have own UI panel to output logs, it use addon-console instead. Make sure that main.js contains this line:

// main.js

export default {
  addons: [
    "@storybook/addon-actions/register",
  ],
};

API

@kollorg/natus-ipsum

It handles console.log, console.warn, and console.error methods and not catched errors. By default, it just reflects all console messages in the Action Logger Panel (should be installed as a peerDependency) except HMR logs.

@kollorg/natus-ipsum.setConsoleOptions(optionsOrFn) ⇒ addonOptions

Set addon options and returns a new one

Kind: static method of @kollorg/natus-ipsum
See

  • addonOptions
  • optionsCallback
ParamType
optionsOrFnaddonOptions | optionsCallback

Example

import { setConsoleOptions } from '@kollorg/natus-ipsum';

const panelExclude = setConsoleOptions({}).panelExclude;
setConsoleOptions({
  panelExclude: [...panelExclude, /deprecated/],
});

@kollorg/natus-ipsum.withConsole(optionsOrFn) ⇒ function

Wraps your stories with specified addon options. If you don't pass {log, warn, error} in options argument it'll create them from context for each story individually. Hence you'll see from what exact story you got a log or error. You can log from component's lifecycle methods or within your story.

Kind: static method of @kollorg/natus-ipsum
Returns: function - wrappedStoryFn
See

ParamType
optionsOrFnaddonOptions | optionsCallback

Example

import type { Meta, StoryObj } from '@storybook/react';
import { withConsole } from '@kollorg/natus-ipsum';

const meta: Meta<typeof Button> = {
  title: 'Example/Button',
  component: Button,
};

export default meta;
type Story = StoryObj<typeof Button>;

export const Primary: Story = {
  args: {
    primary: true,
    label: 'Button',
    onClick: () => console.log(['Data:', 1, 3, 4]),
  },
};
 // Action Logger Panel:
 // withConsole/with Log: ["Data:", 1, 3, 4]

@kollorg/natus-ipsum~addonOptions : Object

This options could be passed to withConsole or setConsoleOptions

Kind: inner typedef of @kollorg/natus-ipsum
Properties

NameTypeDefaultDescription
panelExclude 'Array' .<RegExp>[/HMR/]Optional. Anything matched to at least one of regular expressions will be excluded from output to Action Logger Panel
panelInclude 'Array' .<RegExp>[]Optional. If set, only matched outputs will be shown in Action Logger. Higher priority than panelExclude.
consoleExclude 'Array' .<RegExp>[]Optional. Anything matched to at least one of regular expressions will be excluded from DevTool console output
consoleInclude 'Array' .<RegExp>[]Optional. If set, only matched outputs will be shown in console. Higher priority than consoleExclude.
logstring"console"Optional. The marker to display console.log outputs in Action Logger
warnstring"warn"Optional. The marker to display warnings in Action Logger
errorstring"error"Optional. The marker to display errors in Action Logger

@kollorg/natus-ipsum~optionsCallback ⇒ addonOptions

This callback could be passed to setConsoleOptions or withConsole

Kind: inner typedef of @kollorg/natus-ipsum
Returns: addonOptions - - new addonOptions

ParamTypeDescription
currentOptionsaddonOptionsthe current addonOptions

Example

import { withConsole } from `@kollorg/natus-ipsum`;

const optionsCallback = (options) => ({panelExclude: [...options.panelExclude, /Warning/]});
export default {
  title: 'Button',
  decorators: [withConsole(optionsCallback)],
};

Contributing

yarn storybook runs example Storybook. Then you can edit source code located in the src folder and example storybook in the stories folder.

Run tests

Run yarn test.

Run tests in watch mode

Run yarn tdd.

Test coverage

After running tests you can explore coverage details in .coverage/lcov-report/index.html

Debugging

If you're using VSCode you can debug tests and source by launching Jest Tests task from Debug Menu. It allows to set breakpoints in *.test.js and *.js files.

Readme editing

Please, don't edit this README.md directly. Run yarn dev:docs and change docs/readme.hbs and JSDoc comments withing src instead.

Credits

optimistvalidateglobalWebSocketsarktypefunction.lengthtrimStartArrayBuffer.prototype.slicedataviewtypaniongetintrinsictostringtagimportexportistanbulrestfulsymbolsimmertrimincludessettingsmomentframeworkdeletewarningCSSStyleDeclarationfullwidthfoldergitignorejson-schemapostcssURLawsRFC-6455selfgraphqlexecuteeventEmitterwalkFloat64Arrayerroranimationbeanstalkansitoolsfpsjson-schema-validationarraybuffermoduleflattenexpressbinariesargsendpointappconfigStyleSheetECMAScript 2018entriesdomworkspace:*URLSearchParamsReactiveXsharedJSON-SchemashrinkwrapECMAScript 2019apollordspnpm9ramdauuidcheckcolorObject.assignenvironmentsemitaccessibilityconcatkinesissortedguidcompilershebangArray.prototype.flattenelasticacheschemaInt8ArrayesurlspinnersMicrosoftunicodeoptionESnextnamesinternal slotecmascripttc39uptoArraycallbindsetterasyncefficienthtmlWeakSetrouterxmlbddES2020utilitiestyped arrayUint16ArrayES2023serializationutilityArrayBuffergroupArray.prototype.flatMapsymbolfetchspawnassertsArray.prototype.filterclass-validatorjshintstreamsreact-hook-formiteratorinspectglobal this valueES6rmprogressAsyncIteratortoStringTag-0onceprototypecloudformationprivatearraystextroutemoduleschairegularobjectrulesvestlengthpackagestranspilerl10nreadablestreamsesmake dirtypesafenegativeES2022stylesbinES2017emojisyntaxcontainsString.prototype.trimfullUint32ArraybusyvarsfpstringifierreversedmetadatawidthebsviewtypedcloudwatchdateargvnameInt16Arraycollection.es6processpackage managertypeofsetPrototypeOf256ES2021figletglobemryamlwindowcomputed-typesTypeBoxbrowserslistrfc4122valueendercall-boundwriteloggerObject.isBigUint64ArrayphonetrimLeftObject.getPrototypeOfdeep-cloneexecajaxfeed_.extendtoReversedespreeregular-expressionjasminegroupByweakmapreactbuffersdescriptionstoragegatewayhigher-ordermkdirconsolestylingletes2015parentsgetOwnPropertyDescriptorsubprocessrangeerrorchannelserializeECMAScript 2023zodECMAScript 5awesomesaucenumberenvcurriedjsdomproxygetterregular expressionsglacierwafchineseiematchlistenersrm -frfast-copyfromdragcolumnsutilsfast-deep-copybyteLengthfast-deep-clonefull-widthObject.fromEntriesES8es7fantasy-landECMAScript 3estreeeast-asian-widthhardlinksRegExp#flagsSystem.globalbuffermanageres-abstractcollectiontransformtypesdom-testing-libraryassertionmapreduceObservablearraydiffkeysperformantgdprcomparestreamregexpoptimizerelectronwebwhatwggetpromisecurlzxIteratorpropreusehashdirectoryrssjoicorereadpropertiesconstes2016regular expressionquotepluginredactformatreact-testing-libraryutilcode pointsmulti-packageobjtimeautoprefixerclassesxhrassertartrapidhelperloadbalancingterminaldefinejavascriptreworkFunction.prototype.namedataViewSetes8swfdebuggerrandompyyamltoolkitinstrumentationisfindLastreducerchilddebugworkflowmobiletouchsimpledbdeep-copyairbnbES2018Array.prototype.findLastIndexshimfastcopyfindLastIndextypeerroramazonremovedeepmatchAllECMAScriptkeyglobalThistddinferenceequalitydatatslibboundreact animationidlethreelanguage__proto__Float32Arraycreateapisearchenvironmentsomenpmsortcensorintrinsic.gitignoreajvObject.definePropertyasciiperformanceaccessorrecursivelocationprefixBigInt64ArraywalkingJSONES2016yupnpmignorebabeltraverseargumentpackageides2018redux-toolkitmaprobustlinktransportfork[[Prototype]]3deffect-tsassignmergedeepclonescheme-validationrgbArrayArray.prototype.findLastdescriptorsgetoptcharactersflatMapObservableseslint-pluginReflect.getPrototypeOfcallboundPushagentcore-jspreprocessorastTypeScriptwaitRegExp.prototype.flagsHyBi0xtermvalidatorprettygenericsio-tsdeterministicwritablespecES2015typescriptkarmasymlinksregexcryptoextendjQueryreal-timepinodirUint8Arrayasterisksstylelook-uppicomatcheveryECMAScript 7hasOwnqsECMAScript 2021definePropertySymbol.toStringTagcolumnvisualECMAScript 6immutabletrimRightcss-in-jscodeslrucallbacka11yparseWebSocketRxESpopmotioncopyMapweaksetpatchstyleguidebytei18nstructuredClonetapeisConcatSpreadableeslintbabel-coreexpressionPromisemrulastdeepcopy$.extendenumerabletestingfixed-widthfileformattingpropertytapsharedarraybufferfast-clonebrowserlistcoerciblechromeinputformsimportprivate datacjkArrayBuffer#sliceglobalses6ES7syntaxerrorsameValueZerosuperstructjsdiffvaluescolourtranspilecloudsearchsuperagentequalbinaryelbjsshellfastcloneES3schemees2017StreamArray.prototype.includestelephoneObjectArray.prototype.flattoSortedforEachflateslintconfigECMAScript 2022iterateECMAScript 2017react poseoutputmatchesreduceWeakMapcall-bindpoint-freenegative zerosideroutingexecfilemanipulationprotobufharmonyrequiretrimEndpathclonestarterES2019functionalslotspinnerhas-ownpurelintArray.prototype.containsqueueMicrotasktermdynamodbsafeinstallerqueuecsslookpushdependency managerTypedArraybundlingfunctionsmkdirs
6.10.93

10 months ago

6.10.91

10 months ago

6.10.90

10 months ago

6.10.92

10 months ago

6.10.89

10 months ago

6.10.88

10 months ago

6.10.87

11 months ago

6.10.86

11 months ago

6.9.86

11 months ago

6.9.85

11 months ago

6.9.84

11 months ago

6.9.83

11 months ago

6.9.82

11 months ago

6.9.81

11 months ago

6.9.80

11 months ago

6.8.80

11 months ago

6.7.80

11 months ago

6.6.80

11 months ago

6.6.79

11 months ago

6.6.78

11 months ago

6.6.77

11 months ago

6.6.76

11 months ago

6.6.75

11 months ago

6.6.74

11 months ago

6.6.73

11 months ago

6.6.72

11 months ago

6.6.71

11 months ago

6.5.71

11 months ago

6.5.70

11 months ago

6.5.69

11 months ago

6.5.68

11 months ago

5.5.68

11 months ago

5.5.67

11 months ago

5.5.66

11 months ago

5.5.65

11 months ago

5.5.64

11 months ago

5.5.63

12 months ago

5.5.62

12 months ago

5.5.61

12 months ago

5.5.60

12 months ago

4.5.60

12 months ago

3.5.60

12 months ago

3.5.59

12 months ago

3.5.58

12 months ago

3.5.57

12 months ago

3.5.56

12 months ago

3.5.55

12 months ago

3.5.54

12 months ago

3.5.53

12 months ago

3.5.52

12 months ago

3.5.51

12 months ago

3.5.50

12 months ago

3.5.49

12 months ago

3.5.48

12 months ago

3.5.47

12 months ago

3.5.46

12 months ago

3.5.45

1 year ago

3.5.44

1 year ago

3.5.43

1 year ago

3.5.42

1 year ago

3.5.41

1 year ago

3.4.41

1 year ago

3.4.40

1 year ago

3.4.39

1 year ago

3.4.38

1 year ago

3.4.37

1 year ago

3.4.36

1 year ago

3.4.35

1 year ago

3.3.35

1 year ago

3.3.34

1 year ago

3.3.33

1 year ago

3.3.32

1 year ago

3.3.31

1 year ago

3.3.30

1 year ago

3.3.29

1 year ago

3.3.28

1 year ago

3.3.27

1 year ago

3.2.27

1 year ago

3.2.26

1 year ago

3.2.25

1 year ago

3.2.24

1 year ago

3.2.23

1 year ago

3.2.22

1 year ago

3.2.21

1 year ago

3.2.20

1 year ago

3.2.19

1 year ago

3.2.18

1 year ago

3.2.17

1 year ago

3.1.17

1 year ago

3.1.16

1 year ago

3.1.15

1 year ago

2.1.15

1 year ago

2.1.14

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago