@gobolt/genesis 0.3.21 → 0.3.22
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/Table/Table.d.ts +51 -0
- package/dist/Table/Table.js +14 -0
- package/dist/Table/TableControls/CustomPagination.d.ts +13 -0
- package/dist/Table/TableControls/CustomPagination.js +158 -0
- package/dist/Table/TableControls/PaginationNumber.d.ts +7 -0
- package/dist/Table/TableControls/PaginationNumber.js +30 -0
- package/dist/Table/styles.d.ts +14 -0
- package/dist/Table/styles.js +64 -0
- package/dist/Table/useTable.d.ts +26 -0
- package/dist/Table/useTable.js +141 -0
- package/dist/Typography/Typography.d.ts +17 -0
- package/dist/Typography/Typography.js +16 -0
- package/dist/Typography/index.d.ts +2 -0
- package/dist/Typography/index.js +1 -0
- package/dist/Typography/styles.d.ts +3 -0
- package/dist/Typography/styles.js +54 -0
- package/dist/components/Badge/Badge.js +9 -32
- package/dist/components/Badge/styles.d.ts +1 -10
- package/dist/components/Badge/styles.js +39 -14
- package/dist/components/Button/Button.js +4 -27
- package/dist/components/Button/IconButton.js +4 -27
- package/dist/components/Button/icon-button-styles.d.ts +1 -12
- package/dist/components/Button/icon-button-styles.js +69 -16
- package/dist/components/Button/styles.d.ts +1 -16
- package/dist/components/Button/styles.js +88 -30
- package/dist/components/Input/Input.js +6 -29
- package/dist/components/Input/styles.d.ts +1 -18
- package/dist/components/Input/styles.js +146 -42
- package/dist/components/Select/Select.js +101 -125
- package/dist/components/Select/SelectTrigger.js +71 -57
- package/dist/components/Table/Table.js +8 -27
- package/dist/components/Table/TableControls/CustomPagination.js +50 -66
- package/dist/components/Table/TableControls/PaginationNumber.js +27 -43
- package/dist/components/Table/TableControls/PrimaryTableControlsRow.js +16 -17
- package/dist/components/Table/TableControls/SecondaryTableControlsRow.js +14 -36
- package/dist/components/Table/TableControls/TableControls.js +3 -4
- package/dist/components/Table/TablePagination.js +4 -21
- package/dist/components/Table/__mocks__/table-mocks.js +15 -24
- package/dist/components/Table/styles.d.ts +1 -15
- package/dist/components/Table/styles.js +57 -13
- package/dist/components/Table/useTable.js +69 -166
- package/dist/components/TableWithControls/TableWithControls.js +6 -7
- package/dist/components/TableWithControls/useTableWithControls.js +82 -63
- package/dist/components/Tooltip/Tooltip.js +1 -2
- package/dist/components/Tooltip/styles.d.ts +1 -14
- package/dist/components/Tooltip/styles.js +23 -14
- package/dist/components/Typography/Typography.js +6 -29
- package/dist/components/Typography/styles.d.ts +3 -21
- package/dist/components/Typography/styles.js +41 -24
- package/dist/components/UtilityButton/UtilityButton.js +4 -27
- package/dist/components/shared/DropdownChevron.js +3 -14
- package/dist/constants/index.js +14 -14
- package/dist/genesis-theme.types.d.ts +263 -0
- package/dist/genesis-theme.types.js +6 -0
- package/dist/index.js +89 -0
- package/dist/styled.d.ts +1 -0
- package/dist/styled.js +44 -0
- package/dist/utils/icon-util.d.ts +2 -2
- package/dist/utils/icon-util.js +16 -19
- package/package.json +1 -1
|
@@ -1,38 +1,23 @@
|
|
|
1
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
6
|
-
var t = {};
|
|
7
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
8
|
-
t[p] = s[p];
|
|
9
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
10
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
12
|
-
t[p[i]] = s[p[i]];
|
|
13
|
-
}
|
|
14
|
-
return t;
|
|
15
|
-
};
|
|
16
1
|
import styled from "@gobolt/genesis/utils/styled";
|
|
17
2
|
import { Input as AntInput } from "antd";
|
|
18
3
|
import { TYPE, STATE } from "@gobolt/genesis/constants";
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const getStateColors = (colors, type, state) => {
|
|
5
|
+
const filled = {
|
|
21
6
|
color: colors.inputs.onsurface.active,
|
|
22
7
|
borderColor: colors[TYPE.secondary].active.borderColor,
|
|
23
8
|
ringColor: colors[type].focussed.ringColor,
|
|
24
9
|
};
|
|
25
|
-
|
|
10
|
+
const success = {
|
|
26
11
|
color: colors.status.success.default,
|
|
27
12
|
borderColor: colors.status.success.default,
|
|
28
13
|
ringColor: colors.status.success.ringColor,
|
|
29
14
|
};
|
|
30
|
-
|
|
15
|
+
const error = {
|
|
31
16
|
color: colors.status.error.default,
|
|
32
17
|
borderColor: colors.status.error.default,
|
|
33
18
|
ringColor: colors.status.error.ringColor,
|
|
34
19
|
};
|
|
35
|
-
|
|
20
|
+
const themeState = state !== STATE.error && state !== STATE.success && state !== STATE.filled
|
|
36
21
|
? {
|
|
37
22
|
color: colors.inputs.onsurface.active,
|
|
38
23
|
backgroundColor: colors.inputs.surface.active,
|
|
@@ -40,37 +25,156 @@ var getStateColors = function (colors, type, state) {
|
|
|
40
25
|
ringColor: colors[type][state].ringColor,
|
|
41
26
|
}
|
|
42
27
|
: null;
|
|
43
|
-
|
|
44
|
-
filled
|
|
45
|
-
error
|
|
46
|
-
success
|
|
47
|
-
themeState
|
|
28
|
+
const stateMap = {
|
|
29
|
+
filled,
|
|
30
|
+
error,
|
|
31
|
+
success,
|
|
32
|
+
themeState,
|
|
48
33
|
};
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
const getValidKey = (state) => {
|
|
35
|
+
const validStates = [STATE.filled, STATE.error, STATE.success];
|
|
51
36
|
return validStates.includes(state) ? state : "themeState";
|
|
52
37
|
};
|
|
53
|
-
|
|
38
|
+
const css = stateMap[getValidKey(state)];
|
|
54
39
|
return css;
|
|
55
40
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var getBorderRadius = function (hasBeforeAddon, hasAfterAddon) {
|
|
41
|
+
const getGenesisInputClass = ({ colors, borderRadius, components, shadows }, type, state, hasBeforeAddon, hasAfterAddon, size) => {
|
|
42
|
+
const stateColors = getStateColors(colors, type, state);
|
|
43
|
+
const getBorderRadius = (hasBeforeAddon, hasAfterAddon) => {
|
|
60
44
|
if (hasAfterAddon && !hasBeforeAddon) {
|
|
61
|
-
return
|
|
45
|
+
return `${borderRadius.BorderRadiusMd}px 0px 0px ${borderRadius.BorderRadiusMd}px`;
|
|
62
46
|
}
|
|
63
47
|
if (hasBeforeAddon && !hasAfterAddon) {
|
|
64
|
-
return
|
|
48
|
+
return `0px ${borderRadius.BorderRadiusMd}px ${borderRadius.BorderRadiusMd}px 0px`;
|
|
65
49
|
}
|
|
66
|
-
return
|
|
50
|
+
return `0px`;
|
|
67
51
|
};
|
|
68
|
-
return
|
|
52
|
+
return `
|
|
53
|
+
&.ant-input {
|
|
54
|
+
font-family: 'Inter', sans-serif;
|
|
55
|
+
color: ${stateColors.color};
|
|
56
|
+
border-color: ${stateColors.borderColor};
|
|
57
|
+
box-shadow: ${shadows.inputs[1]} !important;
|
|
58
|
+
height: ${size === "normal" || size === "large" ? "40px" : "32px"} !important;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* Increase specificity for focus states */
|
|
62
|
+
&.ant-input.ant-input:focus,
|
|
63
|
+
&.ant-input.ant-input:focus-visible,
|
|
64
|
+
&.ant-input.ant-input-focused {
|
|
65
|
+
outline: none !important;
|
|
66
|
+
border-color: ${colors[type].focussed.borderColor} !important;
|
|
67
|
+
box-shadow: 0 0 0 1px #fff, 0 0 0 3px ${colors[type].focussed.ringColor} !important;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&.ant-input-outlined {
|
|
71
|
+
border: 1px solid ${stateColors.borderColor};
|
|
72
|
+
|
|
73
|
+
&:hover {
|
|
74
|
+
border-color: ${stateColors.borderColor};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.ant-input-group & {
|
|
79
|
+
&:focus-within {
|
|
80
|
+
outline: none;
|
|
81
|
+
color: ${stateColors.color};
|
|
82
|
+
box-shadow: none;
|
|
83
|
+
border-color: ${colors[type].focussed.borderColor};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.ant-input-group:focus-within {
|
|
88
|
+
outline: none;
|
|
89
|
+
box-shadow: 0 0 0 1px #fff, 0 0 0 3px ${colors[type].focussed.ringColor};
|
|
90
|
+
border-radius: ${borderRadius.BorderRadiusMd}px;
|
|
91
|
+
transition: box-shadow 0.2s ease-in-out;
|
|
92
|
+
|
|
93
|
+
/* Hide focus styles on inner input when parent is focused */
|
|
94
|
+
.ant-input:focus-within {
|
|
95
|
+
box-shadow: none;
|
|
96
|
+
border-radius: 0;
|
|
97
|
+
border-radius: ${getBorderRadius(hasBeforeAddon, hasAfterAddon)};
|
|
98
|
+
border-color: #ddd;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Remove inner input focus styles when in a group */
|
|
103
|
+
.ant-input-group .ant-input:focus,
|
|
104
|
+
.ant-input-group .ant-input:focus-visible,
|
|
105
|
+
.ant-input-group .ant-input:focus-within {
|
|
106
|
+
outline: none;
|
|
107
|
+
box-shadow: none;
|
|
108
|
+
border-color: ${colors[type].focussed.borderColor};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* Single focus ring on group */
|
|
112
|
+
.ant-input-group:focus-within {
|
|
113
|
+
outline: none;
|
|
114
|
+
box-shadow: 0 0 0 1px #fff, 0 0 0 3px ${colors[type].focussed.ringColor};
|
|
115
|
+
border-radius: ${borderRadius.BorderRadiusMd}px;
|
|
116
|
+
transition: box-shadow 0.2s ease-in-out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* Remove focus styles for standalone inputs */
|
|
120
|
+
&:not(.ant-input-group):focus-visible {
|
|
121
|
+
outline: none;
|
|
122
|
+
color: ${stateColors.color};
|
|
123
|
+
box-shadow: 0 0 0 1px #fff, 0 0 0 3px ${colors[type].focussed.ringColor};
|
|
124
|
+
border-radius: ${borderRadius.BorderRadiusMd}px;
|
|
125
|
+
border-color: ${colors[type].focussed.borderColor};
|
|
126
|
+
transition: box-shadow 0.2s ease-in-out;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
&:not(.ant-input-group .ant-input):focus-visible {
|
|
130
|
+
outline: none;
|
|
131
|
+
color: ${stateColors.color};
|
|
132
|
+
box-shadow: 0 0 0 1px #fff, 0 0 0 3px ${colors[type].focussed.ringColor};
|
|
133
|
+
border-radius: ${borderRadius.BorderRadiusMd}px;
|
|
134
|
+
border-color: ${colors[type].focussed.borderColor};
|
|
135
|
+
transition: box-shadow 0.2s ease-in-out;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
&.ant-input-group-wrapper {
|
|
139
|
+
.ant-input-group {
|
|
140
|
+
display: flex;
|
|
141
|
+
align-items: center;
|
|
142
|
+
height: ${size === "normal" || size === "large" ? "40px" : "32px"};
|
|
143
|
+
|
|
144
|
+
.ant-input {
|
|
145
|
+
height: 100% !important;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.ant-input-group-addon {
|
|
149
|
+
padding: 0 ${components.input.suffixPrefixHorPadding};
|
|
150
|
+
height: 100%;
|
|
151
|
+
display: flex;
|
|
152
|
+
align-items: center;
|
|
153
|
+
min-width: fit-content;
|
|
154
|
+
width: auto;
|
|
155
|
+
|
|
156
|
+
> * {
|
|
157
|
+
width: 100%;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.ant-select {
|
|
161
|
+
height: 100%;
|
|
162
|
+
|
|
163
|
+
.ant-select-selector {
|
|
164
|
+
height: 100%;
|
|
165
|
+
display: flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
`;
|
|
69
173
|
};
|
|
70
|
-
export
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
174
|
+
export const Input = styled(AntInput) `
|
|
175
|
+
${({ theme, state, type = TYPE.primary, size = "normal", ...rest }) => {
|
|
176
|
+
const hasBeforeAddon = !!rest.addonBefore;
|
|
177
|
+
const hasAfterAddon = !!rest.addonAfter;
|
|
74
178
|
return getGenesisInputClass(theme, type, state, hasBeforeAddon, hasAfterAddon, size);
|
|
75
|
-
}
|
|
76
|
-
|
|
179
|
+
}}
|
|
180
|
+
`;
|
|
@@ -1,114 +1,91 @@
|
|
|
1
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
6
|
-
var t = {};
|
|
7
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
8
|
-
t[p] = s[p];
|
|
9
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
10
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
12
|
-
t[p[i]] = s[p[i]];
|
|
13
|
-
}
|
|
14
|
-
return t;
|
|
15
|
-
};
|
|
16
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
17
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18
|
-
if (!m) return o;
|
|
19
|
-
var i = m.call(o), r, ar = [], e;
|
|
20
|
-
try {
|
|
21
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
22
|
-
}
|
|
23
|
-
catch (error) { e = { error: error }; }
|
|
24
|
-
finally {
|
|
25
|
-
try {
|
|
26
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
27
|
-
}
|
|
28
|
-
finally { if (e) throw e.error; }
|
|
29
|
-
}
|
|
30
|
-
return ar;
|
|
31
|
-
};
|
|
32
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
33
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
34
|
-
if (ar || !(i in from)) {
|
|
35
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
36
|
-
ar[i] = from[i];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
40
|
-
};
|
|
41
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
42
2
|
import React from "react";
|
|
43
3
|
import { TYPE } from "@gobolt/genesis/constants";
|
|
44
4
|
import styled from "@gobolt/genesis/utils/styled";
|
|
45
5
|
import SelectTrigger from "./SelectTrigger";
|
|
46
6
|
import { useGenesis } from "@gobolt/genesis/providers";
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
7
|
+
const SelectWrapper = styled.div `
|
|
8
|
+
position: relative;
|
|
9
|
+
background-color: transparent;
|
|
10
|
+
border-radius: 8px;
|
|
11
|
+
width: auto;
|
|
12
|
+
|
|
13
|
+
${({ $isFocused, theme, type = "primary" }) => $isFocused &&
|
|
14
|
+
`
|
|
15
|
+
background-color: transparent;
|
|
16
|
+
`}
|
|
17
|
+
|
|
18
|
+
${({ disabled, theme }) => disabled &&
|
|
19
|
+
`
|
|
20
|
+
cursor: not-allowed;
|
|
21
|
+
|
|
22
|
+
&:hover {
|
|
23
|
+
border-color: ${theme.colors.inputs.surface.border};
|
|
24
|
+
}
|
|
25
|
+
`}
|
|
26
|
+
`;
|
|
27
|
+
const SelectDropdown = styled.div `
|
|
28
|
+
padding: 0px;
|
|
29
|
+
border-radius: 0px;
|
|
30
|
+
animation-duration: ${({ theme }) => `${theme.motion.veryfast}s`};
|
|
31
|
+
transition: all ${({ theme }) => `${theme.motion.veryfast}s`}
|
|
32
|
+
cubic-bezier(0.645, 0.045, 0.355, 1);
|
|
33
|
+
|
|
34
|
+
&.entering {
|
|
35
|
+
opacity: 0;
|
|
36
|
+
transform: scaleY(0.8);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.entered {
|
|
40
|
+
opacity: 1;
|
|
41
|
+
transform: scaleY(1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.exiting {
|
|
45
|
+
opacity: 0;
|
|
46
|
+
transform: scaleY(0.8);
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
const MenuItem = styled.div `
|
|
50
|
+
padding: 8px 12px;
|
|
51
|
+
cursor: ${({ disabled }) => (disabled ? "not-allowed" : "pointer")};
|
|
52
|
+
background-color: ${({ $isSelected, theme, type = "primary" }) => $isSelected ? theme.colors[type].hover.backgroundColor : "transparent"};
|
|
53
|
+
color: ${({ $isSelected, disabled, theme, type = "primary" }) => disabled
|
|
54
|
+
? theme.colors.inputs.onsurface.disabled
|
|
55
|
+
: $isSelected
|
|
56
|
+
? theme.colors[type].hover.color
|
|
57
|
+
: theme.colors.onsurface.copy};
|
|
58
|
+
display: flex;
|
|
59
|
+
justify-content: space-between;
|
|
60
|
+
align-items: center;
|
|
61
|
+
transition: all ${({ theme }) => `${theme.motion.veryfast}s`} ease-in-out;
|
|
62
|
+
opacity: ${({ disabled }) => (disabled ? 0.5 : 1)};
|
|
63
|
+
|
|
64
|
+
${({ disabled }) => !disabled &&
|
|
65
|
+
`
|
|
66
|
+
&:hover {
|
|
67
|
+
background-color: ${({ $isSelected, theme, type = "primary" }) => $isSelected
|
|
68
|
+
? theme.colors[type].hover.backgroundColor
|
|
69
|
+
: "rgba(0, 0, 0, 0.04)"};
|
|
70
|
+
color: ${({ $isSelected, theme, type = "primary" }) => $isSelected
|
|
71
|
+
? theme.colors[type].hover.color
|
|
72
|
+
: theme.colors.onsurface["copy-dark"]};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&:active {
|
|
76
|
+
background-color: ${({ theme, type = "primary" }) => theme.colors[type].hover.backgroundColor};
|
|
77
|
+
color: ${({ theme, type = "primary" }) => theme.colors[type].hover.color};
|
|
78
|
+
}
|
|
79
|
+
`}
|
|
80
|
+
`;
|
|
81
|
+
const Select = ({ type = TYPE.primary, state, variant = "none", defaultValue, onChange, size = "normal", width = "100%", value, options = [], placeholder, selectDisplayMode = "count", isSingleSelect = true, disabled = false, ...rest }) => {
|
|
82
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
83
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
84
|
+
const [dropdownAnimation, setDropdownAnimation] = React.useState("entered");
|
|
85
|
+
const selectReference = React.useRef(null);
|
|
86
|
+
const { theme } = useGenesis();
|
|
87
|
+
React.useEffect(() => {
|
|
88
|
+
const handleClickOutside = (event) => {
|
|
112
89
|
if (selectReference.current &&
|
|
113
90
|
!selectReference.current.contains(event.target)) {
|
|
114
91
|
handleClose();
|
|
@@ -118,18 +95,18 @@ var Select = function (_a) {
|
|
|
118
95
|
if (isOpen) {
|
|
119
96
|
document.addEventListener("mousedown", handleClickOutside);
|
|
120
97
|
}
|
|
121
|
-
return
|
|
98
|
+
return () => {
|
|
122
99
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
123
100
|
};
|
|
124
101
|
}, [isOpen]);
|
|
125
|
-
|
|
102
|
+
const handleClose = () => {
|
|
126
103
|
setDropdownAnimation("exiting");
|
|
127
|
-
setTimeout(
|
|
104
|
+
setTimeout(() => {
|
|
128
105
|
setIsOpen(false);
|
|
129
106
|
setDropdownAnimation("entered");
|
|
130
107
|
}, 200);
|
|
131
108
|
};
|
|
132
|
-
|
|
109
|
+
const handleTriggerClick = () => {
|
|
133
110
|
if (disabled)
|
|
134
111
|
return;
|
|
135
112
|
setIsFocused(true);
|
|
@@ -139,21 +116,21 @@ var Select = function (_a) {
|
|
|
139
116
|
else {
|
|
140
117
|
setIsOpen(true);
|
|
141
118
|
setDropdownAnimation("entering");
|
|
142
|
-
setTimeout(
|
|
119
|
+
setTimeout(() => {
|
|
143
120
|
setDropdownAnimation("entered");
|
|
144
121
|
}, 0);
|
|
145
122
|
}
|
|
146
123
|
};
|
|
147
|
-
|
|
124
|
+
const handleOptionSelect = (optionValue) => {
|
|
148
125
|
if (disabled)
|
|
149
126
|
return;
|
|
150
|
-
|
|
127
|
+
let newValue;
|
|
151
128
|
if (Array.isArray(value)) {
|
|
152
129
|
// Handle multi-select
|
|
153
|
-
|
|
130
|
+
const stringValue = value.map(String);
|
|
154
131
|
newValue = stringValue.includes(optionValue)
|
|
155
|
-
? stringValue.filter(
|
|
156
|
-
:
|
|
132
|
+
? stringValue.filter((v) => v !== optionValue)
|
|
133
|
+
: [...stringValue, optionValue];
|
|
157
134
|
}
|
|
158
135
|
else {
|
|
159
136
|
// Handle single select
|
|
@@ -162,23 +139,23 @@ var Select = function (_a) {
|
|
|
162
139
|
// Autoclose if single select or variant is 'simple'
|
|
163
140
|
if (isSingleSelect || variant === "simple") {
|
|
164
141
|
handleClose(); // Close immediately
|
|
165
|
-
onChange
|
|
142
|
+
onChange?.(newValue);
|
|
166
143
|
}
|
|
167
144
|
else {
|
|
168
|
-
onChange
|
|
145
|
+
onChange?.(newValue);
|
|
169
146
|
}
|
|
170
147
|
};
|
|
171
|
-
|
|
148
|
+
const getSelectModeValue = (value) => {
|
|
172
149
|
if (Array.isArray(value)) {
|
|
173
150
|
if (selectDisplayMode === "count") {
|
|
174
|
-
return
|
|
151
|
+
return `${value.length} selected`;
|
|
175
152
|
}
|
|
176
153
|
return value;
|
|
177
154
|
}
|
|
178
155
|
return value;
|
|
179
156
|
};
|
|
180
|
-
|
|
181
|
-
return (_jsx("div", { style: { position: "relative", width
|
|
157
|
+
const modeValue = getSelectModeValue(value);
|
|
158
|
+
return (_jsx("div", { style: { position: "relative", width }, children: _jsxs(SelectWrapper, { ref: selectReference, "$isFocused": isFocused, type: type, disabled: disabled, onFocus: () => !disabled && setIsFocused(true), onBlur: () => !isOpen && setIsFocused(false), tabIndex: disabled ? -1 : 0, children: [_jsx(SelectTrigger, { theme: theme, type: type, state: state, value: modeValue, placeholder: placeholder, open: isOpen, onClick: handleTriggerClick, options: options, disabled: disabled, variant: variant }), isOpen && !disabled && (_jsx(SelectDropdown, { type: type, state: state, className: dropdownAnimation, style: {
|
|
182
159
|
position: "absolute",
|
|
183
160
|
top: "calc(100% + 4px)",
|
|
184
161
|
left: 0,
|
|
@@ -188,12 +165,11 @@ var Select = function (_a) {
|
|
|
188
165
|
boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)",
|
|
189
166
|
border: "1px solid #d9d9d9",
|
|
190
167
|
transformOrigin: "top",
|
|
191
|
-
}, children: options.map(
|
|
192
|
-
|
|
168
|
+
}, children: options.map((option) => {
|
|
169
|
+
const isSelected = Array.isArray(value)
|
|
193
170
|
? value.map(String).includes(option.value)
|
|
194
171
|
: String(value) === option.value;
|
|
195
|
-
return (_jsxs(MenuItem, { onClick:
|
|
172
|
+
return (_jsxs(MenuItem, { onClick: () => handleOptionSelect(option.value), "$isSelected": isSelected, type: type, disabled: disabled, children: [option.label, isSelected && _jsx("span", { style: { marginLeft: "8px" }, children: "\u2713" })] }, option.value));
|
|
196
173
|
}) }))] }) }));
|
|
197
174
|
};
|
|
198
175
|
export default Select;
|
|
199
|
-
var templateObject_1, templateObject_2, templateObject_3;
|