@dhis2-ui/label 10.16.1 → 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/label",
3
- "version": "10.16.1",
3
+ "version": "10.16.3-alpha.1",
4
4
  "description": "UI Label",
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.1",
37
- "@dhis2/ui-constants": "10.16.1",
36
+ "@dhis2-ui/required": "10.16.3-alpha.1",
37
+ "@dhis2/ui-constants": "10.16.3-alpha.1",
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 Label with children is rendered', () => {
4
+ cy.visitStory('Label', 'With children')
5
+ cy.get('[data-test="dhis2-uicore-label"]').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 Label renders children
2
+
3
+ Scenario: A Label with children
4
+ Given a Label 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 Label with required is rendered', () => {
4
+ cy.visitStory('Label', 'With required')
5
+ })
6
+
7
+ Then('the required indicator is visible', () => {
8
+ cy.get('[data-test="dhis2-uicore-label-required"]').should('be.visible')
9
+ })
@@ -0,0 +1,5 @@
1
+ Feature: Required status for the Label
2
+
3
+ Scenario: Rendering a Label that is required
4
+ Given a Label with required is rendered
5
+ Then the required indicator is visible
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { Label } from './label.js'
@@ -0,0 +1,6 @@
1
+ import { Label } from '@dhis2-ui/label'
2
+ import React from 'react'
3
+
4
+ export default { title: 'Label' }
5
+ export const WithChildren = () => <Label>I am a child</Label>
6
+ export const WithRequired = () => <Label required>Content</Label>
package/src/label.js ADDED
@@ -0,0 +1,59 @@
1
+ import { colors } from '@dhis2/ui-constants'
2
+ import { Required } from '@dhis2-ui/required'
3
+ import cx from 'classnames'
4
+ import PropTypes from 'prop-types'
5
+ import React from 'react'
6
+ import css from 'styled-jsx/css'
7
+
8
+ const styles = css`
9
+ label {
10
+ display: block;
11
+ box-sizing: border-box;
12
+ font-size: 14px;
13
+ line-height: 19px;
14
+ color: ${colors.grey900};
15
+ padding: 0;
16
+ }
17
+
18
+ .disabled {
19
+ cursor: not-allowed;
20
+ }
21
+ `
22
+
23
+ const constructClassName = ({ disabled, className }) =>
24
+ cx(className, {
25
+ disabled: disabled,
26
+ })
27
+
28
+ export const Label = ({
29
+ children,
30
+ className,
31
+ dataTest = 'dhis2-uicore-label',
32
+ disabled,
33
+ htmlFor,
34
+ id,
35
+ required,
36
+ }) => (
37
+ <label
38
+ id={id}
39
+ htmlFor={htmlFor}
40
+ className={constructClassName({ className, disabled })}
41
+ data-test={dataTest}
42
+ >
43
+ <span>{children}</span>
44
+
45
+ {required && <Required dataTest={`${dataTest}-required`} />}
46
+
47
+ <style jsx>{styles}</style>
48
+ </label>
49
+ )
50
+
51
+ Label.propTypes = {
52
+ children: PropTypes.string,
53
+ className: PropTypes.string,
54
+ dataTest: PropTypes.string,
55
+ disabled: PropTypes.bool,
56
+ htmlFor: PropTypes.string,
57
+ id: PropTypes.string,
58
+ required: PropTypes.bool,
59
+ }