@bds-web/ui 1.6.0 → 1.8.0
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/Dropdown/ui/DropdownPortal.d.ts +8 -0
- package/dist/Dropdown/ui/DropdownPortal.d.ts.map +1 -0
- package/dist/Dropdown/ui/DropdownPortal.js +26 -0
- package/dist/Dropdown/ui/index.d.ts.map +1 -1
- package/dist/Dropdown/ui/index.js +2 -1
- package/dist/Dropdown/ui/style.d.ts.map +1 -1
- package/dist/Dropdown/ui/style.js +1 -3
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface DropdownPortalProps {
|
|
2
|
+
children: React.ReactNode;
|
|
3
|
+
containerRef: React.RefObject<HTMLElement | null>;
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const DropdownPortal: ({ children, containerRef, isOpen }: DropdownPortalProps) => import("react").ReactPortal | null;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=DropdownPortal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropdownPortal.d.ts","sourceRoot":"","sources":["../../../src/Dropdown/ui/DropdownPortal.tsx"],"names":[],"mappings":"AAIA,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAClD,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,cAAc,GAAI,oCAAoC,mBAAmB,uCAgCrF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
export const DropdownPortal = ({ children, containerRef, isOpen }) => {
|
|
5
|
+
const [position, setPosition] = useState({ top: 0, left: 0, width: 0 });
|
|
6
|
+
const portalRef = useRef(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
if (isOpen && containerRef.current) {
|
|
9
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
10
|
+
setPosition({
|
|
11
|
+
top: rect.bottom + window.scrollY,
|
|
12
|
+
left: rect.left + window.scrollX,
|
|
13
|
+
width: rect.width,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}, [isOpen, containerRef]);
|
|
17
|
+
if (!isOpen)
|
|
18
|
+
return null;
|
|
19
|
+
return createPortal(_jsx("div", { ref: portalRef, style: {
|
|
20
|
+
position: "absolute",
|
|
21
|
+
top: position.top,
|
|
22
|
+
left: position.left,
|
|
23
|
+
width: position.width,
|
|
24
|
+
zIndex: 100000,
|
|
25
|
+
}, children: children }), document.body);
|
|
26
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Dropdown/ui/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Dropdown/ui/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM/C,eAAO,MAAM,QAAQ,GAAI,uDAMtB,aAAa,4CAkCf,CAAC"}
|
|
@@ -4,8 +4,9 @@ import { TriangleIcon } from "../../TriangleIcon";
|
|
|
4
4
|
import { useDropdown } from "../hooks/useDropdown";
|
|
5
5
|
import * as S from "./style";
|
|
6
6
|
import { useOutsideClick } from "../hooks/useOutsideClick";
|
|
7
|
+
import { DropdownPortal } from "./DropdownPortal";
|
|
7
8
|
export const Dropdown = ({ dropdownSize = "small", onSelect, options, selected, width = "auto", }) => {
|
|
8
9
|
const { isOpen, closeDropdown, toggleDropdown } = useDropdown();
|
|
9
10
|
const containerRef = useOutsideClick(isOpen, closeDropdown);
|
|
10
|
-
return (_jsxs(S.Container, { ref: containerRef, "$size": dropdownSize, "$width": width, onClick: toggleDropdown, children: [_jsxs(S.SelectedItem, { children: [_jsx(S.SelectedText, { children: selected ? selected.name : "선택해주세요." }), _jsx(TriangleIcon, {})] }), isOpen
|
|
11
|
+
return (_jsxs(S.Container, { ref: containerRef, "$size": dropdownSize, "$width": width, onClick: toggleDropdown, style: { position: "relative" }, children: [_jsxs(S.SelectedItem, { children: [_jsx(S.SelectedText, { children: selected ? selected.name : "선택해주세요." }), _jsx(TriangleIcon, {})] }), _jsx(DropdownPortal, { containerRef: containerRef, isOpen: isOpen, children: _jsx(S.OptionsList, { "$size": dropdownSize, "$isOpen": isOpen, children: options.map((option, idx) => (_jsx(S.OptionItem, { "$isSelected": selected?.value === option.value, "$size": dropdownSize, onClick: () => onSelect(option), children: option.name }, idx))) }) })] }));
|
|
11
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/Dropdown/ui/style.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAK9C,eAAO,MAAM,SAAS;;;;WAAuB,YAAY;YAAU,MAAM;yGASxE,CAAC;AAEF,eAAO,MAAM,YAAY;;;yGAQxB,CAAC;AAEF,eAAO,MAAM,YAAY;;;2GAIxB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;WAAsB,YAAY;aAAW,OAAO;
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../../src/Dropdown/ui/style.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAK9C,eAAO,MAAM,SAAS;;;;WAAuB,YAAY;YAAU,MAAM;yGASxE,CAAC;AAEF,eAAO,MAAM,YAAY;;;yGAQxB,CAAC;AAEF,eAAO,MAAM,YAAY;;;2GAIxB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;WAAsB,YAAY;aAAW,OAAO;6GAgB3E,CAAC;AAEF,eAAO,MAAM,UAAU;;;;WACd,YAAY;iBACN,OAAO;yGAerB,CAAC"}
|
|
@@ -38,9 +38,7 @@ export const OptionsList = styled.ul `
|
|
|
38
38
|
: `
|
|
39
39
|
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.05);
|
|
40
40
|
`};
|
|
41
|
-
position:
|
|
42
|
-
top: calc(100% + ${({ $size }) => ($size === "small" ? "4px" : "10px")});
|
|
43
|
-
left: -1px;
|
|
41
|
+
position: static;
|
|
44
42
|
box-sizing: border-box;
|
|
45
43
|
z-index: ${({ $isOpen }) => ($isOpen ? 100 : -1)};
|
|
46
44
|
overflow: hidden;
|