@tecsinapse/cortex-react 1.3.0-beta.17 → 1.3.0-beta.18
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/Menubar/MostUsedList.js +3 -1
- package/dist/cjs/components/Popover/Content.js +2 -2
- package/dist/cjs/components/Select/Content.js +1 -1
- package/dist/cjs/components/Select/GroupedOptions.js +4 -3
- package/dist/cjs/components/Select/MultiCheckAllOptions.js +47 -0
- package/dist/cjs/components/Select/MultiGroupedOptions.js +28 -10
- package/dist/cjs/components/Select/MultiOption.js +20 -9
- package/dist/cjs/components/Select/MultiOptions.js +7 -4
- package/dist/cjs/components/Select/Option.js +4 -2
- package/dist/cjs/components/Select/Options.js +4 -2
- package/dist/cjs/components/Select/Popover.js +1 -1
- package/dist/cjs/components/Select/Root.js +1 -1
- package/dist/cjs/components/Select/context.js +4 -0
- package/dist/cjs/components/Select/index.js +3 -1
- package/dist/cjs/provider/SnackbarProvider.js +3 -1
- package/dist/cjs/service/SnackbarSonner.js +3 -1
- package/dist/esm/components/Menubar/MostUsedList.js +3 -1
- package/dist/esm/components/Popover/Content.js +2 -2
- package/dist/esm/components/Select/Content.js +1 -1
- package/dist/esm/components/Select/GroupedOptions.js +4 -3
- package/dist/esm/components/Select/MultiCheckAllOptions.js +45 -0
- package/dist/esm/components/Select/MultiGroupedOptions.js +30 -12
- package/dist/esm/components/Select/MultiOption.js +20 -9
- package/dist/esm/components/Select/MultiOptions.js +8 -5
- package/dist/esm/components/Select/Option.js +4 -2
- package/dist/esm/components/Select/Options.js +4 -2
- package/dist/esm/components/Select/Popover.js +1 -1
- package/dist/esm/components/Select/Root.js +1 -1
- package/dist/esm/components/Select/context.js +4 -1
- package/dist/esm/components/Select/index.js +3 -1
- package/dist/esm/provider/SnackbarProvider.js +3 -1
- package/dist/esm/service/SnackbarSonner.js +3 -1
- package/dist/types/components/Select/Content.d.ts +2 -2
- package/dist/types/components/Select/MultiCheckAllOptions.d.ts +4 -0
- package/dist/types/components/Select/MultiGroupedOptions.d.ts +3 -1
- package/dist/types/components/Select/MultiOption.d.ts +2 -1
- package/dist/types/components/Select/MultiOptions.d.ts +3 -1
- package/dist/types/components/Select/Option.d.ts +2 -1
- package/dist/types/components/Select/context.d.ts +5 -0
- package/dist/types/components/Select/index.d.ts +5 -4
- package/package.json +3 -3
|
@@ -32,8 +32,10 @@ require('../../styles/calendar-cell.js');
|
|
|
32
32
|
require('../../styles/groupButton.js');
|
|
33
33
|
require('../../styles/progressBar.js');
|
|
34
34
|
require('../Select/GroupedOptions.js');
|
|
35
|
-
require('../Select/MultiGroupedOptions.js');
|
|
36
35
|
require('../Select/context.js');
|
|
36
|
+
require('../Select/MultiGroupedOptions.js');
|
|
37
|
+
require('../Select/MultiOptions.js');
|
|
38
|
+
require('../Select/Options.js');
|
|
37
39
|
require('../Select/Trigger.js');
|
|
38
40
|
require('../Tag.js');
|
|
39
41
|
require('../TextArea.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var React = require('react');
|
|
4
3
|
var clsx = require('clsx');
|
|
4
|
+
var React = require('react');
|
|
5
5
|
var Context = require('./Context.js');
|
|
6
6
|
|
|
7
7
|
const PopoverContent = ({
|
|
@@ -14,7 +14,7 @@ const PopoverContent = ({
|
|
|
14
14
|
{
|
|
15
15
|
ref: refs.setFloating,
|
|
16
16
|
className: clsx(
|
|
17
|
-
"border border-gray-200 bg-black
|
|
17
|
+
"border border-gray-200 bg-black p-[0px] rounded-md shadow-lg z-50",
|
|
18
18
|
className
|
|
19
19
|
),
|
|
20
20
|
style: {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
var cortexCore = require('@tecsinapse/cortex-core');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var index = require('./index.js');
|
|
6
|
-
var context = require('./context.js');
|
|
7
6
|
var Context = require('../Popover/Context.js');
|
|
7
|
+
var context = require('./context.js');
|
|
8
8
|
|
|
9
|
-
const { groupedTitle,
|
|
9
|
+
const { groupedTitle, list } = cortexCore.selectVariants();
|
|
10
10
|
const SelectGroupedOptions = ({
|
|
11
11
|
onSelect,
|
|
12
12
|
groupedLabelExtractor,
|
|
@@ -21,9 +21,10 @@ const SelectGroupedOptions = ({
|
|
|
21
21
|
},
|
|
22
22
|
[onSelect]
|
|
23
23
|
);
|
|
24
|
-
return /* @__PURE__ */ React.createElement("ul", { role: "select", className:
|
|
24
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, [...options ?? []].map(([key, value]) => /* @__PURE__ */ React.createElement("div", { key }, /* @__PURE__ */ React.createElement("span", { className: groupedTitle() }, groupedLabelExtractor?.(key)), value.map((option) => /* @__PURE__ */ React.createElement(
|
|
25
25
|
index.Select.Option,
|
|
26
26
|
{
|
|
27
|
+
grouped: true,
|
|
27
28
|
option,
|
|
28
29
|
key: keyExtractor(option),
|
|
29
30
|
onSelectOption: handleSelect
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cortexCore = require('@tecsinapse/cortex-core');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var context = require('./context.js');
|
|
6
|
+
|
|
7
|
+
const SelectMultiCheckAllOptions = ({
|
|
8
|
+
checkAllLabel = "Select all"
|
|
9
|
+
}) => {
|
|
10
|
+
const { keyExtractor, value: currentValue = [] } = React.useContext(context.SelectContext);
|
|
11
|
+
const { options, onSelect } = React.useContext(context.SelectMultiOptionsContext);
|
|
12
|
+
const isChecked = React.useMemo(
|
|
13
|
+
() => (options ?? []).filter(
|
|
14
|
+
(it) => currentValue.find((value) => keyExtractor(value) === keyExtractor(it))
|
|
15
|
+
).length == (options ?? []).length,
|
|
16
|
+
[keyExtractor, currentValue, options]
|
|
17
|
+
);
|
|
18
|
+
const checkAll = React.useCallback(() => {
|
|
19
|
+
{
|
|
20
|
+
let updateSelected = [...currentValue];
|
|
21
|
+
if (!isChecked) {
|
|
22
|
+
updateSelected = [
|
|
23
|
+
.../* @__PURE__ */ new Set([...updateSelected, ...options ?? []])
|
|
24
|
+
];
|
|
25
|
+
} else {
|
|
26
|
+
const optionKeys = new Set(
|
|
27
|
+
options?.map((option2) => keyExtractor(option2))
|
|
28
|
+
);
|
|
29
|
+
updateSelected = updateSelected.filter(
|
|
30
|
+
(item) => !optionKeys.has(keyExtractor(item))
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
onSelect(updateSelected);
|
|
34
|
+
}
|
|
35
|
+
}, [options, onSelect]);
|
|
36
|
+
return options?.length ? /* @__PURE__ */ React.createElement("div", { className: cortexCore.option(), onClick: checkAll }, /* @__PURE__ */ React.createElement(
|
|
37
|
+
"input",
|
|
38
|
+
{
|
|
39
|
+
type: "checkbox",
|
|
40
|
+
className: cortexCore.checkbox(),
|
|
41
|
+
onChange: checkAll,
|
|
42
|
+
checked: isChecked
|
|
43
|
+
}
|
|
44
|
+
), /* @__PURE__ */ React.createElement("span", null, checkAllLabel)) : /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.SelectMultiCheckAllOptions = SelectMultiCheckAllOptions;
|
|
@@ -6,21 +6,39 @@ var index = require('./index.js');
|
|
|
6
6
|
var context = require('./context.js');
|
|
7
7
|
var utils = require('./utils.js');
|
|
8
8
|
|
|
9
|
-
const { groupedTitle,
|
|
9
|
+
const { groupedTitle, list } = cortexCore.selectVariants();
|
|
10
10
|
const SelectMultiGroupedOptions = ({
|
|
11
11
|
onSelect,
|
|
12
12
|
groupedLabelExtractor,
|
|
13
|
-
options
|
|
13
|
+
options,
|
|
14
|
+
children
|
|
14
15
|
}) => {
|
|
15
|
-
const { value: currentValue, keyExtractor } = React.useContext(context.SelectContext);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const { value: currentValue = [], keyExtractor } = React.useContext(context.SelectContext);
|
|
17
|
+
const flattenMap = React.useMemo(
|
|
18
|
+
() => options ? Array.from(options?.values()).flatMap((value) => value) : [],
|
|
19
|
+
[options]
|
|
20
|
+
);
|
|
21
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, /* @__PURE__ */ React.createElement(
|
|
22
|
+
context.SelectMultiOptionsContext.Provider,
|
|
18
23
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
+
value: { onSelect, options: flattenMap }
|
|
25
|
+
},
|
|
26
|
+
children,
|
|
27
|
+
[...options ?? []].map(([key, value]) => /* @__PURE__ */ React.createElement("div", { key }, /* @__PURE__ */ React.createElement("span", { className: groupedTitle() }, groupedLabelExtractor?.(key)), value.map((option) => /* @__PURE__ */ React.createElement(
|
|
28
|
+
index.Select.MultiOption,
|
|
29
|
+
{
|
|
30
|
+
grouped: true,
|
|
31
|
+
option,
|
|
32
|
+
key: keyExtractor(option),
|
|
33
|
+
onSelectOption: (option2) => utils.handleSelectMulti(
|
|
34
|
+
option2,
|
|
35
|
+
currentValue,
|
|
36
|
+
onSelect,
|
|
37
|
+
keyExtractor
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
))))
|
|
41
|
+
));
|
|
24
42
|
};
|
|
25
43
|
|
|
26
44
|
exports.SelectMultiGroupedOptions = SelectMultiGroupedOptions;
|
|
@@ -6,7 +6,8 @@ var context = require('./context.js');
|
|
|
6
6
|
|
|
7
7
|
const SelectMultiOption = ({
|
|
8
8
|
onSelectOption,
|
|
9
|
-
option
|
|
9
|
+
option,
|
|
10
|
+
grouped = false
|
|
10
11
|
}) => {
|
|
11
12
|
const { keyExtractor, labelExtractor, value } = React.useContext(context.SelectContext);
|
|
12
13
|
const inputRef = React.useRef(null);
|
|
@@ -18,15 +19,25 @@ const SelectMultiOption = ({
|
|
|
18
19
|
onSelectOption(option);
|
|
19
20
|
inputRef.current?.click();
|
|
20
21
|
}, [onSelectOption, inputRef]);
|
|
21
|
-
return /* @__PURE__ */ React.createElement(
|
|
22
|
-
"
|
|
22
|
+
return /* @__PURE__ */ React.createElement(
|
|
23
|
+
"li",
|
|
23
24
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
onClick: onClickOption,
|
|
26
|
+
className: cortexCore.option({ grouped }),
|
|
27
|
+
role: "option"
|
|
28
|
+
},
|
|
29
|
+
/* @__PURE__ */ React.createElement(
|
|
30
|
+
"input",
|
|
31
|
+
{
|
|
32
|
+
type: "checkbox",
|
|
33
|
+
checked: isChecked,
|
|
34
|
+
className: cortexCore.checkbox({ className: "pointer-events-none" }),
|
|
35
|
+
onChange: () => false,
|
|
36
|
+
ref: inputRef
|
|
37
|
+
}
|
|
38
|
+
),
|
|
39
|
+
labelExtractor(option)
|
|
40
|
+
);
|
|
30
41
|
};
|
|
31
42
|
|
|
32
43
|
exports.SelectMultiOption = SelectMultiOption;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var cortexCore = require('@tecsinapse/cortex-core');
|
|
3
4
|
var React = require('react');
|
|
4
5
|
var index = require('./index.js');
|
|
5
6
|
var context = require('./context.js');
|
|
6
7
|
var utils = require('./utils.js');
|
|
7
8
|
|
|
9
|
+
const { list } = cortexCore.selectVariants();
|
|
8
10
|
const SelectMultiOptions = ({
|
|
9
11
|
onSelect,
|
|
10
|
-
options
|
|
12
|
+
options,
|
|
13
|
+
children
|
|
11
14
|
}) => {
|
|
12
|
-
const { keyExtractor, value: currentValue } = React.useContext(context.SelectContext);
|
|
13
|
-
return /* @__PURE__ */ React.createElement("ul", { role: "select", className:
|
|
15
|
+
const { keyExtractor, value: currentValue = [] } = React.useContext(context.SelectContext);
|
|
16
|
+
return /* @__PURE__ */ React.createElement(context.SelectMultiOptionsContext.Provider, { value: { onSelect, options } }, /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, children, (options ?? []).map((option) => /* @__PURE__ */ React.createElement(
|
|
14
17
|
index.Select.MultiOption,
|
|
15
18
|
{
|
|
16
19
|
option,
|
|
17
20
|
key: keyExtractor(option),
|
|
18
21
|
onSelectOption: (option2) => utils.handleSelectMulti(option2, currentValue, onSelect, keyExtractor)
|
|
19
22
|
}
|
|
20
|
-
)));
|
|
23
|
+
))));
|
|
21
24
|
};
|
|
22
25
|
|
|
23
26
|
exports.SelectMultiOptions = SelectMultiOptions;
|
|
@@ -6,7 +6,8 @@ var context = require('./context.js');
|
|
|
6
6
|
|
|
7
7
|
const SelectOption = ({
|
|
8
8
|
onSelectOption,
|
|
9
|
-
option
|
|
9
|
+
option,
|
|
10
|
+
grouped = false
|
|
10
11
|
}) => {
|
|
11
12
|
const { keyExtractor, labelExtractor, value } = React.useContext(context.SelectContext);
|
|
12
13
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -14,7 +15,8 @@ const SelectOption = ({
|
|
|
14
15
|
{
|
|
15
16
|
onClick: () => onSelectOption(option),
|
|
16
17
|
className: cortexCore.option({
|
|
17
|
-
selected: value && keyExtractor(value) === keyExtractor(option)
|
|
18
|
+
selected: value && keyExtractor(value) === keyExtractor(option),
|
|
19
|
+
grouped
|
|
18
20
|
}),
|
|
19
21
|
role: "option"
|
|
20
22
|
},
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var cortexCore = require('@tecsinapse/cortex-core');
|
|
3
4
|
var React = require('react');
|
|
4
|
-
var context = require('./context.js');
|
|
5
5
|
var index = require('./index.js');
|
|
6
6
|
var Context = require('../Popover/Context.js');
|
|
7
|
+
var context = require('./context.js');
|
|
7
8
|
|
|
9
|
+
const { list } = cortexCore.selectVariants();
|
|
8
10
|
const SelectOptions = ({
|
|
9
11
|
onSelect,
|
|
10
12
|
options
|
|
@@ -18,7 +20,7 @@ const SelectOptions = ({
|
|
|
18
20
|
},
|
|
19
21
|
[onSelect]
|
|
20
22
|
);
|
|
21
|
-
return /* @__PURE__ */ React.createElement("ul", { role: "select", className:
|
|
23
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, (options ?? []).map((option) => /* @__PURE__ */ React.createElement(
|
|
22
24
|
index.Select.Option,
|
|
23
25
|
{
|
|
24
26
|
option,
|
|
@@ -4,7 +4,7 @@ var React = require('react');
|
|
|
4
4
|
var index = require('../Popover/index.js');
|
|
5
5
|
|
|
6
6
|
const SelectPopover = ({ children }) => {
|
|
7
|
-
return /* @__PURE__ */ React.createElement(index.Popover.Content, { className: "bg-white max-h-[30vh] w-full overflow-y-scroll gap-y-mili flex flex-col" }, children);
|
|
7
|
+
return /* @__PURE__ */ React.createElement(index.Popover.Content, { className: "bg-white max-h-[30vh] w-full overflow-y-scroll gap-y-mili flex flex-col p-0" }, children);
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
exports.SelectPopover = SelectPopover;
|
|
@@ -11,7 +11,7 @@ const SelectRoot = ({
|
|
|
11
11
|
keyExtractor,
|
|
12
12
|
labelExtractor
|
|
13
13
|
}) => {
|
|
14
|
-
return /* @__PURE__ */ React.createElement(index.Popover.Provider, null, /* @__PURE__ */ React.createElement(index.Popover.Root, { placement: "bottom", trigger: "click" }, /* @__PURE__ */ React.createElement(context.SelectContext.Provider, { value: { value, keyExtractor, labelExtractor } }, /* @__PURE__ */ React.createElement(Content, null, children))));
|
|
14
|
+
return /* @__PURE__ */ React.createElement(index.Popover.Provider, null, /* @__PURE__ */ React.createElement(index.Popover.Root, { placement: "bottom", trigger: "click" }, /* @__PURE__ */ React.createElement(context.SelectContext.Provider, { value: { value, keyExtractor, labelExtractor } }, /* @__PURE__ */ React.createElement(Content.Content, null, children))));
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
exports.SelectRoot = SelectRoot;
|
|
@@ -6,5 +6,9 @@ const SelectContext = React.createContext({
|
|
|
6
6
|
keyExtractor: () => "",
|
|
7
7
|
labelExtractor: () => ""
|
|
8
8
|
});
|
|
9
|
+
const SelectMultiOptionsContext = React.createContext({
|
|
10
|
+
onSelect: () => ""
|
|
11
|
+
});
|
|
9
12
|
|
|
10
13
|
exports.SelectContext = SelectContext;
|
|
14
|
+
exports.SelectMultiOptionsContext = SelectMultiOptionsContext;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var GroupedOptions = require('./GroupedOptions.js');
|
|
4
|
+
var MultiCheckAllOptions = require('./MultiCheckAllOptions.js');
|
|
4
5
|
var MultiGroupedOptions = require('./MultiGroupedOptions.js');
|
|
5
6
|
var MultiOption = require('./MultiOption.js');
|
|
6
7
|
var MultiOptions = require('./MultiOptions.js');
|
|
@@ -19,7 +20,8 @@ const Select = {
|
|
|
19
20
|
Option: Option.SelectOption,
|
|
20
21
|
MultiOptions: MultiOptions.SelectMultiOptions,
|
|
21
22
|
MultiGroupedOptions: MultiGroupedOptions.SelectMultiGroupedOptions,
|
|
22
|
-
MultiOption: MultiOption.SelectMultiOption
|
|
23
|
+
MultiOption: MultiOption.SelectMultiOption,
|
|
24
|
+
MultiCheckAllOptions: MultiCheckAllOptions.SelectMultiCheckAllOptions
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
exports.Select = Select;
|
|
@@ -42,8 +42,10 @@ require('../styles/calendar-cell.js');
|
|
|
42
42
|
require('../styles/groupButton.js');
|
|
43
43
|
require('../styles/progressBar.js');
|
|
44
44
|
require('../components/Select/GroupedOptions.js');
|
|
45
|
-
require('../components/Select/MultiGroupedOptions.js');
|
|
46
45
|
require('../components/Select/context.js');
|
|
46
|
+
require('../components/Select/MultiGroupedOptions.js');
|
|
47
|
+
require('../components/Select/MultiOptions.js');
|
|
48
|
+
require('../components/Select/Options.js');
|
|
47
49
|
require('../components/Select/Trigger.js');
|
|
48
50
|
require('../components/Tag.js');
|
|
49
51
|
require('../components/TextArea.js');
|
|
@@ -43,8 +43,10 @@ require('../styles/calendar-cell.js');
|
|
|
43
43
|
require('../styles/groupButton.js');
|
|
44
44
|
require('../styles/progressBar.js');
|
|
45
45
|
require('../components/Select/GroupedOptions.js');
|
|
46
|
-
require('../components/Select/MultiGroupedOptions.js');
|
|
47
46
|
require('../components/Select/context.js');
|
|
47
|
+
require('../components/Select/MultiGroupedOptions.js');
|
|
48
|
+
require('../components/Select/MultiOptions.js');
|
|
49
|
+
require('../components/Select/Options.js');
|
|
48
50
|
require('../components/Select/Trigger.js');
|
|
49
51
|
require('../components/Tag.js');
|
|
50
52
|
require('../components/TextArea.js');
|
|
@@ -30,8 +30,10 @@ import '../../styles/calendar-cell.js';
|
|
|
30
30
|
import '../../styles/groupButton.js';
|
|
31
31
|
import '../../styles/progressBar.js';
|
|
32
32
|
import '../Select/GroupedOptions.js';
|
|
33
|
-
import '../Select/MultiGroupedOptions.js';
|
|
34
33
|
import '../Select/context.js';
|
|
34
|
+
import '../Select/MultiGroupedOptions.js';
|
|
35
|
+
import '../Select/MultiOptions.js';
|
|
36
|
+
import '../Select/Options.js';
|
|
35
37
|
import '../Select/Trigger.js';
|
|
36
38
|
import '../Tag.js';
|
|
37
39
|
import '../TextArea.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import clsx from 'clsx';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import { usePopoverContext } from './Context.js';
|
|
4
4
|
|
|
5
5
|
const PopoverContent = ({
|
|
@@ -12,7 +12,7 @@ const PopoverContent = ({
|
|
|
12
12
|
{
|
|
13
13
|
ref: refs.setFloating,
|
|
14
14
|
className: clsx(
|
|
15
|
-
"border border-gray-200 bg-black
|
|
15
|
+
"border border-gray-200 bg-black p-[0px] rounded-md shadow-lg z-50",
|
|
16
16
|
className
|
|
17
17
|
),
|
|
18
18
|
style: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { selectVariants } from '@tecsinapse/cortex-core';
|
|
2
2
|
import React, { useContext, useCallback } from 'react';
|
|
3
3
|
import { Select } from './index.js';
|
|
4
|
-
import { SelectContext } from './context.js';
|
|
5
4
|
import { usePopoverContext } from '../Popover/Context.js';
|
|
5
|
+
import { SelectContext } from './context.js';
|
|
6
6
|
|
|
7
|
-
const { groupedTitle,
|
|
7
|
+
const { groupedTitle, list } = selectVariants();
|
|
8
8
|
const SelectGroupedOptions = ({
|
|
9
9
|
onSelect,
|
|
10
10
|
groupedLabelExtractor,
|
|
@@ -19,9 +19,10 @@ const SelectGroupedOptions = ({
|
|
|
19
19
|
},
|
|
20
20
|
[onSelect]
|
|
21
21
|
);
|
|
22
|
-
return /* @__PURE__ */ React.createElement("ul", { role: "select", className:
|
|
22
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, [...options ?? []].map(([key, value]) => /* @__PURE__ */ React.createElement("div", { key }, /* @__PURE__ */ React.createElement("span", { className: groupedTitle() }, groupedLabelExtractor?.(key)), value.map((option) => /* @__PURE__ */ React.createElement(
|
|
23
23
|
Select.Option,
|
|
24
24
|
{
|
|
25
|
+
grouped: true,
|
|
25
26
|
option,
|
|
26
27
|
key: keyExtractor(option),
|
|
27
28
|
onSelectOption: handleSelect
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { option, checkbox } from '@tecsinapse/cortex-core';
|
|
2
|
+
import React, { useContext, useMemo, useCallback } from 'react';
|
|
3
|
+
import { SelectContext, SelectMultiOptionsContext } from './context.js';
|
|
4
|
+
|
|
5
|
+
const SelectMultiCheckAllOptions = ({
|
|
6
|
+
checkAllLabel = "Select all"
|
|
7
|
+
}) => {
|
|
8
|
+
const { keyExtractor, value: currentValue = [] } = useContext(SelectContext);
|
|
9
|
+
const { options, onSelect } = useContext(SelectMultiOptionsContext);
|
|
10
|
+
const isChecked = useMemo(
|
|
11
|
+
() => (options ?? []).filter(
|
|
12
|
+
(it) => currentValue.find((value) => keyExtractor(value) === keyExtractor(it))
|
|
13
|
+
).length == (options ?? []).length,
|
|
14
|
+
[keyExtractor, currentValue, options]
|
|
15
|
+
);
|
|
16
|
+
const checkAll = useCallback(() => {
|
|
17
|
+
{
|
|
18
|
+
let updateSelected = [...currentValue];
|
|
19
|
+
if (!isChecked) {
|
|
20
|
+
updateSelected = [
|
|
21
|
+
.../* @__PURE__ */ new Set([...updateSelected, ...options ?? []])
|
|
22
|
+
];
|
|
23
|
+
} else {
|
|
24
|
+
const optionKeys = new Set(
|
|
25
|
+
options?.map((option2) => keyExtractor(option2))
|
|
26
|
+
);
|
|
27
|
+
updateSelected = updateSelected.filter(
|
|
28
|
+
(item) => !optionKeys.has(keyExtractor(item))
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
onSelect(updateSelected);
|
|
32
|
+
}
|
|
33
|
+
}, [options, onSelect]);
|
|
34
|
+
return options?.length ? /* @__PURE__ */ React.createElement("div", { className: option(), onClick: checkAll }, /* @__PURE__ */ React.createElement(
|
|
35
|
+
"input",
|
|
36
|
+
{
|
|
37
|
+
type: "checkbox",
|
|
38
|
+
className: checkbox(),
|
|
39
|
+
onChange: checkAll,
|
|
40
|
+
checked: isChecked
|
|
41
|
+
}
|
|
42
|
+
), /* @__PURE__ */ React.createElement("span", null, checkAllLabel)) : /* @__PURE__ */ React.createElement(React.Fragment, null);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { SelectMultiCheckAllOptions };
|
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
import { selectVariants } from '@tecsinapse/cortex-core';
|
|
2
|
-
import React, { useContext } from 'react';
|
|
2
|
+
import React, { useContext, useMemo } from 'react';
|
|
3
3
|
import { Select } from './index.js';
|
|
4
|
-
import { SelectContext } from './context.js';
|
|
4
|
+
import { SelectContext, SelectMultiOptionsContext } from './context.js';
|
|
5
5
|
import { handleSelectMulti } from './utils.js';
|
|
6
6
|
|
|
7
|
-
const { groupedTitle,
|
|
7
|
+
const { groupedTitle, list } = selectVariants();
|
|
8
8
|
const SelectMultiGroupedOptions = ({
|
|
9
9
|
onSelect,
|
|
10
10
|
groupedLabelExtractor,
|
|
11
|
-
options
|
|
11
|
+
options,
|
|
12
|
+
children
|
|
12
13
|
}) => {
|
|
13
|
-
const { value: currentValue, keyExtractor } = useContext(SelectContext);
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const { value: currentValue = [], keyExtractor } = useContext(SelectContext);
|
|
15
|
+
const flattenMap = useMemo(
|
|
16
|
+
() => options ? Array.from(options?.values()).flatMap((value) => value) : [],
|
|
17
|
+
[options]
|
|
18
|
+
);
|
|
19
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, /* @__PURE__ */ React.createElement(
|
|
20
|
+
SelectMultiOptionsContext.Provider,
|
|
16
21
|
{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
+
value: { onSelect, options: flattenMap }
|
|
23
|
+
},
|
|
24
|
+
children,
|
|
25
|
+
[...options ?? []].map(([key, value]) => /* @__PURE__ */ React.createElement("div", { key }, /* @__PURE__ */ React.createElement("span", { className: groupedTitle() }, groupedLabelExtractor?.(key)), value.map((option) => /* @__PURE__ */ React.createElement(
|
|
26
|
+
Select.MultiOption,
|
|
27
|
+
{
|
|
28
|
+
grouped: true,
|
|
29
|
+
option,
|
|
30
|
+
key: keyExtractor(option),
|
|
31
|
+
onSelectOption: (option2) => handleSelectMulti(
|
|
32
|
+
option2,
|
|
33
|
+
currentValue,
|
|
34
|
+
onSelect,
|
|
35
|
+
keyExtractor
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
))))
|
|
39
|
+
));
|
|
22
40
|
};
|
|
23
41
|
|
|
24
42
|
export { SelectMultiGroupedOptions };
|
|
@@ -4,7 +4,8 @@ import { SelectContext } from './context.js';
|
|
|
4
4
|
|
|
5
5
|
const SelectMultiOption = ({
|
|
6
6
|
onSelectOption,
|
|
7
|
-
option: option$1
|
|
7
|
+
option: option$1,
|
|
8
|
+
grouped = false
|
|
8
9
|
}) => {
|
|
9
10
|
const { keyExtractor, labelExtractor, value } = useContext(SelectContext);
|
|
10
11
|
const inputRef = useRef(null);
|
|
@@ -16,15 +17,25 @@ const SelectMultiOption = ({
|
|
|
16
17
|
onSelectOption(option$1);
|
|
17
18
|
inputRef.current?.click();
|
|
18
19
|
}, [onSelectOption, inputRef]);
|
|
19
|
-
return /* @__PURE__ */ React.createElement(
|
|
20
|
-
"
|
|
20
|
+
return /* @__PURE__ */ React.createElement(
|
|
21
|
+
"li",
|
|
21
22
|
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
onClick: onClickOption,
|
|
24
|
+
className: option({ grouped }),
|
|
25
|
+
role: "option"
|
|
26
|
+
},
|
|
27
|
+
/* @__PURE__ */ React.createElement(
|
|
28
|
+
"input",
|
|
29
|
+
{
|
|
30
|
+
type: "checkbox",
|
|
31
|
+
checked: isChecked,
|
|
32
|
+
className: checkbox({ className: "pointer-events-none" }),
|
|
33
|
+
onChange: () => false,
|
|
34
|
+
ref: inputRef
|
|
35
|
+
}
|
|
36
|
+
),
|
|
37
|
+
labelExtractor(option$1)
|
|
38
|
+
);
|
|
28
39
|
};
|
|
29
40
|
|
|
30
41
|
export { SelectMultiOption };
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
import { selectVariants } from '@tecsinapse/cortex-core';
|
|
1
2
|
import React, { useContext } from 'react';
|
|
2
3
|
import { Select } from './index.js';
|
|
3
|
-
import { SelectContext } from './context.js';
|
|
4
|
+
import { SelectContext, SelectMultiOptionsContext } from './context.js';
|
|
4
5
|
import { handleSelectMulti } from './utils.js';
|
|
5
6
|
|
|
7
|
+
const { list } = selectVariants();
|
|
6
8
|
const SelectMultiOptions = ({
|
|
7
9
|
onSelect,
|
|
8
|
-
options
|
|
10
|
+
options,
|
|
11
|
+
children
|
|
9
12
|
}) => {
|
|
10
|
-
const { keyExtractor, value: currentValue } = useContext(SelectContext);
|
|
11
|
-
return /* @__PURE__ */ React.createElement("ul", { role: "select", className:
|
|
13
|
+
const { keyExtractor, value: currentValue = [] } = useContext(SelectContext);
|
|
14
|
+
return /* @__PURE__ */ React.createElement(SelectMultiOptionsContext.Provider, { value: { onSelect, options } }, /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, children, (options ?? []).map((option) => /* @__PURE__ */ React.createElement(
|
|
12
15
|
Select.MultiOption,
|
|
13
16
|
{
|
|
14
17
|
option,
|
|
15
18
|
key: keyExtractor(option),
|
|
16
19
|
onSelectOption: (option2) => handleSelectMulti(option2, currentValue, onSelect, keyExtractor)
|
|
17
20
|
}
|
|
18
|
-
)));
|
|
21
|
+
))));
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export { SelectMultiOptions };
|
|
@@ -4,7 +4,8 @@ import { SelectContext } from './context.js';
|
|
|
4
4
|
|
|
5
5
|
const SelectOption = ({
|
|
6
6
|
onSelectOption,
|
|
7
|
-
option: option$1
|
|
7
|
+
option: option$1,
|
|
8
|
+
grouped = false
|
|
8
9
|
}) => {
|
|
9
10
|
const { keyExtractor, labelExtractor, value } = useContext(SelectContext);
|
|
10
11
|
return /* @__PURE__ */ React.createElement(
|
|
@@ -12,7 +13,8 @@ const SelectOption = ({
|
|
|
12
13
|
{
|
|
13
14
|
onClick: () => onSelectOption(option$1),
|
|
14
15
|
className: option({
|
|
15
|
-
selected: value && keyExtractor(value) === keyExtractor(option$1)
|
|
16
|
+
selected: value && keyExtractor(value) === keyExtractor(option$1),
|
|
17
|
+
grouped
|
|
16
18
|
}),
|
|
17
19
|
role: "option"
|
|
18
20
|
},
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { selectVariants } from '@tecsinapse/cortex-core';
|
|
1
2
|
import React, { useContext, useCallback } from 'react';
|
|
2
|
-
import { SelectContext } from './context.js';
|
|
3
3
|
import { Select } from './index.js';
|
|
4
4
|
import { usePopoverContext } from '../Popover/Context.js';
|
|
5
|
+
import { SelectContext } from './context.js';
|
|
5
6
|
|
|
7
|
+
const { list } = selectVariants();
|
|
6
8
|
const SelectOptions = ({
|
|
7
9
|
onSelect,
|
|
8
10
|
options
|
|
@@ -16,7 +18,7 @@ const SelectOptions = ({
|
|
|
16
18
|
},
|
|
17
19
|
[onSelect]
|
|
18
20
|
);
|
|
19
|
-
return /* @__PURE__ */ React.createElement("ul", { role: "select", className:
|
|
21
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, (options ?? []).map((option) => /* @__PURE__ */ React.createElement(
|
|
20
22
|
Select.Option,
|
|
21
23
|
{
|
|
22
24
|
option,
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { Popover } from '../Popover/index.js';
|
|
3
3
|
|
|
4
4
|
const SelectPopover = ({ children }) => {
|
|
5
|
-
return /* @__PURE__ */ React.createElement(Popover.Content, { className: "bg-white max-h-[30vh] w-full overflow-y-scroll gap-y-mili flex flex-col" }, children);
|
|
5
|
+
return /* @__PURE__ */ React.createElement(Popover.Content, { className: "bg-white max-h-[30vh] w-full overflow-y-scroll gap-y-mili flex flex-col p-0" }, children);
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export { SelectPopover };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SelectGroupedOptions } from './GroupedOptions.js';
|
|
2
|
+
import { SelectMultiCheckAllOptions } from './MultiCheckAllOptions.js';
|
|
2
3
|
import { SelectMultiGroupedOptions } from './MultiGroupedOptions.js';
|
|
3
4
|
import { SelectMultiOption } from './MultiOption.js';
|
|
4
5
|
import { SelectMultiOptions } from './MultiOptions.js';
|
|
@@ -17,7 +18,8 @@ const Select = {
|
|
|
17
18
|
Option: SelectOption,
|
|
18
19
|
MultiOptions: SelectMultiOptions,
|
|
19
20
|
MultiGroupedOptions: SelectMultiGroupedOptions,
|
|
20
|
-
MultiOption: SelectMultiOption
|
|
21
|
+
MultiOption: SelectMultiOption,
|
|
22
|
+
MultiCheckAllOptions: SelectMultiCheckAllOptions
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export { Select };
|
|
@@ -40,8 +40,10 @@ import '../styles/calendar-cell.js';
|
|
|
40
40
|
import '../styles/groupButton.js';
|
|
41
41
|
import '../styles/progressBar.js';
|
|
42
42
|
import '../components/Select/GroupedOptions.js';
|
|
43
|
-
import '../components/Select/MultiGroupedOptions.js';
|
|
44
43
|
import '../components/Select/context.js';
|
|
44
|
+
import '../components/Select/MultiGroupedOptions.js';
|
|
45
|
+
import '../components/Select/MultiOptions.js';
|
|
46
|
+
import '../components/Select/Options.js';
|
|
45
47
|
import '../components/Select/Trigger.js';
|
|
46
48
|
import '../components/Tag.js';
|
|
47
49
|
import '../components/TextArea.js';
|
|
@@ -41,8 +41,10 @@ import '../styles/calendar-cell.js';
|
|
|
41
41
|
import '../styles/groupButton.js';
|
|
42
42
|
import '../styles/progressBar.js';
|
|
43
43
|
import '../components/Select/GroupedOptions.js';
|
|
44
|
-
import '../components/Select/MultiGroupedOptions.js';
|
|
45
44
|
import '../components/Select/context.js';
|
|
45
|
+
import '../components/Select/MultiGroupedOptions.js';
|
|
46
|
+
import '../components/Select/MultiOptions.js';
|
|
47
|
+
import '../components/Select/Options.js';
|
|
46
48
|
import '../components/Select/Trigger.js';
|
|
47
49
|
import '../components/Tag.js';
|
|
48
50
|
import '../components/TextArea.js';
|
|
@@ -2,5 +2,5 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
interface ContentProps {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
}
|
|
5
|
-
declare const Content: ({ children }: ContentProps) => JSX.Element;
|
|
6
|
-
export
|
|
5
|
+
export declare const Content: ({ children }: ContentProps) => JSX.Element;
|
|
6
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
export interface SelectMultiGroupedOptionsProps<T> {
|
|
2
3
|
onSelect: (value: T[]) => void;
|
|
3
4
|
options?: Map<string, T[]>;
|
|
4
5
|
groupedLabelExtractor: (value: string) => string;
|
|
6
|
+
children?: React.ReactNode;
|
|
5
7
|
}
|
|
6
|
-
export declare const SelectMultiGroupedOptions: <T>({ onSelect, groupedLabelExtractor, options, }: SelectMultiGroupedOptionsProps<T>) => JSX.Element;
|
|
8
|
+
export declare const SelectMultiGroupedOptions: <T>({ onSelect, groupedLabelExtractor, options, children, }: SelectMultiGroupedOptionsProps<T>) => JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface SelectMultiOptionProps<T> {
|
|
2
2
|
option: T;
|
|
3
3
|
onSelectOption: (option: T) => void;
|
|
4
|
+
grouped?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare const SelectMultiOption: <T>({ onSelectOption, option, }: SelectMultiOptionProps<T>) => JSX.Element;
|
|
6
|
+
export declare const SelectMultiOption: <T>({ onSelectOption, option, grouped, }: SelectMultiOptionProps<T>) => JSX.Element;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
export interface SelectMultiOptionsProps<T> {
|
|
2
3
|
options?: T[];
|
|
3
4
|
onSelect: (value: T[]) => void;
|
|
5
|
+
children?: React.ReactNode;
|
|
4
6
|
}
|
|
5
|
-
export declare const SelectMultiOptions: <T>({ onSelect, options, }: SelectMultiOptionsProps<T>) => JSX.Element;
|
|
7
|
+
export declare const SelectMultiOptions: <T>({ onSelect, options, children, }: SelectMultiOptionsProps<T>) => JSX.Element;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface SelectOptionProps<T> {
|
|
2
2
|
option: T;
|
|
3
3
|
onSelectOption: (option: T) => void;
|
|
4
|
+
grouped?: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare const SelectOption: <T>({ onSelectOption, option, }: SelectOptionProps<T>) => JSX.Element;
|
|
6
|
+
export declare const SelectOption: <T>({ onSelectOption, option, grouped, }: SelectOptionProps<T>) => JSX.Element;
|
|
@@ -4,4 +4,9 @@ interface SelectContextProps<T> {
|
|
|
4
4
|
labelExtractor: (value: T) => string;
|
|
5
5
|
}
|
|
6
6
|
export declare const SelectContext: import("react").Context<SelectContextProps<any>>;
|
|
7
|
+
interface SelectMultiOptionsContextProps<T> {
|
|
8
|
+
options?: T[];
|
|
9
|
+
onSelect: (value: T[]) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const SelectMultiOptionsContext: import("react").Context<SelectMultiOptionsContextProps<any>>;
|
|
7
12
|
export {};
|
|
@@ -4,8 +4,9 @@ export declare const Select: {
|
|
|
4
4
|
Popover: ({ children }: import("./Popover").SelectPopoverProps) => JSX.Element;
|
|
5
5
|
Options: <T_1>({ onSelect, options, }: import("./Options").SelectOptionsProps<T_1>) => JSX.Element;
|
|
6
6
|
GroupedOptions: <T_2>({ onSelect, groupedLabelExtractor, options, }: import("./GroupedOptions").SelectGroupedOptionsProps<T_2>) => JSX.Element;
|
|
7
|
-
Option: <T_3>({ onSelectOption, option, }: import("./Option").SelectOptionProps<T_3>) => JSX.Element;
|
|
8
|
-
MultiOptions: <T_4>({ onSelect, options, }: import("./MultiOptions").SelectMultiOptionsProps<T_4>) => JSX.Element;
|
|
9
|
-
MultiGroupedOptions: <T_5>({ onSelect, groupedLabelExtractor, options, }: import("./MultiGroupedOptions").SelectMultiGroupedOptionsProps<T_5>) => JSX.Element;
|
|
10
|
-
MultiOption: <T_6>({ onSelectOption, option, }: import("./MultiOption").SelectMultiOptionProps<T_6>) => JSX.Element;
|
|
7
|
+
Option: <T_3>({ onSelectOption, option, grouped, }: import("./Option").SelectOptionProps<T_3>) => JSX.Element;
|
|
8
|
+
MultiOptions: <T_4>({ onSelect, options, children, }: import("./MultiOptions").SelectMultiOptionsProps<T_4>) => JSX.Element;
|
|
9
|
+
MultiGroupedOptions: <T_5>({ onSelect, groupedLabelExtractor, options, children, }: import("./MultiGroupedOptions").SelectMultiGroupedOptionsProps<T_5>) => JSX.Element;
|
|
10
|
+
MultiOption: <T_6>({ onSelectOption, option, grouped, }: import("./MultiOption").SelectMultiOptionProps<T_6>) => JSX.Element;
|
|
11
|
+
MultiCheckAllOptions: <T_7>({ checkAllLabel, }: import("./MultiCheckAllOptions").SelectMultiCheckAllOptionsProps) => JSX.Element;
|
|
11
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tecsinapse/cortex-react",
|
|
3
|
-
"version": "1.3.0-beta.
|
|
3
|
+
"version": "1.3.0-beta.18",
|
|
4
4
|
"description": "React components based in @tecsinapse/cortex-core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@floating-ui/react": "^0.26.18",
|
|
22
22
|
"@internationalized/date": "*",
|
|
23
|
-
"@tecsinapse/cortex-core": "0.3.0-beta.
|
|
23
|
+
"@tecsinapse/cortex-core": "0.3.0-beta.10",
|
|
24
24
|
"clsx": "*",
|
|
25
25
|
"react-aria": "^3.33.1",
|
|
26
26
|
"react-icons": "^5.2.1",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"react-dom": ">=18.0.0",
|
|
44
44
|
"tailwind": ">=3.3.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "77df5fcf8a51f5f7163663ef33a4961829823940"
|
|
47
47
|
}
|