@inseefr/lunatic 3.4.18 → 3.4.20
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/components/Duration/Duration.js +3 -2
- package/components/Duration/Duration.js.map +1 -1
- package/components/Input/Input.js +6 -3
- package/components/Input/Input.js.map +1 -1
- package/components/Input/Input.spec.js +13 -0
- package/components/Input/Input.spec.js.map +1 -1
- package/components/Textarea/Textarea.js +4 -1
- package/components/Textarea/Textarea.js.map +1 -1
- package/components/Textarea/Textarea.spec.js +13 -0
- package/components/Textarea/Textarea.spec.js.map +1 -1
- package/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/components/shared/CharactersCount/CharactersCount.js +20 -0
- package/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js +28 -0
- package/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/components/shared/utils/getCharactersCountId.js +10 -0
- package/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/esm/components/Duration/Duration.js +3 -2
- package/esm/components/Duration/Duration.js.map +1 -1
- package/esm/components/Input/Input.js +6 -3
- package/esm/components/Input/Input.js.map +1 -1
- package/esm/components/Input/Input.spec.js +13 -0
- package/esm/components/Input/Input.spec.js.map +1 -1
- package/esm/components/Textarea/Textarea.js +4 -1
- package/esm/components/Textarea/Textarea.js.map +1 -1
- package/esm/components/Textarea/Textarea.spec.js +13 -0
- package/esm/components/Textarea/Textarea.spec.js.map +1 -1
- package/esm/components/shared/CharactersCount/CharactersCount.d.ts +7 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js +15 -0
- package/esm/components/shared/CharactersCount/CharactersCount.js.map +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.d.ts +1 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js +26 -0
- package/esm/components/shared/CharactersCount/CharactersCount.spec.js.map +1 -0
- package/esm/components/shared/utils/getCharactersCountId.d.ts +4 -0
- package/esm/components/shared/utils/getCharactersCountId.js +7 -0
- package/esm/components/shared/utils/getCharactersCountId.js.map +1 -0
- package/esm/main.css +10 -0
- package/esm/main.css.map +1 -1
- package/esm/use-lunatic/hooks/use-page-has-response.js +2 -1
- package/esm/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/esm/use-lunatic/props/propValue.js +1 -1
- package/esm/use-lunatic/props/propValue.js.map +1 -1
- package/main.css +10 -0
- package/main.css.map +1 -1
- package/package.json +24 -1
- package/src/components/Duration/Duration.test.tsx +52 -0
- package/src/components/Duration/Duration.tsx +17 -4
- package/src/components/Input/Input.spec.tsx +19 -0
- package/src/components/Input/Input.tsx +26 -18
- package/src/components/Input/__snapshots__/Input.spec.tsx.snap +27 -19
- package/src/components/RosterForLoop/__snapshots__/RosterForLoop.spec.tsx.snap +42 -20
- package/src/components/Textarea/Textarea.spec.tsx +18 -0
- package/src/components/Textarea/Textarea.tsx +21 -13
- package/src/components/Textarea/__snapshots__/Textarea.spec.tsx.snap +21 -11
- package/src/components/shared/CharactersCount/CharactersCount.spec.tsx +31 -0
- package/src/components/shared/CharactersCount/CharactersCount.tsx +27 -0
- package/src/components/shared/utils/getCharactersCountId.test.ts +14 -0
- package/src/components/shared/utils/getCharactersCountId.ts +6 -0
- package/src/css/components/Input.scss +10 -0
- package/src/use-lunatic/hooks/use-page-has-response.ts +1 -0
- package/src/use-lunatic/props/propValue.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/use-lunatic/hooks/use-page-has-response.js +2 -1
- package/use-lunatic/hooks/use-page-has-response.js.map +1 -1
- package/use-lunatic/props/propValue.js +1 -1
- package/use-lunatic/props/propValue.js.map +1 -1
|
@@ -5,12 +5,17 @@ exports[`Textarea > renders without crashing 1`] = `
|
|
|
5
5
|
<div
|
|
6
6
|
class="lunatic-textarea"
|
|
7
7
|
>
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
id="input"
|
|
8
|
+
<div
|
|
9
|
+
class="field-with-count"
|
|
11
10
|
>
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
<textarea
|
|
12
|
+
aria-invalid="false"
|
|
13
|
+
aria-labelledby="label-input"
|
|
14
|
+
id="input"
|
|
15
|
+
>
|
|
16
|
+
input
|
|
17
|
+
</textarea>
|
|
18
|
+
</div>
|
|
14
19
|
</div>
|
|
15
20
|
</div>
|
|
16
21
|
`;
|
|
@@ -20,13 +25,18 @@ exports[`Textarea > should handle readOnly 1`] = `
|
|
|
20
25
|
<div
|
|
21
26
|
class="lunatic-textarea"
|
|
22
27
|
>
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
id="textarea"
|
|
26
|
-
readonly=""
|
|
28
|
+
<div
|
|
29
|
+
class="field-with-count"
|
|
27
30
|
>
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
<textarea
|
|
32
|
+
aria-invalid="false"
|
|
33
|
+
aria-labelledby="label-textarea"
|
|
34
|
+
id="textarea"
|
|
35
|
+
readonly=""
|
|
36
|
+
>
|
|
37
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
|
38
|
+
</textarea>
|
|
39
|
+
</div>
|
|
30
40
|
</div>
|
|
31
41
|
</div>
|
|
32
42
|
`;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { CharactersCount } from './CharactersCount';
|
|
3
|
+
import { render } from '@testing-library/react';
|
|
4
|
+
|
|
5
|
+
describe('CharactersCount', () => {
|
|
6
|
+
const defaultProps = {
|
|
7
|
+
id: 'test-id',
|
|
8
|
+
maxLength: 20,
|
|
9
|
+
value: 'Hello',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
it('renders correctly characters count if there is a maximum length', () => {
|
|
13
|
+
const { getByText } = render(<CharactersCount {...defaultProps} />);
|
|
14
|
+
|
|
15
|
+
expect(getByText('5/20')).toBeInTheDocument();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should apply the max-length-reached class when limit is reached', () => {
|
|
19
|
+
const props = { ...defaultProps, maxLength: 5 };
|
|
20
|
+
const { getByText } = render(<CharactersCount {...props} />);
|
|
21
|
+
|
|
22
|
+
expect(getByText('5/5')).toHaveClass('max-length-reached');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should not render anything when maxLength is not provided', () => {
|
|
26
|
+
const props = { ...defaultProps, maxLength: undefined };
|
|
27
|
+
const { container } = render(<CharactersCount {...props} />);
|
|
28
|
+
|
|
29
|
+
expect(container.firstChild).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { getCharactersCountId } from '../utils/getCharactersCountId';
|
|
3
|
+
|
|
4
|
+
type Props = {
|
|
5
|
+
id: string;
|
|
6
|
+
maxLength?: number;
|
|
7
|
+
value?: string | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function CharactersCount({ id, maxLength, value }: Readonly<Props>) {
|
|
11
|
+
if (!maxLength) return null;
|
|
12
|
+
|
|
13
|
+
const currentLength = value?.length ?? 0;
|
|
14
|
+
const charactersCountId = getCharactersCountId(id, maxLength);
|
|
15
|
+
const hasReachedMaxLength = currentLength === maxLength;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<span
|
|
19
|
+
id={charactersCountId}
|
|
20
|
+
className={classNames('characters-count', {
|
|
21
|
+
'max-length-reached': hasReachedMaxLength,
|
|
22
|
+
})}
|
|
23
|
+
>
|
|
24
|
+
{`${currentLength}/${maxLength}`}
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getCharactersCountId } from './getCharactersCountId';
|
|
3
|
+
|
|
4
|
+
describe('getCharacterCountId', () => {
|
|
5
|
+
it('should return the correct ID when maxLength is provided', () => {
|
|
6
|
+
expect(getCharactersCountId('test-id', 100)).toBe(
|
|
7
|
+
'characters-count-test-id'
|
|
8
|
+
);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return undefined when maxLength is not provided', () => {
|
|
12
|
+
expect(getCharactersCountId('test-id')).toBeUndefined();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -77,6 +77,7 @@ function hasOneResponse(
|
|
|
77
77
|
|
|
78
78
|
// For rosterForLoop we need to inspect child components
|
|
79
79
|
if (
|
|
80
|
+
component.componentType === 'RosterForLoop' &&
|
|
80
81
|
'components' in component &&
|
|
81
82
|
Array.isArray(component.components) &&
|
|
82
83
|
!isSubComponentsEmpty(component.components, executeExpression)
|
|
@@ -28,7 +28,7 @@ export function getValueProp(
|
|
|
28
28
|
return args.variables.get(component.response.name, iteration);
|
|
29
29
|
}
|
|
30
30
|
// For loop, value will be a map of child component values
|
|
31
|
-
if ('
|
|
31
|
+
if (component.componentType === 'Loop') {
|
|
32
32
|
return getChildResponseValues(component.components, args.variables);
|
|
33
33
|
}
|
|
34
34
|
return null;
|