michael-s-molina commented on a change in pull request #14557:
URL: https://github.com/apache/superset/pull/14557#discussion_r632056740
##########
File path: superset-frontend/src/components/Menu/LanguagePicker.tsx
##########
@@ -33,43 +34,72 @@ interface LanguagePickerProps {
languages: Languages;
}
+const StyledLabel = styled.div`
+ display: flex;
+ align-items: center;
+
+ & i {
+ margin-right: ${({ theme }) => theme.gridUnit}px;
+ }
+`;
+
+const StyledFlag = styled.div`
+ margin-top: 2px;
+`;
+
+const StyledIcon = styled(Icons.TriangleDown)`
+ ${({ theme }) => `
+ margin-top: -${theme.gridUnit}px;
+ margin-left: -${theme.gridUnit * 2}px;
+ `}
+`;
+
export default function LanguagePicker({
locale,
languages,
}: LanguagePickerProps) {
- const [dropdownOpen, setDropdownOpen] = useState(false);
+ const theme = useTheme();
+ const [open, setOpen] = useState(false);
+
+ const options = Object.keys(languages).map(langKey => ({
+ label: (
+ <StyledLabel className="f16">
+ <i className={`flag ${languages[langKey].flag}`} />{' '}
+ {languages[langKey].name}
+ </StyledLabel>
+ ),
+ value: langKey,
+ flag: (
+ <StyledFlag className="f16">
+ <i className={`flag ${languages[langKey].flag}`} />
+ </StyledFlag>
+ ),
+ }));
return (
- <NavDropdown
- onMouseEnter={() => setDropdownOpen(true)}
- onMouseLeave={() => setDropdownOpen(false)}
- onToggle={value => setDropdownOpen(value)}
- open={dropdownOpen}
- id="locale-dropdown"
- title={
- <span className="f16">
- <i className={`flag ${languages[locale].flag}`} />
- </span>
+ <Select
+ defaultValue={locale}
+ open={open}
+ onMouseEnter={() => setOpen(true)}
+ onMouseLeave={() => setOpen(false)}
+ onDropdownVisibleChange={open => setOpen(open)}
+ bordered={false}
+ options={options}
+ suffixIcon={
+ <StyledIcon
+ iconColor={theme.colors.grayscale.base}
+ className="ant-select-suffix"
+ />
}
- data-test="language-picker"
- >
- <Menu
- onSelect={({ key }) => {
- window.location.href = languages[key].url;
- }}
- >
- {Object.keys(languages).map(langKey =>
- langKey === locale ? null : (
- <Menu.Item key={langKey}>
- {' '}
- <div className="f16">
- <i className={`flag ${languages[langKey].flag}`} /> -{' '}
- {languages[langKey].name}
- </div>
- </Menu.Item>
- ),
- )}
- </Menu>
- </NavDropdown>
+ listHeight={400}
+ dropdownAlign={{
+ offset: [-135, 0],
Review comment:
@rusackas I changed to make the component wrap big texts in multiple
lines instead of using `transform` to avoid fat dropdowns 😉. Since the width is
fixed, the offset is always correctly positioned. If you agree, you can remove
the `need:followup` label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]