Skip to content

Commit

Permalink
feat: add scrollable props for DropdownContent (#710)
Browse files Browse the repository at this point in the history
* feat: add scrollable props

* feat: add description of scrollable props
  • Loading branch information
im36-123 committed Apr 2, 2020
1 parent 9eda849 commit 9559404
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ storiesOf('Dropdown', module)
</Dropdown>
</Box>
</li>
<li>
<Box>
<Dropdown>
<DropdownTrigger>
<SecondaryButton>Non-scroll dropdown</SecondaryButton>
</DropdownTrigger>
<DropdownContent scrollable={false}>
<ListMenu />
<ListMenu />
</DropdownContent>
</Dropdown>
</Box>
</li>
<li>
<Box>
<ControllableDropdown />
Expand Down
8 changes: 7 additions & 1 deletion src/components/Dropdown/DropdownContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export const DropdownContentContext = React.createContext<{

type Props = {
controllable?: boolean
scrollable?: boolean
className?: string
}

export const DropdownContent: React.FC<Props> = ({
controllable = false,
scrollable = true,
className = '',
children,
}) => {
Expand All @@ -27,7 +29,11 @@ export const DropdownContent: React.FC<Props> = ({
return (
<DropdownContentRoot>
<DropdownContentContext.Provider value={{ onClickCloser }}>
<DropdownContentInner triggerRect={triggerRect} className={`${dropdownKey} ${className}`}>
<DropdownContentInner
triggerRect={triggerRect}
scrollable={scrollable}
className={`${dropdownKey} ${className}`}
>
{controllable ? children : <DropdownCloser>{children}</DropdownCloser>}
</DropdownContentInner>
</DropdownContentContext.Provider>
Expand Down
15 changes: 11 additions & 4 deletions src/components/Dropdown/DropdownContentInner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ import { Rect, getContentBoxStyle, ContentBoxStyle } from './dropdownHelper'

type Props = {
triggerRect: Rect
scrollable: boolean
children: React.ReactNode
className: string
}

export const DropdownContentInner: FC<Props> = ({ triggerRect, children, className }) => {
export const DropdownContentInner: FC<Props> = ({
triggerRect,
scrollable,
children,
className,
}) => {
const theme = useTheme()
const [isMounted, setIsMounted] = useState(false)
const [isActive, setIsActive] = useState(false)
Expand Down Expand Up @@ -53,6 +59,7 @@ export const DropdownContentInner: FC<Props> = ({ triggerRect, children, classNa
<Wrapper
ref={wrapperRef}
contentBox={contentBox}
scrollable={scrollable}
className={`${className} ${isActive ? 'active' : ''}`}
themes={theme}
>
Expand All @@ -61,8 +68,8 @@ export const DropdownContentInner: FC<Props> = ({ triggerRect, children, classNa
)
}

const Wrapper = styled.div<{ themes: Theme; contentBox: ContentBoxStyle }>`
${({ contentBox, themes }) => {
const Wrapper = styled.div<{ themes: Theme; contentBox: ContentBoxStyle; scrollable: boolean }>`
${({ contentBox, themes, scrollable }) => {
return css`
visibility: hidden;
z-index: 99999;
Expand All @@ -78,7 +85,7 @@ const Wrapper = styled.div<{ themes: Theme; contentBox: ContentBoxStyle }>`
visibility: visible;
}
${contentBox.maxHeight
${contentBox.maxHeight && scrollable
? `
overflow-y: scroll;
max-height: ${contentBox.maxHeight};
Expand Down
9 changes: 5 additions & 4 deletions src/components/Dropdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ import { Dropdown, DropdownTrigger, DropdownContent, DropdownCloser } from 'smar

**DropdownContent**

| Name | Required | Type | DefaultValue | Description |
| ------------ | -------- | ---------------------------------- | ------------ | -------------------------------------- |
| controllable | - | **boolean** <br> true &#124; false | false | Use controllable content when its true |
| className | - | **string** | '' | className of DropdownContent |
| Name | Required | Type | DefaultValue | Description |
| ------------ | -------- | ---------------------------------- | ------------ | ----------------------------------------------------------------------------------------- |
| controllable | - | **boolean** <br> true &#124; false | false | Use controllable content when its true |
| scrollable | - | **boolean** <br> true &#124; false | true | If true, the content will automatically be scrollable when the window size is not enough. |
| className | - | **string** | '' | className of DropdownContent |

0 comments on commit 9559404

Please sign in to comment.