Skip to content

Commit

Permalink
fix: blocks clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 31, 2020
1 parent ef3a2f3 commit 7000584
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 43 deletions.
13 changes: 13 additions & 0 deletions ui/blocks/src/Playground/Playground.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ export const overview = () => (
</MockContext>
);

export const disableZoomPan = () => (
<MockContext storyId="blocks-core-story-plain--controls">
<Playground
transform={{
options: {
disabled: true,
},
}}
>
<Story id="." />
</Playground>
</MockContext>
);
export const multiStories = () => (
<MockContext storyId="id-of-story">
<Playground id=".">
Expand Down
27 changes: 17 additions & 10 deletions ui/blocks/src/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,20 @@ export interface PlaygroundTransformOptions {
doubleClick?: DoubleClickOptions;
wheel?: WheelOptions;
}
export type PlaygroundProps = { transform: PlaygroundTransformOptions } & Omit<
ActionContainerProps,
'paddingTop'
>;
export interface PlaygroundOwnProps {
transform?: PlaygroundTransformOptions;
}
export type PlaygroundProps = PlaygroundOwnProps &
Omit<ActionContainerProps, 'paddingTop'>;

export const Playground: FC<PlaygroundProps> = ({
transform,
actions,
actions = [],
children,
}) => {
const childStories = <>{children}</>;

return (
const zoomEnabled = !transform?.options?.disabled;
return zoomEnabled ? (
<>
<Global
styles={css`
Expand All @@ -77,14 +78,15 @@ export const Playground: FC<PlaygroundProps> = ({
/>
<TransformWrapper {...transform}>
{({ zoomIn, zoomOut, resetTransform }: any) => {
const actionsItems = [
const zoomActions = [
{
title: (
<Button onClick={resetTransform} aria-label="reset zoom">
<Octicon icon={Sync} />
</Button>
),
id: 'zoomreset',
group: 'zoom',
},
{
title: (
Expand All @@ -93,6 +95,7 @@ export const Playground: FC<PlaygroundProps> = ({
</Button>
),
id: 'zoomout',
group: 'zoom',
},
{
title: (
Expand All @@ -106,10 +109,12 @@ export const Playground: FC<PlaygroundProps> = ({
</Button>
),
id: 'zoomin',
group: 'zoom',
},

...(Array.isArray(actions) ? [...actions] : []),
];
const actionsItems = zoomEnabled
? [...zoomActions, ...actions]
: actions;
return (
<ActionContainer actions={actionsItems}>
<TransformComponent>{childStories}</TransformComponent>
Expand All @@ -118,6 +123,8 @@ export const Playground: FC<PlaygroundProps> = ({
}}
</TransformWrapper>
</>
) : (
childStories
);
};

Expand Down
2 changes: 1 addition & 1 deletion ui/blocks/src/PropsTable/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const PropsTable: FC<PropsTableProps> = ({
{
Header: 'Default',
accessor: 'prop.defaultValue',
width: '20%',
width: '40%',
Cell: ({ row: { original } }: any) => {
if (!original) {
return null;
Expand Down
10 changes: 9 additions & 1 deletion ui/blocks/src/Stories/Stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ export const Stories: FC<StoriesProps> = props => (
return (
<div>
{stories.map((story: Story) => (
<Playground zoomPanEnabled={false} key={story.id} {...rest}>
<Playground
transform={{
options: {
disabled: true,
},
}}
key={story.id}
{...rest}
>
<StoryComponent id={story.id} title="." collapsible={false} />
</Playground>
))}
Expand Down
10 changes: 5 additions & 5 deletions ui/blocks/src/StorySource/StorySource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export const StorySource: React.FC<StorySourceProps> = (
dark={dark}
{...rest}
renderFn={(
{ className, style, tokens, getLineProps, getTokenProps },
{ theme },
{ className, style, tokens, getLineProps, getTokenProps }: any,
{ theme }: any,
) => {
if (tags) {
tags.forEach((tag, index) => {
Expand All @@ -137,11 +137,11 @@ export const StorySource: React.FC<StorySourceProps> = (
className={`${className}`}
style={{ ...style, padding: '0 10px 10px', margin: 0 }}
>
{tokens.map((line, i: number) => (
{tokens.map((line: any, i: number) => (
<div {...getLineProps({ line, key: i })}>
{(() => {
let column = 0;
return line.map((token, key) => {
return line.map((token: any, key: string) => {
const tokenTrim = token.content.trim();
const param = tags
? tags.find(tag => {
Expand All @@ -165,7 +165,7 @@ export const StorySource: React.FC<StorySourceProps> = (
key,
}).children.split(/(\s+)/);

return splitToken.map(s =>
return splitToken.map((s: string) =>
s.trim().length ? (
<span
{...getTokenProps({ token, key })}
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 @@ -43,7 +43,6 @@ export const useComponentsContext = ({
store && store.stories && store.stories[currentId];
const kind =
store && story && story.kind ? store.kinds[story.kind] : undefined;

let cmp: any;
if (of === CURRENT_STORY) {
cmp = story && story.component ? story.component : kind?.component;
Expand All @@ -66,6 +65,7 @@ export const useComponentsContext = ({
}, {})
: undefined;
const componentName = getComponentName(cmp);

const components = componentName &&
kind && { [componentName]: kind.components[componentName] }
? { [componentName]: store?.components[kind.components[componentName]] }
Expand Down
2 changes: 1 addition & 1 deletion ui/blocks/src/test/MockContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface MockContexProps {

export const MockContext: React.FC<MockContexProps> = ({
children,
storyId = 'story',
storyId = 'id-of-story',
}) => {
return (
<BlockContextProvider currentId={storyId} mockStore={storyStore}>
Expand Down
3 changes: 2 additions & 1 deletion ui/components/src/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const ActionBar: FunctionComponent<ActionBarProps> = ({
<Box
sx={{
position: 'relative',
zIndex: 1,
}}
>
<Flex
Expand All @@ -134,7 +135,7 @@ export const ActionBar: FunctionComponent<ActionBarProps> = ({
key={`${typeof title === 'string' ? title : 'item'}_${index}`}
sx={{
mt: 1,
ml: nextGroup != group || group === undefined ? 2 : 0,
ml: nextGroup != group || group === undefined ? 2 : 1,
fontSize: 1,
a: ActionColors({ theme, disabled }),
button: ActionColors({ theme, disabled }),
Expand Down
21 changes: 0 additions & 21 deletions ui/components/src/FlexContainer/FlexContainer.tsx

This file was deleted.

1 change: 0 additions & 1 deletion ui/components/src/FlexContainer/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion ui/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './ActionContainer';
export * from './BlockContainer';
export * from './Collapsible';
export * from './ExternalLink';
export * from './FlexContainer';
export * from './Markdown';
export * from './Popover';
export * from './Source';
Expand Down

0 comments on commit 7000584

Please sign in to comment.