-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
125fda7
commit c87e4c9
Showing
9 changed files
with
254 additions
and
43 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
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
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,39 @@ | ||
import * as React from 'react' | ||
import { SemanticShorthandContent } from '../../generic' | ||
|
||
export interface ModalDimmerProps extends StrictModalDimmerProps { | ||
[key: string]: any | ||
} | ||
|
||
export interface StrictModalDimmerProps { | ||
/** An element type to render as (string or function). */ | ||
as?: any | ||
|
||
/** A dimmer can be blurred. */ | ||
blurring?: boolean | ||
|
||
/** Primary content. */ | ||
children?: React.ReactNode | ||
|
||
/** Additional classes. */ | ||
className?: string | ||
|
||
/** A dimmer can center its contents in the viewport. */ | ||
centered?: boolean | ||
|
||
/** Shorthand for primary content. */ | ||
content?: SemanticShorthandContent | ||
|
||
/** A dimmer can be inverted. */ | ||
inverted?: boolean | ||
|
||
/** The node where the modal should mount. Defaults to document.body. */ | ||
mountNode?: any | ||
|
||
/** A dimmer can make body scrollable. */ | ||
scrolling?: boolean | ||
} | ||
|
||
declare const ModalDimmer: React.StatelessComponent<ModalDimmerProps> | ||
|
||
export default ModalDimmer |
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,87 @@ | ||
import { Ref } from '@stardust-ui/react-component-ref' | ||
import cx from 'clsx' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
import MountNode from '../../addons/MountNode' | ||
import { | ||
childrenUtils, | ||
createShorthandFactory, | ||
customPropTypes, | ||
getElementType, | ||
getUnhandledProps, | ||
useKeyOnly, | ||
} from '../../lib' | ||
|
||
/** | ||
* A modal has a dimmer. | ||
*/ | ||
function ModalDimmer(props) { | ||
const { blurring, children, className, centered, content, inverted, mountNode, scrolling } = props | ||
const ref = React.useRef() | ||
|
||
const classes = cx( | ||
'ui', | ||
useKeyOnly(inverted, 'inverted'), | ||
!centered && 'top aligned', | ||
'page modals dimmer transition visible active', | ||
className, | ||
) | ||
const bodyClasses = cx( | ||
'dimmable dimmed', | ||
useKeyOnly(blurring, ' blurring'), | ||
useKeyOnly(scrolling, 'scrolling'), | ||
) | ||
|
||
const rest = getUnhandledProps(ModalDimmer, props) | ||
const ElementType = getElementType(ModalDimmer, props) | ||
|
||
React.useEffect(() => { | ||
if (ref.current && ref.current.style) { | ||
ref.current.style.setProperty('display', 'flex', 'important') | ||
} | ||
}, []) | ||
|
||
return ( | ||
<Ref innerRef={ref}> | ||
<ElementType {...rest} className={classes}> | ||
{childrenUtils.isNil(children) ? content : children} | ||
|
||
<MountNode className={bodyClasses} node={mountNode} /> | ||
</ElementType> | ||
</Ref> | ||
) | ||
} | ||
|
||
ModalDimmer.propTypes = { | ||
/** An element type to render as (string or function). */ | ||
as: PropTypes.elementType, | ||
|
||
/** A dimmer can be blurred. */ | ||
blurring: PropTypes.bool, | ||
|
||
/** Primary content. */ | ||
children: PropTypes.node, | ||
|
||
/** Additional classes. */ | ||
className: PropTypes.string, | ||
|
||
/** A dimmer can center its contents in the viewport. */ | ||
centered: PropTypes.bool, | ||
|
||
/** Shorthand for primary content. */ | ||
content: customPropTypes.contentShorthand, | ||
|
||
/** A dimmer can be inverted. */ | ||
inverted: PropTypes.bool, | ||
|
||
/** The node where the modal should mount. Defaults to document.body. */ | ||
mountNode: PropTypes.any, | ||
|
||
/** A dimmer can make body scrollable. */ | ||
scrolling: PropTypes.bool, | ||
} | ||
|
||
ModalDimmer.create = createShorthandFactory(ModalDimmer, (content) => ({ content })) | ||
|
||
export default ModalDimmer |
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
Oops, something went wrong.