Skip to content

Commit 89327aa

Browse files
authored
Merge pull request #1 from darianstlex/v1
Refactoring, tests, documentation, v1
2 parents 3fff228 + 6e56f18 commit 89327aa

60 files changed

Lines changed: 3210 additions & 1142 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ scripts
66
.gitignore
77
.idea
88
webpack.config.js
9+
jest.config.js
10+
*.test.js
11+
__snapshots__

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
> Single/Multi Select React Component
22
3-
Inspired by [React MultiSelect](https://github.com/Khan/react-multi-select)
4-
53
[Demo and Specimens](https://darianstlex.github.io/react-sm-select) Catalog
64

75
### Installation
86

9-
Install the react-sm-select npm package:
10-
117
```code
128
npm install react-sm-select
139
```
@@ -47,10 +43,12 @@ Can be used css overriding, see compiled css. Or use scss variables for general
4743
4844
$SM-white: #fff;
4945
$SM-brightGrey: #ebf5ff;
46+
$SM-smoothGray: #f3f3f3;
5047
$SM-lightGrey: #cfd4d9;
5148
$SM-lightBlue: #1298d4;
5249
$SM-grey: #949ca6;
5350
$SM-darkBlue: #143154;
51+
$SM-shadowBlue: rgba(18,152,212,0.5);
5452
5553
// General Colors
5654
$SM-backgroundColor: $SM-white;
@@ -60,6 +58,7 @@ $SM-borderColor: $SM-grey;
6058
$SM-textColor: $SM-darkBlue;
6159
6260
// Value Colors
61+
$SM-headerSelectedColor: $SM-shadowBlue;
6362
$SM-valueColor: $SM-textColor;
6463
$SM-valuePlaceholderColor: $SM-mutedColor;
6564
@@ -71,15 +70,18 @@ $SM-tagCloseColor: $SM-textColor;
7170
$SM-tagCloseBackgroundColor: $SM-lightGrey;
7271
7372
// DropDown
74-
$SM-dropDownArrowColor: $SM-grey;
73+
$SM-dropDownArrowColor: $SM-mutedColor;
7574
$SM-dropDownActiveArrowColor: $SM-lightBlue;
7675
7776
// Search Colors
77+
$SM-searchTextColor: $SM-textColor;
7878
$SM-searchPlaceholderColor: $SM-mutedColor;
79+
$SM-searchSelectedColor: $SM-shadowBlue;
7980
8081
// Option Colors
8182
$SM-itemTextColor: $SM-textColor;
8283
$SM-itemBackgroundHoverColor: $SM-brightGrey;
84+
$SM-itemBackgroundFocusColor: $SM-smoothGray;
8385
$SM-dividerColor: $SM-lightGrey;
8486
$SM-selectAllColor: $SM-itemTextColor;
8587
@@ -212,47 +214,47 @@ filterOptions(options, text) {
212214

213215
---
214216

215-
- **`ArrowRenderer: function`** DropDown Arrow:
217+
- **`Arrow: function`** DropDown Arrow:
216218

217219
```code
218-
ArrowRenderer({options, value, expanded, hasFocus}) {
220+
Arrow({options, value, expanded, hasFocus, disabled}) {
219221
// options: array - see 'options' prop
220222
// value: array - see 'value' property
221223
// expanded: boolean - expanded component status
222224
// hasFocus: boolean - hasFocus component status
225+
// disabled: boolean - disabled component status
223226
224227
return - component to render custom Arrow
225228
}
226229
```
227230

228231

229-
- **`LoadingRenderer: function`** Loading Indicator:
232+
- **`Loading: function`** Loading Indicator:
230233

231234
```code
232-
LoadingRenderer() {
235+
Loading() {
233236
return - component to render custom Loading Indicator
234237
}
235238
```
236239

237240

238-
- **`OptionRenderer: function`** Option:
241+
- **`Option: function`** Option:
239242

240243
```code
241-
OptionRenderer({option, checked, disabled, onClick}) {
244+
Option({checked, option, isSingle}) {
242245
// option: object - from options props: { value, label }
243246
// checked: boolean - define if option is checked
244-
// disabled: boolean - disable option if component is disabled
245-
// onClick: function - notifies component about option click
247+
// isSingle: boolean - single selection mode
246248
247249
return - component to render custom Option
248250
}
249251
```
250252

251253

252-
- **`TagRenderer: function`** Tag:
254+
- **`Tag: function`** Tag:
253255

254256
```code
255-
TagRenderer({label, index, removableTag, onTagRemove}) {
257+
Tag({label, index, removableTag, onTagRemove}) {
256258
// label: string - tag label
257259
// index: number - tag index in array used in removal
258260
// removableTag: boolean - display/hide remove tag button
@@ -261,10 +263,10 @@ TagRenderer({label, index, removableTag, onTagRemove}) {
261263
```
262264

263265

264-
- **`ValueRenderer: function`** Value:
266+
- **`Value: function`** Value:
265267

266268
```code
267-
ValueRenderer({value, options}) {
269+
Value({value, options}) {
268270
// options: array - see 'options' property
269271
// value: array - see 'value' property
270272

catalog/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Catalog, pageLoader, ReactSpecimen} from 'catalog';
44
import {Controller} from './playground/controller';
55
import logo from "./static/r-logo.svg";
66
import {MultiSelect} from '../src';
7-
import {MultiselectWrapper} from './playground/multiselect-wrapper';
7+
import {MultiSelectWrapper} from './playground/multiselect-wrapper';
88
import 'bulma/css/bulma.min.css';
99
import 'bulma-switch/dist/css/bulma-switch.min.css';
1010
import './catalog.css';
@@ -89,7 +89,7 @@ const pages = [
8989
]
9090
},
9191
{
92-
imports: {MultiselectWrapper, Controller},
92+
imports: {MultiSelectWrapper, Controller},
9393
title: 'PlayGround',
9494
path: 'playground/playground',
9595
content: markdownLoader('playground/playground'),

catalog/install.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ Can be used css overriding, see compiled css. Or use scss variables for general
4545
4646
$SM-white: #fff;
4747
$SM-brightGrey: #ebf5ff;
48+
$SM-smoothGray: #f3f3f3;
4849
$SM-lightGrey: #cfd4d9;
4950
$SM-lightBlue: #1298d4;
5051
$SM-grey: #949ca6;
5152
$SM-darkBlue: #143154;
53+
$SM-shadowBlue: rgba(18,152,212,0.5);
5254
5355
// General Colors
5456
$SM-backgroundColor: $SM-white;
@@ -58,6 +60,7 @@ $SM-borderColor: $SM-grey;
5860
$SM-textColor: $SM-darkBlue;
5961
6062
// Value Colors
63+
$SM-headerSelectedColor: $SM-shadowBlue;
6164
$SM-valueColor: $SM-textColor;
6265
$SM-valuePlaceholderColor: $SM-mutedColor;
6366
@@ -69,15 +72,18 @@ $SM-tagCloseColor: $SM-textColor;
6972
$SM-tagCloseBackgroundColor: $SM-lightGrey;
7073
7174
// DropDown
72-
$SM-dropDownArrowColor: $SM-grey;
75+
$SM-dropDownArrowColor: $SM-mutedColor;
7376
$SM-dropDownActiveArrowColor: $SM-lightBlue;
7477
7578
// Search Colors
79+
$SM-searchTextColor: $SM-textColor;
7680
$SM-searchPlaceholderColor: $SM-mutedColor;
81+
$SM-searchSelectedColor: $SM-shadowBlue;
7782
7883
// Option Colors
7984
$SM-itemTextColor: $SM-textColor;
8085
$SM-itemBackgroundHoverColor: $SM-brightGrey;
86+
$SM-itemBackgroundFocusColor: $SM-smoothGray;
8187
$SM-dividerColor: $SM-lightGrey;
8288
$SM-selectAllColor: $SM-itemTextColor;
8389

catalog/playground/multiselect-wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {Fragment} from 'react';
22
import {Controller} from './controller';
33
import {MultiSelect} from '../../src'
44

5-
export class MultiselectWrapper extends React.Component {
5+
export class MultiSelectWrapper extends React.Component {
66

77
state = {
88
mode: 'list',

catalog/playground/playground.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
```react
44
noSource: true
55
---
6-
<MultiselectWrapper />
6+
<MultiSelectWrapper />
77
```

catalog/props.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,55 +124,55 @@ filterOptions(options, text) {
124124

125125
---
126126

127-
- **`ArrowRenderer: function`** DropDown Arrow:
127+
- **`Arrow: function`** DropDown Arrow:
128128

129129
```code
130130
lang: js
131131
---
132-
ArrowRenderer({options, value, expanded, hasFocus}) {
132+
Arrow({options, value, expanded, hasFocus, disabled}) {
133133
// options: array - see 'options' prop
134134
// value: array - see 'value' property
135135
// expanded: boolean - expanded component status
136136
// hasFocus: boolean - hasFocus component status
137+
// disabled: boolean - disabled component status
137138
138139
return - component to render custom Arrow
139140
}
140141
```
141142

142143

143-
- **`LoadingRenderer: function`** Loading Indicator:
144+
- **`Loading: function`** Loading Indicator:
144145

145146
```code
146147
lang: js
147148
---
148-
LoadingRenderer() {
149+
Loading() {
149150
return - component to render custom Loading Indicator
150151
}
151152
```
152153

153154

154-
- **`OptionRenderer: function`** Option:
155+
- **`Option: function`** Option:
155156

156157
```code
157158
lang: js
158159
---
159-
OptionRenderer({option, checked, disabled, onClick}) {
160+
Option({checked, option, isSingle}) {
160161
// option: object - from options props: { value, label }
161162
// checked: boolean - define if option is checked
162-
// disabled: boolean - disable option if component is disabled
163-
// onClick: function - notifies component about option click
163+
// isSingle: boolean - single selection mode
164164
165165
return - component to render custom Option
166166
}
167167
```
168168

169169

170-
- **`TagRenderer: function`** Tag:
170+
- **`Tag: function`** Tag:
171171

172172
```code
173173
lang: js
174174
---
175-
TagRenderer({label, index, removableTag, onTagRemove}) {
175+
Tag({label, index, removableTag, onTagRemove}) {
176176
// label: string - tag label
177177
// index: number - tag index in array used in removal
178178
// removableTag: boolean - display/hide remove tag button
@@ -181,12 +181,12 @@ TagRenderer({label, index, removableTag, onTagRemove}) {
181181
```
182182

183183

184-
- **`ValueRenderer: function`** Value:
184+
- **`Value: function`** Value:
185185

186186
```code
187187
lang: js
188188
---
189-
ValueRenderer({value, options}) {
189+
Value({value, options}) {
190190
// options: array - see 'options' property
191191
// value: array - see 'value' property
192192

catalog/spec/custom.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ state: {
1111
],
1212
}
1313
---
14-
const LoadingRenderer = () => 'Loading ...';
14+
const Loading = () => 'Loading ...';
1515
1616
<MultiSelect
1717
isLoading
1818
options={state.options}
1919
value={state.value}
2020
onChange={value => setState({ value })}
21-
LoadingRenderer={LoadingRenderer}
21+
Loading={Loading}
2222
/>
2323
```
2424

@@ -35,7 +35,7 @@ state: {
3535
],
3636
}
3737
---
38-
const ValueRenderer = ({value, options}) => {
38+
const Value = ({value, options}) => {
3939
if(!value.length) return 'Colors';
4040
return `Colors (${!!value.length && value.length === options.length ? 'All' : value.length})`;
4141
};
@@ -44,7 +44,7 @@ const ValueRenderer = ({value, options}) => {
4444
options={state.options}
4545
value={state.value}
4646
onChange={value => setState({ value })}
47-
ValueRenderer={ValueRenderer}
47+
Value={Value}
4848
/>
4949
```
5050

@@ -62,15 +62,15 @@ state: {
6262
],
6363
}
6464
---
65-
const ArrowRenderer = ({expanded}) => {
65+
const Arrow = ({expanded}) => {
6666
return expanded ? String.fromCharCode(0x027F0) : String.fromCharCode(0x027F1);
6767
};
6868
6969
<MultiSelect
7070
options={state.options}
7171
value={state.value}
7272
onChange={value => setState({ value })}
73-
ArrowRenderer={ArrowRenderer}
73+
Arrow={Arrow}
7474
/>
7575
```
7676

@@ -87,25 +87,23 @@ state: {
8787
],
8888
}
8989
---
90-
const OptionRenderer = ({checked, option, disabled, onClick }) => (
91-
<span className="SelectItem__renderer">
92-
<input
90+
const Option = ({checked, option, isSingle}) => (
91+
<div className="Option__renderer">
92+
{!isSingle && <input
9393
type="checkbox"
94-
onChange={onClick}
95-
checked={checked}
94+
defaultChecked={checked}
9695
tabIndex="-1"
97-
disabled={disabled}
98-
/>
99-
<span className="SelectItem__label">
96+
/>}
97+
<span className="Option__label">
10098
{option.label}
10199
</span>
102-
</span>
100+
</div>
103101
);
104102
105103
<MultiSelect
106104
options={state.options}
107105
value={state.value}
108106
onChange={value => setState({ value })}
109-
OptionRenderer={OptionRenderer}
107+
Option={Option}
110108
/>
111109
```

0 commit comments

Comments
 (0)