Skip to content

Commit

Permalink
Add descriptive alt text for repeated opening hour icon
Browse files Browse the repository at this point in the history
Because the `OpeningHoursEditorEventContent` component can't be rendered normally, I need the translation in its parent component.
  • Loading branch information
kasperbirch1 committed Apr 25, 2024
1 parent 6731c8d commit 9bded27
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/apps/opening-hours-editor/OpeningHoursEditor.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export default {
name: "Opening hours confirm add repeated submit",
defaultValue: "I'm sure",
control: { type: "text" }
},
openingHoursRepeatedIconAltText: {
name: "Opening hours repeated icon alt text",
defaultValue: "Repeated opening hour",
control: { type: "text" }
}
}
} as ComponentMeta<typeof OpeningHoursEditor>;
Expand Down
1 change: 1 addition & 0 deletions src/apps/opening-hours-editor/OpeningHoursEditor.entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface OpeningHoursEditorEntryTextProps {
openingHoursConfirmAddRepeatedText: string;
openingHoursConfirmAddRepeatedCancelText: string;
openingHoursConfirmAddRepeatedSubmitText: string;
openingHoursRepeatedIconAltText: string;
}

interface OpeningHoursEditorEntryConfigProps {
Expand Down
8 changes: 7 additions & 1 deletion src/apps/opening-hours-editor/OpeningHoursEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useDialog from "../../components/dialog/useDialog";
import DialogFormAdd from "./DialogFormAdd";
import { OpeningHoursCategoriesType } from "./types";
import { useConfig } from "../../core/utils/config";
import { useText } from "../../core/utils/text";

export type OpeningHoursEditorType = {
initialDate?: Date;
Expand All @@ -20,6 +21,10 @@ export type OpeningHoursEditorType = {
const OpeningHoursEditor: React.FC<OpeningHoursEditorType> = ({
initialDate
}) => {
// OpeningHoursEditorEventContent cannot be rendered as a standard component,
// thus preventing the use of useText hook within it.
const t = useText();
const iconAltText = t("openingHoursRepeatedIconAltText");
const config = useConfig();
const openingHoursCategories = config<OpeningHoursCategoriesType[]>(
"openingHoursEditorCategoriesConfig",
Expand Down Expand Up @@ -83,7 +88,8 @@ const OpeningHoursEditor: React.FC<OpeningHoursEditorType> = ({
}
eventContent={(eventInput) =>
OpeningHoursEditorEventContent({
eventInput
eventInput,
iconAltText
})
}
events={events}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { extractTime } from "./helper";

type OpeningHoursEditorEventContentProps = {
eventInput: EventInput;
iconAltText: string;
};

const OpeningHoursEditorEventContent: React.FC<
OpeningHoursEditorEventContentProps
> = ({ eventInput }) => {
> = ({ eventInput, iconAltText }) => {
const { event } = eventInput;
const { repetition } = event.extendedProps;
const isSeries = repetition?.type === "weekly";
Expand All @@ -27,7 +28,7 @@ const OpeningHoursEditorEventContent: React.FC<
</div>
{isSeries && (
<div className="opening-hours-editor-event-content__series-icon">
<img src={logo} alt="" className="" />
<img src={logo} alt={iconAltText} />
</div>
)}
</div>
Expand Down

0 comments on commit 9bded27

Please sign in to comment.