@sillsdev/config-r 1.0.0-alpha.23 → 1.0.0-alpha.24

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/README.md CHANGED
@@ -39,5 +39,29 @@ Use [src/stories/bloom.stories.tsx](src/stories/bloom.stories.tsx) as the canoni
39
39
  - `ConfigrForEach` now uses a render signature of `(pathPrefix, index) => ReactNode`; build full Formik paths from the prefix (see the languages loop in the story).
40
40
  - `ConfigrSelect` options accept numbers or `{ label, value, description }` objects; descriptions become tooltips.
41
41
  - Override/locking behavior is standardized: most controls accept `overrideValue` + `overrideDescription`; `ConfigrBoolean` adds `locked` and `immediateEffect`.
42
- - `ConfigrInput` covers standard text, number, and email fields. Text inputs wrap visually by default; use the custom input variants only for genuinely custom editors whose UI is not just a styled text field.
43
- - `ConfigrPane` adds UI props like `showAppBar`, `showSearch`, `showJson`, `themeOverrides`, and `initiallySelectedTopLevelPageKey`.
42
+ - Leaf controls support `required` and `validation`. `validation` receives the current field value and may return `true`, `false`, or a string. `false` renders a generic `Invalid value` message, while a string is shown inline in red.
43
+ - Required fields show a `*` beside the control. The fallback `Required` message for empty required fields is controlled at the pane level with `showRequiredMessage` and defaults to `true`.
44
+ - `ConfigrInput` covers standard text, number, and email fields. It also supports `charactersWide`, `allowNewLines`, and `maxLines` for compact multiline text entry.
45
+ - `ConfigrPane` adds UI props like `showAppBar`, `showSearch`, `showJson`, `themeOverrides`, `initiallySelectedTopLevelPageKey`, and `localizations`.
46
+
47
+ ## Localization
48
+
49
+ To provide languages other than English for the small set of built-in strings, pass `localizations` to `ConfigrPane`:
50
+
51
+ ```tsx
52
+ <ConfigrPane
53
+ label="Configuracion"
54
+ initialValues={initialValues}
55
+ showSearch={true}
56
+ localizations={{
57
+ fieldRequiredMessage: 'Requiere un valor',
58
+ invalidValueMessage: 'Valor no valido',
59
+ searchLabel: 'Buscar',
60
+ matchesLabel: (count) => `${count} coincidencias`,
61
+ }}
62
+ >
63
+ {/* pages */}
64
+ </ConfigrPane>
65
+ ```
66
+
67
+ `searchLabel` is used for both the visible search placeholder and the input accessibility label.
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ export type ConfigrLocalizations = {
3
+ fieldRequiredMessage: string;
4
+ invalidValueMessage: string;
5
+ searchLabel: string;
6
+ matchesLabel: (count: number) => string;
7
+ };
8
+ export type ConfigrLocalizationOverrides = Partial<ConfigrLocalizations>;
9
+ export declare const defaultConfigrLocalizations: ConfigrLocalizations;
10
+ export declare const ConfigrLocalizationContext: React.Context<ConfigrLocalizations>;
@@ -1,4 +1,5 @@
1
1
  import { ThemeOptions } from '@mui/material';
2
+ import { ConfigrLocalizationOverrides } from './ConfigrLocalizations';
2
3
  import { ConfigrArea, ConfigrPage, ConfigrValues } from './ContentPane';
3
4
  import * as React from 'react';
4
5
  export declare const ConfigrPane: React.FunctionComponent<React.PropsWithChildren<{
@@ -11,6 +12,8 @@ export declare const ConfigrPane: React.FunctionComponent<React.PropsWithChildre
11
12
  showSearch?: boolean;
12
13
  themeOverrides?: ThemeOptions;
13
14
  showJson?: boolean;
15
+ showRequiredMessage?: boolean;
16
+ localizations?: ConfigrLocalizationOverrides;
14
17
  className?: string;
15
18
  initiallySelectedTopLevelPageKey?: string;
16
19
  }>>;
@@ -1,5 +1,6 @@
1
1
  import { SerializedStyles } from '@emotion/react';
2
2
  import { ReactNode } from 'react';
3
+ import { ConfigrErrorMessageGetter, ConfigrValidation } from './validation';
3
4
  import * as React from 'react';
4
5
  export type ConfigrValues = Record<string, unknown>;
5
6
  type valueGetter = () => ConfigrValues;
@@ -12,6 +13,7 @@ export declare const ConfigrArea: React.FunctionComponent<React.PropsWithChildre
12
13
  export declare const ContentPane: React.FunctionComponent<React.PropsWithChildren<{
13
14
  initialValues: ConfigrValues;
14
15
  currentTopLevelPageIndex?: number;
16
+ showRequiredMessage?: boolean;
15
17
  children: React.ReactElement<React.ComponentProps<typeof ConfigrPage>> | React.ReactElement<React.ComponentProps<typeof ConfigrPage>>[];
16
18
  setValueGetter?: (vg: valueGetter) => void;
17
19
  /** Called with the latest values as a plain object (not a JSON string). */
@@ -27,6 +29,9 @@ interface IConfigrProps<T> {
27
29
  label: string;
28
30
  description?: string;
29
31
  disabled?: boolean;
32
+ required?: boolean;
33
+ validation?: ConfigrValidation<T>;
34
+ getErrorMessage?: ConfigrErrorMessageGetter;
30
35
  overrideValue?: T;
31
36
  overrideDescription?: string;
32
37
  pageKey?: string;
@@ -35,7 +40,10 @@ export declare const ConfigrInput: React.FunctionComponent<React.PropsWithChildr
35
40
  className?: string;
36
41
  type?: 'text' | 'number' | 'email';
37
42
  units?: string;
38
- getErrorMessage?: (data: any) => string | undefined;
43
+ charactersWide?: number;
44
+ allowNewLines?: boolean;
45
+ maxLines?: number;
46
+ getErrorMessage?: ConfigrErrorMessageGetter;
39
47
  }>>;
40
48
  interface ICustomStringInputProps extends IConfigrProps<string> {
41
49
  control: React.FunctionComponent<{
@@ -43,12 +51,12 @@ interface ICustomStringInputProps extends IConfigrProps<string> {
43
51
  disabled?: boolean;
44
52
  onChange: (value: string) => void;
45
53
  }>;
46
- getErrorMessage?: (data: any) => string | undefined;
54
+ getErrorMessage?: ConfigrErrorMessageGetter;
47
55
  }
48
56
  export declare const ConfigrCustomStringInput: React.FunctionComponent<React.PropsWithChildren<ICustomStringInputProps>>;
49
57
  interface ICustomBooleanInputProps extends IConfigrProps<boolean> {
50
58
  control: BooleanEditorComponent;
51
- getErrorMessage?: (data: any) => string | undefined;
59
+ getErrorMessage?: ConfigrErrorMessageGetter;
52
60
  }
53
61
  export declare const ConfigrCustomBooleanInput: React.FunctionComponent<React.PropsWithChildren<ICustomBooleanInputProps>>;
54
62
  interface ICustomNumberInputProps extends IConfigrProps<number> {
@@ -57,7 +65,7 @@ interface ICustomNumberInputProps extends IConfigrProps<number> {
57
65
  disabled?: boolean;
58
66
  onChange: (value: number) => void;
59
67
  }>>;
60
- getErrorMessage?: (data: any) => string | undefined;
68
+ getErrorMessage?: ConfigrErrorMessageGetter;
61
69
  }
62
70
  export declare const ConfigrCustomNumberInput: React.FunctionComponent<React.PropsWithChildren<ICustomNumberInputProps>>;
63
71
  interface ICustomObjectInputProps<T> extends IConfigrProps<unknown> {
@@ -66,7 +74,7 @@ interface ICustomObjectInputProps<T> extends IConfigrProps<unknown> {
66
74
  disabled?: boolean;
67
75
  onChange: (value: T) => void;
68
76
  }>>;
69
- getErrorMessage?: (data: any) => string | undefined;
77
+ getErrorMessage?: ConfigrErrorMessageGetter;
70
78
  }
71
79
  export declare function ConfigrCustomObjectInput<T>(props: React.PropsWithChildren<ICustomObjectInputProps<T>>): import("@emotion/react/jsx-runtime").JSX.Element;
72
80
  interface ISelectProps extends IConfigrProps<string> {
@@ -77,7 +85,7 @@ interface ISelectProps extends IConfigrProps<string> {
77
85
  description?: string;
78
86
  } | number>;
79
87
  enableWhen?: string | ((currentValues: object) => boolean);
80
- getErrorMessage?: (data: any) => string | undefined;
88
+ getErrorMessage?: ConfigrErrorMessageGetter;
81
89
  }
82
90
  export declare const ConfigrSelect: React.FunctionComponent<React.PropsWithChildren<ISelectProps>>;
83
91
  export declare const ConfigrStatic: React.FunctionComponent<React.PropsWithChildren<{}>>;
@@ -85,7 +93,7 @@ export declare const ConfigrGroup: React.FunctionComponent<React.PropsWithChildr
85
93
  label?: string;
86
94
  searchTerms?: string;
87
95
  description?: string | React.ReactNode;
88
- getErrorMessage?: (data: any) => string | undefined;
96
+ getErrorMessage?: ConfigrErrorMessageGetter;
89
97
  inFocussedPage?: boolean;
90
98
  }>>;
91
99
  export type PageChild = React.ReactElement<typeof ConfigrGroup> | false | undefined | null;
@@ -95,7 +103,7 @@ export declare const ConfigrPage: React.FunctionComponent<React.PropsWithChildre
95
103
  pageKey: string;
96
104
  searchTerms?: string;
97
105
  topLevel?: boolean;
98
- getErrorMessage?: (data: any) => string | undefined;
106
+ getErrorMessage?: ConfigrErrorMessageGetter;
99
107
  inFocussedPage?: boolean;
100
108
  disabled?: boolean;
101
109
  children: PageChild | PageChild[];
@@ -105,7 +113,7 @@ export declare const ConfigrForEach: React.FunctionComponent<React.PropsWithChil
105
113
  searchTerms: string;
106
114
  inFocussedPage?: boolean;
107
115
  render: (pathPrefix: string, index: number) => React.ReactNode;
108
- getErrorMessage?: (data: any) => string | undefined;
116
+ getErrorMessage?: ConfigrErrorMessageGetter;
109
117
  }>>;
110
118
  export declare const ConfigrBoolean: React.FunctionComponent<React.PropsWithChildren<IConfigrProps<boolean> & {
111
119
  immediateEffect?: boolean;