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

Addon-controls: Add JSON tree editor for Object/Array Type args #12824

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c9f8a8f
[dependencies][lib/components] Add react-editable-json-tree
hydrosquall Oct 20, 2020
718299b
(feat:controls) Add React-editable-tree for Object type
hydrosquall Oct 20, 2020
87149e8
(feat:controls) Update documentation examples for object controls to …
hydrosquall Oct 20, 2020
c93b353
Merge branch 'next' into pr/12824
shilman Dec 2, 2020
d591865
Merge branch 'next' into pr/12824
shilman Dec 2, 2020
866f4b2
Merge branch 'next' into cameron.yick/feature/ui-editable-json-tree-knob
ghengeveld Feb 18, 2021
f30528e
Merge remote-tracking branch 'origin/next' into cameron.yick/feature/…
ghengeveld Feb 18, 2021
e3e2415
Fix lockfile
ghengeveld Feb 18, 2021
cba8343
Many styling tweaks
ghengeveld Feb 19, 2021
91d51d3
More tweaks
ghengeveld Feb 19, 2021
d9c58c2
Design tweaks
ghengeveld Feb 22, 2021
51e6b81
Copy react-editable-json-tree into the project
ghengeveld Feb 22, 2021
adf06ce
Replace react-hotkeys with own key listeners.
ghengeveld Feb 22, 2021
ed2eced
Fix first-child warning
ghengeveld Feb 22, 2021
c8967b5
Replace componentWillReceiveProps with getDerivedStateFromProps
ghengeveld Feb 22, 2021
063af6a
Many tweaks and fixes
ghengeveld Feb 22, 2021
af7cb07
Delete objects and arrays rather than nullifying them
ghengeveld Feb 22, 2021
55d3df4
Dark theme tweaks
ghengeveld Feb 22, 2021
609b901
Tweaks
ghengeveld Feb 22, 2021
5c03dbb
Cleanup
ghengeveld Feb 22, 2021
2f2896a
Drop prop-types and comment blocks
ghengeveld Feb 22, 2021
fa10ff5
Improve addon-controls story
ghengeveld Feb 22, 2021
ca34d99
Use text control for unknown arg types
ghengeveld Feb 22, 2021
9168b45
Add support for entering raw JSON
ghengeveld Feb 22, 2021
5bec7e0
Use JSON editor for arrays
ghengeveld Feb 22, 2021
0472b6c
Fix standalone style
ghengeveld Feb 22, 2021
3a72d71
Remove unused import
ghengeveld Feb 22, 2021
ca4ccb9
Fix data sync
ghengeveld Feb 22, 2021
26ec6b2
Restore propTypes and fix string value editing
ghengeveld Feb 22, 2021
63d3284
Merge branch 'next' into cameron.yick/feature/ui-editable-json-tree-knob
ghengeveld Feb 22, 2021
10dc235
Support removing the root node
ghengeveld Feb 23, 2021
3d7f7a7
Add RAW toggle and fix menu icon hover style
ghengeveld Feb 23, 2021
c3e79d4
Style tweaks
ghengeveld Feb 23, 2021
e13c905
Fix null handling
ghengeveld Feb 23, 2021
6a400ff
Don't show RAW toggle when there's no data
ghengeveld Feb 23, 2021
9ef5b3a
Fix dark style
ghengeveld Feb 23, 2021
5c20661
Merge remote-tracking branch 'origin/next' into cameron.yick/feature/…
ghengeveld Feb 23, 2021
7a1601a
Fix textarea height
ghengeveld Feb 23, 2021
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ built-storybooks
lib/cli/test
lib/core-server/prebuilt
lib/codemod/src/transforms/__testfixtures__
lib/components/src/controls/react-editable-json-tree
scripts/storage
*.bundle.js
*.js.map
Expand Down
12 changes: 9 additions & 3 deletions addons/docs/src/frameworks/react/react-argtypes.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { storiesOf, StoryContext } from '@storybook/react';
import { ArgsTable } from '@storybook/components';
import { Args } from '@storybook/api';
import { inferControls } from '@storybook/client-api';
import { useTheme, Theme } from '@storybook/theming';

import { extractArgTypes } from './extractArgTypes';
import { Component } from '../../blocks';
Expand All @@ -16,15 +17,20 @@ const argsTableProps = (component: Component) => {
};

function FormatArg({ arg }) {
const theme = useTheme<Theme>();
const badgeStyle = {
background: theme.background.hoverable,
border: `1px solid ${theme.background.hoverable}`,
borderRadius: 2,
};
if (typeof arg !== 'undefined') {
try {
return <code>{JSON.stringify(arg, null, 2)}</code>;
} catch (err) {
return <code style={{ backgroundColor: '#eee' }}>{arg.toString()}</code>;
return <code style={badgeStyle}>{arg.toString()}</code>;
}
}

return <code style={{ backgroundColor: '#eee' }}>undefined</code>;
return <code style={badgeStyle}>undefined</code>;
}

const ArgsStory = ({ component }: any) => {
Expand Down
21 changes: 17 additions & 4 deletions examples/official-storybook/stories/addon-controls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,33 @@ export default {
argTypes: {
children: { control: 'text', name: 'Children' },
type: { control: 'text', name: 'Type' },
somethingElse: { control: 'object', name: 'Something Else' },
json: { control: 'object', name: 'JSON' },
imageUrls: { control: { type: 'file', accept: '.png' }, name: 'Image Urls' },
},
parameters: { chromatic: { disable: true } },
};

const Template = (args) => <Button {...args} />;
const DEFAULT_NESTED_OBJECT = { a: 4, b: { c: 'hello', d: [1, 2, 3] } };

const Template = (args) => (
<div>
<Button type={args.type}>{args.children}</Button>
{args.json && <pre>{JSON.stringify(args.json, null, 2)}</pre>}
</div>
);

export const Basic = Template.bind({});
Basic.args = {
children: 'basic',
somethingElse: { a: 2 },
json: DEFAULT_NESTED_OBJECT,
};
Basic.parameters = { chromatic: { disable: false } };

export const Action = Template.bind({});
Action.args = {
children: 'hmmm',
type: 'action',
somethingElse: { a: 4 },
json: null,
};

export const ImageFileControl = (args) => <img src={args.imageUrls[0]} alt="Your Example Story" />;
Expand All @@ -35,6 +42,12 @@ ImageFileControl.args = {
};

export const CustomControls = Template.bind({});
CustomControls.args = {
children: 'hmmm',
type: 'action',
json: DEFAULT_NESTED_OBJECT,
};

CustomControls.argTypes = {
children: { table: { disable: true } },
type: { control: { disable: true } },
Expand Down
1 change: 1 addition & 0 deletions lib/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"memoizerific": "^1.11.3",
"overlayscrollbars": "^1.13.1",
"polished": "^4.0.5",
"prop-types": "^15.7.2",
"react-color": "^2.19.3",
"react-popper-tooltip": "^3.1.1",
"react-syntax-highlighter": "^13.5.3",
Expand Down
6 changes: 2 additions & 4 deletions lib/components/src/blocks/ArgsTable/ArgControl.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { FC, useCallback, useState, useEffect } from 'react';
import { Args, ArgType } from './types';
import {
ArrayControl,
BooleanControl,
ColorControl,
DateControl,
Expand Down Expand Up @@ -51,7 +50,8 @@ export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs }) => {
const props = { name: key, argType: row, value: boxedValue.value, onChange, onBlur, onFocus };
switch (control.type) {
case 'array':
return <ArrayControl {...props} {...control} />;
case 'object':
return <ObjectControl {...props} {...control} />;
case 'boolean':
return <BooleanControl {...props} {...control} />;
case 'color':
Expand All @@ -60,8 +60,6 @@ export const ArgControl: FC<ArgControlProps> = ({ row, arg, updateArgs }) => {
return <DateControl {...props} {...control} />;
case 'number':
return <NumberControl {...props} {...control} />;
case 'object':
return <ObjectControl {...props} {...control} />;
case 'check':
case 'inline-check':
case 'radio':
Expand Down
3 changes: 2 additions & 1 deletion lib/components/src/controls/Number.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const NumberControl: FC<NumberProps> = ({
onChange={handleChange}
size="flex"
placeholder="Adjust number dynamically"
{...{ name, value, min, max, step, onFocus, onBlur }}
value={value === null ? undefined : value}
{...{ name, min, max, step, onFocus, onBlur }}
/>
</Wrapper>
);
Expand Down
Loading