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

feat(utils): add wrapper for the createComponent function #503

Merged
merged 10 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Features
- Add `renderComponent` function in the public API @mnajdova ([#503](https://github.com/stardust-ui/react/pull/503))

### Fixes
- Fix the behaviour of `AutoControlledComponent` when `undefined` is passed as a prop value @layershifter ([#499](https://github.com/stardust-ui/react/pull/499))

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,8 @@ export { default as dialogBehavior } from './lib/accessibility/Behaviors/Dialog/
// Utilities
//
export { default as mergeThemes } from './lib/mergeThemes'
export { createComponent } from './lib'
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
export {
RenderStardustResultConfig,
CreateStardustComponentConfig,
} from './lib/createStardustComponent'
29 changes: 29 additions & 0 deletions src/lib/createStardustComponent.tsx
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 {
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
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,
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
render: (config, props) => {
const filteredConfig = _.pick(config, ['classes', 'rtl'])
return render(Object.assign({ stardust: filteredConfig }, props))
mnajdova marked this conversation as resolved.
Show resolved Hide resolved
},
})
}

export default createComponent
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ export { default as leven } from './leven'
export { pxToRem, setHTMLFontSize } from './fontSizeUtility'
export { customPropTypes }
export { default as createAnimationStyles } from './createAnimationStyles'
export { default as createComponent } from './createStardustComponent'