Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit aa514b3

Browse files
levithomasonmiroslavstastny
authored andcommitted
feat: export mergeThemes and add examples (#285)
1 parent 3e70307 commit aa514b3

File tree

8 files changed

+143
-1
lines changed

8 files changed

+143
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2323
### Fixes
2424
- Fix build on Windows @jurokapsiar ([#383](https://github.com/stardust-ui/react/pull/383))
2525

26+
### Features
27+
- Export `mergeThemes` @levithomason ([#285](https://github.com/stardust-ui/react/pull/285))
28+
29+
### Documentation
30+
- Add `Provider` examples @levithomason ([#285](https://github.com/stardust-ui/react/pull/285))
31+
2632
<!--------------------------------[ v0.10.0 ]------------------------------- -->
2733
## [v0.10.0](https://github.com/stardust-ui/react/tree/v0.10.0) (2018-10-19)
2834
[Compare changes](https://github.com/stardust-ui/react/compare/v0.9.1...v0.10.0)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import { Provider } from '@stardust-ui/react'
3+
4+
const theme = { siteVariables: { brand: 'cornflowerblue' } }
5+
6+
const ProviderExampleShorthand = () => (
7+
<Provider theme={theme}>
8+
<div>
9+
<p>
10+
Use the <code>Provider.Consumer</code> to access the <code>theme</code>:
11+
</p>
12+
13+
<Provider.Consumer
14+
render={theme => <code>theme.siteVariables.brand = {theme.siteVariables.brand}</code>}
15+
/>
16+
</div>
17+
</Provider>
18+
)
19+
20+
export default ProviderExampleShorthand
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react'
2+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
3+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
4+
5+
const Types = () => (
6+
<ExampleSection title="Types">
7+
<ComponentExample
8+
title="Theme"
9+
description="A Provider defines the theme for your components."
10+
examplePath="components/Provider/Types/ProviderExample"
11+
/>
12+
</ExampleSection>
13+
)
14+
15+
export default Types
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react'
2+
import Types from './Types'
3+
4+
const ProviderExamples = () => (
5+
<div>
6+
<Types />
7+
</div>
8+
)
9+
10+
export default ProviderExamples

src/components/Provider/Provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ProviderProps {
2121
}
2222

2323
/**
24-
* The Provider passes the CSS in JS renderer and theme down context.
24+
* The Provider passes the CSS in JS renderer and theme to your components.
2525
*/
2626
class Provider extends React.Component<ProviderProps, any> {
2727
static propTypes = {

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,8 @@ export {
118118
export {
119119
default as chatMessageEnterEscBehavior,
120120
} from './lib/accessibility/Behaviors/Chat/chatMessageEnterEscBehavior'
121+
122+
//
123+
// Utilities
124+
//
125+
export { default as mergeThemes } from './lib/mergeThemes'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Provider from 'src/components/Provider/Provider'
2+
import ProviderConsumer from 'src/components/Provider/ProviderConsumer'
3+
4+
describe('Provider', () => {
5+
test('is exported', () => {
6+
expect(require('src/index.ts').Provider).toEqual(Provider)
7+
})
8+
9+
test('has a ProviderConsumer subcomponent', () => {
10+
expect(require('src/index.ts').Provider.Consumer).toEqual(ProviderConsumer)
11+
})
12+
})
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import * as React from 'react'
2+
import { mount } from 'enzyme'
3+
4+
import Provider from 'src/components/Provider/Provider'
5+
import ProviderConsumer from 'src/components/Provider/ProviderConsumer'
6+
import { IThemeInput } from 'types/theme'
7+
8+
describe('ProviderConsumer', () => {
9+
test('is exported', () => {
10+
expect(require('src/index.ts').ProviderConsumer).toEqual(ProviderConsumer)
11+
})
12+
13+
test('is a subcomponent of the Provider', () => {
14+
expect(Provider.Consumer).toEqual(ProviderConsumer)
15+
})
16+
17+
describe('render', () => {
18+
test('is a callback that receives the prepared theme', () => {
19+
expect.assertions(13)
20+
21+
const inputTheme: IThemeInput = {
22+
siteVariables: { a: 'b' },
23+
componentVariables: { Button: { color: 'red' } },
24+
componentStyles: { Button: { root: { color: 'red' } } },
25+
fontFaces: [{ name: 'name', paths: ['path.woff2'], style: { fontWeight: 400 } }],
26+
staticStyles: ['body{margin:0;}', { body: { margin: 0 } }],
27+
icons: {
28+
user: { icon: { content: '\\f1', fontFamily: 'i' } },
29+
userFunc: { icon: () => ({ content: '\\f1', fontFamily: 'i' }) },
30+
userSvg: { isSvg: true, icon: <svg /> },
31+
userSvgFunc: { isSvg: true, icon: () => <svg /> },
32+
},
33+
}
34+
35+
mount(
36+
<Provider theme={inputTheme}>
37+
<Provider.Consumer
38+
render={preparedTheme => {
39+
// siteVariables
40+
expect(preparedTheme).toHaveProperty('siteVariables.a', 'b')
41+
42+
// componentVariables
43+
expect(preparedTheme).toHaveProperty('componentVariables.Button')
44+
expect(preparedTheme.componentVariables.Button).toBeInstanceOf(Function)
45+
expect(preparedTheme.componentVariables.Button()).toMatchObject(
46+
inputTheme.componentVariables.Button,
47+
)
48+
49+
// componentStyles
50+
expect(preparedTheme).toHaveProperty('componentStyles.Button.root')
51+
expect(preparedTheme.componentStyles.Button.root).toBeInstanceOf(Function)
52+
expect(preparedTheme.componentStyles.Button.root()).toMatchObject(
53+
inputTheme.componentStyles.Button.root,
54+
)
55+
56+
// fontFaces
57+
expect(preparedTheme).toHaveProperty('fontFaces')
58+
expect(preparedTheme.fontFaces).toMatchObject(inputTheme.fontFaces)
59+
60+
// staticStyles
61+
expect(preparedTheme).toHaveProperty('staticStyles')
62+
expect(preparedTheme.staticStyles).toMatchObject(inputTheme.staticStyles)
63+
64+
// icons
65+
expect(preparedTheme).toHaveProperty('icons')
66+
expect(preparedTheme.icons).toMatchObject(inputTheme.icons)
67+
return null
68+
}}
69+
/>
70+
</Provider>,
71+
)
72+
})
73+
})
74+
})

0 commit comments

Comments
 (0)