@dhis2-ui/center 10.16.2 → 10.16.3-alpha.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": "@dhis2-ui/center",
3
- "version": "10.16.2",
3
+ "version": "10.16.3-alpha.1",
4
4
  "description": "UI Center",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,13 +33,14 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2/ui-constants": "10.16.2",
36
+ "@dhis2/ui-constants": "10.16.3-alpha.1",
37
37
  "classnames": "^2.3.1",
38
38
  "prop-types": "^15.7.2"
39
39
  },
40
40
  "files": [
41
41
  "build",
42
- "types"
42
+ "types",
43
+ "src"
43
44
  ],
44
45
  "devDependencies": {
45
46
  "react": "^18.3.1",
package/src/center.js ADDED
@@ -0,0 +1,54 @@
1
+ import cx from 'classnames'
2
+ import PropTypes from 'prop-types'
3
+ import React, { forwardRef } from 'react'
4
+
5
+ export const Center = forwardRef(
6
+ (
7
+ {
8
+ className,
9
+ dataTest = 'dhis2-uicore-centeredcontent',
10
+ children,
11
+ position = 'middle',
12
+ },
13
+ ref
14
+ ) => (
15
+ <div
16
+ className={cx('center', className, position)}
17
+ data-test={dataTest}
18
+ ref={ref}
19
+ >
20
+ <div className="center-inner-content">{children}</div>
21
+
22
+ <style jsx>{`
23
+ .center {
24
+ width: 100%;
25
+ height: 100%;
26
+ display: flex;
27
+ justify-content: space-around;
28
+ flex-direction: row;
29
+ pointer-events: none;
30
+ align-items: center;
31
+ }
32
+ .center.top {
33
+ align-items: flex-start;
34
+ }
35
+ .center.bottom {
36
+ align-items: flex-end;
37
+ }
38
+ .center-inner-content {
39
+ pointer-events: all;
40
+ }
41
+ `}</style>
42
+ </div>
43
+ )
44
+ )
45
+
46
+ Center.displayName = 'Center'
47
+
48
+ Center.propTypes = {
49
+ children: PropTypes.node,
50
+ className: PropTypes.string,
51
+ dataTest: PropTypes.string,
52
+ /** Vertical alignment */
53
+ position: PropTypes.oneOf(['top', 'middle', 'bottom']),
54
+ }
@@ -0,0 +1,34 @@
1
+ import React from 'react'
2
+ import { Center } from './center.js'
3
+
4
+ const description = `
5
+ Centers children horizontally, and by default, vertically.
6
+ Use the \`top\` or \`bottom\` props to change vertical alignment.
7
+
8
+ \`\`\`js
9
+ import { CenteredContent } from '@dhis2/ui'
10
+ \`\`\`
11
+ `
12
+
13
+ const Wrapper = (story) => <div style={{ height: '150px' }}>{story()}</div>
14
+
15
+ export default {
16
+ title: 'Center',
17
+ component: Center,
18
+ decorators: [Wrapper],
19
+ parameters: { docs: { description: { component: description } } },
20
+ }
21
+
22
+ const Template = (args) => (
23
+ <Center {...args}>
24
+ <span>Center me</span>
25
+ </Center>
26
+ )
27
+
28
+ export const Default = Template.bind({})
29
+
30
+ export const Top = Template.bind({})
31
+ Top.args = { position: 'top' }
32
+
33
+ export const Bottom = Template.bind({})
34
+ Bottom.args = { position: 'bottom' }
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Center } from './center.js'