@kwiz/fluentui 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,29 @@
|
|
1
|
+
import { DropdownProps } from '@fluentui/react-components';
|
1
2
|
import React from 'react';
|
2
|
-
|
3
|
-
|
3
|
+
type ForwardProps = Omit<DropdownProps, "onSelect" | "selectedOptions" | "clearable">;
|
4
|
+
interface IProps<dataType, keyType extends string = string> extends ForwardProps {
|
5
|
+
required?: boolean;
|
6
|
+
selected: keyType | keyType[];
|
4
7
|
items: {
|
5
8
|
key: keyType;
|
6
9
|
value: string;
|
7
10
|
data?: dataType;
|
11
|
+
/** display complex controls in the drop down */
|
8
12
|
option?: JSX.Element;
|
9
13
|
}[];
|
10
|
-
onSelect: (
|
14
|
+
onSelect: (
|
15
|
+
/** the specific option that was selected/unselected */
|
16
|
+
option: {
|
11
17
|
key: keyType;
|
12
18
|
value: string;
|
13
19
|
data?: dataType;
|
14
|
-
}
|
15
|
-
|
20
|
+
},
|
21
|
+
/** only sent for multi select - all selected options, in case of multi select */
|
22
|
+
options?: {
|
23
|
+
key: keyType;
|
24
|
+
value: string;
|
25
|
+
data?: dataType;
|
26
|
+
}[]) => void;
|
16
27
|
}
|
17
28
|
export declare const DropdownEX: React.ForwardRefExoticComponent<IProps<unknown, string> & React.RefAttributes<HTMLButtonElement>>;
|
18
29
|
export {};
|
@@ -1,13 +1,27 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { Dropdown, Option } from '@fluentui/react-components';
|
3
|
-
import { filterEmptyEntries, firstOrNull } from '@kwiz/common';
|
3
|
+
import { filterEmptyEntries, firstOrNull, isNullOrUndefined } from '@kwiz/common';
|
4
4
|
import React from 'react';
|
5
5
|
function $DropdownEX(props, ref) {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
const selected = Array.isArray(props.selected) ? props.selected : isNullOrUndefined(props.selected) ? [] : [props.selected];
|
7
|
+
//sometimes control will lose value when re-rendered
|
8
|
+
//use case: public forms when editing other fields after the dropdown was set
|
9
|
+
//re-set the text value manually to fix
|
10
|
+
let text = Array.isArray(props.selected)
|
11
|
+
? filterEmptyEntries(props.selected.map(s => {
|
12
|
+
let v = firstOrNull(props.items, i => i.key === s);
|
13
|
+
return v ? v.value : '';
|
14
|
+
})).join(', ')
|
15
|
+
: props.selected || "";
|
16
|
+
return (_jsx(Dropdown, Object.assign({}, props, { onSelect: undefined, ref: ref, clearable: !props.required && !props.multiselect, appearance: 'underline', selectedOptions: selected, value: text, onOptionSelect: (e, data) => {
|
17
|
+
let o = firstOrNull(props.items, i => i.key === data.optionValue);
|
18
|
+
if (props.multiselect) {
|
19
|
+
let current = data.selectedOptions.map(s => firstOrNull(props.items, i => i.key === s));
|
20
|
+
props.onSelect(o, current);
|
21
|
+
}
|
22
|
+
else
|
23
|
+
props.onSelect(o);
|
24
|
+
}, children: props.items.map(i => _jsx(Option, { value: i.key, text: i.value, children: i.option ? i.option : i.value }, i.key)) })));
|
11
25
|
}
|
12
26
|
export const DropdownEX = React.forwardRef($DropdownEX);
|
13
27
|
//# sourceMappingURL=dropdown.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../src/controls/dropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,
|
1
|
+
{"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../src/controls/dropdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAiB,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,KAAK,MAAM,OAAO,CAAC;AAmB1B,SAAS,WAAW,CAAoD,KAAgC,EAAE,GAA0C;IAChJ,MAAM,QAAQ,GAAc,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KA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AE,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBACxF,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAC/B,CAAC;;gBACI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC3B,CAAC,YACA,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAC,MAAM,IAAa,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,YAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAlE,CAAC,CAAC,GAAG,CAAuE,CAAC,IACzG,CAEd,CAAC;AACN,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,25 +1,48 @@
|
|
1
|
-
import { Dropdown, Option } from '@fluentui/react-components';
|
2
|
-
import { filterEmptyEntries, firstOrNull } from '@kwiz/common';
|
1
|
+
import { Dropdown, DropdownProps, Option } from '@fluentui/react-components';
|
2
|
+
import { filterEmptyEntries, firstOrNull, isNullOrUndefined } from '@kwiz/common';
|
3
3
|
import React from 'react';
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
type ForwardProps = Omit<DropdownProps, "onSelect" | "selectedOptions" | "clearable">;
|
6
|
+
|
7
|
+
interface IProps<dataType, keyType extends string = string> extends ForwardProps {
|
8
|
+
required?: boolean;
|
9
|
+
selected: keyType | keyType[];
|
10
|
+
items: {
|
11
|
+
key: keyType, value: string, data?: dataType,
|
12
|
+
/** display complex controls in the drop down */
|
13
|
+
option?: JSX.Element;
|
14
|
+
}[];
|
15
|
+
onSelect: (
|
16
|
+
/** the specific option that was selected/unselected */
|
17
|
+
option: { key: keyType, value: string, data?: dataType },
|
18
|
+
/** only sent for multi select - all selected options, in case of multi select */
|
19
|
+
options?: { key: keyType, value: string, data?: dataType }[]) => void;
|
10
20
|
}
|
11
21
|
|
12
22
|
function $DropdownEX<keyType extends string = string, dataType = never>(props: IProps<dataType, keyType>, ref: React.ForwardedRef<HTMLButtonElement>) {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
23
|
+
const selected: keyType[] = Array.isArray(props.selected) ? props.selected : isNullOrUndefined(props.selected) ? [] : [props.selected];
|
24
|
+
|
25
|
+
//sometimes control will lose value when re-rendered
|
26
|
+
//use case: public forms when editing other fields after the dropdown was set
|
27
|
+
//re-set the text value manually to fix
|
28
|
+
let text = Array.isArray(props.selected)
|
29
|
+
? filterEmptyEntries(props.selected.map(s => {
|
30
|
+
let v = firstOrNull(props.items, i => i.key === s);
|
31
|
+
return v ? v.value : ''
|
32
|
+
})).join(', ')
|
33
|
+
: props.selected || "";
|
34
|
+
|
17
35
|
return (
|
18
|
-
<Dropdown
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
36
|
+
<Dropdown {...{ ...props, onSelect: undefined }} ref={ref} clearable={!props.required && !props.multiselect}
|
37
|
+
appearance='underline' selectedOptions={selected} value={text} onOptionSelect={(e, data) => {
|
38
|
+
let o = firstOrNull(props.items, i => i.key === data.optionValue);
|
39
|
+
if (props.multiselect) {
|
40
|
+
let current = data.selectedOptions.map(s => firstOrNull(props.items, i => i.key === s));
|
41
|
+
props.onSelect(o, current);
|
42
|
+
}
|
43
|
+
else props.onSelect(o);
|
44
|
+
}}>
|
45
|
+
{props.items.map(i => <Option key={i.key} value={i.key} text={i.value}>{i.option ? i.option : i.value}</Option>)}
|
23
46
|
</Dropdown>
|
24
47
|
|
25
48
|
);
|