@aurora-ds/components 0.19.0 → 0.19.2

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.
@@ -5,13 +5,21 @@ export type SelectProps = {
5
5
  */
6
6
  options: SelectOption[];
7
7
  /**
8
- * The currently selected value
8
+ * The currently selected value (null to show placeholder)
9
9
  */
10
- value?: string | number;
10
+ value: string | number | null;
11
11
  /**
12
12
  * Callback when selection changes
13
13
  */
14
- onChange?: (value: string | number) => void;
14
+ onChange: (value: string | number | null) => void;
15
+ /**
16
+ * Label displayed above the select
17
+ */
18
+ label?: string;
19
+ /**
20
+ * Whether the field is mandatory (displays an asterisk next to the label)
21
+ */
22
+ mandatory?: boolean;
15
23
  /**
16
24
  * Placeholder text when no option is selected
17
25
  */
@@ -28,3 +28,4 @@ export type { AlertVariant, AlertPosition } from '@interfaces/alert.types';
28
28
  export type { ButtonVariants, ButtonVariantStyle } from '@interfaces/button.types';
29
29
  export type { TextVariants, TextVariantStyle } from '@interfaces/text.types';
30
30
  export type { ChipVariant, ChipColor, ChipSize } from '@interfaces/chip.types';
31
+ export type { SelectOption } from '@interfaces/select.types';
package/dist/esm/index.js CHANGED
@@ -1403,10 +1403,11 @@ MenuItem.displayName = 'MenuItem';
1403
1403
  /**
1404
1404
  * Select component that uses Menu for dropdown
1405
1405
  */
1406
- const Select = ({ options, value, onChange, placeholder = 'Select an option', disabled = false, width }) => {
1406
+ const Select = ({ options, value, onChange, label, mandatory = false, placeholder = 'Select an option', disabled = false, width }) => {
1407
1407
  const [isOpen, setIsOpen] = useState(false);
1408
1408
  const triggerRef = useRef(null);
1409
1409
  const selectedOption = options.find(option => option.value === value);
1410
+ const menuWidth = triggerRef.current?.offsetWidth ?? width;
1410
1411
  const handleTriggerClick = () => {
1411
1412
  if (!disabled) {
1412
1413
  setIsOpen(!isOpen);
@@ -1416,10 +1417,10 @@ const Select = ({ options, value, onChange, placeholder = 'Select an option', di
1416
1417
  setIsOpen(false);
1417
1418
  };
1418
1419
  const handleSelect = (selectedValue) => {
1419
- onChange?.(selectedValue);
1420
+ onChange(selectedValue);
1420
1421
  setIsOpen(false);
1421
1422
  };
1422
- return (jsxs(Fragment$1, { children: [jsxs("div", { ref: triggerRef, className: SELECT_STYLES.root({ disabled, width }), onClick: handleTriggerClick, role: 'button', tabIndex: disabled ? -1 : 0, "aria-expanded": isOpen, "aria-haspopup": 'listbox', children: [jsx("div", { className: SELECT_STYLES.trigger, children: jsx(Text, { variant: 'p', maxLines: 1, color: selectedOption ? 'text' : 'textSecondary', children: selectedOption ? selectedOption.label : placeholder }) }), jsx(Icon, { children: jsx(ChevronDownIcon, {}) })] }), jsx(Menu, { anchor: isOpen ? triggerRef.current : null, onClose: handleClose, width: width, children: jsx(MenuGroup, { children: options.map(option => (jsx(SelectItem, { option: option, isSelected: option.value === value, onSelect: handleSelect }, option.value))) }) })] }));
1423
+ return (jsxs(Stack, { direction: 'column', gap: 'xs', align: 'stretch', width: width ?? '100%', children: [label && (jsxs(Stack, { direction: 'row', gap: 'xs', align: 'center', children: [jsx(Text, { variant: 'label', fontSize: 'sm', children: label }), mandatory && (jsx(Text, { variant: 'label', fontSize: 'sm', color: 'error', children: "*" }))] })), jsxs("div", { ref: triggerRef, className: SELECT_STYLES.root({ disabled, width }), onClick: handleTriggerClick, role: 'button', tabIndex: disabled ? -1 : 0, "aria-expanded": isOpen, "aria-haspopup": 'listbox', children: [jsx("div", { className: SELECT_STYLES.trigger, children: jsx(Text, { variant: 'p', maxLines: 1, color: selectedOption ? 'text' : 'textSecondary', children: selectedOption ? selectedOption.label : placeholder }) }), jsx(Icon, { children: jsx(ChevronDownIcon, {}) })] }), jsx(Menu, { anchor: isOpen ? triggerRef.current : null, onClose: handleClose, width: menuWidth, children: jsx(MenuGroup, { children: options.map(option => (jsx(SelectItem, { option: option, isSelected: option.value === value, onSelect: handleSelect }, option.value))) }) })] }));
1423
1424
  };
1424
1425
  Select.displayName = 'Select';
1425
1426