addon-ui 0.9.1 → 0.10.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.
@@ -15,18 +15,34 @@ import "addon-ui-style.scss";
15
15
 
16
16
  import config from "addon-ui-config";
17
17
 
18
- export interface UIProviderProps extends Partial<Config>, Pick<ThemeProviderProps, "storage"> {
18
+ export interface UIProviderProps extends Partial<Config>, Pick<ThemeProviderProps, "storage" | "container"> {
19
+ /**
20
+ * A custom view identifier that allows developers to specify a unique name for styling customization.
21
+ * This value is set as a "view" attribute on the container element and can be targeted through SCSS mixins
22
+ * to apply view-specific styles and behavior.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * <UIProvider view="dashboard">
27
+ * <App />
28
+ * </UIProvider>
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```scss
33
+ * @include view("dashboard") {
34
+ * .some-class {
35
+ * // Custom styles for dashboard view
36
+ * }
37
+ * }
38
+ * ```
39
+ */
19
40
  view?: string;
20
41
  }
21
42
 
22
- const UIProvider: FC<PropsWithChildren<UIProviderProps>> = ({
23
- children,
24
- components = {},
25
- extra = {},
26
- icons = {},
27
- storage,
28
- view,
29
- }) => {
43
+ const UIProvider: FC<PropsWithChildren<UIProviderProps>> = props => {
44
+ const {children, components = {}, extra = {}, icons = {}, storage, view, container = "html"} = props;
45
+
30
46
  const componentsProps = useMemo<ComponentsProps>(() => merge(config.components || {}, components), [components]);
31
47
 
32
48
  const extraProps = useMemo<ExtraProps>(() => merge(config.extra || {}, extra), [extra]);
@@ -34,17 +50,28 @@ const UIProvider: FC<PropsWithChildren<UIProviderProps>> = ({
34
50
  const svgIcons = useMemo<Icons>(() => merge(config.icons || {}, icons), [icons]);
35
51
 
36
52
  useEffect(() => {
37
- const html = document.querySelector("html");
38
- if (html) {
53
+ if (container === false) {
54
+ return;
55
+ }
56
+
57
+ const element = typeof container === "string" ? document.querySelector(container) : container;
58
+
59
+ if (element) {
39
60
  if (view) {
40
- html.setAttribute("view", view);
61
+ element.setAttribute("view", view);
41
62
  }
42
- html.setAttribute("browser", getBrowser());
63
+
64
+ element.setAttribute("browser", getBrowser());
65
+
66
+ return () => {
67
+ element.removeAttribute("browser");
68
+ element.removeAttribute("view");
69
+ };
43
70
  }
44
- }, [view]);
71
+ }, [view, container]);
45
72
 
46
73
  return (
47
- <ThemeProvider components={componentsProps} storage={storage}>
74
+ <ThemeProvider components={componentsProps} storage={storage} container={container}>
48
75
  <ExtraProvider extra={extraProps}>
49
76
  <IconsProvider icons={svgIcons}>{children}</IconsProvider>
50
77
  </ExtraProvider>
@@ -1,6 +1,6 @@
1
1
  @use "../../../styles/mixins" as theme;
2
2
 
3
- @include theme.light {
3
+ :root {
4
4
  --viewport-height: var(--viewport-min-height);
5
5
  --viewport-width: var(--viewport-min-width);
6
6
 
@@ -1,35 +1,48 @@
1
+ @mixin _attribute-context($attr, $value) {
2
+ @if & {
3
+ [#{$attr}="#{$value}"] &,
4
+ &[#{$attr}="#{$value}"] {
5
+ @content;
6
+ }
7
+ } @else {
8
+ [#{$attr}="#{$value}"] {
9
+ @content;
10
+ }
11
+ }
12
+ }
13
+
1
14
  @mixin light {
2
- :root {
15
+ @include _attribute-context("theme", "light") {
3
16
  @content;
4
17
  }
5
18
  }
6
19
 
7
20
  @mixin dark {
8
- html[theme="dark"] {
21
+ @include _attribute-context("theme", "dark") {
9
22
  @content;
10
23
  }
11
24
  }
12
25
 
13
26
  @mixin ltr {
14
- html[dir="ltr"] & {
27
+ @include _attribute-context("dir", "ltr") {
15
28
  @content;
16
29
  }
17
30
  }
18
31
 
19
32
  @mixin rtl {
20
- html[dir="rtl"] & {
33
+ @include _attribute-context("dir", "rtl") {
21
34
  @content;
22
35
  }
23
36
  }
24
37
 
25
38
  @mixin view($view) {
26
- html[view="#{$view}"] & {
39
+ @include _attribute-context("view", $view) {
27
40
  @content;
28
41
  }
29
42
  }
30
43
 
31
44
  @mixin browser($browser) {
32
- html[browser="#{$browser}"] & {
45
+ @include _attribute-context("browser", $browser) {
33
46
  @content;
34
47
  }
35
48
  }