uikit-react-public 0.49.1 → 0.49.3

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.
@@ -24,6 +24,7 @@ const ConfidentialDisplayField = forwardRef<Ref, ConfidentialDisplayFieldProps>(
24
24
  value,
25
25
  numeric,
26
26
  maskFormat,
27
+ format,
27
28
  showable = false,
28
29
  testId = NAME,
29
30
  className,
@@ -45,7 +46,9 @@ const ConfidentialDisplayField = forwardRef<Ref, ConfidentialDisplayFieldProps>(
45
46
  const valueIsShown = showable && isShown;
46
47
  const displayedValue = valueIsShown
47
48
  ? stringValue
48
- : formatConfidentialValue(stringValue, maskFormat);
49
+ : formatConfidentialValue(stringValue, maskFormat, {
50
+ includeTemplateLiterals: !format,
51
+ });
49
52
 
50
53
  useEffect(() => {
51
54
  if (!showable) setIsShown(false);
@@ -68,6 +71,7 @@ const ConfidentialDisplayField = forwardRef<Ref, ConfidentialDisplayFieldProps>(
68
71
  {...props}
69
72
  ref={ref}
70
73
  value={displayedValue}
74
+ format={format}
71
75
  numeric={numeric ?? typeof value === 'number'}
72
76
  testId={testId}
73
77
  noMargins
@@ -76,7 +76,7 @@ describe('ConfidentialDisplayField', () => {
76
76
  const user = userEvent.setup();
77
77
  renderDisplayField({
78
78
  value: '123472',
79
- maskFormat: '****##',
79
+ maskFormat: '**-**-##',
80
80
  format: '##-##-##',
81
81
  showable: true,
82
82
  });
@@ -32,6 +32,7 @@ export const WithSeparators: Story = {
32
32
  'aria-label': 'Sort code',
33
33
  defaultValue: '123472',
34
34
  maskFormat: '**-**-##',
35
+ format: '##-##-##',
35
36
  showable: true,
36
37
  },
37
38
  };
@@ -125,7 +125,8 @@ const ConfidentialInput = forwardRef<Ref, ConfidentialInputProps>(
125
125
  value === undefined ? uncontrolledValue : getStringValue(value);
126
126
  const displayedMaskedValue = formatConfidentialValue(
127
127
  stringValue,
128
- maskFormat
128
+ maskFormat,
129
+ { includeTemplateLiterals: !format }
129
130
  );
130
131
  const configuredValueIsVisible =
131
132
  !isFocused &&
@@ -293,7 +293,7 @@ describe('ConfidentialInput', () => {
293
293
  const user = userEvent.setup();
294
294
  renderInput({
295
295
  value: '123472',
296
- maskFormat: '****##',
296
+ maskFormat: '**-**-##',
297
297
  format: '##-##-##',
298
298
  showable: true,
299
299
  onChange: () => {},
@@ -1,6 +1,14 @@
1
1
  export type MaskFormat = string | ((value: string) => string);
2
2
 
3
- const applyMaskTemplate = (value: string, template: string) => {
3
+ interface FormatConfidentialValueOptions {
4
+ includeTemplateLiterals?: boolean;
5
+ }
6
+
7
+ const applyMaskTemplate = (
8
+ value: string,
9
+ template: string,
10
+ includeTemplateLiterals: boolean
11
+ ) => {
4
12
  const valueCharacters = Array.from(value);
5
13
  let valueIndex = 0;
6
14
  let maskedValue = '';
@@ -14,7 +22,7 @@ const applyMaskTemplate = (value: string, template: string) => {
14
22
  } else if (templateCharacter === '*') {
15
23
  maskedValue += '*';
16
24
  valueIndex += 1;
17
- } else {
25
+ } else if (includeTemplateLiterals) {
18
26
  maskedValue += templateCharacter;
19
27
  }
20
28
  }
@@ -24,11 +32,15 @@ const applyMaskTemplate = (value: string, template: string) => {
24
32
  );
25
33
  };
26
34
 
27
- const formatConfidentialValue = (value: string, maskFormat: MaskFormat) => {
35
+ const formatConfidentialValue = (
36
+ value: string,
37
+ maskFormat: MaskFormat,
38
+ { includeTemplateLiterals = true }: FormatConfidentialValueOptions = {}
39
+ ) => {
28
40
  const maskedValue =
29
41
  typeof maskFormat === 'function'
30
42
  ? maskFormat(value)
31
- : applyMaskTemplate(value, maskFormat);
43
+ : applyMaskTemplate(value, maskFormat, includeTemplateLiterals);
32
44
 
33
45
  return maskedValue.split('*').join('•');
34
46
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "uikit-react-public",
3
3
  "private": false,
4
4
  "license": "UNLICENSED",
5
- "version": "0.49.1",
5
+ "version": "0.49.3",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",