@tecsinapse/cortex-react 1.9.37 → 1.9.38-beta.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/cjs/components/Popover/Content.js +2 -2
- package/dist/cjs/components/Select/Popover.js +15 -1
- package/dist/cjs/components/Select/Root.js +14 -1
- package/dist/cjs/components/Select/Trigger.js +12 -5
- package/dist/esm/components/Popover/Content.js +3 -3
- package/dist/esm/components/Select/Popover.js +16 -2
- package/dist/esm/components/Select/Root.js +15 -2
- package/dist/esm/components/Select/Trigger.js +13 -6
- package/dist/types/components/Select/context.d.ts +2 -0
- package/package.json +2 -2
|
@@ -21,7 +21,7 @@ const PopoverContent = ({
|
|
|
21
21
|
getFloatingProps,
|
|
22
22
|
context
|
|
23
23
|
} = Context.usePopoverContext();
|
|
24
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, isOpen && /* @__PURE__ */ React.createElement(react.
|
|
24
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, isOpen && /* @__PURE__ */ React.createElement(react.FloatingFocusManager, { ...rest, context, modal }, /* @__PURE__ */ React.createElement(
|
|
25
25
|
"div",
|
|
26
26
|
{
|
|
27
27
|
ref: refs.setFloating,
|
|
@@ -38,7 +38,7 @@ const PopoverContent = ({
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
children
|
|
41
|
-
)))
|
|
41
|
+
)));
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
exports.PopoverContent = PopoverContent;
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
|
+
var clsx = require('clsx');
|
|
4
5
|
var index = require('../Popover/index.js');
|
|
6
|
+
var react = require('@floating-ui/react');
|
|
7
|
+
var context = require('./context.js');
|
|
5
8
|
|
|
6
9
|
const SelectPopover = ({ children }) => {
|
|
7
|
-
|
|
10
|
+
const { triggerWidth } = React.useContext(context.SelectContext);
|
|
11
|
+
const widthClass = triggerWidth ? `w-[${triggerWidth}px]` : "w-auto";
|
|
12
|
+
return /* @__PURE__ */ React.createElement(react.FloatingPortal, null, /* @__PURE__ */ React.createElement(
|
|
13
|
+
index.Popover.Content,
|
|
14
|
+
{
|
|
15
|
+
className: clsx(
|
|
16
|
+
"bg-white max-h-[30vh] overflow-y-scroll gap-y-mili flex flex-col p-0",
|
|
17
|
+
widthClass
|
|
18
|
+
)
|
|
19
|
+
},
|
|
20
|
+
children
|
|
21
|
+
));
|
|
8
22
|
};
|
|
9
23
|
|
|
10
24
|
exports.SelectPopover = SelectPopover;
|
|
@@ -12,6 +12,7 @@ const SelectRoot = ({
|
|
|
12
12
|
labelExtractor,
|
|
13
13
|
className
|
|
14
14
|
}) => {
|
|
15
|
+
const [triggerWidth, setTriggerWidth] = React.useState(0);
|
|
15
16
|
return /* @__PURE__ */ React.createElement(
|
|
16
17
|
index.Popover.Root,
|
|
17
18
|
{
|
|
@@ -19,7 +20,19 @@ const SelectRoot = ({
|
|
|
19
20
|
placement: "bottom",
|
|
20
21
|
trigger: "click"
|
|
21
22
|
},
|
|
22
|
-
/* @__PURE__ */ React.createElement(
|
|
23
|
+
/* @__PURE__ */ React.createElement(
|
|
24
|
+
context.SelectContext.Provider,
|
|
25
|
+
{
|
|
26
|
+
value: {
|
|
27
|
+
value,
|
|
28
|
+
keyExtractor,
|
|
29
|
+
labelExtractor,
|
|
30
|
+
triggerWidth,
|
|
31
|
+
setTriggerWidth
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
/* @__PURE__ */ React.createElement(Content.Content, { className }, children)
|
|
35
|
+
)
|
|
23
36
|
);
|
|
24
37
|
};
|
|
25
38
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var cortexCore = require('@tecsinapse/cortex-core');
|
|
4
3
|
var React = require('react');
|
|
5
4
|
var io5 = require('react-icons/io5');
|
|
6
5
|
var index = require('../Popover/index.js');
|
|
7
6
|
var context = require('./context.js');
|
|
8
7
|
var clsx = require('clsx');
|
|
8
|
+
var cortexCore = require('@tecsinapse/cortex-core');
|
|
9
9
|
|
|
10
10
|
const { button } = cortexCore.selectVariants();
|
|
11
11
|
const SelectTrigger = ({
|
|
@@ -15,7 +15,8 @@ const SelectTrigger = ({
|
|
|
15
15
|
multiLabelSelected,
|
|
16
16
|
...rest
|
|
17
17
|
}) => {
|
|
18
|
-
const { value, labelExtractor } = React.useContext(context.SelectContext);
|
|
18
|
+
const { value, labelExtractor, setTriggerWidth } = React.useContext(context.SelectContext);
|
|
19
|
+
const triggerRef = React.useRef(null);
|
|
19
20
|
const _placeholder = React.useMemo(() => {
|
|
20
21
|
if (value?.length === 0 || !value) return placeholder ?? label;
|
|
21
22
|
if (value?.length === 1) return labelExtractor(value[0]);
|
|
@@ -23,12 +24,18 @@ const SelectTrigger = ({
|
|
|
23
24
|
return multiLabelSelected ? multiLabelSelected(value.length) : `${value.length} items selected`;
|
|
24
25
|
return labelExtractor(value);
|
|
25
26
|
}, [label, value]);
|
|
26
|
-
const { className } = rest;
|
|
27
27
|
const hasValue = Array.isArray(value) ? value.length > 0 : !!value;
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
if (triggerRef.current && setTriggerWidth) {
|
|
30
|
+
const width = triggerRef.current.getBoundingClientRect().width;
|
|
31
|
+
setTriggerWidth(width);
|
|
32
|
+
}
|
|
33
|
+
}, [triggerRef.current, setTriggerWidth]);
|
|
28
34
|
return /* @__PURE__ */ React.createElement(index.Popover.Trigger, { disabled }, /* @__PURE__ */ React.createElement("div", { className: "w-full gap-mili" }, /* @__PURE__ */ React.createElement(
|
|
29
35
|
"button",
|
|
30
36
|
{
|
|
31
|
-
|
|
37
|
+
ref: triggerRef,
|
|
38
|
+
className: button({ className: rest.className }),
|
|
32
39
|
disabled,
|
|
33
40
|
role: "button",
|
|
34
41
|
...rest
|
|
@@ -53,7 +60,7 @@ const SelectTrigger = ({
|
|
|
53
60
|
"data-testid": "input-label"
|
|
54
61
|
},
|
|
55
62
|
label
|
|
56
|
-
) :
|
|
63
|
+
) : null));
|
|
57
64
|
};
|
|
58
65
|
|
|
59
66
|
exports.SelectTrigger = SelectTrigger;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FloatingFocusManager } from '@floating-ui/react';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import React__default from 'react';
|
|
4
4
|
import { usePopoverContext } from './Context.js';
|
|
@@ -19,7 +19,7 @@ const PopoverContent = ({
|
|
|
19
19
|
getFloatingProps,
|
|
20
20
|
context
|
|
21
21
|
} = usePopoverContext();
|
|
22
|
-
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, isOpen && /* @__PURE__ */ React__default.createElement(
|
|
22
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, isOpen && /* @__PURE__ */ React__default.createElement(FloatingFocusManager, { ...rest, context, modal }, /* @__PURE__ */ React__default.createElement(
|
|
23
23
|
"div",
|
|
24
24
|
{
|
|
25
25
|
ref: refs.setFloating,
|
|
@@ -36,7 +36,7 @@ const PopoverContent = ({
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
children
|
|
39
|
-
)))
|
|
39
|
+
)));
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export { PopoverContent };
|
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
1
|
+
import React__default, { useContext } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
2
3
|
import { Popover } from '../Popover/index.js';
|
|
4
|
+
import { FloatingPortal } from '@floating-ui/react';
|
|
5
|
+
import { SelectContext } from './context.js';
|
|
3
6
|
|
|
4
7
|
const SelectPopover = ({ children }) => {
|
|
5
|
-
|
|
8
|
+
const { triggerWidth } = useContext(SelectContext);
|
|
9
|
+
const widthClass = triggerWidth ? `w-[${triggerWidth}px]` : "w-auto";
|
|
10
|
+
return /* @__PURE__ */ React__default.createElement(FloatingPortal, null, /* @__PURE__ */ React__default.createElement(
|
|
11
|
+
Popover.Content,
|
|
12
|
+
{
|
|
13
|
+
className: clsx(
|
|
14
|
+
"bg-white max-h-[30vh] overflow-y-scroll gap-y-mili flex flex-col p-0",
|
|
15
|
+
widthClass
|
|
16
|
+
)
|
|
17
|
+
},
|
|
18
|
+
children
|
|
19
|
+
));
|
|
6
20
|
};
|
|
7
21
|
|
|
8
22
|
export { SelectPopover };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
1
|
+
import React__default, { useState } from 'react';
|
|
2
2
|
import { Popover } from '../Popover/index.js';
|
|
3
3
|
import { Content } from './Content.js';
|
|
4
4
|
import { SelectContext } from './context.js';
|
|
@@ -10,6 +10,7 @@ const SelectRoot = ({
|
|
|
10
10
|
labelExtractor,
|
|
11
11
|
className
|
|
12
12
|
}) => {
|
|
13
|
+
const [triggerWidth, setTriggerWidth] = useState(0);
|
|
13
14
|
return /* @__PURE__ */ React__default.createElement(
|
|
14
15
|
Popover.Root,
|
|
15
16
|
{
|
|
@@ -17,7 +18,19 @@ const SelectRoot = ({
|
|
|
17
18
|
placement: "bottom",
|
|
18
19
|
trigger: "click"
|
|
19
20
|
},
|
|
20
|
-
/* @__PURE__ */ React__default.createElement(
|
|
21
|
+
/* @__PURE__ */ React__default.createElement(
|
|
22
|
+
SelectContext.Provider,
|
|
23
|
+
{
|
|
24
|
+
value: {
|
|
25
|
+
value,
|
|
26
|
+
keyExtractor,
|
|
27
|
+
labelExtractor,
|
|
28
|
+
triggerWidth,
|
|
29
|
+
setTriggerWidth
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
/* @__PURE__ */ React__default.createElement(Content, { className }, children)
|
|
33
|
+
)
|
|
21
34
|
);
|
|
22
35
|
};
|
|
23
36
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React__default, { useContext, useMemo } from 'react';
|
|
1
|
+
import React__default, { useContext, useRef, useMemo, useEffect } from 'react';
|
|
3
2
|
import { IoChevronDownOutline } from 'react-icons/io5';
|
|
4
3
|
import { Popover } from '../Popover/index.js';
|
|
5
4
|
import { SelectContext } from './context.js';
|
|
6
5
|
import clsx from 'clsx';
|
|
6
|
+
import { selectVariants, labelStyle } from '@tecsinapse/cortex-core';
|
|
7
7
|
|
|
8
8
|
const { button } = selectVariants();
|
|
9
9
|
const SelectTrigger = ({
|
|
@@ -13,7 +13,8 @@ const SelectTrigger = ({
|
|
|
13
13
|
multiLabelSelected,
|
|
14
14
|
...rest
|
|
15
15
|
}) => {
|
|
16
|
-
const { value, labelExtractor } = useContext(SelectContext);
|
|
16
|
+
const { value, labelExtractor, setTriggerWidth } = useContext(SelectContext);
|
|
17
|
+
const triggerRef = useRef(null);
|
|
17
18
|
const _placeholder = useMemo(() => {
|
|
18
19
|
if (value?.length === 0 || !value) return placeholder ?? label;
|
|
19
20
|
if (value?.length === 1) return labelExtractor(value[0]);
|
|
@@ -21,12 +22,18 @@ const SelectTrigger = ({
|
|
|
21
22
|
return multiLabelSelected ? multiLabelSelected(value.length) : `${value.length} items selected`;
|
|
22
23
|
return labelExtractor(value);
|
|
23
24
|
}, [label, value]);
|
|
24
|
-
const { className } = rest;
|
|
25
25
|
const hasValue = Array.isArray(value) ? value.length > 0 : !!value;
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (triggerRef.current && setTriggerWidth) {
|
|
28
|
+
const width = triggerRef.current.getBoundingClientRect().width;
|
|
29
|
+
setTriggerWidth(width);
|
|
30
|
+
}
|
|
31
|
+
}, [triggerRef.current, setTriggerWidth]);
|
|
26
32
|
return /* @__PURE__ */ React__default.createElement(Popover.Trigger, { disabled }, /* @__PURE__ */ React__default.createElement("div", { className: "w-full gap-mili" }, /* @__PURE__ */ React__default.createElement(
|
|
27
33
|
"button",
|
|
28
34
|
{
|
|
29
|
-
|
|
35
|
+
ref: triggerRef,
|
|
36
|
+
className: button({ className: rest.className }),
|
|
30
37
|
disabled,
|
|
31
38
|
role: "button",
|
|
32
39
|
...rest
|
|
@@ -51,7 +58,7 @@ const SelectTrigger = ({
|
|
|
51
58
|
"data-testid": "input-label"
|
|
52
59
|
},
|
|
53
60
|
label
|
|
54
|
-
) :
|
|
61
|
+
) : null));
|
|
55
62
|
};
|
|
56
63
|
|
|
57
64
|
export { SelectTrigger };
|
|
@@ -2,6 +2,8 @@ interface SelectContextProps<T> {
|
|
|
2
2
|
value?: T | T[];
|
|
3
3
|
keyExtractor: (value: T) => string;
|
|
4
4
|
labelExtractor: (value: T) => string;
|
|
5
|
+
triggerWidth?: number;
|
|
6
|
+
setTriggerWidth?: (width: number) => void;
|
|
5
7
|
}
|
|
6
8
|
export declare const SelectContext: import("react").Context<SelectContextProps<any>>;
|
|
7
9
|
interface SelectMultiOptionsContextProps<T> {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tecsinapse/cortex-react",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.38-beta.0",
|
|
4
4
|
"description": "React components based in @tecsinapse/cortex-core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"react-dom": ">=18.0.0",
|
|
49
49
|
"tailwind": ">=3.3.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ca5ac6efededbf5334f1c4626d1e94eb48751699"
|
|
52
52
|
}
|