-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sheet): new Sheet modal component
- Loading branch information
1 parent
79c323e
commit 15af2f7
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
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,76 @@ | ||
import React from 'react'; | ||
import { cls } from '../shared/cls.js'; | ||
import { positionClass } from '../shared/position-class.js'; | ||
import { useThemeClasses } from '../shared/use-theme-classes.js'; | ||
|
||
const Sheet = (props) => { | ||
const { | ||
component = 'div', | ||
className, | ||
colors: colorsProp, | ||
|
||
opened, | ||
backdrop = true, | ||
onBackdropClick, | ||
|
||
ios, | ||
material, | ||
|
||
// Children | ||
children, | ||
|
||
// Rest | ||
...rest | ||
} = props; | ||
|
||
const state = opened ? 'opened' : 'closed'; | ||
|
||
const Component = component; | ||
|
||
const attrs = { | ||
...rest, | ||
}; | ||
|
||
const colors = { | ||
bg: 'bg-white dark:bg-black', | ||
...colorsProp, | ||
}; | ||
|
||
const themeClasses = useThemeClasses({ ios, material }); | ||
|
||
const c = themeClasses( | ||
{ | ||
base: { | ||
common: cls( | ||
'left-0 top-full transition-transform duration-400 z-40 overflow-hidden', | ||
colors.bg, | ||
positionClass('fixed', className) | ||
), | ||
ios: '', | ||
material: 'shadow-2xl', | ||
opened: '-translate-y-full', | ||
closed: '', | ||
}, | ||
backdrop: { | ||
common: | ||
'fixed z-40 w-full h-full left-0 top-0 bg-black bg-opacity-50 duration-400', | ||
opened: '', | ||
closed: 'opacity-0 pointer-events-none', | ||
}, | ||
}, | ||
className | ||
); | ||
|
||
return ( | ||
<> | ||
{backdrop && ( | ||
<div className={c.backdrop[state]} onClick={onBackdropClick} /> | ||
)} | ||
<Component className={c.base[state]} {...attrs}> | ||
{children} | ||
</Component> | ||
</> | ||
); | ||
}; | ||
|
||
export default Sheet; |
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