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

Add useTheme hook

This commit is contained in:
Rodrigo Pombo 2019-05-14 17:51:11 +02:00
parent 48c734ffbf
commit 79ce0e82c5
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

@ -6,6 +6,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)