@homecode/ui 4.22.8 → 4.22.9

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.
@@ -2,7 +2,19 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import S from './Flex.styl.js';
3
3
 
4
4
  const Flex = ({ children, ...props }) => {
5
- return (jsx("div", { className: S.root, ...props, children: children }));
5
+ return (jsx("div", { className: S.root, ...props, style: {
6
+ justifyContent: props.justifyContent,
7
+ alignItems: props.alignItems,
8
+ flexDirection: props.flexDirection,
9
+ flexWrap: props.flexWrap,
10
+ flexGrow: props.flexGrow,
11
+ flexShrink: props.flexShrink,
12
+ flexBasis: props.flexBasis,
13
+ flex: props.flex,
14
+ order: props.order,
15
+ alignSelf: props.alignSelf,
16
+ flexFlow: props.flexFlow,
17
+ }, children: children }));
6
18
  };
7
19
 
8
20
  export { Flex };
@@ -2,8 +2,8 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { Component } from 'react';
3
3
  import Time from 'timen';
4
4
  import { createStore } from 'justorm/react';
5
- import { Container } from '../Container/Container.js';
6
5
  import { Spinner } from '../Spinner/Spinner.js';
6
+ import { Flex } from '../Flex/Flex.js';
7
7
 
8
8
  function compare(cb1, cb2) {
9
9
  return cb1?.toString() === cb2?.toString();
@@ -11,23 +11,25 @@ function compare(cb1, cb2) {
11
11
  const loaded = new Map();
12
12
  class Lazy extends Component {
13
13
  store;
14
- Node;
15
- hasNode = false;
14
+ importData;
15
+ DefaultNode;
16
+ isLoaded = false;
16
17
  clearSpinnerTimeout;
17
18
  static defaultProps = {
18
19
  size: 'm',
19
20
  };
20
21
  constructor(props) {
21
22
  super(props);
22
- this.Node = loaded.get(this.props.loader);
23
- this.hasNode = Boolean(this.Node);
23
+ this.importData = loaded.get(this.props.loader);
24
+ this.DefaultNode = this.importData?.default;
25
+ const isLoaded = !!this.importData;
24
26
  this.store = createStore(this, {
25
- loading: !this.hasNode,
26
- spinnerTimeout: this.hasNode,
27
+ loading: !isLoaded,
28
+ spinnerTimeout: isLoaded,
27
29
  });
28
30
  }
29
31
  componentDidMount() {
30
- if (!this.hasNode)
32
+ if (!this.importData)
31
33
  this.update();
32
34
  }
33
35
  componentDidUpdate({ loader }) {
@@ -38,27 +40,32 @@ class Lazy extends Component {
38
40
  }
39
41
  }
40
42
  update() {
41
- const { loader } = this.props;
42
- this.clearSpinnerTimeout = Time.after(500, () => this.setState({ spinnerTimeout: false }));
43
+ const { loader, spinnerTimeout = 500 } = this.props;
44
+ this.clearSpinnerTimeout = Time.after(spinnerTimeout, () => this.setState({ spinnerTimeout: false }));
43
45
  this.store.loading = true;
44
- loader().then(({ default: Node }) => {
46
+ loader().then((data) => {
45
47
  if (!compare(this.props.loader, loader))
46
48
  return;
47
- this.Node = Node;
48
- loaded.set(loader, Node);
49
+ this.importData = data;
50
+ this.DefaultNode = data.default;
51
+ loaded.set(loader, data);
49
52
  this.store.loading = false;
50
53
  });
51
54
  }
52
55
  render() {
53
- const { Node } = this;
54
- const { progressElem, loader, hideSpinner, ...props } = this.props;
56
+ const { DefaultNode, importData } = this;
57
+ const { progressElem, loader, render, children, hideSpinner, ...props } = this.props;
55
58
  const { loading, spinnerTimeout } = this.store;
56
- if (Node)
57
- return jsx(Node, { ...props });
58
- if (!spinnerTimeout && loading && !hideSpinner) {
59
- return (progressElem ?? (jsx(Container, { fullHeight: true, fullWidth: true, children: jsx(Spinner, { size: props.size }) })));
59
+ if (loading && !spinnerTimeout && !hideSpinner) {
60
+ return (progressElem ?? (jsx(Flex, { justifyContent: "center", alignItems: "center", flexGrow: 1, width: "100%", height: "100%", children: jsx(Spinner, { size: props.size }) })));
60
61
  }
61
- return null;
62
+ if (render)
63
+ return render(importData);
64
+ if (typeof children === 'function')
65
+ return children(importData);
66
+ if (DefaultNode)
67
+ return jsx(DefaultNode, { ...props });
68
+ return children;
62
69
  }
63
70
  }
64
71
 
@@ -1,5 +1,5 @@
1
- import { HTMLAttributes } from 'react';
2
- type FlexProps = HTMLAttributes<HTMLDivElement> & {
1
+ import { CSSProperties, HTMLAttributes } from 'react';
2
+ type FlexProps = HTMLAttributes<HTMLDivElement> & CSSProperties & {
3
3
  children: React.ReactNode;
4
4
  };
5
5
  export declare const Flex: ({ children, ...props }: FlexProps) => JSX.Element;
@@ -3,8 +3,9 @@ import * as T from './Lazy.types';
3
3
  export type LazyProps = T.Props;
4
4
  export declare class Lazy extends Component<T.Props> {
5
5
  store: T.State;
6
- Node?: ComponentType<any>;
7
- hasNode: boolean;
6
+ importData?: T.ImportData;
7
+ DefaultNode?: ComponentType<any>;
8
+ isLoaded: boolean;
8
9
  clearSpinnerTimeout: null;
9
10
  static defaultProps: {
10
11
  size: string;
@@ -1,10 +1,13 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { Size } from 'uilib/types';
3
- export type Loader = () => Promise<{
4
- default: ReactNode;
5
- }>;
3
+ export type ImportData = Record<string | 'default', any>;
4
+ export type Loader = () => Promise<ImportData>;
5
+ type RenderFunction = (importData: ImportData) => ReactNode;
6
6
  export type Props = {
7
7
  loader: Loader;
8
+ render?: RenderFunction;
9
+ children?: ReactNode | RenderFunction;
10
+ spinnerTimeout?: number;
8
11
  size?: Size;
9
12
  progressElem?: ReactNode;
10
13
  hideSpinner?: boolean;
@@ -13,3 +16,4 @@ export type State = {
13
16
  loading: boolean;
14
17
  spinnerTimeout: boolean;
15
18
  };
19
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.22.8",
3
+ "version": "4.22.9",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "test": "jest",