@trackunit/react-form-components 1.11.18 → 1.11.19

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,8 +1,69 @@
1
1
  import { ReactElement } from "react";
2
2
  import { BaseOptionType, SelectFieldProps } from "./FormFieldSelectAdapter";
3
3
  /**
4
- * MultiSelect is a custom Select component wrapped in the FormGroup component
4
+ * SelectField is a dropdown select component wrapped in the FormGroup component for selecting a single option from a list.
5
5
  *
6
+ * ### When to use
7
+ * Use SelectField when users need to choose one option from a predefined list of 4 or more items.
8
+ *
9
+ * ### When not to use
10
+ * Do not use SelectField for fewer than 4 options. Use RadioGroup instead for better usability with small option sets.
11
+ *
12
+ * @example Basic select field
13
+ * ```tsx
14
+ * import { SelectField } from "@trackunit/react-form-components";
15
+ * import { useState } from "react";
16
+ *
17
+ * const options = [
18
+ * { value: "us", label: "United States" },
19
+ * { value: "uk", label: "United Kingdom" },
20
+ * { value: "de", label: "Germany" },
21
+ * { value: "fr", label: "France" },
22
+ * ];
23
+ *
24
+ * const MyForm = () => {
25
+ * const [country, setCountry] = useState<{ value: string; label: string } | null>(null);
26
+ *
27
+ * return (
28
+ * <SelectField
29
+ * label="Country"
30
+ * options={options}
31
+ * value={country}
32
+ * onChange={(option) => setCountry(option)}
33
+ * placeholder="Select a country"
34
+ * />
35
+ * );
36
+ * };
37
+ * ```
38
+ * @example Async select field with search
39
+ * ```tsx
40
+ * import { SelectField } from "@trackunit/react-form-components";
41
+ * import { useState } from "react";
42
+ *
43
+ * const MyAsyncForm = () => {
44
+ * const [selected, setSelected] = useState(null);
45
+ *
46
+ * const loadOptions = async (inputValue: string) => {
47
+ * const response = await fetch(`/api/users?search=${inputValue}`);
48
+ * const users = await response.json();
49
+ * return users.map((user: { id: string; name: string }) => ({
50
+ * value: user.id,
51
+ * label: user.name,
52
+ * }));
53
+ * };
54
+ *
55
+ * return (
56
+ * <SelectField
57
+ * label="Assign to user"
58
+ * isAsync
59
+ * loadOptions={loadOptions}
60
+ * value={selected}
61
+ * onChange={setSelected}
62
+ * isClearable
63
+ * />
64
+ * );
65
+ * };
66
+ * ```
6
67
  * @param {SelectFieldProps} props - The props for the SelectField component
7
68
  */
8
69
  export declare function SelectField<TOption extends BaseOptionType, TIsAsync extends boolean = false>({ ref, ...props }: SelectFieldProps<TOption, TIsAsync>): ReactElement;
@@ -19,12 +19,54 @@ export interface TextAreaFieldProps extends TextAreaBaseInputProps, FormGroupExp
19
19
  ref?: Ref<HTMLTextAreaElement>;
20
20
  }
21
21
  /**
22
- * Use a text area when you need to allow users to enter a large amount of text, such as a comment or a description.
22
+ * The `<TextAreaField>` component is used for multi-line text input.
23
+ * Use when you need to allow users to enter a large amount of text, such as comments or descriptions.
23
24
  *
24
- * _**Do use** Text areas for larger text inputs, such as comments or descriptions._
25
+ * ### When to use
26
+ * - Longer text inputs like comments, descriptions, or notes
27
+ * - When the expected input is more than one line
28
+ * - For free-form text that benefits from a larger input area
25
29
  *
26
- * _**Do not use** Text areas for small text inputs, such as single-line inputs._
30
+ * ### When not to use
31
+ * - Single-line inputs - use `TextField` instead
32
+ * - Structured data like email or phone - use specialized field components
33
+ * - Rich text editing - consider a rich text editor component
27
34
  *
35
+ * @example Basic usage
36
+ * ```tsx
37
+ * import { TextAreaField } from "@trackunit/react-form-components";
38
+ *
39
+ * const [description, setDescription] = useState("");
40
+ *
41
+ * <TextAreaField
42
+ * label="Description"
43
+ * value={description}
44
+ * onChange={(e) => setDescription(e.target.value)}
45
+ * placeholder="Enter a description..."
46
+ * />
47
+ * ```
48
+ * @example With character limit
49
+ * ```tsx
50
+ * import { TextAreaField } from "@trackunit/react-form-components";
51
+ *
52
+ * <TextAreaField
53
+ * label="Comment"
54
+ * maxLength={500}
55
+ * helpText="Add any additional notes"
56
+ * required
57
+ * />
58
+ * ```
59
+ * @example With validation error
60
+ * ```tsx
61
+ * import { TextAreaField } from "@trackunit/react-form-components";
62
+ *
63
+ * <TextAreaField
64
+ * label="Notes"
65
+ * value={notes}
66
+ * onChange={(e) => setNotes(e.target.value)}
67
+ * errorMessage={notes.length < 10 ? "Notes must be at least 10 characters" : undefined}
68
+ * />
69
+ * ```
28
70
  * @param {TextAreaFieldProps} props - The props for the TextAreaField component
29
71
  * @returns {ReactElement} TextAreaField component
30
72
  */
@@ -14,6 +14,61 @@ export interface TextFieldProps extends TextBaseInputProps, FormGroupExposedProp
14
14
  }
15
15
  /**
16
16
  * Text fields enable the user to interact with and input content and data. This component can be used for long and short form entries. Allow the size of the text input box to reflect the length of the content you expect the user to enter.
17
+ *
18
+ * ### When to use
19
+ * Use text fields for short-form text input such as names, emails, or search queries.
20
+ *
21
+ * ### When not to use
22
+ * Do not use text fields for multi-line text input. Use TextAreaField instead.
23
+ *
24
+ * @example Basic text field
25
+ * ```tsx
26
+ * import { TextField } from "@trackunit/react-form-components";
27
+ * import { useState } from "react";
28
+ *
29
+ * const MyForm = () => {
30
+ * const [name, setName] = useState("");
31
+ *
32
+ * return (
33
+ * <TextField
34
+ * label="Name"
35
+ * value={name}
36
+ * onChange={(e) => setName(e.target.value)}
37
+ * placeholder="Enter your name"
38
+ * />
39
+ * );
40
+ * };
41
+ * ```
42
+ * @example Text field with validation and help text
43
+ * ```tsx
44
+ * import { TextField } from "@trackunit/react-form-components";
45
+ * import { useState } from "react";
46
+ *
47
+ * const MyForm = () => {
48
+ * const [email, setEmail] = useState("");
49
+ * const [error, setError] = useState<string | undefined>();
50
+ *
51
+ * const handleBlur = () => {
52
+ * if (!email.includes("@")) {
53
+ * setError("Please enter a valid email address");
54
+ * } else {
55
+ * setError(undefined);
56
+ * }
57
+ * };
58
+ *
59
+ * return (
60
+ * <TextField
61
+ * label="Email"
62
+ * value={email}
63
+ * onChange={(e) => setEmail(e.target.value)}
64
+ * onBlur={handleBlur}
65
+ * errorMessage={error}
66
+ * helpText="We'll never share your email"
67
+ * required
68
+ * />
69
+ * );
70
+ * };
71
+ * ```
17
72
  */
18
73
  export declare const TextField: {
19
74
  ({ id, label, tip, helpText, helpAddon, errorMessage, isInvalid, maxLength, onChange, className, value, "data-testid": dataTestId, isWarning, ref, ...rest }: TextFieldProps): import("react/jsx-runtime").JSX.Element;
@@ -40,11 +40,55 @@ export interface ToggleSwitchProps extends CommonProps, MappedOmit<InputHTMLAttr
40
40
  preventDefaultOnClick?: boolean;
41
41
  }
42
42
  /**
43
- * A checkbox input wrapper with role="switch". Used as an input element for **ToggleSwitchOption**
44
- * or custom components.
43
+ * The `<ToggleSwitch>` is a low-level checkbox input wrapper with `role="switch"`.
44
+ * It renders just the switch control without label or description.
45
45
  *
46
- * Not intended for standalone use.
46
+ * **Not intended for standalone use** - use `ToggleSwitchOption` instead for forms.
47
+ * This component is for building custom toggle implementations or wrapping in other components.
47
48
  *
49
+ * ### When to use
50
+ * - Building custom toggle components with different layouts
51
+ * - Integrating a toggle into a component that provides its own label (e.g., menu items)
52
+ * - Creating specialized switch controls
53
+ *
54
+ * ### When not to use
55
+ * - Standard forms - use `ToggleSwitchOption` instead (includes label/description)
56
+ * - Multiple selections - use `Checkbox` components instead
57
+ *
58
+ * @example Basic usage (in custom component)
59
+ * ```tsx
60
+ * import { ToggleSwitch } from "@trackunit/react-form-components";
61
+ *
62
+ * const [isEnabled, setIsEnabled] = useState(false);
63
+ *
64
+ * <ToggleSwitch
65
+ * toggled={isEnabled}
66
+ * onChange={(toggled) => setIsEnabled(toggled)}
67
+ * />
68
+ * ```
69
+ * @example Inside a custom wrapper
70
+ * ```tsx
71
+ * import { ToggleSwitch } from "@trackunit/react-form-components";
72
+ *
73
+ * <div className="flex items-center gap-2">
74
+ * <span>Dark Mode</span>
75
+ * <ToggleSwitch
76
+ * toggled={darkMode}
77
+ * onChange={(toggled) => setDarkMode(toggled)}
78
+ * size="small"
79
+ * />
80
+ * </div>
81
+ * ```
82
+ * @example Disabled state
83
+ * ```tsx
84
+ * import { ToggleSwitch } from "@trackunit/react-form-components";
85
+ *
86
+ * <ToggleSwitch
87
+ * toggled={true}
88
+ * onChange={() => {}}
89
+ * disabled
90
+ * />
91
+ * ```
48
92
  * @param {ToggleSwitchProps} props - The props for the ToggleSwitch component
49
93
  * @returns {ReactElement} ToggleSwitch component
50
94
  */
@@ -15,13 +15,65 @@ export interface ToggleSwitchOptionProps extends ToggleSwitchProps {
15
15
  suffix?: ReactElement;
16
16
  }
17
17
  /**
18
- * Use ToggleSwitchOption when you have to only enable/disable a feature.
19
- * Wrapper component for ToggleSwitch.
18
+ * The `<ToggleSwitchOption>` component is used for binary on/off settings in forms.
19
+ * It combines a toggle switch with a label and optional description for complete form integration.
20
20
  *
21
- * _**Do use** ToggleSwitchOption in forms or settings._
21
+ * ### When to use
22
+ * - Enable/disable feature toggles in settings
23
+ * - Binary choices where the action takes effect immediately
24
+ * - Preferences that represent on/off states
22
25
  *
23
- * _**Do not use** ToggleSwitchOption if a user can select multiple options from a list, use checkboxes instead of toggle._
26
+ * ### When not to use
27
+ * - Multiple selections from a list - use `Checkbox` components instead
28
+ * - Mutually exclusive options - use `RadioGroup` instead
29
+ * - Actions requiring confirmation - use buttons with confirmation dialog
24
30
  *
31
+ * @example Basic usage
32
+ * ```tsx
33
+ * import { ToggleSwitchOption } from "@trackunit/react-form-components";
34
+ *
35
+ * const [notifications, setNotifications] = useState(true);
36
+ *
37
+ * <ToggleSwitchOption
38
+ * id="notifications"
39
+ * label="Enable Notifications"
40
+ * toggled={notifications}
41
+ * onChange={(toggled) => setNotifications(toggled)}
42
+ * />
43
+ * ```
44
+ * @example With description
45
+ * ```tsx
46
+ * import { ToggleSwitchOption } from "@trackunit/react-form-components";
47
+ *
48
+ * <ToggleSwitchOption
49
+ * id="email-alerts"
50
+ * label="Email Alerts"
51
+ * description="Receive email notifications for important updates"
52
+ * toggled={emailAlerts}
53
+ * onChange={(toggled) => setEmailAlerts(toggled)}
54
+ * />
55
+ * ```
56
+ * @example In a settings list
57
+ * ```tsx
58
+ * import { ToggleSwitchOption } from "@trackunit/react-form-components";
59
+ *
60
+ * <div className="space-y-4">
61
+ * <ToggleSwitchOption
62
+ * id="dark-mode"
63
+ * label="Dark Mode"
64
+ * description="Use dark theme throughout the application"
65
+ * toggled={darkMode}
66
+ * onChange={(toggled) => setDarkMode(toggled)}
67
+ * />
68
+ * <ToggleSwitchOption
69
+ * id="auto-save"
70
+ * label="Auto-save"
71
+ * description="Automatically save changes as you type"
72
+ * toggled={autoSave}
73
+ * onChange={(toggled) => setAutoSave(toggled)}
74
+ * />
75
+ * </div>
76
+ * ```
25
77
  * @param {ToggleSwitchOptionProps} props - The props for the ToggleSwitchOption component
26
78
  * @returns {ReactElement} ToggleSwitchOption component
27
79
  */
@@ -8,7 +8,53 @@ export interface UploadFieldProps extends UploadInputProps, FormGroupExposedProp
8
8
  errorMessage?: string;
9
9
  }
10
10
  /**
11
- * Upload fields enable the user to upload Files.
11
+ * The `<UploadField>` component enables users to upload files through a form field.
12
+ * It wraps the UploadInput with FormGroup for consistent form styling including label,
13
+ * help text, and error handling.
14
+ *
15
+ * ### When to use
16
+ * - Single file upload in forms (documents, images)
17
+ * - When you need form field styling (label, validation messages)
18
+ * - File attachments in form submissions
19
+ *
20
+ * ### When not to use
21
+ * - Drag and drop file uploads - use `DropZone` instead
22
+ * - Multiple file uploads with preview - consider specialized upload component
23
+ * - Large file uploads requiring progress indication
24
+ *
25
+ * @example Basic usage
26
+ * ```tsx
27
+ * import { UploadField } from "@trackunit/react-form-components";
28
+ *
29
+ * <UploadField
30
+ * label="Upload Document"
31
+ * accept=".pdf,.doc,.docx"
32
+ * onChange={(file) => handleFileUpload(file)}
33
+ * />
34
+ * ```
35
+ * @example With validation
36
+ * ```tsx
37
+ * import { UploadField } from "@trackunit/react-form-components";
38
+ *
39
+ * <UploadField
40
+ * label="Profile Picture"
41
+ * accept="image/*"
42
+ * helpText="Max file size: 5MB"
43
+ * errorMessage={fileTooLarge ? "File exceeds 5MB limit" : undefined}
44
+ * required
45
+ * />
46
+ * ```
47
+ * @example In a form context
48
+ * ```tsx
49
+ * import { UploadField } from "@trackunit/react-form-components";
50
+ *
51
+ * <UploadField
52
+ * label="Attachment"
53
+ * tip="Optional supporting document"
54
+ * accept=".pdf"
55
+ * onChange={(file) => setAttachment(file)}
56
+ * />
57
+ * ```
12
58
  */
13
59
  export declare const UploadField: {
14
60
  ({ label, id, tip, helpText, errorMessage, isInvalid, className, value, "data-testid": dataTestId, ref, ...rest }: UploadFieldProps): import("react/jsx-runtime").JSX.Element;
@@ -8,9 +8,53 @@ export interface UrlFieldProps extends FormGroupExposedProps, UrlBaseInputProps
8
8
  errorMessage?: string;
9
9
  }
10
10
  /**
11
- * The UrlField component is used to enter url.
12
- * UrlField validates that user enters a valid web address.
11
+ * The `<UrlField>` component is used to enter and validate URLs/web addresses.
12
+ * It automatically validates the format on blur and displays appropriate error messages.
13
13
  *
14
+ * ### When to use
15
+ * - Collecting website URLs in forms
16
+ * - Social media profile links
17
+ * - Any input requiring valid URL format
18
+ *
19
+ * ### When not to use
20
+ * - General text input - use `TextField` instead
21
+ * - Email addresses - use `EmailField` instead
22
+ * - Internal application links - use standard link/routing
23
+ *
24
+ * @example Basic usage
25
+ * ```tsx
26
+ * import { UrlField } from "@trackunit/react-form-components";
27
+ *
28
+ * const [website, setWebsite] = useState("");
29
+ *
30
+ * <UrlField
31
+ * label="Website"
32
+ * value={website}
33
+ * onChange={(e) => setWebsite(e.target.value)}
34
+ * placeholder="https://example.com"
35
+ * />
36
+ * ```
37
+ * @example With help text
38
+ * ```tsx
39
+ * import { UrlField } from "@trackunit/react-form-components";
40
+ *
41
+ * <UrlField
42
+ * label="Company Website"
43
+ * helpText="Enter the full URL including https://"
44
+ * required
45
+ * />
46
+ * ```
47
+ * @example With custom validation
48
+ * ```tsx
49
+ * import { UrlField } from "@trackunit/react-form-components";
50
+ *
51
+ * <UrlField
52
+ * label="Documentation URL"
53
+ * value={docUrl}
54
+ * onChange={(e) => setDocUrl(e.target.value)}
55
+ * errorMessage={!docUrl.includes("docs") ? "URL must point to documentation" : undefined}
56
+ * />
57
+ * ```
14
58
  */
15
59
  export declare const UrlField: {
16
60
  ({ label, id, tip, helpText, errorMessage, helpAddon, className, defaultValue, "data-testid": dataTestId, isInvalid, value, onBlur, ref, ...rest }: UrlFieldProps): import("react/jsx-runtime").JSX.Element;