@pushwoosh/dumb-components 1.1.218 → 1.1.219
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/EmojiPicker/EmojiPicker.js +20 -10
- package/EmojiPicker/types.d.ts +1 -0
- package/RichMessageEditor/EditorEmojiPicker.helpers.d.ts +2 -0
- package/RichMessageEditor/EditorEmojiPicker.helpers.js +5 -0
- package/RichMessageEditor/EditorEmojiPicker.js +8 -2
- package/RichMessageEditor/EditorEmojiPicker.styled.d.ts +4 -1
- package/RichMessageEditor/EditorEmojiPicker.styled.js +5 -2
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +2 -1
- package/hooks/useThemeName.d.ts +6 -0
- package/hooks/useThemeName.js +30 -0
- package/package.json +1 -1
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
import { Picker } from 'emoji-mart';
|
|
2
2
|
import { createElement, useEffect, useRef } from 'react';
|
|
3
|
+
import { useThemeName } from '../hooks';
|
|
3
4
|
async function data() {
|
|
4
5
|
const response = await fetch('https://cdn.jsdelivr.net/npm/@emoji-mart/data');
|
|
5
6
|
return response.json();
|
|
6
7
|
}
|
|
7
|
-
export const EmojiPicker =
|
|
8
|
+
export const EmojiPicker = ({
|
|
9
|
+
theme,
|
|
10
|
+
...props
|
|
11
|
+
}) => {
|
|
8
12
|
const ref = useRef(null);
|
|
9
13
|
const instance = useRef(null);
|
|
14
|
+
const themeOfBuiltPicker = useRef(null);
|
|
15
|
+
const observedTheme = useThemeName(ref, !theme);
|
|
16
|
+
const pickerTheme = theme ?? observedTheme;
|
|
10
17
|
useEffect(() => {
|
|
11
|
-
|
|
18
|
+
const isThemeAlreadyBuilt = instance.current && themeOfBuiltPicker.current === pickerTheme;
|
|
19
|
+
if (isThemeAlreadyBuilt) {
|
|
12
20
|
instance.current.update({
|
|
13
21
|
data,
|
|
14
22
|
...props
|
|
15
23
|
});
|
|
16
|
-
|
|
17
|
-
const PickerElement = window?.customElements.get('em-emoji-picker');
|
|
18
|
-
instance.current = new (PickerElement || Picker)({
|
|
19
|
-
data,
|
|
20
|
-
...props,
|
|
21
|
-
ref
|
|
22
|
-
});
|
|
24
|
+
return;
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
const PickerElement = window?.customElements.get('em-emoji-picker');
|
|
27
|
+
instance.current = new (PickerElement || Picker)({
|
|
28
|
+
data,
|
|
29
|
+
...props,
|
|
30
|
+
theme: pickerTheme,
|
|
31
|
+
ref
|
|
32
|
+
});
|
|
33
|
+
themeOfBuiltPicker.current = pickerTheme;
|
|
34
|
+
}, [props, pickerTheme]);
|
|
25
35
|
return createElement('div', {
|
|
26
36
|
ref
|
|
27
37
|
});
|
package/EmojiPicker/types.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
2
3
|
import { EditorEmojiPickerStyled } from './EditorEmojiPicker.styled';
|
|
3
4
|
import { EmojiPicker } from '../EmojiPicker';
|
|
5
|
+
import { useThemeName } from '../hooks';
|
|
4
6
|
export const EditorEmojiPicker = ({
|
|
5
7
|
onEmojiSelect
|
|
6
8
|
}) => {
|
|
9
|
+
const ref = useRef(null);
|
|
10
|
+
const theme = useThemeName(ref);
|
|
7
11
|
return _jsx(EditorEmojiPickerStyled, {
|
|
12
|
+
ref: ref,
|
|
13
|
+
"$theme": theme,
|
|
8
14
|
children: _jsx(EmojiPicker, {
|
|
15
|
+
theme: theme,
|
|
9
16
|
onEmojiSelect: emoji => {
|
|
10
17
|
onEmojiSelect(emoji.native);
|
|
11
|
-
}
|
|
12
|
-
theme: "light"
|
|
18
|
+
}
|
|
13
19
|
})
|
|
14
20
|
});
|
|
15
21
|
};
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ThemeName } from '@pushwoosh/kit-constants';
|
|
2
|
+
export declare const EditorEmojiPickerStyled: import("styled-components").StyledComponent<"div", any, {
|
|
3
|
+
$theme: ThemeName;
|
|
4
|
+
}, never>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
-
import { Color, Shadow, ShapeRadius } from '@pushwoosh/kit-constants';
|
|
2
|
+
import { Color, getThemeColors, Shadow, ShapeRadius } from '@pushwoosh/kit-constants';
|
|
3
|
+
import { rgbChannels } from './EditorEmojiPicker.helpers';
|
|
3
4
|
export const EditorEmojiPickerStyled = styled.div.withConfig({
|
|
4
5
|
displayName: "EditorEmojiPickerStyled",
|
|
5
6
|
componentId: "sc-sdjrip-0"
|
|
6
|
-
})(["min-width:352px;em-emoji-picker{border:1px solid ", ";--border-radius:", ";--shadow:", ";background-color:", ";--rgb-background:", ";}"], Color.FORM, ShapeRadius.CONTROL, Shadow.REGULAR, Color.FROZEN,
|
|
7
|
+
})(["min-width:352px;em-emoji-picker{border:1px solid ", ";--border-radius:", ";--shadow:", ";background-color:", ";--rgb-background:", ";}"], Color.FORM, ShapeRadius.CONTROL, Shadow.REGULAR, Color.FROZEN, ({
|
|
8
|
+
$theme
|
|
9
|
+
}) => rgbChannels(getThemeColors($theme).FROZEN));
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import { type ThemeName } from '@pushwoosh/kit-constants';
|
|
3
|
+
/** Current theme as a value, for widgets that cannot read `var(--pw-color-*)` — canvas, shadow DOM.
|
|
4
|
+
* @param ref - element inside the theme scope, so a light island wins over the document theme
|
|
5
|
+
* @param isEnabled - pass `false` when the caller already knows the theme and needs no observer */
|
|
6
|
+
export declare function useThemeName(ref?: RefObject<Element>, isEnabled?: boolean): ThemeName;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { DEFAULT_THEME, THEME_ATTRIBUTE } from '@pushwoosh/kit-constants';
|
|
3
|
+
function readThemeName(element) {
|
|
4
|
+
if (typeof document === 'undefined') {
|
|
5
|
+
return DEFAULT_THEME;
|
|
6
|
+
}
|
|
7
|
+
const scope = element?.closest(`[${THEME_ATTRIBUTE}]`) ?? document.documentElement;
|
|
8
|
+
return scope.getAttribute(THEME_ATTRIBUTE) === 'dark' ? 'dark' : DEFAULT_THEME;
|
|
9
|
+
}
|
|
10
|
+
/** Current theme as a value, for widgets that cannot read `var(--pw-color-*)` — canvas, shadow DOM.
|
|
11
|
+
* @param ref - element inside the theme scope, so a light island wins over the document theme
|
|
12
|
+
* @param isEnabled - pass `false` when the caller already knows the theme and needs no observer */
|
|
13
|
+
export function useThemeName(ref, isEnabled = true) {
|
|
14
|
+
const [themeName, setThemeName] = useState(() => readThemeName(ref?.current ?? null));
|
|
15
|
+
useLayoutEffect(() => {
|
|
16
|
+
if (!isEnabled) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const syncThemeName = () => setThemeName(readThemeName(ref?.current ?? null));
|
|
20
|
+
syncThemeName();
|
|
21
|
+
const observer = new MutationObserver(syncThemeName);
|
|
22
|
+
observer.observe(document.documentElement, {
|
|
23
|
+
attributes: true,
|
|
24
|
+
attributeFilter: [THEME_ATTRIBUTE],
|
|
25
|
+
subtree: true
|
|
26
|
+
});
|
|
27
|
+
return () => observer.disconnect();
|
|
28
|
+
}, [ref, isEnabled]);
|
|
29
|
+
return themeName;
|
|
30
|
+
}
|