@infomaximum/ui-kit 0.14.11 → 0.15.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.
@@ -12,6 +12,7 @@ export declare const checkboxStyle: (checked: boolean, disabled: boolean, isHove
12
12
  readonly justifyContent: "center";
13
13
  readonly alignItems: "center";
14
14
  readonly position: "relative";
15
+ readonly flex: "0 0 auto";
15
16
  readonly width: 16;
16
17
  readonly height: 16;
17
18
  readonly boxSizing: "border-box";
@@ -39,6 +39,7 @@ const checkboxStyle = (checked, disabled, isHover) => {
39
39
  justifyContent: "center",
40
40
  alignItems: "center",
41
41
  position: "relative",
42
+ flex: "0 0 auto",
42
43
  width: theme.controlInteractiveSize,
43
44
  height: theme.controlInteractiveSize,
44
45
  boxSizing: "border-box",
@@ -0,0 +1,2 @@
1
+ import { SpinProps } from './Spin.types';
2
+ export declare const Spin: import('react').NamedExoticComponent<SpinProps>;
@@ -0,0 +1,86 @@
1
+ import { jsxs, jsx } from "@emotion/react/jsx-runtime";
2
+ import { memo, useState, useEffect, Fragment } from "react";
3
+ import { getSpinTokens } from "./Spin.tokens.js";
4
+ import { shouldDelay } from "./Spin.utils.js";
5
+ import { uniqueId, isUndefined } from "lodash-es";
6
+ import { getWithFullscreenPropWrapperStyle, withChildrenPropWrapperStyle, baseWrapperStyle, getSpinWrapperStyle, getForeignObjectSpinInnerStyle, getTipWrapperStyle, childrenWrapperStyle, containerStyle } from "./Spin.styles.js";
7
+ import { useTheme } from "../../hooks/useTheme/useTheme.js";
8
+ const SpinComponent = (props) => {
9
+ const {
10
+ delay,
11
+ fullscreen = false,
12
+ size = "middle",
13
+ spinning: spinningProp = true,
14
+ tip,
15
+ children
16
+ } = props;
17
+ const clipPathUniqId = uniqueId("spinner_clip_path_");
18
+ const theme = useTheme();
19
+ const spinTokens = getSpinTokens();
20
+ const [spinning, setSpinning] = useState(() => spinningProp && !shouldDelay(spinningProp, delay));
21
+ useEffect(() => {
22
+ if (spinningProp) {
23
+ if (isUndefined(delay)) {
24
+ setSpinning(true);
25
+ return;
26
+ }
27
+ const timerId = setTimeout(() => {
28
+ setSpinning(true);
29
+ }, delay);
30
+ return () => {
31
+ if (timerId) {
32
+ clearTimeout(timerId);
33
+ }
34
+ };
35
+ }
36
+ setSpinning(false);
37
+ }, [delay, spinningProp]);
38
+ if (children && !spinning) {
39
+ return children;
40
+ }
41
+ if (!spinning) {
42
+ return;
43
+ }
44
+ const Container = children ? "div" : Fragment;
45
+ const Wrapper = tip || children || fullscreen ? "div" : Fragment;
46
+ const containerProps = (() => {
47
+ if (!children) {
48
+ return {};
49
+ }
50
+ return {
51
+ css: containerStyle
52
+ };
53
+ })();
54
+ const wrapperProps = (() => {
55
+ if (!(tip || children || fullscreen)) {
56
+ return {};
57
+ }
58
+ if (fullscreen) {
59
+ return {
60
+ css: getWithFullscreenPropWrapperStyle(spinning)(theme)
61
+ };
62
+ }
63
+ if (children) {
64
+ return {
65
+ css: withChildrenPropWrapperStyle(theme)
66
+ };
67
+ }
68
+ return {
69
+ css: baseWrapperStyle(theme)
70
+ };
71
+ })();
72
+ return /* @__PURE__ */ jsxs(Container, { ...containerProps, children: [
73
+ /* @__PURE__ */ jsxs(Wrapper, { ...wrapperProps, children: [
74
+ /* @__PURE__ */ jsx("span", { css: getSpinWrapperStyle(spinTokens, size), children: /* @__PURE__ */ jsxs("svg", { width: "1em", height: "1em", viewBox: "0 0 32 32", xmlns: "http://www.w3.org/2000/svg", children: [
75
+ /* @__PURE__ */ jsx("g", { clipPath: `url(#${clipPathUniqId})`, children: /* @__PURE__ */ jsx("foreignObject", { width: "100%", height: "100%", children: /* @__PURE__ */ jsx("div", { css: getForeignObjectSpinInnerStyle(fullscreen)(theme) }) }) }),
76
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", { id: clipPathUniqId, children: /* @__PURE__ */ jsx("path", { d: "M30 16.0001C30.0001 14.8955 29.1047 14 28.0001 14C26.8955 13.9999 26.0001 14.8953 26 15.9999L28 16L30 16.0001ZM19.09 6.48877C20.1405 6.83008 21.2688 6.25516 21.6101 5.20465C21.9514 4.15413 21.3765 3.02583 20.326 2.68452L19.708 4.58665L19.09 6.48877ZM28 16L26 15.9999C25.9999 18.1116 25.3313 20.1692 24.0899 21.8776L25.7079 23.0532L27.3259 24.2288C29.0638 21.8371 29.9999 18.9565 30 16.0001L28 16ZM25.7079 23.0532L24.0899 21.8776C22.8486 23.586 21.0983 24.8575 19.0899 25.5101L19.7078 27.4122L20.3258 29.3143C23.1376 28.4008 25.588 26.6206 27.3259 24.2288L25.7079 23.0532ZM19.7078 27.4122L19.0899 25.5101C17.0814 26.1626 14.918 26.1625 12.9096 25.5099L12.2915 27.412L11.6734 29.3141C14.4852 30.2277 17.514 30.2278 20.3258 29.3143L19.7078 27.4122ZM12.2915 27.412L12.9096 25.5099C10.9012 24.8573 9.15098 23.5856 7.90974 21.8771L6.29169 23.0527L4.67363 24.2282C6.41137 26.6201 8.8617 28.4004 11.6734 29.3141L12.2915 27.412ZM6.29169 23.0527L7.90974 21.8771C6.6685 20.1686 5.99998 18.1111 6 15.9993L4 15.9993L2 15.9993C1.99998 18.9558 2.9359 21.8363 4.67363 24.2282L6.29169 23.0527ZM4 15.9993L6 15.9993C6.00002 13.8876 6.66856 11.83 7.90982 10.1215L6.29179 8.94598L4.67375 7.77041C2.93599 10.1622 2.00002 13.0428 2 15.9993L4 15.9993ZM6.29179 8.94598L7.90982 10.1215C9.15109 8.41309 10.9013 7.14144 12.9097 6.48885L12.2917 4.58675L11.6736 2.68464C8.86187 3.59827 6.41152 5.37857 4.67375 7.77041L6.29179 8.94598ZM12.2917 4.58675L12.9097 6.48885C14.9181 5.83626 17.0816 5.83623 19.09 6.48877L19.708 4.58665L20.326 2.68452C17.5142 1.77097 14.4854 1.77101 11.6736 2.68464L12.2917 4.58675Z" }) }) })
77
+ ] }) }),
78
+ tip && /* @__PURE__ */ jsx("div", { css: getTipWrapperStyle(fullscreen)(theme), children: tip })
79
+ ] }),
80
+ children && /* @__PURE__ */ jsx("div", { css: childrenWrapperStyle, children })
81
+ ] });
82
+ };
83
+ const Spin = memo(SpinComponent);
84
+ export {
85
+ Spin
86
+ };
@@ -0,0 +1,64 @@
1
+ import { Theme } from '../../themes';
2
+ import { SpinTokens } from './Spin.tokens';
3
+ import { SpinSize } from './Spin.types';
4
+ export declare const containerStyle: {
5
+ readonly position: "relative";
6
+ };
7
+ export declare const baseWrapperStyle: (theme: Theme) => {
8
+ readonly display: "inline-flex";
9
+ readonly flexDirection: "column";
10
+ readonly alignItems: "center";
11
+ readonly rowGap: 4;
12
+ };
13
+ export declare const nonStaticPositionWrapperStyle: (theme: Theme) => {
14
+ justifyContent: string;
15
+ display: "inline-flex";
16
+ flexDirection: "column";
17
+ alignItems: "center";
18
+ rowGap: 4;
19
+ inset: number;
20
+ };
21
+ export declare const getWithFullscreenPropWrapperStyle: (spinning: boolean) => (theme: Theme) => {
22
+ justifyContent: string;
23
+ display: "inline-flex";
24
+ flexDirection: "column";
25
+ alignItems: "center";
26
+ rowGap: 4;
27
+ inset: number;
28
+ position: string;
29
+ backgroundColor: `rgba(${number}, ${number}, ${number}, 0.4)`;
30
+ width: string;
31
+ height: string;
32
+ visibility: string;
33
+ zIndex: number;
34
+ };
35
+ export declare const withChildrenPropWrapperStyle: (theme: Theme) => {
36
+ justifyContent: string;
37
+ display: "inline-flex";
38
+ flexDirection: "column";
39
+ alignItems: "center";
40
+ rowGap: 4;
41
+ inset: number;
42
+ position: string;
43
+ zIndex: number;
44
+ };
45
+ export declare const getSpinWrapperStyle: (spinTokens: SpinTokens, size: SpinSize) => {
46
+ display: string;
47
+ fontSize: number;
48
+ animation: string;
49
+ };
50
+ export declare const getForeignObjectSpinInnerStyle: (fullscreen: boolean) => (theme: Theme) => {
51
+ height: string;
52
+ backgroundImage: string;
53
+ };
54
+ export declare const getTipWrapperStyle: (fullscreen: boolean) => (theme: Theme) => {
55
+ color: "#FFFFFF" | "#0CB3B3";
56
+ fontFamily: "Roboto";
57
+ fontSize: 14;
58
+ lineHeight: "20px";
59
+ };
60
+ export declare const childrenWrapperStyle: {
61
+ readonly userSelect: "none";
62
+ readonly pointerEvents: "none";
63
+ readonly opacity: 0.5;
64
+ };
@@ -0,0 +1,66 @@
1
+ import { keyframes } from "@emotion/react";
2
+ import { getFontSizeBySize } from "./Spin.utils.js";
3
+ import { arr2String } from "../../utils/converter/common.js";
4
+ import { white2Rgba } from "../../themes/baseTokens/const.js";
5
+ const containerStyle = {
6
+ position: "relative"
7
+ };
8
+ const baseWrapperStyle = (theme) => ({
9
+ display: "inline-flex",
10
+ flexDirection: "column",
11
+ alignItems: "center",
12
+ rowGap: theme.spaceXS
13
+ });
14
+ const nonStaticPositionWrapperStyle = (theme) => ({
15
+ inset: 0,
16
+ ...baseWrapperStyle(theme),
17
+ justifyContent: "center"
18
+ });
19
+ const getWithFullscreenPropWrapperStyle = (spinning) => (theme) => ({
20
+ position: "fixed",
21
+ backgroundColor: theme.bgMask,
22
+ width: "100vw",
23
+ height: "100vh",
24
+ visibility: spinning ? "visible" : "hidden",
25
+ zIndex: 2,
26
+ ...nonStaticPositionWrapperStyle(theme)
27
+ });
28
+ const withChildrenPropWrapperStyle = (theme) => ({
29
+ position: "absolute",
30
+ zIndex: 1,
31
+ ...nonStaticPositionWrapperStyle(theme)
32
+ });
33
+ const fullRotateAnimationName = keyframes({
34
+ "100%": {
35
+ transform: "rotate(360deg)"
36
+ }
37
+ });
38
+ const getSpinWrapperStyle = (spinTokens, size) => ({
39
+ display: "inline-flex",
40
+ fontSize: getFontSizeBySize(spinTokens, size),
41
+ animation: `${fullRotateAnimationName} 0.5s infinite linear`
42
+ });
43
+ const getForeignObjectSpinInnerStyle = (fullscreen) => (theme) => ({
44
+ height: "100%",
45
+ backgroundImage: `conic-gradient(${arr2String(["from 30deg", ...fullscreen ? [`${theme.neutral10} 0deg`, `${white2Rgba(0)} 45deg`, `${theme.neutral10} 360deg`] : [`${theme.neutral100} 0deg`, `${white2Rgba(0)} 45deg`, `${theme.primaryBase} 225deg`, `${theme.neutral100} 360deg`]])})`
46
+ });
47
+ const getTipWrapperStyle = (fullscreen) => (theme) => ({
48
+ ...theme.typography.body2,
49
+ color: fullscreen ? theme.textContrast : theme.primaryBase
50
+ });
51
+ const childrenWrapperStyle = {
52
+ userSelect: "none",
53
+ pointerEvents: "none",
54
+ opacity: 0.5
55
+ };
56
+ export {
57
+ baseWrapperStyle,
58
+ childrenWrapperStyle,
59
+ containerStyle,
60
+ getForeignObjectSpinInnerStyle,
61
+ getSpinWrapperStyle,
62
+ getTipWrapperStyle,
63
+ getWithFullscreenPropWrapperStyle,
64
+ nonStaticPositionWrapperStyle,
65
+ withChildrenPropWrapperStyle
66
+ };
@@ -0,0 +1,6 @@
1
+ export declare const getSpinTokens: () => {
2
+ readonly spinSizeS: 16;
3
+ readonly spinSizeM: 24;
4
+ readonly spinSizeL: 32;
5
+ };
6
+ export type SpinTokens = ReturnType<typeof getSpinTokens>;
@@ -0,0 +1,8 @@
1
+ const getSpinTokens = () => ({
2
+ spinSizeS: 16,
3
+ spinSizeM: 24,
4
+ spinSizeL: 32
5
+ });
6
+ export {
7
+ getSpinTokens
8
+ };
@@ -0,0 +1,9 @@
1
+ import { PropsWithChildren, ReactNode } from 'react';
2
+ export interface SpinProps extends PropsWithChildren {
3
+ delay?: number;
4
+ fullscreen?: boolean;
5
+ size?: SpinSize;
6
+ spinning?: boolean;
7
+ tip?: ReactNode;
8
+ }
9
+ export type SpinSize = "small" | "middle" | "large";
@@ -0,0 +1,4 @@
1
+ import { SpinTokens } from './Spin.tokens';
2
+ import { SpinSize } from './Spin.types';
3
+ export declare const getFontSizeBySize: (spinTokens: SpinTokens, size: SpinSize) => number;
4
+ export declare const shouldDelay: (spinning: boolean, delay?: number) => boolean;
@@ -0,0 +1,11 @@
1
+ const fontSizeBySize = (spinTokens) => ({
2
+ small: spinTokens.spinSizeS,
3
+ middle: spinTokens.spinSizeM,
4
+ large: spinTokens.spinSizeL
5
+ });
6
+ const getFontSizeBySize = (spinTokens, size) => fontSizeBySize(spinTokens)[size];
7
+ const shouldDelay = (spinning, delay) => spinning && Boolean(delay) && !Number.isNaN(delay);
8
+ export {
9
+ getFontSizeBySize,
10
+ shouldDelay
11
+ };
@@ -0,0 +1,2 @@
1
+ import { FC } from 'react';
2
+ export declare const FullscreenExample: FC;
@@ -0,0 +1,2 @@
1
+ export { Spin } from './Spin';
2
+ export type { SpinProps } from './Spin.types';
package/dist/index.d.ts CHANGED
@@ -48,4 +48,5 @@ export type { TreeSelectProps } from './components/TreeSelect';
48
48
  export { type EmptyProps, Empty } from './components/Empty';
49
49
  export { type SegmentedProps, type SegmentedLabeledOption, Segmented, } from './components/Segmented';
50
50
  export { ContextIsolator } from './components/ContextIsolator';
51
+ export { type SpinProps, Spin } from './components/Spin';
51
52
  export * from 'react-intersection-observer/test-utils';
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ import { TreeSelect } from "./components/TreeSelect/TreeSelect.js";
36
36
  import { Empty } from "./components/Empty/Empty.js";
37
37
  import { Segmented } from "./components/Segmented/Segmented.js";
38
38
  import { ContextIsolator } from "./components/ContextIsolator/ContextIsolator.js";
39
+ import { Spin } from "./components/Spin/Spin.js";
39
40
  export {
40
41
  Alert,
41
42
  Avatar,
@@ -57,6 +58,7 @@ export {
57
58
  Radio,
58
59
  Segmented,
59
60
  Select,
61
+ Spin,
60
62
  Switch,
61
63
  Tabs,
62
64
  Tag,
@@ -0,0 +1 @@
1
+ export declare const arr2String: (arr: (string | number)[], separator?: string) => string;
@@ -0,0 +1,4 @@
1
+ const arr2String = (arr, separator = ", ") => arr.join(separator);
2
+ export {
3
+ arr2String
4
+ };
@@ -0,0 +1 @@
1
+ export { arr2String } from './common';
@@ -1,2 +1,3 @@
1
1
  export { getRgbaConverter, hex2Rgba } from './color';
2
2
  export { emptyString } from './const';
3
+ export { arr2String } from './converter';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infomaximum/ui-kit",
3
3
  "license": "Apache-2.0",
4
- "version": "0.14.11",
4
+ "version": "0.15.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",