-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from ensdomains/action-sheet
Action sheet
- Loading branch information
Showing
18 changed files
with
398 additions
and
188 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
pnpm lint-staged | ||
pnpm lint |
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,7 @@ | ||
dist | ||
coverage | ||
src/components/icons/generated | ||
|
||
node_modules | ||
pnpm-lock.yaml | ||
pnpm-workspace.yaml |
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
99 changes: 99 additions & 0 deletions
99
components/src/components/molecules/Dropdown/ActionSheet.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,99 @@ | ||
import * as React from 'react' | ||
import styled, { css } from 'styled-components' | ||
|
||
import { breakpoints } from '@/src/tokens' | ||
|
||
import { Button, Modal, Typography } from '../..' | ||
import type { DropdownItem, DropdownItemObject } from './Dropdown' | ||
|
||
const ActionSheetContent = styled.div( | ||
({ theme }) => css` | ||
width: 100%; | ||
flex-direction: column; | ||
padding: ${theme.space['2.5']}; | ||
gap: ${theme.space['2.5']}; | ||
display: flex; | ||
`, | ||
) | ||
|
||
const ActionSheetOptions = styled.div( | ||
({ theme }) => css` | ||
border-radius: ${theme.radii['large']}; | ||
width: ${theme.space['full']}; | ||
text-align: center; | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${theme.space.px}; | ||
`, | ||
) | ||
|
||
const ActionSheetItem = styled.div( | ||
({ theme }) => css` | ||
width: 100%; | ||
padding: 20px; | ||
position: relative; | ||
background: ${theme.colors.backgroundPrimary}; | ||
&:first-child { | ||
border-top-left-radius: ${theme.radii['large']}; | ||
border-top-right-radius: ${theme.radii['large']}; | ||
} | ||
&:last-child { | ||
border-bottom-left-radius: ${theme.radii['large']}; | ||
border-bottom-right-radius: ${theme.radii['large']}; | ||
} | ||
`, | ||
) | ||
|
||
type Props = { | ||
isOpen: boolean | ||
screenSize: number | ||
items: DropdownItem[] | ||
setIsOpen: React.Dispatch<React.SetStateAction<boolean>> | ||
DropdownChild: React.FC<{ | ||
setIsOpen: (isOpen: boolean) => void | ||
item: React.ReactElement<React.PropsWithRef<any>> | ||
}> | ||
cancelLabel?: string | ||
} | ||
export const ActionSheet = React.forwardRef<HTMLDivElement, Props>( | ||
( | ||
{ isOpen, screenSize, items, setIsOpen, DropdownChild, cancelLabel }, | ||
ref, | ||
) => ( | ||
<Modal | ||
mobileOnly | ||
open={isOpen} | ||
onDismiss={ | ||
screenSize < breakpoints.sm ? () => setIsOpen(false) : undefined | ||
} | ||
> | ||
<ActionSheetContent ref={ref}> | ||
<ActionSheetOptions> | ||
{items?.map((item) => { | ||
if (React.isValidElement(item)) { | ||
return DropdownChild({ item, setIsOpen }) | ||
} | ||
|
||
return ( | ||
<ActionSheetItem | ||
key={(item as DropdownItemObject).label} | ||
onClick={() => { | ||
;(item as DropdownItemObject)?.onClick?.( | ||
(item as DropdownItemObject).value, | ||
) | ||
setIsOpen(false) | ||
}} | ||
> | ||
<Typography>{(item as DropdownItemObject).label}</Typography> | ||
</ActionSheetItem> | ||
) | ||
})} | ||
</ActionSheetOptions> | ||
<Button colorStyle="greySecondary" onClick={() => setIsOpen(false)}> | ||
{cancelLabel} | ||
</Button> | ||
</ActionSheetContent> | ||
</Modal> | ||
), | ||
) |
Oops, something went wrong.