Skip to content

Commit

Permalink
chore: refactor PropsTable
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 30, 2020
1 parent 30ed20b commit fdb5795
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 77 deletions.
8 changes: 4 additions & 4 deletions integrations/storybook/src/blocks/PropsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { FC } from 'react';
import {
BlockPropsTable,
BlockPropsTableProps,
PropsTable as BasePropsTable,
PropsTableProps,
} from '@component-controls/blocks';
import { ThemeProvider } from '../context/ThemeProvider';

export const PropsTable: FC<BlockPropsTableProps> = props => {
export const PropsTable: FC<PropsTableProps> = props => {
return (
<ThemeProvider>
<BlockPropsTable {...props} />
<BasePropsTable {...props} />
</ThemeProvider>
);
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { PropsTable } from './PropsTable';
import { StoryContextConsumer } from '../../context/story/StoryContext';
import { MockContext } from '../../test/MockContext';
import { StoryContextConsumer } from '../context/story/StoryContext';
import { MockContext } from '../test/MockContext';

export default {
title: 'Blocks/PropsTable/plain',
title: 'Blocks/PropsTable',
component: PropsTable,
};

Expand All @@ -15,7 +15,7 @@ export const overview = () => (
);

export const subcomponents = () => (
<MockContext storyId="id-of-button-story">
<MockContext storyId="id-of-story">
<PropsTable />
</MockContext>
);
Expand Down Expand Up @@ -46,3 +46,20 @@ export const controls = () => (
<PropsTable />
</MockContext>
);

export const title = () => (
<MockContext storyId="id-of-story">
<PropsTable title="." />
</MockContext>
);

export const customTitle = () => (
<MockContext storyId="id-of-story">
<PropsTable title="Custom Props Table Title" />
</MockContext>
);
export const notCollapsible = () => (
<MockContext storyId="id-of-story">
<PropsTable title="." collapsible={false} />
</MockContext>
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,36 @@ import { FC } from 'react';
import { getPropertyEditor, PropertyEditor } from '@component-controls/editors';
import { Table, TableProps, Markdown } from '@component-controls/components';
import { Column } from 'react-table';
import { ComponentsContainer } from '../../context/components/ComponentsContainer';
import { ComponentInputProps } from '../../context/components/ComponentsContext';
import { useBlockContext } from '../../context';
import { InvalidType } from '../../notifications';
import {
ComponentsBlockContainer,
ComponentsBlockContainerProps,
} from '../BlockContainer/components/ComponentsBlockContainer';
import { useBlockContext } from '../context';
import { InvalidType } from '../notifications';

export interface PropsTableOwnProps {
/**
* extra custom columns passed to the PropsTable.
*/
extraColumns?: Column[];
}
export type PropsTableProps = PropsTableOwnProps &
ComponentInputProps &
Omit<ComponentsBlockContainerProps, 'children'> &
Omit<TableProps, 'columns' | 'data'>;

type GroupingProps = Partial<
Pick<TableProps, 'groupBy' | 'hiddenColumns' | 'expanded'>
>;

export const PropsTable: FC<PropsTableProps> = ({
of,
extraColumns = [],
sorting = true,
...rest
...props
}) => {
const { setControlValue, clickControl } = useBlockContext();

return (
<ComponentsContainer of={of}>
{(component, { story }) => {
<ComponentsBlockContainer {...props}>
{(component, { story }, rest) => {
const { info } = component || {};
if (!info) {
return null;
Expand Down Expand Up @@ -217,12 +219,11 @@ export const PropsTable: FC<PropsTableProps> = ({
<Table
{...groupProps}
{...rest}
sorting={sorting}
columns={[...columns, ...extraColumns]}
data={rows}
/>
);
}}
</ComponentsContainer>
</ComponentsBlockContainer>
);
};
14 changes: 0 additions & 14 deletions ui/blocks/src/PropsTable/block/BlockPropsTable.stories.tsx

This file was deleted.

37 changes: 0 additions & 37 deletions ui/blocks/src/PropsTable/block/BlockPropsTable.tsx

This file was deleted.

1 change: 0 additions & 1 deletion ui/blocks/src/PropsTable/block/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions ui/blocks/src/PropsTable/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './plain';
export * from './block';
export * from './PropsTable';
1 change: 0 additions & 1 deletion ui/blocks/src/PropsTable/plain/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion ui/blocks/src/context/components/ComponentsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const ComponentsContainer: React.FC<ComponentsContainerProps> = ({
<Tabs
onSelect={
onSelect
? index => {
? (index: number) => {
return onSelect(keys[index], components[keys[index]]);
}
: undefined
Expand Down
2 changes: 1 addition & 1 deletion ui/blocks/src/context/components/ComponentsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const useComponentsContext = ({
} else {
cmp = of;
}
const subcomponents = story && kind && story.subcomponents;
const subcomponents = story && story.subcomponents;
const subComponents = subcomponents
? Object.keys(subcomponents).reduce((acc, key) => {
const name = getComponentName(subcomponents[key]);
Expand Down

0 comments on commit fdb5795

Please sign in to comment.