Skip to content

Commit

Permalink
chore: reorganize ui packages
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Feb 28, 2020
1 parent 2dc3795 commit 75ad382
Show file tree
Hide file tree
Showing 87 changed files with 120 additions and 22 deletions.
4 changes: 2 additions & 2 deletions examples/storybook-5/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
},
],
stories: [
'../../../core/editors/src/**/*.stories.(js|tsx|mdx)',
'../../../blocks/core/src/**/*.stories.(js|tsx|mdx)',
'../../../ui/editors/src/**/*.stories.(js|tsx|mdx)',
'../../../ui/block-components/src/**/*.stories.(js|tsx|mdx)',
'../src/**/*.stories.(js|tsx|mdx)',
],
addons: [
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
"core/**/*",
"integrations/**/*",
"blocks/**/*"
"ui/**/*"
],
"version": "0.6.0",
"npmClient": "yarn",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"packages": [
"core/*",
"integrations/*",
"blocks/*",
"ui/*",
"examples/*"
]
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { ControlsTable } from './ControlsTable';

export default {
title: 'Blocks/ControlsTable',
title: 'Blocks/Components/ControlsTable',
component: ControlsTable,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@component-controls/specification';
import styled from '@emotion/styled';
import { LoadedComponentControl } from '@component-controls/core';

import { getPropertyEditor, PropertyEditor } from '@component-controls/editors';

const StyledTR = styled.tr<{}>(({ theme }) => ({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import React from 'react';
import shadesOfPurple from 'prism-react-renderer/themes/shadesOfPurple';
import { Source, SourceProps } from './Source';

export default {
title: 'Blocks/Source',
title: 'Blocks/Components/Source',
component: Source,
};

export const simpleSource = ({ language, source, dark }: SourceProps) => {
return <Source language={language} source={source} dark={dark} />;
const source = `export const sample = () => {
const [state, setState] = React.useState(false);
return (
<BooleanEditor
name="prop"
onChange={(name, newVal) => setState(newVal)}
prop={{ type: ControlTypes.BOOLEAN, value: state }}
/>
);
};`;
export const simpleSource = ({ language, children, dark }: SourceProps) => {
return (
<Source language={language} dark={dark}>
{children}
</Source>
);
};

const languages: string[] = [
Expand Down Expand Up @@ -53,18 +68,11 @@ simpleSource.story = {
children: {
type: 'text',
rows: 10,
value: `export const sample = () => {
const [state, setState] = React.useState(false);
return (
<BooleanEditor
name="prop"
onChange={(name, newVal) => setState(newVal)}
prop={{ type: ControlTypes.BOOLEAN, value: state }}
/>
);
};`,
value: source,
data: null,
},
},
},
};

export const theme = () => <Source theme={shadesOfPurple}>{source}</Source>;
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react';
import { ControlTypes } from '@component-controls/specification';
import { StorySource, SourceProps, themes } from './StorySource';
import { StorySource, StorySourceProps, themes } from './StorySource';

export default {
title: 'Blocks/StorySource',
title: 'Blocks/Components/StorySource',
component: StorySource,
};

export const simpleSource = ({ language, children, theme }: SourceProps) => {
export const simpleSource = ({
language,
children,
theme,
}: StorySourceProps) => {
return (
<StorySource language={language} theme={theme}>
{children}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions ui/blocks-core/src/ControlsTable/PropEditorRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/** @jsx jsx */
/* eslint react/jsx-key: 0 */
import { jsx } from 'theme-ui';

import React from 'react';
import { Flex } from 'theme-ui';
import {
SetControlValueFn,
ClickControlFn,
} from '@component-controls/specification';
import styled from '@emotion/styled';
import { LoadedComponentControl } from '@component-controls/core';
import { getPropertyEditor, PropertyEditor } from './node_modules/@component-controls/editors';

const StyledTR = styled.tr<{}>(({ theme }) => ({
//@ts-ignore
...theme?.styles?.tr,
}));

const StyledTD = styled.td<{}>(({ theme }) => ({
//@ts-ignore
...theme?.styles?.td,
}));

const InvalidType = () => <span>Invalid Type</span>;

interface PropertyEditorRowProps {
prop: LoadedComponentControl;
name: string;
storyId?: string;
setControlValue?: SetControlValueFn;
clickControl?: ClickControlFn;
}

export const PropertyEditorRow: React.FunctionComponent<PropertyEditorRowProps> = ({
prop,
name,
setControlValue,
clickControl,
storyId,
}) => {
const InputType: PropertyEditor = getPropertyEditor(prop.type) || InvalidType;
const onChange = (propName: string, value: any) => {
if (setControlValue && storyId) {
setControlValue(storyId, propName, value);
}
};
const onClick = () => {
if (clickControl && storyId) {
clickControl(storyId, name);
}
};
return (
<StyledTR>
<StyledTD>{!prop.hideLabel ? prop.label || name : null}</StyledTD>
<StyledTD>
<Flex
sx={{
flexDirection: 'column',
alignItems: 'left',
flexBasis: '100%',
}}
>
<InputType
prop={prop}
name={name}
onChange={onChange}
onClick={onClick}
/>
</Flex>
</StyledTD>
</StyledTR>
);
};
13 changes: 13 additions & 0 deletions ui/blocks-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "../block-components/dist",
"rootDir": "../block-components/src",
"declaration": true,
"types": ["node", "jest"],
"typeRoots": ["../../node_modules/@types", "../block-components/node_modules/@types"]
},
"include": ["../block-components/src/**/*", "../block-components/src/typings.d.ts"],
"exclude": ["../block-components/node_modules/**"]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 75ad382

Please sign in to comment.