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

Commit 6d90064

Browse files
author
Alexandru Buliga
authored
fix(docs): createComponent typings and documentation (#954)
* fix(docs): createComponent typings and documentation * changelog * addressed comments * revert WeakValidationMap to ValidationMap
1 parent 45df254 commit 6d90064

5 files changed

Lines changed: 16 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1717

1818
## [Unreleased]
1919

20+
### Fixes
21+
- Fix `createComponent()` typings and documentation examples @Bugaa92 ([#954](https://github.com/stardust-ui/react/pull/954))
22+
2023
### Documentation
2124
- Fix the sidebar missing items for docsite @alinais ([#971](https://github.com/stardust-ui/react/pull/971))
2225

docs/src/components/ComponentDoc/ComponentControls/ComponentButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const centered: ICSSInJSStyle = {
1212
textAlign: 'center',
1313
}
1414

15-
const LabelledButton: React.SFC<LabelledButtonProps> = createComponent<LabelledButtonProps>({
15+
const LabelledButton = createComponent<LabelledButtonProps>({
1616
displayName: 'LabelledButton',
1717
render: ({ stardust, ...props }) => {
1818
const { iconName, label, active, onClick } = props

docs/src/views/IntegrateCustomComponents.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface StyledButtonProps {
2121
children?: ReactChildren
2222
}
2323

24-
const StyledButton: React.SFC<StyledButtonProps> = createComponent<StyledButtonProps>({
24+
const StyledButton = createComponent<StyledButtonProps>({
2525
displayName: 'StyledButton',
2626
render({ stardust, children }) {
2727
const { classes } = stardust
@@ -48,7 +48,7 @@ export default () => (
4848
4949
const StyledButton = createComponent({
5050
displayName: 'StyledButton',
51-
render: ({stardust, className, children}) => {
51+
render: ({ stardust, children }) => {
5252
const { classes } = stardust
5353
return <button className={classes.root}>{children}</button>
5454
}
@@ -75,7 +75,7 @@ export default () => (
7575
},
7676
componentStyles: {
7777
StyledButton: {
78-
root: ({ props, variables, theme: { siteVariables } }) => ({
78+
root: ({ variables, theme: { siteVariables } }) => ({
7979
backgroundColor: siteVariables.colors.primary[500],
8080
color: variables.color,
8181
}),
@@ -257,14 +257,14 @@ export default () => (
257257
</p>
258258
<ExampleSnippet
259259
value={`
260-
import { buttonBehavior } from '@stardust-ui/react'
260+
import { createComponent, buttonBehavior } from '@stardust-ui/react'
261261
262262
const StyledButton = createComponent({
263263
displayName: 'StyledButton',
264264
defaultProps: {
265265
accessibility: buttonBehavior
266266
},
267-
render: ({stardust, className, children}) => {
267+
render: ({ stardust, children }) => {
268268
const { classes, accessibility } = stardust
269269
return <button {...accessibility.attributes.root} className={classes.root}>{children}</button>
270270
}

packages/react/src/lib/createComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import renderComponent, { RenderResultConfig } from './renderComponent'
55
import { AccessibilityActionHandlers } from './accessibility/types'
66
import { FocusZone } from './accessibility/FocusZone'
77
import { createShorthandFactory } from './factories'
8+
import { ObjectOf } from '../types'
89

910
export interface CreateComponentConfig<P> {
1011
displayName: string
@@ -22,7 +23,7 @@ export type CreateComponentReturnType<P> = React.FunctionComponent<P> & {
2223
create: Function
2324
}
2425

25-
const createComponent = <P extends {} = {}, S extends {} = {}>({
26+
const createComponent = <P extends ObjectOf<any> = any>({
2627
displayName = 'StardustComponent',
2728
className = 'ui-stardust-component',
2829
shorthandPropName = 'children',

packages/react/src/lib/createStardustComponent.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import createComponentInternal from './createComponent'
22
import * as React from 'react'
33
import * as _ from 'lodash'
4+
45
import { ComponentSlotClasses, ComponentSlotStylesPrepared } from '../themes/types'
56
import { AccessibilityBehavior, AccessibilityActionHandlers } from './accessibility/types'
7+
import { ObjectOf } from '../types'
68

79
export interface RenderStardustResultConfig {
810
accessibility: AccessibilityBehavior
@@ -18,13 +20,13 @@ export interface CreateStardustComponentConfig<P> {
1820
actionHandlers?: AccessibilityActionHandlers
1921
}
2022

21-
const createComponent = <P extends {} = {}, S extends {} = {}>({
23+
const createComponent = <P extends ObjectOf<any> = any>({
2224
displayName,
2325
render,
2426
defaultProps,
2527
actionHandlers,
26-
}: CreateStardustComponentConfig<P>): React.SFC<P> => {
27-
return createComponentInternal<P, S>({
28+
}: CreateStardustComponentConfig<P>): React.FC<P> => {
29+
return createComponentInternal<P>({
2830
displayName,
2931
render: (config, props) => {
3032
const filteredConfig = _.pick(config, ['accessibility', 'classes', 'rtl', 'styles'])

0 commit comments

Comments
 (0)