@aurora-ds/components 0.19.0 → 0.19.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/dist/cjs/components/forms/select/Select.props.d.ts +11 -3
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/forms/select/Select.props.d.ts +11 -3
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/index.js +4 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +12 -4
- package/package.json +1 -1
|
@@ -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
|
|
10
|
+
value: string | number | null;
|
|
11
11
|
/**
|
|
12
12
|
* Callback when selection changes
|
|
13
13
|
*/
|
|
14
|
-
onChange
|
|
14
|
+
onChange: (value: string | number) => 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/cjs/index.js
CHANGED
|
@@ -1405,10 +1405,11 @@ MenuItem.displayName = 'MenuItem';
|
|
|
1405
1405
|
/**
|
|
1406
1406
|
* Select component that uses Menu for dropdown
|
|
1407
1407
|
*/
|
|
1408
|
-
const Select = ({ options, value, onChange, placeholder = 'Select an option', disabled = false, width }) => {
|
|
1408
|
+
const Select = ({ options, value, onChange, label, mandatory = false, placeholder = 'Select an option', disabled = false, width }) => {
|
|
1409
1409
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
1410
1410
|
const triggerRef = React.useRef(null);
|
|
1411
1411
|
const selectedOption = options.find(option => option.value === value);
|
|
1412
|
+
const menuWidth = triggerRef.current?.offsetWidth ?? width;
|
|
1412
1413
|
const handleTriggerClick = () => {
|
|
1413
1414
|
if (!disabled) {
|
|
1414
1415
|
setIsOpen(!isOpen);
|
|
@@ -1418,10 +1419,10 @@ const Select = ({ options, value, onChange, placeholder = 'Select an option', di
|
|
|
1418
1419
|
setIsOpen(false);
|
|
1419
1420
|
};
|
|
1420
1421
|
const handleSelect = (selectedValue) => {
|
|
1421
|
-
onChange
|
|
1422
|
+
onChange(selectedValue);
|
|
1422
1423
|
setIsOpen(false);
|
|
1423
1424
|
};
|
|
1424
|
-
return (jsxRuntime.jsxs(jsxRuntime.
|
|
1425
|
+
return (jsxRuntime.jsxs(Stack, { direction: 'column', gap: 'xs', align: 'stretch', width: width ?? '100%', children: [label && (jsxRuntime.jsxs(Stack, { direction: 'row', gap: 'xs', align: 'center', children: [jsxRuntime.jsx(Text, { variant: 'label', fontSize: 'sm', children: label }), mandatory && (jsxRuntime.jsx(Text, { variant: 'label', fontSize: 'sm', color: 'error', children: "*" }))] })), jsxRuntime.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: [jsxRuntime.jsx("div", { className: SELECT_STYLES.trigger, children: jsxRuntime.jsx(Text, { variant: 'p', maxLines: 1, color: selectedOption ? 'text' : 'textSecondary', children: selectedOption ? selectedOption.label : placeholder }) }), jsxRuntime.jsx(Icon, { children: jsxRuntime.jsx(ChevronDownIcon, {}) })] }), jsxRuntime.jsx(Menu, { anchor: isOpen ? triggerRef.current : null, onClose: handleClose, width: menuWidth, children: jsxRuntime.jsx(MenuGroup, { children: options.map(option => (jsxRuntime.jsx(SelectItem, { option: option, isSelected: option.value === value, onSelect: handleSelect }, option.value))) }) })] }));
|
|
1425
1426
|
};
|
|
1426
1427
|
Select.displayName = 'Select';
|
|
1427
1428
|
|