@jetbrains/ring-ui 6.0.51 → 6.0.53
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.
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { PureComponent } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
|
-
import deprecate from 'util-deprecate';
|
|
5
4
|
import dataTests from '../global/data-tests';
|
|
6
5
|
import style from './badge.css';
|
|
7
|
-
const warn = deprecate(() => { }, 'Badge is deprecated and will be removed in RingUI 7.0. Use Tag instead.');
|
|
8
6
|
/**
|
|
9
7
|
* @name Badge
|
|
10
8
|
*/
|
|
@@ -20,7 +18,6 @@ export default class Badge extends PureComponent {
|
|
|
20
18
|
'data-test': PropTypes.string
|
|
21
19
|
};
|
|
22
20
|
render() {
|
|
23
|
-
warn();
|
|
24
21
|
const {
|
|
25
22
|
// Modifiers
|
|
26
23
|
gray, valid, invalid, disabled,
|
|
@@ -4,6 +4,10 @@ declare enum Theme {
|
|
|
4
4
|
LIGHT = "light",
|
|
5
5
|
DARK = "dark"
|
|
6
6
|
}
|
|
7
|
+
export declare const ThemeContext: import("react").Context<{
|
|
8
|
+
theme: Theme.LIGHT | Theme.DARK;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const GLOBAL_DARK_CLASS_NAME = "ring-ui-theme-dark";
|
|
7
11
|
export declare function useTheme(): Theme.LIGHT | Theme.DARK;
|
|
8
12
|
export declare function useThemeClasses(theme: Theme): string;
|
|
9
13
|
export interface WithThemeClassesProps {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useState, useEffect, forwardRef, useContext } from 'react';
|
|
1
|
+
import { useMemo, useState, useEffect, forwardRef, useContext, createContext } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { PopupTarget, PopupTargetContext } from '../popup/popup.target';
|
|
@@ -12,6 +12,8 @@ var Theme;
|
|
|
12
12
|
Theme["LIGHT"] = "light";
|
|
13
13
|
Theme["DARK"] = "dark";
|
|
14
14
|
})(Theme || (Theme = {}));
|
|
15
|
+
export const ThemeContext = createContext({ theme: Theme.LIGHT });
|
|
16
|
+
export const GLOBAL_DARK_CLASS_NAME = 'ring-ui-theme-dark';
|
|
15
17
|
const darkMatcher = window.matchMedia('(prefers-color-scheme: dark)');
|
|
16
18
|
export function useTheme() {
|
|
17
19
|
const [dark, setDark] = useState(darkMatcher.matches);
|
|
@@ -27,6 +29,7 @@ export function useThemeClasses(theme) {
|
|
|
27
29
|
const resolvedTheme = theme === Theme.AUTO ? systemTheme : theme;
|
|
28
30
|
return classNames({
|
|
29
31
|
[styles.dark]: resolvedTheme === Theme.DARK,
|
|
32
|
+
[GLOBAL_DARK_CLASS_NAME]: resolvedTheme === Theme.DARK,
|
|
30
33
|
[defaultStyles.light]: resolvedTheme === Theme.LIGHT
|
|
31
34
|
});
|
|
32
35
|
}
|
|
@@ -38,11 +41,11 @@ export function applyTheme(theme, container) {
|
|
|
38
41
|
if (theme === Theme.DARK) {
|
|
39
42
|
container.classList.remove(defaultStyles.light);
|
|
40
43
|
container.classList.add(styles.dark);
|
|
41
|
-
container.classList.add(
|
|
44
|
+
container.classList.add(GLOBAL_DARK_CLASS_NAME);
|
|
42
45
|
}
|
|
43
46
|
else {
|
|
44
47
|
container.classList.remove(styles.dark);
|
|
45
|
-
container.classList.remove(
|
|
48
|
+
container.classList.remove(GLOBAL_DARK_CLASS_NAME);
|
|
46
49
|
container.classList.add(defaultStyles.light);
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -50,6 +53,7 @@ export const ThemeProvider = forwardRef(function ThemeProvider({ theme = Theme.A
|
|
|
50
53
|
const systemTheme = useTheme();
|
|
51
54
|
const resolvedTheme = theme === Theme.AUTO ? systemTheme : theme;
|
|
52
55
|
const id = useMemo(() => getUID('popups-with-theme-'), []);
|
|
56
|
+
const themeValue = useMemo(() => ({ theme: resolvedTheme }), [resolvedTheme]);
|
|
53
57
|
useEffect(() => {
|
|
54
58
|
if (target != null) {
|
|
55
59
|
applyTheme(resolvedTheme, target);
|
|
@@ -57,14 +61,16 @@ export const ThemeProvider = forwardRef(function ThemeProvider({ theme = Theme.A
|
|
|
57
61
|
}, [resolvedTheme, target]);
|
|
58
62
|
const themeClasses = useThemeClasses(theme);
|
|
59
63
|
const parentTarget = useContext(PopupTargetContext);
|
|
60
|
-
return (<
|
|
64
|
+
return (<ThemeContext.Provider value={themeValue}>
|
|
65
|
+
<div ref={ref} className={target != null ? undefined : classNames(className, themeClasses)} {...restProps}>{passToPopups
|
|
61
66
|
? (<PopupTarget id={id}>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
{popupTarget => (<>
|
|
68
|
+
{children}
|
|
69
|
+
{createPortal(<div className={themeClasses}>{popupTarget}</div>, parentTarget && getPopupContainer(parentTarget) || document.body)}
|
|
70
|
+
</>)}
|
|
71
|
+
</PopupTarget>)
|
|
67
72
|
: children}
|
|
68
|
-
|
|
73
|
+
</div>
|
|
74
|
+
</ThemeContext.Provider>);
|
|
69
75
|
});
|
|
70
76
|
export default Theme;
|