@trackunit/custom-field-components 0.0.1-alpha-59a0a75488.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.
@@ -0,0 +1,75 @@
1
+ import { CheckboxProps } from "@trackunit/react-components";
2
+ import * as React from "react";
3
+ import { FieldValues, UseFormRegister, UseFormSetValue } from "react-hook-form";
4
+ import { ValidationRules } from "./getValidationRules";
5
+ import { FormGroupExposedProps } from "./types";
6
+ export interface BooleanCustomFieldProps extends Omit<CheckboxProps, "value" | "defaultValue" | "label">, FormGroupExposedProps {
7
+ /**
8
+ * A id for the field
9
+ *
10
+ * @memberof BooleanCustomFieldProps
11
+ *
12
+ */
13
+ id: string;
14
+ /**
15
+ * A value to be displayed by a input field
16
+ *
17
+ * @memberof BooleanCustomFieldProps
18
+ */
19
+ description?: string;
20
+ /**
21
+ * A text to be displayed under the input with a short description of field purpose
22
+ *
23
+ * @memberof BooleanCustomFieldProps
24
+ */
25
+ value?: boolean;
26
+ /**
27
+ * A default value to be displayed by a input field
28
+ *
29
+ * @memberof BooleanCustomFieldProps
30
+ */
31
+ defaultValue?: boolean;
32
+ /**
33
+ * A id that can be used in tests to get the component
34
+ *
35
+ * @memberof BooleanCustomFieldProps
36
+ */
37
+ dataTestId?: string;
38
+ /**
39
+ * A custom handler for onChange event
40
+ *
41
+ * @memberof BooleanCustomFieldProps
42
+ */
43
+ onChange?: (event: React.SyntheticEvent<HTMLInputElement>) => void;
44
+ /**
45
+ * A flag that can be used to disable the input, default value is false
46
+ *
47
+ * @memberof BooleanCustomFieldProps
48
+ */
49
+ disabled?: boolean;
50
+ /**
51
+ * Used for field validation by React Hook Form library it dynamically set the value of a registered field and have the options to validate and update the form state. At the same time, it tries to avoid unnecessary rerender.
52
+ *
53
+ * @memberof BooleanCustomFieldProps
54
+ */
55
+ setValue?: UseFormSetValue<FieldValues>;
56
+ /**
57
+ * This method allows you to register an input or select element and apply validation rules to React Hook Form. Validation rules are all based on the HTML standard and also allow for custom validation methods.
58
+ *
59
+ * @memberof BooleanCustomFieldProps
60
+ */
61
+ register?: UseFormRegister<FieldValues>;
62
+ /**
63
+ * Validation rules that can be passed to the field, they can be pass along with error messages. Rules are described here https://react-hook-form.com/api/useform/register
64
+ *
65
+ * @memberof BooleanCustomFieldProps
66
+ */
67
+ validationRules?: ValidationRules;
68
+ /**
69
+ * If a value is set, the field is rendered in its invalid state.
70
+ *
71
+ * @memberof BooleanCustomFieldProps
72
+ */
73
+ errorMessage?: string;
74
+ }
75
+ export declare const BooleanCustomField: ({ defaultValue, dataTestId, onChange, value, id, setValue, register, validationRules, disabled, label, tip, isInvalid, errorMessage, helpAddon, maxLength, helpText, ...rest }: BooleanCustomFieldProps) => JSX.Element;
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { ComponentMeta } from "@storybook/react";
3
+ declare const _default: ComponentMeta<({ defaultValue, dataTestId, onChange, value, id, setValue, register, validationRules, disabled, label, tip, isInvalid, errorMessage, helpAddon, maxLength, helpText, ...rest }: import("./BooleanCustomField").BooleanCustomFieldProps) => JSX.Element>;
4
+ export default _default;
5
+ export declare const Playground: ({ id, label, color, defaultValue, value, dataTestId, disabled, description, ...props }: {
6
+ [x: string]: any;
7
+ id: any;
8
+ label: any;
9
+ color: any;
10
+ defaultValue: any;
11
+ value: any;
12
+ dataTestId: any;
13
+ disabled: any;
14
+ description: any;
15
+ }) => JSX.Element;
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { AbstractValueAndDefinition } from "@trackunit/iris-app-runtime-core";
3
+ import { ValueAndDefinition } from "@trackunit/iris-app-runtime-core-api";
4
+ import { FieldValues, FormState, UseFormRegister, UseFormSetValue } from "react-hook-form";
5
+ import { UnitPreference } from "./UnitPreference";
6
+ interface ICustomFieldProps {
7
+ field: AbstractValueAndDefinition;
8
+ register: UseFormRegister<FieldValues>;
9
+ formState: FormState<FieldValues>;
10
+ setValue: UseFormSetValue<FieldValues>;
11
+ unitPreference?: UnitPreference;
12
+ /**
13
+ * An optional Id to override the definition.key
14
+ */
15
+ fieldId?: string;
16
+ }
17
+ export interface ICustomFieldValidation {
18
+ register: UseFormRegister<FieldValues>;
19
+ setValue: UseFormSetValue<FieldValues>;
20
+ formState: FormState<FieldValues>;
21
+ }
22
+ export declare const useCustomFieldResolver: (field: ValueAndDefinition, validation: ICustomFieldValidation, unitPreference?: UnitPreference, fieldId?: string) => JSX.Element | null;
23
+ export declare const CustomField: ({ field, register, formState, setValue, unitPreference, fieldId }: ICustomFieldProps) => JSX.Element | null;
24
+ export {};
@@ -0,0 +1,44 @@
1
+ /// <reference types="react" />
2
+ import { DateFieldProps } from "@trackunit/react-components";
3
+ import { FieldValues, RegisterOptions, UseFormRegister, UseFormSetValue } from "react-hook-form";
4
+ import { FormGroupExposedProps } from "./types";
5
+ export interface DateCustomFieldProps extends Omit<DateFieldProps, "label">, FormGroupExposedProps {
6
+ /**
7
+ * A id for the field
8
+ *
9
+ * @memberof DateCustomFieldProps
10
+ */
11
+ id: string;
12
+ /**
13
+ * Used for field validation by React Hook Form library it dynamically set the value of a registered field and have the options to validate and update the form state. At the same time, it tries to avoid unnecessary rerender.
14
+ *
15
+ * @memberof DateCustomFieldProps
16
+ */
17
+ setValue?: UseFormSetValue<FieldValues>;
18
+ /**
19
+ * This method allows you to register an input or select element and apply validation rules to React Hook Form. Validation rules are all based on the HTML standard and also allow for custom validation methods.
20
+ *
21
+ * @memberof DateCustomFieldProps
22
+ */
23
+ register?: UseFormRegister<FieldValues>;
24
+ /**
25
+ * Validation rules that can be passed to the field, they can be pass along with error messages. Rules are described here https://react-hook-form.com/api/useform/register
26
+ *
27
+ * @memberof DateCustomFieldProps
28
+ */
29
+ validationRules?: RegisterOptions;
30
+ /**
31
+ * If a value is set, the field is rendered in its invalid state.
32
+ *
33
+ * @memberof DateCustomFieldProps
34
+ */
35
+ errorMessage?: string;
36
+ /**
37
+ * A boolean flag to set a component into invalid state
38
+ * which means that selected value is breaking validation rules
39
+ *
40
+ * @memberof DateCustomFieldProps
41
+ */
42
+ isInvalid?: boolean;
43
+ }
44
+ export declare const DateCustomField: (props: DateCustomFieldProps) => JSX.Element;
@@ -0,0 +1,94 @@
1
+ import * as React from "react";
2
+ import { FieldValues, RegisterOptions, UseFormRegister, UseFormSetValue } from "react-hook-form";
3
+ import { FormGroupExposedProps } from "./types";
4
+ export interface DropdownCustomFieldProps extends FormGroupExposedProps {
5
+ /**
6
+ * A id for the field
7
+ *
8
+ * @memberof DropdownCustomFieldProps
9
+ */
10
+ id: string;
11
+ /**
12
+ * A text to be displayed under the input with a short description of field purpose
13
+ *
14
+ * @memberof DropdownCustomFieldProps
15
+ */
16
+ description?: string;
17
+ /**
18
+ * A default value to be displayed by a input field
19
+ *
20
+ * @memberof DropdownCustomFieldProps
21
+ */
22
+ defaultValue?: string[];
23
+ /**
24
+ * A id that can be used in tests to get the component
25
+ *
26
+ * @memberof DropdownCustomFieldProps
27
+ */
28
+ dataTestId?: string;
29
+ /**
30
+ * A custom handler for onChange event
31
+ *
32
+ * @memberof DropdownCustomFieldProps
33
+ */
34
+ onChange?: OnChange;
35
+ /**
36
+ * A flag that can be used to disable the dropdown, default value is false
37
+ *
38
+ * @memberof DropdownCustomFieldProps
39
+ */
40
+ disabled?: boolean;
41
+ /**
42
+ * A flag that can be used to enable multiselect mode, default value is false
43
+ *
44
+ * @memberof DropdownCustomFieldProps
45
+ */
46
+ multiSelect?: boolean;
47
+ /**
48
+ * An array of values to select for
49
+ *
50
+ * @memberof DropdownCustomFieldProps
51
+ */
52
+ allValues: string[] | undefined;
53
+ /**
54
+ * Used for field validation by React Hook Form library it dynamically set the value of a registered field and have the options to validate and update the form state. At the same time, it tries to avoid unnecessary rerender.
55
+ *
56
+ * @memberof DropdownCustomFieldProps
57
+ */
58
+ setValue?: UseFormSetValue<FieldValues>;
59
+ /**
60
+ * This method allows you to register an input or select element and apply validation rules to React Hook Form. Validation rules are all based on the HTML standard and also allow for custom validation methods.
61
+ *
62
+ * @memberof DropdownCustomFieldProps
63
+ */
64
+ register?: UseFormRegister<FieldValues>;
65
+ /**
66
+ * Validation rules that can be passed to the field, they can be pass along with error messages. Rules are described here https://react-hook-form.com/api/useform/register
67
+ *
68
+ * @memberof DropdownCustomFieldProps
69
+ */
70
+ validationRules?: RegisterOptions;
71
+ /**
72
+ * A custom handler for the onBlur event
73
+ *
74
+ * @memberof DropdownCustomFieldProps
75
+ */
76
+ onBlur?: OnBlur;
77
+ /**
78
+ * If a value is set, the field is rendered in its invalid state.
79
+ *
80
+ * @memberof DropdownCustomFieldProps
81
+ */
82
+ errorMessage?: string;
83
+ /**
84
+ * A boolean flag to set a component into invalid state
85
+ * which means that selected value is breaking validation rules
86
+ *
87
+ * @memberof DropdownCustomFieldProps
88
+ */
89
+ isInvalid?: boolean;
90
+ }
91
+ declare type OnChange = (event?: React.ChangeEvent<HTMLInputElement>) => void;
92
+ declare type OnBlur = (event: React.FocusEvent<HTMLDivElement>) => void;
93
+ export declare const DropdownCustomField: ({ defaultValue, dataTestId, onChange, onBlur, id, disabled, allValues, multiSelect, register, validationRules, setValue, label, tip, errorMessage, helpText, isInvalid, helpAddon, }: DropdownCustomFieldProps) => JSX.Element;
94
+ export {};
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { ComponentMeta } from "@storybook/react";
3
+ declare const _default: ComponentMeta<({ defaultValue, dataTestId, onChange, onBlur, id, disabled, allValues, multiSelect, register, validationRules, setValue, label, tip, errorMessage, helpText, isInvalid, helpAddon, }: import("./DropdownCustomField").DropdownCustomFieldProps) => JSX.Element>;
4
+ export default _default;
5
+ export declare const Playground: ({ id, label, color, defaultValue, dataTestId, disabled, description, multiSelect, ...props }: {
6
+ [x: string]: any;
7
+ id: any;
8
+ label: any;
9
+ color: any;
10
+ defaultValue: any;
11
+ dataTestId: any;
12
+ disabled: any;
13
+ description: any;
14
+ multiSelect: any;
15
+ }) => JSX.Element;
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ > **⚠️ Beta**
2
+ >
3
+ > This is a beta version and subject to change without notice.
4
+
5
+ # Trackunit Custom Field Components
6
+
7
+ The `@trackunit/custom-field-components` package contains UI components specifically for use with Custom Fields within [the Trackunit Manager platform](https://www.trackunit.com/services/manager/) and [`@trackunit/iris-app`](https://www.npmjs.com/package/@trackunit/iris-app).
8
+
9
+
10
+ To browse all avaliable components visit our [Public Storybook](https://developers.trackunit.com/page/ui-components).
11
+
12
+ For more info and a full guide on Iris App SDK Development, please visit our [Developer Hub](https://developers.trackunit.com/).
13
+
14
+ ## Trackunit
15
+ This package was developed by Trackunit ApS.
16
+ Trackunit is the leading SaaS-based IoT solution for the construction industry, offering an ecosystem of hardware, fleet management software & telematics.
17
+
18
+ ![The Trackunit logo](https://trackunit.com/wp-content/uploads/2022/03/top-logo.svg)
@@ -0,0 +1 @@
1
+ export declare type UnitPreference = "SI" | "US_CUSTOMARY";
@@ -0,0 +1,11 @@
1
+ import { BooleanFieldDefinition, DateFieldDefinition, DropDownFieldDefinition, EmailFieldDefinition, NumberFieldDefinition, PhoneNumberFieldDefinition, StringFieldDefinition, WebAddressFieldDefinition } from "@trackunit/iris-app-runtime-core-api";
2
+ import { RegisterOptions } from "react-hook-form";
3
+ export declare type ValidationRules = RegisterOptions;
4
+ export declare const getWebAddressValidationRules: (definition: WebAddressFieldDefinition) => ValidationRules;
5
+ export declare const getNumberValidationRules: (definition: NumberFieldDefinition) => ValidationRules;
6
+ export declare const getStringValidationRules: (definition: StringFieldDefinition) => ValidationRules;
7
+ export declare const getBooleanValidationRules: (definition: BooleanFieldDefinition) => ValidationRules;
8
+ export declare const getDropdownValidationRules: (definition: DropDownFieldDefinition) => ValidationRules;
9
+ export declare const getDateValidationRules: (definition: DateFieldDefinition) => ValidationRules;
10
+ export declare const getEmailValidationRules: (definition: EmailFieldDefinition) => ValidationRules;
11
+ export declare const getPhoneNumberValidationRules: (definition: PhoneNumberFieldDefinition) => ValidationRules;
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./CustomField";
2
+ export * from "./UnitPreference";