sera-components 1.5.0 → 1.6.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.
@@ -1,9 +1,9 @@
1
- import { DataProperty, DataType, DB, ObjectProperty } from 'sera-db';
1
+ import { DataProperty, DataType, DB, ObjectProperty, NestedProperty } from 'sera-db';
2
2
  import { DateDisplay, DateTimeDisplay, DateTimeHideTimeDisplay } from './DateTimeDisplay';
3
3
  export { SingleForeignKeyDisplay, MultiForeignKeyDisplay } from './ForeignKeyDisplay';
4
4
  export type DisplayInterface<T> = {
5
5
  db: DB;
6
- property: DataProperty | ObjectProperty;
6
+ property: DataProperty | ObjectProperty | NestedProperty;
7
7
  value: T;
8
8
  };
9
9
  export declare const DataType2DisplayComponent: Partial<Record<DataType, React.ComponentType<DisplayInterface<any>>>>;
@@ -0,0 +1,72 @@
1
+ import { InputInterface } from '.';
2
+ import { DataProperty, ObjectProperty } from 'sera-db';
3
+ export interface ConfirmationLabelProps {
4
+ property: DataProperty | ObjectProperty;
5
+ }
6
+ /**
7
+ * A component that renders a confirmation label with "Confirm" prefix before the property label.
8
+ *
9
+ * This component displays a localized "Confirm" text followed by the property's multilingual label.
10
+ * Commonly used in forms where users need to confirm a value (e.g., "Confirm Password").
11
+ *
12
+ * @param props - The component props
13
+ * @param props.property - The data property or object property containing the label to display
14
+ *
15
+ * @returns A Text component showing "Confirm {property.label}" in the current locale
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * const passwordProperty = {
20
+ * name: "password",
21
+ * label: {
22
+ * lang: "en",
23
+ * lang2value: {
24
+ * en: "Password",
25
+ * vi: "Mật Khẩu"
26
+ * }
27
+ * }
28
+ * };
29
+ *
30
+ * <ConfirmationLabel property={passwordProperty} />
31
+ * // Renders: "Confirm Password" (in English)
32
+ * // Or: "Xác Nhận Mật Khẩu" (in Vietnamese)
33
+ * ```
34
+ */
35
+ export declare const ConfirmationLabel: ({ property }: ConfirmationLabelProps) => import("react/jsx-runtime").JSX.Element;
36
+ /**
37
+ * A confirmation input component that validates matching values against a target field.
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * // In a form field group with custom onChange to track validation state:
42
+ * const [passwordConfirmed, setPasswordConfirmed] = useState(false);
43
+ *
44
+ * {
45
+ * name: "Security Information",
46
+ * fields: [
47
+ * ["password"],
48
+ * [{
49
+ * prop: "password",
50
+ * args: {
51
+ * input: ConfirmationInput,
52
+ * onChange: (value) => {
53
+ * // Track validation state - onChange is called on every change
54
+ * // so you can lift the error state to the parent component
55
+ * setPasswordConfirmed(value === targetPassword);
56
+ * }
57
+ * }
58
+ * }]
59
+ * ]
60
+ * }
61
+ * ```
62
+ *
63
+ * The component:
64
+ * - Uses the `value` prop as the target value to match against
65
+ * - Maintains local state for the confirmation input value
66
+ * - Only shows "Values do not match" error after the field is touched
67
+ * - Calls `onChange` on every keystroke, allowing parent to lift validation errors
68
+ * - The parent can compare the confirmation value with the target to track validation state
69
+ * - Resets when the target value changes (e.g., when switching between records)
70
+ * - Delegates to the appropriate input component based on property constraints
71
+ */
72
+ export declare const ConfirmationInput: React.FC<InputInterface<string>>;
@@ -1,2 +1,4 @@
1
1
  import { InputInterface } from '.';
2
- export declare const EnumInput: React.FC<InputInterface<any>>;
2
+ type EnumValue = string | number;
3
+ export declare const EnumInput: React.FC<InputInterface<EnumValue | undefined>>;
4
+ export {};
@@ -1,16 +1,17 @@
1
- import { DataProperty, DataType, DB, ObjectProperty } from 'sera-db';
1
+ import { DataProperty, DataType, DB, ObjectProperty, NestedProperty } from 'sera-db';
2
2
  import { BooleanInput } from './BooleanInput';
3
3
  import { NumberInput } from './NumberInput';
4
4
  import { TextInput } from './TextInput';
5
5
  import { DateInput } from './DateInput';
6
6
  import { EnumInput } from './EnumInput';
7
+ import { ConfirmationInput, ConfirmationLabel } from './ConfirmationInput';
7
8
  export { SingleForeignKeyInput, MultiForeignKeyInput } from './ForeignKeyInput';
8
9
  export { DateRangeInput, DateTimeRangeInput } from './DateRangeInput';
9
10
  /**
10
11
  * Interface for input components in forms
11
12
  * @interface InputInterface
12
13
  * @template T - The type of the input value
13
- * @property {DataProperty | ObjectProperty} property - The property being edited
14
+ * @property {DataProperty | ObjectProperty | NestedProperty} property - The property being edited
14
15
  * @property {any} value - The current value of the input
15
16
  * @property {function} onChange - Callback function triggered when input value changes
16
17
  * @property {boolean | string} [error] - If the type is boolean it will be error, if there is a string message it should display that message
@@ -18,7 +19,7 @@ export { DateRangeInput, DateTimeRangeInput } from './DateRangeInput';
18
19
  */
19
20
  export type InputInterface<T> = {
20
21
  db: DB;
21
- property: DataProperty | ObjectProperty;
22
+ property: DataProperty | ObjectProperty | NestedProperty;
22
23
  value: T;
23
24
  onChange: (value: T) => void;
24
25
  error?: boolean | string;
@@ -28,4 +29,4 @@ export type InputInterface<T> = {
28
29
  * Mapping of data types to their corresponding input components
29
30
  */
30
31
  export declare const DataType2InputComponent: Partial<Record<DataType, React.FC<InputInterface<any>>>>;
31
- export { NumberInput, BooleanInput, TextInput, DateInput, EnumInput };
32
+ export { NumberInput, BooleanInput, TextInput, DateInput, EnumInput, ConfirmationInput, ConfirmationLabel };
@@ -1,24 +1,24 @@
1
- import { DraftRecord, GenericRecord, MultiLingualString, Schema, SchemaType, Table } from 'sera-db';
1
+ import { PropertyNames, DraftRecord, GenericRecord, Schema, SchemaType, Table, NestedProperty } from 'sera-db';
2
2
  import { InputInterface } from '../data/inputs';
3
3
  import { FormItemLayout } from './FormItem';
4
- export interface CustomField {
5
- name: string;
6
- label: MultiLingualString;
7
- description?: MultiLingualString;
8
- }
9
- interface FieldArgs<DR> {
4
+ interface FieldArgs<R, DR> {
5
+ label?: React.ReactNode;
10
6
  input?: React.ComponentType<InputInterface<any>>;
11
7
  freeze?: boolean;
12
- visible?: (record: DR) => boolean;
8
+ visible?: (record: R | DR) => boolean;
9
+ onChange?: (value: any) => void;
13
10
  }
14
- export interface FieldGroup<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends keyof R, F extends keyof DR, ST extends SchemaType<ID, R, DR, PF, F>> {
11
+ export interface FieldGroup<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends PropertyNames<R>, F extends PropertyNames<DR>, ST extends SchemaType<ID, R, DR, PF, F>> {
15
12
  name?: string;
16
13
  fields: (ST["allProperties"] | {
17
14
  prop: ST["allProperties"];
18
- args?: FieldArgs<DR>;
15
+ args?: FieldArgs<R, DR>;
16
+ } | NestedProperty | {
17
+ prop: NestedProperty;
18
+ args?: FieldArgs<R, DR>;
19
19
  } | ((store: Table<ID, R, DR>, record: R | DR) => React.ReactNode))[][];
20
20
  }
21
- export interface SeraFormProps<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends keyof R, F extends keyof DR, ST extends SchemaType<ID, R, DR, PF, F>> {
21
+ export interface SeraFormProps<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends PropertyNames<R>, F extends PropertyNames<DR>, ST extends SchemaType<ID, R, DR, PF, F>> {
22
22
  schema: Schema<ID, R, DR, PF, F, ST>;
23
23
  store: Table<ID, R, DR>;
24
24
  fieldGroups: FieldGroup<ID, R, DR, PF, F, ST>[];
@@ -67,5 +67,5 @@ export interface SeraFormProps<ID extends string | number, R extends GenericReco
67
67
  * />
68
68
  * ```
69
69
  */
70
- export declare const SeraForm: <ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends keyof R, F extends keyof DR, ST extends SchemaType<ID, R, DR, PF, F>>(props: SeraFormProps<ID, R, DR, PF, F, ST>) => import("react/jsx-runtime").JSX.Element;
70
+ export declare const SeraForm: <ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>, PF extends PropertyNames<R>, F extends PropertyNames<DR>, ST extends SchemaType<ID, R, DR, PF, F>>(props: SeraFormProps<ID, R, DR, PF, F, ST>) => import("react/jsx-runtime").JSX.Element;
71
71
  export {};
@@ -1,4 +1,4 @@
1
- import { DataProperty, DB, DraftRecord, GenericRecord, ObjectProperty, Table, validators } from 'sera-db';
1
+ import { DataProperty, DB, DraftRecord, GenericRecord, ObjectProperty, Table, NestedProperty } from 'sera-db';
2
2
  import { InputInterface } from '../data/inputs';
3
3
  export interface FormItemHorizontalLayout {
4
4
  type: "horizontal";
@@ -14,11 +14,13 @@ export type FormItemLayout = FormItemHorizontalLayout | FormItemVerticalLayout;
14
14
  export interface FormItemProps<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>> {
15
15
  store: Table<ID, R, DR>;
16
16
  record: R | DR;
17
- property: DataProperty | ObjectProperty;
17
+ property: DataProperty | ObjectProperty | NestedProperty;
18
18
  InputComponent: React.FC<InputInterface<any>> | React.ComponentType<InputInterface<any>>;
19
- validator: validators.ValueValidator;
20
19
  layout?: FormItemLayout;
21
20
  freeze?: boolean;
21
+ label?: React.ReactNode;
22
+ onChange?: (value: any) => void;
23
+ visible?: (record: R | DR) => boolean;
22
24
  }
23
25
  export declare const DEFAULT_LAYOUT: FormItemVerticalLayout;
24
26
  /**
@@ -27,18 +29,18 @@ export declare const DEFAULT_LAYOUT: FormItemVerticalLayout;
27
29
  * Supports both horizontal and vertical layouts. In horizontal layout, the label and input are placed side by side in a grid.
28
30
  * In vertical layout, the label is positioned above the input using Mantine's Input.Wrapper.
29
31
  */
30
- export declare const FormItem: (<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>>({ store, record, property, layout, InputComponent, validator, freeze, }: FormItemProps<ID, R, DR>) => import("react/jsx-runtime").JSX.Element) & {
32
+ export declare const FormItem: (<ID extends string | number, R extends GenericRecord<ID, DR>, DR extends DraftRecord<ID>>({ store, record, property, layout, InputComponent, freeze, label, onChange, visible, }: FormItemProps<ID, R, DR>) => import("react/jsx-runtime").JSX.Element) & {
31
33
  displayName: string;
32
34
  };
33
- export declare function FormItemInner({ db, layout, property, InputComponent, freeze, value, error, onChange, }: {
35
+ export declare function FormItemInner({ db, layout, property, InputComponent, freeze, value, error, label, onChange, }: {
34
36
  db: DB;
35
37
  layout: FormItemLayout;
36
- property: DataProperty | ObjectProperty;
38
+ property: DataProperty | ObjectProperty | NestedProperty;
37
39
  InputComponent: React.FC<InputInterface<any>> | React.ComponentType<InputInterface<any>>;
38
- validator: validators.ValueValidator;
39
40
  freeze: boolean;
40
41
  value: any;
41
42
  error: string | undefined;
43
+ label?: React.ReactNode;
42
44
  onChange: (value: any) => void;
43
45
  }): import("react/jsx-runtime").JSX.Element;
44
46
  export declare function isHorizontalLayout(layout: FormItemLayout): layout is FormItemHorizontalLayout;
@@ -1,4 +1,3 @@
1
1
  export * from './Form';
2
2
  export * from './FormItem';
3
3
  export * from './FormItemLabel';
4
- export * from './FormNestedPropertyItem';