cloudmr-ux 1.9.6 → 1.9.7

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ButtonProps, SxProps, Theme } from '@mui/material';
2
+ import { ButtonProps, FormControlProps, SelectProps, SxProps, Theme } from '@mui/material';
3
3
  import * as React from 'react';
4
4
  import React__default, { ReactNode, ChangeEvent, CSSProperties, FC } from 'react';
5
5
  import { SizeType } from 'antd/lib/config-provider/SizeContext';
@@ -41,11 +41,27 @@ declare const CmrRadioGroup: React__default.FC<CmrRadioProps>;
41
41
  interface Option {
42
42
  label: string;
43
43
  value: string;
44
+ disabled?: boolean;
44
45
  }
45
46
  interface CmrSelectProps {
46
47
  options: Option[];
47
48
  label: string;
48
49
  disabled?: boolean;
50
+ /** Controlled value (optional). If provided, component becomes controlled. */
51
+ value?: string;
52
+ /** Fires when selection changes. For controlled usage, update your state here. */
53
+ onChange?: (value: string) => void;
54
+ /** Initial value for uncontrolled mode. Defaults to ''. */
55
+ defaultValue?: string;
56
+ /** Top placeholder item. Shown as first item; disabled so users must pick another. */
57
+ placeholder?: string;
58
+ /** Layout helpers */
59
+ fullWidth?: boolean;
60
+ /** Pass-through styling/props */
61
+ sx?: FormControlProps['sx'];
62
+ className?: string;
63
+ /** Optional passthrough to MUI Select */
64
+ SelectProps?: Partial<SelectProps<string>>;
49
65
  }
50
66
  declare const CmrSelect: React__default.FC<CmrSelectProps>;
51
67
 
package/dist/index.js CHANGED
@@ -134,26 +134,64 @@ var CmrRadioGroup_default = CmrRadioGroup;
134
134
  var import_react2 = require("react");
135
135
  var import_material5 = require("@mui/material");
136
136
  var import_jsx_runtime5 = require("react/jsx-runtime");
137
- var CmrSelect = ({ options, label, disabled }) => {
138
- const [selectedValue, setSelectedValue] = (0, import_react2.useState)("");
137
+ var CmrSelect = ({
138
+ options,
139
+ label,
140
+ disabled,
141
+ value,
142
+ // controlled value (optional)
143
+ onChange,
144
+ // callback (optional)
145
+ defaultValue = "",
146
+ // for uncontrolled
147
+ placeholder,
148
+ // optional top disabled item
149
+ fullWidth,
150
+ sx,
151
+ className,
152
+ SelectProps: SelectProps2
153
+ }) => {
154
+ const isControlled = value !== void 0;
155
+ const [internalValue, setInternalValue] = (0, import_react2.useState)(defaultValue);
156
+ const currentValue = isControlled ? value : internalValue;
157
+ (0, import_react2.useEffect)(() => {
158
+ if (isControlled) {
159
+ setInternalValue(value);
160
+ }
161
+ }, [isControlled, value]);
162
+ const id = (0, import_react2.useId)();
163
+ const labelId = `${id}-label`;
139
164
  const handleChange = (event) => {
140
- setSelectedValue(event.target.value);
141
- console.log("Selected Value:", event.target.value);
165
+ const next = event.target.value;
166
+ if (!isControlled)
167
+ setInternalValue(next);
168
+ onChange == null ? void 0 : onChange(next);
142
169
  };
143
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_material5.FormControl, { className: "dropdown-select", sx: {
144
- minWidth: 200,
145
- // Minimum width for the dropdown
146
- maxWidth: 400,
147
- // Optional: Maximum width for the dropdown
148
- width: "auto"
149
- // Allow auto-resizing based on content
150
- }, disabled, children: [
151
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.InputLabel, { className: "dropdown-label", children: label }),
152
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.Select, { value: selectedValue, onChange: handleChange, label, MenuProps: {
153
- classes: { paper: "custom-dropdown" }
154
- // Apply the class to the dropdown menu
155
- }, children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.MenuItem, { value: option.value, children: option.label }, option.value)) })
156
- ] });
170
+ const items = placeholder ? [{ label: placeholder, value: "", disabled: true }, ...options] : options;
171
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
172
+ import_material5.FormControl,
173
+ {
174
+ className: className ?? "dropdown-select",
175
+ sx: { minWidth: 200, maxWidth: 400, width: fullWidth ? "100%" : "auto", ...sx },
176
+ disabled,
177
+ fullWidth,
178
+ children: [
179
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.InputLabel, { id: labelId, className: "dropdown-label", children: label }),
180
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
181
+ import_material5.Select,
182
+ {
183
+ labelId,
184
+ value: currentValue,
185
+ onChange: handleChange,
186
+ label,
187
+ MenuProps: { classes: { paper: "custom-dropdown" }, ...SelectProps2 == null ? void 0 : SelectProps2.MenuProps },
188
+ ...SelectProps2,
189
+ children: items.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.MenuItem, { value: opt.value, disabled: !!opt.disabled, children: opt.label }, `${opt.value}-${opt.label}`))
190
+ }
191
+ )
192
+ ]
193
+ }
194
+ );
157
195
  };
158
196
  var CmrSelect_default = CmrSelect;
159
197
 
package/dist/index.mjs CHANGED
@@ -83,29 +83,72 @@ var CmrRadioGroup = ({
83
83
  var CmrRadioGroup_default = CmrRadioGroup;
84
84
 
85
85
  // src/CmrComponents/CmrSelect/CmrSelect.tsx
86
- import { useState as useState2 } from "react";
87
- import { Select, MenuItem, FormControl as FormControl2, InputLabel } from "@mui/material";
86
+ import { useEffect, useId, useState as useState2 } from "react";
87
+ import {
88
+ Select,
89
+ MenuItem,
90
+ FormControl as FormControl2,
91
+ InputLabel
92
+ } from "@mui/material";
88
93
  import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
89
- var CmrSelect = ({ options, label, disabled }) => {
90
- const [selectedValue, setSelectedValue] = useState2("");
94
+ var CmrSelect = ({
95
+ options,
96
+ label,
97
+ disabled,
98
+ value,
99
+ // controlled value (optional)
100
+ onChange,
101
+ // callback (optional)
102
+ defaultValue = "",
103
+ // for uncontrolled
104
+ placeholder,
105
+ // optional top disabled item
106
+ fullWidth,
107
+ sx,
108
+ className,
109
+ SelectProps: SelectProps2
110
+ }) => {
111
+ const isControlled = value !== void 0;
112
+ const [internalValue, setInternalValue] = useState2(defaultValue);
113
+ const currentValue = isControlled ? value : internalValue;
114
+ useEffect(() => {
115
+ if (isControlled) {
116
+ setInternalValue(value);
117
+ }
118
+ }, [isControlled, value]);
119
+ const id = useId();
120
+ const labelId = `${id}-label`;
91
121
  const handleChange = (event) => {
92
- setSelectedValue(event.target.value);
93
- console.log("Selected Value:", event.target.value);
122
+ const next = event.target.value;
123
+ if (!isControlled)
124
+ setInternalValue(next);
125
+ onChange == null ? void 0 : onChange(next);
94
126
  };
95
- return /* @__PURE__ */ jsxs2(FormControl2, { className: "dropdown-select", sx: {
96
- minWidth: 200,
97
- // Minimum width for the dropdown
98
- maxWidth: 400,
99
- // Optional: Maximum width for the dropdown
100
- width: "auto"
101
- // Allow auto-resizing based on content
102
- }, disabled, children: [
103
- /* @__PURE__ */ jsx5(InputLabel, { className: "dropdown-label", children: label }),
104
- /* @__PURE__ */ jsx5(Select, { value: selectedValue, onChange: handleChange, label, MenuProps: {
105
- classes: { paper: "custom-dropdown" }
106
- // Apply the class to the dropdown menu
107
- }, children: options.map((option) => /* @__PURE__ */ jsx5(MenuItem, { value: option.value, children: option.label }, option.value)) })
108
- ] });
127
+ const items = placeholder ? [{ label: placeholder, value: "", disabled: true }, ...options] : options;
128
+ return /* @__PURE__ */ jsxs2(
129
+ FormControl2,
130
+ {
131
+ className: className ?? "dropdown-select",
132
+ sx: { minWidth: 200, maxWidth: 400, width: fullWidth ? "100%" : "auto", ...sx },
133
+ disabled,
134
+ fullWidth,
135
+ children: [
136
+ /* @__PURE__ */ jsx5(InputLabel, { id: labelId, className: "dropdown-label", children: label }),
137
+ /* @__PURE__ */ jsx5(
138
+ Select,
139
+ {
140
+ labelId,
141
+ value: currentValue,
142
+ onChange: handleChange,
143
+ label,
144
+ MenuProps: { classes: { paper: "custom-dropdown" }, ...SelectProps2 == null ? void 0 : SelectProps2.MenuProps },
145
+ ...SelectProps2,
146
+ children: items.map((opt) => /* @__PURE__ */ jsx5(MenuItem, { value: opt.value, disabled: !!opt.disabled, children: opt.label }, `${opt.value}-${opt.label}`))
147
+ }
148
+ )
149
+ ]
150
+ }
151
+ );
109
152
  };
110
153
  var CmrSelect_default = CmrSelect;
111
154
 
@@ -713,7 +756,7 @@ import Dialog2 from "@mui/material/Dialog";
713
756
  import DialogActions2 from "@mui/material/DialogActions";
714
757
  import DialogContent2 from "@mui/material/DialogContent";
715
758
  import DialogTitle2 from "@mui/material/DialogTitle";
716
- import { useEffect } from "react";
759
+ import { useEffect as useEffect2 } from "react";
717
760
  import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
718
761
  function CmrNameDialog(props) {
719
762
  let { originalName, open, setOpen } = props;
@@ -724,7 +767,7 @@ function CmrNameDialog(props) {
724
767
  const handleClose = () => {
725
768
  setOpen(false);
726
769
  };
727
- useEffect(() => {
770
+ useEffect2(() => {
728
771
  checkError(originalName);
729
772
  }, [originalName]);
730
773
  const handleConfirm = async () => {
@@ -915,7 +958,7 @@ import DialogContent5 from "@mui/material/DialogContent";
915
958
  import DialogContentText4 from "@mui/material/DialogContentText";
916
959
  import DialogTitle5 from "@mui/material/DialogTitle";
917
960
  import { InputAdornment } from "@mui/material";
918
- import { useEffect as useEffect2 } from "react";
961
+ import { useEffect as useEffect3 } from "react";
919
962
  import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
920
963
  function CmrEditConfirmation({
921
964
  name,
@@ -932,7 +975,7 @@ function CmrEditConfirmation({
932
975
  suffix = ""
933
976
  }) {
934
977
  const [text, setText] = React8.useState(defaultText);
935
- useEffect2(() => {
978
+ useEffect3(() => {
936
979
  if (open)
937
980
  setText(defaultText);
938
981
  }, [open]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudmr-ux",
3
- "version": "1.9.6",
3
+ "version": "1.9.7",
4
4
  "author": "erosmontin@gmail.com",
5
5
  "license": "MIT",
6
6
  "repository": "erosmontin/cloudmr-ux",