@stokr/components-library 4.2.3 → 4.2.5
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/components/AddressItem/AddressItem.d.ts +38 -0
- package/dist/components/AddressItem/AddressItem.js +51 -0
- package/dist/components/AddressItem/AddressItem.styles.d.ts +31 -0
- package/dist/components/AddressItem/AddressItem.styles.js +73 -0
- package/dist/components/Checkbox/Checkbox.styles.d.ts +1 -0
- package/dist/components/Collapsible/Collapsible.d.ts +10 -4
- package/dist/components/Collapsible/Collapsible.js +6 -14
- package/dist/components/Collapsible/Collapsible.styles.d.ts +3 -1
- package/dist/components/Collapsible/Collapsible.styles.js +23 -9
- package/dist/components/Country/CountrySelect.js +9 -14
- package/dist/components/Country/FlagFor.d.ts +9 -0
- package/dist/components/Country/FlagFor.js +25 -0
- package/dist/components/Country/flagLoaders.d.ts +5 -0
- package/dist/components/Country/flagLoaders.js +270 -0
- package/dist/components/Country/flagStore.d.ts +6 -0
- package/dist/components/Country/flagStore.js +29 -0
- package/dist/components/FAQ/FAQ.d.ts +29 -0
- package/dist/components/FAQ/FAQ.js +18 -18
- package/dist/components/FAQ/FAQ.styles.d.ts +38 -0
- package/dist/components/FAQ/FAQ.styles.js +58 -1
- package/dist/components/IdentityInfo/IdentityInfo.js +2 -1
- package/dist/components/IdentityInfo/IdentityInfo.styles.js +3 -1
- package/dist/components/InfoBox/InfoBox.js +44 -20
- package/dist/components/Input/Input.d.ts +3 -0
- package/dist/components/Input/Input.js +5 -2
- package/dist/components/Input/Input.styles.d.ts +4 -0
- package/dist/components/Input/Input.styles.js +57 -0
- package/dist/components/Input/Select.d.ts +57 -0
- package/dist/components/Input/Select.js +77 -98
- package/dist/components/Input/Select.styles.d.ts +89 -0
- package/dist/components/Input/Select.styles.js +104 -2
- package/dist/components/MaterialIcon/requiredIcons.d.ts +1 -1
- package/dist/components/MaterialIcon/requiredIcons.js +2 -0
- package/dist/components/PanelCard/PanelCard.d.ts +51 -0
- package/dist/components/PanelCard/PanelCard.js +35 -0
- package/dist/components/PanelCard/PanelCard.styles.d.ts +29 -0
- package/dist/components/PanelCard/PanelCard.styles.js +87 -0
- package/dist/components/StepSidebar/MobileStepProgress.d.ts +12 -0
- package/dist/components/StepSidebar/MobileStepProgress.js +14 -0
- package/dist/components/StepSidebar/MobileStepProgress.styles.d.ts +15 -0
- package/dist/components/StepSidebar/MobileStepProgress.styles.js +42 -0
- package/dist/components/StepSidebar/StepProgress.d.ts +14 -0
- package/dist/components/StepSidebar/StepProgress.js +14 -0
- package/dist/components/StepSidebar/StepProgress.styles.d.ts +30 -0
- package/dist/components/StepSidebar/StepProgress.styles.js +103 -0
- package/dist/components/StepSidebar/StepSidebar.d.ts +36 -0
- package/dist/components/StepSidebar/StepSidebar.js +58 -0
- package/dist/components/StepSidebar/StepSidebar.styles.d.ts +54 -0
- package/dist/components/StepSidebar/StepSidebar.styles.js +175 -0
- package/dist/components/TaxResidenceCard/TaxResidenceCard.js +27 -11
- package/dist/components/TaxResidenceCard/TaxResidenceCard.styles.js +88 -7
- package/dist/index.d.ts +64 -7
- package/dist/index.js +17 -3
- package/dist/styles/borderedField.d.ts +11 -0
- package/dist/styles/borderedField.js +56 -0
- package/package.json +1 -1
- package/dist/static/images/globe.svg.js +0 -5
- package/dist/static/images/trash.svg +0 -17
- package/dist/static/images/trash.svg.js +0 -5
|
@@ -2,43 +2,53 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import "react";
|
|
3
3
|
import styled from "styled-components";
|
|
4
4
|
import { colors } from "../../styles/colors.js";
|
|
5
|
+
import { typography } from "../../styles/typography.js";
|
|
5
6
|
import { glyph } from "../MaterialIcon/glyph.js";
|
|
7
|
+
import { MaterialIcon } from "../MaterialIcon/MaterialIcon.js";
|
|
8
|
+
const BANNER = { padding: "12px 20px 12px 16px", gap: "12px", align: "center", leftBorder: true };
|
|
6
9
|
const VARIANTS = {
|
|
7
10
|
warning: {
|
|
11
|
+
...BANNER,
|
|
8
12
|
background: "#FFFBEB",
|
|
9
13
|
border: colors.warningYellow,
|
|
10
14
|
iconColor: colors.warningYellow
|
|
11
15
|
},
|
|
12
16
|
info: {
|
|
17
|
+
...BANNER,
|
|
13
18
|
background: "#F8FAFC",
|
|
14
19
|
border: colors.blueDark,
|
|
15
|
-
// border: `${colors.blueDark}80`, // 128 (100% opacity in hex): 50% opacity
|
|
16
20
|
iconColor: colors.blueDark
|
|
17
21
|
},
|
|
18
22
|
error: {
|
|
23
|
+
...BANNER,
|
|
19
24
|
background: "#FDEDEC",
|
|
20
25
|
border: colors.darkRed,
|
|
21
26
|
iconColor: colors.darkRed
|
|
27
|
+
},
|
|
28
|
+
/** Figma "InfoBox" done state: green surface, bold check, no left border, top-aligned. */
|
|
29
|
+
success: {
|
|
30
|
+
padding: "12px",
|
|
31
|
+
gap: "8px",
|
|
32
|
+
align: "flex-start",
|
|
33
|
+
leftBorder: false,
|
|
34
|
+
background: colors.successSurface,
|
|
35
|
+
border: colors.freshGreen,
|
|
36
|
+
iconColor: colors.freshGreen
|
|
22
37
|
}
|
|
23
38
|
};
|
|
24
39
|
const Container = styled.div`
|
|
25
40
|
position: relative;
|
|
26
41
|
display: flex;
|
|
27
42
|
overflow: hidden;
|
|
28
|
-
align-items:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
border-radius: 8px;
|
|
35
|
-
font-size: 12px;
|
|
36
|
-
line-height: 18px;
|
|
37
|
-
letter-spacing: 0.6px;
|
|
38
|
-
font-weight: 400;
|
|
43
|
+
align-items: ${(props) => props.$align};
|
|
44
|
+
gap: var(--info-box-gap, ${(props) => props.$gap});
|
|
45
|
+
padding: var(--info-box-padding, ${(props) => props.$padding});
|
|
46
|
+
background: var(--info-box-background, ${(props) => props.$bg});
|
|
47
|
+
border-radius: var(--info-box-radius, 8px);
|
|
48
|
+
${typography.formInput};
|
|
39
49
|
color: ${colors.black};
|
|
40
50
|
|
|
41
|
-
${(props) =>
|
|
51
|
+
${(props) => props.$leftBorder && `
|
|
42
52
|
&:before {
|
|
43
53
|
content: '';
|
|
44
54
|
display: block;
|
|
@@ -60,6 +70,11 @@ const DefaultIcon = styled.span.attrs({
|
|
|
60
70
|
color: ${(props) => props.$color};
|
|
61
71
|
margin-top: 1px;
|
|
62
72
|
`;
|
|
73
|
+
const SuccessIcon = styled.span`
|
|
74
|
+
display: inline-flex;
|
|
75
|
+
flex-shrink: 0;
|
|
76
|
+
color: var(--info-box-icon-color, ${colors.freshGreen});
|
|
77
|
+
`;
|
|
63
78
|
const CustomIconWrapper = styled.span`
|
|
64
79
|
flex-shrink: 0;
|
|
65
80
|
display: flex;
|
|
@@ -71,25 +86,34 @@ const Content = styled.div`
|
|
|
71
86
|
flex: 1;
|
|
72
87
|
min-width: 0;
|
|
73
88
|
`;
|
|
74
|
-
const
|
|
89
|
+
const Title = styled.div`
|
|
90
|
+
${typography.formInputMain};
|
|
91
|
+
`;
|
|
92
|
+
const InfoBox = ({ variant = "warning", title, children, icon, noLeftBorder, ...rest }) => {
|
|
75
93
|
const theme = VARIANTS[variant] || VARIANTS.warning;
|
|
76
94
|
const renderIcon = () => {
|
|
77
|
-
if (icon) {
|
|
78
|
-
|
|
95
|
+
if (icon) return /* @__PURE__ */ jsx(CustomIconWrapper, { children: icon });
|
|
96
|
+
if (variant === "success") {
|
|
97
|
+
return /* @__PURE__ */ jsx(SuccessIcon, { children: /* @__PURE__ */ jsx(MaterialIcon, { name: "check", weight: 600, size: 20 }) });
|
|
79
98
|
}
|
|
80
99
|
return /* @__PURE__ */ jsx(DefaultIcon, { $color: theme.iconColor });
|
|
81
100
|
};
|
|
82
101
|
return /* @__PURE__ */ jsxs(
|
|
83
102
|
Container,
|
|
84
103
|
{
|
|
104
|
+
...rest,
|
|
85
105
|
$bg: theme.background,
|
|
86
|
-
$noLeftBorder: noLeftBorder,
|
|
87
106
|
$border: theme.border,
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
$padding: theme.padding,
|
|
108
|
+
$gap: theme.gap,
|
|
109
|
+
$align: theme.align,
|
|
110
|
+
$leftBorder: theme.leftBorder && !noLeftBorder,
|
|
90
111
|
children: [
|
|
91
112
|
renderIcon(),
|
|
92
|
-
/* @__PURE__ */
|
|
113
|
+
/* @__PURE__ */ jsxs(Content, { children: [
|
|
114
|
+
title != null && /* @__PURE__ */ jsx(Title, { children: title }),
|
|
115
|
+
children
|
|
116
|
+
] })
|
|
93
117
|
]
|
|
94
118
|
}
|
|
95
119
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CSSProperties, InputHTMLAttributes } from 'react';
|
|
2
2
|
import { Wrapper, Label, InputWrap } from './Input.styles';
|
|
3
|
+
import { FieldVariant } from '../../styles/borderedField';
|
|
3
4
|
export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'value'> {
|
|
4
5
|
id: string;
|
|
5
6
|
name?: string;
|
|
@@ -17,6 +18,8 @@ export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>,
|
|
|
17
18
|
autoHeightLabel?: boolean;
|
|
18
19
|
inputWrapStyle?: CSSProperties;
|
|
19
20
|
wrapperStyle?: CSSProperties;
|
|
21
|
+
/** `bordered`: boxed field with a static label above (sign-up redesign). Default keeps the floating-label look. */
|
|
22
|
+
variant?: FieldVariant;
|
|
20
23
|
}
|
|
21
24
|
/** Text input with a floating label, built for Formik (`onChange`/`onBlur` receive the event). */
|
|
22
25
|
declare const Input: (props: InputProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -18,6 +18,7 @@ const Input = (props) => {
|
|
|
18
18
|
inputWrapStyle,
|
|
19
19
|
wrapperStyle,
|
|
20
20
|
autoHeightLabel,
|
|
21
|
+
variant = "default",
|
|
21
22
|
// Destructure these so they don't get spread to the input
|
|
22
23
|
onChange: onChangeProp,
|
|
23
24
|
onBlur: onBlurProp,
|
|
@@ -49,7 +50,7 @@ const Input = (props) => {
|
|
|
49
50
|
onFocusProp?.(e);
|
|
50
51
|
checkLabel(true);
|
|
51
52
|
};
|
|
52
|
-
return /* @__PURE__ */ jsxs(Wrapper, { inverted, style: wrapperStyle, children: [
|
|
53
|
+
return /* @__PURE__ */ jsxs(Wrapper, { inverted, style: wrapperStyle, $variant: variant, children: [
|
|
53
54
|
label && /* @__PURE__ */ jsx(
|
|
54
55
|
Label,
|
|
55
56
|
{
|
|
@@ -58,6 +59,7 @@ const Input = (props) => {
|
|
|
58
59
|
error: Boolean(error && touched),
|
|
59
60
|
htmlFor: id,
|
|
60
61
|
autoHeightLabel,
|
|
62
|
+
$variant: variant,
|
|
61
63
|
children: label
|
|
62
64
|
}
|
|
63
65
|
),
|
|
@@ -69,6 +71,7 @@ const Input = (props) => {
|
|
|
69
71
|
disabled,
|
|
70
72
|
style: inputWrapStyle,
|
|
71
73
|
autoHeightLabel,
|
|
74
|
+
$variant: variant,
|
|
72
75
|
children: /* @__PURE__ */ jsx(
|
|
73
76
|
"input",
|
|
74
77
|
{
|
|
@@ -82,7 +85,7 @@ const Input = (props) => {
|
|
|
82
85
|
readOnly,
|
|
83
86
|
placeholder,
|
|
84
87
|
disabled,
|
|
85
|
-
style: { WebkitAppearance: "none", WebkitBorderRadius: 0 },
|
|
88
|
+
style: variant === "bordered" ? { WebkitAppearance: "none" } : { WebkitAppearance: "none", WebkitBorderRadius: 0 },
|
|
86
89
|
...restProps
|
|
87
90
|
}
|
|
88
91
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FieldVariant } from '../../styles/borderedField';
|
|
1
2
|
export declare const Label: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>, "style"> & {
|
|
2
3
|
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
3
4
|
}, {
|
|
@@ -5,6 +6,7 @@ export declare const Label: import('styled-components/dist/types').IStyledCompon
|
|
|
5
6
|
isUp?: boolean;
|
|
6
7
|
active?: boolean;
|
|
7
8
|
error?: boolean;
|
|
9
|
+
$variant?: FieldVariant;
|
|
8
10
|
}>> & string;
|
|
9
11
|
export declare const InputWrap: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
10
12
|
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
@@ -13,9 +15,11 @@ export declare const InputWrap: import('styled-components/dist/types').IStyledCo
|
|
|
13
15
|
disabled?: boolean;
|
|
14
16
|
dashboard?: boolean;
|
|
15
17
|
error?: boolean;
|
|
18
|
+
$variant?: FieldVariant;
|
|
16
19
|
}>> & string;
|
|
17
20
|
export declare const Wrapper: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Merged<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style"> & {
|
|
18
21
|
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
19
22
|
}, {
|
|
20
23
|
inverted?: boolean;
|
|
24
|
+
$variant?: FieldVariant;
|
|
21
25
|
}>> & string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import styled, { css } from "styled-components";
|
|
2
2
|
import theme from "../../styles/theme.js";
|
|
3
|
+
import { borderedFieldLabel, borderedFieldBox, borderedFieldText, borderedFieldPlaceholder, borderedFieldFocus, borderedFieldError, borderedFieldDisabled, BORDERED_BORDER } from "../../styles/borderedField.js";
|
|
4
|
+
import { radius } from "../../styles/spacing.js";
|
|
3
5
|
const Label = styled.label.withConfig({
|
|
4
6
|
shouldForwardProp: (props) => !["autoHeightLabel", "isUp", "active", "error"].includes(props)
|
|
5
7
|
})`
|
|
@@ -38,6 +40,18 @@ const Label = styled.label.withConfig({
|
|
|
38
40
|
${(props) => props.error && `
|
|
39
41
|
color: ${theme.cWarning};
|
|
40
42
|
`}
|
|
43
|
+
|
|
44
|
+
${(props) => props.$variant === "bordered" && css`
|
|
45
|
+
position: static;
|
|
46
|
+
z-index: auto;
|
|
47
|
+
top: auto;
|
|
48
|
+
left: auto;
|
|
49
|
+
height: auto;
|
|
50
|
+
transform: none;
|
|
51
|
+
pointer-events: auto;
|
|
52
|
+
${borderedFieldLabel}
|
|
53
|
+
color: ${props.error ? theme.cWarning : theme.cBlack};
|
|
54
|
+
`}
|
|
41
55
|
`;
|
|
42
56
|
const InputWrap = styled.div.withConfig({
|
|
43
57
|
shouldForwardProp: (props) => !["autoHeightLabel", "disabled", "dashboard", "error"].includes(props)
|
|
@@ -115,6 +129,42 @@ const InputWrap = styled.div.withConfig({
|
|
|
115
129
|
${(props) => props.error && `
|
|
116
130
|
color: ${theme.cWarning};
|
|
117
131
|
`}
|
|
132
|
+
|
|
133
|
+
${(props) => props.$variant === "bordered" && css`
|
|
134
|
+
& > input {
|
|
135
|
+
${borderedFieldBox}
|
|
136
|
+
${borderedFieldText}
|
|
137
|
+
height: 44px;
|
|
138
|
+
|
|
139
|
+
&::placeholder {
|
|
140
|
+
${borderedFieldPlaceholder}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
&:hover {
|
|
144
|
+
border-color: ${theme.cLightGrey};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
&:focus {
|
|
148
|
+
${borderedFieldFocus}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
${props.error && css`
|
|
152
|
+
&,
|
|
153
|
+
&:hover,
|
|
154
|
+
&:focus {
|
|
155
|
+
${borderedFieldError}
|
|
156
|
+
}
|
|
157
|
+
`}
|
|
158
|
+
|
|
159
|
+
${props.disabled && css`
|
|
160
|
+
&,
|
|
161
|
+
&:hover,
|
|
162
|
+
&:focus {
|
|
163
|
+
${borderedFieldDisabled}
|
|
164
|
+
}
|
|
165
|
+
`}
|
|
166
|
+
}
|
|
167
|
+
`}
|
|
118
168
|
`;
|
|
119
169
|
const Wrapper = styled.div.withConfig({
|
|
120
170
|
shouldForwardProp: (props) => !["inverted"].includes(props)
|
|
@@ -146,6 +196,13 @@ const Wrapper = styled.div.withConfig({
|
|
|
146
196
|
}
|
|
147
197
|
}
|
|
148
198
|
`}
|
|
199
|
+
|
|
200
|
+
${(props) => props.$variant === "bordered" && css`
|
|
201
|
+
input:-webkit-autofill {
|
|
202
|
+
border: ${BORDERED_BORDER};
|
|
203
|
+
border-radius: ${radius.lg};
|
|
204
|
+
}
|
|
205
|
+
`}
|
|
149
206
|
`;
|
|
150
207
|
export {
|
|
151
208
|
InputWrap,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { GroupBase, Props as ReactSelectProps } from 'react-select';
|
|
3
|
+
import { FieldVariant } from '../../styles/borderedField';
|
|
4
|
+
import { SelectIcon, SelectMenu, SelectOption, SelectControl, SelectWrapper, SelectMenuList, SelectContainer, SelectValueContainer } from './Select.styles';
|
|
5
|
+
export type SelectValue = string | number;
|
|
6
|
+
export interface SelectOptionItem {
|
|
7
|
+
key?: string;
|
|
8
|
+
value: SelectValue;
|
|
9
|
+
label: ReactNode;
|
|
10
|
+
/** URL string (rendered as <img>) or a React node (e.g. an SVG flag) shown left of the label. */
|
|
11
|
+
icon?: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/** What `onChange` / `onBlur` / `onFocus` receive. `value` is the option value, or an array of values in `multiple` mode. */
|
|
14
|
+
export interface SelectChange {
|
|
15
|
+
name: string;
|
|
16
|
+
value: any;
|
|
17
|
+
}
|
|
18
|
+
type PassthroughProps = ReactSelectProps<any, boolean, GroupBase<any>>;
|
|
19
|
+
type OwnPropKeys = 'id' | 'name' | 'value' | 'options' | 'placeholder' | 'onChange' | 'onBlur' | 'onFocus' | 'formatCreateLabel' | 'dataCy' | 'variant';
|
|
20
|
+
export interface SelectProps extends Omit<PassthroughProps, OwnPropKeys> {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
label?: string;
|
|
24
|
+
/** string|number for single mode, array for multi mode. */
|
|
25
|
+
value?: SelectValue | readonly SelectValue[];
|
|
26
|
+
options: readonly SelectOptionItem[];
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/** Shown as an error state once `touched` is true. */
|
|
29
|
+
error?: boolean;
|
|
30
|
+
touched?: boolean;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** Lets the user type to filter the options. */
|
|
33
|
+
search?: boolean;
|
|
34
|
+
/** Lets the user add a value that is not in `options`. */
|
|
35
|
+
creatable?: boolean;
|
|
36
|
+
/** Multi-select: checkbox options + chips list rendered below the field. */
|
|
37
|
+
multiple?: boolean;
|
|
38
|
+
/** Multi mode: values that cannot be removed (chip ✕ disabled, can't be deselected). */
|
|
39
|
+
lockedValues?: readonly SelectValue[];
|
|
40
|
+
/** Max menu height in px. */
|
|
41
|
+
menuHeight?: number;
|
|
42
|
+
/** Heading shown above the chips list in multi mode (default: "Selected"). */
|
|
43
|
+
selectedLabel?: string;
|
|
44
|
+
/** Input-like floating label behavior: label starts in-field, moves up on focus/value. Ignored when `bordered`. */
|
|
45
|
+
floatingLabel?: boolean;
|
|
46
|
+
formatCreateLabel?: (input: string) => ReactNode;
|
|
47
|
+
onChange?(field: SelectChange): void;
|
|
48
|
+
onBlur?(field: SelectChange): void;
|
|
49
|
+
onFocus?(field: SelectChange): void;
|
|
50
|
+
/** Playwright / autocapture: `data-cy` selector on the react-select control. */
|
|
51
|
+
dataCy?: string;
|
|
52
|
+
/** `bordered`: boxed control with a static label above (sign-up redesign). Default keeps the underline look. */
|
|
53
|
+
variant?: FieldVariant;
|
|
54
|
+
}
|
|
55
|
+
/** Dropdown with a floating label on react-select: single, searchable, multiple (checkboxes + chips) or creatable. */
|
|
56
|
+
declare const Select: (props: SelectProps) => import("react/jsx-runtime").JSX.Element;
|
|
57
|
+
export { Select, SelectControl, SelectMenu, SelectMenuList, SelectOption, SelectContainer, SelectValueContainer, SelectIcon, SelectWrapper, };
|
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { useState, useMemo } from "react";
|
|
3
3
|
import { Wrapper, Label } from "./Input.styles.js";
|
|
4
|
+
import { MaterialIcon } from "../MaterialIcon/MaterialIcon.js";
|
|
4
5
|
import { OptionCheckbox } from "../Checkbox/OptionCheckbox.js";
|
|
5
|
-
import { useState, useMemo } from "react";
|
|
6
6
|
import CreatableSelect from "react-select/creatable";
|
|
7
7
|
import ReactSelect, { components } from "react-select";
|
|
8
|
-
import {
|
|
8
|
+
import { colors } from "../../styles/colors.js";
|
|
9
|
+
import { BORDERED_BORDER } from "../../styles/borderedField.js";
|
|
10
|
+
import { radius } from "../../styles/spacing.js";
|
|
11
|
+
import { borderedControlCss, SelectMenu, SelectedChipsWrapper, SelectedChipsTitle, SelectedChipsList, SelectedChip, SelectedChipLabel, SelectedChipRemove, SelectOption, OptionRow, OptionLabel, SelectMenuList, SelectIcon, SelectContainer, SelectControl, OptionIcon } from "./Select.styles.js";
|
|
9
12
|
import { SelectValueContainer, SelectWrapper } from "./Select.styles.js";
|
|
10
|
-
const renderIcon = (icon) => {
|
|
13
|
+
const renderIcon = (icon, variant) => {
|
|
11
14
|
if (!icon) return null;
|
|
12
15
|
if (typeof icon === "string") {
|
|
13
|
-
return /* @__PURE__ */ jsx(OptionIcon, { children: /* @__PURE__ */ jsx("img", { src: icon, alt: "" }) });
|
|
16
|
+
return /* @__PURE__ */ jsx(OptionIcon, { $variant: variant, children: /* @__PURE__ */ jsx("img", { src: icon, alt: "" }) });
|
|
14
17
|
}
|
|
15
|
-
return /* @__PURE__ */ jsx(OptionIcon, { children: icon });
|
|
18
|
+
return /* @__PURE__ */ jsx(OptionIcon, { $variant: variant, children: icon });
|
|
16
19
|
};
|
|
20
|
+
const asStyle = (value) => value;
|
|
21
|
+
const buildBorderedOptionStyle = (_base, state) => asStyle({
|
|
22
|
+
cursor: "pointer",
|
|
23
|
+
padding: "10px 16px",
|
|
24
|
+
fontSize: 14,
|
|
25
|
+
lineHeight: "20px",
|
|
26
|
+
border: 0,
|
|
27
|
+
color: colors.black,
|
|
28
|
+
transition: "background-color 0.12s ease",
|
|
29
|
+
fontWeight: state.isSelected ? 600 : 400,
|
|
30
|
+
backgroundColor: state.isFocused ? colors.grey3 : "transparent"
|
|
31
|
+
});
|
|
17
32
|
const buildOptionStyle = (multiple) => (_base, state) => {
|
|
18
33
|
if (multiple) {
|
|
19
|
-
return {
|
|
34
|
+
return asStyle({
|
|
20
35
|
cursor: "pointer",
|
|
21
36
|
padding: "10px 14px",
|
|
22
37
|
fontSize: 13,
|
|
@@ -26,60 +41,41 @@ const buildOptionStyle = (multiple) => (_base, state) => {
|
|
|
26
41
|
transition: "background-color 0.12s ease",
|
|
27
42
|
fontWeight: state.isSelected ? 600 : 400,
|
|
28
43
|
backgroundColor: state.isSelected ? "rgba(0, 80, 202, 0.08)" : state.isFocused ? "#f5f7fb" : "transparent"
|
|
29
|
-
};
|
|
44
|
+
});
|
|
30
45
|
}
|
|
31
|
-
return {
|
|
46
|
+
return asStyle({
|
|
32
47
|
...SelectOption,
|
|
33
48
|
cursor: "pointer",
|
|
34
49
|
fontWeight: state.isSelected || state.isFocused ? "bold" : "normal"
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
const DropdownIndicator = (props) => /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props, children: /* @__PURE__ */ jsx(SelectIcon, { isMenuOpen: props.selectProps.menuIsOpen }) });
|
|
38
|
-
DropdownIndicator.propTypes = {
|
|
39
|
-
selectProps: PropTypes.instanceOf(Object).isRequired
|
|
50
|
+
});
|
|
40
51
|
};
|
|
52
|
+
const extrasOf = (props) => props.selectProps;
|
|
53
|
+
const DropdownIndicator = (props) => /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props, children: /* @__PURE__ */ jsx(SelectIcon, { isMenuOpen: props.selectProps.menuIsOpen, $variant: extrasOf(props).variant }) });
|
|
41
54
|
const ScrollableMenuList = (props) => {
|
|
42
55
|
const { children, selectProps } = props;
|
|
43
56
|
const { maxMenuHeight = 300 } = selectProps;
|
|
44
57
|
return /* @__PURE__ */ jsx(SelectMenuList, { autoHeight: true, autoHeightMax: maxMenuHeight, fullHeight: true, children });
|
|
45
58
|
};
|
|
46
|
-
ScrollableMenuList.propTypes = {
|
|
47
|
-
children: PropTypes.node.isRequired,
|
|
48
|
-
selectProps: PropTypes.instanceOf(Object).isRequired
|
|
49
|
-
};
|
|
50
59
|
const ControlWithDataCy = (props) => {
|
|
51
|
-
const cy = props
|
|
60
|
+
const cy = extrasOf(props)?.dataCy;
|
|
52
61
|
if (!cy) return /* @__PURE__ */ jsx(components.Control, { ...props });
|
|
53
62
|
return /* @__PURE__ */ jsx(components.Control, { ...props, innerProps: { ...props.innerProps, "data-cy": cy } });
|
|
54
63
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/* @__PURE__ */ jsx(OptionLabel, { children: props.label })
|
|
62
|
-
] }) });
|
|
63
|
-
SingleOption.propTypes = {
|
|
64
|
-
data: PropTypes.instanceOf(Object),
|
|
65
|
-
label: PropTypes.node
|
|
64
|
+
const SingleOption = (props) => {
|
|
65
|
+
const variant = extrasOf(props).variant;
|
|
66
|
+
return /* @__PURE__ */ jsx(components.Option, { ...props, children: /* @__PURE__ */ jsxs(OptionRow, { children: [
|
|
67
|
+
renderIcon(props.data?.icon, variant),
|
|
68
|
+
/* @__PURE__ */ jsx(OptionLabel, { children: props.label })
|
|
69
|
+
] }) });
|
|
66
70
|
};
|
|
67
71
|
const MultiOption = (props) => /* @__PURE__ */ jsx(components.Option, { ...props, children: /* @__PURE__ */ jsx(OptionCheckbox, { checked: props.isSelected, children: /* @__PURE__ */ jsxs(OptionRow, { children: [
|
|
68
72
|
renderIcon(props.data?.icon),
|
|
69
73
|
/* @__PURE__ */ jsx(OptionLabel, { children: props.label })
|
|
70
74
|
] }) }) });
|
|
71
|
-
MultiOption.propTypes = {
|
|
72
|
-
data: PropTypes.instanceOf(Object),
|
|
73
|
-
label: PropTypes.node,
|
|
74
|
-
isSelected: PropTypes.bool
|
|
75
|
-
};
|
|
76
75
|
const SingleValueWithIcon = (props) => /* @__PURE__ */ jsx(components.SingleValue, { ...props, children: /* @__PURE__ */ jsxs(OptionRow, { children: [
|
|
77
|
-
renderIcon(props.data?.icon),
|
|
76
|
+
renderIcon(props.data?.icon, extrasOf(props).variant),
|
|
78
77
|
/* @__PURE__ */ jsx(OptionLabel, { children: props.data?.label })
|
|
79
78
|
] }) });
|
|
80
|
-
SingleValueWithIcon.propTypes = {
|
|
81
|
-
data: PropTypes.instanceOf(Object).isRequired
|
|
82
|
-
};
|
|
83
79
|
const Select = (props) => {
|
|
84
80
|
const {
|
|
85
81
|
id,
|
|
@@ -100,6 +96,7 @@ const Select = (props) => {
|
|
|
100
96
|
floatingLabel = true,
|
|
101
97
|
formatCreateLabel,
|
|
102
98
|
dataCy,
|
|
99
|
+
variant = "default",
|
|
103
100
|
onChange,
|
|
104
101
|
onBlur,
|
|
105
102
|
onFocus,
|
|
@@ -131,15 +128,36 @@ const Select = (props) => {
|
|
|
131
128
|
onChange?.({ name, value: arr });
|
|
132
129
|
};
|
|
133
130
|
const SelectComponent = creatable ? CreatableSelect : ReactSelect;
|
|
131
|
+
const bordered = variant === "bordered";
|
|
132
|
+
const invalid = Boolean(error && touched);
|
|
134
133
|
const selectStyles = useMemo(
|
|
135
|
-
() =>
|
|
136
|
-
control: () =>
|
|
137
|
-
menu: (base) => ({
|
|
134
|
+
() => bordered ? {
|
|
135
|
+
control: (_base, state) => asStyle(borderedControlCss({ focused: state.isFocused, invalid, disabled: state.isDisabled })),
|
|
136
|
+
menu: (base) => ({
|
|
137
|
+
...base,
|
|
138
|
+
marginTop: 4,
|
|
139
|
+
zIndex: 1e3,
|
|
140
|
+
overflow: "hidden",
|
|
141
|
+
border: BORDERED_BORDER,
|
|
142
|
+
borderRadius: radius.lg,
|
|
143
|
+
boxShadow: "none",
|
|
144
|
+
backgroundColor: colors.white
|
|
145
|
+
}),
|
|
146
|
+
option: buildBorderedOptionStyle,
|
|
147
|
+
valueContainer: (base) => ({ ...base, padding: 0 }),
|
|
148
|
+
singleValue: (base) => ({ ...base, margin: 0, color: colors.black }),
|
|
149
|
+
placeholder: (base) => ({ ...base, margin: 0, color: colors.grey2 }),
|
|
150
|
+
input: (base) => ({ ...base, margin: 0, padding: 0, color: colors.black }),
|
|
151
|
+
dropdownIndicator: (base) => ({ ...base, padding: 0, color: colors.black }),
|
|
152
|
+
clearIndicator: (base) => ({ ...base, padding: "0 8px" })
|
|
153
|
+
} : {
|
|
154
|
+
control: () => asStyle(SelectControl),
|
|
155
|
+
menu: (base) => asStyle({ ...base, marginTop: 0, zIndex: 1e3, ...SelectMenu }),
|
|
138
156
|
option: buildOptionStyle(multiple),
|
|
139
|
-
selectContainer: () => SelectContainer,
|
|
157
|
+
selectContainer: () => asStyle(SelectContainer),
|
|
140
158
|
valueContainer: (base) => ({ ...base, padding: 0 })
|
|
141
|
-
}
|
|
142
|
-
[multiple]
|
|
159
|
+
},
|
|
160
|
+
[multiple, bordered, invalid]
|
|
143
161
|
);
|
|
144
162
|
const selectComponents = useMemo(
|
|
145
163
|
() => ({
|
|
@@ -162,14 +180,15 @@ const Select = (props) => {
|
|
|
162
180
|
}
|
|
163
181
|
return options?.find((o) => o.value === value) || null;
|
|
164
182
|
}, [multiple, creatable, value, options]);
|
|
183
|
+
const selectedOptions = multiple ? currentValue : [];
|
|
165
184
|
const hasValue = useMemo(() => {
|
|
166
|
-
if (multiple) return
|
|
185
|
+
if (multiple) return selectedOptions.length > 0;
|
|
167
186
|
return currentValue != null && currentValue.value !== "";
|
|
168
|
-
}, [multiple, currentValue]);
|
|
187
|
+
}, [multiple, currentValue, selectedOptions.length]);
|
|
169
188
|
const isLabelUp = floatingLabel ? hasFocus || hasValue : Boolean(label);
|
|
170
|
-
const effectivePlaceholder = label ? hasFocus && placeholder ? placeholder : "" : placeholder;
|
|
189
|
+
const effectivePlaceholder = label && !bordered ? hasFocus && placeholder ? placeholder : "" : placeholder;
|
|
171
190
|
return /* @__PURE__ */ jsxs(Wrapper, { children: [
|
|
172
|
-
label && /* @__PURE__ */ jsx(Label, { isUp: isLabelUp, active: hasFocus, error: error && touched, htmlFor: id, children: label }),
|
|
191
|
+
label && /* @__PURE__ */ jsx(Label, { isUp: isLabelUp, active: hasFocus, error: error && touched, htmlFor: id, $variant: variant, children: label }),
|
|
173
192
|
/* @__PURE__ */ jsx(
|
|
174
193
|
SelectComponent,
|
|
175
194
|
{
|
|
@@ -193,31 +212,32 @@ const Select = (props) => {
|
|
|
193
212
|
onFocus: handleFocus,
|
|
194
213
|
styles: selectStyles,
|
|
195
214
|
components: selectComponents,
|
|
196
|
-
dataCy,
|
|
215
|
+
...{ dataCy, variant },
|
|
197
216
|
...creatable && {
|
|
198
217
|
formatCreateLabel: formatCreateLabel || ((input) => `Create "${input}"`)
|
|
199
218
|
}
|
|
200
219
|
}
|
|
201
220
|
),
|
|
202
|
-
multiple &&
|
|
203
|
-
/* @__PURE__ */ jsxs(SelectedChipsTitle, { children: [
|
|
221
|
+
multiple && selectedOptions.length > 0 && /* @__PURE__ */ jsxs(SelectedChipsWrapper, { "data-cy": dataCy ? `${dataCy}-chips` : void 0, $variant: variant, children: [
|
|
222
|
+
/* @__PURE__ */ jsxs(SelectedChipsTitle, { $variant: variant, children: [
|
|
204
223
|
selectedLabel,
|
|
205
224
|
" (",
|
|
206
|
-
|
|
225
|
+
selectedOptions.length,
|
|
207
226
|
")"
|
|
208
227
|
] }),
|
|
209
|
-
/* @__PURE__ */ jsx(SelectedChipsList, { children:
|
|
228
|
+
/* @__PURE__ */ jsx(SelectedChipsList, { children: selectedOptions.map((opt) => {
|
|
210
229
|
const isLocked = lockedValues.includes(opt.value);
|
|
211
|
-
return /* @__PURE__ */ jsxs(SelectedChip, { children: [
|
|
212
|
-
renderIcon(opt.icon),
|
|
230
|
+
return /* @__PURE__ */ jsxs(SelectedChip, { $variant: variant, children: [
|
|
231
|
+
!bordered && renderIcon(opt.icon),
|
|
213
232
|
/* @__PURE__ */ jsx(SelectedChipLabel, { children: opt.label }),
|
|
214
233
|
/* @__PURE__ */ jsx(
|
|
215
234
|
SelectedChipRemove,
|
|
216
235
|
{
|
|
236
|
+
$variant: variant,
|
|
217
237
|
onClick: () => removeValue(opt.value),
|
|
218
238
|
"aria-label": `Remove ${typeof opt.label === "string" ? opt.label : opt.value}`,
|
|
219
239
|
disabled: disabled || isLocked,
|
|
220
|
-
children: "✕"
|
|
240
|
+
children: bordered ? /* @__PURE__ */ jsx(MaterialIcon, { name: "close", size: 16 }) : "✕"
|
|
221
241
|
}
|
|
222
242
|
)
|
|
223
243
|
] }, opt.key ?? opt.value);
|
|
@@ -225,47 +245,6 @@ const Select = (props) => {
|
|
|
225
245
|
] })
|
|
226
246
|
] });
|
|
227
247
|
};
|
|
228
|
-
Select.propTypes = {
|
|
229
|
-
id: PropTypes.string.isRequired,
|
|
230
|
-
name: PropTypes.string.isRequired,
|
|
231
|
-
label: PropTypes.string,
|
|
232
|
-
/** string|number for single mode, array for multi mode */
|
|
233
|
-
value: PropTypes.oneOfType([
|
|
234
|
-
PropTypes.string,
|
|
235
|
-
PropTypes.number,
|
|
236
|
-
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number]))
|
|
237
|
-
]),
|
|
238
|
-
options: PropTypes.arrayOf(
|
|
239
|
-
PropTypes.shape({
|
|
240
|
-
key: PropTypes.string,
|
|
241
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
242
|
-
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
|
243
|
-
/** URL string (rendered as <img>) or a React node (e.g. an SVG flag) shown left of the label */
|
|
244
|
-
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
|
|
245
|
-
})
|
|
246
|
-
).isRequired,
|
|
247
|
-
placeholder: PropTypes.string,
|
|
248
|
-
error: PropTypes.bool,
|
|
249
|
-
touched: PropTypes.bool,
|
|
250
|
-
disabled: PropTypes.bool,
|
|
251
|
-
search: PropTypes.bool,
|
|
252
|
-
creatable: PropTypes.bool,
|
|
253
|
-
/** Multi-select: checkbox options + chips list rendered below the field. */
|
|
254
|
-
multiple: PropTypes.bool,
|
|
255
|
-
/** Multi mode: values that cannot be removed (chip ✕ disabled, can't be deselected). */
|
|
256
|
-
lockedValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
257
|
-
menuHeight: PropTypes.number,
|
|
258
|
-
/** Heading shown above the chips list in multi mode (default: "Selected"). */
|
|
259
|
-
selectedLabel: PropTypes.string,
|
|
260
|
-
/** Input-like floating label behavior: label starts in-field, moves up on focus/value. */
|
|
261
|
-
floatingLabel: PropTypes.bool,
|
|
262
|
-
formatCreateLabel: PropTypes.func,
|
|
263
|
-
onChange: PropTypes.func,
|
|
264
|
-
onBlur: PropTypes.func,
|
|
265
|
-
onFocus: PropTypes.func,
|
|
266
|
-
/** Playwright / autocapture: `data-cy` selector on the react-select control. */
|
|
267
|
-
dataCy: PropTypes.string
|
|
268
|
-
};
|
|
269
248
|
export {
|
|
270
249
|
Select,
|
|
271
250
|
SelectContainer,
|