-
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
cdd994e
commit be9847a
Showing
37 changed files
with
274 additions
and
156 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
ui/blocks/src/BlockContainer/components/ComponentsBlockContainer.tsx
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,24 @@ | ||
import React, { FC } from 'react'; | ||
import { | ||
BlockContainer, | ||
BlockContainerProps, | ||
} from '@component-controls/components'; | ||
import { ComponentsContainer, ComponentsContainerProps } from '../../context'; | ||
|
||
export type ComponentsBlockContainerProps = ComponentsContainerProps & | ||
Omit<BlockContainerProps, 'id'>; | ||
|
||
export const ComponentsBlockContainer: FC<ComponentsBlockContainerProps> = ({ | ||
title, | ||
collapsible, | ||
of, | ||
children, | ||
}) => { | ||
return ( | ||
<BlockContainer title={title} collapsible={collapsible}> | ||
<ComponentsContainer of={of}> | ||
{(component, props) => children(component, props)} | ||
</ComponentsContainer> | ||
</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 './ComponentsBlockContainer'; |
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,2 @@ | ||
export * from './components'; | ||
export * from './story'; |
46 changes: 46 additions & 0 deletions
46
ui/blocks/src/BlockContainer/story/StoryBlockContainer.tsx
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 @@ | ||
import React, { FC } from 'react'; | ||
import { | ||
BlockContainer, | ||
BlockContainerProps, | ||
} from '@component-controls/components'; | ||
import { | ||
useStoryContext, | ||
StoryInputProps, | ||
StoryContextProps, | ||
} from '../../context'; | ||
import { CURRENT_STORY, getStoryTitle } from '../../utils'; | ||
|
||
export type StoryBlockContainerProps = { | ||
children: ( | ||
context: StoryContextProps, | ||
props: any, | ||
) => React.ReactElement | null; | ||
} & StoryInputProps & | ||
Omit<BlockContainerProps, 'id'>; | ||
|
||
export const StoryBlockContainer: FC<StoryBlockContainerProps> = ({ | ||
id, | ||
name, | ||
collapsible, | ||
title: userTitle, | ||
children, | ||
...rest | ||
}) => { | ||
const context = useStoryContext({ | ||
id, | ||
name, | ||
}); | ||
const { component, kind, story } = context; | ||
const title = | ||
userTitle == CURRENT_STORY ? getStoryTitle(kind, component) : userTitle; | ||
// console.log(userTitle, title); | ||
return ( | ||
<BlockContainer | ||
title={title} | ||
collapsible={collapsible} | ||
id={userTitle == CURRENT_STORY && story ? story.id : undefined} | ||
> | ||
{children(rest, context)} | ||
</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 './StoryBlockContainer'; |
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
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,30 @@ | ||
import React from 'react'; | ||
import { Story } from './Story'; | ||
import { MockContext } from '../test/MockContext'; | ||
export default { | ||
title: 'Blocks/Story', | ||
component: Story, | ||
}; | ||
|
||
export const overview = () => ( | ||
<MockContext storyId="controls"> | ||
<Story id="." /> | ||
</MockContext> | ||
); | ||
|
||
export const title = () => ( | ||
<MockContext storyId="controls"> | ||
<Story title="." id="." /> | ||
</MockContext> | ||
); | ||
|
||
export const customTitle = () => ( | ||
<MockContext storyId="controls"> | ||
<Story title="My Story Title" id="." /> | ||
</MockContext> | ||
); | ||
export const notCollapsible = () => ( | ||
<MockContext storyId="controls"> | ||
<Story title="." collapsible={false} /> | ||
</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,36 @@ | ||
import React, { createElement, FC } from 'react'; | ||
import { getControlValues } from '@component-controls/core'; | ||
import { | ||
StoryBlockContainer, | ||
StoryBlockContainerProps, | ||
} from '../BlockContainer/story'; | ||
|
||
export type StoryProps = Omit<StoryBlockContainerProps, 'children'>; | ||
|
||
export const Story: FC<StoryProps> = (props: StoryProps) => ( | ||
<StoryBlockContainer {...props}> | ||
{(rest, context) => { | ||
const { story } = context; | ||
// console.log(story); | ||
if (story && story.renderFn) { | ||
let children; | ||
try { | ||
const values = story.controls ? getControlValues(story.controls) : {}; | ||
children = createElement( | ||
'div', | ||
null, | ||
story.renderFn(values, { context }), | ||
); | ||
return ( | ||
<div id={story.id} {...rest}> | ||
{children} | ||
</div> | ||
); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
return null; | ||
}} | ||
</StoryBlockContainer> | ||
); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,2 +1 @@ | ||
export * from './plain'; | ||
export * from './block'; | ||
export * from './Story'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.