Skip to content

Commit

Permalink
feat(gatsby-theme-docz): add custom logo support
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 12, 2019
1 parent ecda697 commit dec4b2b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 25 deletions.
15 changes: 14 additions & 1 deletion core/gatsby-theme-docz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,20 @@ theme files just by creating your own file following a file naming convetion.
Example: If you're using our `gatsby-theme-docz` which has a `Header` component located at `src/components/Header/index.js`
you can override the component by creating `src/gatsby-theme-docz/components/Header/index.js`. Cool right?

So, now that you know about how component shadowing works on Gatsby themes, you can override anything inside the `gatsby-theme-docz`.
### Adding your logo

So, now that you know about how component shadowing works on Gatsby themes, if you don't want to override the entire `<Header>` component
but just change your logo inside it, your can shadow the `<Logo>` component used in the header just by creating your own at `src/gatsby-theme-docz/components/Logo/index.js`

```js
// src/gatsby-theme-docz/components/Logo/index.js
import React from 'react'
import logo from './logo.svg'

export const Logo = () => <img src={logo} alt="That's my logo" />
```

Easy, right?

### Creating your own Docz theme

Expand Down
13 changes: 5 additions & 8 deletions core/gatsby-theme-docz/src/components/Header/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/** @jsx jsx */
import { jsx, Box, Flex, useColorMode } from 'theme-ui'
import { Link, useConfig, useCurrentDoc } from 'docz'
import { useConfig, useCurrentDoc } from 'docz'
import styled from '@emotion/styled'

import { themeProp } from '~utils/theme'

import { Edit, Sun, Github } from '../Icons'
import * as styles from './styles'
import { Edit, Sun, Github } from '../Icons'
import { Logo } from '../Logo'

const Wrapper = styled(Box)`
border-bottom: 1px solid ${themeProp('colors.header.border')};
Expand All @@ -22,13 +23,9 @@ export const Header = () => {
}

return (
<Wrapper sx={styles.wrapper}>
<Wrapper sx={styles.wrapper(colorMode)}>
<div sx={styles.innerContainer}>
<Flex aligmItems="center">
<Link to="/" sx={styles.link}>
{config.title}
</Link>
</Flex>
<Logo />
<Flex>
{config.repository && (
<Box sx={{ mr: 2 }}>
Expand Down
20 changes: 7 additions & 13 deletions core/gatsby-theme-docz/src/components/Header/styles.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as mixins from '~utils/mixins'

export const wrapper = {
bg: 'header.bg',
}
export const wrapper = mode => ({
backgroundSize: '400px auto',
background:
mode === 'dark'
? `url(https://cdn-std.dprcdn.net/files/acc_649651/ykOjN7)`
: `url(https://cdn-std.dprcdn.net/files/acc_649651/zPkIFZ)`,
})

export const innerContainer = {
...mixins.centerAlign,
Expand All @@ -11,16 +15,6 @@ export const innerContainer = {
justifyContent: 'space-between',
}

export const link = {
fontSize: 3,
fontWeight: 600,
color: 'header.text',
textDecoration: 'none',
':hover': {
color: 'primary',
},
}

export const headerButton = {
...mixins.centerAlign,
outline: 'none',
Expand Down
1 change: 1 addition & 0 deletions core/gatsby-theme-docz/src/components/Logo/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('https://fonts.googleapis.com/css?family=Merriweather&display=swap');
16 changes: 16 additions & 0 deletions core/gatsby-theme-docz/src/components/Logo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @jsx jsx */
import { jsx, Flex } from 'theme-ui'
import { Link, useConfig } from 'docz'

import * as styles from './styles'

export const Logo = () => {
const config = useConfig()
return (
<Flex aligmItems="center" sx={styles.logo}>
<Link to="/" sx={styles.link}>
{config.title}
</Link>
</Flex>
)
}
15 changes: 15 additions & 0 deletions core/gatsby-theme-docz/src/components/Logo/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import './index.css'

export const logo = {
fontFamily: 'Merriweather',
fontSize: 3,
}

export const link = {
fontWeight: 600,
color: 'header.text',
textDecoration: 'none',
':hover': {
color: 'primary',
},
}
6 changes: 3 additions & 3 deletions core/gatsby-theme-docz/src/theme/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const light = {
text: colors.dark,
border: colors.grayLight,
button: {
bg: colors.grayLight,
color: colors.grayDark,
bg: colors.blue,
color: colors.white,
},
},
props: {
Expand Down Expand Up @@ -70,7 +70,7 @@ export const dark = {
text: colors.grayLight,
border: colors.grayDark,
button: {
bg: colors.grayDark,
bg: colors.skyBlue,
color: colors.white,
},
},
Expand Down

0 comments on commit dec4b2b

Please sign in to comment.