Skip to content

Commit

Permalink
feat: add scrollable prop to Modal (#3469)
Browse files Browse the repository at this point in the history
bootstrap way ahead of me
  • Loading branch information
jquense committed Mar 21, 2019
1 parent d5e665a commit a7e800e
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 82 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"ci-lint": "eslint --rule \"prettier/prettier: 2\"",
"format": "npm run ci-lint . -- --fix",
"lint": "npm run ci-lint .",
"precommit": "lint-staged",
"release": "rollout",
"prepublishOnly": "npm run build",
"tdd": "karma start",
Expand All @@ -30,6 +29,11 @@
"build-storybook": "build-storybook",
"dtslint": "dtslint types"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"npm run ci-lint -- --fix",
Expand Down Expand Up @@ -103,7 +107,7 @@
"execa": "^1.0.0",
"fs-extra": "^7.0.1",
"husky": "^1.3.1",
"karma": "^3.1.4",
"karma": "^4.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^2.0.0",
"karma-coverage": "^1.1.2",
Expand Down
9 changes: 4 additions & 5 deletions src/ListGroupItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ class ListGroupItem extends React.Component {
*/
disabled: PropTypes.bool,

eventKey: PropTypes.string,

onClick: PropTypes.func,

/**
* You can use a custom element type for this component. For none `action` items, items render as `li`.
* For actions the default is an achor or button element depending on whether a `href` is provided.
*
* @default {'div' | 'a' | 'button'}
*/
as: PropTypes.elementType,

/** @private */
eventKey: PropTypes.any,
/** @private */
onClick: PropTypes.func,
};

static defaultProps = {
Expand Down
35 changes: 26 additions & 9 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { createBootstrapComponent } from './ThemeProvider';
import ModalContext from './ModalContext';

const propTypes = {
/** @default 'modal' */
/**
* @default 'modal'
*/
bsPrefix: PropTypes.string,

/**
Expand Down Expand Up @@ -51,6 +53,11 @@ const propTypes = {
*/
keyboard: PropTypes.bool,

/**
* Allows scrolling the `<Modal.Body>` instead of the entire Modal when overflowing.
*/
scrollable: PropTypes.bool,

This comment has been minimized.

Copy link
@Bartozzz

Bartozzz Mar 23, 2019

Contributor

@jquense Is this prop required here? It is not used in the <Modal /> component.

This comment has been minimized.

Copy link
@jquense

jquense Mar 24, 2019

Author Member

yes it does, it's passed to the ModalDialog component


/**
* Open and close the Modal with a slide and fade animation.
*/
Expand Down Expand Up @@ -94,7 +101,9 @@ const propTypes = {
*/
show: PropTypes.bool,

/** Callback fired when the modal has switch to `show` */
/**
* A callback fired when the Modal is opening.
*/
onShow: PropTypes.func,

/**
Expand All @@ -103,6 +112,11 @@ const propTypes = {
*/
onHide: PropTypes.func,

/**
* A callback fired when the escape key, if specified in `keyboard`, is pressed.
*/
onEscapeKeyDown: PropTypes.func,

/**
* Callback fired before the Modal transitions in
*/
Expand Down Expand Up @@ -133,13 +147,16 @@ const propTypes = {
*/
onExited: PropTypes.func,

/** @private */
container: PropTypes.any,
/**
* A ModalManager instance used to track and manage the state of open
* Modals. Useful when customizing how modals interact within a container
*/
manager: PropTypes.object.isRequired,

/** @private */
manager: PropTypes.any,
/** @private */
onEscapeKeyDown: PropTypes.any,
/**
* @private
*/
container: PropTypes.any,
};

const defaultProps = {
Expand Down Expand Up @@ -280,10 +297,10 @@ class Modal extends React.Component {

/* BaseModal props */
show,
manager,
animation,
backdrop,
keyboard,
manager,
onEscapeKeyDown,
onShow,
onHide,
Expand Down
11 changes: 10 additions & 1 deletion src/ModalDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ const propTypes = {
* Specify whether the Component should be vertically centered
*/
centered: PropTypes.bool,

/**
* Allows scrolling the `<Modal.Body>` instead of the entire Modal when overflowing.
*/
scrollable: PropTypes.bool,
};

const ModalDialog = React.forwardRef(
({ bsPrefix, className, centered, size, children, ...props }, ref) => {
(
{ bsPrefix, className, centered, size, children, scrollable, ...props },
ref,
) => {
bsPrefix = useBootstrapPrefix(bsPrefix, 'modal');
const dialogClass = `${bsPrefix}-dialog`;

Expand All @@ -35,6 +43,7 @@ const ModalDialog = React.forwardRef(
className,
size && `${bsPrefix}-${size}`,
centered && `${dialogClass}-centered`,
scrollable && `${bsPrefix}-scrollable`,
)}
>
<div className={classNames(`${bsPrefix}-content`)}>{children}</div>
Expand Down
Loading

0 comments on commit a7e800e

Please sign in to comment.