Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit f637402

Browse files
authored
Merge pull request #933 from MichaelDevenish/patch/add-margin-support-to-select-input
Add margin support to select input.
2 parents d84599a + 0edace0 commit f637402

File tree

6 files changed

+263
-179
lines changed

6 files changed

+263
-179
lines changed

src/common/types/props.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ namespace Props {
115115
ScrollingTabGroup = 'scrolling_tab_group',
116116
Section = 'section',
117117
SectionList = 'section_list',
118+
SelectInput = 'select_input',
118119
SmartList = 'smart_list',
119120
SmartListColumn = 'smart_list_column',
120121
Statistic = 'statistic',

src/domain/Inputs/SelectInput/SelectInput.examples.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,32 @@ initialState = { options: backendOptions, isFetching: false, value: '' };
222222
onChange={value => setState({ value })}
223223
/>
224224
```
225+
226+
#### Select Input with margins
227+
228+
```jsx
229+
const { Variables } = require('@Common');
230+
231+
initialState = { value: '' };
232+
233+
<SelectInput
234+
placeholder='Select an option!'
235+
name='testInput'
236+
value={state.value}
237+
margins={{
238+
top: Variables.Spacing.sSmall,
239+
bottom: Variables.Spacing.s2XSmall
240+
}}
241+
options={[
242+
{
243+
label: 'Hello World',
244+
value: 20
245+
},
246+
{
247+
label: 'Try selecting me',
248+
value: 40
249+
}
250+
]}
251+
onChange={value => setState({ value })}
252+
/>
253+
```

src/domain/Inputs/SelectInput/SelectInput.tsx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import Select, {
1414
ReactSelectProps
1515
} from 'react-select'
1616

17+
import { Props } from '../../../common'
18+
import { TabGroupContainer } from '../../Tabs/ScrollingTabGroup/style'
19+
import { StyledSelectInputWrapper } from './style'
1720
import style from './style.scss'
1821

1922
export interface ISelectInputProps {
@@ -74,6 +77,11 @@ export interface ISelectInputProps {
7477
filterOptions?: FilterOptionsHandler
7578
/** Label for accessibility */
7679
'aria-label'?: string
80+
81+
/** The margins around the component */
82+
margins?: Props.IMargins
83+
/** The data-component-context */
84+
componentContext?: string
7785
}
7886

7987
export class SelectInput extends React.PureComponent<ISelectInputProps> {
@@ -98,23 +106,37 @@ export class SelectInput extends React.PureComponent<ISelectInputProps> {
98106

99107
public render (): JSX.Element {
100108
const {
101-
onNewOptionCreated
109+
onNewOptionCreated,
110+
margins,
111+
componentContext
102112
} = this.props
103113

104114
if (onNewOptionCreated) {
105115
return (
106-
<Creatable<OptionValues>
107-
{...this.reactSelectProps}
108-
onNewOptionClick={onNewOptionCreated}
109-
showNewOptionAtTop={false}
110-
/>
116+
<StyledSelectInputWrapper
117+
margins={margins}
118+
data-component-context={componentContext}
119+
data-component-type={Props.ComponentType.SelectInput}
120+
>
121+
<Creatable<OptionValues>
122+
{...this.reactSelectProps}
123+
onNewOptionClick={onNewOptionCreated}
124+
showNewOptionAtTop={false}
125+
/>
126+
</StyledSelectInputWrapper>
111127
)
112128
}
113129

114130
return (
115-
<Select<OptionValues>
116-
{...this.reactSelectProps}
117-
/>
131+
<StyledSelectInputWrapper
132+
margins={margins}
133+
data-component-context={componentContext}
134+
data-component-type={Props.ComponentType.SelectInput}
135+
>
136+
<Select<OptionValues>
137+
{...this.reactSelectProps}
138+
/>
139+
</StyledSelectInputWrapper>
118140
)
119141
}
120142

0 commit comments

Comments
 (0)