Skip to content

Commit 15e23cc

Browse files
author
Marcin Mazurek
authored
Merge pull request #196 from input-output-hk/fix/ddw-844-add-select-disabled-state
[DDW-844] Add select disabled state
2 parents d4bf79a + 60b7012 commit 15e23cc

File tree

8 files changed

+61
-8
lines changed

8 files changed

+61
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The history of all changes to react-polymorph.
44

55
# vNext
66

7+
- Add disabled state to Select component ([PR 196](https://github.com/input-output-hk/react-polymorph/pull/196))
8+
79
# 1.0.2
810

911
- Support data-\* attributes on input field component ([PR 2841](https://github.com/input-output-hk/daedalus/pull/2841))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-polymorph",
33
"description": "React components with highly customizable logic, markup and styles.",
4-
"version": "1.0.2",
4+
"version": "1.0.1-next.4",
55
"scripts": {
66
"build": "cross-env yarn clean && yarn sass && yarn js",
77
"build:watch": "concurrently 'yarn js:watch' 'yarn sass:watch'",

source/components/Select.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Props = {
1818
autoFocus: boolean,
1919
className?: string,
2020
context: ThemeContextProp,
21+
disabled?: boolean,
2122
error?: string | Element<any>,
2223
hasSearch?: boolean,
2324
hideSearchClearButton?: boolean,

source/skins/simple/InputSkin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const InputSkin = (props: Props) => {
2929
? props.theme[props.themeId].errored
3030
: null,
3131
])}
32+
disabled={props.disabled}
3233
/>
3334
);
3435

source/skins/simple/SelectSkin.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { Element, ElementRef } from 'react';
55
// external libraries
66
import classnames from 'classnames';
77

8-
98
// components
109
import { Options } from '../../components/Options';
1110
import { Input } from '../../components/Input';
@@ -16,6 +15,7 @@ import { InputSkin } from './InputSkin';
1615

1716
type Props = {
1817
className: string,
18+
disabled?: boolean,
1919
error: string | Element<any>,
2020
getSelectedOption: Function,
2121
handleChange: Function,
@@ -34,7 +34,7 @@ type Props = {
3434
onSearch?: Function,
3535
options: Array<{
3636
isDisabled: boolean,
37-
value: any
37+
value: any,
3838
}>,
3939
optionRenderer: Function,
4040
optionsRef: ElementRef<any>,
@@ -59,12 +59,13 @@ export const SelectSkin = (props: Props) => {
5959
return (
6060
<div
6161
ref={props.rootRef}
62-
className={classnames([
62+
className={classnames(
6363
props.className,
6464
theme[themeId].select,
65-
props.isOpen ? theme[themeId].isOpen : null,
66-
props.isOpeningUpward ? theme[themeId].openUpward : null
67-
])}
65+
props.isOpen && theme[themeId].isOpen,
66+
props.isOpeningUpward && theme[themeId].openUpward,
67+
props.disabled && theme[themeId].disabled
68+
)}
6869
>
6970
<div className={theme[themeId].selectInput}>
7071
<Input
@@ -78,6 +79,7 @@ export const SelectSkin = (props: Props) => {
7879
error={props.error}
7980
selectionRenderer={props.selectionRenderer}
8081
readOnly
82+
disabled={props.disabled}
8183
selectedOption={selectedOption}
8284
/>
8385
</div>

source/themes/simple/SimpleInput.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ $input-placeholder-font-family: var(--rp-input-placeholder-font-family, $theme-f
8282
// BEGIN CUSTOM VALUE RENDERER ---------- //
8383

8484
.customValueWrapper {
85+
input:not(.disabled) {
86+
background-color: transparent !important;
87+
}
88+
8589
input {
8690
color: transparent !important;
87-
background-color: transparent !important;
8891
position: absolute;
8992
z-index: 2;
9093
}

source/themes/simple/SimpleSelect.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55

66
// select-input
77
$select-input-bg-color: var(--rp-select-input-bg-color, #fafbfc) !default;
8+
$select-input-bg-color-disabled: var(--rp-select-input-bg-color-disabled, rgba(45, 45, 45, 0.05)) !default;
89
$select-input-border: var(--rp-select-input-border, 1px solid var(--rp-select-input-border-color, #c6cdd6)) !default;
910
$select-input-border-color-focus: var(--rp-select-input-border-color-focus, #5e6066) !default;
11+
$select-input-border-color-disabled: var(--rp-select-input-border-color-disabled, transparent) !default;
1012
$select-input-cursor: var(--rp-select-input-cursor, default) !default;
1113
$select-input-padding: var(--rp-select-input-padding, 14px 20px) !default;
1214
$select-input-placeholder-color: var(--rp-select-input-placeholder-color, rgba(#5e6066, 0.5)) !default;
1315
$select-input-placeholder-font-family: var(--rp-select-input-placeholder-font-family, $theme-font-light, sans-serif) !default;
1416
$select-input-text-color: var(--rp-select-input-text-color, #5e6066) !default;
17+
$select-input-text-color-disabled: var(--rp-select-input-text-color-disabled, rgba(45, 45, 45, 0.5)) !default;
1518

1619
// arrow default
1720
$select-arrow-bg-color: var(--rp-select-arrow-bg-color, #c6cdd6) !default;
21+
$select-arrow-bg-color-disabled: var(--rp-select-arrow-bg-color-disabled, #c6cdd6) !default;
1822
$select-arrow-bottom: var(--rp-select-arrow-bottom, 20px) !default;
1923
$select-arrow-height: var(--rp-select-arrow-height, 7px) !default;
2024
$select-arrow-left: var(--rp-select-arrow-left, calc(100% - 32px)) !default;
@@ -99,6 +103,20 @@ $select-arrow-url-open: var(--rp-select-arrow-url-open, url("#{$theme-assets-pat
99103
}
100104
}
101105
}
106+
107+
// ==== STATE: disabled ====
108+
.disabled {
109+
pointer-events: none;
110+
111+
.selectInput input {
112+
background-color: $select-input-bg-color-disabled;
113+
border-color: $select-input-border-color-disabled;
114+
}
115+
116+
.SimpleInput_customValueBlock {
117+
color: $select-input-text-color-disabled;
118+
}
119+
}
102120
// END SPECIAL STATES ---------- //
103121

104122
// right-to-left languages support

stories/Select.stories.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,32 @@ storiesOf('Select', module)
182182
))
183183
)
184184

185+
.add('disabled (without value)',
186+
withState({ value: '' }, store => (
187+
<Select
188+
disabled={true}
189+
onChange={value => store.set({ value })}
190+
label="Countries"
191+
options={COUNTRIES_WITH_DISABLED_OPTIONS}
192+
placeholder="Select your country …"
193+
hasSearch={boolean('hasSearch')}
194+
/>
195+
))
196+
)
197+
.add('disabled (with value)',
198+
withState({ value: '' }, store => (
199+
<Select
200+
disabled={true}
201+
onChange={value => store.set({ value })}
202+
value="EN-en"
203+
label="Countries"
204+
options={COUNTRIES_WITH_DISABLED_OPTIONS}
205+
placeholder="Select your country …"
206+
hasSearch={boolean('hasSearch')}
207+
/>
208+
))
209+
)
210+
185211
.add('with disabled options',
186212
withState({ value: '' }, store => (
187213
<Select

0 commit comments

Comments
 (0)