@aristobyte-ui/dropdown 2.6.0 → 2.6.2

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.
@@ -0,0 +1,64 @@
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
+ }
@@ -0,0 +1,20 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../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"}
@@ -0,0 +1,133 @@
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
+ };
@@ -0,0 +1,68 @@
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
+ }
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../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"}
@@ -0,0 +1,13 @@
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
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./Dropdown";
2
+ export * from "./DropdownOption";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/main/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./Dropdown";
2
+ export * from "./DropdownOption";
package/es/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
package/es/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './components';