@servicetitan/form 31.1.0 → 31.3.0
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/color-picker/color-palette.js +8 -9
- package/dist/color-picker/color-palette.js.map +1 -1
- package/dist/color-picker/color-picker.js +46 -9
- package/dist/color-picker/color-picker.js.map +1 -1
- package/dist/color-picker/color-picker.module.css.d.ts +4 -0
- package/dist/color-picker/index.js +1 -0
- package/dist/color-picker/index.js.map +1 -1
- package/dist/date-range-picker/date-range-picker.js +205 -174
- package/dist/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/date-range-picker/date-range-picker.module.css.d.ts +8 -0
- package/dist/date-range-picker/index.js +1 -0
- package/dist/date-range-picker/index.js.map +1 -1
- package/dist/demo/color-picker.js +39 -4
- package/dist/demo/color-picker.js.map +1 -1
- package/dist/demo/date-range-picker.js +18 -2
- package/dist/demo/date-range-picker.js.map +1 -1
- package/dist/demo/file-uploader.js +94 -12
- package/dist/demo/file-uploader.js.map +1 -1
- package/dist/demo/index.js +1 -0
- package/dist/demo/index.js.map +1 -1
- package/dist/demo/input-date-mask.js +18 -2
- package/dist/demo/input-date-mask.js.map +1 -1
- package/dist/demo/number-input.js +121 -3
- package/dist/demo/number-input.js.map +1 -1
- package/dist/demo/original-number-input.js +18 -2
- package/dist/demo/original-number-input.js.map +1 -1
- package/dist/demo/phone-number-input.js +5 -1
- package/dist/demo/phone-number-input.js.map +1 -1
- package/dist/file-uploader/config.js +10 -1
- package/dist/file-uploader/config.js.map +1 -1
- package/dist/file-uploader/file-uploader.js +189 -192
- package/dist/file-uploader/file-uploader.js.map +1 -1
- package/dist/file-uploader/index.js +3 -1
- package/dist/file-uploader/index.js.map +1 -1
- package/dist/file-uploader/uploader.js +57 -41
- package/dist/file-uploader/uploader.js.map +1 -1
- package/dist/form-state-error-banner/form-state-error-banner.js +15 -5
- package/dist/form-state-error-banner/form-state-error-banner.js.map +1 -1
- package/dist/form-state-error-banner/index.js +1 -0
- package/dist/form-state-error-banner/index.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/input-date-mask/index.js +1 -0
- package/dist/input-date-mask/index.js.map +1 -1
- package/dist/input-date-mask/input-date-mask.js +47 -28
- package/dist/input-date-mask/input-date-mask.js.map +1 -1
- package/dist/input-date-mask/input-date-mask.module.css.d.ts +4 -0
- package/dist/label/index.js +1 -0
- package/dist/label/index.js.map +1 -1
- package/dist/label/label.js +29 -1
- package/dist/label/label.js.map +1 -1
- package/dist/label/label.module.css.d.ts +7 -0
- package/dist/masked-input.js +17 -4
- package/dist/masked-input.js.map +1 -1
- package/dist/number-input/common-interfaces.js +2 -1
- package/dist/number-input/common-interfaces.js.map +1 -1
- package/dist/number-input/get-formatted-string.js +2 -3
- package/dist/number-input/get-formatted-string.js.map +1 -1
- package/dist/number-input/index.js +1 -0
- package/dist/number-input/index.js.map +1 -1
- package/dist/number-input/number-input.js +53 -42
- package/dist/number-input/number-input.js.map +1 -1
- package/dist/number-input/process-value.js +10 -16
- package/dist/number-input/process-value.js.map +1 -1
- package/dist/original-number-input/index.js +1 -0
- package/dist/original-number-input/index.js.map +1 -1
- package/dist/original-number-input/ordinal-number-input.js +54 -59
- package/dist/original-number-input/ordinal-number-input.js.map +1 -1
- package/dist/phone-number-input/index.js +1 -0
- package/dist/phone-number-input/index.js.map +1 -1
- package/dist/phone-number-input/phone-number-input.js +13 -1
- package/dist/phone-number-input/phone-number-input.js.map +1 -1
- package/package.json +13 -13
- package/dist/form.stories.js +0 -20
- package/dist/form.stories.js.map +0 -1
- package/dist/number-input/__tests__/get-formatted-string.test.js +0 -41
- package/dist/number-input/__tests__/get-formatted-string.test.js.map +0 -1
- package/dist/number-input/__tests__/process-value.test.js +0 -283
- package/dist/number-input/__tests__/process-value.test.js.map +0 -1
- package/dist/original-number-input/__tests__/ordinal-number-input.test.js +0 -51
- package/dist/original-number-input/__tests__/ordinal-number-input.test.js.map +0 -1
@@ -1,31 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
Object.defineProperty(this, "resumable", {
|
1
|
+
function _define_property(obj, key, value) {
|
2
|
+
if (key in obj) {
|
3
|
+
Object.defineProperty(obj, key, {
|
4
|
+
value: value,
|
6
5
|
enumerable: true,
|
7
6
|
configurable: true,
|
8
|
-
writable: true
|
9
|
-
value: void 0
|
7
|
+
writable: true
|
10
8
|
});
|
9
|
+
} else {
|
10
|
+
obj[key] = value;
|
11
|
+
}
|
12
|
+
return obj;
|
13
|
+
}
|
14
|
+
import { v4 as uuid } from 'uuid';
|
15
|
+
const Resumable = require('resumablejs');
|
16
|
+
export class Uploader {
|
17
|
+
upload(source) {
|
18
|
+
if (source instanceof File) {
|
19
|
+
this.resumable.addFile(source);
|
20
|
+
} else {
|
21
|
+
for (const file of Array.from(source)){
|
22
|
+
this.resumable.addFile(file);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
cancel(file) {
|
27
|
+
if (file) {
|
28
|
+
for (const resumableFile of this.resumable.files){
|
29
|
+
if (resumableFile.file === file) {
|
30
|
+
resumableFile.cancel();
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
this.resumable.cancel();
|
36
|
+
}
|
37
|
+
}
|
38
|
+
constructor(config = {}, handlers = {}, folderName = 'default'){
|
39
|
+
_define_property(this, "resumable", void 0);
|
11
40
|
const { errorParser, ...configuration } = config;
|
12
41
|
const resumable = new Resumable({
|
13
42
|
target: `/app/api/fileuploader/folders/${folderName}/files`,
|
14
43
|
testChunks: false,
|
15
44
|
simultaneousUploads: 1,
|
16
|
-
headers: {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
45
|
+
headers: {
|
46
|
+
'X-Requested-With': 'XMLHttpRequest'
|
47
|
+
},
|
48
|
+
permanentErrors: [
|
49
|
+
302,
|
50
|
+
400,
|
51
|
+
404,
|
52
|
+
415,
|
53
|
+
500,
|
54
|
+
501
|
55
|
+
],
|
56
|
+
generateUniqueIdentifier: ()=>uuid(),
|
57
|
+
fileTypeErrorCallback: (file)=>{
|
58
|
+
var _configuration_fileType_map, _configuration_fileType, _handlers_error;
|
59
|
+
(_handlers_error = handlers.error) === null || _handlers_error === void 0 ? void 0 : _handlers_error.call(handlers, file, `File type not allowed. Please provide file of type ${(_configuration_fileType = configuration.fileType) === null || _configuration_fileType === void 0 ? void 0 : (_configuration_fileType_map = _configuration_fileType.map((ext)=>`.${ext}`)) === null || _configuration_fileType_map === void 0 ? void 0 : _configuration_fileType_map.join(', ')}.`);
|
22
60
|
},
|
23
|
-
...configuration
|
61
|
+
...configuration
|
24
62
|
});
|
25
|
-
resumable.on('fileAdded', ()
|
63
|
+
resumable.on('fileAdded', ()=>{
|
26
64
|
resumable.upload();
|
27
65
|
});
|
28
|
-
resumable.on('fileProgress', resumableFile
|
66
|
+
resumable.on('fileProgress', (resumableFile)=>{
|
29
67
|
if (resumableFile.isComplete()) {
|
30
68
|
return;
|
31
69
|
}
|
@@ -37,13 +75,13 @@ export class Uploader {
|
|
37
75
|
handlers.progress(resumableFile.file, progress);
|
38
76
|
}
|
39
77
|
});
|
40
|
-
resumable.on('fileSuccess', (resumableFile, message)
|
78
|
+
resumable.on('fileSuccess', (resumableFile, message)=>{
|
41
79
|
if (handlers.success) {
|
42
80
|
handlers.success(resumableFile.file, message);
|
43
81
|
}
|
44
82
|
resumableFile.cancel();
|
45
83
|
});
|
46
|
-
resumable.on('fileError', (resumableFile, message)
|
84
|
+
resumable.on('fileError', (resumableFile, message)=>{
|
47
85
|
if (handlers.error) {
|
48
86
|
handlers.error(resumableFile.file, errorParser ? errorParser(message) : message);
|
49
87
|
}
|
@@ -51,28 +89,6 @@ export class Uploader {
|
|
51
89
|
});
|
52
90
|
this.resumable = resumable;
|
53
91
|
}
|
54
|
-
upload(source) {
|
55
|
-
if (source instanceof File) {
|
56
|
-
this.resumable.addFile(source);
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
for (const file of Array.from(source)) {
|
60
|
-
this.resumable.addFile(file);
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
cancel(file) {
|
65
|
-
if (file) {
|
66
|
-
for (const resumableFile of this.resumable.files) {
|
67
|
-
if (resumableFile.file === file) {
|
68
|
-
resumableFile.cancel();
|
69
|
-
break;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
else {
|
74
|
-
this.resumable.cancel();
|
75
|
-
}
|
76
|
-
}
|
77
92
|
}
|
93
|
+
|
78
94
|
//# sourceMappingURL=uploader.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/file-uploader/uploader.ts"],"sourcesContent":["import { v4 as uuid } from 'uuid';\n\nimport { FileUploaderConfig } from './config';\n\nconst Resumable = require('resumablejs');\n\ninterface Resumable {\n files: ResumableFile[];\n on(event: 'fileAdded', callback: (file: ResumableFile, event: Event) => void): void;\n on(event: 'fileProgress', callback: (file: ResumableFile, message?: string) => void): void;\n on(event: 'fileSuccess', callback: (file: ResumableFile, message?: string) => void): void;\n on(event: 'fileError', callback: (file: ResumableFile, message?: string) => void): void;\n addFile(file: File): void;\n upload(): void;\n cancel(): void;\n}\n\ninterface ResumableFile {\n file: File;\n progress(relative?: boolean): number;\n isComplete(): boolean;\n cancel(): void;\n}\n\nexport class Uploader {\n private readonly resumable: Resumable;\n\n constructor(\n config: FileUploaderConfig = {},\n handlers: {\n progress?(file: File, progress: number): void;\n success?(file: File, message?: string): void;\n error?(file: File, message?: string): void;\n } = {},\n folderName = 'default'\n ) {\n const { errorParser, ...configuration } = config;\n\n const resumable: Resumable = new Resumable({\n target: `/app/api/fileuploader/folders/${folderName}/files`,\n testChunks: false,\n simultaneousUploads: 1,\n headers: { 'X-Requested-With': 'XMLHttpRequest' },\n permanentErrors: [302, 400, 404, 415, 500, 501],\n generateUniqueIdentifier: () => uuid(),\n fileTypeErrorCallback: (file: File) => {\n handlers.error?.(\n file,\n `File type not allowed. Please provide file of type ${configuration.fileType\n ?.map(ext => `.${ext}`)\n ?.join(', ')}.`\n );\n },\n ...configuration,\n });\n\n resumable.on('fileAdded', () => {\n resumable.upload();\n });\n\n resumable.on('fileProgress', resumableFile => {\n if (resumableFile.isComplete()) {\n return;\n }\n\n let progress = Math.floor(resumableFile.progress(false) * 100);\n if (progress > 99) {\n progress = 99;\n }\n\n if (handlers.progress) {\n handlers.progress(resumableFile.file, progress);\n }\n });\n\n resumable.on('fileSuccess', (resumableFile, message) => {\n if (handlers.success) {\n handlers.success(resumableFile.file, message);\n }\n\n resumableFile.cancel();\n });\n\n resumable.on('fileError', (resumableFile, message) => {\n if (handlers.error) {\n handlers.error(resumableFile.file, errorParser ? errorParser(message) : message);\n }\n\n resumableFile.cancel();\n });\n\n this.resumable = resumable;\n }\n\n upload(source: File | FileList) {\n if (source instanceof File) {\n this.resumable.addFile(source);\n } else {\n for (const file of Array.from(source)) {\n this.resumable.addFile(file);\n }\n }\n }\n\n cancel(file?: File) {\n if (file) {\n for (const resumableFile of this.resumable.files) {\n if (resumableFile.file === file) {\n resumableFile.cancel();\n break;\n }\n }\n } else {\n this.resumable.cancel();\n }\n }\n}\n"],"names":["v4","uuid","Resumable","require","Uploader","upload","source","File","resumable","addFile","file","Array","from","cancel","resumableFile","files","constructor","config","handlers","folderName","errorParser","configuration","target","testChunks","simultaneousUploads","headers","permanentErrors","generateUniqueIdentifier","fileTypeErrorCallback","error","fileType","map","ext","join","on","isComplete","progress","Math","floor","message","success"],"mappings":";;;;;;;;;;;;;AAAA,SAASA,MAAMC,IAAI,QAAQ,OAAO;AAIlC,MAAMC,YAAYC,QAAQ;AAoB1B,OAAO,MAAMC;IAsETC,OAAOC,MAAuB,EAAE;QAC5B,IAAIA,kBAAkBC,MAAM;YACxB,IAAI,CAACC,SAAS,CAACC,OAAO,CAACH;QAC3B,OAAO;YACH,KAAK,MAAMI,QAAQC,MAAMC,IAAI,CAACN,QAA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AWC,KAAKC,KAAK,CAACxB,cAAcsB,QAAQ,CAAC,SAAS;YAC1D,IAAIA,WAAW,IAAI;gBACfA,WAAW;YACf;YAEA,IAAIlB,SAASkB,QAAQ,EAAE;gBACnBlB,SAASkB,QAAQ,CAACtB,cAAcJ,IAAI,EAAE0B;YAC1C;QACJ;QAEA5B,UAAU0B,EAAE,CAAC,eAAe,CAACpB,eAAeyB;YACxC,IAAIrB,SAASsB,OAAO,EAAE;gBAClBtB,SAASsB,OAAO,CAAC1B,cAAcJ,IAAI,EAAE6B;YACzC;YAEAzB,cAAcD,MAAM;QACxB;QAEAL,UAAU0B,EAAE,CAAC,aAAa,CAACpB,eAAeyB;YACtC,IAAIrB,SAASW,KAAK,EAAE;gBAChBX,SAASW,KAAK,CAACf,cAAcJ,IAAI,EAAEU,cAAcA,YAAYmB,WAAWA;YAC5E;YAEAzB,cAAcD,MAAM;QACxB;QAEA,IAAI,CAACL,SAAS,GAAGA;IACrB;AAwBJ"}
|
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Banner } from '@servicetitan/design-system';
|
3
3
|
import { traverseFormState } from '@servicetitan/form-state';
|
4
4
|
import { observer } from 'mobx-react';
|
5
|
-
export const FormStateErrorBanner = observer(({ form, className, errorTitle = 'Form Incomplete', successTitle = 'Form Complete'
|
5
|
+
export const FormStateErrorBanner = observer(({ form, className, errorTitle = 'Form Incomplete', successTitle = 'Form Complete' })=>{
|
6
6
|
const errors = [];
|
7
|
-
traverseFormState(true, form, (_0, formState)
|
7
|
+
traverseFormState(true, form, (_0, formState)=>{
|
8
8
|
if (formState.formError) {
|
9
9
|
errors.push(formState.formError);
|
10
10
|
}
|
@@ -14,8 +14,18 @@ export const FormStateErrorBanner = observer(({ form, className, errorTitle = 'F
|
|
14
14
|
}
|
15
15
|
const status = errors.length === 0 ? 'success' : 'critical';
|
16
16
|
const title = errors.length === 0 ? successTitle : errorTitle;
|
17
|
-
return
|
18
|
-
|
19
|
-
|
17
|
+
return /*#__PURE__*/ _jsx(Banner, {
|
18
|
+
className: className,
|
19
|
+
status: status,
|
20
|
+
icon: true,
|
21
|
+
title: title,
|
22
|
+
children: /*#__PURE__*/ _jsx("ul", {
|
23
|
+
children: errors.map((e, index)=>// eslint-disable-next-line react/no-array-index-key
|
24
|
+
/*#__PURE__*/ _jsx("li", {
|
25
|
+
children: e
|
26
|
+
}, index))
|
27
|
+
})
|
28
|
+
});
|
20
29
|
});
|
30
|
+
|
21
31
|
//# sourceMappingURL=form-state-error-banner.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/form-state-error-banner/form-state-error-banner.tsx"],"sourcesContent":["import { Banner } from '@servicetitan/design-system';\nimport { traverseFormState } from '@servicetitan/form-state';\nimport { observer } from 'mobx-react';\nimport { FormState, ValidatableMapOrArray } from 'formstate';\n\nexport interface FormStateErrorBannerProps<T extends ValidatableMapOrArray> {\n form: FormState<T>;\n className?: string;\n errorTitle?: string;\n successTitle?: string;\n}\n\nexport const FormStateErrorBanner = observer(\n <T extends ValidatableMapOrArray>({\n form,\n className,\n errorTitle = 'Form Incomplete',\n successTitle = 'Form Complete',\n }: FormStateErrorBannerProps<T>) => {\n const errors: string[] = [];\n traverseFormState(true, form, (_0, formState) => {\n if (formState.formError) {\n errors.push(formState.formError);\n }\n });\n if (form.formError) {\n errors.push(form.formError);\n }\n const status = errors.length === 0 ? 'success' : 'critical';\n const title = errors.length === 0 ? successTitle : errorTitle;\n return (\n <Banner className={className} status={status} icon title={title}>\n <ul>\n {errors.map((e, index) => (\n // eslint-disable-next-line react/no-array-index-key\n <li key={index}>{e}</li>\n ))}\n </ul>\n </Banner>\n );\n }\n);\n"],"names":["Banner","traverseFormState","observer","FormStateErrorBanner","form","className","errorTitle","successTitle","errors","_0","formState","formError","push","status","length","title","icon","ul","map","e","index","li"],"mappings":";AAAA,SAASA,MAAM,QAAQ,8BAA8B;AACrD,SAASC,iBAAiB,QAAQ,2BAA2B;AAC7D,SAASC,QAAQ,QAAQ,aAAa;AAUtC,OAAO,MAAMC,uBAAuBD,SAChC,CAAkC,EAC9BE,IAAI,EACJC,SAAS,EACTC,aAAa,iBAAiB,EAC9BC,eAAe,eAAe,EACH;IAC3B,MAAMC,SAAmB,EAAE;IAC3BP,kBAAkB,MAAMG,MAAM,CAACK,IAAIC;QAC/B,IAAIA,UAAUC,SAAS,EAAE;YACrBH,OAAOI,IAAI,CAACF,UAAUC,SAAS;QACnC;IACJ;IACA,IAAIP,KAAKO,SAAS,EAAE;QAChBH,OAAOI,IAAI,CAACR,KAAKO,SAAS;IAC9B;IACA,MAAME,SAASL,OAAOM,MAAM,KAAK,IAAI,YAAY;IACjD,MAAMC,QAAQP,OAAOM,MAAM,KAAK,IAAIP,eAAeD;IACnD,qBACI,KAACN;QAAOK,WAAWA;QAAWQ,QAAQA;QAAQG,IAAI;QAACD,OAAOA;kBACtD,cAAA,KAACE;sBACIT,OAAOU,GAAG,CAAC,CAACC,GAAGC,QACZ,oDAAoD;8BACpD,KAACC;8BAAgBF;mBAARC;;;AAK7B,GACF"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/form-state-error-banner/index.ts"],"sourcesContent":["export * from './form-state-error-banner';\n"],"names":[],"mappings":"AAAA,cAAc,4BAA4B"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './color-picker';\nexport * from './file-uploader';\nexport * from './form-state-error-banner';\nexport * from './label';\nexport * from './number-input';\nexport * from './masked-input';\nexport * from './date-range-picker';\nexport * from './phone-number-input';\nexport * from './original-number-input';\nexport * from './input-date-mask';\n\nexport * from '@servicetitan/form-state';\n"],"names":[],"mappings":"AAAA,cAAc,iBAAiB;AAC/B,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,UAAU;AACxB,cAAc,iBAAiB;AAC/B,cAAc,iBAAiB;AAC/B,cAAc,sBAAsB;AACpC,cAAc,uBAAuB;AACrC,cAAc,0BAA0B;AACxC,cAAc,oBAAoB;AAElC,cAAc,2BAA2B"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/input-date-mask/index.ts"],"sourcesContent":["export * from './input-date-mask';\n"],"names":[],"mappings":"AAAA,cAAc,oBAAoB"}
|
@@ -8,20 +8,20 @@ import InputMask from 'react-input-mask';
|
|
8
8
|
import classnames from 'classnames';
|
9
9
|
import * as Styles from './input-date-mask.module.css';
|
10
10
|
const KEY_DEL = 46;
|
11
|
-
export const InputDateMask = observer(({ className, maskChar = 'X', alwaysShowMask, shortLabel, value, onChange, 'qa-testing': qaTestingLocator, error, disabled, placeholder, dateFormat = 'MM/DD/YYYY', minDate, maxDate
|
12
|
-
const state = useLocalStore(()
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
const handleKeyDown = (evt)
|
11
|
+
export const InputDateMask = observer(({ className, maskChar = 'X', alwaysShowMask, shortLabel, value, onChange, 'qa-testing': qaTestingLocator, error, disabled, placeholder, dateFormat = 'MM/DD/YYYY', minDate, maxDate })=>{
|
12
|
+
const state = useLocalStore(()=>({
|
13
|
+
maskValue: '',
|
14
|
+
setMask: action(function(mask) {
|
15
|
+
this.maskValue = mask;
|
16
|
+
})
|
17
|
+
}));
|
18
|
+
const handleKeyDown = (evt)=>{
|
19
19
|
if (evt.keyCode === KEY_DEL) {
|
20
20
|
onChange(undefined);
|
21
21
|
state.setMask('');
|
22
22
|
}
|
23
23
|
};
|
24
|
-
const handleChange = (event)
|
24
|
+
const handleChange = (event)=>{
|
25
25
|
const value = event.target.value;
|
26
26
|
state.setMask(value);
|
27
27
|
if (event.type === 'focus' || event.type === 'blur') {
|
@@ -29,45 +29,44 @@ export const InputDateMask = observer(({ className, maskChar = 'X', alwaysShowMa
|
|
29
29
|
}
|
30
30
|
if (isMaskValid(value)) {
|
31
31
|
onChange(parseDate(value));
|
32
|
-
}
|
33
|
-
else {
|
32
|
+
} else {
|
34
33
|
onChange(undefined);
|
35
34
|
}
|
36
35
|
};
|
37
|
-
useEffect(()
|
36
|
+
useEffect(()=>{
|
38
37
|
if (value === undefined && isMaskValid(state.maskValue)) {
|
39
38
|
state.setMask('');
|
40
39
|
}
|
41
|
-
}, [
|
42
|
-
|
40
|
+
}, [
|
41
|
+
value
|
42
|
+
]); // eslint-disable-line react-hooks/exhaustive-deps
|
43
|
+
const getMaskError = ()=>{
|
43
44
|
return value === undefined && state.maskValue !== '' && isMaskInvalid(state.maskValue);
|
44
45
|
};
|
45
|
-
const getValueError = ()
|
46
|
+
const getValueError = ()=>{
|
46
47
|
return value !== undefined && !isDateInRange(value);
|
47
48
|
};
|
48
|
-
const formatDate = (date)
|
49
|
+
const formatDate = (date)=>{
|
49
50
|
return date ? moment(date).format(dateFormat) : '';
|
50
51
|
};
|
51
|
-
const parseDate = (date)
|
52
|
+
const parseDate = (date)=>{
|
52
53
|
return moment(date, dateFormat).toDate();
|
53
54
|
};
|
54
|
-
const isMaskValid = (mask)
|
55
|
+
const isMaskValid = (mask)=>{
|
55
56
|
return !mask.includes(maskChar) && isDateStringValid(mask);
|
56
57
|
};
|
57
|
-
const isMaskInvalid = (mask)
|
58
|
+
const isMaskInvalid = (mask)=>{
|
58
59
|
return !mask.includes(maskChar) && !isDateStringValid(mask);
|
59
60
|
};
|
60
|
-
const isDateStringValid = (date)
|
61
|
+
const isDateStringValid = (date)=>{
|
61
62
|
return moment(date, dateFormat).isValid() && isDateInRange(parseDate(date));
|
62
63
|
};
|
63
|
-
const isDateInRange = (date)
|
64
|
+
const isDateInRange = (date)=>{
|
64
65
|
if (minDate && maxDate) {
|
65
66
|
return date >= minDate && date <= maxDate;
|
66
|
-
}
|
67
|
-
else if (minDate) {
|
67
|
+
} else if (minDate) {
|
68
68
|
return date >= minDate;
|
69
|
-
}
|
70
|
-
else if (maxDate) {
|
69
|
+
} else if (maxDate) {
|
71
70
|
return date <= maxDate;
|
72
71
|
}
|
73
72
|
return true;
|
@@ -76,9 +75,29 @@ export const InputDateMask = observer(({ className, maskChar = 'X', alwaysShowMa
|
|
76
75
|
const realError = error || getMaskError() || getValueError();
|
77
76
|
const realPlaceholder = placeholder || mask.replace(/9/g, maskChar);
|
78
77
|
const classes = classnames(className, qaTestingLocator, Styles.input, {
|
79
|
-
[Styles.error]: realError
|
78
|
+
[Styles.error]: realError
|
79
|
+
});
|
80
|
+
const renderFunction = ({ size, ...props })=>/*#__PURE__*/ _jsx("div", {
|
81
|
+
children: /*#__PURE__*/ _jsx(Input, {
|
82
|
+
...props,
|
83
|
+
shortLabel: shortLabel,
|
84
|
+
className: classes,
|
85
|
+
small: true,
|
86
|
+
fluid: true,
|
87
|
+
error: realError,
|
88
|
+
disabled: disabled,
|
89
|
+
placeholder: realPlaceholder
|
90
|
+
})
|
91
|
+
});
|
92
|
+
return /*#__PURE__*/ _jsx(InputMask, {
|
93
|
+
mask: mask,
|
94
|
+
maskChar: maskChar,
|
95
|
+
onChange: handleChange,
|
96
|
+
onKeyDown: handleKeyDown,
|
97
|
+
alwaysShowMask: alwaysShowMask,
|
98
|
+
value: formatDate(value) || state.maskValue,
|
99
|
+
children: renderFunction
|
80
100
|
});
|
81
|
-
const renderFunction = ({ size, ...props }) => (_jsx("div", { children: _jsx(Input, { ...props, shortLabel: shortLabel, className: classes, small: true, fluid: true, error: realError, disabled: disabled, placeholder: realPlaceholder }) }));
|
82
|
-
return (_jsx(InputMask, { mask: mask, maskChar: maskChar, onChange: handleChange, onKeyDown: handleKeyDown, alwaysShowMask: alwaysShowMask, value: formatDate(value) || state.maskValue, children: renderFunction }));
|
83
101
|
});
|
102
|
+
|
84
103
|
//# sourceMappingURL=input-date-mask.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/input-date-mask/input-date-mask.tsx"],"sourcesContent":["import { FC, ChangeEvent, useEffect, InputHTMLAttributes, PropsWithChildren } from 'react';\nimport { Input, InputProps } from '@servicetitan/design-system';\nimport { action } from 'mobx';\nimport { useLocalStore, observer } from 'mobx-react';\nimport moment from 'moment';\nimport InputMask from 'react-input-mask';\nimport classnames from 'classnames';\nimport * as Styles from './input-date-mask.module.css';\n\nconst KEY_DEL = 46;\n\ninterface InputDateMaskStore {\n maskValue: string;\n setMask(maskValue: string): void;\n}\n\nexport interface InputDateMaskProps extends Omit<InputProps, 'onChange' | 'value'> {\n value?: Date;\n ['qa-testing']?: string;\n maskChar?: string;\n alwaysShowMask?: boolean;\n dateFormat?: string;\n minDate?: Date;\n maxDate?: Date;\n onChange(value: Date | undefined): void;\n}\n\nexport const InputDateMask: FC<PropsWithChildren<InputDateMaskProps>> = observer(\n ({\n className,\n maskChar = 'X',\n alwaysShowMask,\n shortLabel,\n value,\n onChange,\n 'qa-testing': qaTestingLocator,\n error,\n disabled,\n placeholder,\n dateFormat = 'MM/DD/YYYY',\n minDate,\n maxDate,\n }: InputDateMaskProps) => {\n const state = useLocalStore(() => ({\n maskValue: '',\n setMask: action(function (this: InputDateMaskStore, mask: string) {\n this.maskValue = mask;\n }),\n }));\n\n const handleKeyDown = (evt: any) => {\n if (evt.keyCode === KEY_DEL) {\n onChange(undefined);\n\n state.setMask('');\n }\n };\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n const value = event.target.value;\n\n state.setMask(value);\n\n if (event.type === 'focus' || event.type === 'blur') {\n return;\n }\n\n if (isMaskValid(value)) {\n onChange(parseDate(value));\n } else {\n onChange(undefined);\n }\n };\n\n useEffect(() => {\n if (value === undefined && isMaskValid(state.maskValue)) {\n state.setMask('');\n }\n }, [value]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const getMaskError = () => {\n return value === undefined && state.maskValue !== '' && isMaskInvalid(state.maskValue);\n };\n\n const getValueError = () => {\n return value !== undefined && !isDateInRange(value);\n };\n\n const formatDate = (date?: Date) => {\n return date ? moment(date).format(dateFormat) : '';\n };\n\n const parseDate = (date: string) => {\n return moment(date, dateFormat).toDate();\n };\n\n const isMaskValid = (mask: string) => {\n return !mask.includes(maskChar) && isDateStringValid(mask);\n };\n\n const isMaskInvalid = (mask: string) => {\n return !mask.includes(maskChar) && !isDateStringValid(mask);\n };\n\n const isDateStringValid = (date: string) => {\n return moment(date, dateFormat).isValid() && isDateInRange(parseDate(date));\n };\n\n const isDateInRange = (date: Date) => {\n if (minDate && maxDate) {\n return date >= minDate && date <= maxDate;\n } else if (minDate) {\n return date >= minDate;\n } else if (maxDate) {\n return date <= maxDate;\n }\n\n return true;\n };\n\n const mask = dateFormat.replace(/[MDY]/g, '9');\n\n const realError = error || getMaskError() || getValueError();\n\n const realPlaceholder = placeholder || mask.replace(/9/g, maskChar);\n\n const classes = classnames(className, qaTestingLocator, Styles.input, {\n [Styles.error]: realError,\n });\n\n const renderFunction = ({ size, ...props }: InputHTMLAttributes<HTMLInputElement>) => (\n <div>\n <Input\n {...props}\n shortLabel={shortLabel}\n className={classes}\n small\n fluid\n error={realError}\n disabled={disabled}\n placeholder={realPlaceholder}\n />\n </div>\n );\n\n return (\n <InputMask\n mask={mask}\n maskChar={maskChar}\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n alwaysShowMask={alwaysShowMask}\n value={formatDate(value) || state.maskValue}\n >\n {renderFunction as any}\n </InputMask>\n );\n }\n);\n"],"names":["useEffect","Input","action","useLocalStore","observer","moment","InputMask","classnames","Styles","KEY_DEL","InputDateMask","className","maskChar","alwaysShowMask","shortLabel","value","onChange","qaTestingLocator","error","disabled","placeholder","dateFormat","minDate","maxDate","state","maskValue","setMask","mask","handleKeyDown","evt","keyCode","undefined","handleChange","event","target","type","isMaskValid","parseDate","getMaskError","isMaskInvalid","getValueError","isDateInRange","formatDate","date","format","toDate","includes","isDateStringValid","isValid","replace","realError","realPlaceholder","classes","input","renderFunction","size","props","div","small","fluid","onKeyDown"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KAAK;gBACLzC,OAAOgC;gBACP/B,UAAUA;gBACVC,aAAa+B;;;IAKzB,qBACI,KAAC7C;QACGqB,MAAMA;QACNf,UAAUA;QACVI,UAAUgB;QACV4B,WAAWhC;QACXf,gBAAgBA;QAChBE,OAAO2B,WAAW3B,UAAUS,MAAMC,SAAS;kBAE1C6B;;AAGb,GACF"}
|
package/dist/label/index.js
CHANGED
package/dist/label/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/label/index.ts"],"sourcesContent":["export * from './label';\n"],"names":[],"mappings":"AAAA,cAAc,UAAU"}
|
package/dist/label/label.js
CHANGED
@@ -2,5 +2,33 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import classNames from 'classnames';
|
3
3
|
import { Stack, Icon, Text, Tooltip } from '@servicetitan/design-system';
|
4
4
|
import * as Styles from './label.module.css';
|
5
|
-
export const Label = ({ label, tooltip, tooltipDirection = 'r', hasError, error
|
5
|
+
export const Label = ({ label, tooltip, tooltipDirection = 'r', hasError, error })=>/*#__PURE__*/ _jsxs("div", {
|
6
|
+
className: classNames(Styles.label, hasError && Styles.hasError),
|
7
|
+
children: [
|
8
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
9
|
+
className: Styles.text,
|
10
|
+
children: [
|
11
|
+
/*#__PURE__*/ _jsx(Stack.Item, {
|
12
|
+
children: label
|
13
|
+
}),
|
14
|
+
tooltip && /*#__PURE__*/ _jsx(Stack.Item, {
|
15
|
+
className: Styles.tooltip,
|
16
|
+
children: /*#__PURE__*/ _jsx(Tooltip, {
|
17
|
+
direction: tooltipDirection,
|
18
|
+
text: tooltip,
|
19
|
+
children: /*#__PURE__*/ _jsx(Icon, {
|
20
|
+
name: "info"
|
21
|
+
})
|
22
|
+
})
|
23
|
+
})
|
24
|
+
]
|
25
|
+
}),
|
26
|
+
hasError && /*#__PURE__*/ _jsx(Text, {
|
27
|
+
className: Styles.error,
|
28
|
+
size: 1,
|
29
|
+
children: error
|
30
|
+
})
|
31
|
+
]
|
32
|
+
});
|
33
|
+
|
6
34
|
//# sourceMappingURL=label.js.map
|
package/dist/label/label.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/label/label.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport { FC } from 'react';\nimport { Stack, Icon, Text, Tooltip } from '@servicetitan/design-system';\n\nimport * as Styles from './label.module.css';\n\ntype Direction =\n | 'top'\n | 't'\n | 'right'\n | 'r'\n | 'bottom'\n | 'b'\n | 'left'\n | 'l'\n | 'topleft'\n | 'tl'\n | 'topright'\n | 'tr'\n | 'bottomleft'\n | 'bl'\n | 'bottomright'\n | 'br';\n\ninterface LabelProps {\n label: string;\n tooltip?: string;\n tooltipDirection?: Direction;\n hasError?: boolean;\n error?: string;\n}\n\nexport const Label: FC<LabelProps> = ({\n label,\n tooltip,\n tooltipDirection = 'r',\n hasError,\n error,\n}) => (\n <div className={classNames(Styles.label, hasError && Styles.hasError)}>\n <Stack className={Styles.text}>\n <Stack.Item>{label}</Stack.Item>\n {tooltip && (\n <Stack.Item className={Styles.tooltip}>\n <Tooltip direction={tooltipDirection} text={tooltip}>\n <Icon name=\"info\" />\n </Tooltip>\n </Stack.Item>\n )}\n </Stack>\n {hasError && (\n <Text className={Styles.error} size={1}>\n {error}\n </Text>\n )}\n </div>\n);\n"],"names":["classNames","Stack","Icon","Text","Tooltip","Styles","Label","label","tooltip","tooltipDirection","hasError","error","div","className","text","Item","direction","name","size"],"mappings":";AAAA,OAAOA,gBAAgB,aAAa;AAEpC,SAASC,KAAK,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,QAAQ,8BAA8B;AAEzE,YAAYC,YAAY,qBAAqB;AA4B7C,OAAO,MAAMC,QAAwB,CAAC,EAClCC,KAAK,EACLC,OAAO,EACPC,mBAAmB,GAAG,EACtBC,QAAQ,EACRC,KAAK,EACR,iBACG,MAACC;QAAIC,WAAWb,WAAWK,OAAOE,KAAK,EAAEG,YAAYL,OAAOK,QAAQ;;0BAChE,MAACT;gBAAMY,WAAWR,OAAOS,IAAI;;kCACzB,KAACb,MAAMc,IAAI;kCAAER;;oBACZC,yBACG,KAACP,MAAMc,IAAI;wBAACF,WAAWR,OAAOG,OAAO;kCACjC,cAAA,KAACJ;4BAAQY,WAAWP;4BAAkBK,MAAMN;sCACxC,cAAA,KAACN;gCAAKe,MAAK;;;;;;YAK1BP,0BACG,KAACP;gBAAKU,WAAWR,OAAOM,KAAK;gBAAEO,MAAM;0BAChCP;;;OAIf"}
|
package/dist/masked-input.js
CHANGED
@@ -1,11 +1,24 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import ReactInputMask from 'react-input-mask';
|
3
3
|
import { Form } from '@servicetitan/design-system';
|
4
|
-
export const MaskedInput = ({ mask, maskChar, value, onChange, placeholder, disabled, formatChars, ...props })
|
5
|
-
const handleInputChange = (e)
|
4
|
+
export const MaskedInput = ({ mask, maskChar, value, onChange, placeholder, disabled, formatChars, ...props })=>{
|
5
|
+
const handleInputChange = (e)=>{
|
6
6
|
onChange(e.target.value);
|
7
7
|
};
|
8
|
-
const renderFunction = (innerProps)
|
9
|
-
|
8
|
+
const renderFunction = (innerProps)=>/*#__PURE__*/ _jsx(Form.Input, {
|
9
|
+
...props,
|
10
|
+
...innerProps
|
11
|
+
});
|
12
|
+
return /*#__PURE__*/ _jsx(ReactInputMask, {
|
13
|
+
mask: mask,
|
14
|
+
maskChar: maskChar,
|
15
|
+
value: value,
|
16
|
+
onChange: handleInputChange,
|
17
|
+
placeholder: placeholder,
|
18
|
+
disabled: disabled,
|
19
|
+
formatChars: formatChars,
|
20
|
+
children: renderFunction
|
21
|
+
});
|
10
22
|
};
|
23
|
+
|
11
24
|
//# sourceMappingURL=masked-input.js.map
|
package/dist/masked-input.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/masked-input.tsx"],"sourcesContent":["import { FC, InputHTMLAttributes, ChangeEvent } from 'react';\r\n\r\nimport ReactInputMask, { Props as ReactMaskedInputProps } from 'react-input-mask';\r\nimport { Form, FormInputProps } from '@servicetitan/design-system';\r\n\r\ntype MaskedInputProps = FormInputProps &\r\n Omit<ReactMaskedInputProps, keyof InputHTMLAttributes<HTMLInputElement>>;\r\n\r\nexport const MaskedInput: FC<MaskedInputProps> = ({\r\n mask,\r\n maskChar,\r\n value,\r\n onChange,\r\n placeholder,\r\n disabled,\r\n formatChars,\r\n ...props\r\n}) => {\r\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {\r\n onChange(e.target.value);\r\n };\r\n\r\n const renderFunction = (innerProps: InputHTMLAttributes<HTMLInputElement>) => (\r\n <Form.Input {...props} {...innerProps} />\r\n );\r\n\r\n return (\r\n <ReactInputMask\r\n mask={mask}\r\n maskChar={maskChar}\r\n value={value}\r\n onChange={handleInputChange}\r\n placeholder={placeholder}\r\n disabled={disabled}\r\n formatChars={formatChars}\r\n >\r\n {renderFunction as any}\r\n </ReactInputMask>\r\n );\r\n};\r\n"],"names":["ReactInputMask","Form","MaskedInput","mask","maskChar","value","onChange","placeholder","disabled","formatChars","props","handleInputChange","e","target","renderFunction","innerProps","Input"],"mappings":";AAEA,OAAOA,oBAAwD,mBAAmB;AAClF,SAASC,IAAI,QAAwB,8BAA8B;AAKnE,OAAO,MAAMC,cAAoC,CAAC,EAC9CC,IAAI,EACJC,QAAQ,EACRC,KAAK,EACLC,QAAQ,EACRC,WAAW,EACXC,QAAQ,EACRC,WAAW,EACX,GAAGC,OACN;IACG,MAAMC,oBAAoB,CAACC;QACvBN,SAASM,EAAEC,MAAM,CAACR,KAAK;IAC3B;IAEA,MAAMS,iBAAiB,CAACC,2BACpB,KAACd,KAAKe,KAAK;YAAE,GAAGN,KAAK;YAAG,GAAGK,UAAU;;IAGzC,qBACI,KAACf;QACGG,MAAMA;QACNC,UAAUA;QACVC,OAAOA;QACPC,UAAUK;QACVJ,aAAaA;QACbC,UAAUA;QACVC,aAAaA;kBAEZK;;AAGb,EAAE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/number-input/common-interfaces.ts"],"sourcesContent":["export type EmptyValue = 0 | undefined;\nexport type NumberValue<TEmpty extends EmptyValue> = TEmpty extends 0 ? number : number | undefined;\n\nexport interface Range {\n min?: number;\n max?: number;\n}\n\nexport interface Separators {\n thousand: string;\n decimal: string;\n}\n"],"names":[],"mappings":"AAQA,WAGC"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { formatNumber as formatNumberDefault } from 'accounting';
|
2
2
|
export function getFormattedString(value, { emptyValue, precision, separators }, formatNumber = formatNumberDefault) {
|
3
|
-
return typeof value === 'number' || emptyValue === 0
|
4
|
-
? formatNumber((typeof value === 'number' ? value : emptyValue), precision !== null && precision !== void 0 ? precision : 0, separators.thousand, separators.decimal)
|
5
|
-
: '';
|
3
|
+
return typeof value === 'number' || emptyValue === 0 ? formatNumber(typeof value === 'number' ? value : emptyValue, precision !== null && precision !== void 0 ? precision : 0, separators.thousand, separators.decimal) : '';
|
6
4
|
}
|
5
|
+
|
7
6
|
//# sourceMappingURL=get-formatted-string.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/number-input/get-formatted-string.ts"],"sourcesContent":["import { formatNumber as formatNumberDefault } from 'accounting';\n\nimport { EmptyValue, NumberValue, Separators } from './common-interfaces';\n\nexport type FormatNumber = (\n value: number,\n precision?: number,\n thousand?: string,\n decimal?: string\n) => string;\n\ninterface GetFormattedStringOptions<TEmpty extends EmptyValue> {\n emptyValue: TEmpty;\n precision?: number;\n separators: Separators;\n}\n\nexport function getFormattedString<TEmpty extends EmptyValue>(\n value: NumberValue<TEmpty>,\n { emptyValue, precision, separators }: GetFormattedStringOptions<TEmpty>,\n formatNumber: FormatNumber = formatNumberDefault\n) {\n return typeof value === 'number' || emptyValue === 0\n ? formatNumber(\n (typeof value === 'number' ? value : emptyValue) as number,\n precision ?? 0,\n separators.thousand,\n separators.decimal\n )\n : '';\n}\n"],"names":["formatNumber","formatNumberDefault","getFormattedString","value","emptyValue","precision","separators","thousand","decimal"],"mappings":"AAAA,SAASA,gBAAgBC,mBAAmB,QAAQ,aAAa;AAiBjE,OAAO,SAASC,mBACZC,KAA0B,EAC1B,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,EAAqC,EACxEN,eAA6BC,mBAAmB;IAEhD,OAAO,OAAOE,UAAU,YAAYC,eAAe,IAC7CJ,aACK,OAAOG,UAAU,WAAWA,QAAQC,YACrCC,sBAAAA,uBAAAA,YAAa,GACbC,WAAWC,QAAQ,EACnBD,WAAWE,OAAO,IAEtB;AACV"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/number-input/index.ts"],"sourcesContent":["export * from './number-input';\n"],"names":[],"mappings":"AAAA,cAAc,iBAAiB"}
|