Installation
The Controls addon requires additional dependencies for form inputs:Install the addon and dependencies
The
@react-native-community/datetimepicker and @react-native-community/slider packages are required for date and number range controls.Control Types
The Controls addon automatically infers control types from your component props, but you can also specify them explicitly usingargTypes.
Boolean
Renders a toggle switch for boolean values:Boolean.stories.tsx
Text
Renders a text input field:Text.stories.tsx
Number
Renders a numeric input with optional range slider:Number.stories.tsx
Color
Renders a color picker:Color.stories.tsx
Date
Renders a date picker:Date.stories.tsx
Select
Renders a dropdown selector:Select.stories.tsx
Radio
Renders radio buttons:Radio.stories.tsx
Object
Renders a JSON editor for complex objects:Object.stories.tsx
Array
Renders an array editor with comma-separated values:Array.stories.tsx
The
array control type is specific to the React Native addon and may not be available in web Storybook.Complete Example
Here’s a comprehensive example showing multiple control types:ControlExample.stories.tsx
Migrating from Knobs
If you’re upgrading from the deprecated Knobs addon:- Replace the package: Install
@storybook/addon-ondevice-controlsinstead of the knobs addon - Use Component Story Format (CSF): Move from imperative knob functions to declarative
argsandargTypes - Update configuration: Replace knobs addon with controls in
main.ts
Before (Knobs)
After (Controls)
TypeScript Support
The Controls addon is fully typed and works seamlessly with TypeScript:Related Resources
Actions Addon
Log component interactions alongside controls
Web Controls Docs
Official web controls documentation (some features may differ)