@delightui/components 0.1.122 → 0.1.123

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,4 +1,3 @@
1
- import React from 'react';
2
- import { ChipInputProps } from "./ChipInput.types";
3
- declare const _default: React.NamedExoticComponent<ChipInputProps>;
4
- export default _default;
1
+ import { ChipInputProps, OptionLike } from "./ChipInput.types";
2
+ declare const ChipInput: <T extends string[] | OptionLike[]>(props: ChipInputProps<T>) => import("react/jsx-runtime").JSX.Element;
3
+ export default ChipInput;
@@ -1,28 +1,14 @@
1
- import { ChipInputProps, ChipListItemProps } from './ChipInput.types';
2
- declare const usePresenter: (props: ChipInputProps) => {
1
+ import { ChipInputProps } from './ChipInput.types';
2
+ import { ChipProps } from '../../atoms/Chip/Chip.types';
3
+ import { OptionLike } from './ChipInput.types';
4
+ declare const usePresenter: <T extends string[] | OptionLike[]>(props: ChipInputProps<T>) => {
3
5
  handleChipInputAreaClick: () => void;
4
- chips: (ChipListItemProps | {
5
- type: string;
6
- props: {
7
- onKeyUp: (event: React.KeyboardEvent<HTMLInputElement>) => void;
8
- value: string;
9
- onValueChange: (value: string) => void;
10
- placeholder: string;
11
- className: string;
12
- disabled: boolean;
13
- id: string | undefined;
14
- };
15
- inputRef: import("react").RefObject<HTMLInputElement>;
16
- })[];
17
- optionList: {
18
- id: string;
19
- children: string;
20
- className: string;
21
- onValueChange: () => void;
22
- checked: boolean;
23
- value: boolean;
24
- labelAlignment: string;
25
- }[];
6
+ handleKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
7
+ inputValue: string;
8
+ onValueChange: (value: string) => void;
9
+ chips: ChipProps[];
10
+ inputRef: import("react").RefObject<HTMLInputElement>;
11
+ optionList: import("../..").CheckboxItemProps[];
26
12
  variantProps: {
27
13
  'component-variant': string;
28
14
  };
@@ -1,17 +1,129 @@
1
- import { RefObject } from 'react';
2
- import type { ChipProps, InputProps } from "../../atoms";
3
1
  import { ControlledFormComponentProps } from '../FormField/FormField.types';
4
- export type ChipListItemTypeEnum = 'chip' | 'input';
5
- export type ChipListItemProps = {
6
- type: ChipListItemTypeEnum;
7
- props: ChipProps | InputProps;
8
- inputRef?: RefObject<HTMLInputElement>;
2
+ /**
3
+ * Represents an option that can be selected in the ChipInput component.
4
+ * This is the normalized format used internally to handle both string arrays and object arrays.
5
+ */
6
+ export type OptionLike = {
7
+ /** Unique identifier for the option. Can be string or number. */
8
+ key: string | number;
9
+ /** Display text shown to the user for this option. */
10
+ label: string;
9
11
  };
10
- export type ChipInputProps = ControlledFormComponentProps<string[]> & {
12
+ /**
13
+ * Type alias for the key property of OptionLike.
14
+ * Used for type safety when working with selected values.
15
+ */
16
+ export type OptionLikeKey = OptionLike['key'];
17
+ /**
18
+ * Props for the ChipInput component.
19
+ *
20
+ * @template T - The type of the value array. Can be string[] or OptionLike[].
21
+ * This generic ensures type consistency between input and output.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * // String array usage
26
+ * const [fruits, setFruits] = useState<string[]>(['apple']);
27
+ * <ChipInput
28
+ * value={fruits}
29
+ * onValueChange={setFruits}
30
+ * options={['apple', 'banana', 'cherry']}
31
+ * />
32
+ *
33
+ * // OptionLike array usage
34
+ * const [items, setItems] = useState<OptionLike[]>([{key: 1, label: 'Apple'}]);
35
+ * <ChipInput
36
+ * value={items}
37
+ * onValueChange={setItems}
38
+ * options={[{key: 1, label: 'Apple'}, {key: 2, label: 'Banana'}]}
39
+ * />
40
+ * ```
41
+ */
42
+ export type ChipInputProps<T = string[] | OptionLike[]> = Omit<ControlledFormComponentProps<OptionLikeKey[]>, 'value' | 'onValueChange'> & {
43
+ /**
44
+ * Current selected values. Type matches the generic T parameter.
45
+ * For string arrays: ['apple', 'banana']
46
+ * For OptionLike arrays: [{key: 1, label: 'Apple'}, {key: 2, label: 'Banana'}]
47
+ */
48
+ value?: T;
49
+ /**
50
+ * Callback fired when the selected values change.
51
+ * Returns the same type as the input value for type consistency.
52
+ *
53
+ * @param value - The new array of selected values in the same format as input
54
+ */
55
+ onValueChange?: (value: T) => void;
56
+ /**
57
+ * Current value of the text input field.
58
+ * Used for controlled input behavior and filtering.
59
+ */
11
60
  inputValue?: string;
61
+ /**
62
+ * Callback fired when the input field value changes.
63
+ *
64
+ * @param value - The new input field value
65
+ */
12
66
  onInputChange?: (value: string) => void;
13
- options?: string[];
67
+ /**
68
+ * Available options for selection. Can be either:
69
+ * - string[]: Simple array of strings like ['apple', 'banana']
70
+ * - OptionLike[]: Array of objects like [{key: 1, label: 'Apple'}]
71
+ *
72
+ * Options are automatically filtered as the user types in the input field.
73
+ */
74
+ options?: string[] | OptionLike[];
75
+ /**
76
+ * Placeholder text shown in the input field when it's empty.
77
+ *
78
+ * @default undefined
79
+ */
14
80
  placeholder?: string;
81
+ /**
82
+ * Additional CSS class name applied to the root element.
83
+ */
15
84
  className?: string;
16
- onAddNewOption?: (value: string) => void;
85
+ /**
86
+ * Optional callback for creating new items when they don't exist in options.
87
+ * Can be synchronous or asynchronous for API integration.
88
+ *
89
+ * When this prop is provided:
90
+ * - Optimistic UI updates are applied immediately
91
+ * - If async, the UI shows loading states and handles errors
92
+ * - Failed operations are automatically reverted
93
+ *
94
+ * @param newItemValue - The text value entered by the user
95
+ * @returns Promise<OptionLike> for async operations, OptionLike for sync operations
96
+ *
97
+ * @example
98
+ * ```tsx
99
+ * // Sync operation
100
+ * onAddItem={(value) => ({ key: value, label: value })}
101
+ *
102
+ * // Async operation
103
+ * onAddItem={async (value) => {
104
+ * const newItem = await api.createItem(value);
105
+ * return { key: newItem.id, label: newItem.name };
106
+ * }}
107
+ * ```
108
+ */
109
+ onAddItem?: (newItemValue: string) => Promise<OptionLike> | OptionLike;
110
+ /**
111
+ * Optional callback for deleting items.
112
+ * Typically used for API integration to sync deletions with backend.
113
+ *
114
+ * When provided, this callback is called when a chip is removed.
115
+ * The component handles UI updates automatically.
116
+ *
117
+ * @param keyToDelete - The key of the item being deleted
118
+ * @returns Promise<void> for the deletion operation
119
+ *
120
+ * @example
121
+ * ```tsx
122
+ * onDeleteItem={async (key) => {
123
+ * await api.deleteItem(key);
124
+ * // Component automatically updates UI
125
+ * }}
126
+ * ```
127
+ */
128
+ onDeleteItem?: (keyToDelete: OptionLikeKey) => Promise<void>;
17
129
  };
@@ -1,2 +1,63 @@
1
- import React from 'react';
2
- export declare const onEnterKeyPreventFormSubmit: (onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>) => (e: React.KeyboardEvent<HTMLInputElement>) => void;
1
+ import { ChipProps } from '../../atoms/Chip/Chip.types';
2
+ import { CheckboxItemProps } from '../../atoms/CheckboxItem/CheckboxItem.types';
3
+ import { OptionLike, OptionLikeKey } from './ChipInput.types';
4
+ /**
5
+ * Normalizes string array or OptionLike array to OptionLike array
6
+ */
7
+ export declare const normalizeToOptionLike: (options: string[] | OptionLike[]) => OptionLike[];
8
+ /**
9
+ * Normalizes string array or OptionLike array to OptionLikeKey array
10
+ */
11
+ export declare const normalizeToOptionLikeKey: (options: string[] | OptionLike[]) => OptionLikeKey[];
12
+ /**
13
+ * Creates chip props for a selected value using OptionLike
14
+ */
15
+ export declare const createChipProps: (option: OptionLike, onRemove: (key: OptionLikeKey) => void, className?: string) => ChipProps;
16
+ /**
17
+ * Creates checkbox item props for context menu options using OptionLike
18
+ */
19
+ export declare const createCheckboxItemProps: (option: OptionLike, isChecked: boolean, onSelect: (key: OptionLikeKey) => void, className?: string) => CheckboxItemProps;
20
+ /**
21
+ * Toggles an option key in the selected keys array
22
+ */
23
+ export declare const toggleOptionInArray: (selectedKeys: OptionLikeKey[], optionKey: OptionLikeKey) => OptionLikeKey[];
24
+ /**
25
+ * Adds a new OptionLike to available options if it doesn't exist
26
+ */
27
+ export declare const addUniqueOption: (availableOptions: OptionLike[], newOption: OptionLike) => OptionLike[];
28
+ /**
29
+ * Handles Enter key press for adding new chips
30
+ */
31
+ export declare const handleEnterKeyForChip: (event: React.KeyboardEvent<HTMLInputElement>, inputValue: string, onAddChip: (value: string) => void, onClearInput: () => void) => void;
32
+ /**
33
+ * Finds an OptionLike by its key
34
+ */
35
+ export declare const findOptionByKey: (options: OptionLike[], key: OptionLikeKey) => OptionLike | undefined;
36
+ /**
37
+ * Converts OptionLikeKey array back to original format (string[] or OptionLike[])
38
+ */
39
+ export declare const convertKeysToOriginalFormat: <T extends string[] | OptionLike[]>(keys: OptionLikeKey[], originalValue: T | undefined, availableOptions: OptionLike[]) => T;
40
+ /**
41
+ * Filters options by input value for search functionality
42
+ */
43
+ export declare const filterOptionsByInput: (options: OptionLike[], inputValue: string) => OptionLike[];
44
+ /**
45
+ * Creates an optimistic item for async operations
46
+ */
47
+ export declare const createOptimisticItem: (value: string) => OptionLike;
48
+ /**
49
+ * Adds a key to selected keys array
50
+ */
51
+ export declare const addKeyToSelection: (selectedKeys: OptionLikeKey[], keyToAdd: OptionLikeKey) => OptionLikeKey[];
52
+ /**
53
+ * Removes a key from selected keys array
54
+ */
55
+ export declare const removeKeyFromSelection: (selectedKeys: OptionLikeKey[], keyToRemove: OptionLikeKey) => OptionLikeKey[];
56
+ /**
57
+ * Replaces a temporary key with a real key in selected keys array
58
+ */
59
+ export declare const replaceKeyInSelection: (selectedKeys: OptionLikeKey[], oldKey: OptionLikeKey, newKey: OptionLikeKey) => OptionLikeKey[];
60
+ /**
61
+ * Handles async add item operation with optimistic updates
62
+ */
63
+ export declare const handleAsyncAddItem: (inputValue: string, onAddItem: (value: string) => Promise<OptionLike>, currentOptions: OptionLike[], currentSelectedKeys: OptionLikeKey[], setOptions: (options: OptionLike[]) => void, setSelectedKeys: (keys: OptionLikeKey[]) => void) => Promise<void>;
@@ -3708,6 +3708,9 @@ span.flatpickr-weekday {
3708
3708
  }
3709
3709
 
3710
3710
  .ChipInput-module_chipInput__tCCgW .ChipInput-module_trigger__KLvR4 {
3711
+ display: flex;
3712
+ flex-wrap: wrap;
3713
+ align-items: center;
3711
3714
  padding-top: calc(var(--chip-input-padding-top) - var(--chip-input-border-top-width));
3712
3715
  padding-bottom: calc(var(--chip-input-padding-bottom) - var(--chip-input-border-bottom-width));
3713
3716
  padding-left: calc(var(--chip-input-padding-left) - var(--chip-input-border-left-width));