@dhis2-ui/box 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/box",
3
- "version": "10.16.2",
3
+ "version": "10.16.3-alpha.1",
4
4
  "description": "UI Box",
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",
@@ -0,0 +1,10 @@
1
+ import React from 'react'
2
+ import { Box } from './box.js'
3
+
4
+ export default { title: 'Box' }
5
+ export const WithChildren = () => <Box>I am a child</Box>
6
+ export const Multiple = () => (
7
+ <Box marginTop="16px" maxWidth="400px">
8
+ I am a child in a Box.
9
+ </Box>
10
+ )
package/src/box.js ADDED
@@ -0,0 +1,46 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+
4
+ export const Box = ({
5
+ overflow,
6
+ height,
7
+ minHeight,
8
+ maxHeight,
9
+ width,
10
+ minWidth,
11
+ maxWidth,
12
+ marginTop,
13
+ children,
14
+ dataTest = 'dhis2-uicore-box',
15
+ className,
16
+ }) => (
17
+ <div data-test={dataTest} className={className}>
18
+ {children}
19
+ <style jsx>{`
20
+ div {
21
+ ${marginTop ? `margin-top: ${marginTop};` : ''}
22
+ ${height ? `height: ${height};` : ''}
23
+ ${minHeight ? `min-height: ${minHeight};` : ''}
24
+ ${maxHeight ? `max-height: ${maxHeight};` : ''}
25
+ ${width ? `width: ${width};` : ''}
26
+ ${minWidth ? `min-width: ${minWidth};` : ''}
27
+ ${maxWidth ? `max-width: ${maxWidth};` : ''}
28
+ ${overflow ? `overflow: ${overflow};` : ''}
29
+ }
30
+ `}</style>
31
+ </div>
32
+ )
33
+
34
+ Box.propTypes = {
35
+ children: PropTypes.node,
36
+ className: PropTypes.string,
37
+ dataTest: PropTypes.string,
38
+ height: PropTypes.string,
39
+ marginTop: PropTypes.string,
40
+ maxHeight: PropTypes.string,
41
+ maxWidth: PropTypes.string,
42
+ minHeight: PropTypes.string,
43
+ minWidth: PropTypes.string,
44
+ overflow: PropTypes.string,
45
+ width: PropTypes.string,
46
+ }
@@ -0,0 +1,58 @@
1
+ import React from 'react'
2
+ import { Box } from './box.js'
3
+
4
+ const description = `
5
+ A box for creating some layout on the page.
6
+
7
+ \`\`\`js
8
+ import { Box } from '@dhis2/ui'
9
+ \`\`\`
10
+ `
11
+
12
+ export default {
13
+ title: 'Box',
14
+ component: Box,
15
+ parameters: { docs: { description: { component: description } } },
16
+ }
17
+
18
+ const Template = (args) => <Box {...args} />
19
+
20
+ export const Default = Template.bind({})
21
+ Default.args = { children: 'I am a child in a Box.' }
22
+
23
+ export const Height = Template.bind({})
24
+ Height.args = {
25
+ ...Default.args,
26
+ height: '250px',
27
+ }
28
+
29
+ export const MaxHeight = Template.bind({})
30
+ MaxHeight.args = {
31
+ children: (
32
+ <p style={{ height: '500px' }}>I am a tall child in a low Box.</p>
33
+ ),
34
+ maxHeight: '250px',
35
+ }
36
+
37
+ export const MinHeight = Template.bind({})
38
+ MinHeight.args = { ...Default.args, minHeight: '50vh' }
39
+
40
+ export const Width = Template.bind({})
41
+ Width.args = { ...Default.args, width: '250px' }
42
+
43
+ export const MinWidth = Template.bind({})
44
+ MinWidth.args = { ...Default.args, minWidth: '50vh' }
45
+
46
+ export const MaxWidth = Template.bind({})
47
+ MaxWidth.args = { ...Default.args, maxWidth: '50vh' }
48
+
49
+ export const Overflow = Template.bind({})
50
+ Overflow.args = {
51
+ maxHeight: '250px',
52
+ overflow: 'scroll',
53
+ children: (
54
+ <p style={{ height: '500px' }}>
55
+ I am a tall child in a low Box, and my parent clips me
56
+ </p>
57
+ ),
58
+ }
@@ -0,0 +1,10 @@
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
2
+
3
+ Given('a Box with children is rendered', () => {
4
+ cy.visitStory('Box', 'With children')
5
+ cy.get('[data-test="dhis2-uicore-box"]').should('be.visible')
6
+ })
7
+
8
+ Then('the children are visible', () => {
9
+ cy.contains('I am a child').should('be.visible')
10
+ })
@@ -0,0 +1,5 @@
1
+ Feature: The Box renders children
2
+
3
+ Scenario: A Box with children
4
+ Given a Box with children is rendered
5
+ Then the children are visible
@@ -0,0 +1,12 @@
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
2
+
3
+ Given('a Box with multiple props is rendered', () => {
4
+ cy.visitStory('Box', 'Multiple')
5
+ cy.get('[data-test="dhis2-uicore-box"]').should('be.visible')
6
+ })
7
+
8
+ Then('the styles are all applied', () => {
9
+ cy.get('[data-test="dhis2-uicore-box"]')
10
+ .should('have.css', 'margin-top', '16px')
11
+ .should('have.css', 'max-width', '400px')
12
+ })
@@ -0,0 +1,5 @@
1
+ Feature: The Box accepts multiple props
2
+
3
+ Scenario: A Box with multiple props
4
+ Given a Box with multiple props is rendered
5
+ Then the styles are all applied
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Box } from './box.js'