@dhis2-ui/legend 10.16.2 → 10.16.3

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/legend",
3
- "version": "10.16.2",
3
+ "version": "10.16.3",
4
4
  "description": "UI Legend",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,14 +33,15 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2-ui/required": "10.16.2",
37
- "@dhis2/ui-constants": "10.16.2",
36
+ "@dhis2-ui/required": "10.16.3",
37
+ "@dhis2/ui-constants": "10.16.3",
38
38
  "classnames": "^2.3.1",
39
39
  "prop-types": "^15.7.2"
40
40
  },
41
41
  "files": [
42
42
  "build",
43
- "types"
43
+ "types",
44
+ "src"
44
45
  ],
45
46
  "devDependencies": {
46
47
  "react": "^18.3.1",
@@ -0,0 +1,10 @@
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
2
+
3
+ Given('a Legend with children is rendered', () => {
4
+ cy.visitStory('Legend', 'With children')
5
+ cy.get('[data-test="dhis2-uicore-legend"]').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 Legend renders children
2
+
3
+ Scenario: A Legend with children
4
+ Given a Legend with children is rendered
5
+ Then the children are visible
@@ -0,0 +1,9 @@
1
+ import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'
2
+
3
+ Given('a Legend with content and a required flag is rendered', () => {
4
+ cy.visitStory('Legend', 'With content and required')
5
+ })
6
+
7
+ Then('the required indicator is visible', () => {
8
+ cy.get('[data-test="dhis2-uicore-legend-required"]').should('be.visible')
9
+ })
@@ -0,0 +1,5 @@
1
+ Feature: Required status for the Legend
2
+
3
+ Scenario: Rendering a Legend that is required
4
+ Given a Legend with content and a required flag is rendered
5
+ Then the required indicator is visible
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Legend } from './legend.js'
@@ -0,0 +1,8 @@
1
+ import React from 'react'
2
+ import { Legend } from './legend.js'
3
+
4
+ export default { title: 'Legend' }
5
+ export const WithContentAndRequired = () => (
6
+ <Legend required>I am wrapped in a legend which has some styling</Legend>
7
+ )
8
+ export const WithChildren = () => <Legend>I am a child</Legend>
package/src/legend.js ADDED
@@ -0,0 +1,35 @@
1
+ import { colors } from '@dhis2/ui-constants'
2
+ import { Required } from '@dhis2-ui/required'
3
+ import PropTypes from 'prop-types'
4
+ import React from 'react'
5
+
6
+ const Legend = ({
7
+ className,
8
+ children,
9
+ required,
10
+ dataTest = 'dhis2-uicore-legend',
11
+ }) => (
12
+ <legend className={className} data-test={dataTest}>
13
+ {children}
14
+
15
+ {required && <Required dataTest={`${dataTest}-required`} />}
16
+
17
+ <style jsx>{`
18
+ legend {
19
+ font-size: 14px;
20
+ line-height: 16px;
21
+ color: ${colors.grey900};
22
+ }
23
+ `}</style>
24
+ </legend>
25
+ )
26
+
27
+ Legend.propTypes = {
28
+ children: PropTypes.node,
29
+ className: PropTypes.string,
30
+ dataTest: PropTypes.string,
31
+ /** Indicates the associated field set is required */
32
+ required: PropTypes.bool,
33
+ }
34
+
35
+ export { Legend }
@@ -0,0 +1,27 @@
1
+ import React from 'react'
2
+ import { Legend } from './legend.js'
3
+
4
+ const description = `
5
+ Legends are to be used in a Field Set to describe the form fields. They may indicate that the fields are required.
6
+
7
+ See the [Field Set](../?path=/docs/forms-field-set-field-set--usage-example-a-radio-button-group-with-error-status) for a usage example.
8
+
9
+ \`\`\`js
10
+ import { Legend } from '@dhis2/ui'
11
+ \`\`\`
12
+ `
13
+
14
+ export default {
15
+ title: 'Legend',
16
+ component: Legend,
17
+ parameters: { docs: { description: { component: description } } },
18
+ }
19
+
20
+ const Template = (args) => (
21
+ <Legend {...args}>I am wrapped in a legend which has some styling</Legend>
22
+ )
23
+
24
+ export const Default = Template.bind({})
25
+
26
+ export const Required = Template.bind({})
27
+ Required.args = { required: true }