1
1
mirror of https://github.com/jxnblk/mdx-deck.git synced 2024-11-25 15:50:39 +03:00

Merge pull request #359 from pomber/use-theme

Add useTheme hook
This commit is contained in:
Brent Jackson 2019-06-19 14:19:47 -04:00 committed by GitHub
commit e7d73f1374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 2 deletions

View File

@ -101,4 +101,20 @@ export default props => {
}
```
## `useTheme` Hook
The `useTheme` hook returns the current [theme](theming.md).
```jsx
// example
import React from 'react'
import { useTheme } from '@mdx-deck/components'
export default props => {
const theme = useTheme()
return <h2 style={{ border: `1px solid ${theme.colors.text}` }}>Hello</h2>
}
```
[provider component]: advanced.md#custom-provider-component

View File

@ -1,7 +1,7 @@
import React, { useContext } from 'react'
import { ThemeContext } from '@emotion/core'
import styled from '@emotion/styled'
import FluidFontSize from './FluidFontSize'
import useTheme from './useTheme'
const getPadding = ratio =>
ratio > 1 ? (1 / ratio) * 100 + '%' : ratio * 100 + '%'
@ -36,7 +36,7 @@ const Inner = styled.div(
)
export default props => {
const theme = useContext(ThemeContext)
const theme = useTheme()
if (!theme.aspectRatio) {
return <>{props.children}</>
}

View File

@ -7,6 +7,7 @@ export { Steps } from './Steps'
export { Appear } from './Appear'
export { withContext, useDeck } from './context'
export { default as useSteps } from './useSteps'
export { default as useTheme } from './useTheme'
export { Slide } from './Slide'
export { Zoom } from './Zoom'

View File

@ -0,0 +1,4 @@
import { useContext } from 'react'
import { ThemeContext } from '@emotion/core'
export default () => useContext(ThemeContext)