@openedx/paragon 22.7.0 → 22.8.0

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.
@@ -0,0 +1,16 @@
1
+ import { type ContainerProps as RBContainerProps } from 'react-bootstrap/Container';
2
+ import type { ComponentWithAsProp } from '../utils/types/bootstrap';
3
+ declare enum ContainerSizeClass {
4
+ xs = "container-mw-xs",
5
+ sm = "container-mw-sm",
6
+ md = "container-mw-md",
7
+ lg = "container-mw-lg",
8
+ xl = "container-mw-xl"
9
+ }
10
+ export type ContainerSize = keyof typeof ContainerSizeClass;
11
+ interface ContainerProps extends RBContainerProps {
12
+ size?: ContainerSize;
13
+ }
14
+ type ContainerType = ComponentWithAsProp<'div', ContainerProps>;
15
+ declare const Container: ContainerType;
16
+ export default Container;
@@ -8,24 +8,26 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
9
9
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
10
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
- import React, { forwardRef } from 'react';
11
+ /* eslint-disable react/require-default-props */
12
+ import React from 'react';
12
13
  import classNames from 'classnames';
13
- import RBContainer from 'react-bootstrap/Container';
14
14
  import PropTypes from 'prop-types';
15
- var SIZE_CLASS_NAMES = {
16
- xs: 'container-mw-xs',
17
- sm: 'container-mw-sm',
18
- md: 'container-mw-md',
19
- lg: 'container-mw-lg',
20
- xl: 'container-mw-xl'
21
- };
22
- var Container = /*#__PURE__*/forwardRef(function (_ref, ref) {
15
+ import RBContainer from 'react-bootstrap/Container';
16
+ var ContainerSizeClass = /*#__PURE__*/function (ContainerSizeClass) {
17
+ ContainerSizeClass["xs"] = "container-mw-xs";
18
+ ContainerSizeClass["sm"] = "container-mw-sm";
19
+ ContainerSizeClass["md"] = "container-mw-md";
20
+ ContainerSizeClass["lg"] = "container-mw-lg";
21
+ ContainerSizeClass["xl"] = "container-mw-xl";
22
+ return ContainerSizeClass;
23
+ }(ContainerSizeClass || {});
24
+ var Container = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
23
25
  var size = _ref.size,
24
26
  children = _ref.children,
25
27
  props = _objectWithoutProperties(_ref, _excluded);
26
28
  return /*#__PURE__*/React.createElement(RBContainer, _extends({}, props, {
27
29
  ref: ref,
28
- className: classNames(props.className, SIZE_CLASS_NAMES[size])
30
+ className: classNames(props.className, size && ContainerSizeClass[size])
29
31
  }), children);
30
32
  });
31
33
  Container.propTypes = _objectSpread(_objectSpread({}, RBContainer.propTypes), {}, {
@@ -35,8 +37,8 @@ Container.propTypes = _objectSpread(_objectSpread({}, RBContainer.propTypes), {}
35
37
  children: PropTypes.node,
36
38
  /** Fill all available space at any breakpoint */
37
39
  fluid: PropTypes.bool,
38
- /** Set the maximum width for the container */
39
- size: PropTypes.oneOf(Object.keys(SIZE_CLASS_NAMES)),
40
+ /** Set the maximum width for the container. Omiting the prop will remove the max-width */
41
+ size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
40
42
  /** Overrides underlying component base CSS class name */
41
43
  bsPrefix: PropTypes.string
42
44
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["React","forwardRef","classNames","RBContainer","PropTypes","SIZE_CLASS_NAMES","xs","sm","md","lg","xl","Container","_ref","ref","size","children","props","_objectWithoutProperties","_excluded","createElement","_extends","className","propTypes","_objectSpread","as","elementType","node","fluid","bool","oneOf","Object","keys","bsPrefix","string","defaultProps","undefined"],"sources":["../../src/Container/index.jsx"],"sourcesContent":["import React, { forwardRef } from 'react';\nimport classNames from 'classnames';\nimport RBContainer from 'react-bootstrap/Container';\nimport PropTypes from 'prop-types';\n\nconst SIZE_CLASS_NAMES = {\n xs: 'container-mw-xs',\n sm: 'container-mw-sm',\n md: 'container-mw-md',\n lg: 'container-mw-lg',\n xl: 'container-mw-xl',\n};\n\nconst Container = forwardRef(({ size, children, ...props }, ref) => (\n <RBContainer\n {...props}\n ref={ref}\n className={classNames(\n props.className,\n SIZE_CLASS_NAMES[size],\n )}\n >\n {children}\n </RBContainer>\n));\n\nContainer.propTypes = {\n ...RBContainer.propTypes,\n /** Override the base element */\n as: PropTypes.elementType,\n /** Specifies the contents of the container */\n children: PropTypes.node,\n /** Fill all available space at any breakpoint */\n fluid: PropTypes.bool,\n /** Set the maximum width for the container */\n size: PropTypes.oneOf(Object.keys(SIZE_CLASS_NAMES)),\n /** Overrides underlying component base CSS class name */\n bsPrefix: PropTypes.string,\n};\n\nContainer.defaultProps = {\n as: 'div',\n children: undefined,\n fluid: true,\n size: undefined,\n bsPrefix: 'container',\n};\n\nexport default Container;\n"],"mappings":";;;;;;;;;;AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,WAAW,MAAM,2BAA2B;AACnD,OAAOC,SAAS,MAAM,YAAY;AAElC,IAAMC,gBAAgB,GAAG;EACvBC,EAAE,EAAE,iBAAiB;EACrBC,EAAE,EAAE,iBAAiB;EACrBC,EAAE,EAAE,iBAAiB;EACrBC,EAAE,EAAE,iBAAiB;EACrBC,EAAE,EAAE;AACN,CAAC;AAED,IAAMC,SAAS,gBAAGV,UAAU,CAAC,UAAAW,IAAA,EAA+BC,GAAG;EAAA,IAA/BC,IAAI,GAAAF,IAAA,CAAJE,IAAI;IAAEC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IAAKC,KAAK,GAAAC,wBAAA,CAAAL,IAAA,EAAAM,SAAA;EAAA,oBACtDlB,KAAA,CAAAmB,aAAA,CAAChB,WAAW,EAAAiB,QAAA,KACNJ,KAAK;IACTH,GAAG,EAAEA,GAAI;IACTQ,SAAS,EAAEnB,UAAU,CACnBc,KAAK,CAACK,SAAS,EACfhB,gBAAgB,CAACS,IAAI,CACvB;EAAE,IAEDC,QACU,CAAC;AAAA,CACf,CAAC;AAEFJ,SAAS,CAACW,SAAS,GAAAC,aAAA,CAAAA,aAAA,KACdpB,WAAW,CAACmB,SAAS;EACxB;EACAE,EAAE,EAAEpB,SAAS,CAACqB,WAAW;EACzB;EACAV,QAAQ,EAAEX,SAAS,CAACsB,IAAI;EACxB;EACAC,KAAK,EAAEvB,SAAS,CAACwB,IAAI;EACrB;EACAd,IAAI,EAAEV,SAAS,CAACyB,KAAK,CAACC,MAAM,CAACC,IAAI,CAAC1B,gBAAgB,CAAC,CAAC;EACpD;EACA2B,QAAQ,EAAE5B,SAAS,CAAC6B;AAAM,EAC3B;AAEDtB,SAAS,CAACuB,YAAY,GAAG;EACvBV,EAAE,EAAE,KAAK;EACTT,QAAQ,EAAEoB,SAAS;EACnBR,KAAK,EAAE,IAAI;EACXb,IAAI,EAAEqB,SAAS;EACfH,QAAQ,EAAE;AACZ,CAAC;AAED,eAAerB,SAAS","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","classNames","PropTypes","RBContainer","ContainerSizeClass","Container","forwardRef","_ref","ref","size","children","props","_objectWithoutProperties","_excluded","createElement","_extends","className","propTypes","_objectSpread","as","elementType","node","fluid","bool","oneOf","bsPrefix","string","defaultProps","undefined"],"sources":["../../src/Container/index.tsx"],"sourcesContent":["/* eslint-disable react/require-default-props */\nimport React from 'react';\nimport classNames from 'classnames';\nimport PropTypes from 'prop-types';\nimport RBContainer, { type ContainerProps as RBContainerProps } from 'react-bootstrap/Container';\n\nimport type { ComponentWithAsProp } from '../utils/types/bootstrap';\n\nenum ContainerSizeClass {\n xs = 'container-mw-xs',\n sm = 'container-mw-sm',\n md = 'container-mw-md',\n lg = 'container-mw-lg',\n xl = 'container-mw-xl',\n}\n\nexport type ContainerSize = keyof typeof ContainerSizeClass;\n\ninterface ContainerProps extends RBContainerProps {\n size?: ContainerSize;\n}\n\ntype ContainerType = ComponentWithAsProp<'div', ContainerProps>;\n\nconst Container: ContainerType = React.forwardRef<Element, ContainerProps>(({\n size,\n children,\n ...props\n}, ref) => (\n <RBContainer\n {...props}\n ref={ref}\n className={classNames(\n props.className,\n size && ContainerSizeClass[size],\n )}\n >\n {children}\n </RBContainer>\n));\n\nContainer.propTypes = {\n ...RBContainer.propTypes,\n /** Override the base element */\n as: PropTypes.elementType,\n /** Specifies the contents of the container */\n children: PropTypes.node,\n /** Fill all available space at any breakpoint */\n fluid: PropTypes.bool,\n /** Set the maximum width for the container. Omiting the prop will remove the max-width */\n size: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),\n /** Overrides underlying component base CSS class name */\n bsPrefix: PropTypes.string,\n};\n\nContainer.defaultProps = {\n as: 'div',\n children: undefined,\n fluid: true,\n size: undefined,\n bsPrefix: 'container',\n};\n\nexport default Container;\n"],"mappings":";;;;;;;;;;AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,UAAU,MAAM,YAAY;AACnC,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,WAAW,MAAmD,2BAA2B;AAAC,IAI5FC,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA,EAAlBA,kBAAkB;AAgBvB,IAAMC,SAAwB,gBAAGL,KAAK,CAACM,UAAU,CAA0B,UAAAC,IAAA,EAIxEC,GAAG;EAAA,IAHJC,IAAI,GAAAF,IAAA,CAAJE,IAAI;IACJC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IACLC,KAAK,GAAAC,wBAAA,CAAAL,IAAA,EAAAM,SAAA;EAAA,oBAERb,KAAA,CAAAc,aAAA,CAACX,WAAW,EAAAY,QAAA,KACNJ,KAAK;IACTH,GAAG,EAAEA,GAAI;IACTQ,SAAS,EAAEf,UAAU,CACnBU,KAAK,CAACK,SAAS,EACfP,IAAI,IAAIL,kBAAkB,CAACK,IAAI,CACjC;EAAE,IAEDC,QACU,CAAC;AAAA,CACf,CAAC;AAEFL,SAAS,CAACY,SAAS,GAAAC,aAAA,CAAAA,aAAA,KACdf,WAAW,CAACc,SAAS;EACxB;EACAE,EAAE,EAAEjB,SAAS,CAACkB,WAAW;EACzB;EACAV,QAAQ,EAAER,SAAS,CAACmB,IAAI;EACxB;EACAC,KAAK,EAAEpB,SAAS,CAACqB,IAAI;EACrB;EACAd,IAAI,EAAEP,SAAS,CAACsB,KAAK,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;EACrD;EACAC,QAAQ,EAAEvB,SAAS,CAACwB;AAAM,EAC3B;AAEDrB,SAAS,CAACsB,YAAY,GAAG;EACvBR,EAAE,EAAE,KAAK;EACTT,QAAQ,EAAEkB,SAAS;EACnBN,KAAK,EAAE,IAAI;EACXb,IAAI,EAAEmB,SAAS;EACfH,QAAQ,EAAE;AACZ,CAAC;AAED,eAAepB,SAAS","ignoreList":[]}
package/dist/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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/paragon",
3
- "version": "22.7.0",
3
+ "version": "22.8.0",
4
4
  "description": "Accessible, responsive UI component library based on Bootstrap.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -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;