-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
254 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './theme'; | ||
export * from './style'; | ||
export * from './modal'; | ||
export * from './props'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
all, | ||
allWithRest, | ||
} from './props.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
export interface Props { | ||
[key: string]: any; | ||
} | ||
|
||
export interface RestProps { | ||
rest?: Partial<Props>; | ||
} | ||
|
||
export type AllOfProps = Partial<Props>; | ||
|
||
export type AllWithRestProps = Partial<Props> & RestProps; | ||
|
||
/** | ||
* Retrieves all props included in `from` array | ||
* | ||
* @param source (Props) - source object | ||
* @param from (string[]) - array of keys needed to retrieve from `source` | ||
* | ||
* @return (Partial<Props>) - object with keys contained in `from` array | ||
*/ | ||
export function all(source: Props | undefined, from: string[]): AllOfProps { | ||
if (!source) { | ||
return {}; | ||
} | ||
|
||
return from.reduce((acc: Partial<AllOfProps>, prop: string): Partial<AllOfProps> => { | ||
return { ...acc, [prop]: source[prop] }; | ||
}, {}); | ||
} | ||
|
||
/** | ||
* Retrieves all props included in `from` array, rest props includes in under the `rest` key | ||
*/ | ||
export function allWithRest(source: Props | undefined, from: string[]): AllWithRestProps { | ||
if (!source) { | ||
return { rest: {} }; | ||
} | ||
|
||
return Object.keys(source).reduce((acc: Partial<AllWithRestProps>, prop: string): Partial<AllWithRestProps> => { | ||
const { rest, ...allOf } = acc; | ||
|
||
if (from.includes(prop)) { | ||
return { ...allOf, [prop]: source[prop], rest }; | ||
} | ||
|
||
return { ...allOf, rest: { ...rest, [prop]: source[prop] } }; | ||
}, {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
all, | ||
AllOfProps, | ||
allWithRest, | ||
AllWithRestProps, | ||
Props, | ||
} from './props.service'; | ||
|
||
describe('@props: service checks', () => { | ||
|
||
const json = (value: any): string => JSON.stringify(value); | ||
|
||
const props: Props = { | ||
backgroundColor: 'black', | ||
color: 'white', | ||
fontSize: 32, | ||
}; | ||
|
||
const textProps: string[] = [ | ||
'color', | ||
'fontSize', | ||
]; | ||
|
||
describe('* all', () => { | ||
|
||
it('* non-null', () => { | ||
const retrievedProps: AllOfProps = all(props, textProps); | ||
|
||
expect(json(retrievedProps)).toEqual(json({ | ||
color: 'white', | ||
fontSize: 32, | ||
})); | ||
}); | ||
|
||
it('* nullable', () => { | ||
const retrievedProps: AllOfProps = all(undefined, textProps); | ||
|
||
expect(json(retrievedProps)).toEqual(json({})); | ||
}); | ||
|
||
}); | ||
|
||
describe('* allWithRest', () => { | ||
|
||
it('* non-null', () => { | ||
const retrievedProps: AllWithRestProps = allWithRest(props, textProps); | ||
|
||
const { rest, ...allOf } = retrievedProps; | ||
|
||
expect(json(allOf)).toEqual(json({ | ||
color: 'white', | ||
fontSize: 32, | ||
})); | ||
|
||
expect(json(rest)).toEqual(json({ | ||
backgroundColor: 'black', | ||
})); | ||
}); | ||
|
||
it('* nullable', () => { | ||
const retrievedProps: AllWithRestProps = allWithRest(undefined, textProps); | ||
|
||
expect(json(retrievedProps)).toEqual(json({ | ||
rest: {}, | ||
})); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export const TextStyleProps: string[] = [ | ||
|
||
// TextStyle | ||
|
||
'color', | ||
'fontFamily', | ||
'fontSize', | ||
'fontStyle', | ||
'fontWeight', | ||
'letterSpacing', | ||
'lineHeight', | ||
'textAlign', | ||
'textAlign', | ||
'textDecorationLine', | ||
'textDecorationStyle', | ||
'textDecorationColor', | ||
'textShadowColor', | ||
'textShadowColor', | ||
'textShadowOffset', | ||
'textShadowRadius', | ||
|
||
// TextStyleIOS | ||
|
||
'textTransform', | ||
'writingDirection', | ||
|
||
// TextStyleAndroid | ||
|
||
'textAlignVertical', | ||
'includeFontPadding', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.