@basic-ui/material 1.0.0-alpha.43 → 1.0.0-alpha.44
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.
- package/build/esm/Chip/ButtonChip.d.ts +1 -1
- package/build/esm/Select/CustomContainerExample.d.ts +1 -1
- package/build/esm/Snackbar/Snackbar.d.ts +1 -1
- package/build/esm/Snackbar/Snackbar.js.map +1 -1
- package/build/esm/Snackbar/Stack.js.map +1 -1
- package/build/esm/Snackbar/index.js.map +1 -1
- package/build/esm/Snackbar/useSnackbarAnimation.js.map +1 -1
- package/build/esm/Table/TableHead.d.ts +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Snackbar/Snackbar.tsx +82 -82
- package/src/Snackbar/Stack.tsx +239 -239
- package/src/Snackbar/index.ts +3 -3
- package/src/Snackbar/useSnackbarAnimation.ts +170 -170
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
import type { CSSProperties, MutableRefObject } from 'react';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
|
|
4
|
-
import { EASING_STANDARD } from '../motion';
|
|
5
|
-
import { useStackItem } from './Stack';
|
|
6
|
-
|
|
7
|
-
const TRANSITION_TIME = 150;
|
|
8
|
-
const slideFromBottom = {
|
|
9
|
-
entering: (x: string, y: string) => ({
|
|
10
|
-
opacity: 0.6,
|
|
11
|
-
transform: `translate(${x}, calc(${y} + 100%))`,
|
|
12
|
-
}),
|
|
13
|
-
entered: (x: string, y: string) => ({
|
|
14
|
-
opacity: 1,
|
|
15
|
-
transform: `translate(${x}, ${y})`,
|
|
16
|
-
}),
|
|
17
|
-
exiting: (x: string, y: string) => ({
|
|
18
|
-
opacity: 1,
|
|
19
|
-
transform: `translate(${x}, calc(${y} - 100%))`,
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const slideFromTop = {
|
|
24
|
-
entering: (x: string, y: string) => ({
|
|
25
|
-
opacity: 0.6,
|
|
26
|
-
transform: `translate(${x}, calc(${y} - 100%))`,
|
|
27
|
-
}),
|
|
28
|
-
entered: (x: string, y: string) => ({
|
|
29
|
-
opacity: 1,
|
|
30
|
-
transform: `translate(${x}, ${y})`,
|
|
31
|
-
}),
|
|
32
|
-
exiting: (x: string, y: string) => ({
|
|
33
|
-
opacity: 1,
|
|
34
|
-
transform: `translate(${x}, calc(${y} + 100%))`,
|
|
35
|
-
}),
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const slideFromRight = {
|
|
39
|
-
entering: (x: string, y: string) => ({
|
|
40
|
-
opacity: 0.6,
|
|
41
|
-
transform: `translate(calc(${x} + 100%), ${y})`,
|
|
42
|
-
}),
|
|
43
|
-
entered: (x: string, y: string) => ({
|
|
44
|
-
opacity: 1,
|
|
45
|
-
transform: `translate(${x}, ${y})`,
|
|
46
|
-
}),
|
|
47
|
-
exiting: (x: string, y: string) => ({
|
|
48
|
-
opacity: 0.6,
|
|
49
|
-
transform: `translate(calc(${x} + 100%), ${y})`,
|
|
50
|
-
}),
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const slideFromLeft = {
|
|
54
|
-
entering: (x: string, y: string) => ({
|
|
55
|
-
opacity: 0.6,
|
|
56
|
-
transform: `translate(calc(${x} - 100%), ${y})`,
|
|
57
|
-
}),
|
|
58
|
-
entered: (x: string, y: string) => ({
|
|
59
|
-
opacity: 1,
|
|
60
|
-
transform: `translate(${x}, ${y})`,
|
|
61
|
-
}),
|
|
62
|
-
exiting: (x: string, y: string) => ({
|
|
63
|
-
opacity: 0.6,
|
|
64
|
-
transform: `translate(calc(${x} - 100%), ${y})`,
|
|
65
|
-
}),
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
type AnimationState = 'entering' | 'entered' | 'exiting';
|
|
69
|
-
const placements = {
|
|
70
|
-
'top-right': {
|
|
71
|
-
style: { top: 3, right: 3 },
|
|
72
|
-
animate: (state: AnimationState, translateY: number) =>
|
|
73
|
-
slideFromRight[state]('0px', `${translateY}px`),
|
|
74
|
-
},
|
|
75
|
-
'top-center': {
|
|
76
|
-
style: { top: 3, left: '50%' },
|
|
77
|
-
animate: (state: AnimationState, translateY: number) =>
|
|
78
|
-
slideFromBottom[state]('-50%', `${translateY}px`),
|
|
79
|
-
},
|
|
80
|
-
'top-left': {
|
|
81
|
-
style: { top: 3, left: 3 },
|
|
82
|
-
animate: (state: AnimationState, translateY: number) =>
|
|
83
|
-
slideFromLeft[state]('0px', `${translateY}px`),
|
|
84
|
-
},
|
|
85
|
-
'bottom-right': {
|
|
86
|
-
style: { bottom: 3, right: 3 },
|
|
87
|
-
animate: (state: AnimationState, translateY: number) =>
|
|
88
|
-
slideFromRight[state]('0px', `${-translateY}px`),
|
|
89
|
-
},
|
|
90
|
-
'bottom-center': {
|
|
91
|
-
style: { bottom: 3, left: '50%' },
|
|
92
|
-
animate: (state: AnimationState, translateY: number) =>
|
|
93
|
-
slideFromTop[state]('-50%', `${-translateY}px`),
|
|
94
|
-
},
|
|
95
|
-
'bottom-left': {
|
|
96
|
-
style: { bottom: 3, left: 3 },
|
|
97
|
-
animate: (state: AnimationState, translateY: number) =>
|
|
98
|
-
slideFromLeft[state]('0px', `${-translateY}px`),
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
const commonStyle = { position: 'fixed', zIndex: 'snackbar' };
|
|
102
|
-
|
|
103
|
-
function getTransition(timems: number) {
|
|
104
|
-
return `opacity ${timems}ms ${EASING_STANDARD},transform ${timems}ms ${EASING_STANDARD}`;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const defaultAnimation = {
|
|
108
|
-
style: {},
|
|
109
|
-
placementStyle: {},
|
|
110
|
-
onClose: undefined,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export function useSnackbarAnimation(
|
|
114
|
-
ref: MutableRefObject<HTMLDivElement | null>,
|
|
115
|
-
timeout: number
|
|
116
|
-
): {
|
|
117
|
-
style: CSSProperties;
|
|
118
|
-
placementStyle: CSSProperties;
|
|
119
|
-
onClose?: () => void;
|
|
120
|
-
} {
|
|
121
|
-
const stackItem = useStackItem({
|
|
122
|
-
ref,
|
|
123
|
-
closeTimeoutInMilliseconds: TRANSITION_TIME,
|
|
124
|
-
});
|
|
125
|
-
if (!stackItem) {
|
|
126
|
-
return defaultAnimation;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const { onClose, state, translateY = 0, placement } = stackItem;
|
|
130
|
-
const placementStyle = placements[placement].style;
|
|
131
|
-
const animateFn = placements[placement].animate;
|
|
132
|
-
|
|
133
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
const handler = setTimeout(() => {
|
|
136
|
-
onClose();
|
|
137
|
-
}, timeout);
|
|
138
|
-
return () => {
|
|
139
|
-
clearTimeout(handler);
|
|
140
|
-
};
|
|
141
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
142
|
-
}, [timeout]);
|
|
143
|
-
|
|
144
|
-
switch (state) {
|
|
145
|
-
case 'entering':
|
|
146
|
-
return {
|
|
147
|
-
style: { ...animateFn('entering', translateY), visibility: 'hidden' },
|
|
148
|
-
placementStyle: { ...(placementStyle as any), ...commonStyle },
|
|
149
|
-
onClose,
|
|
150
|
-
};
|
|
151
|
-
case 'entered':
|
|
152
|
-
return {
|
|
153
|
-
style: {
|
|
154
|
-
...animateFn('entered', translateY),
|
|
155
|
-
transition: getTransition(TRANSITION_TIME),
|
|
156
|
-
},
|
|
157
|
-
placementStyle: { ...(placementStyle as any), ...commonStyle },
|
|
158
|
-
onClose,
|
|
159
|
-
};
|
|
160
|
-
case 'exiting':
|
|
161
|
-
return {
|
|
162
|
-
style: {
|
|
163
|
-
...animateFn('exiting', translateY),
|
|
164
|
-
transition: getTransition(TRANSITION_TIME),
|
|
165
|
-
},
|
|
166
|
-
placementStyle: { ...(placementStyle as any), ...commonStyle },
|
|
167
|
-
onClose,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
1
|
+
import type { CSSProperties, MutableRefObject } from 'react';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
import { EASING_STANDARD } from '../motion';
|
|
5
|
+
import { useStackItem } from './Stack';
|
|
6
|
+
|
|
7
|
+
const TRANSITION_TIME = 150;
|
|
8
|
+
const slideFromBottom = {
|
|
9
|
+
entering: (x: string, y: string) => ({
|
|
10
|
+
opacity: 0.6,
|
|
11
|
+
transform: `translate(${x}, calc(${y} + 100%))`,
|
|
12
|
+
}),
|
|
13
|
+
entered: (x: string, y: string) => ({
|
|
14
|
+
opacity: 1,
|
|
15
|
+
transform: `translate(${x}, ${y})`,
|
|
16
|
+
}),
|
|
17
|
+
exiting: (x: string, y: string) => ({
|
|
18
|
+
opacity: 1,
|
|
19
|
+
transform: `translate(${x}, calc(${y} - 100%))`,
|
|
20
|
+
}),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const slideFromTop = {
|
|
24
|
+
entering: (x: string, y: string) => ({
|
|
25
|
+
opacity: 0.6,
|
|
26
|
+
transform: `translate(${x}, calc(${y} - 100%))`,
|
|
27
|
+
}),
|
|
28
|
+
entered: (x: string, y: string) => ({
|
|
29
|
+
opacity: 1,
|
|
30
|
+
transform: `translate(${x}, ${y})`,
|
|
31
|
+
}),
|
|
32
|
+
exiting: (x: string, y: string) => ({
|
|
33
|
+
opacity: 1,
|
|
34
|
+
transform: `translate(${x}, calc(${y} + 100%))`,
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const slideFromRight = {
|
|
39
|
+
entering: (x: string, y: string) => ({
|
|
40
|
+
opacity: 0.6,
|
|
41
|
+
transform: `translate(calc(${x} + 100%), ${y})`,
|
|
42
|
+
}),
|
|
43
|
+
entered: (x: string, y: string) => ({
|
|
44
|
+
opacity: 1,
|
|
45
|
+
transform: `translate(${x}, ${y})`,
|
|
46
|
+
}),
|
|
47
|
+
exiting: (x: string, y: string) => ({
|
|
48
|
+
opacity: 0.6,
|
|
49
|
+
transform: `translate(calc(${x} + 100%), ${y})`,
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const slideFromLeft = {
|
|
54
|
+
entering: (x: string, y: string) => ({
|
|
55
|
+
opacity: 0.6,
|
|
56
|
+
transform: `translate(calc(${x} - 100%), ${y})`,
|
|
57
|
+
}),
|
|
58
|
+
entered: (x: string, y: string) => ({
|
|
59
|
+
opacity: 1,
|
|
60
|
+
transform: `translate(${x}, ${y})`,
|
|
61
|
+
}),
|
|
62
|
+
exiting: (x: string, y: string) => ({
|
|
63
|
+
opacity: 0.6,
|
|
64
|
+
transform: `translate(calc(${x} - 100%), ${y})`,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
type AnimationState = 'entering' | 'entered' | 'exiting';
|
|
69
|
+
const placements = {
|
|
70
|
+
'top-right': {
|
|
71
|
+
style: { top: 3, right: 3 },
|
|
72
|
+
animate: (state: AnimationState, translateY: number) =>
|
|
73
|
+
slideFromRight[state]('0px', `${translateY}px`),
|
|
74
|
+
},
|
|
75
|
+
'top-center': {
|
|
76
|
+
style: { top: 3, left: '50%' },
|
|
77
|
+
animate: (state: AnimationState, translateY: number) =>
|
|
78
|
+
slideFromBottom[state]('-50%', `${translateY}px`),
|
|
79
|
+
},
|
|
80
|
+
'top-left': {
|
|
81
|
+
style: { top: 3, left: 3 },
|
|
82
|
+
animate: (state: AnimationState, translateY: number) =>
|
|
83
|
+
slideFromLeft[state]('0px', `${translateY}px`),
|
|
84
|
+
},
|
|
85
|
+
'bottom-right': {
|
|
86
|
+
style: { bottom: 3, right: 3 },
|
|
87
|
+
animate: (state: AnimationState, translateY: number) =>
|
|
88
|
+
slideFromRight[state]('0px', `${-translateY}px`),
|
|
89
|
+
},
|
|
90
|
+
'bottom-center': {
|
|
91
|
+
style: { bottom: 3, left: '50%' },
|
|
92
|
+
animate: (state: AnimationState, translateY: number) =>
|
|
93
|
+
slideFromTop[state]('-50%', `${-translateY}px`),
|
|
94
|
+
},
|
|
95
|
+
'bottom-left': {
|
|
96
|
+
style: { bottom: 3, left: 3 },
|
|
97
|
+
animate: (state: AnimationState, translateY: number) =>
|
|
98
|
+
slideFromLeft[state]('0px', `${-translateY}px`),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
const commonStyle = { position: 'fixed', zIndex: 'snackbar' };
|
|
102
|
+
|
|
103
|
+
function getTransition(timems: number) {
|
|
104
|
+
return `opacity ${timems}ms ${EASING_STANDARD},transform ${timems}ms ${EASING_STANDARD}`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const defaultAnimation = {
|
|
108
|
+
style: {},
|
|
109
|
+
placementStyle: {},
|
|
110
|
+
onClose: undefined,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export function useSnackbarAnimation(
|
|
114
|
+
ref: MutableRefObject<HTMLDivElement | null>,
|
|
115
|
+
timeout: number
|
|
116
|
+
): {
|
|
117
|
+
style: CSSProperties;
|
|
118
|
+
placementStyle: CSSProperties;
|
|
119
|
+
onClose?: () => void;
|
|
120
|
+
} {
|
|
121
|
+
const stackItem = useStackItem({
|
|
122
|
+
ref,
|
|
123
|
+
closeTimeoutInMilliseconds: TRANSITION_TIME,
|
|
124
|
+
});
|
|
125
|
+
if (!stackItem) {
|
|
126
|
+
return defaultAnimation;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const { onClose, state, translateY = 0, placement } = stackItem;
|
|
130
|
+
const placementStyle = placements[placement].style;
|
|
131
|
+
const animateFn = placements[placement].animate;
|
|
132
|
+
|
|
133
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const handler = setTimeout(() => {
|
|
136
|
+
onClose();
|
|
137
|
+
}, timeout);
|
|
138
|
+
return () => {
|
|
139
|
+
clearTimeout(handler);
|
|
140
|
+
};
|
|
141
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
142
|
+
}, [timeout]);
|
|
143
|
+
|
|
144
|
+
switch (state) {
|
|
145
|
+
case 'entering':
|
|
146
|
+
return {
|
|
147
|
+
style: { ...animateFn('entering', translateY), visibility: 'hidden' },
|
|
148
|
+
placementStyle: { ...(placementStyle as any), ...commonStyle },
|
|
149
|
+
onClose,
|
|
150
|
+
};
|
|
151
|
+
case 'entered':
|
|
152
|
+
return {
|
|
153
|
+
style: {
|
|
154
|
+
...animateFn('entered', translateY),
|
|
155
|
+
transition: getTransition(TRANSITION_TIME),
|
|
156
|
+
},
|
|
157
|
+
placementStyle: { ...(placementStyle as any), ...commonStyle },
|
|
158
|
+
onClose,
|
|
159
|
+
};
|
|
160
|
+
case 'exiting':
|
|
161
|
+
return {
|
|
162
|
+
style: {
|
|
163
|
+
...animateFn('exiting', translateY),
|
|
164
|
+
transition: getTransition(TRANSITION_TIME),
|
|
165
|
+
},
|
|
166
|
+
placementStyle: { ...(placementStyle as any), ...commonStyle },
|
|
167
|
+
onClose,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|