-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://git.smc.it/openk9/openk9 into 554-fix-…
…sort-result
- Loading branch information
Showing
15 changed files
with
444 additions
and
57 deletions.
There are no files selected for viewing
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
134 changes: 134 additions & 0 deletions
134
js-packages/search-frontend/src/components/ChangeLanguage.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,134 @@ | ||
import { css } from "styled-components/macro"; | ||
import { UseQueryResult } from "react-query"; | ||
import React from "react"; | ||
import { useQuery } from "react-query"; | ||
import { SortField, useOpenK9Client } from "../components/client"; | ||
import { useTranslation } from "react-i18next"; | ||
import { GloboSvg } from "../svgElement/Globo"; | ||
import Select, { components } from "react-select"; | ||
import { i18n } from "i18next"; | ||
import { remappingLanguage } from "../embeddable/Main"; | ||
|
||
export function ChangeLanguage({ | ||
setChangeLanguage, | ||
background = "white", | ||
minHeight = "40px", | ||
color = "#7e7e7e", | ||
languages, | ||
activeLanguage, | ||
i18nElement, | ||
}: { | ||
setChangeLanguage: (sortResultNew: string) => void; | ||
background?: string; | ||
minHeight?: string; | ||
color?: string; | ||
activeLanguage: string; | ||
i18nElement: i18n; | ||
languages: | ||
| { | ||
createDate: any; | ||
modifiedDate: any; | ||
id: number; | ||
name: string; | ||
value: "value"; | ||
}[] | ||
| undefined; | ||
}) { | ||
const filterLanguages = languages?.find( | ||
(language) => language.value === activeLanguage, | ||
); | ||
|
||
const startValue = filterLanguages | ||
? { | ||
value: filterLanguages.value, | ||
name: filterLanguages.name, | ||
icon: <GloboSvg />, | ||
} | ||
: null; | ||
|
||
const handleChange = (e: any) => { | ||
i18nElement.changeLanguage(remappingLanguage({ language: e.value })); | ||
setChangeLanguage(e.value); | ||
}; | ||
const customStyles = { | ||
control: (provided: any, state: any) => ({ | ||
...provided, | ||
borderRadius: "50px", | ||
backgroundColor: "#FAFAFA", | ||
border: | ||
!state.isFocused || !state.isHovered | ||
? "1px solid #FAFAFA" | ||
: "1px solid var(--openk9-embeddable-search--active-color)", | ||
boxShadow: "0 0 0 1px var(--openk9-embeddable-search--active-color)", | ||
":hover": { | ||
border: "1px solid var(--openk9-embeddable-search--active-color)", | ||
}, | ||
}), | ||
menu: (provided: any, state: any) => ({ | ||
...provided, | ||
zIndex: state.selectProps.menuIsOpen ? "1000" : "1", | ||
}), | ||
option: (provided: any, state: any) => ({ | ||
...provided, | ||
backgroundColor: state.isFocused ? "#your-option-focus-color" : "white", | ||
color: "black", | ||
":hover": { | ||
backgroundColor: state.isSelected ? "#d54949" : "#e836362e", | ||
cursor: "pointer", | ||
}, | ||
...(state.isSelected && { | ||
backgroundColor: "#d54949", | ||
color: "white", | ||
}), | ||
}), | ||
indicatorSeparator: () => ({ | ||
display: "none", // Nasconde la linea separatoria | ||
}), | ||
}; | ||
|
||
const languagesOption = languages?.map((language) => ({ | ||
value: language.value, | ||
name: language.name, | ||
icon: <GloboSvg />, | ||
})); | ||
|
||
const SingleValue = (props: any) => ( | ||
<components.SingleValue {...props}> | ||
<div style={{ display: "flex", alignItems: "center", gap: "5px" }}> | ||
<GloboSvg /> {/* Icona SVG */} | ||
{remappingLanguageToBack({ language: activeLanguage })} | ||
</div> | ||
</components.SingleValue> | ||
); | ||
|
||
return ( | ||
<span> | ||
<Select | ||
value={startValue} | ||
options={languagesOption} | ||
components={{ SingleValue }} | ||
onChange={handleChange} | ||
getOptionLabel={(e) => e.name} | ||
getOptionValue={(e) => e.value} | ||
styles={customStyles} | ||
/> | ||
</span> | ||
); | ||
} | ||
|
||
function remappingLanguageToBack({ language }: { language: string }) { | ||
switch (language) { | ||
case "it_IT": | ||
return "ITA"; | ||
case "es_ES": | ||
return "ESP"; | ||
case "en_US": | ||
return "GBR"; | ||
case "de_DE": | ||
return "DEU"; | ||
case "fr_FR": | ||
return "FRA"; | ||
default: | ||
return "GBR"; | ||
} | ||
} |
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
Oops, something went wrong.