grep-components 2.3.0 → 2.4.0-GREPF-2436-test.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.
@@ -13,6 +13,8 @@ export type GrepSelectProps = SelectProps & {
13
13
  errorMessage?: string;
14
14
  selectItems: SelectItem[];
15
15
  unselectOption?: boolean;
16
+ unselectOptionBottom?: boolean;
17
+ defaultHighlight?: string;
16
18
  useCheckedSelect?: boolean;
17
19
  inputProps?: InputBaseComponentProps | undefined;
18
20
  };
package/dist/index.js CHANGED
@@ -2646,7 +2646,8 @@ const GrepSelect = (props) => {
2646
2646
  React.useEffect(() => {
2647
2647
  setLabelWidth(inputLabel.current.offsetWidth);
2648
2648
  }, []);
2649
- const { unselectOption = true, errorMessage, selectItems, helperText, fullWidth, outlined, disabled, required, label, inputProps, value, size, id, useCheckedSelect, ...rest } = props;
2649
+ const { unselectOption = true, unselectOptionBottom = false, defaultHighlight = '', errorMessage, selectItems, helperText, fullWidth, outlined, disabled, required, label, inputProps, value, size, id, useCheckedSelect, ...rest } = props;
2650
+ const [highlightValue, setHighlightValue] = React.useState('');
2650
2651
  const error = errorMessage ? errorMessage.length > 0 : false;
2651
2652
  const selected = value;
2652
2653
  return (React.createElement(FormControl, { variant: outlined ? 'outlined' : 'standard', className: props.className, fullWidth: fullWidth, required: required, style: props.style, error: error, size: size, disabled: disabled },
@@ -2654,7 +2655,29 @@ const GrepSelect = (props) => {
2654
2655
  minWidth: 'max-content',
2655
2656
  overflow: 'visible',
2656
2657
  } }, label),
2657
- React.createElement(Select, { ...rest, inputProps: { id, ...inputProps }, disabled: !selectItems || disabled, value: value === null ? '' : value, style: { minWidth: labelWidth + (outlined ? 35 : 25) },
2658
+ React.createElement(Select, { ...rest, inputProps: { id, ...inputProps }, onOpen: (e) => {
2659
+ if (highlightValue) {
2660
+ props.onOpen && props.onOpen(e);
2661
+ return;
2662
+ }
2663
+ if (selectItems.length > 0 && defaultHighlight !== '') {
2664
+ const index = selectItems.findIndex((e) => e.value === defaultHighlight);
2665
+ if (index >= 0) {
2666
+ setHighlightValue(defaultHighlight);
2667
+ }
2668
+ }
2669
+ props.onOpen && props.onOpen(e);
2670
+ }, onChange: (e, c) => {
2671
+ //console.log(highlightValue, e.target.value);
2672
+ if (highlightValue === e.target.value) {
2673
+ setHighlightValue('');
2674
+ //console.log('asdlfjlasfjlkasd');
2675
+ }
2676
+ else {
2677
+ setHighlightValue(e.target.value);
2678
+ }
2679
+ props.onChange && props.onChange(e, c);
2680
+ }, disabled: !selectItems || disabled, value: value || highlightValue, style: { minWidth: labelWidth + (outlined ? 35 : 25) },
2658
2681
  // @todo: make input respect label length
2659
2682
  input: outlined ? React.createElement(OutlinedInput, { label: label }) : React.createElement(Input, null), MenuProps: {
2660
2683
  ...rest.MenuProps,
@@ -2671,7 +2694,9 @@ const GrepSelect = (props) => {
2671
2694
  React.createElement("em", null, "Fjern valgt"))),
2672
2695
  selectItems.map(({ label, value, disabled, lang }, i) => (React.createElement(MenuItem$1, { key: i, value: value, disabled: disabled, lang: lang },
2673
2696
  useCheckedSelect && (React.createElement(Checkbox, { checked: selected?.indexOf(value) > -1 })),
2674
- React.createElement(ListItemText, { sx: { margin: '0px', span: { lineHeight: '1.4375em' } }, primary: label ? label : value }))))),
2697
+ React.createElement(ListItemText, { sx: { margin: '0px', span: { lineHeight: '1.4375em' } }, primary: label ? label : value })))),
2698
+ unselectOptionBottom && (React.createElement(MenuItem$1, { value: "" },
2699
+ React.createElement("em", null, "Fjern valgt")))),
2675
2700
  React.createElement(FormHelperText, null, errorMessage || helperText)));
2676
2701
  };
2677
2702