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 @@ -24,6 +24,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixes
- Make Chat.Messages position relative to contain absolutely positioned children @levithomason (7625becc55fc051175fa3143bdfbc212de2d436c)

### Features
- Add Button `fluid` prop @Bugaa92 ([#6](https://github.com/stardust-ui/react/pull/6))

<!--------------------------------[ v0.2.2 ]------------------------------- -->
## [v0.2.2](https://github.com/stardust-ui/react/tree/v0.2.2) (2018-07-24)
[Compare changes](https://github.com/stardust-ui/react/compare/v0.2.1...v0.2.2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Button } from '@stardust-ui/react'

const ButtonExampleFluid = () => <Button fluid content="Fits to Container" />

export default ButtonExampleFluid
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { Button } from '@stardust-ui/react'

const ButtonExampleFluid = () => <Button fluid>Fits to Container</Button>

export default ButtonExampleFluid
5 changes: 5 additions & 0 deletions docs/src/examples/components/Button/Variations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'

const Variations = () => (
<ExampleSection title="Variations">
<ComponentExample
title="Fluid"
description="A button can take the width of its container."
examplePath="components/Button/Variations/ButtonExampleFluid"
/>
<ComponentExample
title="Circular"
description="A button can be circular."
Expand Down
55 changes: 44 additions & 11 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
import PropTypes from 'prop-types'
import React from 'react'
import React, { ReactNode, CSSProperties } from 'react'

import { UIComponent, childrenExist, customPropTypes } from '../../lib'
import { UIComponent, childrenExist, customPropTypes, IRenderResultConfig } from '../../lib'
import buttonRules from './buttonRules'
import buttonVariables from './buttonVariables'

export type ButtonType = 'primary' | 'secondary'

export interface IButtonProps {
as?: string
children?: ReactNode
circular?: boolean
className?: string
content?: ReactNode
fluid?: boolean
style?: CSSProperties
type?: ButtonType
}

/**
* A button.
* @accessibility This is example usage of the accessibility tag.
* This should be replaced with the actual description after the PR is merged
*/
class Button extends UIComponent<any, any> {
static displayName = 'Button'
class Button extends UIComponent<IButtonProps, any> {
public static displayName = 'Button'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS uses public by default in classes. Let's keep the code concise.

Copy link
Collaborator Author

@bmdalex bmdalex Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levithomason - I'm aware, but I don't like that feature; I feel that with public by default developers are prone to exposing methods that should be private just because the habit of adding a modifier is not enforced; I don't mind reverting tho'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Want to make sure it is addressed properly as well. If you feel very strongly for this topic, please raise an RFC and let's have some good conversation around it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other benefit of explicitly deciding we want to declare public is that for an open source project it's going to be easier for contributors to pick up on what should or should not be public. Not sure if there is a tslint rule for this actually, which would be great.

I am still new to TS and I was not aware of the default public nature. Always declaring public/private is probably going to help new contributors.


static className = 'ui-button'
public static className = 'ui-button'

static rules = buttonRules
public static rules = buttonRules

static variables = buttonVariables
public static variables = buttonVariables

static propTypes = {
public static propTypes = {
/** An element type to render as (string or function). */
as: customPropTypes.as,

/** Primary content. */
children: PropTypes.node,

/** A button can appear circular. */
circular: PropTypes.bool,

Expand All @@ -32,23 +48,40 @@ class Button extends UIComponent<any, any> {
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,

/** A button can take the width of its container. */
fluid: PropTypes.bool,

/** A button can be formatted to show different levels of emphasis. */
type: PropTypes.oneOf(['primary', 'secondary']),
}

static handledProps = ['as', 'circular', 'className', 'content', 'type']
public static handledProps = [
'as',
'children',
'circular',
'className',
'content',
'fluid',
'type',
]

static defaultProps = {
public static defaultProps = {
as: 'button',
}

renderComponent({ ElementType, classes, rest }) {
public renderComponent({
ElementType,
classes,
rest,
}: IRenderResultConfig<IButtonProps>): ReactNode {
Copy link
Member

@levithomason levithomason Jul 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already be typed by extension of the UIComponent, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
doesn't look like it...

const { children, content } = this.props

return (
<ElementType {...rest} className={classes.root}>
{childrenExist(children) ? children : content}
</ElementType>
)
}
}

export default Button
15 changes: 11 additions & 4 deletions src/components/Button/buttonRules.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { pxToRem } from '../../lib'
import { IButtonVariables } from './buttonVariables'
import { IButtonProps } from './Button'

export default {
root: ({ props, theme, variables }) => {
root: ({ props, variables }: { props: IButtonProps; variables: IButtonVariables }) => {
const { children, circular, content, fluid, type } = props
const primary = type === 'primary'
const secondary = type === 'secondary'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


const {
backgroundColor,
backgroundColorHover,
Expand Down Expand Up @@ -31,9 +36,11 @@ export default {
':hover': {
backgroundColor: backgroundColorHover,
},
...(props.circular && { borderRadius: circularRadius, width: circularWidth }),
...(circular && { borderRadius: circularRadius, width: circularWidth }),

...(fluid && { display: 'block', width: '100%' }),

...(props.type === 'primary' && {
...(type === 'primary' && {
color: typePrimaryColor,
backgroundColor: typePrimaryBackgroundColor,
borderColor: typePrimaryBorderColor,
Expand All @@ -42,7 +49,7 @@ export default {
},
}),

...(props.type === 'secondary' && {
...(type === 'secondary' && {
color: typeSecondaryColor,
backgroundColor: typeSecondaryBackgroundColor,
borderColor: typeSecondaryBorderColor,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export * from './factories'
export { default as getClasses } from './getClasses'
export { default as getElementType } from './getElementType'
export { default as getUnhandledProps } from './getUnhandledProps'
export { default as renderComponent } from './renderComponent'
export { default as renderComponent, IRenderResultConfig } from './renderComponent'
export {
useKeyOnly,
useKeyOrValueAndKey,
Expand Down