@madie/madie-design-system 1.0.15 → 1.0.16

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.
@@ -0,0 +1,99 @@
1
+ import React from "react";
2
+ import PropTypes from "prop-types";
3
+ import { withKnobs } from "@storybook/addon-knobs";
4
+ import ReadOnlyTextField from "./index";
5
+ import { FormHelperText } from "@mui/material";
6
+ export default {
7
+ title: "ReadOnlyTextField",
8
+ component: ReadOnlyTextField,
9
+ decorators: [withKnobs],
10
+ };
11
+
12
+ const Wrapper = ({ children }) => (
13
+ <div className="qpp-u-padding--16" style={{ width: 300 }}>
14
+ {children}
15
+ </div>
16
+ );
17
+ Wrapper.propTypes = {
18
+ className: PropTypes.string,
19
+ children: PropTypes.node,
20
+ };
21
+ export const Textfield = () => (
22
+ <Wrapper>
23
+ <ReadOnlyTextField
24
+ placeholder="Placeholder"
25
+ label="Text Label"
26
+ id="measureName"
27
+ inputProps={{ "data-testid": "measure-name-input" }}
28
+ data-testid="measure-name-text-field"
29
+ size="small"
30
+ />
31
+ </Wrapper>
32
+ );
33
+
34
+ export const WithHelperText = () => (
35
+ <Wrapper>
36
+ <ReadOnlyTextField
37
+ placeholder="Placeholder"
38
+ label="Text Label"
39
+ id="measureName"
40
+ inputProps={{ "data-testid": "measure-name-input" }}
41
+ data-testid="measure-name-text-field"
42
+ size="small"
43
+ helperText={
44
+ <FormHelperText data-testid={`helper-text`} error={false}>
45
+ a descriptive message
46
+ </FormHelperText>
47
+ }
48
+ />
49
+ </Wrapper>
50
+ );
51
+
52
+ export const Disabled = () => (
53
+ <Wrapper>
54
+ <ReadOnlyTextField
55
+ placeholder="Placeholder"
56
+ label="Text Label"
57
+ id="measureName"
58
+ inputProps={{ "data-testid": "measure-name-input" }}
59
+ data-testid="measure-name-text-field"
60
+ size="small"
61
+ disabled
62
+ required
63
+ />
64
+ </Wrapper>
65
+ );
66
+
67
+ export const Required = () => (
68
+ <Wrapper>
69
+ <ReadOnlyTextField
70
+ placeholder="Placeholder"
71
+ required
72
+ label="Text Label"
73
+ id="measureName"
74
+ inputProps={{ "data-testid": "measure-name-input" }}
75
+ data-testid="measure-name-text-field"
76
+ size="small"
77
+ />
78
+ </Wrapper>
79
+ );
80
+
81
+ export const Error = () => (
82
+ <Wrapper>
83
+ <ReadOnlyTextField
84
+ placeholder="Placeholder"
85
+ error
86
+ required
87
+ label="Text Label"
88
+ id="measureName"
89
+ inputProps={{ "data-testid": "measure-name-input" }}
90
+ data-testid="measure-name-text-field"
91
+ size="small"
92
+ helperText={
93
+ <FormHelperText data-testid={`helper-text`} error={true}>
94
+ An error message
95
+ </FormHelperText>
96
+ }
97
+ />
98
+ </Wrapper>
99
+ );
@@ -0,0 +1,76 @@
1
+ import React from "react";
2
+ import { FormControl, TextField as MUITextField } from "@mui/material";
3
+ import InputLabel from "../InputLabel";
4
+ import PropTypes from "prop-types";
5
+
6
+ const ReadOnlyTextField = ({
7
+ id,
8
+ error = false,
9
+ helperText = undefined,
10
+ required = false,
11
+ disabled = false,
12
+ label,
13
+ ...rest
14
+ }) => {
15
+ return (
16
+ <FormControl fullWidth error={error}>
17
+ <InputLabel
18
+ disabled={disabled}
19
+ shrink
20
+ required={required}
21
+ error={error}
22
+ htmlFor={id}
23
+ >
24
+ {label}
25
+ </InputLabel>
26
+ <MUITextField
27
+ sx={{
28
+ height: 40, //there's a .13 coming from somewhere.
29
+ border: "none",
30
+ "& .MuiOutlinedInput-root": {
31
+ "& > fieldset": {
32
+ border: "none",
33
+ },
34
+ },
35
+ // input base selector
36
+ "& .MuiInputBase-input": {
37
+ lineHeight: "19px",
38
+ fontFamily: "Rubik",
39
+ disableUnderline: true,
40
+ fontSize: 16,
41
+ padding: "9px 0px",
42
+ "&::placeholder": {
43
+ opacity: 0.6,
44
+ },
45
+ "&:focus": {
46
+ border: "none",
47
+ outline: "none",
48
+ boxShadow: "none",
49
+ },
50
+ },
51
+ }}
52
+ InputProps={{
53
+ readOnly: true,
54
+ }}
55
+ disableUnderline={true}
56
+ label={null}
57
+ error={error}
58
+ disabled={disabled}
59
+ id={id}
60
+ {...rest}
61
+ />
62
+ {helperText && helperText}
63
+ </FormControl>
64
+ );
65
+ };
66
+
67
+ ReadOnlyTextField.propTypes = {
68
+ id: PropTypes.string,
69
+ error: PropTypes.bool,
70
+ helperText: PropTypes.string,
71
+ required: PropTypes.bool,
72
+ disabled: PropTypes.bool,
73
+ placeholder: PropTypes.string, // expects placeholder objects of { name: value } and inserts into the render item function.
74
+ label: PropTypes.string,
75
+ };
76
+ export default ReadOnlyTextField;
@@ -13,6 +13,7 @@ import MadieDiscardDialog from "./MadieDiscardDialog";
13
13
  import MadieSpinner from "./MadieSpinner";
14
14
  import Modal from "./Modal";
15
15
  import { Pagination } from "./Pagination";
16
+ import ReadOnlyTextField from "./ReadOnlyTextField";
16
17
  import Select from "./Select";
17
18
  import Spinner from "./UnwrappedSpinner";
18
19
  import TabPanel from "./Tabs/TabPanel";
@@ -125,6 +126,7 @@ export {
125
126
  MadieDiscardDialog,
126
127
  MadieSpinner,
127
128
  Pagination,
129
+ ReadOnlyTextField,
128
130
  Search,
129
131
  Select,
130
132
  Spinner,