@pushwoosh/dumb-components 1.1.196 → 1.1.197
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/Select/Select.js +9 -4
- package/Select/themeStyles.d.ts +6 -0
- package/Select/themeStyles.js +72 -0
- package/package.json +1 -1
package/Select/Select.js
CHANGED
|
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { CloseIcon } from '@pushwoosh/kit-icons';
|
|
3
3
|
import { CLASS_NAME_PREFIX } from './constants';
|
|
4
4
|
import { SelectStyled, SelectAsyncStyled, ClearIndicatorBox } from './styles';
|
|
5
|
+
import { withThemeStyles } from './themeStyles';
|
|
5
6
|
const componentsProps = {
|
|
6
7
|
ClearIndicator: ({
|
|
7
8
|
clearValue
|
|
@@ -24,11 +25,13 @@ const componentsProps = {
|
|
|
24
25
|
*/
|
|
25
26
|
export function Select(props) {
|
|
26
27
|
const {
|
|
27
|
-
classNamePrefix = CLASS_NAME_PREFIX
|
|
28
|
+
classNamePrefix = CLASS_NAME_PREFIX,
|
|
29
|
+
styles
|
|
28
30
|
} = props;
|
|
29
31
|
const customProps = {
|
|
30
32
|
...props,
|
|
31
|
-
classNamePrefix
|
|
33
|
+
classNamePrefix,
|
|
34
|
+
styles: withThemeStyles(styles)
|
|
32
35
|
};
|
|
33
36
|
return _jsx(SelectStyled, {
|
|
34
37
|
components: componentsProps,
|
|
@@ -44,11 +47,13 @@ export function Select(props) {
|
|
|
44
47
|
*/
|
|
45
48
|
export function SelectAsync(props) {
|
|
46
49
|
const {
|
|
47
|
-
classNamePrefix = CLASS_NAME_PREFIX
|
|
50
|
+
classNamePrefix = CLASS_NAME_PREFIX,
|
|
51
|
+
styles
|
|
48
52
|
} = props;
|
|
49
53
|
const customProps = {
|
|
50
54
|
...props,
|
|
51
|
-
classNamePrefix
|
|
55
|
+
classNamePrefix,
|
|
56
|
+
styles: withThemeStyles(styles)
|
|
52
57
|
};
|
|
53
58
|
return _jsx(SelectAsyncStyled, {
|
|
54
59
|
components: componentsProps,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GroupBase, StylesConfig } from 'react-select';
|
|
2
|
+
/**
|
|
3
|
+
* Merges the Pushwoosh select theme under a caller's own `styles`, so theirs still wins.
|
|
4
|
+
* Goes through `styles`, not CSS: a menu portalled into `body` escapes the styled wrapper.
|
|
5
|
+
*/
|
|
6
|
+
export declare function withThemeStyles<Option, IsMulti extends boolean, Group extends GroupBase<Option>>(styles?: StylesConfig<Option, IsMulti, Group>): StylesConfig<Option, IsMulti, Group>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Color, FontWeight, Shadow } from '@pushwoosh/kit-constants';
|
|
2
|
+
const themeStyles = {
|
|
3
|
+
menu: base => ({
|
|
4
|
+
...base,
|
|
5
|
+
backgroundColor: Color.CLEAR,
|
|
6
|
+
boxShadow: Shadow.REGULAR
|
|
7
|
+
}),
|
|
8
|
+
menuList: base => ({
|
|
9
|
+
...base,
|
|
10
|
+
backgroundColor: Color.CLEAR
|
|
11
|
+
}),
|
|
12
|
+
option: (base, state) => ({
|
|
13
|
+
...base,
|
|
14
|
+
color: Color.MAIN,
|
|
15
|
+
fontWeight: state.isSelected ? FontWeight.MEDIUM : FontWeight.REGULAR,
|
|
16
|
+
backgroundColor: (() => {
|
|
17
|
+
if (state.isSelected && state.isFocused) return Color.BRIGHT_LIGHT_HOVER;
|
|
18
|
+
if (state.isSelected) return Color.BRIGHT_LIGHT;
|
|
19
|
+
if (state.isFocused) return Color.SOFT_LIGHT;
|
|
20
|
+
return 'transparent';
|
|
21
|
+
})(),
|
|
22
|
+
':active': {
|
|
23
|
+
backgroundColor: Color.BRIGHT_LIGHT_HOVER
|
|
24
|
+
}
|
|
25
|
+
}),
|
|
26
|
+
singleValue: base => ({
|
|
27
|
+
...base,
|
|
28
|
+
color: Color.MAIN
|
|
29
|
+
}),
|
|
30
|
+
multiValueLabel: base => ({
|
|
31
|
+
...base,
|
|
32
|
+
color: Color.PRIMARY
|
|
33
|
+
}),
|
|
34
|
+
input: base => ({
|
|
35
|
+
...base,
|
|
36
|
+
color: Color.MAIN
|
|
37
|
+
}),
|
|
38
|
+
placeholder: base => ({
|
|
39
|
+
...base,
|
|
40
|
+
color: Color.PHANTOM
|
|
41
|
+
}),
|
|
42
|
+
groupHeading: base => ({
|
|
43
|
+
...base,
|
|
44
|
+
color: Color.LOCKED
|
|
45
|
+
}),
|
|
46
|
+
noOptionsMessage: base => ({
|
|
47
|
+
...base,
|
|
48
|
+
color: Color.LOCKED
|
|
49
|
+
}),
|
|
50
|
+
loadingMessage: base => ({
|
|
51
|
+
...base,
|
|
52
|
+
color: Color.LOCKED
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Merges the Pushwoosh select theme under a caller's own `styles`, so theirs still wins.
|
|
57
|
+
* Goes through `styles`, not CSS: a menu portalled into `body` escapes the styled wrapper.
|
|
58
|
+
*/
|
|
59
|
+
export function withThemeStyles(styles) {
|
|
60
|
+
if (!styles) return themeStyles;
|
|
61
|
+
const keys = new Set([...Object.keys(themeStyles), ...Object.keys(styles)]);
|
|
62
|
+
const merged = {};
|
|
63
|
+
keys.forEach(key => {
|
|
64
|
+
const ours = themeStyles[key];
|
|
65
|
+
const theirs = styles[key];
|
|
66
|
+
merged[key] = (base, state) => {
|
|
67
|
+
const themed = ours ? ours(base, state) : base;
|
|
68
|
+
return theirs ? theirs(themed, state) : themed;
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
return merged;
|
|
72
|
+
}
|