Skip to content

Commit 344a0e7

Browse files
committed
WIP(theming): wIP: theming
1 parent ffd61b6 commit 344a0e7

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import getThemeProp from './getThemeProp'
2+
3+
test('should return default prop', () => {
4+
expect(getThemeProp('primaryColor', 'red', undefined)).toBe('red')
5+
expect(getThemeProp('primaryColor', 'red', {})).toBe('red')
6+
expect(getThemeProp('primaryColor', 'red', {reactDatepicker: {}})).toBe('red')
7+
})
8+
9+
test('should return theme prop', () => {
10+
expect(getThemeProp('primaryColor', 'red', {reactDatepicker: {primaryColor: 'blue'}})).toBe(
11+
'blue',
12+
)
13+
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function getThemeProp(themeProp: string, defaultValue: any, theme?: Record<string, any>) {
2+
if (
3+
theme &&
4+
typeof theme === 'object' &&
5+
theme.reactDatepicker &&
6+
typeof theme.reactDatepicker === 'object' &&
7+
theme.reactDatepicker[themeProp]
8+
) {
9+
return theme.reactDatepicker[themeProp]
10+
}
11+
12+
return defaultValue
13+
}
14+
15+
export default getThemeProp

0 commit comments

Comments
 (0)