addon-ui 0.3.1 → 0.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.
@@ -1,9 +1,12 @@
1
- import React, {FC, PropsWithChildren, useMemo, useRef} from "react";
1
+ import React, {FC, PropsWithChildren, useEffect, useMemo} from "react";
2
+ import {getBrowser} from "adnbn";
3
+
2
4
  import {merge} from "ts-deepmerge";
3
5
 
4
- import {ExtraProvider, IconsProvider, ThemeProvider, ThemeStorage} from "../index";
6
+ import {ExtraProvider} from "../extra";
7
+ import {IconsProvider} from "../icons";
8
+ import {ThemeProvider, ThemeProviderProps} from "../theme";
5
9
 
6
- import {ThemeStorageContract} from "../../types/theme";
7
10
  import {ComponentsProps, Config, ExtraProps, Icons} from "../../types/config";
8
11
 
9
12
  import "./styles/default.scss";
@@ -12,23 +15,36 @@ import "addon-ui-style.scss";
12
15
 
13
16
  import config from "addon-ui-config";
14
17
 
15
- export type UIProviderProps = Partial<Config>;
16
-
17
- const UIProvider: FC<PropsWithChildren<UIProviderProps>> = ({children, components = {}, extra = {}, icons = {}}) => {
18
- const storageRef = useRef<ThemeStorageContract | null>(null);
19
-
20
- if (!storageRef.current) {
21
- storageRef.current = new ThemeStorage();
22
- }
23
-
18
+ export interface UIProviderProps extends Partial<Config>, Pick<ThemeProviderProps, "storage"> {
19
+ view?: string;
20
+ }
21
+
22
+ const UIProvider: FC<PropsWithChildren<UIProviderProps>> = ({
23
+ children,
24
+ components = {},
25
+ extra = {},
26
+ icons = {},
27
+ storage,
28
+ view,
29
+ }) => {
24
30
  const componentsProps = useMemo<ComponentsProps>(() => merge(config.components || {}, components), [components]);
25
31
 
26
32
  const extraProps = useMemo<ExtraProps>(() => merge(config.extra || {}, extra), [extra]);
27
33
 
28
34
  const svgIcons = useMemo<Icons>(() => merge(config.icons || {}, icons), [icons]);
29
35
 
36
+ useEffect(() => {
37
+ const html = document.querySelector("html");
38
+ if (html) {
39
+ if (view) {
40
+ html.setAttribute("view", view);
41
+ }
42
+ html.setAttribute("browser", getBrowser());
43
+ }
44
+ }, [view]);
45
+
30
46
  return (
31
- <ThemeProvider components={componentsProps} storage={storageRef.current}>
47
+ <ThemeProvider components={componentsProps} storage={storage}>
32
48
  <ExtraProvider extra={extraProps}>
33
49
  <IconsProvider icons={svgIcons}>{children}</IconsProvider>
34
50
  </ExtraProvider>
@@ -1,11 +1,14 @@
1
1
  @use "../../../styles/mixins" as theme;
2
2
 
3
3
  @include theme.light {
4
- --min-height: 440px;
5
- --max-height: 540px;
4
+ --viewport-height: var(--viewport-min-height);
5
+ --viewport-width: var(--viewport-min-width);
6
6
 
7
- --min-width: 380px;
8
- --max-width: var(--min-width);
7
+ --viewport-min-height: 440px;
8
+ --viewport-max-height: 600px;
9
+
10
+ --viewport-min-width: 380px;
11
+ --viewport-max-width: var(--viewport-min-width);
9
12
 
10
13
  --font-family: "Arial", sans-serif;
11
14
  --font-size: 14px;
@@ -21,3 +21,33 @@
21
21
  @content;
22
22
  }
23
23
  }
24
+
25
+ @mixin browser($browser) {
26
+ html[browser="#{$browser}"] & {
27
+ @content;
28
+ }
29
+ }
30
+
31
+ @mixin chromeOnly() {
32
+ @include browser(chrome) {
33
+ @content;
34
+ }
35
+ }
36
+
37
+ @mixin edgeOnly() {
38
+ @include browser(edge) {
39
+ @content;
40
+ }
41
+ }
42
+
43
+ @mixin operaOnly() {
44
+ @include browser(opera) {
45
+ @content;
46
+ }
47
+ }
48
+
49
+ @mixin firefoxOnly() {
50
+ @include browser(firefox) {
51
+ @content;
52
+ }
53
+ }
@@ -1,60 +0,0 @@
1
- import React, {
2
- ComponentProps,
3
- forwardRef,
4
- ForwardRefRenderFunction,
5
- PropsWithChildren,
6
- useCallback,
7
- useState,
8
- } from "react";
9
-
10
- import {expandType, LayoutContext} from "./context";
11
-
12
- import classnames from "classnames";
13
-
14
- import styles from "./layout.module.scss";
15
-
16
- export type LayoutProps = ComponentProps<"div">;
17
-
18
- const Provider: ForwardRefRenderFunction<HTMLDivElement, PropsWithChildren<LayoutProps>> = (
19
- {children, className, style, ...props},
20
- ref
21
- ) => {
22
- const [isExpanded, setExpanded] = useState(false);
23
- const [height, setHeight] = useState<number | string | undefined>(undefined);
24
- const [width, setWidth] = useState<number | string | undefined>(undefined);
25
-
26
- const expand = useCallback((value?: expandType) => {
27
- setHeight(value?.height);
28
- setWidth(value?.width);
29
- setExpanded(true);
30
- }, []);
31
-
32
- const collapse = useCallback(() => {
33
- setHeight(undefined);
34
- setWidth(undefined);
35
- setExpanded(false);
36
- }, []);
37
-
38
- return (
39
- <LayoutContext.Provider value={{isExpanded, expand, collapse}}>
40
- <div
41
- ref={ref}
42
- style={{minHeight: height, minWidth: width, ...style}}
43
- className={classnames(
44
- styles["layout"],
45
- {
46
- [styles["layout--expanded"]]: isExpanded,
47
- },
48
- className
49
- )}
50
- {...props}
51
- >
52
- {children}
53
- </div>
54
- </LayoutContext.Provider>
55
- );
56
- };
57
-
58
- Provider.displayName = "ViewportProvider";
59
-
60
- export default forwardRef(Provider);
@@ -1,24 +0,0 @@
1
- import {createContext, useContext} from "react";
2
-
3
- export type expandType = {
4
- height?: number | string;
5
- width?: number | string;
6
- };
7
-
8
- export interface LayoutContract {
9
- isExpanded?: boolean;
10
-
11
- expand(value?: expandType): void;
12
-
13
- collapse(): void;
14
- }
15
-
16
- export const LayoutContext = createContext<LayoutContract>({
17
- isExpanded: false,
18
- expand() {},
19
- collapse() {},
20
- });
21
-
22
- LayoutContext.displayName = "LayoutContext";
23
-
24
- export const useLayout = () => useContext(LayoutContext);
@@ -1,2 +0,0 @@
1
- export {default as LayoutProvider, type LayoutProps} from "./Provider";
2
- export {useLayout} from "./context";
@@ -1,17 +0,0 @@
1
- .layout {
2
- display: flex;
3
- flex-direction: column;
4
- overflow: hidden;
5
- min-width: var(--min-width);
6
- max-width: var(--max-width);
7
- min-height: var(--min-height);
8
- max-height: var(--max-height);
9
- transition:
10
- min-height var(--transition-speed-md) ease-in-out,
11
- min-width var(--transition-speed-md) ease-in-out;
12
-
13
- &--expanded {
14
- min-height: var(--max-height);
15
- min-width: var(--max-width);
16
- }
17
- }