This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
feat(button): added fluid prop #6
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Button/Variations/ButtonExampleFluid.shorthand.tsx
This file contains hidden or 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,6 @@ | ||
| import React from 'react' | ||
| import { Button } from '@stardust-ui/react' | ||
|
|
||
| const ButtonExampleFluid = () => <Button fluid content="Fits to Container" /> | ||
|
|
||
| export default ButtonExampleFluid |
6 changes: 6 additions & 0 deletions
6
docs/src/examples/components/Button/Variations/ButtonExampleFluid.tsx
This file contains hidden or 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,6 @@ | ||
| import React from 'react' | ||
| import { Button } from '@stardust-ui/react' | ||
|
|
||
| const ButtonExampleFluid = () => <Button fluid>Fits to Container</Button> | ||
|
|
||
| export default ButtonExampleFluid |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -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' | ||
|
|
||
| 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, | ||
|
|
||
|
|
@@ -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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should already be typed by extension of the UIComponent, no?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const { children, content } = this.props | ||
|
|
||
| return ( | ||
| <ElementType {...rest} className={classes.root}> | ||
| {childrenExist(children) ? children : content} | ||
| </ElementType> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default Button | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -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' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| const { | ||
| backgroundColor, | ||
| backgroundColorHover, | ||
|
|
@@ -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, | ||
|
|
@@ -42,7 +49,7 @@ export default { | |
| }, | ||
| }), | ||
|
|
||
| ...(props.type === 'secondary' && { | ||
| ...(type === 'secondary' && { | ||
| color: typeSecondaryColor, | ||
| backgroundColor: typeSecondaryBackgroundColor, | ||
| borderColor: typeSecondaryBorderColor, | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 defaultdevelopers 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'There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.