@dhis2-ui/field 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/field",
3
- "version": "10.16.2",
3
+ "version": "10.16.3-alpha.1",
4
4
  "description": "UI Field",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,16 +33,17 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2-ui/box": "10.16.2",
37
- "@dhis2-ui/help": "10.16.2",
38
- "@dhis2-ui/label": "10.16.2",
39
- "@dhis2/ui-constants": "10.16.2",
36
+ "@dhis2-ui/box": "10.16.3-alpha.1",
37
+ "@dhis2-ui/help": "10.16.3-alpha.1",
38
+ "@dhis2-ui/label": "10.16.3-alpha.1",
39
+ "@dhis2/ui-constants": "10.16.3-alpha.1",
40
40
  "classnames": "^2.3.1",
41
41
  "prop-types": "^15.7.2"
42
42
  },
43
43
  "files": [
44
44
  "build",
45
- "types"
45
+ "types",
46
+ "src"
46
47
  ],
47
48
  "devDependencies": {
48
49
  "react": "^18.3.1",
@@ -0,0 +1,10 @@
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
2
+
3
+ Given('a Field with children is rendered', () => {
4
+ cy.visitStory('Field', 'With children')
5
+ cy.get('[data-test="dhis2-uicore-field"]').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 Field renders children
2
+
3
+ Scenario: A Field with children
4
+ Given a Field with children is rendered
5
+ Then the children are visible
@@ -0,0 +1,5 @@
1
+ import React from 'react'
2
+ import { Field } from './field.js'
3
+
4
+ export default { title: 'Field' }
5
+ export const WithChildren = () => <Field>I am a child</Field>
@@ -0,0 +1,93 @@
1
+ import { sharedPropTypes } from '@dhis2/ui-constants'
2
+ import { Box } from '@dhis2-ui/box'
3
+ import { Help } from '@dhis2-ui/help'
4
+ import { Label } from '@dhis2-ui/label'
5
+ import PropTypes from 'prop-types'
6
+ import React from 'react'
7
+
8
+ const Field = ({
9
+ children,
10
+ className,
11
+ disabled,
12
+ helpText,
13
+ label,
14
+ labelId,
15
+ name,
16
+ validationText,
17
+ required,
18
+ dataTest = 'dhis2-uicore-field',
19
+ valid,
20
+ error,
21
+ warning,
22
+ }) => (
23
+ <Box className={className} dataTest={dataTest}>
24
+ {label && (
25
+ <Label
26
+ id={labelId}
27
+ dataTest={`${dataTest}-label`}
28
+ required={required}
29
+ disabled={disabled}
30
+ htmlFor={name}
31
+ >
32
+ {label}
33
+ </Label>
34
+ )}
35
+
36
+ <Box dataTest={`${dataTest}-content`} marginTop={label ? '2px' : '0'}>
37
+ {children}
38
+ </Box>
39
+
40
+ {helpText && <Help dataTest={`${dataTest}-help`}>{helpText}</Help>}
41
+
42
+ {validationText && (
43
+ <Help
44
+ error={error}
45
+ warning={warning}
46
+ valid={valid}
47
+ dataTest={`${dataTest}-validation`}
48
+ >
49
+ {validationText}
50
+ </Help>
51
+ )}
52
+ </Box>
53
+ )
54
+
55
+ Field.propTypes = {
56
+ children: PropTypes.node,
57
+
58
+ className: PropTypes.string,
59
+
60
+ dataTest: PropTypes.string,
61
+
62
+ /** Disabled status, shown when mouse is over label */
63
+ disabled: PropTypes.bool,
64
+
65
+ /** Field status. Mutually exclusive with `valid` and `warning` props */
66
+ error: sharedPropTypes.statusPropType,
67
+
68
+ /** Useful text within the field */
69
+ helpText: PropTypes.string,
70
+
71
+ /** Label at the top of the field */
72
+ label: PropTypes.string,
73
+
74
+ /** id passed to the label element */
75
+ labelId: PropTypes.string,
76
+
77
+ /** `name` will become the target of the `for`/`htmlFor` attribute on the `<label>` element */
78
+ name: PropTypes.string,
79
+
80
+ /** Inidcates this field is required */
81
+ required: PropTypes.bool,
82
+
83
+ /** Field status. Mutually exclusive with `error` and `warning` props */
84
+ valid: sharedPropTypes.statusPropType,
85
+
86
+ /** Feedback given related to validation status of field */
87
+ validationText: PropTypes.string,
88
+
89
+ /** Field status. Mutually exclusive with `valid` and `error` props */
90
+ warning: sharedPropTypes.statusPropType,
91
+ }
92
+
93
+ export { Field }
@@ -0,0 +1,51 @@
1
+ import { sharedPropTypes } from '@dhis2/ui-constants'
2
+ import { Input } from '@dhis2-ui/input'
3
+ import React from 'react'
4
+ import { Field } from './field.js'
5
+
6
+ const description = `
7
+ A useful container for form components, including a label, help text, and validation text.
8
+
9
+ \`\`\`js
10
+ import { Field } from '@dhis2/ui'
11
+ \`\`\`
12
+ `
13
+
14
+ export default {
15
+ title: 'Field',
16
+ component: Field,
17
+ argTypes: {
18
+ valid: { ...sharedPropTypes.statusArgType },
19
+ warning: { ...sharedPropTypes.statusArgType },
20
+ error: { ...sharedPropTypes.statusArgType },
21
+ },
22
+ parameters: { docs: { description: { component: description } } },
23
+ }
24
+
25
+ export const Default = (args) => (
26
+ <>
27
+ <Field {...args}>
28
+ <Input
29
+ onChange={() => {
30
+ console.log('Nothing happens')
31
+ }}
32
+ name="input"
33
+ label="An input"
34
+ />
35
+ </Field>
36
+ <Field helpText="Help!" label="Second field">
37
+ <Input
38
+ onChange={() => {
39
+ console.log('Nothing happens')
40
+ }}
41
+ name="input2"
42
+ label="An second input"
43
+ />
44
+ </Field>
45
+ </>
46
+ )
47
+ Default.args = {
48
+ label: 'First field (change me with controls)',
49
+ helpText: 'Help text!',
50
+ validationText: "I'm validation text",
51
+ }
@@ -0,0 +1 @@
1
+ export { Field } from './field.js'
@@ -0,0 +1,11 @@
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
2
+
3
+ Given('a FieldGroup with label and a required flag is rendered', () => {
4
+ cy.visitStory('FieldGroup', 'With label and required')
5
+ })
6
+
7
+ Then('the required indicator is visible', () => {
8
+ cy.get('[data-test="dhis2-uicore-field-label-required"]').should(
9
+ 'be.visible'
10
+ )
11
+ })
@@ -0,0 +1,5 @@
1
+ Feature: Required status for the FieldGroup
2
+
3
+ Scenario: Rendering a FieldGroup that is required
4
+ Given a FieldGroup with label and a required flag is rendered
5
+ Then the required indicator is visible
@@ -0,0 +1,17 @@
1
+ import { Checkbox } from '@dhis2-ui/checkbox'
2
+ import React from 'react'
3
+ import { FieldGroup } from './field-group.js'
4
+
5
+ export default { title: 'FieldGroup' }
6
+ export const WithLabelAndRequired = () => (
7
+ <FieldGroup
8
+ label="I am a required label"
9
+ name="required"
10
+ value={['second', 'third']}
11
+ required
12
+ >
13
+ <Checkbox value="first" label="First" />
14
+ <Checkbox value="second" label="Second" />
15
+ <Checkbox value="third" label="Third" />
16
+ </FieldGroup>
17
+ )
@@ -0,0 +1,61 @@
1
+ import { sharedPropTypes } from '@dhis2/ui-constants'
2
+ import PropTypes from 'prop-types'
3
+ import React from 'react'
4
+ import { Field } from '../field/index.js'
5
+ import { FieldSet } from '../field-set/index.js'
6
+ const FieldGroup = ({
7
+ children,
8
+ className,
9
+ disabled,
10
+ helpText,
11
+ validationText,
12
+ label,
13
+ name,
14
+ required,
15
+ dataTest = 'dhis2-uiwidgets-fieldsetfield',
16
+ valid,
17
+ error,
18
+ warning,
19
+ }) => (
20
+ <FieldSet classname={className} dataTest={dataTest}>
21
+ <Field
22
+ label={label}
23
+ disabled={disabled}
24
+ required={required}
25
+ helpText={helpText}
26
+ validationText={validationText}
27
+ error={error}
28
+ warning={warning}
29
+ valid={valid}
30
+ name={name}
31
+ >
32
+ {children}
33
+ </Field>
34
+ </FieldSet>
35
+ )
36
+
37
+ FieldGroup.propTypes = {
38
+ children: PropTypes.node,
39
+ className: PropTypes.string,
40
+ dataTest: PropTypes.string,
41
+ /** Disables the form controls within */
42
+ disabled: PropTypes.bool,
43
+ /** Applies 'error' styling to validation text for feedback. Mutually exclusive with `warning` and `valid` props */
44
+ error: sharedPropTypes.statusPropType,
45
+ /** Useful instructions for the user */
46
+ helpText: PropTypes.string,
47
+ /** Labels the Field Group */
48
+ label: PropTypes.string,
49
+ /** Name associate with the Field Group. Passed in object as argument to event handlers */
50
+ name: PropTypes.string,
51
+ /** Adds an asterisk to indicate this field is required */
52
+ required: PropTypes.bool,
53
+ /** Applies 'valid' styling to validation text for feedback. Mutually exclusive with `warning` and `error` props */
54
+ valid: sharedPropTypes.statusPropType,
55
+ /** Adds text at the bottom of the field to provide validation feedback. Acquires styles from `valid`, `warning` and `error` statuses */
56
+ validationText: PropTypes.string,
57
+ /** Applies 'warning' styling to validation text for feedback. Mutually exclusive with `valid` and `error` props */
58
+ warning: sharedPropTypes.statusPropType,
59
+ }
60
+
61
+ export { FieldGroup }
@@ -0,0 +1,110 @@
1
+ import { sharedPropTypes } from '@dhis2/ui-constants'
2
+ import { Checkbox } from '@dhis2-ui/checkbox'
3
+ import { Radio } from '@dhis2-ui/radio'
4
+ import { Switch } from '@dhis2-ui/switch'
5
+ import React from 'react'
6
+ import { FieldGroup } from './field-group.js'
7
+
8
+ const description = `
9
+ Wraps a group of form components like Radios, Checkboxes, or Switches. The FieldGroup wraps the form controls in a FieldSet and a Field component to group them and add a label, help text, and/or validation text.
10
+
11
+ \`\`\`js
12
+ import { FieldGroup } from '@dhis2/ui'
13
+ \`\`\`
14
+ `
15
+
16
+ export default {
17
+ title: 'Field Group',
18
+ component: FieldGroup,
19
+ parameters: { docs: { description: { component: description } } },
20
+ argTypes: {
21
+ valid: { ...sharedPropTypes.statusArgType },
22
+ warning: { ...sharedPropTypes.statusArgType },
23
+ error: { ...sharedPropTypes.statusArgType },
24
+ },
25
+ }
26
+
27
+ export const WithCheckbox = (args) => (
28
+ <FieldGroup {...args}>
29
+ <Checkbox value="first" label="First" />
30
+ <Checkbox value="second" label="Second" />
31
+ <Checkbox value="third" label="Third" />
32
+ </FieldGroup>
33
+ )
34
+
35
+ export const WithRadio = (args) => (
36
+ <FieldGroup {...args}>
37
+ <Radio value="first" label="First" />
38
+ <Radio value="second" label="Second" checked />
39
+ <Radio value="third" label="Third" />
40
+ <Radio value="fourth" label="Fourth" />
41
+ </FieldGroup>
42
+ )
43
+
44
+ export const WithSwitch = (args) => (
45
+ <FieldGroup {...args}>
46
+ <Switch value="first" label="First" />
47
+ <Switch value="second" label="Second" />
48
+ <Switch value="third" label="Third" />
49
+ <Switch value="fourth" label="Fourth" />
50
+ </FieldGroup>
51
+ )
52
+
53
+ export const WithLabel = (args) => (
54
+ <>
55
+ <FieldGroup {...args}>
56
+ <Checkbox value="first" label="First" />
57
+ <Checkbox value="second" label="Second" />
58
+ <Checkbox value="third" label="Third" />
59
+ </FieldGroup>
60
+ <FieldGroup label="I am a required field" required>
61
+ <Checkbox value="first" label="First" />
62
+ <Checkbox value="second" label="Second" />
63
+ <Checkbox value="third" label="Third" />
64
+ </FieldGroup>
65
+ </>
66
+ )
67
+ WithLabel.args = { label: 'I am a label/legend' }
68
+
69
+ export const HelpAndValidationTexts = (args) => (
70
+ <>
71
+ <FieldGroup {...args}>
72
+ <Checkbox value="first" label="First" />
73
+ <Checkbox value="second" label="Second" />
74
+ <Checkbox value="third" label="Third" />
75
+ </FieldGroup>
76
+ <FieldGroup label="I am a legend" helpText="I am disabled" disabled>
77
+ <Checkbox value="first" label="First" disabled />
78
+ <Checkbox value="second" label="Second" disabled />
79
+ <Checkbox value="third" label="Third" disabled />
80
+ </FieldGroup>
81
+ <FieldGroup label="I am a legend" valid validationText="I am valid">
82
+ <Checkbox value="first" label="First" />
83
+ <Checkbox value="second" label="Second" checked />
84
+ <Checkbox value="third" label="Third" checked />
85
+ </FieldGroup>
86
+ <FieldGroup
87
+ label="I am a legend"
88
+ name="warning"
89
+ warning
90
+ validationText="I have a warning"
91
+ >
92
+ <Checkbox value="first" label="First" />
93
+ <Checkbox value="second" label="Second" />
94
+ <Checkbox value="third" label="Third" />
95
+ </FieldGroup>
96
+ <FieldGroup
97
+ label="I am a legend"
98
+ error
99
+ validationText="I have an error"
100
+ >
101
+ <Checkbox value="first" label="First" />
102
+ <Checkbox value="second" label="Second" />
103
+ <Checkbox value="third" label="Third" />
104
+ </FieldGroup>
105
+ </>
106
+ )
107
+ HelpAndValidationTexts.args = {
108
+ label: 'I am a field',
109
+ helpText: 'I am help text!',
110
+ }
@@ -0,0 +1 @@
1
+ export { FieldGroup } from './field-group.js'
@@ -0,0 +1,10 @@
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
2
+
3
+ Given('a FieldSet with children is rendered', () => {
4
+ cy.visitStory('FieldSet', 'With children')
5
+ cy.get('[data-test="dhis2-uicore-fieldset"]').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 FieldSet renders children
2
+
3
+ Scenario: A FieldSet with children
4
+ Given a FieldSet with children is rendered
5
+ Then the children are visible
@@ -0,0 +1,5 @@
1
+ import React from 'react'
2
+ import { FieldSet } from './field-set.js'
3
+
4
+ export default { title: 'FieldSet' }
5
+ export const WithChildren = () => <FieldSet>I am a child</FieldSet>
@@ -0,0 +1,27 @@
1
+ import PropTypes from 'prop-types'
2
+ import React from 'react'
3
+
4
+ const FieldSet = ({
5
+ className,
6
+ children,
7
+ dataTest = 'dhis2-uicore-fieldset',
8
+ }) => (
9
+ <fieldset className={className} data-test={dataTest}>
10
+ {children}
11
+ <style jsx>{`
12
+ fieldset {
13
+ border: none;
14
+ margin: 0;
15
+ padding: 0;
16
+ }
17
+ `}</style>
18
+ </fieldset>
19
+ )
20
+
21
+ FieldSet.propTypes = {
22
+ children: PropTypes.node,
23
+ className: PropTypes.string,
24
+ dataTest: PropTypes.string,
25
+ }
26
+
27
+ export { FieldSet }
@@ -0,0 +1,66 @@
1
+ import { Help } from '@dhis2-ui/help'
2
+ import { Legend } from '@dhis2-ui/legend'
3
+ import { Radio } from '@dhis2-ui/radio'
4
+ import React from 'react'
5
+ import { Field } from '../index.js'
6
+ import { FieldSet } from './field-set.js'
7
+
8
+ const description = `
9
+ A container for grouping several Field components together. Use a \`<Legend>\` component to add helpful guiding text.
10
+
11
+ \`\`\`js
12
+ import { FieldSet } from '@dhis2/ui'
13
+ \`\`\`
14
+ `
15
+
16
+ const onChange = () => {
17
+ console.log('Radio was clicked, nothing else will happen')
18
+ }
19
+
20
+ export default {
21
+ title: 'Field Set',
22
+ component: FieldSet,
23
+ parameters: { docs: { description: { component: description } } },
24
+ }
25
+
26
+ export const Default = (args) => (
27
+ <FieldSet {...args}>
28
+ It renders something in a fieldset element without the browser styles
29
+ </FieldSet>
30
+ )
31
+
32
+ export const UsageExampleARadioButtonGroupWithErrorStatus = (args) => (
33
+ <FieldSet {...args}>
34
+ <Legend required>Choose an option</Legend>
35
+ <Field>
36
+ <Radio
37
+ onChange={onChange}
38
+ name="radio"
39
+ value="first"
40
+ label="First"
41
+ error
42
+ />
43
+ </Field>
44
+ <Field>
45
+ <Radio
46
+ onChange={onChange}
47
+ name="radio"
48
+ value="second"
49
+ label="Second"
50
+ error
51
+ />
52
+ </Field>
53
+ <Field>
54
+ <Radio
55
+ onChange={onChange}
56
+ name="radio"
57
+ value="third"
58
+ label="Third"
59
+ error
60
+ />
61
+ </Field>
62
+ <Help error>You really have to choose something!</Help>
63
+ </FieldSet>
64
+ )
65
+ UsageExampleARadioButtonGroupWithErrorStatus.storyName =
66
+ 'Usage example - a radio button group with error status'
@@ -0,0 +1 @@
1
+ export { FieldSet } from './field-set.js'
package/src/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Field } from './field/index.js'
2
+ export { FieldGroup } from './field-group/index.js'
3
+ export { FieldSet } from './field-set/index.js'