@dvrd/dvr-controls 1.0.46 → 1.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -28,8 +28,8 @@ export default function DvrdButton(props: DvrdButtonProps) {
|
|
|
28
28
|
{
|
|
29
29
|
className, disabled, label, labelClassName, onClick, ornamentClassName, ornaments, red, secondary,
|
|
30
30
|
customBaseColor, customContrastColor
|
|
31
|
-
} = props
|
|
32
|
-
|
|
31
|
+
} = props;
|
|
32
|
+
const [hover, setHover] = useState(false);
|
|
33
33
|
|
|
34
34
|
function onMouseEnter() {
|
|
35
35
|
setHover(true);
|
|
@@ -71,7 +71,7 @@ export default function DvrdButton(props: DvrdButtonProps) {
|
|
|
71
71
|
} else if (secondary) color = context.contrastColor;
|
|
72
72
|
else color = context.baseColor;
|
|
73
73
|
color = convertColor(color);
|
|
74
|
-
if (hover) color = editColor(-.2, color);
|
|
74
|
+
if (hover && !disabled) color = editColor(-.2, color);
|
|
75
75
|
return color;
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -159,7 +159,8 @@ export default function DvrdMultiSelect(props: Props) {
|
|
|
159
159
|
const label = selectableItemLabel ?? item.label;
|
|
160
160
|
if (['number', 'string'].includes(typeof label)) return (
|
|
161
161
|
<label key={index} className={classNames('dvrd-select-item', isSelected && 'selected', itemClassName)}
|
|
162
|
-
onClick={onClickItem(value)}>{
|
|
162
|
+
onClick={onClickItem(value)}>{selected &&
|
|
163
|
+
<AwesomeIcon name='check' className='check-icon'/>} {label}</label>
|
|
163
164
|
);
|
|
164
165
|
const labelElement: ReactElement = label as ReactElement;
|
|
165
166
|
const onClick = (evt: React.MouseEvent) => {
|
|
@@ -207,183 +208,4 @@ export default function DvrdMultiSelect(props: Props) {
|
|
|
207
208
|
{renderError()}
|
|
208
209
|
</div>
|
|
209
210
|
)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// class DvrdSelect extends PureComponent<Props, State> {
|
|
213
|
-
// private container: HTMLDivElement;
|
|
214
|
-
// state: State = {
|
|
215
|
-
// open: false,
|
|
216
|
-
// searchFocused: false,
|
|
217
|
-
// };
|
|
218
|
-
//
|
|
219
|
-
// hasError = (): boolean => this.props.error !== undefined && this.props.error !== null;
|
|
220
|
-
//
|
|
221
|
-
// onClickElement = (evt: React.MouseEvent) => {
|
|
222
|
-
// evt.stopPropagation();
|
|
223
|
-
// if (!this.props.disabled)
|
|
224
|
-
// this.setState({open: !this.state.open});
|
|
225
|
-
// };
|
|
226
|
-
//
|
|
227
|
-
// onClickItem = (value: string | number) => (evt: React.MouseEvent) => {
|
|
228
|
-
// evt.stopPropagation();
|
|
229
|
-
// this.props.onChange(value)(evt);
|
|
230
|
-
// this.setState({open: false});
|
|
231
|
-
// };
|
|
232
|
-
//
|
|
233
|
-
// onFocusInput = () => {
|
|
234
|
-
// this.setState({searchFocused: true, open: true});
|
|
235
|
-
// };
|
|
236
|
-
//
|
|
237
|
-
// onBlurInput = () => {
|
|
238
|
-
// window.setTimeout(() => {
|
|
239
|
-
// this.setState({searchFocused: false});
|
|
240
|
-
// this.props.onChangeSearch({target: {value: ''}});
|
|
241
|
-
// }, 200);
|
|
242
|
-
// };
|
|
243
|
-
//
|
|
244
|
-
// getLongestValue = (): string => {
|
|
245
|
-
// const {items} = this.props;
|
|
246
|
-
// let longest: string = '';
|
|
247
|
-
// for (const item of items) {
|
|
248
|
-
// if (item.label.toString().length > longest.length) {
|
|
249
|
-
// longest = item.label.toString();
|
|
250
|
-
// }
|
|
251
|
-
// }
|
|
252
|
-
// return longest;
|
|
253
|
-
// };
|
|
254
|
-
//
|
|
255
|
-
// getValueLabel = (): string | number => {
|
|
256
|
-
// const {value, items} = this.props;
|
|
257
|
-
// for (const item of items) {
|
|
258
|
-
// if (item.value === value) return this.getItemLabel(item);
|
|
259
|
-
// }
|
|
260
|
-
// return '';
|
|
261
|
-
// }
|
|
262
|
-
//
|
|
263
|
-
// getItemLabel = (item: SelectItemShape): string | number => {
|
|
264
|
-
// const {label} = item;
|
|
265
|
-
// if (['string', 'number'].includes(typeof label)) return label as string | number;
|
|
266
|
-
// else if (!!item.valueLabel) return item.valueLabel;
|
|
267
|
-
// return item.value;
|
|
268
|
-
// }
|
|
269
|
-
//
|
|
270
|
-
// getItemsContainerStyle = (): CSSProperties => {
|
|
271
|
-
// let {optionsContainerHeight} = this.props;
|
|
272
|
-
// if (typeof optionsContainerHeight === 'number') optionsContainerHeight = `${optionsContainerHeight}px`;
|
|
273
|
-
// return {maxHeight: optionsContainerHeight};
|
|
274
|
-
// }
|
|
275
|
-
//
|
|
276
|
-
// renderLabel = () => {
|
|
277
|
-
// const {labelClassName, label} = this.props;
|
|
278
|
-
// if (!label) return null;
|
|
279
|
-
// return <label className={classNames('dvrd-select-label', labelClassName)}
|
|
280
|
-
// onClick={this.onClickElement}>{label}</label>
|
|
281
|
-
// };
|
|
282
|
-
//
|
|
283
|
-
// renderValue = () => {
|
|
284
|
-
// const {valueClassName, selectOnly, searchValue, onChangeSearch, disabled} = this.props,
|
|
285
|
-
// {searchFocused} = this.state, valueLabel = this.getValueLabel();
|
|
286
|
-
// if (selectOnly)
|
|
287
|
-
// return (
|
|
288
|
-
// <div style={{display: 'flex', flexDirection: 'column'}}>
|
|
289
|
-
// <label className={classNames('dvrd-select-value', valueClassName)}
|
|
290
|
-
// onClick={this.onClickElement}>{valueLabel}</label>
|
|
291
|
-
// <label style={{height: 0, visibility: 'hidden'}}>{this.getLongestValue()}</label>
|
|
292
|
-
// </div>
|
|
293
|
-
// );
|
|
294
|
-
// const value = searchFocused ? searchValue : valueLabel;
|
|
295
|
-
// return <input className='dvrd-select-search' value={value} onChange={onChangeSearch} disabled={disabled}
|
|
296
|
-
// onFocus={this.onFocusInput} onBlur={this.onBlurInput} onClick={stopPropagation}/>
|
|
297
|
-
// };
|
|
298
|
-
//
|
|
299
|
-
// renderArrow = () => {
|
|
300
|
-
// const {arrowClassName} = this.props, {open} = this.state;
|
|
301
|
-
// return <AwesomeIcon name='chevron-down' onClick={this.onClickElement}
|
|
302
|
-
// className={classNames('dvrd-select-arrow', open && 'open', arrowClassName)}/>;
|
|
303
|
-
// };
|
|
304
|
-
//
|
|
305
|
-
// renderItems = () => {
|
|
306
|
-
// const {disabled, itemContainerClassName, itemsPosition} = this.props, {open} = this.state;
|
|
307
|
-
// const items = this.props.items.filter((item: SelectItemShape) => {
|
|
308
|
-
// if (item.selectable === false) return false;
|
|
309
|
-
// if (typeof item.label === 'string') return item.label.length > 0;
|
|
310
|
-
// return true;
|
|
311
|
-
// })
|
|
312
|
-
// return (
|
|
313
|
-
// <div
|
|
314
|
-
// className={classNames('dvrd-select-items', (open && !disabled) && 'open', itemsPosition,
|
|
315
|
-
// itemContainerClassName)} style={this.getItemsContainerStyle()}>
|
|
316
|
-
// {items.map(this.renderItem)}
|
|
317
|
-
// </div>
|
|
318
|
-
// )
|
|
319
|
-
// };
|
|
320
|
-
//
|
|
321
|
-
// renderItem = (item: SelectItemShape, index: number) => {
|
|
322
|
-
// const {value, selectableItemLabel} = item;
|
|
323
|
-
// const label = selectableItemLabel ?? item.label;
|
|
324
|
-
// const {itemClassName} = this.props;
|
|
325
|
-
// if (['number', 'string'].includes(typeof label)) return (
|
|
326
|
-
// <label key={index} className={classNames('dvrd-select-item', itemClassName)}
|
|
327
|
-
// onClick={this.onClickItem(value)}>{label}</label>
|
|
328
|
-
// );
|
|
329
|
-
// const labelElement: ReactElement = label as ReactElement;
|
|
330
|
-
// const onClick = (evt: React.MouseEvent) => {
|
|
331
|
-
// this.onClickItem(value)(evt);
|
|
332
|
-
// labelElement.props.onClick?.(evt);
|
|
333
|
-
// };
|
|
334
|
-
// const className = classNames(labelElement.props.className, 'dvrd-select-item', itemClassName);
|
|
335
|
-
// return React.cloneElement(labelElement, Object.assign({}, labelElement.props, {
|
|
336
|
-
// onClick,
|
|
337
|
-
// className,
|
|
338
|
-
// key: index
|
|
339
|
-
// }));
|
|
340
|
-
// }
|
|
341
|
-
//
|
|
342
|
-
// renderError = () => {
|
|
343
|
-
// if (!this.hasError()) return null;
|
|
344
|
-
// const {error, errorClassName} = this.props;
|
|
345
|
-
// return <label className={classNames('dvrd-select-error', errorClassName)}>{error}</label>
|
|
346
|
-
// };
|
|
347
|
-
//
|
|
348
|
-
// addClickListener = () => {
|
|
349
|
-
// document.addEventListener('click', this.clickListener);
|
|
350
|
-
// };
|
|
351
|
-
//
|
|
352
|
-
// removeClickListener = () => {
|
|
353
|
-
// document.removeEventListener('click', this.clickListener);
|
|
354
|
-
// }
|
|
355
|
-
//
|
|
356
|
-
// clickListener = () => {
|
|
357
|
-
// if (!hasHover(this.container)) this.setState({open: false});
|
|
358
|
-
// };
|
|
359
|
-
//
|
|
360
|
-
// componentDidUpdate = (props: Props, prevState: State) => {
|
|
361
|
-
// const {open} = this.state, prevOpen = prevState.open;
|
|
362
|
-
// if (open && !prevOpen) this.addClickListener();
|
|
363
|
-
// else if (!open && prevOpen) this.removeClickListener();
|
|
364
|
-
// };
|
|
365
|
-
//
|
|
366
|
-
// componentWillUnmount = () => {
|
|
367
|
-
// this.removeClickListener();
|
|
368
|
-
// };
|
|
369
|
-
//
|
|
370
|
-
// render = () => {
|
|
371
|
-
// const {className, disabled, selectOnly} = this.props, {open} = this.state;
|
|
372
|
-
// return (
|
|
373
|
-
// <div
|
|
374
|
-
// className={classNames('dvrd-select-container', disabled && 'disabled', open && 'open',
|
|
375
|
-
// this.hasError() && 'error', className)}
|
|
376
|
-
// ref={(ref: HTMLDivElement) => {
|
|
377
|
-
// this.container = ref
|
|
378
|
-
// }} onClick={this.onClickElement}>
|
|
379
|
-
// {this.renderLabel()}
|
|
380
|
-
// <div className={classNames('content-container', !selectOnly && 'search')}>
|
|
381
|
-
// {this.renderValue()}
|
|
382
|
-
// {this.renderArrow()}
|
|
383
|
-
// </div>
|
|
384
|
-
// {this.renderItems()}
|
|
385
|
-
// {this.renderError()}
|
|
386
|
-
// </div>
|
|
387
|
-
// )
|
|
388
|
-
// };
|
|
389
|
-
// };
|
|
211
|
+
}
|
|
@@ -12,7 +12,7 @@ type ValueType = string | number | Array<string | number>;
|
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
14
|
onChange: ChangeFunction<ValueType>;
|
|
15
|
-
value:
|
|
15
|
+
value: ValueType;
|
|
16
16
|
items: SelectItemShape[];
|
|
17
17
|
disabled?: boolean;
|
|
18
18
|
label?: string;
|
|
@@ -137,4 +137,22 @@
|
|
|
137
137
|
opacity: 1;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
&.multi {
|
|
142
|
+
.dvrd-select-items {
|
|
143
|
+
.dvrd-select-item {
|
|
144
|
+
.check-icon {
|
|
145
|
+
vertical-align: middle;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
&.selected {
|
|
149
|
+
background-color: rgba($color-green-whatsapp, .2);
|
|
150
|
+
|
|
151
|
+
.check-icon {
|
|
152
|
+
color: $color-green-whatsapp;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
140
158
|
}
|
package/src/js/util/colorUtil.ts
CHANGED
|
@@ -124,8 +124,7 @@ export const getRandomColor = (): string => {
|
|
|
124
124
|
return color;
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
export const editColor = (p, c0, c1?, l?): string => {
|
|
127
|
+
export const editColor = (p: number, c0: string, c1?: string, l?: any): string => {
|
|
129
128
|
c0 = convertColor(c0);
|
|
130
129
|
let r, g, b, P, f, t, h, i = parseInt, m = Math.round, a = typeof (c1) == "string";
|
|
131
130
|
if (p < -1 || p > 1 || (c0[0] !== 'r' && c0[0] !== '#') || (c1 && !a)) return c0;
|