Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
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]

### Fixes
- Fix `createComponent()` typings and documentation examples @Bugaa92 ([#954](https://github.com/stardust-ui/react/pull/954))

### Documentation
- Fix the sidebar missing items for docsite @alinais ([#971](https://github.com/stardust-ui/react/pull/971))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const centered: ICSSInJSStyle = {
textAlign: 'center',
}

const LabelledButton: React.SFC<LabelledButtonProps> = createComponent<LabelledButtonProps>({
const LabelledButton = createComponent<LabelledButtonProps>({
displayName: 'LabelledButton',
render: ({ stardust, ...props }) => {
const { iconName, label, active, onClick } = props
Expand Down
10 changes: 5 additions & 5 deletions docs/src/views/IntegrateCustomComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface StyledButtonProps {
children?: ReactChildren
}

const StyledButton: React.SFC<StyledButtonProps> = createComponent<StyledButtonProps>({
const StyledButton = createComponent<StyledButtonProps>({
displayName: 'StyledButton',
render({ stardust, children }) {
const { classes } = stardust
Expand All @@ -48,7 +48,7 @@ export default () => (

const StyledButton = createComponent({
displayName: 'StyledButton',
render: ({stardust, className, children}) => {
render: ({ stardust, children }) => {
const { classes } = stardust
return <button className={classes.root}>{children}</button>
}
Expand All @@ -75,7 +75,7 @@ export default () => (
},
componentStyles: {
StyledButton: {
root: ({ props, variables, theme: { siteVariables } }) => ({
root: ({ variables, theme: { siteVariables } }) => ({
backgroundColor: siteVariables.colors.primary[500],
color: variables.color,
}),
Expand Down Expand Up @@ -257,14 +257,14 @@ export default () => (
</p>
<ExampleSnippet
value={`
import { buttonBehavior } from '@stardust-ui/react'
import { createComponent, buttonBehavior } from '@stardust-ui/react'

const StyledButton = createComponent({
displayName: 'StyledButton',
defaultProps: {
accessibility: buttonBehavior
},
render: ({stardust, className, children}) => {
render: ({ stardust, children }) => {
const { classes, accessibility } = stardust
return <button {...accessibility.attributes.root} className={classes.root}>{children}</button>
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/lib/createComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import renderComponent, { RenderResultConfig } from './renderComponent'
import { AccessibilityActionHandlers } from './accessibility/types'
import { FocusZone } from './accessibility/FocusZone'
import { createShorthandFactory } from './factories'
import { ObjectOf } from '../types'

export interface CreateComponentConfig<P> {
displayName: string
Expand All @@ -22,7 +23,7 @@ export type CreateComponentReturnType<P> = React.FunctionComponent<P> & {
create: Function
}

const createComponent = <P extends {} = {}, S extends {} = {}>({
const createComponent = <P extends ObjectOf<any> = any>({
displayName = 'StardustComponent',
className = 'ui-stardust-component',
shorthandPropName = 'children',
Expand Down
8 changes: 5 additions & 3 deletions packages/react/src/lib/createStardustComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import createComponentInternal from './createComponent'
import * as React from 'react'
import * as _ from 'lodash'

import { ComponentSlotClasses, ComponentSlotStylesPrepared } from '../themes/types'
import { AccessibilityBehavior, AccessibilityActionHandlers } from './accessibility/types'
import { ObjectOf } from '../types'

export interface RenderStardustResultConfig {
accessibility: AccessibilityBehavior
Expand All @@ -18,13 +20,13 @@ export interface CreateStardustComponentConfig<P> {
actionHandlers?: AccessibilityActionHandlers
}

const createComponent = <P extends {} = {}, S extends {} = {}>({
const createComponent = <P extends ObjectOf<any> = any>({
displayName,
render,
defaultProps,
actionHandlers,
}: CreateStardustComponentConfig<P>): React.SFC<P> => {
return createComponentInternal<P, S>({
}: CreateStardustComponentConfig<P>): React.FC<P> => {
return createComponentInternal<P>({
displayName,
render: (config, props) => {
const filteredConfig = _.pick(config, ['accessibility', 'classes', 'rtl', 'styles'])
Expand Down