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

Commit 816037f

Browse files
authored
fix(theming): make params in styles functions required (#2235)
* -moved changes from useStyles hook * -updated changelog -fixed ProviderConsumer test
1 parent 02c7b2d commit 816037f

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2222

2323
### Fixes
2424
- Fix event lister leak in `FocusZone` @miroslavstastny ([#2227](https://github.com/microsoft/fluent-ui-react/pull/2227))
25+
- Fix styleParam to always be required in the styles functions @layershifter, @mnajdova ([#2235](https://github.com/microsoft/fluent-ui-react/pull/2235))
2526

2627
<!--------------------------------[ v0.43.0 ]------------------------------- -->
2728
## [v0.43.0](https://github.com/microsoft/fluent-ui-react/tree/v0.43.0) (2020-01-08)

packages/react/test/specs/components/Provider/ProviderConsumer-test.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import { ThemeInput } from '@fluentui/styles'
1+
import { ComponentStyleFunctionParam, emptyTheme, ThemeInput } from '@fluentui/styles'
22
import * as React from 'react'
33
import { mount } from 'enzyme'
44

55
import Provider from 'src/components/Provider/Provider'
66
import ProviderConsumer from 'src/components/Provider/ProviderConsumer'
77

8+
const styleParam: ComponentStyleFunctionParam = {
9+
disableAnimations: false,
10+
displayName: 'Test',
11+
props: {},
12+
rtl: false,
13+
theme: emptyTheme,
14+
variables: {},
15+
}
16+
817
describe('ProviderConsumer', () => {
918
test('is exported', () => {
1019
expect(require('src/index.ts').ProviderConsumer).toEqual(ProviderConsumer)
@@ -49,7 +58,7 @@ describe('ProviderConsumer', () => {
4958
// componentStyles
5059
expect(preparedTheme).toHaveProperty('componentStyles.Button.root')
5160
expect(preparedTheme.componentStyles.Button.root).toBeInstanceOf(Function)
52-
expect(preparedTheme.componentStyles.Button.root()).toMatchObject(
61+
expect(preparedTheme.componentStyles.Button.root(styleParam)).toMatchObject(
5362
inputTheme.componentStyles.Button.root,
5463
)
5564

packages/styles/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export interface ComponentStyleFunctionParam<
201201
}
202202

203203
export type ComponentSlotStyleFunction<TProps = {}, TVars = {}> = (
204-
styleParam?: ComponentStyleFunctionParam<TProps, TVars>,
204+
styleParam: ComponentStyleFunctionParam<TProps, TVars>,
205205
) => ICSSInJSStyle
206206

207207
export interface ComponentSlotStylesPrepared<TProps = {}, TVars = {}>

packages/styles/test/mergeThemes/mergeComponentStyles-test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
import { ComponentStyleFunctionParam, withDebugId } from '@fluentui/styles'
1+
import { ComponentStyleFunctionParam, emptyTheme, withDebugId } from '@fluentui/styles'
22

33
import * as debugEnabled from '../../src/debugEnabled'
44
import { mergeComponentStyles__PROD, mergeComponentStyles__DEV } from '../../src/mergeThemes'
55

6+
const styleParam: ComponentStyleFunctionParam = {
7+
disableAnimations: false,
8+
displayName: 'Test',
9+
props: {},
10+
rtl: false,
11+
theme: emptyTheme,
12+
variables: {},
13+
}
14+
615
describe('mergeComponentStyles', () => {
716
let originalDebugEnabled
817

@@ -154,7 +163,7 @@ describe('mergeComponentStyles', () => {
154163

155164
const merged = mergeComponentStyles__PROD(target, source)
156165

157-
const resolvedRoot = merged.root()
166+
const resolvedRoot = merged.root(styleParam)
158167
expect(resolvedRoot._debug).toBe(undefined)
159168
})
160169
})
@@ -172,7 +181,7 @@ describe('mergeComponentStyles', () => {
172181

173182
const merged = mergeComponentStyles__DEV(target, source)
174183

175-
const resolvedRoot = merged.root()
184+
const resolvedRoot = merged.root(styleParam)
176185
expect(resolvedRoot._debug).toBe(undefined)
177186
})
178187
})
@@ -199,7 +208,7 @@ describe('mergeComponentStyles', () => {
199208
_debug: [{ styles: { a: 'tA', b: 'tB' } }, { styles: { a: 'sA', c: { deep: 'vC' } } }],
200209
})
201210

202-
const resolvedIcon = merged.icon()
211+
const resolvedIcon = merged.icon(styleParam)
203212
expect(resolvedIcon).toMatchObject({
204213
_debug: [{ styles: { d: 'sD' } }],
205214
})
@@ -210,7 +219,7 @@ describe('mergeComponentStyles', () => {
210219
const source = withDebugId({ root: { a: 'sA', c: { deep: 'c' } } }, 'source')
211220

212221
const merged = mergeComponentStyles__DEV(target, source)
213-
const resolvedRoot = merged.root()
222+
const resolvedRoot = merged.root(styleParam)
214223
expect(resolvedRoot).toMatchObject({
215224
_debug: [{ debugId: 'target' }, { debugId: 'source' }],
216225
})
@@ -243,7 +252,7 @@ describe('mergeComponentStyles', () => {
243252
)
244253

245254
const merged1 = mergeComponentStyles__DEV(target, source1, source2)
246-
const resolvedRoot1 = merged1.root()
255+
const resolvedRoot1 = merged1.root(styleParam)
247256
expect(resolvedRoot1).toMatchObject({
248257
_debug: [{ debugId: 'target' }, { debugId: 'source1' }, { debugId: 'source2' }],
249258
})
@@ -252,7 +261,7 @@ describe('mergeComponentStyles', () => {
252261
mergeComponentStyles__DEV(target, source1),
253262
source2,
254263
)
255-
const resolvedRoot2 = merged2.root()
264+
const resolvedRoot2 = merged2.root(styleParam)
256265
expect(resolvedRoot2).toMatchObject({
257266
_debug: [{ debugId: 'target' }, { debugId: 'source1' }, { debugId: 'source2' }],
258267
})
@@ -261,7 +270,7 @@ describe('mergeComponentStyles', () => {
261270
target,
262271
mergeComponentStyles__DEV(source1, source2),
263272
)
264-
const resolvedRoot3 = merged3.root()
273+
const resolvedRoot3 = merged3.root(styleParam)
265274
expect(resolvedRoot3).toMatchObject({
266275
_debug: [{ debugId: 'target' }, { debugId: 'source1' }, { debugId: 'source2' }],
267276
})

packages/styles/test/mergeThemes/mergeThemes-test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ import {
55
mergeStyles,
66
ThemeInput,
77
withDebugId,
8+
emptyTheme,
89
} from '@fluentui/styles'
910

1011
import * as debugEnabled from '../../src/debugEnabled'
1112

13+
const styleParam: ComponentStyleFunctionParam = {
14+
disableAnimations: false,
15+
displayName: 'Test',
16+
props: {},
17+
rtl: false,
18+
theme: emptyTheme,
19+
variables: {},
20+
}
21+
1222
describe('mergeThemes', () => {
1323
test(`always returns an object`, () => {
1424
expect(mergeThemes({}, {})).toMatchObject({})
@@ -244,7 +254,7 @@ describe('mergeThemes', () => {
244254

245255
const merged = mergeThemes(target, source)
246256

247-
expect(merged.componentStyles.Button.root()).toMatchObject({
257+
expect(merged.componentStyles.Button.root(styleParam)).toMatchObject({
248258
display: 'inline-block',
249259
color: 'blue',
250260
'::before': {

0 commit comments

Comments
 (0)