mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-29 05:46:00 +03:00
Add useTheme hook
This commit is contained in:
parent
48c734ffbf
commit
79ce0e82c5
16
docs/api.md
16
docs/api.md
@ -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
|
[provider component]: advanced.md#custom-provider-component
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
import { ThemeContext } from '@emotion/core'
|
|
||||||
import styled from '@emotion/styled'
|
import styled from '@emotion/styled'
|
||||||
import FluidFontSize from './FluidFontSize'
|
import FluidFontSize from './FluidFontSize'
|
||||||
|
import useTheme from './useTheme'
|
||||||
|
|
||||||
const getPadding = ratio =>
|
const getPadding = ratio =>
|
||||||
ratio > 1 ? (1 / ratio) * 100 + '%' : ratio * 100 + '%'
|
ratio > 1 ? (1 / ratio) * 100 + '%' : ratio * 100 + '%'
|
||||||
@ -36,7 +36,7 @@ const Inner = styled.div(
|
|||||||
)
|
)
|
||||||
|
|
||||||
export default props => {
|
export default props => {
|
||||||
const theme = useContext(ThemeContext)
|
const theme = useTheme()
|
||||||
if (!theme.aspectRatio) {
|
if (!theme.aspectRatio) {
|
||||||
return <>{props.children}</>
|
return <>{props.children}</>
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ export { Steps } from './Steps'
|
|||||||
export { Appear } from './Appear'
|
export { Appear } from './Appear'
|
||||||
export { withContext, useDeck } from './context'
|
export { withContext, useDeck } from './context'
|
||||||
export { default as useSteps } from './useSteps'
|
export { default as useSteps } from './useSteps'
|
||||||
|
export { default as useTheme } from './useTheme'
|
||||||
|
|
||||||
export { Slide } from './Slide'
|
export { Slide } from './Slide'
|
||||||
export { Zoom } from './Zoom'
|
export { Zoom } from './Zoom'
|
||||||
|
4
packages/components/src/useTheme.js
Normal file
4
packages/components/src/useTheme.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { useContext } from 'react'
|
||||||
|
import { ThemeContext } from '@emotion/core'
|
||||||
|
|
||||||
|
export default () => useContext(ThemeContext)
|
Loading…
Reference in New Issue
Block a user