@aristobyte-ui/dropdown 2.5.1 → 2.6.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/README.md +120 -0
- package/package.json +6 -6
- package/es/src/main/components/Dropdown/Dropdown.scss +0 -64
- package/es/src/main/components/Dropdown/index.d.ts +0 -20
- package/es/src/main/components/Dropdown/index.d.ts.map +0 -1
- package/es/src/main/components/Dropdown/index.js +0 -133
- package/es/src/main/components/DropdownOption/DropdownOption.scss +0 -68
- package/es/src/main/components/DropdownOption/index.d.ts +0 -17
- package/es/src/main/components/DropdownOption/index.d.ts.map +0 -1
- package/es/src/main/components/DropdownOption/index.js +0 -13
- package/es/src/main/components/index.d.ts +0 -3
- package/es/src/main/components/index.d.ts.map +0 -1
- package/es/src/main/components/index.js +0 -2
- package/es/src/main/index.d.ts +0 -2
- package/es/src/main/index.d.ts.map +0 -1
- package/es/src/main/index.js +0 -1
- package/lib/src/main/components/Dropdown/Dropdown.scss +0 -64
- package/lib/src/main/components/Dropdown/index.d.ts +0 -20
- package/lib/src/main/components/Dropdown/index.d.ts.map +0 -1
- package/lib/src/main/components/Dropdown/index.js +0 -170
- package/lib/src/main/components/DropdownOption/DropdownOption.scss +0 -68
- package/lib/src/main/components/DropdownOption/index.d.ts +0 -17
- package/lib/src/main/components/DropdownOption/index.d.ts.map +0 -1
- package/lib/src/main/components/DropdownOption/index.js +0 -50
- package/lib/src/main/components/index.d.ts +0 -3
- package/lib/src/main/components/index.d.ts.map +0 -1
- package/lib/src/main/components/index.js +0 -18
- package/lib/src/main/index.d.ts +0 -2
- package/lib/src/main/index.d.ts.map +0 -1
- package/lib/src/main/index.js +0 -17
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @aristobyte-ui/dropdown
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/badge/TypeScript-5.8-blue?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript" />
|
|
5
|
+
<img src="https://img.shields.io/badge/Build-Turbo-green?style=for-the-badge&logo=turbo&logoColor=white" alt="TurboRepo" />
|
|
6
|
+
<img src="https://img.shields.io/badge/Lint-Strict-red?style=for-the-badge&logo=eslint&logoColor=white" alt="ESLint" />
|
|
7
|
+
<img src="https://img.shields.io/badge/License-MIT-black?style=for-the-badge&logo=open-source-initiative&logoColor=white" alt="License" />
|
|
8
|
+
<img src="https://img.shields.io/badge/AristoByte-UI-purple?style=for-the-badge&logo=react&logoColor=white" alt="AristoByte UI" />
|
|
9
|
+
<img src="https://img.shields.io/badge/Node-20.17.0+-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js >=20.17.0" />
|
|
10
|
+
<img src="https://img.shields.io/badge/Yarn-1.22+-2C8EBB?style=for-the-badge&logo=yarn&logoColor=white" alt="Yarn >=1.22" />
|
|
11
|
+
<img src="https://img.shields.io/badge/NPM-10.8+-CB3837?style=for-the-badge&logo=npm&logoColor=white" alt="NPM >=10.8" />
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
> A fully typed, modular, and composable Dropdown component built for AristoByteUI, leveraging Button for interactive triggers and providing lightweight, performant, and flexible menus for React applications.
|
|
15
|
+
|
|
16
|
+
## 📦 Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Install via Yarn
|
|
20
|
+
yarn add -D @aristobyte-ui/dropdown
|
|
21
|
+
|
|
22
|
+
# Or via npm
|
|
23
|
+
npm install -D @aristobyte-ui/dropdown
|
|
24
|
+
|
|
25
|
+
# Or via pnpm
|
|
26
|
+
pnpm add -D @aristobyte-ui/dropdown
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 🛠 Usage
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { Dropdown } from "@aristobyte-ui/dropdown";
|
|
34
|
+
import { Button } from "@aristobyte-ui/button";
|
|
35
|
+
|
|
36
|
+
export default function Example() {
|
|
37
|
+
return (
|
|
38
|
+
<Dropdown
|
|
39
|
+
trigger={<Button variant="primary">Options</Button>}
|
|
40
|
+
items={[
|
|
41
|
+
{ label: "Profile", onClick: () => console.log("Profile clicked") },
|
|
42
|
+
{ label: "Settings", onClick: () => console.log("Settings clicked") },
|
|
43
|
+
{ label: "Logout", onClick: () => console.log("Logout clicked") },
|
|
44
|
+
]}
|
|
45
|
+
placement="bottom-start"
|
|
46
|
+
disabled={false}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
##📂 Presets Available
|
|
53
|
+
|
|
54
|
+
- **trigger**: Any React element, commonly a Button, to toggle the dropdown.
|
|
55
|
+
- **items**: Array of menu items, each with label, optional icon, and onClick callback.
|
|
56
|
+
- **placement**: Positioning of the dropdown menu (e.g., `top`, `bottom`, `left`, `right` with variations like -start or -end).
|
|
57
|
+
- **disabled**: Boolean to disable the dropdown trigger.
|
|
58
|
+
|
|
59
|
+
## 🔧 Example in a Package
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { Dropdown } from "@aristobyte-ui/dropdown";
|
|
63
|
+
import { Button } from "@aristobyte-ui/button";
|
|
64
|
+
import { FiSettings, FiUser } from "react-icons/fi";
|
|
65
|
+
|
|
66
|
+
export function UserMenu() {
|
|
67
|
+
return (
|
|
68
|
+
<Dropdown
|
|
69
|
+
trigger={
|
|
70
|
+
<Button variant="secondary" appearance="outline">
|
|
71
|
+
Menu
|
|
72
|
+
</Button>
|
|
73
|
+
}
|
|
74
|
+
items={[
|
|
75
|
+
{
|
|
76
|
+
label: "Profile",
|
|
77
|
+
icon: FiUser,
|
|
78
|
+
onClick: () => console.log("Profile"),
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: "Settings",
|
|
82
|
+
icon: FiSettings,
|
|
83
|
+
onClick: () => console.log("Settings"),
|
|
84
|
+
},
|
|
85
|
+
{ label: "Logout", onClick: () => console.log("Logout") },
|
|
86
|
+
]}
|
|
87
|
+
placement="bottom-end"
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 📊 Why This Matters
|
|
94
|
+
|
|
95
|
+
- **Performance-first:** Lightweight CSS ensures fast rendering and smooth transitions.
|
|
96
|
+
- **Fully typed:** TypeScript-first API ensures predictable usage and IDE autocomplete.
|
|
97
|
+
- **AristoByteUI ready:** Seamlessly integrates with design tokens, SCSS modules, and Button component composition.
|
|
98
|
+
- **Flexible:** Supports multiple variants, appearances, sizes, radius options, icons, ripple-enabled interactive feedback, and nested menu structures.
|
|
99
|
+
|
|
100
|
+
## 🏆 Philosophy
|
|
101
|
+
|
|
102
|
+
- **Modular architecture:** Dropdown component is fully composable with Button and other interactive elements.
|
|
103
|
+
- **Declarative styling:** SCSS modules keep styles maintainable and scoped.
|
|
104
|
+
- **Strict typing & runtime flexibility:** Props fully typed while allowing runtime overrides.
|
|
105
|
+
- **Developer experience optimized:** Easy to use with predictable behavior and minimal boilerplate.
|
|
106
|
+
|
|
107
|
+
## 📜 License
|
|
108
|
+
|
|
109
|
+
MIT © AristoByte
|
|
110
|
+
|
|
111
|
+
## 🛡 Shields Showcase
|
|
112
|
+
|
|
113
|
+
<p align="center">
|
|
114
|
+
<img src="https://img.shields.io/badge/Consistency-100%25-green?style=for-the-badge&logo=typescript" />
|
|
115
|
+
<img src="https://img.shields.io/badge/Maintained-Active-brightgreen?style=for-the-badge&logo=github" />
|
|
116
|
+
<img src="https://img.shields.io/badge/Strictness-High-critical?style=for-the-badge&logo=eslint" />
|
|
117
|
+
<img src="https://img.shields.io/badge/Declarations-Enabled-blue?style=for-the-badge&logo=typescript" />
|
|
118
|
+
<img src="https://img.shields.io/badge/Monorepo-Turbo-green?style=for-the-badge&logo=monorepo" />
|
|
119
|
+
<img src="https://img.shields.io/badge/Interop-ESM%2FCJS-orange?style=for-the-badge&logo=javascript" />
|
|
120
|
+
</p>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aristobyte-ui/dropdown",
|
|
3
3
|
"description": "react dropdown component with trigger button, dropdownoptions, placement variants, fully typed typescript support, and composable integration with aristobyte ui button",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.6.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"author": "AristoByte <info@aristobyte.com>",
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"main": "lib/
|
|
47
|
-
"module": "es/
|
|
48
|
-
"types": "es/
|
|
46
|
+
"main": "lib/index.js",
|
|
47
|
+
"module": "es/index.js",
|
|
48
|
+
"types": "es/index.d.ts",
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^19.1.0",
|
|
51
51
|
"react-dom": "^19.1.0",
|
|
52
52
|
"sass": "^1.97.3"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@aristobyte-ui/button": "^2.
|
|
56
|
-
"@aristobyte-ui/utils": "^2.
|
|
55
|
+
"@aristobyte-ui/button": "^2.6.1",
|
|
56
|
+
"@aristobyte-ui/utils": "^2.6.1"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
@use '@aristobyte-ui/utils/styles' as *;
|
|
2
|
-
|
|
3
|
-
.dropdown {
|
|
4
|
-
width: max-content;
|
|
5
|
-
|
|
6
|
-
&__button {
|
|
7
|
-
width: max-content;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
&__box {
|
|
11
|
-
&-variant--default &-options {
|
|
12
|
-
background-color: $color-default;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
&-variant--primary &-options {
|
|
16
|
-
background-color: $color-primary;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
&-variant--secondary &-options {
|
|
20
|
-
background-color: $color-secondary;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
&-variant--warning &-options {
|
|
24
|
-
background-color: $color-warning;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
&-variant--error &-options {
|
|
28
|
-
background-color: $color-error;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&-variant--success &-options {
|
|
32
|
-
background-color: $color-success;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
&-overlay {
|
|
36
|
-
backdrop-filter: blur(12px);
|
|
37
|
-
height: 100%;
|
|
38
|
-
left: 0;
|
|
39
|
-
position: fixed;
|
|
40
|
-
top: 0;
|
|
41
|
-
width: 100%;
|
|
42
|
-
z-index: 99999999999;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
&-options {
|
|
46
|
-
align-items: flex-start;
|
|
47
|
-
border-radius: 8px; //TODO: change to dynamic
|
|
48
|
-
box-shadow:
|
|
49
|
-
0 4px 6px rgba(0, 0, 0, 0.04),
|
|
50
|
-
0 12px 24px rgba(0, 0, 0, 0.1);
|
|
51
|
-
display: flex;
|
|
52
|
-
flex-direction: column;
|
|
53
|
-
opacity: 1;
|
|
54
|
-
min-width: 300px;
|
|
55
|
-
padding: 4px;
|
|
56
|
-
position: absolute;
|
|
57
|
-
transition:
|
|
58
|
-
transform 200ms $cubic-bezier-secondary,
|
|
59
|
-
opacity 150ms ease;
|
|
60
|
-
width: 100%;
|
|
61
|
-
z-index: 99999999999;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { type IDropdownOption } from '../DropdownOption';
|
|
3
|
-
import { type IButton } from '@aristobyte-ui/button';
|
|
4
|
-
import './Dropdown.scss';
|
|
5
|
-
export interface IDropdown {
|
|
6
|
-
children: React.ReactElement<IDropdownOption> | React.ReactElement<IDropdownOption>[];
|
|
7
|
-
value: string;
|
|
8
|
-
button?: Omit<IButton, 'children' | 'dangerouslySetInnerHTML'>;
|
|
9
|
-
variant?: 'default' | 'primary' | 'secondary' | 'success' | 'error' | 'warning';
|
|
10
|
-
appearance?: 'solid' | 'outline' | 'outline-dashed' | 'no-outline' | 'glowing';
|
|
11
|
-
onChange?: (newValue: string) => void;
|
|
12
|
-
initiallyOpened?: boolean;
|
|
13
|
-
choice?: 'multiple' | 'single';
|
|
14
|
-
placeholder?: string;
|
|
15
|
-
disabled?: boolean;
|
|
16
|
-
className?: string;
|
|
17
|
-
style?: React.CSSProperties;
|
|
18
|
-
}
|
|
19
|
-
export declare const Dropdown: React.FC<IDropdown>;
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/dropdown/src/main/components/Dropdown/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,iBAAiB,CAAC;AAQzB,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC;IACtF,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,yBAAyB,CAAC,CAAC;IAC/D,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,GAAG,YAAY,GAAG,SAAS,CAAC;IAC/E,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA4JxC,CAAC"}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
|
-
import * as React from 'react';
|
|
39
|
-
import { AnimatePresence, motion } from 'framer-motion';
|
|
40
|
-
import { DropdownOption } from '../DropdownOption';
|
|
41
|
-
import { Button } from '@aristobyte-ui/button';
|
|
42
|
-
import { Portal } from '@aristobyte-ui/utils';
|
|
43
|
-
import './Dropdown.scss';
|
|
44
|
-
export var Dropdown = function (_a) {
|
|
45
|
-
var children = _a.children, value = _a.value, onChange = _a.onChange, _b = _a.appearance, appearance = _b === void 0 ? 'outline' : _b, _c = _a.variant, variant = _c === void 0 ? 'default' : _c, _d = _a.placeholder, placeholder = _d === void 0 ? 'Select' : _d, _e = _a.choice, choice = _e === void 0 ? 'single' : _e, _f = _a.className, className = _f === void 0 ? '' : _f, _g = _a.initiallyOpened, initiallyOpened = _g === void 0 ? false : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.button, button = _j === void 0 ? {} : _j, _k = _a.style, style = _k === void 0 ? {} : _k;
|
|
46
|
-
var _l = __read(React.useState(initiallyOpened), 2), isOpened = _l[0], setIsOpened = _l[1];
|
|
47
|
-
var _m = __read(React.useState(value ? [value] : []), 2), selected = _m[0], setSelected = _m[1];
|
|
48
|
-
var _o = __read(React.useState({
|
|
49
|
-
top: 0,
|
|
50
|
-
left: 0,
|
|
51
|
-
width: 0,
|
|
52
|
-
}), 2), position = _o[0], setPosition = _o[1];
|
|
53
|
-
var _p = __read(React.useState(0), 2), dropdownHeight = _p[0], setDropdownHeight = _p[1];
|
|
54
|
-
var _q = __read(React.useState(0), 2), buttonHeight = _q[0], setButtonHeight = _q[1];
|
|
55
|
-
var buttonRef = React.useRef(null);
|
|
56
|
-
var boxRef = React.useRef(null);
|
|
57
|
-
var uniqueId = React.useId();
|
|
58
|
-
React.useLayoutEffect(function () {
|
|
59
|
-
if (!isOpened) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (boxRef.current) {
|
|
63
|
-
setDropdownHeight(boxRef.current.getBoundingClientRect().height);
|
|
64
|
-
}
|
|
65
|
-
if (buttonRef.current) {
|
|
66
|
-
setButtonHeight(buttonRef.current.getBoundingClientRect().height);
|
|
67
|
-
}
|
|
68
|
-
}, [isOpened]);
|
|
69
|
-
var options = React.Children.toArray(children).filter(function (child) {
|
|
70
|
-
return React.isValidElement(child) && child.type === DropdownOption;
|
|
71
|
-
});
|
|
72
|
-
var isValidValue = function () {
|
|
73
|
-
return !!options.find(function (_a) {
|
|
74
|
-
var props = _a.props;
|
|
75
|
-
return props.value === value;
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
var handleChange = function (currentRadioValue) {
|
|
79
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(currentRadioValue);
|
|
80
|
-
if (!choice) {
|
|
81
|
-
setSelected([currentRadioValue]);
|
|
82
|
-
setIsOpened(false);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (choice === 'single') {
|
|
86
|
-
setSelected([currentRadioValue]);
|
|
87
|
-
}
|
|
88
|
-
if (choice === 'multiple') {
|
|
89
|
-
setSelected(function (prev) {
|
|
90
|
-
return prev.includes(currentRadioValue) ? prev.filter(function (v) { return v !== currentRadioValue; }) : __spreadArray(__spreadArray([], __read(prev), false), [currentRadioValue], false);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
var handleToggle = function (e) {
|
|
95
|
-
var _a;
|
|
96
|
-
if (disabled)
|
|
97
|
-
return;
|
|
98
|
-
var rect = (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
99
|
-
if (!rect)
|
|
100
|
-
return;
|
|
101
|
-
var spaceBelow = window.innerHeight - rect.bottom;
|
|
102
|
-
var spaceAbove = rect.top;
|
|
103
|
-
var shouldOpenUpwards = dropdownHeight > 0 && spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
|
|
104
|
-
var finalPosition = {
|
|
105
|
-
top: shouldOpenUpwards
|
|
106
|
-
? rect.top + window.scrollY - dropdownHeight - buttonHeight / 2
|
|
107
|
-
: rect.top + window.scrollY + buttonHeight + 6,
|
|
108
|
-
left: rect.left + window.scrollX,
|
|
109
|
-
width: rect.width,
|
|
110
|
-
};
|
|
111
|
-
setPosition(finalPosition);
|
|
112
|
-
if (button === null || button === void 0 ? void 0 : button.onClick)
|
|
113
|
-
button.onClick(e);
|
|
114
|
-
setIsOpened(function (prev) { return !prev; });
|
|
115
|
-
};
|
|
116
|
-
if (!isValidValue()) {
|
|
117
|
-
throw new Error('The "value" prop did not match with any of the DropdownOption "value" prop');
|
|
118
|
-
}
|
|
119
|
-
return (React.createElement(React.Fragment, null,
|
|
120
|
-
React.createElement("div", { className: "dropdown ".concat(className) },
|
|
121
|
-
React.createElement(Button, { onClick: handleToggle, className: "dropdown__button ".concat((button === null || button === void 0 ? void 0 : button.className) || ''), appearance: (button === null || button === void 0 ? void 0 : button.appearance) || appearance, variant: (button === null || button === void 0 ? void 0 : button.variant) || variant, disabled: (button === null || button === void 0 ? void 0 : button.disabled) || disabled, ref: buttonRef }, placeholder)),
|
|
122
|
-
React.createElement(Portal, null,
|
|
123
|
-
React.createElement(AnimatePresence, null, isOpened && (React.createElement("div", { className: "dropdown__box ".concat("dropdown__box-variant--".concat(variant)), style: style },
|
|
124
|
-
React.createElement(motion.div, { className: "dropdown__box-overlay", initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.3, ease: 'easeIn' }, onClick: function () { return setIsOpened(false); } }),
|
|
125
|
-
React.createElement(motion.div, { ref: boxRef, className: "dropdown__box-options", initial: { opacity: 0, y: 20, scale: 0.95 }, animate: { opacity: 1, y: 0, scale: 1 }, exit: { opacity: 0, y: 20, scale: 0.95 }, transition: { duration: 0.2, ease: 'easeIn' }, style: {
|
|
126
|
-
top: position.top,
|
|
127
|
-
left: position.left,
|
|
128
|
-
width: position.width,
|
|
129
|
-
} }, options.map(function (_a) {
|
|
130
|
-
var props = _a.props;
|
|
131
|
-
return (React.createElement(DropdownOption, __assign({}, props, { variant: variant, appearance: appearance, key: "".concat(props.value, "-").concat(uniqueId), selectedValues: selected, onChange: function () { return handleChange(props.value); } })));
|
|
132
|
-
}))))))));
|
|
133
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
@use '@aristobyte-ui/utils/styles' as *;
|
|
2
|
-
|
|
3
|
-
.dropdown-option {
|
|
4
|
-
align-items: center;
|
|
5
|
-
border-radius: 8px; //TODO: change to dynamic
|
|
6
|
-
color: $white;
|
|
7
|
-
display: flex;
|
|
8
|
-
font-size: 14px;
|
|
9
|
-
font-weight: 500;
|
|
10
|
-
gap: 10px;
|
|
11
|
-
padding: 10px 16px;
|
|
12
|
-
text-align: left;
|
|
13
|
-
transition: all 120ms ease-out;
|
|
14
|
-
width: 100%;
|
|
15
|
-
|
|
16
|
-
&-variant {
|
|
17
|
-
&--default:hover {
|
|
18
|
-
background-color: $color-default-hover;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
&--primary:hover {
|
|
22
|
-
background-color: $color-primary-hover;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
&--secondary:hover {
|
|
26
|
-
background-color: $color-secondary-hover;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
&--warning:hover {
|
|
30
|
-
background-color: $color-warning-hover;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
&--error:hover {
|
|
34
|
-
background-color: $color-error-hover;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
&--success:hover {
|
|
38
|
-
background-color: $color-success-hover;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
&--disabled,
|
|
43
|
-
&--disabled:hover {
|
|
44
|
-
background-color: $color-default-disabled;
|
|
45
|
-
cursor: auto;
|
|
46
|
-
opacity: 0.5;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
&__title {
|
|
50
|
-
color: $white;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
&__description {
|
|
54
|
-
color: rgba($white, 0.6);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
&__tick {
|
|
58
|
-
color: rgba($white, 0.6);
|
|
59
|
-
opacity: 0;
|
|
60
|
-
transform: scale(0, 0.7) translate(0, 10px);
|
|
61
|
-
transition: all 120ms ease-out;
|
|
62
|
-
|
|
63
|
-
&--active {
|
|
64
|
-
opacity: 1;
|
|
65
|
-
transform: scale(1) translate(0);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import './DropdownOption.scss';
|
|
3
|
-
export interface IDropdownOption {
|
|
4
|
-
variant?: 'default' | 'primary' | 'secondary' | 'success' | 'error' | 'warning';
|
|
5
|
-
appearance?: 'solid' | 'outline' | 'outline-dashed' | 'no-outline' | 'glowing';
|
|
6
|
-
children: string;
|
|
7
|
-
value: string;
|
|
8
|
-
onChange?: () => void;
|
|
9
|
-
selectedValues?: string[];
|
|
10
|
-
description?: string;
|
|
11
|
-
icon?: string;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
choice?: 'multiple' | 'single';
|
|
14
|
-
style?: React.CSSProperties;
|
|
15
|
-
}
|
|
16
|
-
export declare const DropdownOption: React.FC<IDropdownOption>;
|
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/dropdown/src/main/components/DropdownOption/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,uBAAuB,CAAC;AAE/B,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,GAAG,YAAY,GAAG,SAAS,CAAC;IAC/E,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA+BpD,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Icons } from '@aristobyte-ui/utils';
|
|
3
|
-
import './DropdownOption.scss';
|
|
4
|
-
export var DropdownOption = function (_a) {
|
|
5
|
-
var variant = _a.variant, children = _a.children, value = _a.value, selectedValues = _a.selectedValues, onChange = _a.onChange, description = _a.description, disabled = _a.disabled, _b = _a.style, style = _b === void 0 ? {} : _b;
|
|
6
|
-
var uniqueId = React.useId();
|
|
7
|
-
return (React.createElement("button", { style: style, key: uniqueId, disabled: disabled, className: "".concat('dropdown-option', " ").concat("dropdown-option-variant--".concat(variant), " ").concat(disabled ? 'dropdown-option--disabled' : ''), onClick: onChange },
|
|
8
|
-
React.createElement("div", { className: 'dropdown-option__content' },
|
|
9
|
-
React.createElement("h3", { className: 'dropdown-option__title' }, children),
|
|
10
|
-
React.createElement("p", { className: 'dropdown-option__description' }, description)),
|
|
11
|
-
React.createElement("div", { className: "".concat('dropdown-option__tick', " ").concat((selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(value)) ? 'dropdown-option__tick--active' : '') },
|
|
12
|
-
React.createElement(Icons.Success, { size: 18 }))));
|
|
13
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/dropdown/src/main/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
package/es/src/main/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/dropdown/src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
package/es/src/main/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './components';
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
@use '@aristobyte-ui/utils/styles' as *;
|
|
2
|
-
|
|
3
|
-
.dropdown {
|
|
4
|
-
width: max-content;
|
|
5
|
-
|
|
6
|
-
&__button {
|
|
7
|
-
width: max-content;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
&__box {
|
|
11
|
-
&-variant--default &-options {
|
|
12
|
-
background-color: $color-default;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
&-variant--primary &-options {
|
|
16
|
-
background-color: $color-primary;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
&-variant--secondary &-options {
|
|
20
|
-
background-color: $color-secondary;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
&-variant--warning &-options {
|
|
24
|
-
background-color: $color-warning;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
&-variant--error &-options {
|
|
28
|
-
background-color: $color-error;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&-variant--success &-options {
|
|
32
|
-
background-color: $color-success;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
&-overlay {
|
|
36
|
-
backdrop-filter: blur(12px);
|
|
37
|
-
height: 100%;
|
|
38
|
-
left: 0;
|
|
39
|
-
position: fixed;
|
|
40
|
-
top: 0;
|
|
41
|
-
width: 100%;
|
|
42
|
-
z-index: 99999999999;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
&-options {
|
|
46
|
-
align-items: flex-start;
|
|
47
|
-
border-radius: 8px; //TODO: change to dynamic
|
|
48
|
-
box-shadow:
|
|
49
|
-
0 4px 6px rgba(0, 0, 0, 0.04),
|
|
50
|
-
0 12px 24px rgba(0, 0, 0, 0.1);
|
|
51
|
-
display: flex;
|
|
52
|
-
flex-direction: column;
|
|
53
|
-
opacity: 1;
|
|
54
|
-
min-width: 300px;
|
|
55
|
-
padding: 4px;
|
|
56
|
-
position: absolute;
|
|
57
|
-
transition:
|
|
58
|
-
transform 200ms $cubic-bezier-secondary,
|
|
59
|
-
opacity 150ms ease;
|
|
60
|
-
width: 100%;
|
|
61
|
-
z-index: 99999999999;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { type IDropdownOption } from '../DropdownOption';
|
|
3
|
-
import { type IButton } from '@aristobyte-ui/button';
|
|
4
|
-
import './Dropdown.scss';
|
|
5
|
-
export interface IDropdown {
|
|
6
|
-
children: React.ReactElement<IDropdownOption> | React.ReactElement<IDropdownOption>[];
|
|
7
|
-
value: string;
|
|
8
|
-
button?: Omit<IButton, 'children' | 'dangerouslySetInnerHTML'>;
|
|
9
|
-
variant?: 'default' | 'primary' | 'secondary' | 'success' | 'error' | 'warning';
|
|
10
|
-
appearance?: 'solid' | 'outline' | 'outline-dashed' | 'no-outline' | 'glowing';
|
|
11
|
-
onChange?: (newValue: string) => void;
|
|
12
|
-
initiallyOpened?: boolean;
|
|
13
|
-
choice?: 'multiple' | 'single';
|
|
14
|
-
placeholder?: string;
|
|
15
|
-
disabled?: boolean;
|
|
16
|
-
className?: string;
|
|
17
|
-
style?: React.CSSProperties;
|
|
18
|
-
}
|
|
19
|
-
export declare const Dropdown: React.FC<IDropdown>;
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/dropdown/src/main/components/Dropdown/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,iBAAiB,CAAC;AAQzB,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC;IACtF,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,yBAAyB,CAAC,CAAC;IAC/D,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,GAAG,YAAY,GAAG,SAAS,CAAC;IAC/E,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA4JxC,CAAC"}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use client';
|
|
3
|
-
var __assign = (this && this.__assign) || function () {
|
|
4
|
-
__assign = Object.assign || function(t) {
|
|
5
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
-
s = arguments[i];
|
|
7
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
-
t[p] = s[p];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
return __assign.apply(this, arguments);
|
|
13
|
-
};
|
|
14
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
-
}
|
|
20
|
-
Object.defineProperty(o, k2, desc);
|
|
21
|
-
}) : (function(o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
}));
|
|
25
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
-
}) : function(o, v) {
|
|
28
|
-
o["default"] = v;
|
|
29
|
-
});
|
|
30
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
-
var ownKeys = function(o) {
|
|
32
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
-
var ar = [];
|
|
34
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
-
return ar;
|
|
36
|
-
};
|
|
37
|
-
return ownKeys(o);
|
|
38
|
-
};
|
|
39
|
-
return function (mod) {
|
|
40
|
-
if (mod && mod.__esModule) return mod;
|
|
41
|
-
var result = {};
|
|
42
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
-
__setModuleDefault(result, mod);
|
|
44
|
-
return result;
|
|
45
|
-
};
|
|
46
|
-
})();
|
|
47
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
48
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
49
|
-
if (!m) return o;
|
|
50
|
-
var i = m.call(o), r, ar = [], e;
|
|
51
|
-
try {
|
|
52
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
53
|
-
}
|
|
54
|
-
catch (error) { e = { error: error }; }
|
|
55
|
-
finally {
|
|
56
|
-
try {
|
|
57
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
58
|
-
}
|
|
59
|
-
finally { if (e) throw e.error; }
|
|
60
|
-
}
|
|
61
|
-
return ar;
|
|
62
|
-
};
|
|
63
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
64
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
65
|
-
if (ar || !(i in from)) {
|
|
66
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
67
|
-
ar[i] = from[i];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
71
|
-
};
|
|
72
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
|
-
exports.Dropdown = void 0;
|
|
74
|
-
var React = __importStar(require("react"));
|
|
75
|
-
var framer_motion_1 = require("framer-motion");
|
|
76
|
-
var DropdownOption_1 = require("../DropdownOption");
|
|
77
|
-
var button_1 = require("@aristobyte-ui/button");
|
|
78
|
-
var utils_1 = require("@aristobyte-ui/utils");
|
|
79
|
-
require("./Dropdown.scss");
|
|
80
|
-
var Dropdown = function (_a) {
|
|
81
|
-
var children = _a.children, value = _a.value, onChange = _a.onChange, _b = _a.appearance, appearance = _b === void 0 ? 'outline' : _b, _c = _a.variant, variant = _c === void 0 ? 'default' : _c, _d = _a.placeholder, placeholder = _d === void 0 ? 'Select' : _d, _e = _a.choice, choice = _e === void 0 ? 'single' : _e, _f = _a.className, className = _f === void 0 ? '' : _f, _g = _a.initiallyOpened, initiallyOpened = _g === void 0 ? false : _g, _h = _a.disabled, disabled = _h === void 0 ? false : _h, _j = _a.button, button = _j === void 0 ? {} : _j, _k = _a.style, style = _k === void 0 ? {} : _k;
|
|
82
|
-
var _l = __read(React.useState(initiallyOpened), 2), isOpened = _l[0], setIsOpened = _l[1];
|
|
83
|
-
var _m = __read(React.useState(value ? [value] : []), 2), selected = _m[0], setSelected = _m[1];
|
|
84
|
-
var _o = __read(React.useState({
|
|
85
|
-
top: 0,
|
|
86
|
-
left: 0,
|
|
87
|
-
width: 0,
|
|
88
|
-
}), 2), position = _o[0], setPosition = _o[1];
|
|
89
|
-
var _p = __read(React.useState(0), 2), dropdownHeight = _p[0], setDropdownHeight = _p[1];
|
|
90
|
-
var _q = __read(React.useState(0), 2), buttonHeight = _q[0], setButtonHeight = _q[1];
|
|
91
|
-
var buttonRef = React.useRef(null);
|
|
92
|
-
var boxRef = React.useRef(null);
|
|
93
|
-
var uniqueId = React.useId();
|
|
94
|
-
React.useLayoutEffect(function () {
|
|
95
|
-
if (!isOpened) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (boxRef.current) {
|
|
99
|
-
setDropdownHeight(boxRef.current.getBoundingClientRect().height);
|
|
100
|
-
}
|
|
101
|
-
if (buttonRef.current) {
|
|
102
|
-
setButtonHeight(buttonRef.current.getBoundingClientRect().height);
|
|
103
|
-
}
|
|
104
|
-
}, [isOpened]);
|
|
105
|
-
var options = React.Children.toArray(children).filter(function (child) {
|
|
106
|
-
return React.isValidElement(child) && child.type === DropdownOption_1.DropdownOption;
|
|
107
|
-
});
|
|
108
|
-
var isValidValue = function () {
|
|
109
|
-
return !!options.find(function (_a) {
|
|
110
|
-
var props = _a.props;
|
|
111
|
-
return props.value === value;
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
var handleChange = function (currentRadioValue) {
|
|
115
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(currentRadioValue);
|
|
116
|
-
if (!choice) {
|
|
117
|
-
setSelected([currentRadioValue]);
|
|
118
|
-
setIsOpened(false);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (choice === 'single') {
|
|
122
|
-
setSelected([currentRadioValue]);
|
|
123
|
-
}
|
|
124
|
-
if (choice === 'multiple') {
|
|
125
|
-
setSelected(function (prev) {
|
|
126
|
-
return prev.includes(currentRadioValue) ? prev.filter(function (v) { return v !== currentRadioValue; }) : __spreadArray(__spreadArray([], __read(prev), false), [currentRadioValue], false);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
var handleToggle = function (e) {
|
|
131
|
-
var _a;
|
|
132
|
-
if (disabled)
|
|
133
|
-
return;
|
|
134
|
-
var rect = (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
135
|
-
if (!rect)
|
|
136
|
-
return;
|
|
137
|
-
var spaceBelow = window.innerHeight - rect.bottom;
|
|
138
|
-
var spaceAbove = rect.top;
|
|
139
|
-
var shouldOpenUpwards = dropdownHeight > 0 && spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
|
|
140
|
-
var finalPosition = {
|
|
141
|
-
top: shouldOpenUpwards
|
|
142
|
-
? rect.top + window.scrollY - dropdownHeight - buttonHeight / 2
|
|
143
|
-
: rect.top + window.scrollY + buttonHeight + 6,
|
|
144
|
-
left: rect.left + window.scrollX,
|
|
145
|
-
width: rect.width,
|
|
146
|
-
};
|
|
147
|
-
setPosition(finalPosition);
|
|
148
|
-
if (button === null || button === void 0 ? void 0 : button.onClick)
|
|
149
|
-
button.onClick(e);
|
|
150
|
-
setIsOpened(function (prev) { return !prev; });
|
|
151
|
-
};
|
|
152
|
-
if (!isValidValue()) {
|
|
153
|
-
throw new Error('The "value" prop did not match with any of the DropdownOption "value" prop');
|
|
154
|
-
}
|
|
155
|
-
return (React.createElement(React.Fragment, null,
|
|
156
|
-
React.createElement("div", { className: "dropdown ".concat(className) },
|
|
157
|
-
React.createElement(button_1.Button, { onClick: handleToggle, className: "dropdown__button ".concat((button === null || button === void 0 ? void 0 : button.className) || ''), appearance: (button === null || button === void 0 ? void 0 : button.appearance) || appearance, variant: (button === null || button === void 0 ? void 0 : button.variant) || variant, disabled: (button === null || button === void 0 ? void 0 : button.disabled) || disabled, ref: buttonRef }, placeholder)),
|
|
158
|
-
React.createElement(utils_1.Portal, null,
|
|
159
|
-
React.createElement(framer_motion_1.AnimatePresence, null, isOpened && (React.createElement("div", { className: "dropdown__box ".concat("dropdown__box-variant--".concat(variant)), style: style },
|
|
160
|
-
React.createElement(framer_motion_1.motion.div, { className: "dropdown__box-overlay", initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.3, ease: 'easeIn' }, onClick: function () { return setIsOpened(false); } }),
|
|
161
|
-
React.createElement(framer_motion_1.motion.div, { ref: boxRef, className: "dropdown__box-options", initial: { opacity: 0, y: 20, scale: 0.95 }, animate: { opacity: 1, y: 0, scale: 1 }, exit: { opacity: 0, y: 20, scale: 0.95 }, transition: { duration: 0.2, ease: 'easeIn' }, style: {
|
|
162
|
-
top: position.top,
|
|
163
|
-
left: position.left,
|
|
164
|
-
width: position.width,
|
|
165
|
-
} }, options.map(function (_a) {
|
|
166
|
-
var props = _a.props;
|
|
167
|
-
return (React.createElement(DropdownOption_1.DropdownOption, __assign({}, props, { variant: variant, appearance: appearance, key: "".concat(props.value, "-").concat(uniqueId), selectedValues: selected, onChange: function () { return handleChange(props.value); } })));
|
|
168
|
-
}))))))));
|
|
169
|
-
};
|
|
170
|
-
exports.Dropdown = Dropdown;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
@use '@aristobyte-ui/utils/styles' as *;
|
|
2
|
-
|
|
3
|
-
.dropdown-option {
|
|
4
|
-
align-items: center;
|
|
5
|
-
border-radius: 8px; //TODO: change to dynamic
|
|
6
|
-
color: $white;
|
|
7
|
-
display: flex;
|
|
8
|
-
font-size: 14px;
|
|
9
|
-
font-weight: 500;
|
|
10
|
-
gap: 10px;
|
|
11
|
-
padding: 10px 16px;
|
|
12
|
-
text-align: left;
|
|
13
|
-
transition: all 120ms ease-out;
|
|
14
|
-
width: 100%;
|
|
15
|
-
|
|
16
|
-
&-variant {
|
|
17
|
-
&--default:hover {
|
|
18
|
-
background-color: $color-default-hover;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
&--primary:hover {
|
|
22
|
-
background-color: $color-primary-hover;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
&--secondary:hover {
|
|
26
|
-
background-color: $color-secondary-hover;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
&--warning:hover {
|
|
30
|
-
background-color: $color-warning-hover;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
&--error:hover {
|
|
34
|
-
background-color: $color-error-hover;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
&--success:hover {
|
|
38
|
-
background-color: $color-success-hover;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
&--disabled,
|
|
43
|
-
&--disabled:hover {
|
|
44
|
-
background-color: $color-default-disabled;
|
|
45
|
-
cursor: auto;
|
|
46
|
-
opacity: 0.5;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
&__title {
|
|
50
|
-
color: $white;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
&__description {
|
|
54
|
-
color: rgba($white, 0.6);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
&__tick {
|
|
58
|
-
color: rgba($white, 0.6);
|
|
59
|
-
opacity: 0;
|
|
60
|
-
transform: scale(0, 0.7) translate(0, 10px);
|
|
61
|
-
transition: all 120ms ease-out;
|
|
62
|
-
|
|
63
|
-
&--active {
|
|
64
|
-
opacity: 1;
|
|
65
|
-
transform: scale(1) translate(0);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import './DropdownOption.scss';
|
|
3
|
-
export interface IDropdownOption {
|
|
4
|
-
variant?: 'default' | 'primary' | 'secondary' | 'success' | 'error' | 'warning';
|
|
5
|
-
appearance?: 'solid' | 'outline' | 'outline-dashed' | 'no-outline' | 'glowing';
|
|
6
|
-
children: string;
|
|
7
|
-
value: string;
|
|
8
|
-
onChange?: () => void;
|
|
9
|
-
selectedValues?: string[];
|
|
10
|
-
description?: string;
|
|
11
|
-
icon?: string;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
choice?: 'multiple' | 'single';
|
|
14
|
-
style?: React.CSSProperties;
|
|
15
|
-
}
|
|
16
|
-
export declare const DropdownOption: React.FC<IDropdownOption>;
|
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/dropdown/src/main/components/DropdownOption/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,uBAAuB,CAAC;AAE/B,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAChF,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,GAAG,YAAY,GAAG,SAAS,CAAC;IAC/E,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA+BpD,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.DropdownOption = void 0;
|
|
37
|
-
var React = __importStar(require("react"));
|
|
38
|
-
var utils_1 = require("@aristobyte-ui/utils");
|
|
39
|
-
require("./DropdownOption.scss");
|
|
40
|
-
var DropdownOption = function (_a) {
|
|
41
|
-
var variant = _a.variant, children = _a.children, value = _a.value, selectedValues = _a.selectedValues, onChange = _a.onChange, description = _a.description, disabled = _a.disabled, _b = _a.style, style = _b === void 0 ? {} : _b;
|
|
42
|
-
var uniqueId = React.useId();
|
|
43
|
-
return (React.createElement("button", { style: style, key: uniqueId, disabled: disabled, className: "".concat('dropdown-option', " ").concat("dropdown-option-variant--".concat(variant), " ").concat(disabled ? 'dropdown-option--disabled' : ''), onClick: onChange },
|
|
44
|
-
React.createElement("div", { className: 'dropdown-option__content' },
|
|
45
|
-
React.createElement("h3", { className: 'dropdown-option__title' }, children),
|
|
46
|
-
React.createElement("p", { className: 'dropdown-option__description' }, description)),
|
|
47
|
-
React.createElement("div", { className: "".concat('dropdown-option__tick', " ").concat((selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.includes(value)) ? 'dropdown-option__tick--active' : '') },
|
|
48
|
-
React.createElement(utils_1.Icons.Success, { size: 18 }))));
|
|
49
|
-
};
|
|
50
|
-
exports.DropdownOption = DropdownOption;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/dropdown/src/main/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Dropdown"), exports);
|
|
18
|
-
__exportStar(require("./DropdownOption"), exports);
|
package/lib/src/main/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/dropdown/src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
package/lib/src/main/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./components"), exports);
|