react-restyle-components 0.3.83 → 0.3.86
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/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.d.ts +4 -0
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.d.ts.map +1 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.js +3 -3
- package/lib/src/core-components/src/components/Accordion/AccordionSection/Header.js +2 -2
- package/lib/src/core-components/src/components/Accordion/AccordionSection/elements.d.ts +4 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/elements.d.ts.map +1 -1
- package/lib/src/core-components/src/components/Accordion/AccordionSection/elements.js +31 -20
- package/lib/src/core-components/src/components/AutoComplete/autocomplete/autocomplete.d.ts.map +1 -1
- package/lib/src/core-components/src/components/AutoComplete/autocomplete/autocomplete.js +174 -35
- package/lib/src/core-components/src/core-components/StateLayer.d.ts.map +1 -1
- package/lib/src/core-components/src/core-components/StateLayer.js +3 -2
- package/lib/src/core-components/src/index.css +0 -1
- package/lib/src/core-components/src/index.d.ts +0 -1
- package/lib/src/core-components/src/index.d.ts.map +1 -1
- package/lib/src/core-components/src/index.js +0 -1
- package/lib/src/core-components/src/tc.global.css +24 -2
- package/lib/src/core-components/src/tc.module.css +1 -2
- package/lib/src/core-components/src/utils/designTokens.d.ts +36 -0
- package/lib/src/core-components/src/utils/designTokens.d.ts.map +1 -0
- package/lib/src/core-components/src/utils/designTokens.js +42 -0
- package/lib/src/core-components/src/utils/index.d.ts +1 -0
- package/lib/src/core-components/src/utils/index.d.ts.map +1 -1
- package/lib/src/core-components/src/utils/index.js +1 -0
- package/lib/src/core-components/tailwind.config.js +331 -0
- package/package.json +1 -1
- package/lib/src/core-components/src/assets/css/tokens.css +0 -416
package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { IconProps } from '../../Icon';
|
|
3
3
|
export type AccordionSectionProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
4
4
|
buttonClassName?: string;
|
|
5
|
+
headerClassName?: string;
|
|
6
|
+
subheaderClassName?: string;
|
|
5
7
|
iconWrapperClassName?: string;
|
|
6
8
|
/** @deprecated use `aria-label` instead */
|
|
7
9
|
ariaLabel?: string;
|
|
@@ -20,6 +22,8 @@ export type AccordionSectionProps = React.ButtonHTMLAttributes<HTMLButtonElement
|
|
|
20
22
|
};
|
|
21
23
|
export declare const AccordionSection: React.ForwardRefExoticComponent<React.ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
22
24
|
buttonClassName?: string | undefined;
|
|
25
|
+
headerClassName?: string | undefined;
|
|
26
|
+
subheaderClassName?: string | undefined;
|
|
23
27
|
iconWrapperClassName?: string | undefined;
|
|
24
28
|
/** @deprecated use `aria-label` instead */
|
|
25
29
|
ariaLabel?: string | undefined;
|
package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccordionSection.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/Accordion/AccordionSection/AccordionSection.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAgD,MAAM,OAAO,CAAC;AAUrE,OAAO,EAAO,SAAS,EAAC,MAAM,YAAY,CAAC;AAU3C,MAAM,MAAM,qBAAqB,GAC/B,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,GAAG;IAC9C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mGAAmG;IACnG,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB;IAClB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEJ,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"AccordionSection.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/Accordion/AccordionSection/AccordionSection.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAgD,MAAM,OAAO,CAAC;AAUrE,OAAO,EAAO,SAAS,EAAC,MAAM,YAAY,CAAC;AAU3C,MAAM,MAAM,qBAAqB,GAC/B,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,GAAG;IAC9C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,mGAAmG;IACnG,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB;IAClB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEJ,eAAO,MAAM,gBAAgB;;;;;IAhBzB,2CAA2C;;IAE3C,mGAAmG;;;;;;IAMnG,kBAAkB;;IAElB,kBAAkB;;qCAEc,OAAO,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;CAmInD,CAAC"}
|
package/lib/src/core-components/src/components/Accordion/AccordionSection/AccordionSection.js
CHANGED
|
@@ -8,7 +8,7 @@ import { useCurrentAccordionIndex } from './hooks/useCurrentAccordionIndex';
|
|
|
8
8
|
import AccordionContext from './AccordionContext';
|
|
9
9
|
import { StateLayer } from '../../../core-components';
|
|
10
10
|
import { attachSubComponents, separateChildrenByType, usePropDeprecation, } from '../../../utils';
|
|
11
|
-
export const AccordionSection = attachSubComponents('AccordionSection', React.forwardRef(({ buttonClassName = '', iconWrapperClassName = '', ariaLabel = '', icons, children, header, subheader, startOpen = false, transitionDuration = '.3s', transitionTimingFunction = 'ease-in', onClick, onOpenStateChange, isOpen, ...rest }, fRef) => {
|
|
11
|
+
export const AccordionSection = attachSubComponents('AccordionSection', React.forwardRef(({ buttonClassName = '', headerClassName = '', subheaderClassName = '', iconWrapperClassName = '', ariaLabel = '', icons, children, header, subheader, startOpen = false, transitionDuration = '.3s', transitionTimingFunction = 'ease-in', onClick, onOpenStateChange, isOpen, ...rest }, fRef) => {
|
|
12
12
|
usePropDeprecation({
|
|
13
13
|
name: 'iconSrc',
|
|
14
14
|
version: '5.0.0',
|
|
@@ -23,8 +23,8 @@ export const AccordionSection = attachSubComponents('AccordionSection', React.fo
|
|
|
23
23
|
setAccordionOpenState(isOpen ?? startOpen);
|
|
24
24
|
}, [isOpen]);
|
|
25
25
|
const [headerElements, content] = separateChildrenByType(children, Header);
|
|
26
|
-
const sectionHeader = React.Children.count(headerElements) !== 0 ? (headerElements) : (_jsxs(Header, { children: [numbered ? (_jsx(Header.Leading, { children: _jsxs(Header.Number, { children: [accordionIndex, "."] }) })) : (icons && (_jsx(Header.Leading, { className: iconWrapperClassName, children: _jsx(Icon, { nameIcon: icons.nameIcon }) }))), _jsx(Header.Heading, { children: header }), subheader && (_jsx(Header.SupportiveText, { children: subheader }))] }));
|
|
27
|
-
return (_jsxs(AccordionSectionWrapper, { "$variant": variant, "$isOpen": accordionOpen, "data-aui": "accordion.section", ref: accordionRef, children: [_jsxs(ButtonElement, { ref: fRef, className: buttonClassName, "aria-label": ariaLabel, "aria-expanded": accordionOpen, onClick: (e) => {
|
|
26
|
+
const sectionHeader = React.Children.count(headerElements) !== 0 ? (headerElements) : (_jsxs(Header, { children: [numbered ? (_jsx(Header.Leading, { children: _jsxs(Header.Number, { children: [accordionIndex, "."] }) })) : (icons && (_jsx(Header.Leading, { className: iconWrapperClassName, children: _jsx(Icon, { nameIcon: icons.nameIcon }) }))), _jsx(Header.Heading, { className: headerClassName, children: header }), subheader && (_jsx(Header.SupportiveText, { className: subheaderClassName, children: subheader }))] }));
|
|
27
|
+
return (_jsxs(AccordionSectionWrapper, { "$variant": variant, "$isOpen": accordionOpen, "data-aui": "accordion.section", ref: accordionRef, children: [_jsxs(ButtonElement, { ref: fRef, className: buttonClassName, "aria-label": ariaLabel, "aria-expanded": accordionOpen, "$variant": variant, "$isOpen": accordionOpen, onClick: (e) => {
|
|
28
28
|
onClick?.(e);
|
|
29
29
|
onOpenStateChange?.(!accordionOpen);
|
|
30
30
|
setAccordionOpenState(!accordionOpen);
|
|
@@ -17,7 +17,7 @@ const Text = ({ size, weight, color, children, ...props }) => {
|
|
|
17
17
|
return (_jsx("span", { style: {
|
|
18
18
|
fontSize: fontSizeMap[size] || fontSizeMap[2],
|
|
19
19
|
fontWeight: fontWeightMap[weight] || fontWeightMap['regular'],
|
|
20
|
-
color: color || '
|
|
20
|
+
color: color || 'white',
|
|
21
21
|
}, ...props, children: children }));
|
|
22
22
|
};
|
|
23
23
|
const LeadingTrailing = ({ children, ...props }) => (_jsx(StyledLeadingTrailing, { ...props, children: _jsx(DefaultsProvider, { value: { iconSize: 'large' }, children: children }) }));
|
|
@@ -25,7 +25,7 @@ const Leading = (props) => _jsx(LeadingTrailing, { ...props });
|
|
|
25
25
|
const Trailing = (props) => _jsx(LeadingTrailing, { ...props });
|
|
26
26
|
const Number = ({ children, ...props }) => (_jsx(Text, { size: 2, weight: "heavy", ...props, children: children }));
|
|
27
27
|
const Heading = ({ children, ...props }) => (_jsx(Text, { size: 2, weight: "heavy", ...props, children: children }));
|
|
28
|
-
const SupportiveText = ({ children, ...props }) => (_jsx(Text, { size: 1,
|
|
28
|
+
const SupportiveText = ({ children, ...props }) => (_jsx(Text, { size: 1, ...props, children: children }));
|
|
29
29
|
export const Header = attachSubComponents('Header', ({ children }) => {
|
|
30
30
|
const [leading, trailing, content] = separateChildrenByType(children, Leading, Trailing);
|
|
31
31
|
return (_jsxs(_Fragment, { children: [leading, _jsx(AccordionSectionText, { children: content }), trailing] }));
|
|
@@ -7,7 +7,10 @@ export declare const AccordionSectionWrapper: import("styled-components/dist/typ
|
|
|
7
7
|
$variant: AccordionVariant | 'inline' | 'full-page';
|
|
8
8
|
$isOpen: boolean;
|
|
9
9
|
}>> & string;
|
|
10
|
-
export declare const ButtonElement: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").
|
|
10
|
+
export declare const ButtonElement: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {
|
|
11
|
+
$variant?: AccordionVariant | "inline" | "full-page" | undefined;
|
|
12
|
+
$isOpen?: boolean | undefined;
|
|
13
|
+
}>> & string;
|
|
11
14
|
export declare const AccordionSectionText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
12
15
|
type AccordionSectionContentProps = {
|
|
13
16
|
$isOpen: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/Accordion/AccordionSection/elements.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAC,gBAAgB,EAA2B,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/Accordion/AccordionSection/elements.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAC,gBAAgB,EAA2B,MAAM,SAAS,CAAC;AAUnE,eAAO,MAAM,gBAAgB;cACjB,gBAAgB,GAAG,QAAQ,GAAG,WAAW;YAepD,CAAC;AAEF,eAAO,MAAM,uBAAuB;cACxB,gBAAgB,GAAG,QAAQ,GAAG,WAAW;aAC1C,OAAO;YAYjB,CAAC;AAEF,eAAO,MAAM,aAAa;;;YAmCzB,CAAC;AAEF,eAAO,MAAM,oBAAoB,6NAShC,CAAC;AAEF,KAAK,4BAA4B,GAAG;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,aAAa;aACf,OAAO;yBACK,MAAM;+BACA,MAAM;YAQlC,CAAC;AAmBF,eAAO,MAAM,8BAA8B;aAChC,OAAO;yBACK,MAAM;+BACA,MAAM;YAWlC,CAAC;AAEF,eAAO,MAAM,uBAAuB,iQASnC,CAAC;AAEF,eAAO,MAAM,qBAAqB;;YAejC,CAAC;AAEF,eAAO,MAAM,gBAAgB;;mBAE5B,CAAC;AAEF,eAAO,MAAM,YAAY;iBACV,OAAO;2IAMrB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { styled, css } from 'styled-components';
|
|
2
2
|
import { Icon } from '../../Icon';
|
|
3
3
|
import { StateLayer } from '../../../core-components';
|
|
4
|
+
import { tokens } from '../../../utils/designTokens';
|
|
4
5
|
const Divider = styled.hr `
|
|
5
6
|
border: none;
|
|
6
7
|
border-top: 1px solid;
|
|
@@ -14,18 +15,17 @@ export const AccordionElement = styled.div `
|
|
|
14
15
|
flex-direction: column;
|
|
15
16
|
${({ $variant }) => $variant === 'inline' &&
|
|
16
17
|
css `
|
|
17
|
-
border: 1px solid
|
|
18
|
-
border-radius:
|
|
18
|
+
border: 1px solid ${tokens.outline};
|
|
19
|
+
border-radius: ${tokens.borderRadius100};
|
|
19
20
|
`};
|
|
20
21
|
overflow: hidden;
|
|
21
22
|
width: 100%;
|
|
22
|
-
color:
|
|
23
|
+
color: ${tokens.onSurface};
|
|
23
24
|
`;
|
|
24
25
|
export const AccordionSectionWrapper = styled.div `
|
|
25
26
|
overflow: hidden;
|
|
26
27
|
width: 100%;
|
|
27
28
|
isolation: isolate;
|
|
28
|
-
|
|
29
29
|
${({ $variant }) => $variant === 'inline' &&
|
|
30
30
|
css `
|
|
31
31
|
&:last-child ${AccordionDivider} {
|
|
@@ -35,44 +35,53 @@ export const AccordionSectionWrapper = styled.div `
|
|
|
35
35
|
`;
|
|
36
36
|
export const ButtonElement = styled.button `
|
|
37
37
|
all: unset;
|
|
38
|
+
box-sizing: border-box;
|
|
38
39
|
|
|
39
40
|
z-index: 1;
|
|
40
41
|
position: relative;
|
|
41
42
|
cursor: pointer;
|
|
42
43
|
width: 100%;
|
|
43
|
-
box-sizing: border-box;
|
|
44
44
|
|
|
45
|
-
background-color:
|
|
45
|
+
background-color: ${tokens.surface};
|
|
46
46
|
|
|
47
47
|
display: flex;
|
|
48
|
-
gap:
|
|
48
|
+
gap: ${tokens.spacing100};
|
|
49
49
|
align-items: center;
|
|
50
|
-
padding:
|
|
50
|
+
padding-top: ${tokens.spacing200};
|
|
51
|
+
padding-right: ${tokens.spacing200};
|
|
52
|
+
padding-bottom: ${tokens.spacing200};
|
|
53
|
+
padding-left: ${tokens.spacing200};
|
|
54
|
+
|
|
55
|
+
${({ $variant }) => $variant === 'inline' &&
|
|
56
|
+
css `
|
|
57
|
+
border-radius: ${tokens.borderRadius100};
|
|
58
|
+
`}
|
|
51
59
|
|
|
52
60
|
&:hover:not(:disabled) ${StateLayer} {
|
|
53
|
-
opacity:
|
|
61
|
+
opacity: ${tokens.stateLayerHover};
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
&:active:not(:disabled) ${StateLayer} {
|
|
57
|
-
opacity:
|
|
65
|
+
opacity: ${tokens.stateLayerPress};
|
|
58
66
|
}
|
|
59
67
|
`;
|
|
60
68
|
export const AccordionSectionText = styled.div `
|
|
61
69
|
line-height: 1.3;
|
|
62
70
|
flex-grow: 1;
|
|
63
|
-
padding-right:
|
|
64
|
-
|
|
71
|
+
padding-right: ${tokens.spacing100};
|
|
72
|
+
position: relative;
|
|
73
|
+
z-index: 1;
|
|
65
74
|
display: flex;
|
|
66
75
|
flex-direction: column;
|
|
67
|
-
gap:
|
|
76
|
+
gap: ${tokens.spacing050};
|
|
68
77
|
`;
|
|
69
78
|
export const AccordionFade = styled.div `
|
|
70
79
|
z-index: 0;
|
|
71
80
|
position: relative;
|
|
72
|
-
background: linear-gradient(to bottom, transparent,
|
|
81
|
+
background: linear-gradient(to bottom, transparent, ${tokens.surface});
|
|
73
82
|
width: 100%;
|
|
74
|
-
height:
|
|
75
|
-
margin-top: calc(
|
|
83
|
+
height: ${tokens.spacing150};
|
|
84
|
+
margin-top: calc(${tokens.spacing150} * -1);
|
|
76
85
|
`;
|
|
77
86
|
const getTransitionTimingFunction = (transitionTimingFunction, isOpen) => {
|
|
78
87
|
if (transitionTimingFunction !== 'ease-in' &&
|
|
@@ -96,14 +105,16 @@ export const AccordionSectionContent = styled.div `
|
|
|
96
105
|
transition: ${({ $transitionDuration }) => `opacity ${$transitionDuration} linear`};
|
|
97
106
|
line-height: 1.3;
|
|
98
107
|
opacity: ${({ $isOpen }) => ($isOpen ? 1 : 0)};
|
|
99
|
-
padding-right:
|
|
100
|
-
padding-left: ${({ $hasLeader }) => $hasLeader ?
|
|
108
|
+
padding-right: ${tokens.spacing150};
|
|
109
|
+
padding-left: ${({ $hasLeader }) => $hasLeader ? tokens.spacing600 : tokens.spacing200};
|
|
101
110
|
`;
|
|
102
111
|
export const StyledLeadingTrailing = styled.div `
|
|
103
112
|
flex-shrink: 0;
|
|
104
|
-
min-width:
|
|
113
|
+
min-width: ${tokens.spacing300};
|
|
105
114
|
display: flex;
|
|
106
115
|
align-self: ${({ alignment }) => alignment === 'center' ? 'center' : 'flex-start'};
|
|
116
|
+
position: relative;
|
|
117
|
+
z-index: 1;
|
|
107
118
|
|
|
108
119
|
img,
|
|
109
120
|
picture {
|
|
@@ -111,7 +122,7 @@ export const StyledLeadingTrailing = styled.div `
|
|
|
111
122
|
}
|
|
112
123
|
`;
|
|
113
124
|
export const AccordionDivider = styled(Divider) `
|
|
114
|
-
border-color:
|
|
125
|
+
border-color: ${tokens.outline};
|
|
115
126
|
`;
|
|
116
127
|
export const RotatingIcon = styled(Icon.SSR) `
|
|
117
128
|
overflow: hidden;
|
package/lib/src/core-components/src/components/AutoComplete/autocomplete/autocomplete.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/AutoComplete/autocomplete/autocomplete.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAKtE,4BAA4B;AAC5B,MAAM,WAAW,kBAAkB;IACjC,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,sBAAsB;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,2BAA2B;AAC3B,MAAM,WAAW,wBAAwB;IACvC,uBAAuB;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+BAA+B;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,CACT,MAAM,EAAE,MAAM,GAAG,kBAAkB,EACnC,WAAW,EAAE,MAAM,KAChB,OAAO,CAAC;IACb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plete.d.ts","sourceRoot":"","sources":["../../../../../../../src/core-components/src/components/AutoComplete/autocomplete/autocomplete.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAKtE,4BAA4B;AAC5B,MAAM,WAAW,kBAAkB;IACjC,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,sBAAsB;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,2BAA2B;AAC3B,MAAM,WAAW,wBAAwB;IACvC,uBAAuB;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+BAA+B;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,CACT,MAAM,EAAE,MAAM,GAAG,kBAAkB,EACnC,WAAW,EAAE,MAAM,KAChB,OAAO,CAAC;IACb,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,4BAA4B;AAC5B,MAAM,WAAW,yBAAyB;IACxC,wCAAwC;IACxC,YAAY,CAAC,EAAE,CACb,MAAM,EAAE,MAAM,GAAG,kBAAkB,EACnC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,OAAO,KACd,KAAK,CAAC,SAAS,CAAC;IACrB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC;IACzC,8BAA8B;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gCAAgC;IAChC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,yBAAyB;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wCAAwC;AACxC,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,EAAE,CAA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,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,sBAAsB;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,KAAK,IAAI,CAAC;IACzD,gCAAgC;IAChC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAID,eAAO,MAAM,YAAY,oNAmBtB,iBAAiB,4CAsvBnB,CAAC"}
|
|
@@ -32,27 +32,43 @@ export const Autocomplete = ({ value = '', onValueChange, options = [], filterCo
|
|
|
32
32
|
(typeof opt === 'string' ? opt : opt.label) === value);
|
|
33
33
|
return index !== -1 ? index : 0;
|
|
34
34
|
});
|
|
35
|
+
// Initialize filtered options - will be updated by useEffect
|
|
35
36
|
const [filteredOptions, setFilteredOptions] = useState(options);
|
|
36
37
|
const [shouldShowList, setShouldShowList] = useState(false);
|
|
37
38
|
const [searchValue, setSearchValue] = useState(value);
|
|
38
39
|
const inputRef = useRef(null);
|
|
39
40
|
const listRef = useRef(null);
|
|
41
|
+
const wrapperRef = useRef(null);
|
|
42
|
+
// Track if user is actively typing to prevent value prop from overwriting input
|
|
43
|
+
const isTypingRef = useRef(false);
|
|
44
|
+
const typingTimeoutRef = useRef(null);
|
|
40
45
|
// Filter function
|
|
41
46
|
const filterOptions = useCallback((searchValue) => {
|
|
42
47
|
if (!filterEnabled)
|
|
43
48
|
return options;
|
|
44
|
-
|
|
49
|
+
// If search is empty and minCharacters is 0, show all options
|
|
50
|
+
if (searchValue.length === 0 && minCharacters === 0)
|
|
45
51
|
return options;
|
|
52
|
+
// If search length is less than minCharacters, return empty array or all options
|
|
53
|
+
if (searchValue.length < minCharacters) {
|
|
54
|
+
return minCharacters === 0 ? options : [];
|
|
55
|
+
}
|
|
56
|
+
// Use custom filter function if provided
|
|
46
57
|
if (filterFn) {
|
|
47
58
|
return options.filter((option) => filterFn(option, searchValue));
|
|
48
59
|
}
|
|
60
|
+
// Default filtering: case-insensitive substring match
|
|
49
61
|
const lowerSearch = caseSensitive
|
|
50
|
-
? searchValue
|
|
51
|
-
: searchValue.toLowerCase();
|
|
62
|
+
? searchValue.trim()
|
|
63
|
+
: searchValue.trim().toLowerCase();
|
|
64
|
+
if (lowerSearch.length === 0)
|
|
65
|
+
return options;
|
|
52
66
|
return options.filter((option) => {
|
|
53
67
|
const label = getOptionLabel(option);
|
|
54
|
-
const matchText = caseSensitive
|
|
55
|
-
|
|
68
|
+
const matchText = caseSensitive
|
|
69
|
+
? label.trim()
|
|
70
|
+
: label.trim().toLowerCase();
|
|
71
|
+
return matchText.includes(lowerSearch);
|
|
56
72
|
});
|
|
57
73
|
}, [
|
|
58
74
|
options,
|
|
@@ -64,21 +80,34 @@ export const Autocomplete = ({ value = '', onValueChange, options = [], filterCo
|
|
|
64
80
|
]);
|
|
65
81
|
const onInputChange = useCallback((event) => {
|
|
66
82
|
const input = event.target.value;
|
|
83
|
+
// Mark that user is typing
|
|
84
|
+
isTypingRef.current = true;
|
|
85
|
+
// Clear existing timeout
|
|
86
|
+
if (typingTimeoutRef.current) {
|
|
87
|
+
clearTimeout(typingTimeoutRef.current);
|
|
88
|
+
}
|
|
89
|
+
// Reset typing flag after user stops typing (300ms)
|
|
90
|
+
typingTimeoutRef.current = setTimeout(() => {
|
|
91
|
+
isTypingRef.current = false;
|
|
92
|
+
}, 300);
|
|
67
93
|
// Call onInputValueChange callback
|
|
68
94
|
if (onInputValueChange) {
|
|
69
95
|
onInputValueChange(input);
|
|
70
96
|
}
|
|
97
|
+
// Update search value immediately for responsive UI
|
|
98
|
+
setSearchValue(input);
|
|
71
99
|
// Filter options
|
|
72
100
|
const filtered = filterOptions(input);
|
|
73
101
|
setFilteredOptions(filtered);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onValueChange(filtered[0]);
|
|
102
|
+
// Reset active option to first item or 0
|
|
103
|
+
setActiveOption(filtered.length > 0 ? 0 : 0);
|
|
104
|
+
// Show list if there are filtered options or if input is not empty
|
|
105
|
+
if (filtered.length > 0 || input.length > 0) {
|
|
106
|
+
setShouldShowList(true);
|
|
80
107
|
}
|
|
81
|
-
|
|
108
|
+
// Don't auto-select when user is typing - only update the input value
|
|
109
|
+
// Auto-select should only happen on initial load or when dropdown opens
|
|
110
|
+
}, [filterOptions, onInputValueChange]);
|
|
82
111
|
const handleOptionSelect = useCallback((option, index) => {
|
|
83
112
|
const label = getOptionLabel(option);
|
|
84
113
|
setShouldShowList(false);
|
|
@@ -183,24 +212,56 @@ export const Autocomplete = ({ value = '', onValueChange, options = [], filterCo
|
|
|
183
212
|
]);
|
|
184
213
|
const handleInputFocus = useCallback(() => {
|
|
185
214
|
if (showOnFocus && !shouldShowList) {
|
|
215
|
+
// Update filtered options when opening
|
|
216
|
+
const filtered = filterOptions(searchValue);
|
|
217
|
+
setFilteredOptions(filtered);
|
|
186
218
|
setShouldShowList(true);
|
|
187
219
|
if (onOpen) {
|
|
188
220
|
onOpen();
|
|
189
221
|
}
|
|
190
222
|
}
|
|
191
|
-
}, [showOnFocus, shouldShowList, onOpen]);
|
|
223
|
+
}, [showOnFocus, shouldShowList, onOpen, filterOptions, searchValue]);
|
|
192
224
|
const handleInputClick = useCallback(() => {
|
|
193
225
|
if (showOnClick && !shouldShowList) {
|
|
226
|
+
// Update filtered options when opening
|
|
227
|
+
const filtered = filterOptions(searchValue);
|
|
228
|
+
setFilteredOptions(filtered);
|
|
229
|
+
setShouldShowList(true);
|
|
230
|
+
if (onOpen) {
|
|
231
|
+
onOpen();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}, [showOnClick, shouldShowList, onOpen, filterOptions, searchValue]);
|
|
235
|
+
const handleIconClick = useCallback(() => {
|
|
236
|
+
if (disabled)
|
|
237
|
+
return;
|
|
238
|
+
if (shouldShowList) {
|
|
239
|
+
// Close dropdown
|
|
240
|
+
setShouldShowList(false);
|
|
241
|
+
if (onClose) {
|
|
242
|
+
onClose();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
// Open dropdown
|
|
247
|
+
const filtered = filterOptions(searchValue);
|
|
248
|
+
setFilteredOptions(filtered);
|
|
194
249
|
setShouldShowList(true);
|
|
250
|
+
// Focus input when opening via icon
|
|
251
|
+
inputRef.current?.focus();
|
|
195
252
|
if (onOpen) {
|
|
196
253
|
onOpen();
|
|
197
254
|
}
|
|
198
255
|
}
|
|
199
|
-
}, [
|
|
256
|
+
}, [disabled, shouldShowList, onOpen, onClose, filterOptions, searchValue]);
|
|
200
257
|
const renderList = () => {
|
|
201
258
|
if (!shouldShowList)
|
|
202
259
|
return null;
|
|
203
|
-
return (_jsxs("div", { className: cn(s['absolute'], s['w-full'], s['mt-1'], s['rounded-lg'], s['bg-white'], s['border'], s['border-gray-200'], s['shadow-lg'], s['overflow-hidden'], '
|
|
260
|
+
return (_jsxs("div", { className: cn(s['absolute'], s['w-full'], s['mt-1'], s['rounded-lg'], s['bg-white'], s['border'], s['border-gray-200'], s['shadow-lg'], s['overflow-hidden'], s['left-0']), style: {
|
|
261
|
+
position: 'absolute',
|
|
262
|
+
top: '100%',
|
|
263
|
+
left: 0,
|
|
264
|
+
right: 0,
|
|
204
265
|
zIndex,
|
|
205
266
|
animation: 'fadeIn 0.15s ease-out',
|
|
206
267
|
transformOrigin: 'top',
|
|
@@ -220,30 +281,63 @@ export const Autocomplete = ({ value = '', onValueChange, options = [], filterCo
|
|
|
220
281
|
scrollbarWidth: 'thin',
|
|
221
282
|
}, children: filteredOptions.map((option, index) => {
|
|
222
283
|
const isActive = highlightActive && index === activeOption;
|
|
223
|
-
let itemClassName = cn(s['flex'], s['items-center'], s['px-4'], s['py-3'], s['cursor-pointer'], s['text-sm'], s['transition-all'], s['duration-150'], s['ease-in-out'], optionClassName
|
|
284
|
+
let itemClassName = cn(s['flex'], s['items-center'], s['px-4'], s['py-3'], s['cursor-pointer'], s['text-sm'], s['transition-all'], s['duration-150'], s['ease-in-out'], optionClassName);
|
|
224
285
|
if (isActive && highlightActive) {
|
|
225
|
-
itemClassName = cn(itemClassName, s['bg-blue-50'], s['text-blue-700'], s['font-medium'],
|
|
286
|
+
itemClassName = cn(itemClassName, s['bg-blue-50'], s['text-blue-700'], s['font-medium'], activeOptionClassName);
|
|
226
287
|
}
|
|
227
288
|
return (_jsx("li", { className: itemClassName, role: "option", "aria-selected": isActive, id: `autocomplete-option-${index}`, "data-index": index, onClick: onOptionClick, onMouseEnter: () => setActiveOption(index), style: {
|
|
228
|
-
transition: 'background-color 0.15s ease, color 0.15s ease
|
|
229
|
-
|
|
289
|
+
transition: 'background-color 0.15s ease, color 0.15s ease',
|
|
290
|
+
backgroundColor: isActive && highlightActive
|
|
291
|
+
? 'rgb(239, 246, 255)'
|
|
292
|
+
: 'transparent',
|
|
293
|
+
color: isActive && highlightActive
|
|
294
|
+
? 'rgb(29, 78, 216)'
|
|
295
|
+
: 'rgb(55, 65, 81)',
|
|
296
|
+
}, onMouseOver: (e) => {
|
|
297
|
+
if (!isActive) {
|
|
298
|
+
e.currentTarget.style.backgroundColor =
|
|
299
|
+
'rgb(239, 246, 255)';
|
|
300
|
+
e.currentTarget.style.color = 'rgb(29, 78, 216)';
|
|
301
|
+
}
|
|
302
|
+
}, onMouseOut: (e) => {
|
|
303
|
+
if (!isActive) {
|
|
304
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
305
|
+
e.currentTarget.style.color = 'rgb(55, 65, 81)';
|
|
306
|
+
}
|
|
307
|
+
}, children: renderOption ? (renderOption(option, index, isActive)) : (_jsx("span", { className: cn(s['select-none']), children: getOptionLabel(option) })) }, index));
|
|
230
308
|
}) })) : (_jsx("div", { className: cn(s['flex'], s['flex-col'], s['items-center'], s['justify-center'], s['py-8'], s['px-4'], s['text-center']), children: renderEmptyState ? (renderEmptyState()) : (_jsxs(_Fragment, { children: [_jsx(Icon, { nameIcon: "FaSearch", propsIcon: {
|
|
231
309
|
size: 32,
|
|
232
310
|
color: '#9ca3af',
|
|
233
311
|
} }), _jsx("p", { className: cn(s['mt-3'], s['text-sm'], s['font-medium'], s['text-gray-500']), children: emptyStateMessage }), _jsx("p", { className: cn(s['mt-1'], s['text-xs'], s['text-gray-400']), children: "Try adjusting your search" })] })) }))] }));
|
|
234
312
|
};
|
|
235
|
-
// Update filtered options when options
|
|
313
|
+
// Update filtered options when options or search value changes
|
|
236
314
|
useEffect(() => {
|
|
237
315
|
const filtered = filterOptions(searchValue);
|
|
238
316
|
setFilteredOptions(filtered);
|
|
239
|
-
// Update active option if current value is
|
|
317
|
+
// Update active option if current value is in filtered options
|
|
240
318
|
if (filtered.length > 0) {
|
|
241
319
|
const currentIndex = filtered.findIndex((opt) => getOptionValue(opt) === value || getOptionLabel(opt) === value);
|
|
242
|
-
if (currentIndex !== -1
|
|
320
|
+
if (currentIndex !== -1) {
|
|
243
321
|
setActiveOption(currentIndex);
|
|
244
322
|
}
|
|
323
|
+
else if (activeOption >= filtered.length) {
|
|
324
|
+
// Reset to first option if current active is out of bounds
|
|
325
|
+
setActiveOption(0);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
else if (filtered.length === 0 && searchValue.length === 0) {
|
|
329
|
+
// If no search and no filtered results, reset active option
|
|
330
|
+
setActiveOption(0);
|
|
245
331
|
}
|
|
246
|
-
}, [
|
|
332
|
+
}, [
|
|
333
|
+
options,
|
|
334
|
+
searchValue,
|
|
335
|
+
filterOptions,
|
|
336
|
+
value,
|
|
337
|
+
activeOption,
|
|
338
|
+
getOptionValue,
|
|
339
|
+
getOptionLabel,
|
|
340
|
+
]);
|
|
247
341
|
// Auto-focus and auto-select first option on mount
|
|
248
342
|
useEffect(() => {
|
|
249
343
|
if (autoFocus) {
|
|
@@ -256,41 +350,86 @@ export const Autocomplete = ({ value = '', onValueChange, options = [], filterCo
|
|
|
256
350
|
onValueChange(filteredOptions[0]);
|
|
257
351
|
}
|
|
258
352
|
}, [autoFocus, autoSelectFirst, filteredOptions, value, onValueChange]);
|
|
259
|
-
// Update search value when value prop changes
|
|
353
|
+
// Update search value when value prop changes (but not when user is actively typing)
|
|
260
354
|
useEffect(() => {
|
|
355
|
+
// Don't sync if user is currently typing
|
|
356
|
+
if (isTypingRef.current) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
// Only sync if value prop changed and doesn't match current search
|
|
261
360
|
if (value !== searchValue) {
|
|
262
361
|
const matchingOption = options.find((opt) => getOptionValue(opt) === value || getOptionLabel(opt) === value);
|
|
263
362
|
if (matchingOption) {
|
|
264
363
|
setSearchValue(getOptionLabel(matchingOption));
|
|
265
364
|
}
|
|
266
|
-
else {
|
|
365
|
+
else if (value) {
|
|
267
366
|
setSearchValue(value);
|
|
268
367
|
}
|
|
269
368
|
}
|
|
270
|
-
}, [value, options, searchValue]);
|
|
271
|
-
|
|
369
|
+
}, [value, options, searchValue, getOptionValue, getOptionLabel]);
|
|
370
|
+
// Handle click outside to close dropdown
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
function handleClickOutside(event) {
|
|
373
|
+
if (wrapperRef.current &&
|
|
374
|
+
!wrapperRef.current.contains(event.target) &&
|
|
375
|
+
shouldShowList) {
|
|
376
|
+
setShouldShowList(false);
|
|
377
|
+
if (onClose) {
|
|
378
|
+
onClose();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (shouldShowList) {
|
|
383
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
384
|
+
}
|
|
385
|
+
return () => {
|
|
386
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
387
|
+
};
|
|
388
|
+
}, [shouldShowList, onClose]);
|
|
389
|
+
// Cleanup typing timeout on unmount
|
|
390
|
+
useEffect(() => {
|
|
391
|
+
return () => {
|
|
392
|
+
if (typingTimeoutRef.current) {
|
|
393
|
+
clearTimeout(typingTimeoutRef.current);
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
}, []);
|
|
397
|
+
return (_jsxs("div", { ref: wrapperRef, className: cn(s['flex'], s['flex-col'], s['relative'], s['w-full'], className), style: style, children: [_jsx("div", { className: cn(s['flex'], s['items-center'], s['relative'], s['w-full'], s['bg-white'], s['border'], s['rounded-lg'], s['shadow-sm'], s['transition-all'], s['duration-200'], s['ease-in-out'], s['overflow-hidden'], {
|
|
272
398
|
[s['border-red-500']]: hasError,
|
|
273
399
|
[s['border-gray-300']]: !hasError && !shouldShowList,
|
|
274
|
-
'border-blue-500': !hasError && shouldShowList,
|
|
275
|
-
'ring-2': !hasError && shouldShowList,
|
|
276
|
-
'ring-blue-200': !hasError && shouldShowList,
|
|
400
|
+
[s['border-blue-500']]: !hasError && shouldShowList,
|
|
401
|
+
[s['ring-2']]: !hasError && shouldShowList,
|
|
402
|
+
[s['ring-blue-200']]: !hasError && shouldShowList,
|
|
277
403
|
[s['opacity-50']]: disabled,
|
|
278
404
|
[s['cursor-not-allowed']]: disabled,
|
|
279
|
-
'hover:border-gray-400': !hasError && !disabled && !shouldShowList,
|
|
280
405
|
}), style: {
|
|
281
406
|
boxShadow: shouldShowList && !hasError
|
|
282
407
|
? '0 0 0 3px rgba(59, 130, 246, 0.1)'
|
|
283
408
|
: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
284
|
-
|
|
409
|
+
overflow: 'hidden',
|
|
410
|
+
}, children: _jsxs("div", { className: cn(s['flex'], s['items-center'], s['w-full'], s['relative']), style: {
|
|
411
|
+
padding: '0.5rem 0.75rem',
|
|
412
|
+
minWidth: 0,
|
|
413
|
+
}, children: [_jsx("div", { className: cn(s['mr-2'], s['flex-shrink-0']), style: { display: 'flex', alignItems: 'center' }, children: _jsx(Icon, { nameIcon: "FaSearch", propsIcon: {
|
|
285
414
|
size: 18,
|
|
286
415
|
color: shouldShowList ? '#3b82f6' : '#9ca3af',
|
|
287
416
|
} }) }), _jsx("input", { type: "text", role: "combobox", "aria-autocomplete": "list", "aria-expanded": shouldShowList, "aria-controls": "autocomplete-list", "aria-activedescendant": shouldShowList && activeOption >= 0
|
|
288
417
|
? `autocomplete-option-${activeOption}`
|
|
289
|
-
: undefined, name: name || 'autocomplete-input', className: cn(s['flex
|
|
418
|
+
: undefined, name: name || 'autocomplete-input', className: cn(s['flex-1'], s['bg-transparent'], s['text-sm'], s['text-gray-700'], s['placeholder-gray-400'], s['focus:outline-none'], s['border-none'], s['focus:ring-0'], inputClassName), placeholder: placeholder, onChange: onInputChange, onKeyDown: onKeyDown, onFocus: handleInputFocus, onClick: handleInputClick, value: searchValue, ref: inputRef, disabled: disabled, autoComplete: "off", style: {
|
|
290
419
|
cursor: disabled ? 'not-allowed' : 'text',
|
|
291
|
-
|
|
420
|
+
minWidth: 0,
|
|
421
|
+
flex: '1 1 0%',
|
|
422
|
+
width: 0,
|
|
423
|
+
} }), _jsx("div", { className: cn(s['flex-shrink-0'], s['flex'], s['items-center'], s['justify-center'], s['cursor-pointer']), onClick: handleIconClick, style: {
|
|
424
|
+
marginLeft: '0.5rem',
|
|
425
|
+
transition: 'transform 0.2s ease',
|
|
426
|
+
display: 'flex',
|
|
427
|
+
alignItems: 'center',
|
|
428
|
+
justifyContent: 'center',
|
|
429
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
430
|
+
}, children: shouldShowList ? (_jsx(Icon, { nameIcon: "FaChevronUp", propsIcon: {
|
|
292
431
|
size: 16,
|
|
293
|
-
color: '#3b82f6',
|
|
432
|
+
color: disabled ? '#9ca3af' : '#3b82f6',
|
|
294
433
|
} })) : (_jsx(Icon, { nameIcon: "FaChevronDown", propsIcon: {
|
|
295
434
|
size: 16,
|
|
296
435
|
color: '#9ca3af',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StateLayer.d.ts","sourceRoot":"","sources":["../../../../../src/core-components/src/core-components/StateLayer.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"StateLayer.d.ts","sourceRoot":"","sources":["../../../../../src/core-components/src/core-components/StateLayer.ts"],"names":[],"mappings":";AAGA,eAAO,MAAM,UAAU,6NAUtB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { styled } from 'styled-components';
|
|
2
|
+
import { tokens } from '../utils/designTokens';
|
|
2
3
|
export const StateLayer = styled.div `
|
|
3
4
|
position: absolute;
|
|
4
5
|
top: 0;
|
|
@@ -6,7 +7,7 @@ export const StateLayer = styled.div `
|
|
|
6
7
|
bottom: 0;
|
|
7
8
|
left: 0;
|
|
8
9
|
pointer-events: none;
|
|
9
|
-
z-index:
|
|
10
|
+
z-index: 0;
|
|
10
11
|
background: currentColor;
|
|
11
|
-
opacity:
|
|
12
|
+
opacity: ${tokens.stateLayerNone};
|
|
12
13
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core-components/src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core-components/src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,aAAa,CAAC"}
|