Skip to content

Commit

Permalink
feat(docz-theme-default): add logo option
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed May 26, 2018
1 parent 0dcaefb commit 435da9b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
8 changes: 6 additions & 2 deletions packages/docz-core/src/DataServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export class DataServer {
}

private configData(config: Config): string {
return this.dataObj('docz.config', config.themeConfig)
return this.dataObj('docz.config', {
...config.themeConfig,
title: config.title,
description: config.description,
})
}

private updateEntries(
Expand All @@ -105,7 +109,7 @@ export class DataServer {
}

private updateConfig(socket: WS): () => void {
const config = load('docz', {}, true)
const config = load('docz', { ...this.config }, true)

return () => {
if (isSocketOpened(socket)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/docz-core/src/commands/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export const args = (yargs: any) => {
})
yargs.positional('title', {
type: 'string',
default: 'Docz',
default: 'MyDoc',
})
yargs.positional('description', {
type: 'string',
default: 'My awesome design system!',
default: 'My awesome app using Docz',
})
yargs.positional('theme', {
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { Docs, Link, Entry } from 'docz'
import { Docs, Link, Entry, ThemeConfig } from 'docz'
import styled from 'react-emotion'

import { Menu, isActive } from './Menu'
Expand Down Expand Up @@ -38,6 +38,28 @@ const Wrapper = styled('div')`
}
`

const LogoImg = styled('img')`
margin: 24px 16px 64px;
padding: 0;
`

const LogoText = styled('h1')`
position: relative;
margin: 24px 16px 64px;
padding: 0;
font-size: 32px;
&:before {
position: absolute;
content: '';
bottom: 0;
left: 0;
width: 15%;
height: 3px;
background: ${p => p.theme.colors.primary};
}
`

export const Sidebar = () => (
<Docs>
{({ docs, menus }) => {
Expand All @@ -46,6 +68,15 @@ export const Sidebar = () => (

return (
<Wrapper>
<ThemeConfig>
{({ title, logo }) =>
logo ? (
<LogoImg src={logo.src} width={logo.width} alt={title} />
) : (
<LogoText>{title}</LogoText>
)
}
</ThemeConfig>
{docsWithoutMenu.map(doc => (
<Link key={doc.id} to={doc.slug} isActive={isActive}>
{doc.name}
Expand Down
8 changes: 2 additions & 6 deletions packages/docz/src/components/ThemeConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ import { SFC, Children } from 'react'

import { dataContext, ThemeConfig as Config } from '../theme'

export interface ThemeConfigRenderProps {
config: Config
}

export interface ThemeConfigProps {
children?: (renderProps: ThemeConfigRenderProps) => React.ReactNode
children?: (config: Config) => React.ReactNode
}

export const ThemeConfig: SFC<ThemeConfigProps> = ({ children }) => {
if (typeof children !== 'function') return null

return (
<dataContext.Consumer>
{({ config }) => Children.only(children({ config }))}
{({ config }) => Children.only(children(config))}
</dataContext.Consumer>
)
}
2 changes: 1 addition & 1 deletion packages/docz/src/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function theme(
const value = {
entries,
imports,
config: merge(defaultConfig || {}, config),
config: merge(defaultConfig, config),
}

return (
Expand Down

0 comments on commit 435da9b

Please sign in to comment.