You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/05/13 18:58:27 UTC

[GitHub] [superset] rusackas commented on a change in pull request #14557: fix: Consolidating dropdown/NavDropdown user experience (removing React-bootstrap, using AntD)

rusackas commented on a change in pull request #14557:
URL: https://github.com/apache/superset/pull/14557#discussion_r632034174



##########
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:
       could also do some styling to reposition this, e.g.:
   ```
   transform: translateX(-100%);
   ```




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org