-
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: migrates Container to TypeScript; Container without max-width o…
…n docs site [FC-0062] (#3216)
- Loading branch information
Showing
6 changed files
with
86 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,64 @@ | ||
/* 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>; | ||
|
||
const Container: ContainerType = React.forwardRef<Element, ContainerProps>(({ | ||
size, | ||
children, | ||
...props | ||
}, ref) => ( | ||
<RBContainer | ||
{...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. Omiting the prop will remove the max-width */ | ||
size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']), | ||
/** 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