Skip to content

Commit b51caee

Browse files
committed
Document merge and tweak types
1 parent 9637bcd commit b51caee

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

packages/core/src/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import './react-jsx'
1313

1414
export * from './types'
1515

16-
const getCSS = props => {
16+
const getCSS = (props) => {
1717
if (!props.sx && !props.css) return undefined
18-
return theme => {
18+
return (theme) => {
1919
const styles = css(props.sx)(theme)
2020
const raw = typeof props.css === 'function' ? props.css(theme) : props.css
2121
return [styles, raw]
2222
}
2323
}
2424

25-
const parseProps = props => {
25+
const parseProps = (props) => {
2626
if (!props) return null
2727
const next: typeof props & { css?: InterpolationWithTheme<any> } = {}
2828
for (let key in props) {
@@ -55,7 +55,7 @@ const canUseSymbol = typeof Symbol === 'function' && Symbol.for
5555
const REACT_ELEMENT = canUseSymbol ? Symbol.for('react.element') : 0xeac7
5656
const FORWARD_REF = canUseSymbol ? Symbol.for('react.forward_ref') : 0xeac7
5757

58-
const isMergeableObject = n => {
58+
const isMergeableObject = (n) => {
5959
return (
6060
!!n &&
6161
typeof n === 'object' &&
@@ -66,10 +66,13 @@ const isMergeableObject = n => {
6666

6767
const arrayMerge = (destinationArray, sourceArray, options) => sourceArray
6868

69-
export const merge = <T>(a: Partial<T>, b: Partial<T>): T =>
69+
/**
70+
* Deeply merge themes
71+
*/
72+
export const merge = (a: Theme, b: Theme): Theme =>
7073
deepmerge(a, b, { isMergeableObject, arrayMerge })
7174

72-
merge.all = <T>(...args: Partial<T>[]) =>
75+
merge.all = <T = Theme>(...args: Partial<T>[]) =>
7376
deepmerge.all<T>(args, { isMergeableObject, arrayMerge })
7477

7578
interface BaseProviderProps {

packages/docs/src/pages/api.mdx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ It adds support for the `sx` prop, which uses Emotion's create element function
1919
/** @jsx jsx */
2020
import { jsx } from 'theme-ui'
2121

22-
export default props => (
22+
export default (props) => (
2323
<div
2424
{...props}
2525
sx={{
@@ -89,7 +89,9 @@ Note that this will increase the CSS specificity of child elements, and you may
8989

9090
```jsx
9191
<BaseStyles>
92-
<h1>Styled based on <code>theme.styles</code></h1>
92+
<h1>
93+
Styled based on <code>theme.styles</code>
94+
</h1>
9395
</BaseStyles>
9496
```
9597

@@ -121,7 +123,21 @@ An existential getter function used internally.
121123

122124
### `merge`
123125

124-
A deep object merge function used internally.
126+
A function to deeply merge themes.
127+
128+
**Usage**
129+
130+
```jsx
131+
import dark from '@theme-ui/preset-dark'
132+
133+
const theme = merge(dark, {
134+
fontWeights: {
135+
body: 500,
136+
heading: 700,
137+
bold: 900,
138+
},
139+
})
140+
```
125141

126142
### `InitializeColorMode`
127143

0 commit comments

Comments
 (0)