Skip to content

Commit

Permalink
Merge pull request #195 from dmytroshch/feature/dialog-style
Browse files Browse the repository at this point in the history
(feature) Dialog: add style prop
  • Loading branch information
bhoomij authored Aug 24, 2023
2 parents 68e9778 + fb481ac commit 18a236e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/core/src/components/ui/Dialog/Dialog.Modal.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import cx from 'classnames'
import FocusTrap from 'focus-trap-react'
import PropTypes from 'prop-types'
import React, { forwardRef, useRef } from 'react'
import React, { forwardRef, useMemo, useRef } from 'react'

import * as Classes from '../../../common/classes'
import { DIALOG_CONTAINER_ID } from './Dialog.constants'
import * as Classes from '../../../common/classes'

Check failure on line 7 in packages/core/src/components/ui/Dialog/Dialog.Modal.js

View workflow job for this annotation

GitHub Actions / checks (14.x)

`../../../common/classes` import should occur before import of `./Dialog.constants`

const Modal = forwardRef(({
state,
Expand All @@ -21,8 +21,16 @@ const Modal = forwardRef(({
width,
height,
textAlign,
style,
}, ref) => {
const titleRef = useRef()
const modalStyle = useMemo(() => ({
maxWidth: width,
height,
textAlign,
...style,
}), [width, height, textAlign, style])

return (
/* eslint-disable jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */
<FocusTrap
Expand All @@ -47,7 +55,7 @@ const Modal = forwardRef(({
'is-mobile-fullscreen': isFullscreenInMobile,
})}
ref={ref}
style={{ maxWidth: width, height, textAlign }}
style={modalStyle}
>
{title && (
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
Expand Down Expand Up @@ -137,6 +145,11 @@ Modal.propTypes = {
* Need to disable if modal contains iframe, to avoid conflicts
*/
isFocusTrapEnabled: PropTypes.bool.isRequired,
/**
* Style object of the Modal
*/
// eslint-disable-next-line react/forbid-prop-types
style: PropTypes.object,
}

Modal.defaultProps = {
Expand All @@ -150,6 +163,7 @@ Modal.defaultProps = {
width: 460,
height: 'auto',
textAlign: 'center',
style: {},
}

export default Modal
8 changes: 8 additions & 0 deletions packages/core/src/components/ui/Dialog/Dialog.Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Dialog = forwardRef(function Dialog(props, ref) {
height,
textAlign,
isFocusTrapEnabled,
style,
} = props

useEffect(() => {
Expand Down Expand Up @@ -77,6 +78,7 @@ const Dialog = forwardRef(function Dialog(props, ref) {
width={width}
height={height}
textAlign={textAlign}
style={style}
>
{children}
</Modal>
Expand Down Expand Up @@ -166,6 +168,11 @@ Dialog.propTypes = {
* Need to disable if modal contains iframe, to avoid conflicts
*/
isFocusTrapEnabled: PropTypes.bool,
/**
* Style object of the Modal
*/
// eslint-disable-next-line react/forbid-prop-types
style: PropTypes.object,
}

Dialog.defaultProps = {
Expand All @@ -182,6 +189,7 @@ Dialog.defaultProps = {
height: 'auto',
textAlign: 'center',
onSubmit: () => {},
style: {},
}

export default Dialog

0 comments on commit 18a236e

Please sign in to comment.