-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Translate dynamic row props (#4266)
* add inputs to translate screen * a11y descriptions/labels --------- Co-authored-by: Dave Samojlenko <[email protected]>
- Loading branch information
1 parent
bdb9821
commit 3070872
Showing
4 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
...orm administration)/form-builder/[id]/edit/translate/components/TranslateCustomizeSet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { Language } from "@lib/types/form-builder-types"; | ||
import { FieldsetLegend } from "."; | ||
import { LanguageLabel } from "./LanguageLabel"; | ||
import { useTranslation } from "@i18n/client"; | ||
import { useTemplateStore } from "@lib/store/useTemplateStore"; | ||
import { FormElement } from "@lib/types"; | ||
|
||
export const TranslateCustomizeSet = ({ | ||
element, | ||
primaryLanguage, | ||
secondaryLanguage, | ||
}: { | ||
element: FormElement; | ||
primaryLanguage: Language; | ||
secondaryLanguage: Language; | ||
}) => { | ||
const { t } = useTranslation("form-builder"); | ||
|
||
const { updateField, localizeField, propertyPath } = useTemplateStore((s) => ({ | ||
updateField: s.updateField, | ||
localizeField: s.localizeField, | ||
propertyPath: s.propertyPath, | ||
})); | ||
|
||
const dynamicRowProps = element.properties.dynamicRow; | ||
|
||
if (!dynamicRowProps) { | ||
return null; | ||
} | ||
|
||
// Add button | ||
const addButtonText = "addButtonText"; | ||
|
||
const addButtonPropEn = localizeField(addButtonText, primaryLanguage); | ||
const addButtonEnValue = dynamicRowProps[addButtonPropEn]; | ||
const addButtonPropFr = localizeField(addButtonText, secondaryLanguage); | ||
const addButtonFrValue = dynamicRowProps[addButtonPropFr]; | ||
|
||
// Remove button | ||
const removeButtonText = "removeButtonText"; | ||
|
||
const removeButtonPropEn = localizeField(removeButtonText, primaryLanguage); | ||
const removeButtonEnValue = dynamicRowProps[removeButtonPropEn]; | ||
const removeButtonPropFr = localizeField(removeButtonText, secondaryLanguage); | ||
const removeButtonFrValue = dynamicRowProps[removeButtonPropFr]; | ||
|
||
return ( | ||
<> | ||
{/* Start add button inputs */} | ||
<fieldset> | ||
<FieldsetLegend> | ||
{t("dynamicRow.translate.repeatingSet")} {":"} {t("dynamicRow.translate.addButtonText")} | ||
</FieldsetLegend> | ||
{/* English */} | ||
<div className="mb-10 flex gap-px divide-x-2 border border-gray-300" key={primaryLanguage}> | ||
<label htmlFor={`add-button-text-english-${element.id}`} className="sr-only"> | ||
<>{primaryLanguage}</> | ||
</label> | ||
<div className="relative w-1/2 flex-1"> | ||
<LanguageLabel id={`add-button-text-english-desc-${element.id}`} lang={primaryLanguage}> | ||
<>{primaryLanguage}</> | ||
</LanguageLabel> | ||
<textarea | ||
className="size-full p-4 focus:outline-blue-focus" | ||
id={`add-button-text-english-${element.id}`} | ||
aria-describedby={`add-button-text-english-desc-${element.id}`} | ||
value={addButtonEnValue} | ||
onChange={(e) => { | ||
updateField( | ||
propertyPath(element.id, `dynamicRow.${addButtonText}`, primaryLanguage), | ||
e.target.value | ||
); | ||
}} | ||
/> | ||
</div> | ||
{/* French */} | ||
<div className="relative w-1/2 flex-1"> | ||
<label htmlFor={`add-button-text-french-${element.id}`} className="sr-only"> | ||
<>{secondaryLanguage}</> | ||
</label> | ||
<LanguageLabel | ||
id={`add-button-text-french-desc-${element.id}`} | ||
lang={secondaryLanguage} | ||
> | ||
<>{secondaryLanguage}</> | ||
</LanguageLabel> | ||
<textarea | ||
className="size-full p-4 focus:outline-blue-focus" | ||
id={`add-button-text-french-${element.id}`} | ||
aria-describedby={`add-button-text-french-desc-${element.id}`} | ||
value={addButtonFrValue} | ||
onChange={(e) => { | ||
updateField( | ||
propertyPath(element.id, `dynamicRow.${addButtonText}`, secondaryLanguage), | ||
e.target.value | ||
); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</fieldset> | ||
{/* End add button inputs */} | ||
|
||
{/* Start remove button inputs */} | ||
<fieldset> | ||
<FieldsetLegend> | ||
{t("dynamicRow.translate.repeatingSet")} {":"}{" "} | ||
{t("dynamicRow.translate.removeButtonText")} | ||
</FieldsetLegend> | ||
<div className="mb-10 flex gap-px divide-x-2 border border-gray-300" key={primaryLanguage}> | ||
<div className="relative w-1/2 flex-1"> | ||
<label htmlFor={`remove-button-text-english-${element.id}`} className="sr-only"> | ||
<>{primaryLanguage}</> | ||
</label> | ||
<LanguageLabel | ||
id={`remove-button-text-english-desc-${element.id}`} | ||
lang={primaryLanguage} | ||
> | ||
<>{primaryLanguage}</> | ||
</LanguageLabel> | ||
<textarea | ||
className="size-full p-4 focus:outline-blue-focus" | ||
id={`remove-button-text-french-${element.id}`} | ||
aria-describedby={`remove-button-text-english-desc-${element.id}`} | ||
value={removeButtonEnValue} | ||
onChange={(e) => { | ||
updateField( | ||
propertyPath(element.id, `dynamicRow.${removeButtonText}`, primaryLanguage), | ||
e.target.value | ||
); | ||
}} | ||
/> | ||
</div> | ||
<div className="relative w-1/2 flex-1"> | ||
<label htmlFor={`remove-button-text-french-${element.id}`} className="sr-only"> | ||
<>{secondaryLanguage}</> | ||
</label> | ||
<LanguageLabel | ||
id={`remove-button-text-french-desc-${element.id}`} | ||
lang={secondaryLanguage} | ||
> | ||
<>{secondaryLanguage}</> | ||
</LanguageLabel> | ||
<textarea | ||
className="size-full p-4 focus:outline-blue-focus" | ||
id={`remove-button-text-french-${element.id}`} | ||
aria-describedby={`remove-button-text-french-desc-${element.id}`} | ||
value={removeButtonFrValue} | ||
onChange={(e) => { | ||
updateField( | ||
propertyPath(element.id, `dynamicRow.${removeButtonText}`, secondaryLanguage), | ||
e.target.value | ||
); | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
</fieldset> | ||
{/* End remove button inputs */} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters