Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Fixes

- Changing the default styles for Input component @alinais ([#25](https://github.com/stardust-ui/react/pull/25))

### Features
- Update styles for Menu underlined primary @miroslavstastny ([#20](https://github.com/stardust-ui/react/pull/20))

Expand All @@ -32,6 +36,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
[Compare changes](https://github.com/stardust-ui/react/compare/v0.2.3...v0.2.4)

### Fixes

- Replaced Header `subheader` with `description` and fixed it to render well-formed HTML @mnajdova ([#17](https://github.com/stardust-ui/react/pull/17))
- Removed allowSyntheticDefaultImports from shared tsconfig but allow it on docs @aniknafs ([#46](https://github.com/stardust-ui/react/pull/46))

Expand Down
33 changes: 30 additions & 3 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import inputRules from './inputRules'
import inputVariables from './inputVariables'
import Icon from '../Icon'
import callable from '../../lib/callable'

/**
* An Input
Expand Down Expand Up @@ -54,11 +55,20 @@ class Input extends UIComponent<any, any> {
type: 'text',
}

inputRef: any

computeTabIndex = props => {
if (!_.isNil(props.tabIndex)) return props.tabIndex
if (props.onClick) return 0
}

handleChildOverrides = (child, defaultProps) => ({
...defaultProps,
...child.props,
})

handleInputRef = c => (this.inputRef = c)

partitionProps = () => {
const { type } = this.props

Expand All @@ -69,6 +79,7 @@ class Input extends UIComponent<any, any> {
{
...htmlInputProps,
type,
onClick: () => this.inputRef.focus(),
},
rest,
]
Expand All @@ -81,11 +92,18 @@ class Input extends UIComponent<any, any> {
return null
}

handleIconOverrides = predefinedProps => {
return {
tabIndex: this.computeTabIndex,
}
}

renderComponent({ ElementType, classes, rest }) {
const { children, className, icon, input, type } = this.props
const [htmlInputProps, restProps] = this.partitionProps()

const inputClasses = cx(classes.input)
const iconClasses = cx(classes.icon)
Copy link
Contributor

@mnajdova mnajdova Aug 6, 2018

Choose a reason for hiding this comment

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

No need for using cx here, as the classes are already calculated and we are not combining multiple object to classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


// Render with children
// ----------------------------------------
Expand All @@ -108,9 +126,15 @@ class Input extends UIComponent<any, any> {
<ElementType {...rest} className={classes.root} {...htmlInputProps}>
{createHTMLInput(input || type, {
defaultProps: htmlInputProps,
Copy link
Contributor

Choose a reason for hiding this comment

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

We can extract the creation of the input in a separate variable and reuse it in the both return statements. I would actually refactor this with the following:

return (<ElementType {...rest} className={classes.root} {...htmlInputProps}>
          {createHTMLInput(input || type, {
            defaultProps: htmlInputProps,
            overrideProps: {
              className: inputClasses,
              ref: this.handleInputRef,
            },
          })}
          {this.computeIcon() && Icon.create(this.computeIcon(), {
            defaultProps: { className: iconClasses },
            overrideProps: predefinedProps => this.handleIconOverrides,
          })}
        </ElementType>)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

overrideProps: { className: inputClasses },
overrideProps: {
className: inputClasses,
ref: this.handleInputRef,
},
})}
{Icon.create(this.computeIcon(), {
defaultProps: { className: iconClasses },
overrideProps: predefinedProps => this.handleIconOverrides,
})}
<Icon name={this.computeIcon()} />
</ElementType>
)
}
Expand All @@ -119,7 +143,10 @@ class Input extends UIComponent<any, any> {
<ElementType {...rest} className={classes.root} {...htmlInputProps}>
{createHTMLInput(input || type, {
defaultProps: htmlInputProps,
overrideProps: { className: inputClasses },
overrideProps: {
className: inputClasses,
ref: this.handleInputRef,
},
})}
</ElementType>
)
Expand Down
22 changes: 19 additions & 3 deletions src/components/Input/inputRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@ const inputRules = {
position: 'relative',
alignItems: 'center',
justifyContent: 'flex-end',
border: variables.defaultBorder,
borderRadius: variables.borderRadius,
outline: 0,
padding: variables.defaultPadding,
}
},

input: ({ props, variables }) => {
return {
outline: 0,
border: 0,
borderRadius: variables.borderRadius,
borderBottom: variables.borderBottom,
color: variables.fontColor,
backgroundColor: variables.backgroundColor,
height: variables.height,
padding: variables.inputPadding,

':focus': {
borderColor: variables.inputFocusBorderColor,
borderRadius: variables.inputFocusBorderRadius,
},
}
},

icon: ({ props, variables }) => {
return {
position: variables.iconPosition,
right: variables.iconRight,
outline: 0,
}
},
}
Expand Down
18 changes: 13 additions & 5 deletions src/components/Input/inputVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ import { pxToRem } from '../../lib'
export default (siteVars: any) => {
const vars: any = {}

vars.borderRadius = `${pxToRem(3)} ${pxToRem(3)} ${pxToRem(2)} ${pxToRem(2)}`
vars.borderRadius = `${pxToRem(3)}`
vars.borderBottom = `${pxToRem(2)} solid transparent`
vars.height = '100%'
vars.backgroundColor = siteVars.gray10

vars.defaultBorder = `${pxToRem(1)} solid #222426`
vars.defaultBorderFocus = `${pxToRem(1)} solid #85b7d9`
vars.defaultBorderError = `${pxToRem(1)} solid #e0b4b4`
vars.defaultPadding = `${pxToRem(6)} 0 ${pxToRem(6)} ${pxToRem(10)}`
vars.fontColor = siteVars.fontBlack
vars.fontSize = siteVars.fontSizeBase

vars.inputPadding = `${pxToRem(6)} ${pxToRem(24)} ${pxToRem(6)} ${pxToRem(12)}`
vars.inputFocusBorderColor = siteVars.brand
vars.inputFocusBorderRadius = `${pxToRem(3)} ${pxToRem(3)} ${pxToRem(2)} ${pxToRem(2)}`

vars.iconPosition = 'absolute'
vars.iconRight = `${pxToRem(2)}`

return vars
}
1 change: 1 addition & 0 deletions src/themes/teams/siteVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const gray09 = '#EDEBE9'
export const gray10 = '#F3F2F1'
export const gray12 = blackRgbaFormat(0.05)
export const gray14 = '#FAF9F8'
export const fontBlack = '#252424'

export const white = '#FFF'

Expand Down