@openedx/paragon 22.7.0 → 22.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/paragon",
3
- "version": "22.7.0",
3
+ "version": "22.8.1",
4
4
  "description": "Accessible, responsive UI component library based on Bootstrap.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -353,6 +353,8 @@ a.pgn__card {
353
353
  bottom: #{-$card-logo-bottom-offset};
354
354
  width: $card-logo-width;
355
355
  height: $card-logo-height;
356
+ object-fit: scale-down;
357
+ object-position: center center;
356
358
  border-radius: $card-logo-border-radius;
357
359
  box-shadow: $level-1-box-shadow;
358
360
  padding: map_get($spacers, 2);
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
- import Container from '.';
3
+ import Container, { type ContainerSize } from '.';
4
4
 
5
- const getClassNames = (container) => container.className.split(' ');
5
+ const getClassNames = (container: HTMLElement) => container.className.split(' ');
6
6
 
7
7
  describe('<Container />', () => {
8
8
  it('displays children', () => {
@@ -12,32 +12,38 @@ describe('<Container />', () => {
12
12
 
13
13
  it('adds the .container-fluid class', () => {
14
14
  const { container } = render(<Container>Content</Container>);
15
- const containerElement = container.firstChild;
15
+ const containerElement = container.firstChild as HTMLElement;
16
16
  expect(getClassNames(containerElement)).toContain('container-fluid');
17
17
  });
18
18
 
19
19
  it('adds the .container class', () => {
20
20
  const { container } = render(<Container fluid={false}>Content</Container>);
21
- const containerElement = container.firstChild;
22
- expect(getClassNames(containerElement)).toContain('container');
21
+ const containerElement = container.firstChild as HTMLElement;
22
+ expect(getClassNames(containerElement!)).toContain('container');
23
23
  expect(getClassNames(containerElement)).not.toContain('container-fluid');
24
24
  });
25
25
 
26
- ['xs', 'sm', 'md', 'lg', 'xl'].forEach((size) => {
26
+ ['xs', 'sm', 'md', 'lg', 'xl'].forEach((size: ContainerSize) => {
27
27
  it(`adds the .container-mw-${size} class`, () => {
28
28
  const { container } = render(<Container size={size}>Content</Container>);
29
- const containerElement = container.firstChild;
29
+ const containerElement = container.firstChild as HTMLElement;
30
30
  expect(getClassNames(containerElement)).toContain(`container-mw-${size}`);
31
31
  });
32
32
  });
33
33
 
34
+ it('does not add a size class when size is not specified', () => {
35
+ const { container } = render(<Container>Content</Container>);
36
+ const containerElement = container.firstChild as HTMLElement;
37
+ expect(getClassNames(containerElement)).toEqual(['container-fluid']);
38
+ });
39
+
34
40
  it('preserves custom class names', () => {
35
41
  const { container } = render(
36
42
  <Container className="custom-class" size="md">
37
43
  Content
38
44
  </Container>,
39
45
  );
40
- const containerElement = container.firstChild;
46
+ const containerElement = container.firstChild as HTMLElement;
41
47
  expect(getClassNames(containerElement)).toContain('container-mw-md');
42
48
  expect(getClassNames(containerElement)).toContain('container-fluid');
43
49
  expect(getClassNames(containerElement)).toContain('custom-class');
@@ -19,6 +19,10 @@ The base container to contain, pad, and center content in the viewport. This com
19
19
  ```jsx live
20
20
  <div style={{ overflowX: 'auto' }}>
21
21
  <div style={{ width: '1500px', border: 'solid 3px red' }}>
22
+ <Container className="bg-danger-300 my-4">
23
+ The content in this container doesn't have a max width
24
+ </Container>
25
+
22
26
  <Container size="xl" className="bg-danger-300 my-4">
23
27
  The content in this container won't exceed the extra large width.
24
28
  </Container>
@@ -0,0 +1,64 @@
1
+ /* eslint-disable react/require-default-props */
2
+ import React from 'react';
3
+ import classNames from 'classnames';
4
+ import PropTypes from 'prop-types';
5
+ import RBContainer, { type ContainerProps as RBContainerProps } from 'react-bootstrap/Container';
6
+
7
+ import type { ComponentWithAsProp } from '../utils/types/bootstrap';
8
+
9
+ enum ContainerSizeClass {
10
+ xs = 'container-mw-xs',
11
+ sm = 'container-mw-sm',
12
+ md = 'container-mw-md',
13
+ lg = 'container-mw-lg',
14
+ xl = 'container-mw-xl',
15
+ }
16
+
17
+ export type ContainerSize = keyof typeof ContainerSizeClass;
18
+
19
+ interface ContainerProps extends RBContainerProps {
20
+ size?: ContainerSize;
21
+ }
22
+
23
+ type ContainerType = ComponentWithAsProp<'div', ContainerProps>;
24
+
25
+ const Container: ContainerType = React.forwardRef<Element, ContainerProps>(({
26
+ size,
27
+ children,
28
+ ...props
29
+ }, ref) => (
30
+ <RBContainer
31
+ {...props}
32
+ ref={ref}
33
+ className={classNames(
34
+ props.className,
35
+ size && ContainerSizeClass[size],
36
+ )}
37
+ >
38
+ {children}
39
+ </RBContainer>
40
+ ));
41
+
42
+ Container.propTypes = {
43
+ ...RBContainer.propTypes,
44
+ /** Override the base element */
45
+ as: PropTypes.elementType,
46
+ /** Specifies the contents of the container */
47
+ children: PropTypes.node,
48
+ /** Fill all available space at any breakpoint */
49
+ fluid: PropTypes.bool,
50
+ /** Set the maximum width for the container. Omiting the prop will remove the max-width */
51
+ size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
52
+ /** Overrides underlying component base CSS class name */
53
+ bsPrefix: PropTypes.string,
54
+ };
55
+
56
+ Container.defaultProps = {
57
+ as: 'div',
58
+ children: undefined,
59
+ fluid: true,
60
+ size: undefined,
61
+ bsPrefix: 'container',
62
+ };
63
+
64
+ export default Container;
package/src/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export { default as Bubble } from './Bubble';
8
8
  export { default as Button, ButtonGroup, ButtonToolbar } from './Button';
9
9
  export { default as Chip, CHIP_PGN_CLASS } from './Chip';
10
10
  export { default as ChipCarousel } from './ChipCarousel';
11
+ export { default as Container, ContainerSize } from './Container';
11
12
  export { default as Hyperlink, HYPER_LINK_EXTERNAL_LINK_ALT_TEXT, HYPER_LINK_EXTERNAL_LINK_TITLE } from './Hyperlink';
12
13
  export { default as Icon } from './Icon';
13
14
  export { default as IconButton, IconButtonWithTooltip } from './IconButton';
@@ -41,7 +42,6 @@ export const
41
42
  export const CheckBox: any; // from './CheckBox';
42
43
  export const CheckBoxGroup: any; // from './CheckBoxGroup';
43
44
  export const CloseButton: any; // from './CloseButton';
44
- export const Container: any; // from './Container';
45
45
  export const Layout: any, Col: any, Row: any; // from './Layout';
46
46
  export const Collapse: any; // from './Collapse';
47
47
  export const Collapsible: any; // from './Collapsible';
@@ -1,49 +0,0 @@
1
- import React, { forwardRef } from 'react';
2
- import classNames from 'classnames';
3
- import RBContainer from 'react-bootstrap/Container';
4
- import PropTypes from 'prop-types';
5
-
6
- const SIZE_CLASS_NAMES = {
7
- xs: 'container-mw-xs',
8
- sm: 'container-mw-sm',
9
- md: 'container-mw-md',
10
- lg: 'container-mw-lg',
11
- xl: 'container-mw-xl',
12
- };
13
-
14
- const Container = forwardRef(({ size, children, ...props }, ref) => (
15
- <RBContainer
16
- {...props}
17
- ref={ref}
18
- className={classNames(
19
- props.className,
20
- SIZE_CLASS_NAMES[size],
21
- )}
22
- >
23
- {children}
24
- </RBContainer>
25
- ));
26
-
27
- Container.propTypes = {
28
- ...RBContainer.propTypes,
29
- /** Override the base element */
30
- as: PropTypes.elementType,
31
- /** Specifies the contents of the container */
32
- children: PropTypes.node,
33
- /** Fill all available space at any breakpoint */
34
- fluid: PropTypes.bool,
35
- /** Set the maximum width for the container */
36
- size: PropTypes.oneOf(Object.keys(SIZE_CLASS_NAMES)),
37
- /** Overrides underlying component base CSS class name */
38
- bsPrefix: PropTypes.string,
39
- };
40
-
41
- Container.defaultProps = {
42
- as: 'div',
43
- children: undefined,
44
- fluid: true,
45
- size: undefined,
46
- bsPrefix: 'container',
47
- };
48
-
49
- export default Container;