This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): add wrapper for the createComponent function (#503)
* -introduced createStardustComponent method * -renamed export * -addressed comments * -addressed comments * -exported types, refactored typings * -exported types from function file * -updated params for the render method inside the CreateStardustComponentConfig -updated changelog * -addressed comments: lodash , themes imports * -changed displayName to be required
- Loading branch information
Showing
4 changed files
with
38 additions
and
0 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
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,29 @@ | ||
import createComponentInternal from './createComponent' | ||
import * as React from 'react' | ||
import * as _ from 'lodash' | ||
import { ComponentSlotClasses } from '../themes/types' | ||
|
||
export interface RenderStardustResultConfig { | ||
classes: ComponentSlotClasses | ||
rtl: boolean | ||
} | ||
|
||
export interface CreateStardustComponentConfig<P> { | ||
displayName: string | ||
render: (props: P & { stardust: RenderStardustResultConfig }) => React.ReactNode | ||
} | ||
|
||
const createComponent = <P extends {} = {}, S extends {} = {}>({ | ||
displayName, | ||
render, | ||
}: CreateStardustComponentConfig<P>): React.SFC<P> => { | ||
return createComponentInternal<P, S>({ | ||
displayName, | ||
render: (config, props) => { | ||
const filteredConfig = _.pick(config, ['classes', 'rtl']) | ||
return render(Object.assign({ stardust: filteredConfig }, props)) | ||
}, | ||
}) | ||
} | ||
|
||
export default createComponent |
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