Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/dropdown component and navbar bottom line #802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
},
"dependencies": {
"@floating-ui/dom": "^1.6.3",
"@floating-ui/react": "^0.26.28",
"@fortawesome/fontawesome-free": "^5.10.2",
"@fortawesome/fontawesome-svg-core": "^1.2.35",
"@fortawesome/free-regular-svg-icons": "^5.15.3",
Expand Down
75 changes: 45 additions & 30 deletions src/lib/components/dropdown/Dropdown.component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// @ts-nocheck
import { useState, useCallback } from 'react';
import styled, { css } from 'styled-components';

import styled from 'styled-components';
import {
ButtonStyled,
ButtonIcon,
Expand All @@ -14,6 +12,9 @@ import { getThemePropSelector } from '../../utils';
import { Icon } from '../icon/Icon.component';
import { useSelect } from 'downshift';
import { FocusVisibleStyle } from '../buttonv2/Buttonv2.component';
import { flip, offset, Placement, shift } from '@floating-ui/dom';
import { useFloating, useInteractions, autoUpdate } from '@floating-ui/react';

export type Item = {
label: string;
name?: string;
Expand All @@ -29,6 +30,7 @@ type Props = {
items: Items;
icon?: JSX.Element;
caret?: boolean;
placement?: Placement;
};
const DropdownStyled = styled.div`
position: relative;
Expand All @@ -39,6 +41,7 @@ const DropdownStyled = styled.div`
border-radius: 0;
}
`;

const DropdownMenuStyled = styled.ul`
position: absolute;
margin: 0;
Expand All @@ -49,9 +52,9 @@ const DropdownMenuStyled = styled.ul`
max-height: 200px;
min-width: 100%;
overflow: auto;
border-bottom: 0.3px solid ${getThemePropSelector('border')};
display: ${(props) => (props.isOpen ? 'auto' : 'none')};
`;

const DropdownMenuItemStyled = styled.li`
display: flex;
align-items: center;
Expand Down Expand Up @@ -97,6 +100,7 @@ function Dropdown({
variant = 'buttonSecondary',
title,
caret = true,
placement = 'bottom',
...rest
}: Props) {
const {
Expand All @@ -109,19 +113,29 @@ function Dropdown({
items,
itemToString: (item) => item?.label || '',
});

const { refs, floatingStyles } = useFloating({
middleware: [offset(10), flip(), shift()],
placement: placement,
whileElementsMounted: autoUpdate,
});

const { getReferenceProps, getFloatingProps } = useInteractions();

return (
<DropdownStyled
active={open}
variant={variant}
className="sc-dropdown"
{...rest}
ref={refs.setReference}
>
<TriggerStyled
variant={variant}
size={size}
className="trigger"
title={title}
{...getToggleButtonProps()}
{...getReferenceProps()}
>
{icon && (
<ButtonIcon text={text} size={size}>
Expand All @@ -134,32 +148,33 @@ function Dropdown({
<Icon name="Dropdown-down" />
</Caret>
)}

<DropdownMenuStyled
className="menu-item"
isOpen={isOpen}
{...getMenuProps()}
>
{items.map((item, index) => {
return (
<DropdownMenuItemStyled
className="menu-item-label"
key={item.label}
variant={item.variant}
{...item}
{...getItemProps({
item,
index,
onClick: item.onClick,
})}
isSelected={index === highlightedIndex}
>
{item.label}
</DropdownMenuItemStyled>
);
})}
</DropdownMenuStyled>
</TriggerStyled>
<DropdownMenuStyled
className="menu-item"
isOpen={isOpen}
style={floatingStyles}
{...getFloatingProps()}
{...getMenuProps({ ref: refs.setFloating })}
>
{items.map((item, index) => {
return (
<DropdownMenuItemStyled
className="menu-item-label"
key={item.label}
variant={item.variant}
{...item}
{...getItemProps({
item,
index,
onClick: item.onClick,
})}
isSelected={index === highlightedIndex}
>
{item.label}
</DropdownMenuItemStyled>
);
})}
</DropdownMenuStyled>
</DropdownStyled>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/navbar/Navbar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const NavbarContainer = styled.div`
.sc-trigger-text {
color: ${getThemePropSelector('textPrimary')};
}
border-bottom: 0.5px solid ${(props) => props.theme.backgroundLevel3};
box-sizing: border-box;
border-bottom: 0.5px solid ${(props) => props.theme.backgroundLevel2};
`};
`;
const NavbarMenu = styled.div`
Expand Down Expand Up @@ -122,7 +122,7 @@ const NavbarMenuItem = styled.div`
&:hover {
background-color: ${getThemePropSelector('highlight')};
}
height: ${navbarHeight};
height: auto;
font-size: ${fontSize.base};
}
.menu-item {
Expand Down
Loading