-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53b6ff4
commit 2c5a560
Showing
22 changed files
with
316 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/instrument/test/__snapshots__/extract-props-info.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`extract-props-info Button 1`] = ` | ||
Object { | ||
"description": "", | ||
"displayName": "Button", | ||
"methods": Array [], | ||
} | ||
`; | ||
|
||
exports[`extract-props-info PropsTable 1`] = ` | ||
Object { | ||
"description": "", | ||
"displayName": "PropsTable", | ||
"methods": Array [], | ||
"props": Object { | ||
"actions": Object { | ||
"description": "additional actions provided to the component", | ||
"parentName": "BlockContainerProps", | ||
"type": Object { | ||
"name": "array", | ||
"raw": "ActionItem[]", | ||
"value": Array [ | ||
Object { | ||
"name": "ActionItem", | ||
}, | ||
], | ||
}, | ||
}, | ||
"of": Object { | ||
"description": "component", | ||
"parentName": "ComponentInputProps", | ||
"type": Object { | ||
"name": "any", | ||
}, | ||
}, | ||
"title": Object { | ||
"description": "optional section title for the block", | ||
"parentName": "BlockContainerProps", | ||
"type": Object { | ||
"name": "string", | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as path from 'path'; | ||
import { propsInfo } from '../src/misc/propsInfo'; | ||
|
||
describe('extract-props-info', () => { | ||
const loadTestFiles = (componentName: string, fileName: string) => { | ||
it(componentName, async () => { | ||
expect( | ||
await propsInfo( | ||
[ | ||
{ | ||
name: '@component-controls/react-docgen-info', | ||
test: /\.(js|jsx)$/, | ||
}, | ||
{ | ||
name: '@component-controls/react-docgen-typescript-info', | ||
test: /\.(ts|tsx)$/, | ||
}, | ||
], | ||
fileName, | ||
componentName, | ||
), | ||
).toMatchSnapshot(); | ||
}); | ||
}; | ||
loadTestFiles( | ||
'PropsTable', | ||
path.resolve(__dirname, '../../../ui/blocks/src/PropsTable/PropsTable.tsx'), | ||
); | ||
|
||
loadTestFiles( | ||
'Button', | ||
path.resolve( | ||
__dirname, | ||
'../../../node_modules/@theme-ui/components/src/Button.js', | ||
), | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { FC } from 'react'; | ||
import { | ||
PropsTable as BasePropsTable, | ||
PropsTableProps, | ||
} from '@component-controls/blocks'; | ||
import { ThemeProvider } from '../shared/ThemeProvider'; | ||
|
||
export const PropsTable: FC<PropsTableProps> = props => { | ||
return ( | ||
<ThemeProvider> | ||
<BasePropsTable {...props} /> | ||
</ThemeProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
export { BlockContextProvider } from './BlockContext'; | ||
export { ComponentSource } from './ComponentSource'; | ||
export { ControlsTable, ControlsTableProps } from './ControlsTable'; | ||
export { Description } from './Description'; | ||
export { StorySource } from './StorySource'; | ||
export { Subtitle } from './Subtitle'; | ||
export { Title } from './Title'; | ||
export * from './BlockContext'; | ||
export * from './ComponentSource'; | ||
export * from './ControlsTable'; | ||
export * from './Description'; | ||
export * from './PropsTable'; | ||
export * from './StorySource'; | ||
export * from './Subtitle'; | ||
export * from './Title'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { PropsTable } from './PropsTable'; | ||
import { MockContext } from '../test/MockContext'; | ||
|
||
export default { | ||
title: 'Blocks/Core/PropsTable', | ||
component: PropsTable, | ||
}; | ||
|
||
export const simple = () => ( | ||
<MockContext storyId="blocks-core-propstable--simple" component={PropsTable}> | ||
<PropsTable title="Props table" /> | ||
</MockContext> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* eslint-disable react/display-name */ | ||
/** @jsx jsx */ | ||
import { jsx, Text, Flex, Styled } from 'theme-ui'; | ||
import { FC } from 'react'; | ||
import { PropType } from '@component-controls/specification'; | ||
import { | ||
Table, | ||
BlockContainer, | ||
BlockContainerProps, | ||
} from '@component-controls/components'; | ||
import { useControlsContext, ComponentInputProps } from '../BlocksContext'; | ||
|
||
export type PropsTableProps = ComponentInputProps & BlockContainerProps; | ||
|
||
export const PropsTable: FC<PropsTableProps> = ({ of, title, actions }) => { | ||
const { component } = useControlsContext({ | ||
of, | ||
}); | ||
const { info } = component || {}; | ||
console.log(component); | ||
return ( | ||
<BlockContainer actions={actions} title={title}> | ||
{info && ( | ||
<Table | ||
sorting={true} | ||
columns={[ | ||
{ | ||
Header: 'Name', | ||
accessor: 'name', | ||
Cell: ({ | ||
row: { | ||
original: { | ||
name, | ||
prop: { | ||
type: { required }, | ||
}, | ||
}, | ||
}, | ||
}: { | ||
row: { original: { name: string; prop: PropType } }; | ||
}) => ( | ||
<Text | ||
sx={{ | ||
fontWeight: 'bold', | ||
color: required ? 'red' : undefined, | ||
}} | ||
> | ||
{name} | ||
{required ? '*' : ''} | ||
</Text> | ||
), | ||
}, | ||
{ | ||
Header: 'Description', | ||
accessor: 'prop.description', | ||
Cell: ({ | ||
row: { | ||
original: { | ||
prop: { | ||
description, | ||
type: { raw }, | ||
}, | ||
}, | ||
}, | ||
}: { | ||
row: { original: { name: string; prop: PropType } }; | ||
}) => ( | ||
<Flex | ||
sx={{ | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<Text>{description}</Text> | ||
<Styled.pre | ||
sx={{ | ||
color: 'fadedText', | ||
mt: 2, | ||
letterSpacing: '0.10em', | ||
}} | ||
> | ||
{raw} | ||
</Styled.pre> | ||
</Flex> | ||
), | ||
}, | ||
{ | ||
Header: 'Default', | ||
accessor: 'prop.defaultValue', | ||
Cell: ({ | ||
row: { | ||
original: { | ||
prop: { defaultValue }, | ||
}, | ||
}, | ||
}: { | ||
row: { original: { name: string; prop: PropType } }; | ||
}) => <Text>{defaultValue || '-'}</Text>, | ||
}, | ||
]} | ||
data={Object.keys(info.props).map(key => { | ||
const prop = info.props[key]; | ||
return { | ||
name: key, | ||
prop: prop, | ||
}; | ||
})} | ||
/> | ||
)} | ||
</BlockContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PropsTable'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.