expensify-common 2.0.188 → 2.0.190
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/dist/Logger.js +11 -1
- package/dist/esm/API.d.ts +11 -0
- package/dist/esm/API.js +786 -0
- package/dist/esm/APIDeferred.d.ts +7 -0
- package/dist/esm/APIDeferred.js +216 -0
- package/dist/esm/BrowserDetect.d.ts +19 -0
- package/dist/esm/BrowserDetect.js +105 -0
- package/dist/esm/CLI.js +37 -29
- package/dist/esm/CONST.d.ts +1727 -0
- package/dist/esm/CONST.js +1847 -0
- package/dist/esm/Cookie.d.ts +68 -0
- package/dist/esm/Cookie.js +159 -0
- package/dist/esm/CredentialsWrapper.d.ts +32 -0
- package/dist/esm/CredentialsWrapper.js +46 -0
- package/dist/esm/Device.d.ts +8 -0
- package/dist/esm/Device.js +24 -0
- package/dist/esm/ExpenseRule.d.ts +39 -0
- package/dist/esm/ExpenseRule.js +77 -0
- package/dist/esm/ExpensiMark.d.ts +197 -0
- package/dist/esm/ExpensiMark.js +1374 -0
- package/dist/esm/Func.d.ts +40 -0
- package/dist/esm/Func.js +69 -0
- package/dist/esm/Log.d.ts +3 -0
- package/dist/esm/Log.js +35 -0
- package/dist/esm/Logger.d.ts +82 -0
- package/dist/esm/Logger.js +148 -0
- package/dist/esm/Network.d.ts +6 -0
- package/dist/esm/Network.js +168 -0
- package/dist/esm/Num.d.ts +95 -0
- package/dist/esm/Num.js +190 -0
- package/dist/esm/PageEvent.d.ts +25 -0
- package/dist/esm/PageEvent.js +22 -0
- package/dist/esm/PubSub.d.ts +2 -0
- package/dist/esm/PubSub.js +111 -0
- package/dist/esm/ReportHistoryStore.d.ts +8 -0
- package/dist/esm/ReportHistoryStore.js +199 -0
- package/dist/esm/SafeString.js +2 -2
- package/dist/esm/Templates.d.ts +58 -0
- package/dist/esm/Templates.js +196 -0
- package/dist/esm/Url.d.ts +10 -0
- package/dist/esm/Url.js +15 -0
- package/dist/esm/components/CopyText.d.ts +45 -0
- package/dist/esm/components/CopyText.js +56 -0
- package/dist/esm/components/StepProgressBar.d.ts +26 -0
- package/dist/esm/components/StepProgressBar.js +40 -0
- package/dist/esm/components/form/element/combobox.d.ts +231 -0
- package/dist/esm/components/form/element/combobox.js +812 -0
- package/dist/esm/components/form/element/dropdown.d.ts +35 -0
- package/dist/esm/components/form/element/dropdown.js +61 -0
- package/dist/esm/components/form/element/dropdownItem.d.ts +55 -0
- package/dist/esm/components/form/element/dropdownItem.js +113 -0
- package/dist/esm/components/form/element/onOffSwitch.d.ts +94 -0
- package/dist/esm/components/form/element/onOffSwitch.js +167 -0
- package/dist/esm/components/form/element/switch.d.ts +58 -0
- package/dist/esm/components/form/element/switch.js +98 -0
- package/dist/esm/fastMerge.d.ts +9 -0
- package/dist/esm/fastMerge.js +58 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/jquery.expensifyIframify.d.ts +9 -0
- package/dist/esm/jquery.expensifyIframify.js +397 -0
- package/dist/esm/md5.d.ts +2 -0
- package/dist/esm/md5.js +170 -0
- package/dist/esm/mixins/PubSub.d.ts +20 -0
- package/dist/esm/mixins/PubSub.js +47 -0
- package/dist/esm/mixins/extraClasses.d.ts +8 -0
- package/dist/esm/mixins/extraClasses.js +37 -0
- package/dist/esm/mixins/validationClasses.d.ts +12 -0
- package/dist/esm/mixins/validationClasses.js +30 -0
- package/dist/esm/str.d.ts +604 -0
- package/dist/esm/str.js +1036 -0
- package/dist/esm/tlds.d.ts +2 -0
- package/dist/esm/tlds.js +2 -0
- package/dist/esm/utils.d.ts +30 -0
- package/dist/esm/utils.js +65 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -1
- package/package.json +221 -4
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default DropDown;
|
|
2
|
+
declare class DropDown extends React.Component<any, any, any> {
|
|
3
|
+
constructor(props: any);
|
|
4
|
+
handleClick(option: any): void;
|
|
5
|
+
renderOption(option: any): React.JSX.Element;
|
|
6
|
+
render(): React.JSX.Element;
|
|
7
|
+
}
|
|
8
|
+
declare namespace DropDown {
|
|
9
|
+
export { propTypes };
|
|
10
|
+
export { defaultProps };
|
|
11
|
+
}
|
|
12
|
+
import React from 'react';
|
|
13
|
+
declare namespace propTypes {
|
|
14
|
+
let options: PropTypes.Validator<(PropTypes.InferProps<{
|
|
15
|
+
value: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
|
|
16
|
+
text: PropTypes.Requireable<string>;
|
|
17
|
+
children: PropTypes.Requireable<PropTypes.ReactElementLike>;
|
|
18
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
19
|
+
focused: PropTypes.Requireable<boolean>;
|
|
20
|
+
isSelected: PropTypes.Requireable<boolean>;
|
|
21
|
+
isSelectable: PropTypes.Requireable<boolean>;
|
|
22
|
+
}> | null | undefined)[]>;
|
|
23
|
+
let onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
24
|
+
let bs4: PropTypes.Requireable<boolean>;
|
|
25
|
+
let extraClasses: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
|
|
26
|
+
}
|
|
27
|
+
declare namespace defaultProps {
|
|
28
|
+
export function onChange_1(): void;
|
|
29
|
+
export { onChange_1 as onChange };
|
|
30
|
+
let bs4_1: boolean;
|
|
31
|
+
export { bs4_1 as bs4 };
|
|
32
|
+
let extraClasses_1: never[];
|
|
33
|
+
export { extraClasses_1 as extraClasses };
|
|
34
|
+
}
|
|
35
|
+
import PropTypes from 'prop-types';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import uniqueId from 'lodash/uniqueId';
|
|
5
|
+
import DropDownItem from './dropdownItem';
|
|
6
|
+
const propTypes = {
|
|
7
|
+
// These are the elements to show in the dropdown
|
|
8
|
+
options: PropTypes.arrayOf(PropTypes.shape({
|
|
9
|
+
// The value of the option, should be unique
|
|
10
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
11
|
+
// The human readable text of the option
|
|
12
|
+
text: PropTypes.string,
|
|
13
|
+
// If we need more than text to style more each option
|
|
14
|
+
children: PropTypes.element,
|
|
15
|
+
// Whether or not the option is currently disabled
|
|
16
|
+
disabled: PropTypes.bool,
|
|
17
|
+
// Whether or not the option is currently in focus
|
|
18
|
+
focused: PropTypes.bool,
|
|
19
|
+
// Whether or not the option is currently selected
|
|
20
|
+
isSelected: PropTypes.bool,
|
|
21
|
+
// Whether or not the option can be selected
|
|
22
|
+
isSelectable: PropTypes.bool,
|
|
23
|
+
})).isRequired,
|
|
24
|
+
// A callback that is triggered when a selection is made and passes the value
|
|
25
|
+
// of the selected option as the only parameter
|
|
26
|
+
onChange: PropTypes.func,
|
|
27
|
+
// Bootstrap 4 compatibility flag
|
|
28
|
+
bs4: PropTypes.bool,
|
|
29
|
+
// An array of extra classes to put on the combobox
|
|
30
|
+
extraClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
|
31
|
+
};
|
|
32
|
+
const defaultProps = {
|
|
33
|
+
onChange: () => { },
|
|
34
|
+
bs4: false,
|
|
35
|
+
extraClasses: [],
|
|
36
|
+
};
|
|
37
|
+
class DropDown extends React.Component {
|
|
38
|
+
constructor(props) {
|
|
39
|
+
super(props);
|
|
40
|
+
this.handleClick = this.handleClick.bind(this);
|
|
41
|
+
this.renderOption = this.renderOption.bind(this);
|
|
42
|
+
}
|
|
43
|
+
handleClick(option) {
|
|
44
|
+
if (option.isSelectable === false || option.disabled) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.props.onChange(option.value);
|
|
48
|
+
}
|
|
49
|
+
renderOption(option) {
|
|
50
|
+
return (React.createElement(DropDownItem, { key: uniqueId(), bs4: this.props.bs4, value: option.value, text: option.text || '',
|
|
51
|
+
// eslint-disable-next-line react/no-children-prop
|
|
52
|
+
children: option.children || null, disabled: option.disabled || false, focused: option.focused || false, isSelected: option.isSelected || false, isSelectable: option.isSelectable || true, divider: option.divider || false, extraClasses: option.extraClasses || [], onClick: () => this.handleClick(option) }, option.children));
|
|
53
|
+
}
|
|
54
|
+
render() {
|
|
55
|
+
const { options, extraClasses } = this.props;
|
|
56
|
+
return React.createElement("ul", { className: cn('dropdown-menu', extraClasses) }, options.map(this.renderOption));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
DropDown.propTypes = propTypes;
|
|
60
|
+
DropDown.defaultProps = defaultProps;
|
|
61
|
+
export default DropDown;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export default DropDownItem;
|
|
2
|
+
declare class DropDownItem extends React.Component<any, any, any> {
|
|
3
|
+
constructor(props: any);
|
|
4
|
+
/**
|
|
5
|
+
* Only instantiate the tooltip this dropdown item contains
|
|
6
|
+
*/
|
|
7
|
+
createTooltip(): void;
|
|
8
|
+
hasInstantiatedTooltip: boolean;
|
|
9
|
+
componentWillUnmount(): void;
|
|
10
|
+
/**
|
|
11
|
+
* If there is an instantiated tooltip on the component, destroy it
|
|
12
|
+
*/
|
|
13
|
+
destroyTooltip(): void;
|
|
14
|
+
render(): React.JSX.Element;
|
|
15
|
+
tooltipContainer: JQueryStatic | undefined;
|
|
16
|
+
}
|
|
17
|
+
declare namespace DropDownItem {
|
|
18
|
+
export { propTypes };
|
|
19
|
+
export { defaultProps };
|
|
20
|
+
}
|
|
21
|
+
import React from 'react';
|
|
22
|
+
declare namespace propTypes {
|
|
23
|
+
let onClick: PropTypes.Validator<(...args: any[]) => any>;
|
|
24
|
+
let value: PropTypes.Validator<any>;
|
|
25
|
+
let text: PropTypes.Requireable<string>;
|
|
26
|
+
let children: PropTypes.Requireable<PropTypes.ReactElementLike>;
|
|
27
|
+
let disabled: PropTypes.Requireable<boolean>;
|
|
28
|
+
let focused: PropTypes.Requireable<boolean>;
|
|
29
|
+
let isSelected: PropTypes.Requireable<boolean>;
|
|
30
|
+
let isSelectable: PropTypes.Requireable<boolean>;
|
|
31
|
+
let divider: PropTypes.Requireable<boolean>;
|
|
32
|
+
let bs4: PropTypes.Requireable<boolean>;
|
|
33
|
+
let extraClasses: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
|
|
34
|
+
}
|
|
35
|
+
declare namespace defaultProps {
|
|
36
|
+
let text_1: string;
|
|
37
|
+
export { text_1 as text };
|
|
38
|
+
let children_1: null;
|
|
39
|
+
export { children_1 as children };
|
|
40
|
+
let disabled_1: boolean;
|
|
41
|
+
export { disabled_1 as disabled };
|
|
42
|
+
let focused_1: boolean;
|
|
43
|
+
export { focused_1 as focused };
|
|
44
|
+
let isSelected_1: boolean;
|
|
45
|
+
export { isSelected_1 as isSelected };
|
|
46
|
+
let isSelectable_1: boolean;
|
|
47
|
+
export { isSelectable_1 as isSelectable };
|
|
48
|
+
let divider_1: boolean;
|
|
49
|
+
export { divider_1 as divider };
|
|
50
|
+
let bs4_1: boolean;
|
|
51
|
+
export { bs4_1 as bs4 };
|
|
52
|
+
let extraClasses_1: never[];
|
|
53
|
+
export { extraClasses_1 as extraClasses };
|
|
54
|
+
}
|
|
55
|
+
import PropTypes from 'prop-types';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import Str from '../../../str';
|
|
5
|
+
/**
|
|
6
|
+
* A very basic dropdown item
|
|
7
|
+
*/
|
|
8
|
+
const propTypes = {
|
|
9
|
+
// The function to be called when this item is being clicked
|
|
10
|
+
onClick: PropTypes.func.isRequired,
|
|
11
|
+
// The value of the option, should be unique
|
|
12
|
+
value: PropTypes.any.isRequired, // eslint-disable-line react/forbid-prop-types
|
|
13
|
+
// The human readable text of the option
|
|
14
|
+
text: PropTypes.string,
|
|
15
|
+
// If we need more than text to style more each option
|
|
16
|
+
children: PropTypes.element,
|
|
17
|
+
// Whether or not the option is currently disabled
|
|
18
|
+
disabled: PropTypes.bool,
|
|
19
|
+
// Whether or not the option is currently in focus
|
|
20
|
+
focused: PropTypes.bool,
|
|
21
|
+
// Whether or not the option is currently selected
|
|
22
|
+
isSelected: PropTypes.bool,
|
|
23
|
+
// Whether or not the option can be selected
|
|
24
|
+
isSelectable: PropTypes.bool,
|
|
25
|
+
// Whether this item is a divider or not
|
|
26
|
+
divider: PropTypes.bool,
|
|
27
|
+
// Bootstrap 4 compatibility flag
|
|
28
|
+
bs4: PropTypes.bool,
|
|
29
|
+
// An array of extra classes to put on the combobox
|
|
30
|
+
extraClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
|
31
|
+
};
|
|
32
|
+
const defaultProps = {
|
|
33
|
+
text: '',
|
|
34
|
+
children: null,
|
|
35
|
+
disabled: false,
|
|
36
|
+
focused: false,
|
|
37
|
+
isSelected: false,
|
|
38
|
+
isSelectable: true,
|
|
39
|
+
divider: false,
|
|
40
|
+
bs4: false,
|
|
41
|
+
extraClasses: [],
|
|
42
|
+
};
|
|
43
|
+
class DropDownItem extends React.Component {
|
|
44
|
+
constructor(props) {
|
|
45
|
+
super(props);
|
|
46
|
+
this.createTooltip = this.createTooltip.bind(this);
|
|
47
|
+
this.hasInstantiatedTooltip = false;
|
|
48
|
+
}
|
|
49
|
+
componentWillUnmount() {
|
|
50
|
+
this.destroyTooltip();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Only instantiate the tooltip this dropdown item contains
|
|
54
|
+
*/
|
|
55
|
+
createTooltip() {
|
|
56
|
+
if (this.hasInstantiatedTooltip) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.tooltipContainer.tooltip({
|
|
60
|
+
template: '<div class="tooltip tooltip--from-combobox" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
|
|
61
|
+
});
|
|
62
|
+
this.hasInstantiatedTooltip = true;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* If there is an instantiated tooltip on the component, destroy it
|
|
66
|
+
*/
|
|
67
|
+
destroyTooltip() {
|
|
68
|
+
if (!this.hasInstantiatedTooltip) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.tooltipContainer.tooltip('destroy');
|
|
72
|
+
this.hasInstantiatedTooltip = false;
|
|
73
|
+
}
|
|
74
|
+
render() {
|
|
75
|
+
const classes = {
|
|
76
|
+
a: {
|
|
77
|
+
focus: this.props.focused,
|
|
78
|
+
},
|
|
79
|
+
liOrButton: {
|
|
80
|
+
active: this.props.isSelected && this.props.isSelectable !== false,
|
|
81
|
+
'li-compact': !this.props.bs4,
|
|
82
|
+
'dropdown-item': this.props.bs4,
|
|
83
|
+
disabled: this.props.isSelectable === false || this.props.disabled,
|
|
84
|
+
'dropdown-header': this.props.disabled,
|
|
85
|
+
divider: this.props.divider,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
const extraClasses = cn('expensicons expensicons-checkmark', this.props.extraClasses);
|
|
89
|
+
// Don't do anything when clicking if we can't select something
|
|
90
|
+
const clickHandler = this.props.isSelectable !== false && !this.props.disabled ? this.props.onClick : () => { };
|
|
91
|
+
// Special rendering if we're in Bootstrap 4 compat mode
|
|
92
|
+
if (this.props.bs4) {
|
|
93
|
+
if (this.props.divider) {
|
|
94
|
+
return React.createElement("div", { className: "dropdown-divider" });
|
|
95
|
+
}
|
|
96
|
+
return (React.createElement("button", { type: "button", className: cn(classes.liOrButton), onClick: clickHandler, "data-toggle": "tooltip", "data-container": "body", "data-delay": '{"show":1000, "hide":100}', "data-value": this.props.value, title: typeof this.props.children === 'string' ? this.props.children : Str.htmlDecode(this.props.text) },
|
|
97
|
+
this.props.isSelected && this.props.isSelectable !== false ? (React.createElement("span", null,
|
|
98
|
+
React.createElement("i", { className: extraClasses }),
|
|
99
|
+
' ')) : (''),
|
|
100
|
+
this.props.children || Str.htmlDecode(this.props.text)));
|
|
101
|
+
}
|
|
102
|
+
return (React.createElement("li", { className: cn(classes.liOrButton), "data-value": this.props.value }, !this.props.divider && (
|
|
103
|
+
// eslint-disable-next-line jsx-a11y/anchor-is-valid
|
|
104
|
+
React.createElement("a", { href: "#", className: cn(classes.a), onClick: clickHandler, role: "button", tabIndex: "-1", "data-toggle": "tooltip", onMouseEnter: this.createTooltip, onFocus: this.createTooltip, "data-container": "body", "data-delay": '{"show":1000, "hide":100}', title: typeof this.props.children === 'string' ? this.props.children : Str.htmlDecode(this.props.text), ref: (el) => (this.tooltipContainer = $(el)) },
|
|
105
|
+
this.props.isSelected && this.props.isSelectable !== false ? (React.createElement("span", null,
|
|
106
|
+
React.createElement("i", { className: extraClasses }),
|
|
107
|
+
' ')) : (''),
|
|
108
|
+
this.props.children || Str.htmlDecode(this.props.text)))));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
DropDownItem.propTypes = propTypes;
|
|
112
|
+
DropDownItem.defaultProps = defaultProps;
|
|
113
|
+
export default DropDownItem;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export default OnOffSwitch;
|
|
2
|
+
declare class OnOffSwitch extends React.Component<any, any, any> {
|
|
3
|
+
constructor(props: any);
|
|
4
|
+
/**
|
|
5
|
+
* Callback function called after toggling the switch
|
|
6
|
+
* @param {boolean} newState
|
|
7
|
+
*/
|
|
8
|
+
onChangeCallback(newState: boolean): void;
|
|
9
|
+
/**
|
|
10
|
+
* Force switch off and prevent editing it
|
|
11
|
+
* @param {boolean} checked
|
|
12
|
+
* @param {string} msg
|
|
13
|
+
*/
|
|
14
|
+
lock(checked: boolean, msg: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Release switch to its original value, and allow editing it
|
|
17
|
+
*/
|
|
18
|
+
unlock(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Is the switch on or off ?
|
|
21
|
+
*
|
|
22
|
+
* @returns {boolean} true if on
|
|
23
|
+
*/
|
|
24
|
+
getValue(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Toggle the state of this switch.
|
|
27
|
+
*
|
|
28
|
+
* Note: this is used via refs, so please don't delete it unless you know what you're doing :D
|
|
29
|
+
*/
|
|
30
|
+
toggle(): void;
|
|
31
|
+
state: {
|
|
32
|
+
checked: any;
|
|
33
|
+
preventEdit: any;
|
|
34
|
+
preventEditDescription: string;
|
|
35
|
+
};
|
|
36
|
+
render(): React.JSX.Element;
|
|
37
|
+
}
|
|
38
|
+
declare namespace OnOffSwitch {
|
|
39
|
+
export { propTypes };
|
|
40
|
+
export { defaultProps };
|
|
41
|
+
}
|
|
42
|
+
import React from 'react';
|
|
43
|
+
declare namespace propTypes {
|
|
44
|
+
let id: PropTypes.Validator<string>;
|
|
45
|
+
let label: PropTypes.Requireable<string>;
|
|
46
|
+
let labelOnRight: PropTypes.Requireable<boolean>;
|
|
47
|
+
let labelClasses: PropTypes.Requireable<any>;
|
|
48
|
+
let checked: PropTypes.Validator<boolean>;
|
|
49
|
+
let onChangeCallback: PropTypes.Requireable<(...args: any[]) => any>;
|
|
50
|
+
let children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
51
|
+
let preventEdit: PropTypes.Requireable<boolean>;
|
|
52
|
+
let description: PropTypes.Requireable<string>;
|
|
53
|
+
let onlyShowDescriptionWhenOn: PropTypes.Requireable<boolean>;
|
|
54
|
+
let noLeftPaddingOnChildren: PropTypes.Requireable<boolean>;
|
|
55
|
+
let alwaysShowChildren: PropTypes.Requireable<boolean>;
|
|
56
|
+
let descriptionBeforeChildren: PropTypes.Requireable<boolean>;
|
|
57
|
+
let safeDescription: PropTypes.Requireable<boolean>;
|
|
58
|
+
let extraClasses: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
|
|
59
|
+
let hideEnabledDisabledText: PropTypes.Requireable<boolean>;
|
|
60
|
+
let tooltipText: PropTypes.Requireable<string>;
|
|
61
|
+
}
|
|
62
|
+
declare namespace defaultProps {
|
|
63
|
+
let label_1: string;
|
|
64
|
+
export { label_1 as label };
|
|
65
|
+
let labelOnRight_1: boolean;
|
|
66
|
+
export { labelOnRight_1 as labelOnRight };
|
|
67
|
+
let labelClasses_1: null;
|
|
68
|
+
export { labelClasses_1 as labelClasses };
|
|
69
|
+
export function onChangeCallback_1(): void;
|
|
70
|
+
export { onChangeCallback_1 as onChangeCallback };
|
|
71
|
+
let children_1: null;
|
|
72
|
+
export { children_1 as children };
|
|
73
|
+
let preventEdit_1: boolean;
|
|
74
|
+
export { preventEdit_1 as preventEdit };
|
|
75
|
+
let description_1: string;
|
|
76
|
+
export { description_1 as description };
|
|
77
|
+
let onlyShowDescriptionWhenOn_1: boolean;
|
|
78
|
+
export { onlyShowDescriptionWhenOn_1 as onlyShowDescriptionWhenOn };
|
|
79
|
+
let noLeftPaddingOnChildren_1: boolean;
|
|
80
|
+
export { noLeftPaddingOnChildren_1 as noLeftPaddingOnChildren };
|
|
81
|
+
let alwaysShowChildren_1: boolean;
|
|
82
|
+
export { alwaysShowChildren_1 as alwaysShowChildren };
|
|
83
|
+
let descriptionBeforeChildren_1: boolean;
|
|
84
|
+
export { descriptionBeforeChildren_1 as descriptionBeforeChildren };
|
|
85
|
+
let safeDescription_1: boolean;
|
|
86
|
+
export { safeDescription_1 as safeDescription };
|
|
87
|
+
let hideEnabledDisabledText_1: boolean;
|
|
88
|
+
export { hideEnabledDisabledText_1 as hideEnabledDisabledText };
|
|
89
|
+
let extraClasses_1: never[];
|
|
90
|
+
export { extraClasses_1 as extraClasses };
|
|
91
|
+
let tooltipText_1: string;
|
|
92
|
+
export { tooltipText_1 as tooltipText };
|
|
93
|
+
}
|
|
94
|
+
import PropTypes from 'prop-types';
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import cn from 'classnames';
|
|
4
|
+
import { invoke } from '../../../Func';
|
|
5
|
+
import { UI } from '../../../CONST';
|
|
6
|
+
import Switch from './switch';
|
|
7
|
+
/**
|
|
8
|
+
* Displays an on off switch (optionally) with label
|
|
9
|
+
*/
|
|
10
|
+
const propTypes = {
|
|
11
|
+
// A unique identifier
|
|
12
|
+
id: PropTypes.string.isRequired,
|
|
13
|
+
// Label to be displayed left to the switch
|
|
14
|
+
label: PropTypes.string,
|
|
15
|
+
// True if the label should be on the right
|
|
16
|
+
labelOnRight: PropTypes.bool,
|
|
17
|
+
// Classes of the label
|
|
18
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
19
|
+
labelClasses: PropTypes.any,
|
|
20
|
+
// True if the switch is on
|
|
21
|
+
checked: PropTypes.bool.isRequired,
|
|
22
|
+
// Callback function to call when changing the switch (optional)
|
|
23
|
+
onChangeCallback: PropTypes.func,
|
|
24
|
+
// Element to be displayed below the switch when it's on (optional)
|
|
25
|
+
children: PropTypes.node,
|
|
26
|
+
// Disable edition of the switch (optional)
|
|
27
|
+
preventEdit: PropTypes.bool,
|
|
28
|
+
// Description to be displayed below the switch (optional)
|
|
29
|
+
description: PropTypes.string,
|
|
30
|
+
// If set to true, the description of the switch is only displayed when it is in the 'checked' state (optional)
|
|
31
|
+
onlyShowDescriptionWhenOn: PropTypes.bool,
|
|
32
|
+
// If set to true, children elements won't be applied a left padding (optional)
|
|
33
|
+
noLeftPaddingOnChildren: PropTypes.bool,
|
|
34
|
+
// Whether we should always show the children classes
|
|
35
|
+
alwaysShowChildren: PropTypes.bool,
|
|
36
|
+
// If set to true, the description of the switch will be placed above the children elements (optional)
|
|
37
|
+
descriptionBeforeChildren: PropTypes.bool,
|
|
38
|
+
// Safety check to ensure we are using dangerouslySetInnerHTML() safely
|
|
39
|
+
safeDescription: PropTypes.bool,
|
|
40
|
+
// An array of extra classes to put on the combobox
|
|
41
|
+
extraClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
|
42
|
+
// There is usually text just following a switch that says "ENABLED" and "DISABLED" and
|
|
43
|
+
// you can use this option to hide that text
|
|
44
|
+
hideEnabledDisabledText: PropTypes.bool,
|
|
45
|
+
// Text to display in a tooltip
|
|
46
|
+
tooltipText: PropTypes.string,
|
|
47
|
+
};
|
|
48
|
+
const defaultProps = {
|
|
49
|
+
label: '',
|
|
50
|
+
labelOnRight: false,
|
|
51
|
+
labelClasses: null,
|
|
52
|
+
onChangeCallback: () => { },
|
|
53
|
+
children: null,
|
|
54
|
+
preventEdit: false,
|
|
55
|
+
description: '',
|
|
56
|
+
onlyShowDescriptionWhenOn: false,
|
|
57
|
+
noLeftPaddingOnChildren: false,
|
|
58
|
+
alwaysShowChildren: false,
|
|
59
|
+
descriptionBeforeChildren: false,
|
|
60
|
+
safeDescription: false,
|
|
61
|
+
hideEnabledDisabledText: false,
|
|
62
|
+
extraClasses: [],
|
|
63
|
+
tooltipText: '',
|
|
64
|
+
};
|
|
65
|
+
class OnOffSwitch extends Component {
|
|
66
|
+
constructor(props) {
|
|
67
|
+
super(props);
|
|
68
|
+
this.onChangeCallback = this.onChangeCallback.bind(this);
|
|
69
|
+
this.lock = this.lock.bind(this);
|
|
70
|
+
this.unlock = this.unlock.bind(this);
|
|
71
|
+
this.getValue = this.getValue.bind(this);
|
|
72
|
+
this.toggle = this.toggle.bind(this);
|
|
73
|
+
this.state = {
|
|
74
|
+
checked: this.props.checked,
|
|
75
|
+
preventEdit: this.props.preventEdit,
|
|
76
|
+
preventEditDescription: '',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Callback function called after toggling the switch
|
|
81
|
+
* @param {boolean} newState
|
|
82
|
+
*/
|
|
83
|
+
onChangeCallback(newState) {
|
|
84
|
+
invoke(this.props.onChangeCallback, [newState]);
|
|
85
|
+
this.setState({
|
|
86
|
+
checked: newState,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Is the switch on or off ?
|
|
91
|
+
*
|
|
92
|
+
* @returns {boolean} true if on
|
|
93
|
+
*/
|
|
94
|
+
getValue() {
|
|
95
|
+
return this.state.checked;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Toggle the state of this switch.
|
|
99
|
+
*
|
|
100
|
+
* Note: this is used via refs, so please don't delete it unless you know what you're doing :D
|
|
101
|
+
*/
|
|
102
|
+
toggle() {
|
|
103
|
+
this.setState((prevState) => ({
|
|
104
|
+
checked: !prevState.checked,
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Force switch off and prevent editing it
|
|
109
|
+
* @param {boolean} checked
|
|
110
|
+
* @param {string} msg
|
|
111
|
+
*/
|
|
112
|
+
lock(checked, msg) {
|
|
113
|
+
this.setState({
|
|
114
|
+
checked,
|
|
115
|
+
preventEdit: true,
|
|
116
|
+
preventEditDescription: msg,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Release switch to its original value, and allow editing it
|
|
121
|
+
*/
|
|
122
|
+
unlock() {
|
|
123
|
+
this.setState((prevState) => ({
|
|
124
|
+
checked: prevState.checked,
|
|
125
|
+
preventEdit: false,
|
|
126
|
+
preventEditDescription: '',
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
render() {
|
|
130
|
+
const childrenClasses = {
|
|
131
|
+
depreciated: !this.props.noLeftPaddingOnChildren,
|
|
132
|
+
helperLabel: !this.props.noLeftPaddingOnChildren,
|
|
133
|
+
};
|
|
134
|
+
if (!this.props.alwaysShowChildren) {
|
|
135
|
+
childrenClasses[UI.HIDDEN] = !this.state.checked;
|
|
136
|
+
}
|
|
137
|
+
const children = this.props.children ? React.createElement("div", { className: cn(childrenClasses) }, this.props.children) : null;
|
|
138
|
+
// Only use dangerouslySetInnerHTML if we explicitly pass safeDescription as a parameter.
|
|
139
|
+
// Otherwise, just set the description inside a div
|
|
140
|
+
// We use dangerouslySetInnerHTML, which could introduce XSS vulnerabilities if derived from user input,
|
|
141
|
+
// to keep the description property simple without a bunch of nested HTML elements
|
|
142
|
+
const description = this.state.preventEdit && this.state.preventEditDescription ? this.state.preventEditDescription : this.props.description;
|
|
143
|
+
let descriptionElm = null;
|
|
144
|
+
if (description && (this.state.checked || !this.props.onlyShowDescriptionWhenOn)) {
|
|
145
|
+
if (this.props.safeDescription) {
|
|
146
|
+
descriptionElm = (React.createElement("div", { className: "depreciated helperLabel",
|
|
147
|
+
// eslint-disable-next-line react/no-danger
|
|
148
|
+
dangerouslySetInnerHTML: { __html: description } }));
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
descriptionElm = React.createElement("div", { className: "depreciated helperLabel" }, description);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return (React.createElement("div", null,
|
|
155
|
+
this.props.label && !this.props.labelOnRight && (React.createElement("label", { className: cn(this.props.labelClasses), htmlFor: this.props.id }, this.props.label)),
|
|
156
|
+
React.createElement(Switch, { id: this.props.id, checked: this.state.checked, disabled: this.state.preventEdit, onChange: this.onChangeCallback, extraClasses: [this.props.extraClasses, { marginLeft10: !this.props.labelOnRight }], hideEnabledDisabledText: this.props.hideEnabledDisabledText, tooltipText: this.props.tooltipText }),
|
|
157
|
+
this.props.label && this.props.labelOnRight && (React.createElement("label", { className: cn(this.props.labelClasses, 'marginLeft5'), htmlFor: this.props.id }, this.props.label)),
|
|
158
|
+
this.props.descriptionBeforeChildren ? (React.createElement("div", null,
|
|
159
|
+
descriptionElm,
|
|
160
|
+
children)) : (React.createElement("div", null,
|
|
161
|
+
children,
|
|
162
|
+
descriptionElm))));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
OnOffSwitch.propTypes = propTypes;
|
|
166
|
+
OnOffSwitch.defaultProps = defaultProps;
|
|
167
|
+
export default OnOffSwitch;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export default Switch;
|
|
2
|
+
declare class Switch extends React.Component<any, any, any> {
|
|
3
|
+
constructor(props: any);
|
|
4
|
+
/**
|
|
5
|
+
* Fires the change handler with the current value
|
|
6
|
+
*/
|
|
7
|
+
fireChangeHandler(): void;
|
|
8
|
+
/**
|
|
9
|
+
* If there was a confirm object specified in our properties,
|
|
10
|
+
* then we need to open a confirm modal with those settings
|
|
11
|
+
*
|
|
12
|
+
* @param {SyntheticEvent} e
|
|
13
|
+
* @returns {Boolean}
|
|
14
|
+
*/
|
|
15
|
+
showConfirm(e: SyntheticEvent): boolean;
|
|
16
|
+
checkbox: HTMLInputElement | null;
|
|
17
|
+
element: HTMLSpanElement | null;
|
|
18
|
+
componentDidMount(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the value of the field
|
|
21
|
+
*
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
getValue(): boolean;
|
|
25
|
+
render(): React.JSX.Element;
|
|
26
|
+
}
|
|
27
|
+
declare namespace Switch {
|
|
28
|
+
export { propTypes };
|
|
29
|
+
export { defaultProps };
|
|
30
|
+
}
|
|
31
|
+
import React from 'react';
|
|
32
|
+
declare namespace propTypes {
|
|
33
|
+
let id: PropTypes.Validator<string>;
|
|
34
|
+
let checked: PropTypes.Requireable<boolean>;
|
|
35
|
+
let disabled: PropTypes.Requireable<boolean>;
|
|
36
|
+
let onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
37
|
+
let confirm: PropTypes.Requireable<object>;
|
|
38
|
+
let extraClasses: PropTypes.Requireable<NonNullable<string | object | null | undefined>>;
|
|
39
|
+
let hideEnabledDisabledText: PropTypes.Requireable<boolean>;
|
|
40
|
+
let tooltipText: PropTypes.Requireable<string>;
|
|
41
|
+
}
|
|
42
|
+
declare namespace defaultProps {
|
|
43
|
+
let checked_1: boolean;
|
|
44
|
+
export { checked_1 as checked };
|
|
45
|
+
let disabled_1: boolean;
|
|
46
|
+
export { disabled_1 as disabled };
|
|
47
|
+
export function onChange_1(): void;
|
|
48
|
+
export { onChange_1 as onChange };
|
|
49
|
+
let confirm_1: null;
|
|
50
|
+
export { confirm_1 as confirm };
|
|
51
|
+
let extraClasses_1: never[];
|
|
52
|
+
export { extraClasses_1 as extraClasses };
|
|
53
|
+
let hideEnabledDisabledText_1: boolean;
|
|
54
|
+
export { hideEnabledDisabledText_1 as hideEnabledDisabledText };
|
|
55
|
+
let tooltipText_1: string;
|
|
56
|
+
export { tooltipText_1 as tooltipText };
|
|
57
|
+
}
|
|
58
|
+
import PropTypes from 'prop-types';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* globals Func, Modal */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import get from 'lodash/get';
|
|
6
|
+
/**
|
|
7
|
+
* Form Element Switch - Displays an on/off switch
|
|
8
|
+
*/
|
|
9
|
+
const propTypes = {
|
|
10
|
+
id: PropTypes.string.isRequired,
|
|
11
|
+
// If it is turned on by default
|
|
12
|
+
checked: PropTypes.bool,
|
|
13
|
+
// If it is disabled or not
|
|
14
|
+
disabled: PropTypes.bool,
|
|
15
|
+
// A callback method for when the value is changed
|
|
16
|
+
onChange: PropTypes.func,
|
|
17
|
+
// A configuration object that is passed to Modal.confirm() if we want to have
|
|
18
|
+
// the user confirm their choice
|
|
19
|
+
confirm: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
|
20
|
+
// An array of extra classes to put on the combobox
|
|
21
|
+
extraClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
|
|
22
|
+
// There is usually text just following a switch that says "ENABLED" and "DISABLED" and
|
|
23
|
+
// you can use this option to hide that text
|
|
24
|
+
hideEnabledDisabledText: PropTypes.bool,
|
|
25
|
+
// Text to display in a tooltip
|
|
26
|
+
tooltipText: PropTypes.string,
|
|
27
|
+
};
|
|
28
|
+
const defaultProps = {
|
|
29
|
+
checked: false,
|
|
30
|
+
disabled: false,
|
|
31
|
+
onChange: () => { },
|
|
32
|
+
confirm: null,
|
|
33
|
+
extraClasses: [],
|
|
34
|
+
hideEnabledDisabledText: false,
|
|
35
|
+
tooltipText: '',
|
|
36
|
+
};
|
|
37
|
+
class Switch extends React.Component {
|
|
38
|
+
constructor(props) {
|
|
39
|
+
super(props);
|
|
40
|
+
this.fireChangeHandler = this.fireChangeHandler.bind(this);
|
|
41
|
+
this.showConfirm = this.showConfirm.bind(this);
|
|
42
|
+
this.checkbox = null;
|
|
43
|
+
this.element = null;
|
|
44
|
+
}
|
|
45
|
+
componentDidMount() {
|
|
46
|
+
$(this.element).tooltip('destroy').tooltip();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the value of the field
|
|
50
|
+
*
|
|
51
|
+
* @returns {boolean}
|
|
52
|
+
*/
|
|
53
|
+
getValue() {
|
|
54
|
+
return $(this.checkbox)[0].checked;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fires the change handler with the current value
|
|
58
|
+
*/
|
|
59
|
+
fireChangeHandler() {
|
|
60
|
+
// Don't do anything here if we want the user to confirm their choice
|
|
61
|
+
if (this.props.confirm) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
Func.invoke(this.props.onChange, [this.getValue()]);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* If there was a confirm object specified in our properties,
|
|
68
|
+
* then we need to open a confirm modal with those settings
|
|
69
|
+
*
|
|
70
|
+
* @param {SyntheticEvent} e
|
|
71
|
+
* @returns {Boolean}
|
|
72
|
+
*/
|
|
73
|
+
showConfirm(e) {
|
|
74
|
+
// Let our event happen normally
|
|
75
|
+
if (!this.props.confirm) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
Modal.confirm(Object.assign(Object.assign({}, get(this.props, 'confirm', {})), { onYesCallback: () => {
|
|
80
|
+
// Toggle the checked property and then fire our change handler
|
|
81
|
+
this.checkbox.checked = !this.getValue();
|
|
82
|
+
Func.invoke(this.props.onChange, [this.getValue()]);
|
|
83
|
+
} }));
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
return (React.createElement("span", { className: cn('onoffswitch-wrapper js_tooltip', this.props.extraClasses), title: this.props.tooltipText, ref: (el) => (this.element = el) },
|
|
88
|
+
React.createElement("input", { ref: (el) => (this.checkbox = el), type: "checkbox", id: this.props.id, className: "onoffswitch-checkbox", checked: this.props.checked, disabled: this.props.disabled, onClick: this.showConfirm, onChange: this.fireChangeHandler }),
|
|
89
|
+
React.createElement("label", { className: "onoffswitch-label", htmlFor: this.props.id },
|
|
90
|
+
React.createElement("span", { className: cn('onoffswitch-inner', {
|
|
91
|
+
noText: this.props.hideEnabledDisabledText,
|
|
92
|
+
}) }),
|
|
93
|
+
React.createElement("span", { className: "onoffswitch-switch" }))));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
Switch.propTypes = propTypes;
|
|
97
|
+
Switch.defaultProps = defaultProps;
|
|
98
|
+
export default Switch;
|