@udixio/ui-react 2.5.2 → 2.7.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.
- package/CHANGELOG.md +41 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +2566 -2264
- package/dist/lib/components/Button.d.ts.map +1 -1
- package/dist/lib/components/Card.d.ts.map +1 -1
- package/dist/lib/components/Carousel.d.ts +0 -2
- package/dist/lib/components/Carousel.d.ts.map +1 -1
- package/dist/lib/components/Fab.d.ts +1 -1
- package/dist/lib/components/Fab.d.ts.map +1 -1
- package/dist/lib/components/FabMenu.d.ts +9 -0
- package/dist/lib/components/FabMenu.d.ts.map +1 -0
- package/dist/lib/components/IconButton.d.ts.map +1 -1
- package/dist/lib/components/NavigationRail.d.ts.map +1 -1
- package/dist/lib/components/NavigationRailItem.d.ts.map +1 -1
- package/dist/lib/components/Tab.d.ts.map +1 -1
- package/dist/lib/components/ToolTip.d.ts.map +1 -1
- package/dist/lib/components/index.d.ts +1 -0
- package/dist/lib/components/index.d.ts.map +1 -1
- package/dist/lib/effects/AnimateOnScroll.d.ts.map +1 -1
- package/dist/lib/effects/State.d.ts +26 -0
- package/dist/lib/effects/State.d.ts.map +1 -0
- package/dist/lib/effects/index.d.ts +1 -0
- package/dist/lib/effects/index.d.ts.map +1 -1
- package/dist/lib/effects/ripple/RippleEffect.d.ts.map +1 -1
- package/dist/lib/interfaces/button.interface.d.ts +4 -1
- package/dist/lib/interfaces/button.interface.d.ts.map +1 -1
- package/dist/lib/interfaces/fab-menu.interface.d.ts +12 -0
- package/dist/lib/interfaces/fab-menu.interface.d.ts.map +1 -0
- package/dist/lib/interfaces/fab.interface.d.ts +2 -2
- package/dist/lib/interfaces/fab.interface.d.ts.map +1 -1
- package/dist/lib/interfaces/index.d.ts +1 -0
- package/dist/lib/interfaces/index.d.ts.map +1 -1
- package/dist/lib/interfaces/side-sheet.interface.d.ts +1 -1
- package/dist/lib/interfaces/side-sheet.interface.d.ts.map +1 -1
- package/dist/lib/styles/button.style.d.ts +43 -3
- package/dist/lib/styles/button.style.d.ts.map +1 -1
- package/dist/lib/styles/card.style.d.ts +9 -1
- package/dist/lib/styles/card.style.d.ts.map +1 -1
- package/dist/lib/styles/carousel-item.style.d.ts +11 -1
- package/dist/lib/styles/carousel-item.style.d.ts.map +1 -1
- package/dist/lib/styles/carousel.style.d.ts +16 -1
- package/dist/lib/styles/carousel.style.d.ts.map +1 -1
- package/dist/lib/styles/divider.style.d.ts +8 -2
- package/dist/lib/styles/divider.style.d.ts.map +1 -1
- package/dist/lib/styles/fab-menu.style.d.ts +83 -0
- package/dist/lib/styles/fab-menu.style.d.ts.map +1 -0
- package/dist/lib/styles/fab.style.d.ts +29 -5
- package/dist/lib/styles/fab.style.d.ts.map +1 -1
- package/dist/lib/styles/icon-button.style.d.ts +37 -1
- package/dist/lib/styles/icon-button.style.d.ts.map +1 -1
- package/dist/lib/styles/index.d.ts +2 -0
- package/dist/lib/styles/index.d.ts.map +1 -1
- package/dist/lib/styles/navigation-rail-item.style.d.ts +11 -1
- package/dist/lib/styles/navigation-rail-item.style.d.ts.map +1 -1
- package/dist/lib/styles/navigation-rail.style.d.ts +31 -1
- package/dist/lib/styles/navigation-rail.style.d.ts.map +1 -1
- package/dist/lib/styles/progress-indicator.style.d.ts +12 -1
- package/dist/lib/styles/progress-indicator.style.d.ts.map +1 -1
- package/dist/lib/styles/side-sheet.style.d.ts +20 -3
- package/dist/lib/styles/side-sheet.style.d.ts.map +1 -1
- package/dist/lib/styles/slider.style.d.ts +21 -2
- package/dist/lib/styles/slider.style.d.ts.map +1 -1
- package/dist/lib/styles/snackbar.style.d.ts +14 -3
- package/dist/lib/styles/snackbar.style.d.ts.map +1 -1
- package/dist/lib/styles/switch.style.d.ts +14 -2
- package/dist/lib/styles/switch.style.d.ts.map +1 -1
- package/dist/lib/styles/tab.style.d.ts +12 -2
- package/dist/lib/styles/tab.style.d.ts.map +1 -1
- package/dist/lib/styles/tabs.style.d.ts +17 -2
- package/dist/lib/styles/tabs.style.d.ts.map +1 -1
- package/dist/lib/styles/text-field.style.d.ts +23 -2
- package/dist/lib/styles/text-field.style.d.ts.map +1 -1
- package/dist/lib/styles/tooltip.style.d.ts +20 -3
- package/dist/lib/styles/tooltip.style.d.ts.map +1 -1
- package/dist/lib/utils/styles/get-classname.d.ts +3 -0
- package/dist/lib/utils/styles/get-classname.d.ts.map +1 -1
- package/dist/lib/utils/styles/index.d.ts +1 -0
- package/dist/lib/utils/styles/index.d.ts.map +1 -1
- package/dist/lib/utils/styles/use-classnames.d.ts +6 -0
- package/dist/lib/utils/styles/use-classnames.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/lib/components/Button.tsx +54 -20
- package/src/lib/components/Card.tsx +11 -9
- package/src/lib/components/Carousel.tsx +70 -205
- package/src/lib/components/CarouselItem.tsx +2 -2
- package/src/lib/components/Divider.tsx +2 -2
- package/src/lib/components/Fab.tsx +22 -21
- package/src/lib/components/FabMenu.tsx +229 -0
- package/src/lib/components/IconButton.tsx +24 -30
- package/src/lib/components/NavigationRail.tsx +7 -4
- package/src/lib/components/NavigationRailItem.tsx +13 -4
- package/src/lib/components/ProgressIndicator.tsx +2 -2
- package/src/lib/components/SideSheet.tsx +2 -2
- package/src/lib/components/Slider.tsx +2 -2
- package/src/lib/components/Snackbar.tsx +2 -2
- package/src/lib/components/Switch.tsx +2 -2
- package/src/lib/components/Tab.tsx +11 -11
- package/src/lib/components/Tabs.tsx +2 -2
- package/src/lib/components/TextField.tsx +2 -2
- package/src/lib/components/ToolTip.tsx +9 -3
- package/src/lib/components/index.ts +1 -0
- package/src/lib/effects/AnimateOnScroll.ts +51 -18
- package/src/lib/effects/State.tsx +83 -0
- package/src/lib/effects/index.ts +1 -0
- package/src/lib/effects/ripple/RippleEffect.tsx +40 -27
- package/src/lib/interfaces/button.interface.ts +5 -1
- package/src/lib/interfaces/fab-menu.interface.ts +12 -0
- package/src/lib/interfaces/fab.interface.ts +8 -2
- package/src/lib/interfaces/index.ts +1 -0
- package/src/lib/interfaces/side-sheet.interface.tsx +1 -1
- package/src/lib/styles/button.style.ts +127 -136
- package/src/lib/styles/card.style.ts +22 -17
- package/src/lib/styles/carousel-item.style.ts +23 -9
- package/src/lib/styles/carousel.style.ts +17 -5
- package/src/lib/styles/divider.style.ts +27 -13
- package/src/lib/styles/fab-menu.style.ts +28 -0
- package/src/lib/styles/fab.style.ts +41 -43
- package/src/lib/styles/icon-button.style.ts +160 -149
- package/src/lib/styles/index.ts +2 -0
- package/src/lib/styles/navigation-rail-item.style.ts +49 -40
- package/src/lib/styles/navigation-rail.style.ts +31 -15
- package/src/lib/styles/progress-indicator.style.ts +49 -36
- package/src/lib/styles/side-sheet.style.ts +41 -27
- package/src/lib/styles/slider.style.ts +37 -23
- package/src/lib/styles/snackbar.style.ts +22 -10
- package/src/lib/styles/switch.style.ts +61 -45
- package/src/lib/styles/tab.style.ts +76 -66
- package/src/lib/styles/tabs.style.ts +19 -10
- package/src/lib/styles/text-field.style.ts +108 -97
- package/src/lib/styles/tooltip.style.ts +42 -33
- package/src/lib/utils/styles/get-classname.ts +23 -0
- package/src/lib/utils/styles/index.ts +1 -0
- package/src/lib/utils/styles/use-classnames.ts +25 -0
- package/src/tests/useClassNames.spec.tsx +82 -0
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import { classNames, ReactProps } from '../utils';
|
|
2
2
|
import { ButtonInterface } from '../interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { useButtonStyle } from '../styles';
|
|
4
4
|
import { Icon } from '../icon';
|
|
5
5
|
import { ProgressIndicator } from './ProgressIndicator';
|
|
6
|
-
import {
|
|
6
|
+
import { State } from '../effects';
|
|
7
7
|
import React, { useEffect, useRef } from 'react';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Resolves variant aliases to their actual variant values
|
|
11
|
+
*/
|
|
12
|
+
function resolveVariantAlias(
|
|
13
|
+
variant?:
|
|
14
|
+
| 'filled'
|
|
15
|
+
| 'elevated'
|
|
16
|
+
| 'tonal'
|
|
17
|
+
| 'outlined'
|
|
18
|
+
| 'text'
|
|
19
|
+
| 'primary'
|
|
20
|
+
| 'secondary',
|
|
21
|
+
): 'filled' | 'elevated' | 'tonal' | 'outlined' | 'text' {
|
|
22
|
+
const aliasMap = {
|
|
23
|
+
primary: 'filled',
|
|
24
|
+
secondary: 'tonal',
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
if (variant && variant in aliasMap) {
|
|
28
|
+
return aliasMap[variant as keyof typeof aliasMap];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
(variant as 'filled' | 'elevated' | 'tonal' | 'outlined' | 'text') ||
|
|
33
|
+
'filled'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
9
37
|
/**
|
|
10
38
|
* Buttons prompt most actions in a UI
|
|
11
39
|
* @status beta
|
|
@@ -38,6 +66,7 @@ export const Button = ({
|
|
|
38
66
|
'Button component requires either a label prop or children content',
|
|
39
67
|
);
|
|
40
68
|
}
|
|
69
|
+
variant = resolveVariantAlias(variant);
|
|
41
70
|
|
|
42
71
|
const ElementType = href ? 'a' : 'button';
|
|
43
72
|
|
|
@@ -72,7 +101,7 @@ export const Button = ({
|
|
|
72
101
|
onToggle(next);
|
|
73
102
|
};
|
|
74
103
|
}
|
|
75
|
-
const styles =
|
|
104
|
+
const styles = useButtonStyle({
|
|
76
105
|
allowShapeTransformation,
|
|
77
106
|
size,
|
|
78
107
|
disableTextMargins,
|
|
@@ -109,25 +138,30 @@ export const Button = ({
|
|
|
109
138
|
style={{ transition: transition.duration + 's' }}
|
|
110
139
|
>
|
|
111
140
|
<div className={styles.touchTarget}></div>
|
|
112
|
-
<
|
|
113
|
-
className={styles.stateLayer}
|
|
141
|
+
<State
|
|
114
142
|
style={{ transition: transition.duration + 's' }}
|
|
115
|
-
|
|
116
|
-
{
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
143
|
+
className={styles.stateLayer}
|
|
144
|
+
colorName={classNames(
|
|
145
|
+
variant === 'filled' && {
|
|
146
|
+
'on-surface-variant': !isActive && Boolean(onToggle),
|
|
147
|
+
'on-primary': isActive || !onToggle,
|
|
148
|
+
},
|
|
149
|
+
variant === 'elevated' && {
|
|
150
|
+
'on-primary': isActive && Boolean(onToggle),
|
|
151
|
+
primary: !isActive || !onToggle,
|
|
152
|
+
},
|
|
153
|
+
variant === 'tonal' && {
|
|
154
|
+
'on-secondary': isActive && Boolean(onToggle),
|
|
155
|
+
'on-secondary-container': !isActive || !onToggle,
|
|
156
|
+
},
|
|
157
|
+
variant === 'outlined' && {
|
|
158
|
+
'inverse-on-surface': isActive && Boolean(onToggle),
|
|
159
|
+
'on-surface-variant': !isActive || !onToggle,
|
|
160
|
+
},
|
|
161
|
+
variant === 'text' && 'primary',
|
|
129
162
|
)}
|
|
130
|
-
|
|
163
|
+
stateClassName={'state-ripple-group-[button]'}
|
|
164
|
+
/>
|
|
131
165
|
|
|
132
166
|
{iconPosition === 'left' && iconElement}
|
|
133
167
|
{loading && (
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import { RippleEffect } from '../effects/ripple';
|
|
4
2
|
import { CardInterface } from '../interfaces';
|
|
5
|
-
import {
|
|
3
|
+
import { useCardStyle } from '../styles';
|
|
6
4
|
import { ReactProps } from '../utils';
|
|
5
|
+
import { State } from '../effects';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Cards display content and actions about a single subject
|
|
@@ -18,18 +17,21 @@ export const Card = ({
|
|
|
18
17
|
ref,
|
|
19
18
|
...rest
|
|
20
19
|
}: ReactProps<CardInterface>) => {
|
|
21
|
-
const styles =
|
|
20
|
+
const styles = useCardStyle({ className, isInteractive, variant, children });
|
|
22
21
|
|
|
23
22
|
const defaultRef = useRef<HTMLDivElement>(null);
|
|
24
23
|
const resolvedRef = ref || defaultRef;
|
|
25
24
|
|
|
26
25
|
return (
|
|
27
26
|
<div {...rest} ref={resolvedRef} className={styles.card}>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
{isInteractive && (
|
|
28
|
+
<State
|
|
29
|
+
className={styles.stateLayer}
|
|
30
|
+
colorName={'on-surface'}
|
|
31
|
+
stateClassName={'state-ripple-group-[card]'}
|
|
32
|
+
/>
|
|
33
|
+
)}
|
|
34
|
+
|
|
33
35
|
{children}
|
|
34
36
|
</div>
|
|
35
37
|
);
|
|
@@ -2,19 +2,21 @@ import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import { animate } from 'motion/react';
|
|
3
3
|
import { CarouselInterface, CarouselItemInterface } from '../interfaces';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useCarouselStyle } from '../styles';
|
|
6
6
|
import { CustomScroll } from '../effects';
|
|
7
7
|
import { ReactProps } from '../utils';
|
|
8
8
|
import { CarouselItem, normalize } from './CarouselItem';
|
|
9
9
|
|
|
10
|
+
function clamp(v: number, min: number, max: number) {
|
|
11
|
+
return Math.max(min, Math.min(max, v));
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Carousels show a collection of items that can be scrolled on and off the screen
|
|
12
16
|
*
|
|
13
17
|
* @status beta
|
|
14
18
|
* @category Layout
|
|
15
19
|
* @limitations
|
|
16
|
-
* - At the end of the scroll, a residual gap/space may remain visible.
|
|
17
|
-
* - In/out behavior is inconsistent at range edges.
|
|
18
20
|
* - Responsive behavior on mobile is not supported.
|
|
19
21
|
* - Only the default (hero) variant is supported.
|
|
20
22
|
*/
|
|
@@ -38,7 +40,7 @@ export const Carousel = ({
|
|
|
38
40
|
|
|
39
41
|
const [translateX, setTranslateX] = useState(0);
|
|
40
42
|
|
|
41
|
-
const styles =
|
|
43
|
+
const styles = useCarouselStyle({
|
|
42
44
|
index,
|
|
43
45
|
className,
|
|
44
46
|
children,
|
|
@@ -49,6 +51,7 @@ export const Carousel = ({
|
|
|
49
51
|
onChange,
|
|
50
52
|
gap,
|
|
51
53
|
scrollSensitivity,
|
|
54
|
+
onMetricsChange,
|
|
52
55
|
});
|
|
53
56
|
|
|
54
57
|
const items = React.Children.toArray(children).filter(
|
|
@@ -79,7 +82,6 @@ export const Carousel = ({
|
|
|
79
82
|
|
|
80
83
|
const scrollVisible =
|
|
81
84
|
scroll?.scrollVisible ?? (ref.current as any)?.clientWidth ?? 0;
|
|
82
|
-
// const scrollProgress = scrollMV.get();
|
|
83
85
|
|
|
84
86
|
function assignRelativeIndexes(
|
|
85
87
|
values: number[],
|
|
@@ -90,13 +92,16 @@ export const Carousel = ({
|
|
|
90
92
|
index: number;
|
|
91
93
|
width: number;
|
|
92
94
|
}[] {
|
|
93
|
-
return values.map((value, index) =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
return values.map((value, index) => {
|
|
96
|
+
const relativeIndex =
|
|
97
|
+
(value - progressScroll) / Math.abs(values[1] - values[0]);
|
|
98
|
+
return {
|
|
99
|
+
itemScrollXCenter: value,
|
|
100
|
+
relativeIndex,
|
|
101
|
+
index: index,
|
|
102
|
+
width: 0,
|
|
103
|
+
};
|
|
104
|
+
});
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
const itemsScrollXCenter = items.map((_, index) => {
|
|
@@ -113,206 +118,85 @@ export const Carousel = ({
|
|
|
113
118
|
itemsScrollXCenter,
|
|
114
119
|
scroll?.scrollProgress ?? 0,
|
|
115
120
|
).sort((a, b) => a.index - b.index);
|
|
116
|
-
// const visible =
|
|
117
|
-
// ((ref.current?.clientWidth ?? scrollVisible) - (outputRange[0] + gap)) /
|
|
118
|
-
// (outputRange[1] + gap);
|
|
119
|
-
|
|
120
|
-
const visible =
|
|
121
|
-
((ref.current?.clientWidth ?? scrollVisible) + gap) /
|
|
122
|
-
(outputRange[1] + gap);
|
|
123
121
|
|
|
124
|
-
let
|
|
125
|
-
|
|
126
|
-
let selectedItem;
|
|
122
|
+
let widthLeft =
|
|
123
|
+
(ref.current?.clientWidth ?? scrollVisible) + gap + outputRange[0] + gap;
|
|
127
124
|
|
|
128
125
|
const visibleItemValues = itemValues
|
|
129
126
|
.sort((a, b) => Math.abs(a.relativeIndex) - Math.abs(b.relativeIndex))
|
|
130
127
|
.map((item, index) => {
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
if (widthLeft <= 0) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
if (index == 0) {
|
|
134
132
|
setSelectedItem(item.index);
|
|
135
|
-
selectedItem = item;
|
|
136
133
|
}
|
|
137
134
|
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
item.width = normalize(
|
|
136
|
+
widthLeft - gap,
|
|
137
|
+
[outputRange[0], outputRange[1]],
|
|
138
|
+
[outputRange[0], outputRange[1]],
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
widthLeft -= item.width + gap;
|
|
140
142
|
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
if (widthLeft != 0 && widthLeft < (outputRange[0] + gap) * 2) {
|
|
144
|
+
const newWidth =
|
|
145
|
+
item.width - ((outputRange[0] + gap) * 2 - widthLeft);
|
|
146
|
+
|
|
147
|
+
widthLeft += item.width;
|
|
148
|
+
item.width = newWidth;
|
|
149
|
+
widthLeft -= item.width;
|
|
150
|
+
} else if (widthLeft == 0 && item.width >= outputRange[0] * 2 + gap) {
|
|
151
|
+
const newWidth = item.width - (outputRange[0] + gap - widthLeft);
|
|
146
152
|
|
|
147
|
-
|
|
153
|
+
widthLeft += item.width;
|
|
154
|
+
item.width = newWidth;
|
|
155
|
+
widthLeft -= item.width;
|
|
156
|
+
}
|
|
148
157
|
return item;
|
|
149
158
|
})
|
|
150
|
-
.filter(Boolean)
|
|
151
|
-
.sort((a, b) => a.index - b.index) as {
|
|
159
|
+
.filter(Boolean) as unknown as {
|
|
152
160
|
itemScrollXCenter: number;
|
|
153
161
|
relativeIndex: number;
|
|
154
162
|
index: number;
|
|
155
163
|
width: number;
|
|
156
164
|
}[];
|
|
157
165
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (item.width == outputRange[1]) {
|
|
163
|
-
if (index === 0 || index === array.length - 1) {
|
|
164
|
-
isDynamic = true;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (isDynamic) {
|
|
168
|
-
return true;
|
|
169
|
-
} else {
|
|
170
|
-
widthLeft -= item.width + gap;
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
166
|
+
const reverseItemsVisible = visibleItemValues.reverse();
|
|
167
|
+
const itemsVisibleByIndex = [...visibleItemValues].sort(
|
|
168
|
+
(a, b) => Math.abs(a.index) - Math.abs(b.index),
|
|
169
|
+
);
|
|
174
170
|
|
|
175
|
-
//
|
|
171
|
+
//dynamic items
|
|
176
172
|
|
|
177
|
-
|
|
173
|
+
reverseItemsVisible.forEach((item, index) => {
|
|
174
|
+
const nextItem = reverseItemsVisible[index + 1];
|
|
175
|
+
if (!nextItem) return;
|
|
178
176
|
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
const test =
|
|
178
|
+
1 - (Math.abs(item.relativeIndex) - Math.abs(nextItem?.relativeIndex));
|
|
181
179
|
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
[0,
|
|
185
|
-
[
|
|
180
|
+
const newWidth = normalize(
|
|
181
|
+
test,
|
|
182
|
+
[0, 2],
|
|
183
|
+
[item.width + widthLeft, nextItem.width],
|
|
186
184
|
);
|
|
187
|
-
item.width = result;
|
|
188
|
-
dynamicWidth += result;
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// let widthLeft =
|
|
192
|
-
// (visible -
|
|
193
|
-
// visibleItemValues
|
|
194
|
-
// .slice(0, visibleItemValues.length - 2)
|
|
195
|
-
// .filter((item) => item.width === outputRange[1]).length) *
|
|
196
|
-
// outputRange[1];
|
|
197
|
-
|
|
198
|
-
// console.log(
|
|
199
|
-
// visible,
|
|
200
|
-
// widthLeft,
|
|
201
|
-
// visibleItemValues
|
|
202
|
-
// .slice(0, visibleItemValues.length - 2)
|
|
203
|
-
// .filter((item) => item.width === outputRange[1]).length,
|
|
204
|
-
// );
|
|
205
|
-
|
|
206
|
-
let translate = 0;
|
|
207
|
-
dynamicItems.forEach((item, index) => {
|
|
208
|
-
if (!item) return;
|
|
209
|
-
|
|
210
|
-
if (index == 0) {
|
|
211
|
-
const percent = normalize(
|
|
212
|
-
item?.relativeIndex,
|
|
213
|
-
[-2, item.index == 0 ? 0 : -1],
|
|
214
|
-
[0, 1],
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
if (item.index >= 1) {
|
|
218
|
-
itemValues.sort((a, b) => a.index - b.index);
|
|
219
185
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
translate = normalize(
|
|
225
|
-
1 - percent,
|
|
226
|
-
[0, 1],
|
|
227
|
-
[0, -(outputRange[0] + gap)],
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
widthLeft -= translate;
|
|
231
|
-
|
|
232
|
-
// let relative = selectedItem?.relativeIndex * 2;
|
|
233
|
-
// relative = relative > 0 ? (1 - relative) * -1 : 1 + relative;
|
|
234
|
-
|
|
235
|
-
item.width = normalize(
|
|
236
|
-
percent,
|
|
237
|
-
[0, 1],
|
|
238
|
-
[outputRange[0], outputRange[1]],
|
|
239
|
-
);
|
|
240
|
-
|
|
241
|
-
widthLeft -= item.width;
|
|
242
|
-
|
|
243
|
-
// console.log(widthLeft);
|
|
244
|
-
} else {
|
|
245
|
-
let dynamicIndex = item.index;
|
|
246
|
-
// console.log('n', dynamicIndex, widthLeft);
|
|
247
|
-
let isEnd = dynamicIndex == itemValues.length - 1;
|
|
248
|
-
const isNearEnd = dynamicIndex == itemValues.length - 2;
|
|
249
|
-
// console.log('start');
|
|
250
|
-
while (widthLeft > 0) {
|
|
251
|
-
// console.log('boucle', widthLeft);
|
|
252
|
-
const dynamicItem = itemValues.filter(
|
|
253
|
-
(item) => item.index === dynamicIndex,
|
|
254
|
-
)[0];
|
|
255
|
-
|
|
256
|
-
if (!dynamicItem) {
|
|
257
|
-
if (isEnd) {
|
|
258
|
-
throw new Error('dynamicItem not found');
|
|
259
|
-
}
|
|
260
|
-
// dynamicIndex = dynamicItems[0].index;
|
|
261
|
-
isEnd = true;
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
if (!visibleItemValues.includes(dynamicItem)) {
|
|
266
|
-
visibleItemValues.push(dynamicItem);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
dynamicItem.width = normalize(
|
|
270
|
-
widthLeft,
|
|
271
|
-
[outputRange[0], outputRange[1] + (gap + outputRange[0]) * 2],
|
|
272
|
-
[outputRange[0], outputRange[1]],
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
widthLeft -= dynamicItem.width + gap;
|
|
276
|
-
|
|
277
|
-
if (
|
|
278
|
-
(isNearEnd || isEnd) &&
|
|
279
|
-
dynamicItem.index == itemValues.length - 1
|
|
280
|
-
) {
|
|
281
|
-
let dynamicItemIndexStart = isEnd ? 1 : 1;
|
|
282
|
-
|
|
283
|
-
while (widthLeft > 0) {
|
|
284
|
-
const dynamicItemStart = visibleItemValues[dynamicItemIndexStart];
|
|
285
|
-
|
|
286
|
-
const width =
|
|
287
|
-
normalize(
|
|
288
|
-
dynamicItemStart.width + widthLeft,
|
|
289
|
-
[outputRange[0], outputRange[1]],
|
|
290
|
-
[outputRange[0], outputRange[1]],
|
|
291
|
-
) - dynamicItemStart.width;
|
|
292
|
-
|
|
293
|
-
dynamicItemStart.width += width;
|
|
294
|
-
widthLeft -= width;
|
|
295
|
-
|
|
296
|
-
dynamicItemIndexStart--;
|
|
297
|
-
// break;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
break;
|
|
301
|
-
} else {
|
|
302
|
-
dynamicIndex++;
|
|
303
|
-
}
|
|
304
|
-
// }
|
|
305
|
-
}
|
|
306
|
-
}
|
|
186
|
+
widthLeft += item.width;
|
|
187
|
+
item.width = newWidth;
|
|
188
|
+
widthLeft -= item.width;
|
|
189
|
+
});
|
|
307
190
|
|
|
308
|
-
|
|
191
|
+
const percentMax = visibleItemValues.length / 2;
|
|
192
|
+
const percent = normalize(
|
|
193
|
+
Math.abs(itemsVisibleByIndex[0].relativeIndex),
|
|
194
|
+
[itemsVisibleByIndex[0].index == 0 ? 0 : percentMax - 1, percentMax],
|
|
195
|
+
[0, 1],
|
|
196
|
+
);
|
|
309
197
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
// [0, 1],
|
|
313
|
-
// [0, visible * outputRange[1]],
|
|
314
|
-
// );
|
|
315
|
-
});
|
|
198
|
+
const translate =
|
|
199
|
+
normalize(percent, [0, 1], [0, 1]) * -(outputRange[0] + gap);
|
|
316
200
|
|
|
317
201
|
setTranslateX(translate);
|
|
318
202
|
|
|
@@ -414,25 +298,6 @@ export const Carousel = ({
|
|
|
414
298
|
);
|
|
415
299
|
});
|
|
416
300
|
|
|
417
|
-
// persistent motion value for scroll progress, driven by user scroll and programmatic centering
|
|
418
|
-
// const scrollMVRef = useRef(motionValue(0));
|
|
419
|
-
// const scrollMV = scrollMVRef.current;
|
|
420
|
-
|
|
421
|
-
// const transform = useTransform(
|
|
422
|
-
// scrollMV,
|
|
423
|
-
// [0, 1],
|
|
424
|
-
// [
|
|
425
|
-
// 0,
|
|
426
|
-
// 1 -
|
|
427
|
-
// (ref.current?.clientWidth ?? 0) / (trackRef?.current?.clientWidth ?? 0),
|
|
428
|
-
// ],
|
|
429
|
-
// );
|
|
430
|
-
|
|
431
|
-
// const percentTransform = useTransform(
|
|
432
|
-
// transform,
|
|
433
|
-
// (value) => `${-value * 100}%`,
|
|
434
|
-
// );
|
|
435
|
-
|
|
436
301
|
const handleScroll = (args: {
|
|
437
302
|
scrollProgress: number;
|
|
438
303
|
scrollTotal: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
2
|
import { CarouselItemInterface } from '../interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { useCarouselItemStyle } from '../styles';
|
|
4
4
|
import { MotionProps } from '../utils';
|
|
5
5
|
|
|
6
6
|
export const normalize = (
|
|
@@ -34,7 +34,7 @@ export const CarouselItem = ({
|
|
|
34
34
|
const defaultRef = useRef(null);
|
|
35
35
|
const ref: React.RefObject<null | HTMLDivElement> = optionalRef || defaultRef;
|
|
36
36
|
|
|
37
|
-
const styles =
|
|
37
|
+
const styles = useCarouselItemStyle({
|
|
38
38
|
className,
|
|
39
39
|
index,
|
|
40
40
|
width,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useDividerStyle } from '../styles';
|
|
2
2
|
import { DividerInterface } from '../interfaces';
|
|
3
3
|
import { ReactProps } from '../utils';
|
|
4
4
|
|
|
@@ -12,7 +12,7 @@ export const Divider = ({
|
|
|
12
12
|
className,
|
|
13
13
|
...restProps
|
|
14
14
|
}: ReactProps<DividerInterface>) => {
|
|
15
|
-
const styles =
|
|
15
|
+
const styles = useDividerStyle({ orientation, className });
|
|
16
16
|
|
|
17
17
|
return <hr className={styles.divider} {...restProps} />;
|
|
18
18
|
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { useRef } from 'react';
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
2
|
import { Icon } from '../icon';
|
|
3
|
-
|
|
4
|
-
import { RippleEffect } from '../effects/ripple';
|
|
5
3
|
import { AnimatePresence, motion } from 'motion/react';
|
|
6
4
|
import { FabInterface } from '../interfaces/fab.interface';
|
|
7
|
-
import {
|
|
5
|
+
import { useFabStyle } from '../styles/fab.style';
|
|
8
6
|
import { classNames } from '../utils';
|
|
9
7
|
import { ReactProps } from '../utils/component';
|
|
10
8
|
import { ToolTip } from './ToolTip';
|
|
9
|
+
import { State } from '../effects';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Floating action buttons (FABs) help people take primary actions
|
|
@@ -22,7 +21,7 @@ export const Fab = ({
|
|
|
22
21
|
href,
|
|
23
22
|
type,
|
|
24
23
|
icon,
|
|
25
|
-
|
|
24
|
+
extended = false,
|
|
26
25
|
ref,
|
|
27
26
|
transition,
|
|
28
27
|
children,
|
|
@@ -36,10 +35,10 @@ export const Fab = ({
|
|
|
36
35
|
}
|
|
37
36
|
const ElementType = href ? 'a' : 'button';
|
|
38
37
|
|
|
39
|
-
const styles =
|
|
38
|
+
const styles = useFabStyle({
|
|
40
39
|
href,
|
|
41
40
|
icon,
|
|
42
|
-
|
|
41
|
+
extended,
|
|
43
42
|
label,
|
|
44
43
|
size,
|
|
45
44
|
variant,
|
|
@@ -84,28 +83,30 @@ export const Fab = ({
|
|
|
84
83
|
{...(restProps as any)}
|
|
85
84
|
ref={resolvedRef}
|
|
86
85
|
href={href}
|
|
87
|
-
aria-label={
|
|
86
|
+
aria-label={extended ? undefined : label}
|
|
88
87
|
className={styles.fab}
|
|
89
88
|
>
|
|
90
89
|
<ToolTip
|
|
91
|
-
trigger={
|
|
90
|
+
trigger={extended ? null : undefined}
|
|
92
91
|
text={label}
|
|
93
92
|
targetRef={resolvedRef}
|
|
94
93
|
/>
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
<State
|
|
95
|
+
style={{ transition: transition.duration + 's' }}
|
|
96
|
+
className={styles.stateLayer}
|
|
97
|
+
colorName={classNames({
|
|
98
|
+
'on-primary': variant == 'primary',
|
|
99
|
+
'on-secondary': variant == 'secondary',
|
|
100
|
+
'on-tertiary': variant == 'tertiary',
|
|
101
|
+
'on-primary-container': variant == 'primaryContainer',
|
|
102
|
+
'on-secondary-container': variant == 'secondaryContainer',
|
|
103
|
+
'on-tertiary-container': variant == 'tertiaryContainer',
|
|
104
|
+
})}
|
|
105
|
+
stateClassName={'state-ripple-group-[fab]'}
|
|
106
|
+
/>
|
|
106
107
|
<Icon icon={icon} className={styles.icon} />
|
|
107
108
|
<AnimatePresence>
|
|
108
|
-
{
|
|
109
|
+
{extended && (
|
|
109
110
|
<motion.span
|
|
110
111
|
variants={labelVariants}
|
|
111
112
|
initial="hidden"
|