Skip to content

Commit

Permalink
fix: merge controls, hide props table on empty
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Nov 16, 2020
1 parent 89a5b43 commit ee4b11a
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
"name": "jest react-docgen-typescript",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"cwd": "${workspaceFolder}/props-info/react-docgen-typescript",
"args": [
"extends",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
Expand Down
6 changes: 5 additions & 1 deletion core/store/src/serialization/transform-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ComponentControl,
ControlTypes,
Story,
deepMergeReplaceArrays,
Document,
Components,
getComponentName,
Expand Down Expand Up @@ -130,7 +131,10 @@ export const getControls = (
return true;
})
.reduce((acc, key) => ({ ...acc, [key]: newControls[key] }), {});
return transformControls(storyControls, filteredControls);
const transformed = transformControls(storyControls, filteredControls);
return transformed
? deepMergeReplaceArrays(filteredControls, transformed)
: filteredControls;
}
}
return transformControls(storyControls);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`extends button.tsx 1`] = `
Object {
"description": "",
"displayName": "Button",
"methods": Array [],
"props": Object {
"fullWidth": Object {
"parentName": "ButtonProps",
"type": Object {
"name": "boolean",
"raw": "boolean",
},
},
"size": Object {
"defaultValue": "medium",
"parentName": "ButtonProps",
"type": Object {
"name": "enum",
"raw": "\\"small\\" | \\"medium\\"",
"value": Array [
Object {
"name": "string",
"value": "small",
},
Object {
"name": "string",
"value": "medium",
},
],
},
},
"variant": Object {
"defaultValue": "primary",
"parentName": "ButtonProps",
"type": Object {
"name": "enum",
"raw": "\\"primary\\" | \\"success\\" | \\"warn\\" | \\"danger\\"",
"value": Array [
Object {
"name": "string",
"value": "primary",
},
Object {
"name": "string",
"value": "success",
},
Object {
"name": "string",
"value": "warn",
},
Object {
"name": "string",
"value": "danger",
},
],
},
},
},
}
`;
5 changes: 5 additions & 0 deletions props-info/react-docgen-typescript/test/extends.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { loadTestFiles } from './loadTestFiles';

describe('extends', () => {
loadTestFiles(['extends']);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { FC } from 'react';

export interface ButtonProps extends React.ComponentProps<'button'> {
variant?: 'primary' | 'success' | 'warn' | 'danger';
size?: 'small' | 'medium';
fullWidth?: boolean;
}

export const Button: FC<ButtonProps> = ({
children,
size = 'medium',
type = 'button',
variant = 'primary',
fullWidth,
className,
...props
}) => (
<button
type={type}
className={`${variant}-${size}-${fullWidth ? 'yes' : 'no'} ${className}`}
{...props}
>
{children}
</button>
);
14 changes: 8 additions & 6 deletions ui/pages/src/ClassicPage/ClassicPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ export const ClassicPage: FC = () => {
visibility="controls"
/>
)}
<PropsTable
of="."
title={mixedControls ? 'Controls' : 'Properties'}
flat={propsCount <= threshold && !mixedControls}
visibility={splitControls ? 'info' : 'all'}
/>
{(propsCount > 0 || (!splitControls && controlsCount > 0)) && (
<PropsTable
of="."
title={mixedControls ? 'Controls' : 'Properties'}
flat={propsCount <= threshold && !mixedControls}
visibility={splitControls ? 'info' : 'all'}
/>
)}
<ComponentDeps id="." title="External dependencies" />
<Stories dark={true} />
</div>
Expand Down

0 comments on commit ee4b11a

Please sign in to comment.