@homecode/ui 4.22.8 → 4.22.10

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 };
@@ -171,9 +171,9 @@ class Gallery extends Component {
171
171
  props.onPointerLeave = this.onPointerUp;
172
172
  }
173
173
  }
174
- return (jsxs("div", { className: classes, ...props, children: [jsx("div", { className: innerClasses, ref: this.innerRef, children: items.map((src, i) => (jsx(Item, { src: src, size: size, isLoaded: loading[src], isError: errors[src], onLoad: () => (loading[src] = true), onError: () => (errors[src] = true) }, `${i}_${src}`))) }), !isSingle && showArrows && !isDragging && (jsxs(Fragment, { children: [jsx(Arr, { className: S.left, size: size, icon: "chevronLeft", onClick: () => this.move(1) }), jsx(Arr, { className: S.right, size: size, icon: "chevronRight", onClick: () => this.move(-1) })] })), showDots && (jsx(Lazy, { hideSpinner: true,
174
+ return (jsxs("div", { className: classes, ...props, children: [jsx("div", { className: innerClasses, ref: this.innerRef, children: items.map((src, i) => (jsx(Item, { src: src, size: size, isLoaded: loading[src], isError: errors[src], onLoad: () => (loading[src] = true), onError: () => (errors[src] = true) }, `${i}_${src}`))) }), !isSingle && showArrows && !isDragging && (jsxs(Fragment, { children: [jsx(Arr, { className: S.left, size: size, icon: "chevronLeft", onClick: () => this.move(1) }), jsx(Arr, { className: S.right, size: size, icon: "chevronRight", onClick: () => this.move(-1) })] })), showDots && (jsx(Lazy, { hideSpinner: true, loader: () => import('./Dots/Dots.js'),
175
175
  // @ts-ignore
176
- loader: () => import('./Dots/Dots.js'), index: this.index % items.length, count: items.length }))] }));
176
+ index: this.index % items.length, count: items.length }))] }));
177
177
  }
178
178
  }
179
179
 
@@ -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
 
@@ -8,7 +8,7 @@ import S from './Tabs.styl.js';
8
8
 
9
9
  const isId = id => ['string', 'number'].includes(typeof id);
10
10
  function Tabs(props) {
11
- const { size = 'm', className, contentClassName, items, hideTabsIfSingle = false, allowEmpty = false, onChange, renderAll, activeId: initialId, children, ...rest } = props;
11
+ const { size = 'm', className, tabsWrapperClassName, tabsClassName, contentClassName, items, hideTabsIfSingle = false, allowEmpty = false, onChange, renderAll, activeId: initialId, children, ...rest } = props;
12
12
  const [activeId, setActiveId] = useState(isId(initialId) ? initialId : allowEmpty ? null : items[0].id);
13
13
  useEffect(() => {
14
14
  if (isId(initialId)) {
@@ -18,7 +18,7 @@ function Tabs(props) {
18
18
  const onTabClick = useCallback((e, { id, onClick } = {}) => {
19
19
  // @ts-ignore
20
20
  if (onClick && !onClick(e)) {
21
- e.peventDefault();
21
+ e.preventDefault();
22
22
  return;
23
23
  }
24
24
  const newId = allowEmpty && id === activeId ? null : id;
@@ -35,7 +35,7 @@ function Tabs(props) {
35
35
  }
36
36
  return (createElement(Button, { ...rest, className: cn(S.tab, rest.className), size: size, key: id, onClick: e => onTabClick(e, params), checked: isActive }, label));
37
37
  });
38
- const tabs = tabsButtons.length === 1 && hideTabsIfSingle ? null : (jsx(Scroll, { x: true, offset: { x: { before: 10, after: 10 } }, innerClassName: cn(S.tabsScroll, S[`size-${size}`]), autoHide: true, fadeSize: size, size: size, children: jsx(ButtonGroup, { className: className, ...rest, children: tabsButtons }) }));
38
+ const tabs = tabsButtons.length === 1 && hideTabsIfSingle ? null : (jsx(Scroll, { x: true, offset: { x: { before: 10, after: 10 } }, className: tabsWrapperClassName, innerClassName: cn(S.tabsScroll, S[`size-${size}`]), autoHide: true, fadeSize: size, size: size, children: jsx(ButtonGroup, { className: tabsClassName, ...rest, children: tabsButtons }) }));
39
39
  if (typeof children === 'function') {
40
40
  return children({
41
41
  tabs,
@@ -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 {};
@@ -16,6 +16,8 @@ export type RenderProps = {
16
16
  export type Props = {
17
17
  size?: Size;
18
18
  className?: string;
19
+ tabsWrapperClassName?: string;
20
+ tabsClassName?: string;
19
21
  contentClassName?: string;
20
22
  items: Item[];
21
23
  hideTabsIfSingle?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.22.8",
3
+ "version": "4.22.10",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "test": "jest",