@imposium-hub/components 1.38.3 → 1.38.5

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.
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import FieldWrapper from '../field-wrapper/FieldWrapper';
3
3
  import { IToolTipConfig } from '../Tooltip';
4
- import { ICON_CARET_DOWN } from '../../constants/icons';
4
+ import {ICON_CARET_DOWN, ICON_CLIPBOARD} from '../../constants/icons';
5
+ import Button from '../button/Button';
5
6
 
6
7
  interface ISelectOption {
7
8
  label : string;
@@ -22,15 +23,33 @@ interface ISelectFieldProps {
22
23
  onChange(e) : void;
23
24
  info? : string;
24
25
  labelPosition? : string;
26
+ showCopy? : boolean;
27
+ onNotification?(e) : void;
28
+ onError?(e) : void;
25
29
  }
26
30
 
27
31
  class SelectField extends React.PureComponent<ISelectFieldProps, {}> {
28
-
32
+ private evtHandlers = {
33
+ copyToClipboard: (e) => this.copyToClipboard(e),
34
+ };
29
35
  constructor(props) {
30
36
 
31
37
  super(props);
32
38
  }
39
+ private copyToClipboard(e) {
40
+
41
+ const {onNotification, onError} = this.props;
42
+ navigator.clipboard.writeText(this.props.value).then(() => {
33
43
 
44
+ if (onNotification) {
45
+ onNotification('Copied to clipboard!');
46
+ }
47
+ }, () => {
48
+ if (onError) {
49
+ onError('Error copying to clipboard.');
50
+ }
51
+ });
52
+ }
34
53
  private onChange(e) {
35
54
 
36
55
  // handle selects converting booleans to strings
@@ -43,7 +62,7 @@ class SelectField extends React.PureComponent<ISelectFieldProps, {}> {
43
62
 
44
63
  public render() {
45
64
 
46
- const {label, placeholder, options, value, width, buttons, selectRef, disable, tooltip, info, labelPosition, disableFirst} = this.props;
65
+ const {label, showCopy, placeholder, options, value, width, buttons, selectRef, disable, tooltip, info, labelPosition, disableFirst} = this.props;
47
66
  let opts = [];
48
67
 
49
68
  const selectValue = (value === null || value === undefined) ? '' : value;
@@ -59,6 +78,16 @@ class SelectField extends React.PureComponent<ISelectFieldProps, {}> {
59
78
  } else {
60
79
  btns = [caret];
61
80
  }
81
+ if (showCopy) {
82
+ btns.push(<Button
83
+ key = 'btn-copy'
84
+ style = 'subtle'
85
+ color = 'primary'
86
+ tooltip = 'Copy to Clipboard'
87
+ onClick = {this.evtHandlers.copyToClipboard}>
88
+ {ICON_CLIPBOARD}
89
+ </Button>);
90
+ }
62
91
 
63
92
  if (options) {
64
93
  opts = options.map((option , i) => {