@skyscanner/backpack-web 41.3.0 → 41.4.0
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/bpk-component-card-list/src/BpkCardListRowRail/BpkCardListCarousel.module.css +1 -1
- package/bpk-component-code/index.d.ts +6 -0
- package/bpk-component-code/index.js +3 -1
- package/bpk-component-code/src/BpkCode.d.ts +9 -0
- package/bpk-component-code/src/BpkCode.js +14 -33
- package/bpk-component-code/src/BpkCodeBlock.d.ts +9 -0
- package/bpk-component-code/src/BpkCodeBlock.js +15 -28
- package/bpk-component-theme-toggle/index.d.ts +4 -0
- package/bpk-component-theme-toggle/src/BpkThemeToggle.d.ts +16 -0
- package/bpk-component-theme-toggle/src/BpkThemeToggle.js +12 -7
- package/bpk-component-theme-toggle/src/theming.d.ts +136 -0
- package/bpk-component-theme-toggle/src/updateOnThemeChange.d.ts +42 -0
- package/bpk-component-theme-toggle/src/updateOnThemeChange.js +10 -8
- package/bpk-component-theme-toggle/src/utils.d.ts +3 -0
- package/bpk-component-theme-toggle/src/utils.js +1 -1
- package/package.json +1 -1
|
@@ -15,4 +15,4 @@
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
|
-
.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{display:flex;overflow-x:hidden;box-sizing:border-box;gap:.25rem;margin-
|
|
18
|
+
.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{display:flex;overflow-x:hidden;box-sizing:border-box;gap:.25rem;margin-inline:-0.5rem;scroll-snap-stop:always;scroll-snap-type:x mandatory;scrollbar-width:none}@media(max-width: 32rem){.bpk-card-list-row-rail__row,.bpk-card-list-row-rail__rail{overflow-x:scroll}}.bpk-card-list-row-rail__row::-webkit-scrollbar,.bpk-card-list-row-rail__rail::-webkit-scrollbar{display:none}.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{position:relative;padding:0 .5rem;flex:0 0 calc((100% - .5rem*(var(--initially-shown-cards, 3) - 1))/var(--initially-shown-cards, 3));overflow:visible;box-sizing:border-box;scroll-snap-align:start}@media(max-width: 32rem){.bpk-card-list-row-rail__row__card,.bpk-card-list-row-rail__rail__card{flex-basis:calc((100% - .5rem*(var(--initially-shown-cards, 3) - 1))/max(1,var(--initially-shown-cards, 3) - .8))}}.bpk-card-list-row-rail__row__card{flex-basis:calc((100% - .25rem*(var(--initially-shown-cards, 3) - 1))/var(--initially-shown-cards, 3))}.bpk-card-list-row-rail__rail{-webkit-overflow-scrolling:touch}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import BpkCode from './src/BpkCode';
|
|
2
|
+
import BpkCodeBlock from './src/BpkCodeBlock';
|
|
3
|
+
import type { Props as BpkCodeProps } from './src/BpkCode';
|
|
4
|
+
import type { Props as BpkCodeBlockProps } from './src/BpkCodeBlock';
|
|
5
|
+
export type { BpkCodeProps, BpkCodeBlockProps };
|
|
6
|
+
export { BpkCode, BpkCodeBlock };
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import BpkCode from "./src/BpkCode";
|
|
18
20
|
import BpkCodeBlock from "./src/BpkCodeBlock";
|
|
19
21
|
export { BpkCode, BpkCodeBlock };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type Props = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
alternate?: boolean;
|
|
5
|
+
className?: string;
|
|
6
|
+
[rest: string]: any;
|
|
7
|
+
};
|
|
8
|
+
declare const BpkCode: ({ alternate, children, className, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default BpkCode;
|
|
@@ -14,42 +14,23 @@
|
|
|
14
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
|
|
18
19
|
import { cssModules } from "../../bpk-react-utils";
|
|
19
20
|
import STYLES from "./BpkCode.module.css";
|
|
20
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
22
|
const getClassName = cssModules(STYLES);
|
|
22
|
-
const BpkCode =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
classNames.push(className);
|
|
35
|
-
}
|
|
36
|
-
return (
|
|
37
|
-
/*#__PURE__*/
|
|
38
|
-
// $FlowFixMe[cannot-spread-inexact] - inexact rest. See 'decisions/flowfixme.md'.
|
|
39
|
-
_jsx("code", {
|
|
40
|
-
className: classNames.join(' '),
|
|
41
|
-
...rest,
|
|
42
|
-
children: children
|
|
43
|
-
})
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
BpkCode.propTypes = {
|
|
47
|
-
children: PropTypes.node.isRequired,
|
|
48
|
-
className: PropTypes.string,
|
|
49
|
-
alternate: PropTypes.bool
|
|
50
|
-
};
|
|
51
|
-
BpkCode.defaultProps = {
|
|
52
|
-
className: null,
|
|
53
|
-
alternate: false
|
|
23
|
+
const BpkCode = ({
|
|
24
|
+
alternate = false,
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
...rest
|
|
28
|
+
}) => {
|
|
29
|
+
const classNames = getClassName('bpk-code', alternate && 'bpk-code--alternate', className);
|
|
30
|
+
return /*#__PURE__*/_jsx("code", {
|
|
31
|
+
className: classNames,
|
|
32
|
+
...rest,
|
|
33
|
+
children: children
|
|
34
|
+
});
|
|
54
35
|
};
|
|
55
36
|
export default BpkCode;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export type Props = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
alternate?: boolean;
|
|
5
|
+
className?: string;
|
|
6
|
+
[rest: string]: any;
|
|
7
|
+
};
|
|
8
|
+
declare const BpkCodeBlock: ({ alternate, children, className, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default BpkCodeBlock;
|
|
@@ -14,40 +14,27 @@
|
|
|
14
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
|
|
18
19
|
import { cssModules } from "../../bpk-react-utils";
|
|
19
20
|
import STYLES from "./BpkCodeBlock.module.css";
|
|
20
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
22
|
const getClassName = cssModules(STYLES);
|
|
22
|
-
const BpkCodeBlock =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = props;
|
|
23
|
+
const BpkCodeBlock = ({
|
|
24
|
+
alternate = false,
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
...rest
|
|
28
|
+
}) => {
|
|
29
29
|
const preClassNames = getClassName('bpk-code__pre', alternate && 'bpk-code__pre--alternate', className);
|
|
30
30
|
const codeClassNames = getClassName('bpk-code', 'bpk-code--block');
|
|
31
|
-
return (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
_jsx("
|
|
35
|
-
className:
|
|
36
|
-
|
|
37
|
-
children: /*#__PURE__*/_jsx("code", {
|
|
38
|
-
className: codeClassNames,
|
|
39
|
-
children: children
|
|
40
|
-
})
|
|
31
|
+
return /*#__PURE__*/_jsx("pre", {
|
|
32
|
+
className: preClassNames,
|
|
33
|
+
...rest,
|
|
34
|
+
children: /*#__PURE__*/_jsx("code", {
|
|
35
|
+
className: codeClassNames,
|
|
36
|
+
children: children
|
|
41
37
|
})
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
BpkCodeBlock.propTypes = {
|
|
45
|
-
children: PropTypes.node.isRequired,
|
|
46
|
-
alternate: PropTypes.bool,
|
|
47
|
-
className: PropTypes.string
|
|
48
|
-
};
|
|
49
|
-
BpkCodeBlock.defaultProps = {
|
|
50
|
-
alternate: false,
|
|
51
|
-
className: null
|
|
38
|
+
});
|
|
52
39
|
};
|
|
53
40
|
export default BpkCodeBlock;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChangeEvent } from 'react';
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
type Props = Record<string, never>;
|
|
4
|
+
type State = {
|
|
5
|
+
selectedTheme: string;
|
|
6
|
+
};
|
|
7
|
+
declare class BpkThemeToggle extends Component<Props, State> {
|
|
8
|
+
constructor(props: Props);
|
|
9
|
+
componentDidMount(): void;
|
|
10
|
+
componentWillUnmount(): void;
|
|
11
|
+
handleKeyDown: (e: KeyboardEvent) => void;
|
|
12
|
+
handleChange: (e: ChangeEvent<HTMLSelectElement>) => void;
|
|
13
|
+
cycleTheme: () => void;
|
|
14
|
+
render(): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
}
|
|
16
|
+
export default BpkThemeToggle;
|
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { Component } from 'react';
|
|
20
|
+
|
|
21
|
+
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
20
22
|
import BpkLabel from "../../bpk-component-label";
|
|
23
|
+
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
21
24
|
import BpkSelect from "../../bpk-component-select";
|
|
22
25
|
import { cssModules } from "../../bpk-react-utils";
|
|
23
26
|
import bpkCustomThemes from "./theming";
|
|
@@ -29,11 +32,13 @@ const getClassName = cssModules(STYLES);
|
|
|
29
32
|
const availableThemes = Object.keys(bpkCustomThemes);
|
|
30
33
|
const setTheme = theme => {
|
|
31
34
|
const htmlElement = getHtmlElement();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
if (htmlElement) {
|
|
36
|
+
htmlElement.dispatchEvent(new CustomEvent(THEME_CHANGE_EVENT, {
|
|
37
|
+
detail: {
|
|
38
|
+
theme
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
37
42
|
};
|
|
38
43
|
class BpkThemeToggle extends Component {
|
|
39
44
|
constructor(props) {
|
|
@@ -58,7 +63,7 @@ class BpkThemeToggle extends Component {
|
|
|
58
63
|
this.setState({
|
|
59
64
|
selectedTheme
|
|
60
65
|
});
|
|
61
|
-
setTheme(bpkCustomThemes[selectedTheme]);
|
|
66
|
+
setTheme(selectedTheme ? bpkCustomThemes[selectedTheme] : undefined);
|
|
62
67
|
};
|
|
63
68
|
cycleTheme = () => {
|
|
64
69
|
let {
|
|
@@ -73,7 +78,7 @@ class BpkThemeToggle extends Component {
|
|
|
73
78
|
this.setState({
|
|
74
79
|
selectedTheme
|
|
75
80
|
});
|
|
76
|
-
setTheme(bpkCustomThemes[selectedTheme]);
|
|
81
|
+
setTheme(selectedTheme ? bpkCustomThemes[selectedTheme] : undefined);
|
|
77
82
|
};
|
|
78
83
|
render() {
|
|
79
84
|
const {
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export type Theme = {
|
|
2
|
+
themeName: string;
|
|
3
|
+
primaryColor: string;
|
|
4
|
+
logoFillColor: string;
|
|
5
|
+
accordionActiveColor: string;
|
|
6
|
+
accordionColor: string;
|
|
7
|
+
accordionHoverColor: string;
|
|
8
|
+
badgeBackgroundColor: string;
|
|
9
|
+
badgeSuccessBackgroundColor: string;
|
|
10
|
+
badgeDestructiveBackgroundColor: string;
|
|
11
|
+
bannerAlertPrimaryColor: string;
|
|
12
|
+
bannerAlertSuccessColor: string;
|
|
13
|
+
bannerAlertWarnColor: string;
|
|
14
|
+
bannerAlertErrorColor: string;
|
|
15
|
+
barchartBarBackgroundColor: string;
|
|
16
|
+
barchartBarHoverBackgroundColor: string;
|
|
17
|
+
barchartBarActiveBackgroundColor: string;
|
|
18
|
+
barchartBarSelectedBackgroundColor: string;
|
|
19
|
+
blockquoteBarColor: string;
|
|
20
|
+
buttonFontSize: string;
|
|
21
|
+
buttonPrimaryTextColor: string;
|
|
22
|
+
buttonPrimaryHoverTextColor: string;
|
|
23
|
+
buttonPrimaryActiveTextColor: string;
|
|
24
|
+
buttonPrimaryGradientStartColor: string;
|
|
25
|
+
buttonPrimaryGradientEndColor: string;
|
|
26
|
+
buttonPrimaryBackgroundColor: string;
|
|
27
|
+
buttonPrimaryHoverBackgroundColor: string;
|
|
28
|
+
buttonPrimaryActiveBackgroundColor: string;
|
|
29
|
+
buttonSecondaryTextColor: string;
|
|
30
|
+
buttonSecondaryHoverTextColor: string;
|
|
31
|
+
buttonSecondaryActiveTextColor: string;
|
|
32
|
+
buttonSecondaryBorderColor: string;
|
|
33
|
+
buttonSecondaryHoverBorderColor: string;
|
|
34
|
+
buttonSecondaryActiveBorderColor: string;
|
|
35
|
+
buttonSecondaryBackgroundColor: string;
|
|
36
|
+
buttonSecondaryHoverBackgroundColor: string;
|
|
37
|
+
buttonSecondaryActiveBackgroundColor: string;
|
|
38
|
+
buttonFeaturedTextColor: string;
|
|
39
|
+
buttonFeaturedHoverTextColor: string;
|
|
40
|
+
buttonFeaturedActiveTextColor: string;
|
|
41
|
+
buttonFeaturedGradientStartColor: string;
|
|
42
|
+
buttonFeaturedGradientEndColor: string;
|
|
43
|
+
buttonFeaturedBackgroundColor: string;
|
|
44
|
+
buttonFeaturedHoverBackgroundColor: string;
|
|
45
|
+
buttonFeaturedActiveBackgroundColor: string;
|
|
46
|
+
buttonDestructiveTextColor: string;
|
|
47
|
+
buttonDestructiveHoverTextColor: string;
|
|
48
|
+
buttonDestructiveActiveTextColor: string;
|
|
49
|
+
buttonDestructiveBorderColor: string;
|
|
50
|
+
buttonDestructiveHoverBorderColor: string;
|
|
51
|
+
buttonDestructiveActiveBorderColor: string;
|
|
52
|
+
buttonDestructiveBackgroundColor: string;
|
|
53
|
+
buttonDestructiveHoverBackgroundColor: string;
|
|
54
|
+
buttonDestructiveActiveBackgroundColor: string;
|
|
55
|
+
chipDefaultSelectedBackgroundColor: string;
|
|
56
|
+
chipDefaultSelectedTextColor: string;
|
|
57
|
+
chipOnDarkSelectedBackgroundColor: string;
|
|
58
|
+
chipOnDarkSelectedTextColor: string;
|
|
59
|
+
chipOnImageSelectedBackgroundColor: string;
|
|
60
|
+
chipOnImageSelectedHoverBackgroundColor: string;
|
|
61
|
+
chipOnImageSelectedActiveBackgroundColor: string;
|
|
62
|
+
chipOnImageSelectedTextColor: string;
|
|
63
|
+
fieldsetLabelTextColor: string;
|
|
64
|
+
formValidationIconFill: string;
|
|
65
|
+
formValidationTextColor: string;
|
|
66
|
+
inputInvalidBorderColor: string;
|
|
67
|
+
linkColor: string;
|
|
68
|
+
linkHoverColor: string;
|
|
69
|
+
linkActiveColor: string;
|
|
70
|
+
linkVisitedColor: string;
|
|
71
|
+
linkAlternateColor: string;
|
|
72
|
+
linkAlternateHoverColor: string;
|
|
73
|
+
linkAlternateActiveColor: string;
|
|
74
|
+
linkAlternateVisitedColor: string;
|
|
75
|
+
horizontalNavBarSelectedColor: string;
|
|
76
|
+
horizontalNavLinkSelectedColor: string;
|
|
77
|
+
horizontalNavLinkColor: string;
|
|
78
|
+
horizontalNavLinkHoverColor: string;
|
|
79
|
+
horizontalNavLinkActiveColor: string;
|
|
80
|
+
selectInvalidBorderColor: string;
|
|
81
|
+
spinnerPrimaryColor: string;
|
|
82
|
+
starRatingFilledColor: string;
|
|
83
|
+
sliderBarColor: string;
|
|
84
|
+
textareaInvalidBorderColor: string;
|
|
85
|
+
paginationNudgerActiveColor: string;
|
|
86
|
+
paginationNudgerColor: string;
|
|
87
|
+
paginationNudgerHoverColor: string;
|
|
88
|
+
paginationSelectedBackgroundColor: string;
|
|
89
|
+
progressBarFillColor: string;
|
|
90
|
+
calendarDateTextColor: string;
|
|
91
|
+
calendarDateTextHoverColor: string;
|
|
92
|
+
calendarDateTextActiveColor: string;
|
|
93
|
+
calendarDateTextFocusColor: string;
|
|
94
|
+
calendarDateTextSelectedColor: string;
|
|
95
|
+
calendarDateSelectedBackgroundColor: string;
|
|
96
|
+
calendarDateFocusedBorderColor: string;
|
|
97
|
+
calendarNudgerIconColor: string;
|
|
98
|
+
calendarNudgerIconHoverColor: string;
|
|
99
|
+
calendarNudgerIconActiveColor: string;
|
|
100
|
+
checkboxCheckedColor: string;
|
|
101
|
+
radioCheckedColor: string;
|
|
102
|
+
switchCheckedColor: string;
|
|
103
|
+
ratingHighTextColor: string;
|
|
104
|
+
ratingHighColor: string;
|
|
105
|
+
ratingMediumTextColor: string;
|
|
106
|
+
ratingMediumColor: string;
|
|
107
|
+
ratingLowColor: string;
|
|
108
|
+
iconMarkerDefaultBackgroundColor: string;
|
|
109
|
+
iconMarkerDefaultSelectedColor: string;
|
|
110
|
+
iconMarkerDefaultDisabledColor: string;
|
|
111
|
+
iconMarkerDefaultDisabledBackgroundColor: string;
|
|
112
|
+
priceMarkerBackgroundColor: string;
|
|
113
|
+
priceMarkerSelectedBorderColor: string;
|
|
114
|
+
priceMarkerSelectedColor: string;
|
|
115
|
+
priceMarkerViewedBackgroundColor: string;
|
|
116
|
+
priceMarkerViewedBorderColor: string;
|
|
117
|
+
priceMarkerViewedColor: string;
|
|
118
|
+
skipLinkBackgroundColor: string;
|
|
119
|
+
navigationBarIconButtonColor: string;
|
|
120
|
+
navigationBarIconButtonHoverColor: string;
|
|
121
|
+
navigationBarIconButtonActiveColor: string;
|
|
122
|
+
navigationBarButtonLinkColor: string;
|
|
123
|
+
navigationBarButtonLinkHoverColor: string;
|
|
124
|
+
navigationBarButtonLinkActiveColor: string;
|
|
125
|
+
navigationBarButtonLinkVisitedColor: string;
|
|
126
|
+
navigationBarTitleColor: string;
|
|
127
|
+
navigationBarBackgroundColor: string;
|
|
128
|
+
docsSidebarBackground: string;
|
|
129
|
+
docsSidebarLink: string;
|
|
130
|
+
docsSidebarLinkBorder: string;
|
|
131
|
+
docsSidebarSelectedArrowColor: string;
|
|
132
|
+
};
|
|
133
|
+
declare const bpkCustomThemes: {
|
|
134
|
+
[key: string]: Theme;
|
|
135
|
+
};
|
|
136
|
+
export default bpkCustomThemes;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import type { Theme } from './theming';
|
|
3
|
+
type ThemeChangeEvent = CustomEvent<{
|
|
4
|
+
theme: Theme | null;
|
|
5
|
+
}>;
|
|
6
|
+
type UpdateOnThemeChangeProps = {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
type UpdateOnThemeChangeState = {
|
|
10
|
+
theme: Theme | null;
|
|
11
|
+
};
|
|
12
|
+
declare const updateOnThemeChange: <P extends object>(EnhancedComponent: ComponentType<P & {
|
|
13
|
+
theme: Theme | null;
|
|
14
|
+
}>) => {
|
|
15
|
+
new (props: P & UpdateOnThemeChangeProps): {
|
|
16
|
+
componentDidMount(): void;
|
|
17
|
+
componentWillUnmount(): void;
|
|
18
|
+
onThemeChange: (e: ThemeChangeEvent) => void;
|
|
19
|
+
render(): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
context: unknown;
|
|
21
|
+
setState<K extends "theme">(state: UpdateOnThemeChangeState | ((prevState: Readonly<UpdateOnThemeChangeState>, props: Readonly<P & UpdateOnThemeChangeProps>) => UpdateOnThemeChangeState | Pick<UpdateOnThemeChangeState, K> | null) | Pick<UpdateOnThemeChangeState, K> | null, callback?: (() => void) | undefined): void;
|
|
22
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
23
|
+
readonly props: Readonly<P & UpdateOnThemeChangeProps>;
|
|
24
|
+
state: Readonly<UpdateOnThemeChangeState>;
|
|
25
|
+
refs: {
|
|
26
|
+
[key: string]: import("react").ReactInstance;
|
|
27
|
+
};
|
|
28
|
+
shouldComponentUpdate?(nextProps: Readonly<P & UpdateOnThemeChangeProps>, nextState: Readonly<UpdateOnThemeChangeState>, nextContext: any): boolean;
|
|
29
|
+
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
|
|
30
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<P & UpdateOnThemeChangeProps>, prevState: Readonly<UpdateOnThemeChangeState>): any;
|
|
31
|
+
componentDidUpdate?(prevProps: Readonly<P & UpdateOnThemeChangeProps>, prevState: Readonly<UpdateOnThemeChangeState>, snapshot?: any): void;
|
|
32
|
+
componentWillMount?(): void;
|
|
33
|
+
UNSAFE_componentWillMount?(): void;
|
|
34
|
+
componentWillReceiveProps?(nextProps: Readonly<P & UpdateOnThemeChangeProps>, nextContext: any): void;
|
|
35
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<P & UpdateOnThemeChangeProps>, nextContext: any): void;
|
|
36
|
+
componentWillUpdate?(nextProps: Readonly<P & UpdateOnThemeChangeProps>, nextState: Readonly<UpdateOnThemeChangeState>, nextContext: any): void;
|
|
37
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<P & UpdateOnThemeChangeProps>, nextState: Readonly<UpdateOnThemeChangeState>, nextContext: any): void;
|
|
38
|
+
};
|
|
39
|
+
displayName: string;
|
|
40
|
+
contextType?: import("react").Context<any> | undefined;
|
|
41
|
+
};
|
|
42
|
+
export default updateOnThemeChange;
|
|
@@ -16,24 +16,29 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import PropTypes from 'prop-types';
|
|
20
19
|
import { Component } from 'react';
|
|
21
20
|
import { wrapDisplayName } from "../../bpk-react-utils";
|
|
22
21
|
import { getHtmlElement, THEME_CHANGE_EVENT } from "./utils";
|
|
23
22
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
23
|
const updateOnThemeChange = EnhancedComponent => {
|
|
25
24
|
class UpdateOnThemeChange extends Component {
|
|
26
|
-
constructor() {
|
|
27
|
-
super();
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super(props);
|
|
28
27
|
this.state = {
|
|
29
28
|
theme: null
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
31
|
componentDidMount() {
|
|
33
|
-
getHtmlElement()
|
|
32
|
+
const htmlElement = getHtmlElement();
|
|
33
|
+
if (htmlElement) {
|
|
34
|
+
htmlElement.addEventListener(THEME_CHANGE_EVENT, this.onThemeChange, false);
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
37
|
componentWillUnmount() {
|
|
36
|
-
getHtmlElement()
|
|
38
|
+
const htmlElement = getHtmlElement();
|
|
39
|
+
if (htmlElement) {
|
|
40
|
+
htmlElement.removeEventListener(THEME_CHANGE_EVENT, this.onThemeChange, false);
|
|
41
|
+
}
|
|
37
42
|
}
|
|
38
43
|
onThemeChange = e => {
|
|
39
44
|
const {
|
|
@@ -52,9 +57,6 @@ const updateOnThemeChange = EnhancedComponent => {
|
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
UpdateOnThemeChange.displayName = wrapDisplayName(EnhancedComponent, 'updateOnThemeChange');
|
|
55
|
-
UpdateOnThemeChange.propTypes = {
|
|
56
|
-
children: PropTypes.node.isRequired
|
|
57
|
-
};
|
|
58
60
|
return UpdateOnThemeChange;
|
|
59
61
|
};
|
|
60
62
|
export default updateOnThemeChange;
|
|
@@ -16,5 +16,5 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
const THEME_CHANGE_EVENT = 'bpkchangetheme';
|
|
19
|
-
const getHtmlElement = () => typeof document !== 'undefined' ? document.querySelector('html') :
|
|
19
|
+
const getHtmlElement = () => typeof document !== 'undefined' ? document.querySelector('html') : null;
|
|
20
20
|
export { THEME_CHANGE_EVENT, getHtmlElement };
|