@dfx.swiss/react-components 1.1.3-beta.3 → 1.1.3-beta.4
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ControlProps } from './Form';
|
|
2
|
+
import { RefObject } from 'react';
|
|
2
3
|
import { IconVariant } from '../DfxIcon';
|
|
3
4
|
import { AssetIconVariant } from '../DfxAssetIcon';
|
|
4
5
|
export interface StyledDropdownProps<T> extends ControlProps {
|
|
@@ -12,6 +13,7 @@ export interface StyledDropdownProps<T> extends ControlProps {
|
|
|
12
13
|
descriptionFunc?: (item: T) => string;
|
|
13
14
|
priceFunc?: (item: T) => string;
|
|
14
15
|
assetIconFunc?: (item: T) => AssetIconVariant;
|
|
16
|
+
rootRef?: RefObject<HTMLElement>;
|
|
15
17
|
}
|
|
16
|
-
export default function StyledDropdown<T>({ label, labelIcon, control, name, rules, disabled, items, placeholder, full, smallLabel, labelFunc, balanceFunc, descriptionFunc, priceFunc, assetIconFunc, ...props }: StyledDropdownProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export default function StyledDropdown<T>({ label, labelIcon, control, name, rules, disabled, items, placeholder, full, smallLabel, labelFunc, balanceFunc, descriptionFunc, priceFunc, assetIconFunc, rootRef, ...props }: StyledDropdownProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
17
19
|
//# sourceMappingURL=StyledDropdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StyledDropdown.d.ts","sourceRoot":"","sources":["../../../src/stories/form/StyledDropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"StyledDropdown.d.ts","sourceRoot":"","sources":["../../../src/stories/form/StyledDropdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;AAC/D,OAAgB,EAAuB,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvE,OAAqB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGjE,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,YAAY;IAC1D,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAClC,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IACtC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,gBAAgB,CAAC;IAC9C,OAAO,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;CAClC;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,EACxC,KAAK,EACL,SAAS,EACT,OAAO,EACP,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,KAAK,EACL,WAAW,EACX,IAAI,EACJ,UAAU,EACV,SAAS,EACT,WAAW,EACX,eAAe,EACf,SAAS,EACT,aAAa,EACb,OAAO,EACP,GAAG,KAAK,EACT,EAAE,mBAAmB,CAAC,CAAC,CAAC,2CA6HxB"}
|
|
@@ -21,19 +21,20 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
|
-
import { useRef, useState } from 'react';
|
|
24
|
+
import { useEffect, useRef, useState } from 'react';
|
|
25
25
|
import DfxIcon, { IconColor, IconSize, IconVariant } from '../DfxIcon';
|
|
26
26
|
import { Controller } from 'react-hook-form';
|
|
27
27
|
import DfxAssetIcon from '../DfxAssetIcon';
|
|
28
28
|
import { Utils } from '../../utils';
|
|
29
29
|
export default function StyledDropdown(_a) {
|
|
30
|
-
var label = _a.label, labelIcon = _a.labelIcon, control = _a.control, name = _a.name, rules = _a.rules, disabled = _a.disabled, items = _a.items, placeholder = _a.placeholder, full = _a.full, smallLabel = _a.smallLabel, labelFunc = _a.labelFunc, balanceFunc = _a.balanceFunc, descriptionFunc = _a.descriptionFunc, priceFunc = _a.priceFunc, assetIconFunc = _a.assetIconFunc, props = __rest(_a, ["label", "labelIcon", "control", "name", "rules", "disabled", "items", "placeholder", "full", "smallLabel", "labelFunc", "balanceFunc", "descriptionFunc", "priceFunc", "assetIconFunc"]);
|
|
30
|
+
var label = _a.label, labelIcon = _a.labelIcon, control = _a.control, name = _a.name, rules = _a.rules, disabled = _a.disabled, items = _a.items, placeholder = _a.placeholder, full = _a.full, smallLabel = _a.smallLabel, labelFunc = _a.labelFunc, balanceFunc = _a.balanceFunc, descriptionFunc = _a.descriptionFunc, priceFunc = _a.priceFunc, assetIconFunc = _a.assetIconFunc, rootRef = _a.rootRef, props = __rest(_a, ["label", "labelIcon", "control", "name", "rules", "disabled", "items", "placeholder", "full", "smallLabel", "labelFunc", "balanceFunc", "descriptionFunc", "priceFunc", "assetIconFunc", "rootRef"]);
|
|
31
31
|
var buttonRef = useRef(null);
|
|
32
32
|
var dropdownRef = useRef(null);
|
|
33
33
|
var _b = useState(false), isOpen = _b[0], setIsOpen = _b[1];
|
|
34
34
|
var buttonClasses = 'flex justify-between border border-dfxGray-500 px-4 py-3 shadow-sm w-full';
|
|
35
35
|
isOpen ? (buttonClasses += ' rounded-x rounded-t bg-dfxGray-400/50') : (buttonClasses += ' rounded');
|
|
36
36
|
var isDisabled = disabled || items.length <= 1;
|
|
37
|
+
useEffect(function () { var _a; return (_a = rootRef === null || rootRef === void 0 ? void 0 : rootRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mousedown', closeDropdown); }, [rootRef, rootRef === null || rootRef === void 0 ? void 0 : rootRef.current, isOpen]);
|
|
37
38
|
function closeDropdown(e) {
|
|
38
39
|
if (isOpen &&
|
|
39
40
|
Utils.isNode(e.target) &&
|
|
@@ -44,7 +45,6 @@ export default function StyledDropdown(_a) {
|
|
|
44
45
|
setIsOpen(false);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
document.addEventListener('mousedown', closeDropdown);
|
|
48
48
|
return (_jsx(Controller, { control: control, render: function (_a) {
|
|
49
49
|
var _b = _a.field, onChange = _b.onChange, onBlur = _b.onBlur, value = _b.value;
|
|
50
50
|
return (_jsxs("div", __assign({ className: "relative ".concat(full ? 'w-full' : '') }, { children: [_jsxs("div", __assign({ className: "flex items-center ml-3.5 mb-2.5" }, { children: [labelIcon !== undefined && _jsx(DfxIcon, { icon: labelIcon, size: IconSize.SM, color: IconColor.BLUE }), _jsx("label", __assign({ className: "text-dfxBlue-800 ".concat(smallLabel ? 'text-sm' : 'text-base', " font-semibold ").concat(labelIcon ? 'pl-3.5' : '') }, { children: label }))] })), _jsxs("button", __assign({ ref: buttonRef, id: "dropDownButton", type: "button", onClick: function () { return setIsOpen(!isOpen); }, className: buttonClasses, onBlur: onBlur, disabled: isDisabled }, props, { children: [_jsxs("div", __assign({ className: "flex flex-row gap-2 items-center w-full" }, { children: [value && assetIconFunc && _jsx(DfxAssetIcon, { asset: assetIconFunc(value) }), _jsx("div", __assign({ className: "flex flex-col gap-1 justify-between text-left w-full" }, { children: value === undefined ? (_jsx("p", __assign({ className: "text-dfxGray-600 drop-shadow-none py-[0.25rem]" }, { children: placeholder }))) : (_jsxs(_Fragment, { children: [_jsxs("span", __assign({ className: "text-dfxBlue-800 leading-none font-semibold flex justify-between ".concat(!descriptionFunc && !assetIconFunc ? 'py-[0.25rem]' : '') }, { children: [labelFunc(value), balanceFunc && _jsx("p", { children: balanceFunc(value) })] })), descriptionFunc && (_jsxs("span", __assign({ className: "text-dfxGray-800 text-xs h-min leading-none flex justify-between" }, { children: [descriptionFunc(value), priceFunc && _jsx("p", { children: priceFunc(value) })] })))] })) }))] })), !isDisabled && (_jsx("div", __assign({ className: "place-self-center" }, { children: _jsx(DfxIcon, { icon: isOpen ? IconVariant.EXPAND_LESS : IconVariant.EXPAND_MORE, size: IconSize.LG }) })))] })), isOpen && (_jsx("div", __assign({ ref: dropdownRef, className: "absolute bg-white rounded-b w-full z-10 max-h-40 overflow-y-auto" }, { children: items.map(function (item, index) { return (_jsx("button", __assign({ onClick: function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StyledDropdown.js","sourceRoot":"","sources":["../../../src/stories/form/StyledDropdown.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"StyledDropdown.js","sourceRoot":"","sources":["../../../src/stories/form/StyledDropdown.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,YAAkC,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAgBpC,MAAM,CAAC,OAAO,UAAU,cAAc,CAAI,EAkBjB;IAjBvB,IAAA,KAAK,WAAA,EACL,SAAS,eAAA,EACT,OAAO,aAAA,EACP,IAAI,UAAA,EACJ,KAAK,WAAA,EAC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AC,IAAI,CAAC,EACrB,SAAS,IAAI,sBAAI,SAAS,CAAC,IAAI,CAAC,GAAK,KACjC,CACR,KACG,KACF,KAzBD,KAAK,CA0BH,CACV,EA7B2B,CA6B3B,CAAC,IACE,CACP,KACG,CACP;QA1FmD,CA0FnD,EACD,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,GACZ,CACH,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"private": false,
|
|
3
3
|
"name": "@dfx.swiss/react-components",
|
|
4
|
-
"version": "1.1.3-beta.
|
|
4
|
+
"version": "1.1.3-beta.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"tailwindcss": "^3.2.4",
|
|
88
88
|
"webpack": "^5.75.0"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "b0277e9bfb12eec6cc713f8cc689d98895591c79"
|
|
91
91
|
}
|