@stokr/components-library 5.0.0 → 5.0.1
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 +71 -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 +26 -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 +11 -3
- package/dist/components/FAQ/FAQ.styles.js +55 -1
- package/dist/components/IdentityInfo/IdentityInfo.js +2 -1
- package/dist/components/IdentityInfo/IdentityInfo.styles.js +3 -1
- package/dist/components/InfoBox/InfoBox.d.ts +13 -11
- package/dist/components/InfoBox/InfoBox.js +27 -12
- 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 +56 -0
- package/dist/components/Input/Select.d.ts +57 -0
- package/dist/components/Input/Select.js +89 -99
- package/dist/components/Input/Select.styles.d.ts +89 -0
- package/dist/components/Input/Select.styles.js +102 -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 +84 -0
- package/dist/components/Radio/Radio.styles.d.ts +1 -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 +41 -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 +106 -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 +55 -0
- package/dist/components/StepSidebar/StepSidebar.styles.js +174 -0
- package/dist/components/StokrLoader/StokrLoader.d.ts +16 -2
- package/dist/components/StokrLoader/StokrLoader.js +140 -26
- package/dist/components/TaxResidenceCard/TaxResidenceCard.js +26 -11
- package/dist/components/TaxResidenceCard/TaxResidenceCard.styles.d.ts +29 -12
- package/dist/components/TaxResidenceCard/TaxResidenceCard.styles.js +85 -7
- package/dist/constants/chainLogos.d.ts +9 -0
- package/dist/constants/chainLogos.js +17 -0
- package/dist/index.d.ts +73 -6
- package/dist/index.js +21 -4
- package/dist/static/images/chains/avalanche.svg +7 -0
- package/dist/static/images/chains/avalanche.svg.js +4 -0
- package/dist/static/images/chains/ethereum.svg +14 -0
- package/dist/static/images/chains/ethereum.svg.js +4 -0
- package/dist/static/images/chains/liquid.svg +7 -0
- package/dist/static/images/chains/liquid.svg.js +4 -0
- package/dist/static/images/chains/solana.svg +29 -0
- package/dist/static/images/chains/solana.svg.js +4 -0
- package/dist/static/images/chains/stellar.svg +17 -0
- package/dist/static/images/chains/stellar.svg.js +4 -0
- package/dist/static/images/chains/tempo.svg +11 -0
- package/dist/static/images/chains/tempo.svg.js +4 -0
- package/dist/styles/borderedField.d.ts +11 -0
- package/dist/styles/borderedField.js +53 -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
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import styled from "styled-components";
|
|
3
3
|
import { glyph } from "../MaterialIcon/glyph.js";
|
|
4
|
+
import { MaterialIcon } from "../MaterialIcon/MaterialIcon.js";
|
|
4
5
|
const status = (variant, part) => `var(--stokr-status-${variant}-${part})`;
|
|
6
|
+
const BANNER = { padding: "12px 20px 12px 16px", gap: "12px", align: "center", leftBorder: true };
|
|
7
|
+
const SUCCESS = { padding: "12px", gap: "8px", align: "flex-start", leftBorder: false };
|
|
5
8
|
const Container = styled.div`
|
|
6
9
|
position: relative;
|
|
7
10
|
display: flex;
|
|
8
11
|
overflow: hidden;
|
|
9
|
-
align-items:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
border-radius: 8px;
|
|
12
|
+
align-items: ${(props) => props.$layout.align};
|
|
13
|
+
gap: var(--info-box-gap, ${(props) => props.$layout.gap});
|
|
14
|
+
padding: var(--info-box-padding, ${(props) => props.$layout.padding});
|
|
15
|
+
background: var(--info-box-background, ${(props) => status(props.$variant, "bg")});
|
|
16
|
+
border-radius: var(--info-box-radius, 8px);
|
|
15
17
|
font-size: 12px;
|
|
16
18
|
line-height: 18px;
|
|
17
19
|
letter-spacing: 0.6px;
|
|
18
20
|
font-weight: 400;
|
|
19
21
|
color: ${(props) => status(props.$variant, "text")};
|
|
20
22
|
|
|
21
|
-
${(props) =>
|
|
23
|
+
${(props) => props.$leftBorder && `
|
|
22
24
|
&:before {
|
|
23
25
|
content: '';
|
|
24
26
|
display: block;
|
|
@@ -40,6 +42,11 @@ const DefaultIcon = styled.span.attrs({
|
|
|
40
42
|
color: ${(props) => status(props.$variant, "icon")};
|
|
41
43
|
margin-top: 1px;
|
|
42
44
|
`;
|
|
45
|
+
const SuccessIcon = styled.span`
|
|
46
|
+
display: inline-flex;
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
color: var(--info-box-icon-color, ${status("success", "icon")});
|
|
49
|
+
`;
|
|
43
50
|
const CustomIconWrapper = styled.span`
|
|
44
51
|
flex-shrink: 0;
|
|
45
52
|
display: flex;
|
|
@@ -51,17 +58,25 @@ const Content = styled.div`
|
|
|
51
58
|
flex: 1;
|
|
52
59
|
min-width: 0;
|
|
53
60
|
`;
|
|
54
|
-
const
|
|
61
|
+
const Title = styled.div`
|
|
62
|
+
font-weight: 600;
|
|
63
|
+
`;
|
|
64
|
+
const InfoBox = ({ variant = "warning", title, children, icon, noLeftBorder, ...rest }) => {
|
|
55
65
|
const resolved = ["warning", "info", "error", "success"].includes(variant) ? variant : "warning";
|
|
66
|
+
const layout = resolved === "success" ? SUCCESS : BANNER;
|
|
56
67
|
const renderIcon = () => {
|
|
57
|
-
if (icon) {
|
|
58
|
-
|
|
68
|
+
if (icon) return /* @__PURE__ */ jsx(CustomIconWrapper, { children: icon });
|
|
69
|
+
if (resolved === "success") {
|
|
70
|
+
return /* @__PURE__ */ jsx(SuccessIcon, { children: /* @__PURE__ */ jsx(MaterialIcon, { name: "check", weight: 600, size: 20 }) });
|
|
59
71
|
}
|
|
60
72
|
return /* @__PURE__ */ jsx(DefaultIcon, { $variant: resolved });
|
|
61
73
|
};
|
|
62
|
-
return /* @__PURE__ */ jsxs(Container, { $variant: resolved, $
|
|
74
|
+
return /* @__PURE__ */ jsxs(Container, { ...rest, $variant: resolved, $layout: layout, $leftBorder: layout.leftBorder && !noLeftBorder, children: [
|
|
63
75
|
renderIcon(),
|
|
64
|
-
/* @__PURE__ */
|
|
76
|
+
/* @__PURE__ */ jsxs(Content, { children: [
|
|
77
|
+
title != null && /* @__PURE__ */ jsx(Title, { children: title }),
|
|
78
|
+
children
|
|
79
|
+
] })
|
|
65
80
|
] });
|
|
66
81
|
};
|
|
67
82
|
export {
|
|
@@ -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
|
),
|
|
@@ -70,6 +72,7 @@ const Input = (props) => {
|
|
|
70
72
|
disabled,
|
|
71
73
|
style: inputWrapStyle,
|
|
72
74
|
autoHeightLabel,
|
|
75
|
+
$variant: variant,
|
|
73
76
|
children: /* @__PURE__ */ jsx(
|
|
74
77
|
"input",
|
|
75
78
|
{
|
|
@@ -83,7 +86,7 @@ const Input = (props) => {
|
|
|
83
86
|
readOnly,
|
|
84
87
|
placeholder,
|
|
85
88
|
disabled,
|
|
86
|
-
style: { WebkitAppearance: "none", WebkitBorderRadius: 0 },
|
|
89
|
+
style: variant === "bordered" ? { WebkitAppearance: "none" } : { WebkitAppearance: "none", WebkitBorderRadius: 0 },
|
|
87
90
|
...restProps
|
|
88
91
|
}
|
|
89
92
|
)
|
|
@@ -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;
|
|
@@ -14,9 +16,11 @@ export declare const InputWrap: import('styled-components/dist/types').IStyledCo
|
|
|
14
16
|
dashboard?: boolean;
|
|
15
17
|
error?: boolean;
|
|
16
18
|
hasLabel?: boolean;
|
|
19
|
+
$variant?: FieldVariant;
|
|
17
20
|
}>> & string;
|
|
18
21
|
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"> & {
|
|
19
22
|
style?: import('react').CSSProperties | import('styled-components/dist/types').CSSPropertiesWithVars;
|
|
20
23
|
}, {
|
|
21
24
|
inverted?: boolean;
|
|
25
|
+
$variant?: FieldVariant;
|
|
22
26
|
}>> & string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import styled, { css } from "styled-components";
|
|
2
|
+
import { borderedFieldLabel, borderedFieldBox, borderedFieldText, borderedFieldPlaceholder, borderedFieldFocus, borderedFieldError, borderedFieldDisabled, BORDERED_BORDER } from "../../styles/borderedField.js";
|
|
2
3
|
const Label = styled.label.withConfig({
|
|
3
4
|
shouldForwardProp: (props) => !["autoHeightLabel", "isUp", "active", "error"].includes(props)
|
|
4
5
|
})`
|
|
@@ -37,6 +38,18 @@ const Label = styled.label.withConfig({
|
|
|
37
38
|
${(props) => props.error && `
|
|
38
39
|
color: var(--stokr-status-error-text);
|
|
39
40
|
`}
|
|
41
|
+
|
|
42
|
+
${(props) => props.$variant === "bordered" && css`
|
|
43
|
+
position: static;
|
|
44
|
+
z-index: auto;
|
|
45
|
+
top: auto;
|
|
46
|
+
left: auto;
|
|
47
|
+
height: auto;
|
|
48
|
+
transform: none;
|
|
49
|
+
pointer-events: auto;
|
|
50
|
+
${borderedFieldLabel}
|
|
51
|
+
color: ${props.error ? "var(--stokr-status-error-text)" : "var(--stokr-text-primary)"};
|
|
52
|
+
`}
|
|
40
53
|
`;
|
|
41
54
|
const InputWrap = styled.div.withConfig({
|
|
42
55
|
shouldForwardProp: (props) => !["autoHeightLabel", "disabled", "dashboard", "error", "hasLabel"].includes(props)
|
|
@@ -119,6 +132,42 @@ const InputWrap = styled.div.withConfig({
|
|
|
119
132
|
${(props) => props.error && `
|
|
120
133
|
color: var(--stokr-status-error-text);
|
|
121
134
|
`}
|
|
135
|
+
|
|
136
|
+
${(props) => props.$variant === "bordered" && css`
|
|
137
|
+
& > input {
|
|
138
|
+
${borderedFieldBox}
|
|
139
|
+
${borderedFieldText}
|
|
140
|
+
height: 44px;
|
|
141
|
+
|
|
142
|
+
&::placeholder {
|
|
143
|
+
${borderedFieldPlaceholder}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
&:hover {
|
|
147
|
+
border-color: var(--stokr-border-subtle);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
&:focus {
|
|
151
|
+
${borderedFieldFocus}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
${props.error && css`
|
|
155
|
+
&,
|
|
156
|
+
&:hover,
|
|
157
|
+
&:focus {
|
|
158
|
+
${borderedFieldError}
|
|
159
|
+
}
|
|
160
|
+
`}
|
|
161
|
+
|
|
162
|
+
${props.disabled && css`
|
|
163
|
+
&,
|
|
164
|
+
&:hover,
|
|
165
|
+
&:focus {
|
|
166
|
+
${borderedFieldDisabled}
|
|
167
|
+
}
|
|
168
|
+
`}
|
|
169
|
+
}
|
|
170
|
+
`}
|
|
122
171
|
`;
|
|
123
172
|
const Wrapper = styled.div.withConfig({
|
|
124
173
|
shouldForwardProp: (props) => !["inverted"].includes(props)
|
|
@@ -150,6 +199,13 @@ const Wrapper = styled.div.withConfig({
|
|
|
150
199
|
}
|
|
151
200
|
}
|
|
152
201
|
`}
|
|
202
|
+
|
|
203
|
+
${(props) => props.$variant === "bordered" && css`
|
|
204
|
+
input:-webkit-autofill {
|
|
205
|
+
border: ${BORDERED_BORDER};
|
|
206
|
+
border-radius: var(--stokr-radius-lg);
|
|
207
|
+
}
|
|
208
|
+
`}
|
|
153
209
|
`;
|
|
154
210
|
export {
|
|
155
211
|
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,35 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { useState, useMemo, useRef, useEffect } 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, useRef, useEffect } from "react";
|
|
6
6
|
import CreatableSelect from "react-select/creatable";
|
|
7
7
|
import ReactSelect, { components } from "react-select";
|
|
8
|
-
import {
|
|
8
|
+
import { BORDERED_BORDER } from "../../styles/borderedField.js";
|
|
9
|
+
import { borderedControlCss, SelectedChipsWrapper, SelectedChipsTitle, SelectedChipsList, SelectedChip, SelectedChipLabel, SelectedChipRemove, OptionRow, OptionLabel, SelectMenuList, SelectIcon, SelectContainer, SelectControl, OptionIcon } from "./Select.styles.js";
|
|
9
10
|
import { SelectMenu, SelectOption, SelectValueContainer, SelectWrapper } from "./Select.styles.js";
|
|
10
|
-
const renderIcon = (icon) => {
|
|
11
|
+
const renderIcon = (icon, variant) => {
|
|
11
12
|
if (!icon) return null;
|
|
12
13
|
if (typeof icon === "string") {
|
|
13
|
-
return /* @__PURE__ */ jsx(OptionIcon, { children: /* @__PURE__ */ jsx("img", { src: icon, alt: "" }) });
|
|
14
|
+
return /* @__PURE__ */ jsx(OptionIcon, { $variant: variant, children: /* @__PURE__ */ jsx("img", { src: icon, alt: "" }) });
|
|
14
15
|
}
|
|
15
|
-
return /* @__PURE__ */ jsx(OptionIcon, { children: icon });
|
|
16
|
+
return /* @__PURE__ */ jsx(OptionIcon, { $variant: variant, children: icon });
|
|
16
17
|
};
|
|
18
|
+
const asStyle = (value) => value;
|
|
19
|
+
const buildBorderedOptionStyle = (_base, state) => asStyle({
|
|
20
|
+
cursor: "pointer",
|
|
21
|
+
padding: "10px 16px",
|
|
22
|
+
fontSize: 14,
|
|
23
|
+
lineHeight: "20px",
|
|
24
|
+
border: 0,
|
|
25
|
+
color: "var(--stokr-text-primary)",
|
|
26
|
+
transition: "background-color 0.12s ease",
|
|
27
|
+
fontWeight: state.isSelected ? 600 : 400,
|
|
28
|
+
backgroundColor: state.isFocused ? "var(--stokr-background-surface)" : "transparent"
|
|
29
|
+
});
|
|
17
30
|
const buildOptionStyle = (multiple) => (base, state) => {
|
|
18
31
|
if (multiple) {
|
|
19
|
-
return {
|
|
32
|
+
return asStyle({
|
|
20
33
|
cursor: "pointer",
|
|
21
34
|
padding: "10px 14px",
|
|
22
35
|
fontSize: 13,
|
|
@@ -26,39 +39,29 @@ const buildOptionStyle = (multiple) => (base, state) => {
|
|
|
26
39
|
transition: "background-color 0.12s ease",
|
|
27
40
|
fontWeight: state.isSelected ? 600 : 400,
|
|
28
41
|
backgroundColor: state.isSelected ? "var(--stokr-action-secondary-bg)" : state.isFocused ? "var(--stokr-background-surface)" : "transparent"
|
|
29
|
-
};
|
|
42
|
+
});
|
|
30
43
|
}
|
|
31
|
-
return {
|
|
44
|
+
return asStyle({
|
|
32
45
|
...base,
|
|
33
46
|
cursor: "pointer",
|
|
34
47
|
color: "var(--stokr-text-primary)",
|
|
35
48
|
backgroundColor: "transparent",
|
|
36
49
|
fontWeight: state.isSelected || state.isFocused ? "bold" : "normal",
|
|
37
50
|
":active": { backgroundColor: "var(--stokr-action-secondary-bg)" }
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const DropdownIndicator = (props) => /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props, children: /* @__PURE__ */ jsx(SelectIcon, { isMenuOpen: props.selectProps.menuIsOpen }) });
|
|
41
|
-
DropdownIndicator.propTypes = {
|
|
42
|
-
selectProps: PropTypes.instanceOf(Object).isRequired
|
|
51
|
+
});
|
|
43
52
|
};
|
|
53
|
+
const extrasOf = (props) => props.selectProps;
|
|
54
|
+
const DropdownIndicator = (props) => /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props, children: /* @__PURE__ */ jsx(SelectIcon, { isMenuOpen: props.selectProps.menuIsOpen, $variant: extrasOf(props).variant }) });
|
|
44
55
|
const ScrollableMenuList = (props) => {
|
|
45
56
|
const { children, selectProps } = props;
|
|
46
57
|
const { maxMenuHeight = 300 } = selectProps;
|
|
47
58
|
return /* @__PURE__ */ jsx(SelectMenuList, { autoHeight: true, autoHeightMax: maxMenuHeight, fullHeight: true, children });
|
|
48
59
|
};
|
|
49
|
-
ScrollableMenuList.propTypes = {
|
|
50
|
-
children: PropTypes.node.isRequired,
|
|
51
|
-
selectProps: PropTypes.instanceOf(Object).isRequired
|
|
52
|
-
};
|
|
53
60
|
const ControlWithDataCy = (props) => {
|
|
54
|
-
const cy = props
|
|
61
|
+
const cy = extrasOf(props)?.dataCy;
|
|
55
62
|
if (!cy) return /* @__PURE__ */ jsx(components.Control, { ...props });
|
|
56
63
|
return /* @__PURE__ */ jsx(components.Control, { ...props, innerProps: { ...props.innerProps, "data-cy": cy } });
|
|
57
64
|
};
|
|
58
|
-
ControlWithDataCy.propTypes = {
|
|
59
|
-
innerProps: PropTypes.instanceOf(Object),
|
|
60
|
-
selectProps: PropTypes.instanceOf(Object).isRequired
|
|
61
|
-
};
|
|
62
65
|
const useScrollIntoViewWhenFocused = (isFocused) => {
|
|
63
66
|
const ref = useRef(null);
|
|
64
67
|
useEffect(() => {
|
|
@@ -67,17 +70,13 @@ const useScrollIntoViewWhenFocused = (isFocused) => {
|
|
|
67
70
|
return ref;
|
|
68
71
|
};
|
|
69
72
|
const SingleOption = (props) => {
|
|
73
|
+
const variant = extrasOf(props).variant;
|
|
70
74
|
const ref = useScrollIntoViewWhenFocused(props.isFocused);
|
|
71
75
|
return /* @__PURE__ */ jsx(components.Option, { ...props, children: /* @__PURE__ */ jsxs(OptionRow, { ref, children: [
|
|
72
|
-
renderIcon(props.data?.icon),
|
|
76
|
+
renderIcon(props.data?.icon, variant),
|
|
73
77
|
/* @__PURE__ */ jsx(OptionLabel, { children: props.label })
|
|
74
78
|
] }) });
|
|
75
79
|
};
|
|
76
|
-
SingleOption.propTypes = {
|
|
77
|
-
data: PropTypes.instanceOf(Object),
|
|
78
|
-
label: PropTypes.node,
|
|
79
|
-
isFocused: PropTypes.bool
|
|
80
|
-
};
|
|
81
80
|
const MultiOption = (props) => {
|
|
82
81
|
const ref = useScrollIntoViewWhenFocused(props.isFocused);
|
|
83
82
|
return /* @__PURE__ */ jsx(components.Option, { ...props, children: /* @__PURE__ */ jsx(OptionCheckbox, { checked: props.isSelected, children: /* @__PURE__ */ jsxs(OptionRow, { ref, children: [
|
|
@@ -85,19 +84,10 @@ const MultiOption = (props) => {
|
|
|
85
84
|
/* @__PURE__ */ jsx(OptionLabel, { children: props.label })
|
|
86
85
|
] }) }) });
|
|
87
86
|
};
|
|
88
|
-
MultiOption.propTypes = {
|
|
89
|
-
data: PropTypes.instanceOf(Object),
|
|
90
|
-
label: PropTypes.node,
|
|
91
|
-
isSelected: PropTypes.bool,
|
|
92
|
-
isFocused: PropTypes.bool
|
|
93
|
-
};
|
|
94
87
|
const SingleValueWithIcon = (props) => /* @__PURE__ */ jsx(components.SingleValue, { ...props, children: /* @__PURE__ */ jsxs(OptionRow, { children: [
|
|
95
|
-
renderIcon(props.data?.icon),
|
|
88
|
+
renderIcon(props.data?.icon, extrasOf(props).variant),
|
|
96
89
|
/* @__PURE__ */ jsx(OptionLabel, { children: props.data?.label })
|
|
97
90
|
] }) });
|
|
98
|
-
SingleValueWithIcon.propTypes = {
|
|
99
|
-
data: PropTypes.instanceOf(Object).isRequired
|
|
100
|
-
};
|
|
101
91
|
const Select = (props) => {
|
|
102
92
|
const {
|
|
103
93
|
id,
|
|
@@ -118,6 +108,7 @@ const Select = (props) => {
|
|
|
118
108
|
floatingLabel = true,
|
|
119
109
|
formatCreateLabel,
|
|
120
110
|
dataCy,
|
|
111
|
+
variant = "default",
|
|
121
112
|
onChange,
|
|
122
113
|
onBlur,
|
|
123
114
|
onFocus,
|
|
@@ -155,9 +146,47 @@ const Select = (props) => {
|
|
|
155
146
|
onChange?.({ name, value: arr });
|
|
156
147
|
};
|
|
157
148
|
const SelectComponent = creatable ? CreatableSelect : ReactSelect;
|
|
149
|
+
const bordered = variant === "bordered";
|
|
150
|
+
const invalid = Boolean(error && touched);
|
|
158
151
|
const selectStyles = useMemo(
|
|
159
|
-
() =>
|
|
160
|
-
control: () =>
|
|
152
|
+
() => bordered ? {
|
|
153
|
+
control: (_base, state) => asStyle(borderedControlCss({ focused: state.isFocused, invalid, disabled: state.isDisabled })),
|
|
154
|
+
menu: (base) => ({
|
|
155
|
+
...base,
|
|
156
|
+
marginTop: 4,
|
|
157
|
+
zIndex: 1e3,
|
|
158
|
+
overflow: "hidden",
|
|
159
|
+
border: BORDERED_BORDER,
|
|
160
|
+
borderRadius: "var(--stokr-radius-lg)",
|
|
161
|
+
boxShadow: "none",
|
|
162
|
+
backgroundColor: "var(--stokr-background-default)"
|
|
163
|
+
}),
|
|
164
|
+
option: buildBorderedOptionStyle,
|
|
165
|
+
valueContainer: (base) => ({ ...base, padding: 0 }),
|
|
166
|
+
singleValue: (base) => ({ ...base, margin: 0, color: "var(--stokr-text-primary)" }),
|
|
167
|
+
placeholder: (base, state) => ({
|
|
168
|
+
...base,
|
|
169
|
+
margin: 0,
|
|
170
|
+
color: state.isMulti && state.selectProps.menuIsOpen && state.selectProps.value ? "var(--stokr-text-secondary)" : "var(--stokr-text-tertiary)",
|
|
171
|
+
maxWidth: "100%",
|
|
172
|
+
overflow: "hidden",
|
|
173
|
+
whiteSpace: "nowrap",
|
|
174
|
+
textOverflow: "ellipsis"
|
|
175
|
+
}),
|
|
176
|
+
input: (base) => ({
|
|
177
|
+
...base,
|
|
178
|
+
margin: 0,
|
|
179
|
+
padding: 0,
|
|
180
|
+
color: "var(--stokr-text-primary)"
|
|
181
|
+
}),
|
|
182
|
+
dropdownIndicator: (base) => ({
|
|
183
|
+
...base,
|
|
184
|
+
padding: 0,
|
|
185
|
+
color: "var(--stokr-text-primary)"
|
|
186
|
+
}),
|
|
187
|
+
clearIndicator: (base) => ({ ...base, padding: "0 8px" })
|
|
188
|
+
} : {
|
|
189
|
+
control: () => asStyle(SelectControl),
|
|
161
190
|
menu: (base) => ({
|
|
162
191
|
...base,
|
|
163
192
|
marginTop: 0,
|
|
@@ -173,16 +202,16 @@ const Select = (props) => {
|
|
|
173
202
|
// While open, a multiple select shows who is selected here (see `overview`): readable text, one line.
|
|
174
203
|
placeholder: (base, state) => ({
|
|
175
204
|
...base,
|
|
176
|
-
color: state.isMulti && state.selectProps.menuIsOpen && state.selectProps.value
|
|
205
|
+
color: state.isMulti && state.selectProps.menuIsOpen && state.selectProps.value ? "var(--stokr-text-secondary)" : "var(--stokr-text-tertiary)",
|
|
177
206
|
maxWidth: "100%",
|
|
178
207
|
overflow: "hidden",
|
|
179
208
|
whiteSpace: "nowrap",
|
|
180
209
|
textOverflow: "ellipsis"
|
|
181
210
|
}),
|
|
182
|
-
selectContainer: () => SelectContainer,
|
|
211
|
+
selectContainer: () => asStyle(SelectContainer),
|
|
183
212
|
valueContainer: (base) => ({ ...base, padding: 0 })
|
|
184
|
-
}
|
|
185
|
-
[multiple]
|
|
213
|
+
},
|
|
214
|
+
[multiple, bordered, invalid]
|
|
186
215
|
);
|
|
187
216
|
const selectComponents = useMemo(
|
|
188
217
|
() => ({
|
|
@@ -205,16 +234,17 @@ const Select = (props) => {
|
|
|
205
234
|
}
|
|
206
235
|
return options?.find((o) => o.value === value) || null;
|
|
207
236
|
}, [multiple, creatable, value, options]);
|
|
237
|
+
const selectedOptions = multiple ? currentValue : [];
|
|
208
238
|
const hasValue = useMemo(() => {
|
|
209
|
-
if (multiple) return
|
|
239
|
+
if (multiple) return selectedOptions.length > 0;
|
|
210
240
|
return currentValue != null && currentValue.value !== "";
|
|
211
|
-
}, [multiple, currentValue]);
|
|
241
|
+
}, [multiple, currentValue, selectedOptions.length]);
|
|
212
242
|
const isLabelUp = floatingLabel ? hasFocus || hasValue : Boolean(label);
|
|
213
|
-
const ownPlaceholder = label ? hasFocus && placeholder ? placeholder : "" : placeholder;
|
|
214
|
-
const overview = multiple && menuIsOpen &&
|
|
243
|
+
const ownPlaceholder = label && !bordered ? hasFocus && placeholder ? placeholder : "" : placeholder;
|
|
244
|
+
const overview = multiple && menuIsOpen && selectedOptions.length > 0 ? `${selectedLabel} (${selectedOptions.length}): ${selectedOptions.map((opt) => typeof opt.label === "string" ? opt.label : String(opt.value)).join(", ")}` : null;
|
|
215
245
|
const effectivePlaceholder = overview ?? ownPlaceholder;
|
|
216
246
|
return /* @__PURE__ */ jsxs(Wrapper, { children: [
|
|
217
|
-
label && /* @__PURE__ */ jsx(Label, { isUp: isLabelUp, active: hasFocus, error: error && touched, htmlFor: id, children: label }),
|
|
247
|
+
label && /* @__PURE__ */ jsx(Label, { isUp: isLabelUp, active: hasFocus, error: error && touched, htmlFor: id, $variant: variant, children: label }),
|
|
218
248
|
/* @__PURE__ */ jsx(
|
|
219
249
|
SelectComponent,
|
|
220
250
|
{
|
|
@@ -248,31 +278,32 @@ const Select = (props) => {
|
|
|
248
278
|
onFocus: handleFocus,
|
|
249
279
|
styles: selectStyles,
|
|
250
280
|
components: selectComponents,
|
|
251
|
-
dataCy,
|
|
281
|
+
...{ dataCy, variant },
|
|
252
282
|
...creatable && {
|
|
253
283
|
formatCreateLabel: formatCreateLabel || ((input) => `Create "${input}"`)
|
|
254
284
|
}
|
|
255
285
|
}
|
|
256
286
|
),
|
|
257
|
-
multiple &&
|
|
258
|
-
/* @__PURE__ */ jsxs(SelectedChipsTitle, { children: [
|
|
287
|
+
multiple && selectedOptions.length > 0 && /* @__PURE__ */ jsxs(SelectedChipsWrapper, { "data-cy": dataCy ? `${dataCy}-chips` : void 0, $variant: variant, children: [
|
|
288
|
+
/* @__PURE__ */ jsxs(SelectedChipsTitle, { $variant: variant, children: [
|
|
259
289
|
selectedLabel,
|
|
260
290
|
" (",
|
|
261
|
-
|
|
291
|
+
selectedOptions.length,
|
|
262
292
|
")"
|
|
263
293
|
] }),
|
|
264
|
-
/* @__PURE__ */ jsx(SelectedChipsList, { children:
|
|
294
|
+
/* @__PURE__ */ jsx(SelectedChipsList, { children: selectedOptions.map((opt) => {
|
|
265
295
|
const isLocked = lockedValues.includes(opt.value);
|
|
266
|
-
return /* @__PURE__ */ jsxs(SelectedChip, { children: [
|
|
267
|
-
renderIcon(opt.icon),
|
|
296
|
+
return /* @__PURE__ */ jsxs(SelectedChip, { $variant: variant, children: [
|
|
297
|
+
!bordered && renderIcon(opt.icon),
|
|
268
298
|
/* @__PURE__ */ jsx(SelectedChipLabel, { children: opt.label }),
|
|
269
299
|
/* @__PURE__ */ jsx(
|
|
270
300
|
SelectedChipRemove,
|
|
271
301
|
{
|
|
302
|
+
$variant: variant,
|
|
272
303
|
onClick: () => removeValue(opt.value),
|
|
273
304
|
"aria-label": `Remove ${typeof opt.label === "string" ? opt.label : opt.value}`,
|
|
274
305
|
disabled: disabled || isLocked,
|
|
275
|
-
children: "✕"
|
|
306
|
+
children: bordered ? /* @__PURE__ */ jsx(MaterialIcon, { name: "close", size: 16 }) : "✕"
|
|
276
307
|
}
|
|
277
308
|
)
|
|
278
309
|
] }, opt.key ?? opt.value);
|
|
@@ -280,47 +311,6 @@ const Select = (props) => {
|
|
|
280
311
|
] })
|
|
281
312
|
] });
|
|
282
313
|
};
|
|
283
|
-
Select.propTypes = {
|
|
284
|
-
id: PropTypes.string.isRequired,
|
|
285
|
-
name: PropTypes.string.isRequired,
|
|
286
|
-
label: PropTypes.string,
|
|
287
|
-
/** string|number for single mode, array for multi mode */
|
|
288
|
-
value: PropTypes.oneOfType([
|
|
289
|
-
PropTypes.string,
|
|
290
|
-
PropTypes.number,
|
|
291
|
-
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number]))
|
|
292
|
-
]),
|
|
293
|
-
options: PropTypes.arrayOf(
|
|
294
|
-
PropTypes.shape({
|
|
295
|
-
key: PropTypes.string,
|
|
296
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
297
|
-
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
|
298
|
-
/** URL string (rendered as <img>) or a React node (e.g. an SVG flag) shown left of the label */
|
|
299
|
-
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
|
|
300
|
-
})
|
|
301
|
-
).isRequired,
|
|
302
|
-
placeholder: PropTypes.string,
|
|
303
|
-
error: PropTypes.bool,
|
|
304
|
-
touched: PropTypes.bool,
|
|
305
|
-
disabled: PropTypes.bool,
|
|
306
|
-
search: PropTypes.bool,
|
|
307
|
-
creatable: PropTypes.bool,
|
|
308
|
-
/** Multi-select: checkbox options + chips list rendered below the field. */
|
|
309
|
-
multiple: PropTypes.bool,
|
|
310
|
-
/** Multi mode: values that cannot be removed (chip ✕ disabled, can't be deselected). */
|
|
311
|
-
lockedValues: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
|
312
|
-
menuHeight: PropTypes.number,
|
|
313
|
-
/** Heading shown above the chips list in multi mode (default: "Selected"). */
|
|
314
|
-
selectedLabel: PropTypes.string,
|
|
315
|
-
/** Input-like floating label behavior: label starts in-field, moves up on focus/value. */
|
|
316
|
-
floatingLabel: PropTypes.bool,
|
|
317
|
-
formatCreateLabel: PropTypes.func,
|
|
318
|
-
onChange: PropTypes.func,
|
|
319
|
-
onBlur: PropTypes.func,
|
|
320
|
-
onFocus: PropTypes.func,
|
|
321
|
-
/** Playwright / autocapture: `data-cy` selector on the react-select control. */
|
|
322
|
-
dataCy: PropTypes.string
|
|
323
|
-
};
|
|
324
314
|
export {
|
|
325
315
|
Select,
|
|
326
316
|
SelectContainer,
|