Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Set the ref of the `FocusZone` in `Embed` mode @sophieH29 ([#435](https://github.com/stardust-ui/react/pull/435))
- Close `Popup` on outside click @kuzhelov ([#410](https://github.com/stardust-ui/react/pull/410))
- Set default `chatBehavior` which uses Enter/Esc keys @sophieH29 ([#443](https://github.com/stardust-ui/react/pull/443))
- Add `iconPosition` property to `Input` component @mnajdova ([#442](https://github.com/stardust-ui/react/pull/442))

### Documentation
- Add all missing component descriptions and improve those existing @levithomason ([#400](https://github.com/stardust-ui/react/pull/400))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Input } from '@stardust-ui/react'

const InputExampleIconPosition = () => (
<Input icon="search" placeholder="Search..." iconPosition="start" />
)

export default InputExampleIconPosition
5 changes: 5 additions & 0 deletions docs/src/examples/components/Input/Variations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const Variations = () => (
description="An input can have an icon."
examplePath="components/Input/Variations/InputExampleIcon"
/>
<ComponentExample
title="Icon position"
description="The icon inside the input can be positioned at the start of the input."
examplePath="components/Input/Variations/InputExampleIconPosition"
/>
<ComponentExample
title="Fluid"
description="An input can take the full width of the parent element."
Expand Down
5 changes: 5 additions & 0 deletions src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface InputProps {
defaultValue?: React.ReactText
fluid?: boolean
icon?: ShorthandValue
iconPosition?: 'start' | 'end'
inline?: boolean
input?: ShorthandValue
onChange?: ComponentEventHandler<InputProps>
Expand Down Expand Up @@ -87,6 +88,9 @@ class Input extends AutoControlledComponent<Extendable<InputProps>, InputState>
/** Optional Icon to display inside the Input. */
icon: customPropTypes.itemShorthand,

/** An Input with icon can format the icon to appear at the start or at the end of the input field. */
iconPosition: PropTypes.oneOf(['start', 'end']),

/** Shorthand for the input component. */
input: customPropTypes.itemShorthand,

Expand Down Expand Up @@ -155,6 +159,7 @@ class Input extends AutoControlledComponent<Extendable<InputProps>, InputState>
as: 'div',
type: 'text',
wrapper: 'div',
iconPosition: 'end',
}

static autoControlledProps = ['value']
Expand Down
14 changes: 12 additions & 2 deletions src/themes/teams/components/Input/inputStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,22 @@ const inputStyles: ComponentSlotStylesInput<InputProps, InputVariables> = {
borderBottomColor: v.inputFocusBorderBottomColor,
boxShadow: v.boxShadow,
},
...(p.clearable && { padding: v.inputPaddingWithIconAtEnd }),
...(p.icon && {
padding:
p.iconPosition === 'start' ? v.inputPaddingWithIconAtStart : v.inputPaddingWithIconAtEnd,
}),
}),

icon: ({ variables: v }): ICSSInJSStyle => ({
icon: ({ props: { iconPosition }, variables: v }): ICSSInJSStyle => ({
position: v.iconPosition as PositionProperty,
color: v.iconColor,
right: v.iconRight,
...(iconPosition === 'start' && {
left: v.iconLeft,
}),
...(iconPosition === 'end' && {
right: v.iconRight,
}),
outline: 0,
}),
}
Expand Down
9 changes: 8 additions & 1 deletion src/themes/teams/components/Input/inputVariables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pxToRem } from '../../../../lib'

export interface InputVariables {
backgroundColor: string
border: string
Expand All @@ -9,6 +10,9 @@ export interface InputVariables {
iconColor: string
iconPosition: string
iconRight: string
iconLeft: string
inputPaddingWithIconAtStart: string
inputPaddingWithIconAtEnd: string
inputPadding: string
inputFocusBorderBottomColor: string
inputFocusBorderRadius: string
Expand All @@ -26,8 +30,11 @@ export default (siteVars): InputVariables => ({
iconPosition: 'absolute',
iconRight: pxToRem(2),
iconColor: siteVars.bodyColor,
iconLeft: pxToRem(6),
inputPaddingWithIconAtStart: `${pxToRem(6)} ${pxToRem(12)} ${pxToRem(6)} ${pxToRem(24)}`,
inputPaddingWithIconAtEnd: `${pxToRem(6)} ${pxToRem(24)} ${pxToRem(6)} ${pxToRem(12)}`,

inputPadding: `${pxToRem(6)} ${pxToRem(24)} ${pxToRem(6)} ${pxToRem(12)}`,
inputPadding: `${pxToRem(6)} ${pxToRem(12)} ${pxToRem(6)} ${pxToRem(12)}`,
inputFocusBorderBottomColor: siteVars.brand,
inputFocusBorderRadius: `${pxToRem(3)} ${pxToRem(3)} ${pxToRem(2)} ${pxToRem(2)}`,
})