-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow Container render without a max width
- Loading branch information
Showing
6 changed files
with
88 additions
and
61 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable react/require-default-props */ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import RBContainer, { type ContainerProps as RBContainerProps } from 'react-bootstrap/Container'; | ||
|
||
import type { ComponentWithAsProp } from '../utils/types/bootstrap'; | ||
|
||
enum ContainerSizeClass { | ||
xs = 'container-mw-xs', | ||
sm = 'container-mw-sm', | ||
md = 'container-mw-md', | ||
lg = 'container-mw-lg', | ||
xl = 'container-mw-xl', | ||
} | ||
|
||
export type ContainerSize = keyof typeof ContainerSizeClass; | ||
|
||
interface ContainerProps extends RBContainerProps { | ||
size?: ContainerSize; | ||
} | ||
|
||
type ContainerType = ComponentWithAsProp<'div', ContainerProps> & { Deprecated?: any }; | ||
|
||
const Container: ContainerType = React.forwardRef<HTMLDivElement, ContainerProps>(({ | ||
size, | ||
children, | ||
...props | ||
}, ref) => ( | ||
<RBContainer | ||
bsPrefix="container" | ||
fluid | ||
{...props} | ||
ref={ref} | ||
className={classNames( | ||
props.className, | ||
size && ContainerSizeClass[size], | ||
)} | ||
> | ||
{children} | ||
</RBContainer> | ||
)); | ||
|
||
Container.propTypes = { | ||
...RBContainer.propTypes, | ||
/** Override the base element */ | ||
as: PropTypes.elementType, | ||
/** Specifies the contents of the container */ | ||
children: PropTypes.node, | ||
/** Fill all available space at any breakpoint */ | ||
fluid: PropTypes.bool, | ||
/** Set the maximum width for the container */ | ||
size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', undefined]), | ||
/** Overrides underlying component base CSS class name */ | ||
bsPrefix: PropTypes.string, | ||
}; | ||
|
||
Container.defaultProps = { | ||
as: 'div', | ||
children: undefined, | ||
fluid: true, | ||
size: undefined, | ||
bsPrefix: 'container', | ||
}; | ||
|
||
export default Container; |
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