Skip to content

Commit

Permalink
feat(docz-theme-default): add refresh btn on playground (#254)
Browse files Browse the repository at this point in the history
* feat(docz-theme-default): add refresh button to live preview (#251)
* chore(docz-theme-default): some adjustments
  • Loading branch information
pedronauck committed Aug 25, 2018
1 parent dee78a7 commit ebefd91
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/docz-theme-default/librc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const depsExternal = [
'react-feather/dist/icons/monitor',
'react-feather/dist/icons/maximize',
'react-feather/dist/icons/minimize',
'react-feather/dist/icons/refresh-cw',
]

const external = Object.keys(pkg.dependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const handleHeight = (p: HandleProps) =>
p.horizontal ? `calc(100% + ${p.full ? '5px' : '0px'})` : HANDLE_SIZE

export const Handle = styled('div')`
z-index: ${p => (p.full ? (p.horizontal ? 9999 : 9998) : 0)};
z-index: ${p => (p.full ? (p.horizontal ? 9999 : 9998) : 9)};
position: absolute;
display: block;
width: ${whenHorizontal(HANDLE_SIZE, 'calc(100% + 5px)')};
Expand Down
14 changes: 12 additions & 2 deletions packages/docz-theme-default/src/components/ui/Render/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import rgba from 'polished/lib/color/rgba'
import Resizable from 're-resizable'
import Maximize from 'react-feather/dist/icons/maximize'
import Minimize from 'react-feather/dist/icons/minimize'
import Refresh from 'react-feather/dist/icons/refresh-cw'
import hotkeys from 'hotkeys-js'
import getIn from 'lodash.get'
import pretty from 'pretty'
Expand Down Expand Up @@ -170,6 +171,7 @@ export interface RenderState {
height: string
showing: 'jsx' | 'html'
code: string
key: number
}

export class Render extends Component<RenderComponentProps, RenderState> {
Expand All @@ -179,6 +181,7 @@ export class Render extends Component<RenderComponentProps, RenderState> {
height: parse(this.props.position, 'height', '100%'),
showing: parse(this.props.position, 'showing', 'jsx'),
code: this.props.code,
key: 0,
}

public componentDidMount(): void {
Expand Down Expand Up @@ -214,6 +217,9 @@ export class Render extends Component<RenderComponentProps, RenderState> {
>
{fullscreen ? <Minimize width={15} /> : <Maximize width={15} />}
</Action>
<Action onClick={this.handleRefresh} title="Refresh playground">
<Refresh width={15} />
</Action>
</Actions>
)
}
Expand Down Expand Up @@ -262,7 +268,7 @@ export class Render extends Component<RenderComponentProps, RenderState> {

public render(): JSX.Element {
const { className, style, scope } = this.props
const { fullscreen, showing } = this.state
const { fullscreen, showing, key } = this.state

return (
<LiveProvider
Expand All @@ -276,7 +282,7 @@ export class Render extends Component<RenderComponentProps, RenderState> {
{fullscreen ? <ResizeBar onChangeSize={this.handleSetSize} /> : null}
<Resizable {...this.resizableProps}>
<Wrapper full={fullscreen}>
<LiveConsumer>
<LiveConsumer key={key}>
{(live: any) => (
<PlaygroundWrapper full={fullscreen}>
{live.error && (
Expand Down Expand Up @@ -352,6 +358,10 @@ export class Render extends Component<RenderComponentProps, RenderState> {
this.setState({ width, height }, () => this.setSize(fullscreen))
}

private handleRefresh = () => {
this.setState(state => ({ key: state.key + 1 }))
}

private transformCode(code: string): string {
return `
const App = ({ children }) => (
Expand Down
1 change: 1 addition & 0 deletions packages/docz-theme-default/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare module 'react-feather/dist/icons/tablet'
declare module 'react-feather/dist/icons/monitor'
declare module 'react-feather/dist/icons/maximize'
declare module 'react-feather/dist/icons/minimize'
declare module 'react-feather/dist/icons/refresh-cw'
declare module 'react-lightweight-tooltip'
declare module 'react-powerplug'
declare module 're-resizable'
Expand Down

0 comments on commit ebefd91

Please sign in to comment.