@madie/madie-design-system 1.0.45 → 1.0.46

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,110 @@
1
+ import React from "react";
2
+ import {
3
+ FormControl,
4
+ FormHelperText,
5
+ FormControlLabel,
6
+ Radio,
7
+ RadioGroup,
8
+ } from "@mui/material";
9
+ import PropTypes from "prop-types";
10
+ import InputLabel from "../InputLabel";
11
+
12
+ const RadioButton = ({
13
+ id,
14
+ dataTestId,
15
+ options = [],
16
+ disabled = false,
17
+ label,
18
+ required = false,
19
+ error = false,
20
+ helperText,
21
+ ...rest
22
+ }) => {
23
+ return (
24
+ <FormControl error={error} fullWidth>
25
+ <InputLabel
26
+ htmlFor={`${id}`}
27
+ id={`${id}-label`}
28
+ disabled={disabled}
29
+ required={required}
30
+ shrink
31
+ style={{marginBottom: 0, height: 16}} // force a height
32
+ sx={[
33
+ {
34
+ backgroundColor: "transparent",
35
+ display: "flex",
36
+ flexDirection: "row-reverse",
37
+ alignSelf: "baseline",
38
+ textTransform: "none",
39
+ // force it outside the select box
40
+ position: "initial",
41
+ transform: "translateX(0px) translateY(0px)",
42
+ fontFamily: "Rubik",
43
+ fontWeight: 500,
44
+ fontSize: 14,
45
+ color: "#333",
46
+ "& .MuiInputLabel-asterisk": {
47
+ color: "#AE1C1C !important",
48
+ marginRight: "3px !important", //this was
49
+ },
50
+ },
51
+ required && {
52
+ transform: "translateX(-12px) translateY(0px)",
53
+ "& .MuiInputLabel-asterisk": {
54
+ color: "#D92F2",
55
+ marginRight: "3px !important", //this was
56
+ },
57
+ },
58
+ disabled && {
59
+ color: "rgba(0,0,0,0.6)",
60
+ },
61
+ error && {
62
+ color: "#AE1C1C !important",
63
+ },
64
+ ]}
65
+ >
66
+ {label}
67
+ </InputLabel>
68
+ {helperText && (<FormHelperText
69
+ tabIndex={0}
70
+ aria-live="polite"
71
+ id={`${id}-helper-text`}
72
+ data-testid={`${id}-helper-text`}
73
+ error={error}
74
+ sx={[{
75
+ margin: "4px 0px 0px 0px",
76
+ color: "#515151",
77
+ lineHeight: 1
78
+ },
79
+ error && {
80
+ color: "#AE1C1C !important",
81
+ },
82
+ ]}
83
+ >
84
+ {helperText}
85
+ </FormHelperText>)}
86
+ <RadioGroup
87
+ aria-labelledby={`${id}-radio-buttons-group`}
88
+ data-testid={`${id}-radio-buttons-group`}
89
+ {...rest}
90
+ >
91
+ {options.map((option, index) => (
92
+ <FormControlLabel key={index} value={option.value} control={<Radio />} label={option.label} />
93
+ ))}
94
+ </RadioGroup>
95
+ </FormControl>
96
+ );
97
+ };
98
+
99
+ RadioButton.propTypes = {
100
+ id: PropTypes.string,
101
+ dataTestId: PropTypes.string,
102
+ required: PropTypes.bool,
103
+ disabled: PropTypes.bool,
104
+ error: PropTypes.bool,
105
+ label: PropTypes.string,
106
+ helperText: PropTypes.string,
107
+ options: PropTypes.arrayOf(PropTypes.any),
108
+ };
109
+
110
+ export default RadioButton;
@@ -0,0 +1,59 @@
1
+ import React, { useState } from "react";
2
+ import RadioButton from "./RadioButton";
3
+
4
+ export default {
5
+ title: "RadioButton",
6
+ component: RadioButton,
7
+ };
8
+
9
+ const options = [
10
+ { label: "option 1", value: true },
11
+ { label: "option 2", value: false},
12
+ { label: "options 3", value: "options 3"},
13
+ ];
14
+
15
+ const TemplateRadioButton = (args) => {
16
+ const [value, setValue] = useState("test");
17
+ const handleChange = (id, selectedVal) => {
18
+ console.log("Handle change triggered", id, selectedVal);
19
+ setValue(selectedVal);
20
+ };
21
+ return (
22
+ <div className="qpp-u-padding--16">
23
+ <RadioButton
24
+ id="RadioButton"
25
+ dataTestId="v"
26
+ label="Radio Button"
27
+ options={options}
28
+ onChange={handleChange}
29
+ value={value}
30
+ {...args}
31
+ />
32
+ </div>
33
+ );
34
+ };
35
+
36
+ export const RadioButtonWithLabel = TemplateRadioButton.bind({});
37
+ RadioButtonWithLabel.args = {};
38
+
39
+ export const RadioButtonWithLabelDisabled = TemplateRadioButton.bind({});
40
+ RadioButtonWithLabelDisabled.args = {
41
+ disabled: true,
42
+ };
43
+
44
+ export const RadioButtonWithHelperText = TemplateRadioButton.bind({});
45
+ RadioButtonWithHelperText.args = {
46
+ helperText: "Helper text goes here",
47
+ };
48
+
49
+ export const RadioButtonRequired = TemplateRadioButton.bind({});
50
+ RadioButtonRequired.args = {
51
+ required: true,
52
+ };
53
+
54
+ export const RadioButtonWithError = TemplateRadioButton.bind({});
55
+ RadioButtonWithError.args = {
56
+ required: true,
57
+ helperText: "This field is required",
58
+ error: true,
59
+ };
@@ -17,6 +17,7 @@ import MadieSpinner from "./MadieSpinner";
17
17
  import Modal from "./Modal";
18
18
  import Popover from "./Popover";
19
19
  import { Pagination } from "./Pagination";
20
+ import RadioButton from "./RadioButton/RadioButton";
20
21
  import ReadOnlyTextField from "./ReadOnlyTextField";
21
22
  import Select from "./Select";
22
23
  import Spinner from "./UnwrappedSpinner";
@@ -136,6 +137,7 @@ export {
136
137
  MadieSpinner,
137
138
  Pagination,
138
139
  Popover,
140
+ RadioButton,
139
141
  ReadOnlyTextField,
140
142
  Search,
141
143
  Select,