@arquimedes.co/eureka-forms 3.0.60-test → 3.0.61
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/dist/App/App.stories.d.ts +10 -0
- package/dist/App/App.stories.js +189 -0
- package/dist/Form/Form.js +7 -6
- package/dist/Form/FormFunctions.d.ts +17 -0
- package/dist/Form/FormFunctions.js +22 -0
- package/dist/Form/FormFunctions.test.js +28 -1
- package/dist/FormSteps/CheckBoxStep/CheckBoxStep.mobileLabel.test.js +17 -9
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +6 -13
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.module.css +0 -11
- package/package.json +1 -1
|
@@ -28,3 +28,13 @@ export declare const ParseadoConValores: Story;
|
|
|
28
28
|
export declare const PreParseado: Story;
|
|
29
29
|
/** Final view (postview): what the user submitted, rendered read-only. */
|
|
30
30
|
export declare const Postview: Story;
|
|
31
|
+
/**
|
|
32
|
+
* Every checkbox variant in one form: sizes 1–4, required, description, list mode, long
|
|
33
|
+
* labels, nested `steps` / `uncheckedSteps`, and a checkbox inside a collapsible. Resize the
|
|
34
|
+
* preview below ~900px to see the collapsed label mode (100% width, 2-line clamp, "ver más").
|
|
35
|
+
* Inside the collapsible, close/reopen it and then check the checkbox to reproduce the clipped
|
|
36
|
+
* nested steps.
|
|
37
|
+
*/
|
|
38
|
+
export declare const Checkboxes: Story;
|
|
39
|
+
/** Same checkboxes form in postview, read-only. */
|
|
40
|
+
export declare const CheckboxesPostview: Story;
|
package/dist/App/App.stories.js
CHANGED
|
@@ -296,3 +296,192 @@ export const Postview = {
|
|
|
296
296
|
editable: false,
|
|
297
297
|
},
|
|
298
298
|
};
|
|
299
|
+
// ---------------------------------------------------------------------------------------------
|
|
300
|
+
// Checkboxes: a full form exercising every checkbox variant side by side (sizes, required,
|
|
301
|
+
// description, list mode, long label, nested steps, uncheckedSteps and a checkbox inside a
|
|
302
|
+
// collapsible). Resize the preview to see the collapsed (100% width, 2-line clamp) label mode.
|
|
303
|
+
// ---------------------------------------------------------------------------------------------
|
|
304
|
+
const cbTextInput = (id, label, size = 2) => ({
|
|
305
|
+
id,
|
|
306
|
+
type: 'TEXTINPUT',
|
|
307
|
+
label,
|
|
308
|
+
description: '',
|
|
309
|
+
required: false,
|
|
310
|
+
size,
|
|
311
|
+
isSubject: false,
|
|
312
|
+
});
|
|
313
|
+
const checkboxesForm = {
|
|
314
|
+
steps: {
|
|
315
|
+
'CHECKBOX-size-1': {
|
|
316
|
+
id: 'CHECKBOX-size-1',
|
|
317
|
+
type: 'CHECKBOX',
|
|
318
|
+
label: 'Tamaño 1',
|
|
319
|
+
description: null,
|
|
320
|
+
required: false,
|
|
321
|
+
size: 1,
|
|
322
|
+
},
|
|
323
|
+
'CHECKBOX-size-2': {
|
|
324
|
+
id: 'CHECKBOX-size-2',
|
|
325
|
+
type: 'CHECKBOX',
|
|
326
|
+
label: 'Tamaño 2 con descripción',
|
|
327
|
+
description: 'Texto de ayuda debajo del checkbox.',
|
|
328
|
+
required: false,
|
|
329
|
+
size: 2,
|
|
330
|
+
},
|
|
331
|
+
'CHECKBOX-size-1-required': {
|
|
332
|
+
id: 'CHECKBOX-size-1-required',
|
|
333
|
+
type: 'CHECKBOX',
|
|
334
|
+
label: 'Obligatorio',
|
|
335
|
+
description: null,
|
|
336
|
+
required: true,
|
|
337
|
+
size: 1,
|
|
338
|
+
},
|
|
339
|
+
'CHECKBOX-size-3': {
|
|
340
|
+
id: 'CHECKBOX-size-3',
|
|
341
|
+
type: 'CHECKBOX',
|
|
342
|
+
label: 'Tamaño 3 con un label bastante largo que en escritorio se corta con puntos suspensivos',
|
|
343
|
+
description: null,
|
|
344
|
+
required: false,
|
|
345
|
+
size: 3,
|
|
346
|
+
},
|
|
347
|
+
'CHECKBOX-size-1-checked': {
|
|
348
|
+
id: 'CHECKBOX-size-1-checked',
|
|
349
|
+
type: 'CHECKBOX',
|
|
350
|
+
label: 'Marcado',
|
|
351
|
+
description: null,
|
|
352
|
+
required: false,
|
|
353
|
+
size: 1,
|
|
354
|
+
defaultValue: true,
|
|
355
|
+
},
|
|
356
|
+
'CHECKBOX-size-4': {
|
|
357
|
+
id: 'CHECKBOX-size-4',
|
|
358
|
+
type: 'CHECKBOX',
|
|
359
|
+
label: 'Tamaño 4 (ancho completo): confirmo que la información suministrada es veraz, que he leído la ' +
|
|
360
|
+
'política de tratamiento de datos personales y autorizo el uso de mis datos para los fines ' +
|
|
361
|
+
'descritos en el presente formulario',
|
|
362
|
+
description: null,
|
|
363
|
+
required: true,
|
|
364
|
+
size: 4,
|
|
365
|
+
},
|
|
366
|
+
'CHECKBOX-list': {
|
|
367
|
+
id: 'CHECKBOX-list',
|
|
368
|
+
type: 'CHECKBOX',
|
|
369
|
+
label: 'Modo lista (isList): el checkbox va antes del label y sin dos puntos',
|
|
370
|
+
description: null,
|
|
371
|
+
required: false,
|
|
372
|
+
size: 4,
|
|
373
|
+
isList: true,
|
|
374
|
+
},
|
|
375
|
+
'CHECKBOX-nested': {
|
|
376
|
+
id: 'CHECKBOX-nested',
|
|
377
|
+
type: 'CHECKBOX',
|
|
378
|
+
label: '¿Desea agregar una dirección de envío distinta?',
|
|
379
|
+
description: 'Al marcarlo aparecen los campos de la dirección.',
|
|
380
|
+
required: false,
|
|
381
|
+
size: 4,
|
|
382
|
+
steps: ['TEXTINPUT-shipping-address', 'TEXTINPUT-shipping-city'],
|
|
383
|
+
},
|
|
384
|
+
'TEXTINPUT-shipping-address': cbTextInput('TEXTINPUT-shipping-address', 'Dirección de envío', 2),
|
|
385
|
+
'TEXTINPUT-shipping-city': cbTextInput('TEXTINPUT-shipping-city', 'Ciudad', 2),
|
|
386
|
+
'CHECKBOX-unchecked-steps': {
|
|
387
|
+
id: 'CHECKBOX-unchecked-steps',
|
|
388
|
+
type: 'CHECKBOX',
|
|
389
|
+
label: 'Usar los datos de contacto registrados',
|
|
390
|
+
description: 'Al desmarcarlo aparecen los campos de contacto (uncheckedSteps).',
|
|
391
|
+
required: false,
|
|
392
|
+
size: 4,
|
|
393
|
+
defaultValue: true,
|
|
394
|
+
uncheckedSteps: ['TEXTINPUT-contact-phone', 'TEXTINPUT-contact-email'],
|
|
395
|
+
},
|
|
396
|
+
'TEXTINPUT-contact-phone': cbTextInput('TEXTINPUT-contact-phone', 'Teléfono', 2),
|
|
397
|
+
'TEXTINPUT-contact-email': cbTextInput('TEXTINPUT-contact-email', 'Correo', 2),
|
|
398
|
+
'COLLAPSIBLE-checkbox': {
|
|
399
|
+
id: 'COLLAPSIBLE-checkbox',
|
|
400
|
+
type: 'COLLAPSIBLE',
|
|
401
|
+
label: 'Colapsable con checkbox anidado',
|
|
402
|
+
defaultValue: true,
|
|
403
|
+
steps: ['CHECKBOX-in-collapsible'],
|
|
404
|
+
},
|
|
405
|
+
'CHECKBOX-in-collapsible': {
|
|
406
|
+
id: 'CHECKBOX-in-collapsible',
|
|
407
|
+
type: 'CHECKBOX',
|
|
408
|
+
label: '¿Desea agregar información adicional?',
|
|
409
|
+
description: null,
|
|
410
|
+
required: false,
|
|
411
|
+
size: 4,
|
|
412
|
+
steps: ['TEXTINPUT-extra-1', 'TEXTINPUT-extra-2'],
|
|
413
|
+
},
|
|
414
|
+
'TEXTINPUT-extra-1': cbTextInput('TEXTINPUT-extra-1', 'Información adicional 1', 2),
|
|
415
|
+
'TEXTINPUT-extra-2': cbTextInput('TEXTINPUT-extra-2', 'Información adicional 2', 2),
|
|
416
|
+
},
|
|
417
|
+
size: { blockNum: 4, blockSize: 210, spacingSize: 20 },
|
|
418
|
+
rootSteps: [
|
|
419
|
+
'CHECKBOX-size-1',
|
|
420
|
+
'CHECKBOX-size-2',
|
|
421
|
+
'CHECKBOX-size-1-required',
|
|
422
|
+
'CHECKBOX-size-3',
|
|
423
|
+
'CHECKBOX-size-1-checked',
|
|
424
|
+
'CHECKBOX-size-4',
|
|
425
|
+
'CHECKBOX-list',
|
|
426
|
+
'CHECKBOX-nested',
|
|
427
|
+
'CHECKBOX-unchecked-steps',
|
|
428
|
+
'COLLAPSIBLE-checkbox',
|
|
429
|
+
],
|
|
430
|
+
label: 'Enviar',
|
|
431
|
+
firstSection: 'FIRST',
|
|
432
|
+
sections: {
|
|
433
|
+
FIRST: {
|
|
434
|
+
id: 'FIRST',
|
|
435
|
+
steps: [
|
|
436
|
+
'CHECKBOX-size-1',
|
|
437
|
+
'CHECKBOX-size-2',
|
|
438
|
+
'CHECKBOX-size-1-required',
|
|
439
|
+
'CHECKBOX-size-3',
|
|
440
|
+
'CHECKBOX-size-1-checked',
|
|
441
|
+
'CHECKBOX-size-4',
|
|
442
|
+
'CHECKBOX-list',
|
|
443
|
+
'CHECKBOX-nested',
|
|
444
|
+
'CHECKBOX-unchecked-steps',
|
|
445
|
+
'COLLAPSIBLE-checkbox',
|
|
446
|
+
],
|
|
447
|
+
name: '',
|
|
448
|
+
nextSection: null,
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* Every checkbox variant in one form: sizes 1–4, required, description, list mode, long
|
|
454
|
+
* labels, nested `steps` / `uncheckedSteps`, and a checkbox inside a collapsible. Resize the
|
|
455
|
+
* preview below ~900px to see the collapsed label mode (100% width, 2-line clamp, "ver más").
|
|
456
|
+
* Inside the collapsible, close/reopen it and then check the checkbox to reproduce the clipped
|
|
457
|
+
* nested steps.
|
|
458
|
+
*/
|
|
459
|
+
export const Checkboxes = {
|
|
460
|
+
args: {
|
|
461
|
+
formData: checkboxesForm,
|
|
462
|
+
},
|
|
463
|
+
};
|
|
464
|
+
/** Same checkboxes form in postview, read-only. */
|
|
465
|
+
export const CheckboxesPostview = {
|
|
466
|
+
args: {
|
|
467
|
+
formData: checkboxesForm,
|
|
468
|
+
valuesData: {
|
|
469
|
+
'CHECKBOX-size-1': true,
|
|
470
|
+
'CHECKBOX-size-2': false,
|
|
471
|
+
'CHECKBOX-size-1-required': true,
|
|
472
|
+
'CHECKBOX-size-3': true,
|
|
473
|
+
'CHECKBOX-size-1-checked': true,
|
|
474
|
+
'CHECKBOX-size-4': true,
|
|
475
|
+
'CHECKBOX-list': true,
|
|
476
|
+
'CHECKBOX-nested': true,
|
|
477
|
+
'TEXTINPUT-shipping-address': 'Calle 123 # 45-67',
|
|
478
|
+
'TEXTINPUT-shipping-city': 'Bogotá',
|
|
479
|
+
'CHECKBOX-unchecked-steps': true,
|
|
480
|
+
'COLLAPSIBLE-checkbox': true,
|
|
481
|
+
'CHECKBOX-in-collapsible': false,
|
|
482
|
+
},
|
|
483
|
+
postview: true,
|
|
484
|
+
internal: true,
|
|
485
|
+
editable: false,
|
|
486
|
+
},
|
|
487
|
+
};
|
package/dist/Form/Form.js
CHANGED
|
@@ -6,7 +6,7 @@ import InternalFormStyle from '../constants/InternalFormStyle';
|
|
|
6
6
|
import ColumnForm from './FormTypes/ColumnForm/ColumnForm';
|
|
7
7
|
import StepperForm from './FormTypes/StepperForm/StepperForm';
|
|
8
8
|
import { FormStyleTypes, FormTypes } from '../constants/FormStepTypes';
|
|
9
|
-
import { calcValue } from './FormFunctions';
|
|
9
|
+
import { calcValue, resolveCaptchaToken } from './FormFunctions';
|
|
10
10
|
import { FormProvider, useForm } from 'react-hook-form';
|
|
11
11
|
import widgetInstance from '../Utils/AxiosWidget';
|
|
12
12
|
import axiosInstance from '../Utils/AxiosAPI';
|
|
@@ -38,15 +38,16 @@ function FormComponent({ form, apiKey, reload, isWidget, branding, setSubmit, sc
|
|
|
38
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
39
|
}, [idFocusStep]);
|
|
40
40
|
const onSubmit = useCallback(async (values) => {
|
|
41
|
-
let token = null;
|
|
42
|
-
if (form.hasCaptcha && !internal && !customSubmit) {
|
|
43
|
-
token = recaptchaRef.current?.getValue();
|
|
44
|
-
token ?? (token = await recaptchaRef?.current.executeAsync());
|
|
45
|
-
}
|
|
46
41
|
const ApiKey = internal ? form.apiKey : apiKey;
|
|
47
42
|
if (!ApiKey && !customSubmit && !customSubmitBtns)
|
|
48
43
|
return;
|
|
49
44
|
try {
|
|
45
|
+
// Resolved inside the try so a captcha that cannot mint a token surfaces through the same
|
|
46
|
+
// error path as any other submit failure, rather than rejecting out of the handler and
|
|
47
|
+
// leaving the submitter with no feedback at all.
|
|
48
|
+
const token = form.hasCaptcha && !internal && !customSubmit
|
|
49
|
+
? await resolveCaptchaToken(recaptchaRef.current)
|
|
50
|
+
: null;
|
|
50
51
|
const state = await dispatch(getAppState({ idForm })).unwrap();
|
|
51
52
|
const newValues = {
|
|
52
53
|
...state.site.values.global,
|
|
@@ -4,6 +4,23 @@ import { CustomStep } from '../FormSteps/CustomStep';
|
|
|
4
4
|
import { CBRFormStep } from '../@Types/CBRFormStep';
|
|
5
5
|
import { MapperElement } from '../@Types/MapperElement';
|
|
6
6
|
import { ValuesStore } from '../States/SiteSlice';
|
|
7
|
+
/** The reCAPTCHA widget surface a submission needs: the response it holds, and the challenge that mints one. */
|
|
8
|
+
export interface CaptchaWidget {
|
|
9
|
+
getValue(): string | null;
|
|
10
|
+
executeAsync(): Promise<string | null>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the reCAPTCHA response to send with a submission, running the invisible challenge when the widget
|
|
14
|
+
* is not holding one yet.
|
|
15
|
+
*
|
|
16
|
+
* An unsolved invisible widget answers `getValue()` with an EMPTY STRING rather than null, so emptiness —
|
|
17
|
+
* not nullishness — is what decides whether the challenge still has to run. A submission that skips the
|
|
18
|
+
* challenge carries no token, and the API rejects every captcha-protected public form with a 403.
|
|
19
|
+
*
|
|
20
|
+
* Yields null when no widget is mounted, leaving the caller to submit tokenless rather than throwing out of
|
|
21
|
+
* the submit handler.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveCaptchaToken(captcha: CaptchaWidget | null | undefined): Promise<string | null>;
|
|
7
24
|
/**
|
|
8
25
|
* Function that cals the value of a step to output on submit
|
|
9
26
|
*/
|
|
@@ -3,6 +3,28 @@ import FormStepTypes, { EntityValueDataTypes } from '../constants/FormStepTypes'
|
|
|
3
3
|
import { calcStepDeps } from '../FormSteps/StepHooks';
|
|
4
4
|
import { calcRecursiveData } from '../Utils/FormStepFunctions';
|
|
5
5
|
import { isValidPhoneNumber } from '../Utils/PhoneFunctions';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the reCAPTCHA response to send with a submission, running the invisible challenge when the widget
|
|
8
|
+
* is not holding one yet.
|
|
9
|
+
*
|
|
10
|
+
* An unsolved invisible widget answers `getValue()` with an EMPTY STRING rather than null, so emptiness —
|
|
11
|
+
* not nullishness — is what decides whether the challenge still has to run. A submission that skips the
|
|
12
|
+
* challenge carries no token, and the API rejects every captcha-protected public form with a 403.
|
|
13
|
+
*
|
|
14
|
+
* Yields null when no widget is mounted, leaving the caller to submit tokenless rather than throwing out of
|
|
15
|
+
* the submit handler.
|
|
16
|
+
*/
|
|
17
|
+
export async function resolveCaptchaToken(captcha) {
|
|
18
|
+
if (!captcha)
|
|
19
|
+
return null;
|
|
20
|
+
const held = captcha.getValue();
|
|
21
|
+
if (held)
|
|
22
|
+
return held;
|
|
23
|
+
const solved = await captcha.executeAsync();
|
|
24
|
+
if (solved)
|
|
25
|
+
return solved;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
6
28
|
/**
|
|
7
29
|
* Function that cals the value of a step to output on submit
|
|
8
30
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/require-await */
|
|
2
2
|
import { ContentState, EditorState } from 'draft-js';
|
|
3
3
|
import FormStepTypes, { EntityValueDataTypes } from '../constants/FormStepTypes';
|
|
4
|
-
import { calcDependencies, calcValue } from './FormFunctions';
|
|
4
|
+
import { calcDependencies, calcValue, resolveCaptchaToken } from './FormFunctions';
|
|
5
5
|
import { stringToDraft } from '../Utils/DraftFunctions';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
describe('FormFunctions', function () {
|
|
@@ -455,4 +455,31 @@ describe('FormFunctions', function () {
|
|
|
455
455
|
expect(dependencyStore.idStep.dependents.length).toBe(1);
|
|
456
456
|
});
|
|
457
457
|
});
|
|
458
|
+
describe('resolveCaptchaToken', function () {
|
|
459
|
+
test('Uses the token the widget already holds without re-running the challenge', async () => {
|
|
460
|
+
let executed = false;
|
|
461
|
+
const token = await resolveCaptchaToken({
|
|
462
|
+
getValue: () => 'already-solved',
|
|
463
|
+
executeAsync: async () => {
|
|
464
|
+
executed = true;
|
|
465
|
+
return 'freshly-solved';
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
expect(token).toBe('already-solved');
|
|
469
|
+
expect(executed).toBe(false);
|
|
470
|
+
});
|
|
471
|
+
test('Runs the challenge when the invisible widget reports an empty response', async () => {
|
|
472
|
+
// An unsolved invisible captcha answers `getValue()` with '' — not null — so emptiness is what
|
|
473
|
+
// must decide whether the challenge still has to run. Treating only nullish as unsolved leaves
|
|
474
|
+
// the submission tokenless and the API answers 403.
|
|
475
|
+
const token = await resolveCaptchaToken({
|
|
476
|
+
getValue: () => '',
|
|
477
|
+
executeAsync: async () => 'freshly-solved',
|
|
478
|
+
});
|
|
479
|
+
expect(token).toBe('freshly-solved');
|
|
480
|
+
});
|
|
481
|
+
test('Yields no token when the widget is not mounted', async () => {
|
|
482
|
+
expect(await resolveCaptchaToken(null)).toBeNull();
|
|
483
|
+
});
|
|
484
|
+
});
|
|
458
485
|
});
|
|
@@ -48,7 +48,7 @@ function makeStore(currentBreakPoint) {
|
|
|
48
48
|
...defaultRootState,
|
|
49
49
|
widthStats: {
|
|
50
50
|
currentBreakPoint,
|
|
51
|
-
isMobile: currentBreakPoint <=
|
|
51
|
+
isMobile: currentBreakPoint <= 1,
|
|
52
52
|
isResponsive: true,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
@@ -57,9 +57,9 @@ function makeStore(currentBreakPoint) {
|
|
|
57
57
|
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(RootApi.middleware),
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
function Harness({ currentBreakPoint }) {
|
|
60
|
+
function Harness({ currentBreakPoint, step = checkBoxStep, }) {
|
|
61
61
|
const methods = useForm({ mode: 'onTouched' });
|
|
62
|
-
return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: makeStore(currentBreakPoint), context: StoreContext, children: _jsx(IdFormContext.Provider, { value: STORY_FORM_ID, children: _jsx(FormContext.Provider, { value: form, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(CheckBoxStep, { step:
|
|
62
|
+
return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: makeStore(currentBreakPoint), context: StoreContext, children: _jsx(IdFormContext.Provider, { value: STORY_FORM_ID, children: _jsx(FormContext.Provider, { value: { ...form, steps: { ...form.steps, [step.id]: step } }, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(CheckBoxStep, { step: step, editable: true }) }) }) }) }) }) }));
|
|
63
63
|
}
|
|
64
64
|
function getLabelDiv() {
|
|
65
65
|
// the leaf div holding only the label text (the wrapping column also matches by textContent)
|
|
@@ -85,22 +85,30 @@ afterEach(() => {
|
|
|
85
85
|
delete HTMLElement.prototype.scrollHeight;
|
|
86
86
|
delete HTMLElement.prototype.clientHeight;
|
|
87
87
|
});
|
|
88
|
-
describe('CheckBoxStep
|
|
88
|
+
describe('CheckBoxStep long labels', () => {
|
|
89
89
|
it('wraps the label (2-line clamp) instead of single-line truncating it when the step collapses to 100% width', () => {
|
|
90
90
|
// breakpoint 1 <= size 2 → MaterialInputContainer renders the step at width: 100%
|
|
91
91
|
render(_jsx(Harness, { currentBreakPoint: 1 }));
|
|
92
92
|
const label = getLabelDiv();
|
|
93
93
|
expect(label.className).toBe(styles.clampLbl);
|
|
94
|
-
|
|
95
|
-
// the fixed desktop pixel maxWidth must not constrain the collapsed label
|
|
94
|
+
// no fixed desktop pixel maxWidth constrains the label
|
|
96
95
|
expect(label.style.maxWidth).toBe('');
|
|
97
96
|
});
|
|
98
|
-
it('
|
|
97
|
+
it('also clamps (with "ver más") when the step keeps a fixed width on a phone where 2 columns fit', () => {
|
|
98
|
+
// regression: a size-1 checkbox at breakpoint 2 used to render a single-line ellipsis with
|
|
99
|
+
// no way to read the full label
|
|
100
|
+
mockLabelOverflow();
|
|
101
|
+
render(_jsx(Harness, { currentBreakPoint: 2, step: { ...checkBoxStep, size: 1 } }));
|
|
102
|
+
const label = getLabelDiv();
|
|
103
|
+
expect(label.className).toBe(styles.clampLbl);
|
|
104
|
+
expect(label.style.maxWidth).toBe('');
|
|
105
|
+
expect(screen.getByRole('button', { name: 'ver más' })).toBeInTheDocument();
|
|
106
|
+
});
|
|
107
|
+
it('clamps on desktop widths too, without a toggle while the label fits', () => {
|
|
99
108
|
// breakpoint 4 > size 2 → the step keeps its fixed desktop width
|
|
100
109
|
render(_jsx(Harness, { currentBreakPoint: 4 }));
|
|
101
110
|
const label = getLabelDiv();
|
|
102
|
-
expect(label.className).toBe(styles.
|
|
103
|
-
expect(label.style.maxWidth).not.toBe('');
|
|
111
|
+
expect(label.className).toBe(styles.clampLbl);
|
|
104
112
|
expect(screen.queryByRole('button', { name: 'ver más' })).not.toBeInTheDocument();
|
|
105
113
|
});
|
|
106
114
|
it('shows no "ver más" toggle when the label fits in the clamp', () => {
|
|
@@ -8,7 +8,6 @@ import { useAppSelector, selectWidthStats } from '../../../hooks';
|
|
|
8
8
|
import { useFormStep } from '../../StepHooks';
|
|
9
9
|
import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
|
|
10
10
|
import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
|
|
11
|
-
import { calcStepWidth, resolveStepSpan } from '../../StepFunctions';
|
|
12
11
|
function CheckBoxStep({ step, editable }) {
|
|
13
12
|
const { ref, value, onChange, error, field } = useFormStep(step, {
|
|
14
13
|
defaultValue: step.defaultValue ?? false,
|
|
@@ -20,15 +19,15 @@ function CheckBoxStep({ step, editable }) {
|
|
|
20
19
|
const { formStyle, postview } = useAppSelector((state) => state.global);
|
|
21
20
|
const form = useContext(FormContext);
|
|
22
21
|
const widthStats = useAppSelector(selectWidthStats);
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
// the
|
|
26
|
-
|
|
22
|
+
// The label is clamped to 2 lines with a "ver más" toggle at every width. A single-line
|
|
23
|
+
// ellipsis was used while the step kept its fixed desktop pixel width, but that left long
|
|
24
|
+
// labels unreadable wherever the step is narrow (e.g. a size-1 checkbox on a phone where 2
|
|
25
|
+
// columns fit).
|
|
27
26
|
const labelRef = useRef(null);
|
|
28
27
|
const [expanded, setExpanded] = useState(false);
|
|
29
28
|
const [clamped, setClamped] = useState(false);
|
|
30
29
|
useLayoutEffect(() => {
|
|
31
|
-
if (
|
|
30
|
+
if (expanded)
|
|
32
31
|
return;
|
|
33
32
|
const measure = () => {
|
|
34
33
|
const label = labelRef.current;
|
|
@@ -38,7 +37,7 @@ function CheckBoxStep({ step, editable }) {
|
|
|
38
37
|
measure();
|
|
39
38
|
window.addEventListener('resize', measure);
|
|
40
39
|
return () => window.removeEventListener('resize', measure);
|
|
41
|
-
}, [
|
|
40
|
+
}, [expanded, step.label, widthStats.currentBreakPoint]);
|
|
42
41
|
const renderNested = () => {
|
|
43
42
|
const steps = value ? step.steps : step.uncheckedSteps;
|
|
44
43
|
return (_jsx(React.Fragment, { children: steps?.map((idStep) => {
|
|
@@ -48,18 +47,12 @@ function CheckBoxStep({ step, editable }) {
|
|
|
48
47
|
};
|
|
49
48
|
const renderLabel = (colon = false) => {
|
|
50
49
|
const label = `${step.label}${step.required ? ' *' : ''}${colon ? ':' : ''}`;
|
|
51
|
-
if (!collapsed) {
|
|
52
|
-
return (_jsx("div", { className: span === 4 ? styles.checkboxLbl : styles.overflowLbl, style: {
|
|
53
|
-
maxWidth: calcStepWidth(span, form.size) - 45,
|
|
54
|
-
}, children: label }));
|
|
55
|
-
}
|
|
56
50
|
return (_jsxs("div", { className: styles.labelColumn, children: [_jsx("div", { ref: labelRef, className: expanded ? styles.expandedLbl : styles.clampLbl, children: label }), (clamped || expanded) && (_jsx("button", { type: "button", className: styles.toggleLbl, style: { color: formStyle.primaryColor }, onClick: (event) => {
|
|
57
51
|
event.stopPropagation();
|
|
58
52
|
setExpanded(!expanded);
|
|
59
53
|
}, children: expanded ? 'ver menos' : 'ver más' }))] }));
|
|
60
54
|
};
|
|
61
55
|
return (_jsxs(StepFillerContainer, { step: step, children: [_jsx(MaterialInputContainer, { step: step, editable: editable, maxHeight: step.size < 4, children: _jsxs("div", { className: styles.container, children: [_jsxs("div", { className: styles.labelCheckBoxContainer, style: {
|
|
62
|
-
height: span < 4 && !collapsed ? 31 : undefined,
|
|
63
56
|
minHeight: 31,
|
|
64
57
|
alignItems: step.isList ? 'start' : 'center',
|
|
65
58
|
}, children: [step.label && !step.isList && renderLabel(true), _jsx(ErkCheckBox, { ...field, padding: "0px", inputRef: ref, error: !!error, checked: value, onChange: onChange, "data-testid": step.id, readOnly: !editable || postview }), step.label && step.isList && renderLabel()] }), (step.description ?? !!error) && (_jsx("div", { className: styles.descriptionPar, style: {
|
|
@@ -3,17 +3,6 @@
|
|
|
3
3
|
flex-direction: column;
|
|
4
4
|
max-width: 100%;
|
|
5
5
|
}
|
|
6
|
-
.checkboxLbl,
|
|
7
|
-
.overflowLbl {
|
|
8
|
-
font-size: 18px;
|
|
9
|
-
margin-right: 10px;
|
|
10
|
-
margin-left: 10px;
|
|
11
|
-
}
|
|
12
|
-
.overflowLbl {
|
|
13
|
-
white-space: nowrap;
|
|
14
|
-
overflow: hidden;
|
|
15
|
-
text-overflow: ellipsis;
|
|
16
|
-
}
|
|
17
6
|
.labelColumn {
|
|
18
7
|
display: flex;
|
|
19
8
|
flex-direction: column;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arquimedes.co/eureka-forms",
|
|
3
3
|
"repository": "git://github.com/Arquimede5/Eureka-Forms.git",
|
|
4
|
-
"version":"3.0.
|
|
4
|
+
"version": "3.0.61",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"watch": "node node_modules/@typescript/native/bin/tsc --noEmit --watch --project tsconfig.app.json",
|
|
7
7
|
"start": "vite",
|