@sonardigital/carbon-ui 1.2.17 → 1.2.19
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/package.json +2 -1
- package/src/components/atoms/bounce/Bounce.tsx +55 -0
- package/src/components/atoms/bounce/index.ts +2 -0
- package/src/components/atoms/index.ts +2 -0
- package/src/components/atoms/pulsing-badge/PulsingBadge.tsx +106 -0
- package/src/components/atoms/pulsing-badge/index.ts +1 -0
- package/src/components/form/fields/FormNumber.tsx +33 -0
- package/src/components/form/fields/index.ts +1 -0
- package/src/components/inputs/Number.tsx +102 -0
- package/src/components/inputs/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonardigital/carbon-ui",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.19",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
+
"@base-ui/react": "^1.6.0",
|
|
55
56
|
"@emotion/react": "^11.14.0",
|
|
56
57
|
"@emotion/styled": "^11.14.1",
|
|
57
58
|
"@mui/icons-material": "^7.3.2",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { motion, useReducedMotion, type Transition } from 'framer-motion';
|
|
2
|
+
|
|
3
|
+
export type BounceProps = React.PropsWithChildren<{
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
tapScale?: number;
|
|
8
|
+
tapY?: number;
|
|
9
|
+
transition?: Transition;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export function Bounce({
|
|
13
|
+
children,
|
|
14
|
+
className,
|
|
15
|
+
style,
|
|
16
|
+
disabled = false,
|
|
17
|
+
tapScale = 0.98,
|
|
18
|
+
tapY = 0,
|
|
19
|
+
transition,
|
|
20
|
+
}: BounceProps): React.ReactElement {
|
|
21
|
+
const reducedMotion = useReducedMotion();
|
|
22
|
+
|
|
23
|
+
const effectiveDisabled = disabled || reducedMotion;
|
|
24
|
+
const effectiveTransition: Transition = transition ?? {
|
|
25
|
+
type: 'spring',
|
|
26
|
+
stiffness: 520,
|
|
27
|
+
damping: 22,
|
|
28
|
+
mass: 0.55,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<motion.span
|
|
33
|
+
className={className}
|
|
34
|
+
style={{
|
|
35
|
+
display: 'inline-flex',
|
|
36
|
+
willChange: effectiveDisabled ? undefined : 'transform',
|
|
37
|
+
transform: effectiveDisabled ? undefined : 'translateZ(0)',
|
|
38
|
+
backfaceVisibility: 'hidden',
|
|
39
|
+
transformOrigin: 'center',
|
|
40
|
+
...style,
|
|
41
|
+
}}
|
|
42
|
+
whileTap={
|
|
43
|
+
effectiveDisabled
|
|
44
|
+
? undefined
|
|
45
|
+
: {
|
|
46
|
+
...(tapScale != null ? { scale: tapScale } : null),
|
|
47
|
+
...(tapY ? { y: tapY } : null),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
transition={effectiveTransition}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
</motion.span>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Box, keyframes, type BoxProps } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
const pulseRing = keyframes`
|
|
4
|
+
0% {
|
|
5
|
+
transform: scale(1);
|
|
6
|
+
opacity: 0.5;
|
|
7
|
+
}
|
|
8
|
+
100% {
|
|
9
|
+
transform: scale(1.35);
|
|
10
|
+
opacity: 0;
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
const pulseScale = keyframes`
|
|
15
|
+
0%, 100% {
|
|
16
|
+
transform: scale(1);
|
|
17
|
+
}
|
|
18
|
+
50% {
|
|
19
|
+
transform: scale(1.04);
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export type PulsingBadgeProps = BoxProps & {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
showBadge?: boolean;
|
|
26
|
+
badgePosition?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
27
|
+
badgeSize?: number;
|
|
28
|
+
badgeColor?: string;
|
|
29
|
+
pulseContent?: boolean;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function PulsingBadge({
|
|
33
|
+
children,
|
|
34
|
+
showBadge = true,
|
|
35
|
+
badgePosition = 'top-right',
|
|
36
|
+
badgeSize = 10,
|
|
37
|
+
badgeColor = 'primary.main',
|
|
38
|
+
pulseContent = false,
|
|
39
|
+
sx,
|
|
40
|
+
...props
|
|
41
|
+
}: PulsingBadgeProps): React.ReactElement {
|
|
42
|
+
const badgeOffsets =
|
|
43
|
+
badgePosition === 'top-left'
|
|
44
|
+
? { top: -4, left: -4 }
|
|
45
|
+
: badgePosition === 'bottom-right'
|
|
46
|
+
? { bottom: -4, right: -4 }
|
|
47
|
+
: badgePosition === 'bottom-left'
|
|
48
|
+
? { bottom: -4, left: -4 }
|
|
49
|
+
: { top: -4, right: -4 };
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Box
|
|
53
|
+
{...props}
|
|
54
|
+
sx={{
|
|
55
|
+
position: 'relative',
|
|
56
|
+
display: 'inline-flex',
|
|
57
|
+
'& > *': {
|
|
58
|
+
position: 'relative',
|
|
59
|
+
zIndex: 1,
|
|
60
|
+
...(pulseContent
|
|
61
|
+
? { animation: `${pulseScale} 2s ease-in-out infinite` }
|
|
62
|
+
: null),
|
|
63
|
+
},
|
|
64
|
+
...(showBadge
|
|
65
|
+
? {
|
|
66
|
+
'& .PulsingBadge-badge': {
|
|
67
|
+
position: 'absolute',
|
|
68
|
+
zIndex: 2,
|
|
69
|
+
width: badgeSize,
|
|
70
|
+
height: badgeSize,
|
|
71
|
+
borderRadius: 999,
|
|
72
|
+
backgroundColor: badgeColor,
|
|
73
|
+
boxShadow: theme =>
|
|
74
|
+
`0 0 0 2px ${theme.palette.background.paper}`,
|
|
75
|
+
pointerEvents: 'none',
|
|
76
|
+
...badgeOffsets,
|
|
77
|
+
'&::before': {
|
|
78
|
+
content: '""',
|
|
79
|
+
position: 'absolute',
|
|
80
|
+
inset: -6,
|
|
81
|
+
borderRadius: 999,
|
|
82
|
+
border: '2px solid',
|
|
83
|
+
borderColor: badgeColor,
|
|
84
|
+
opacity: 0.6,
|
|
85
|
+
animation: `${pulseRing} 1.8s ease-out infinite`,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
: null),
|
|
90
|
+
'@media (prefers-reduced-motion: reduce)': {
|
|
91
|
+
'& .PulsingBadge-badge::before': {
|
|
92
|
+
animation: 'none',
|
|
93
|
+
opacity: 0,
|
|
94
|
+
},
|
|
95
|
+
'& > *': { animation: 'none' },
|
|
96
|
+
},
|
|
97
|
+
...sx,
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
{showBadge ? (
|
|
102
|
+
<Box component="span" className="PulsingBadge-badge" />
|
|
103
|
+
) : null}
|
|
104
|
+
</Box>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PulsingBadge';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Stack } from '@mui/material';
|
|
2
|
+
import { Controller } from 'react-hook-form';
|
|
3
|
+
import { FormLabel } from '../layout';
|
|
4
|
+
import { FormError } from '../layout/FormError';
|
|
5
|
+
import { NumberProps } from '../../inputs';
|
|
6
|
+
import { Number } from '../../inputs/Number';
|
|
7
|
+
|
|
8
|
+
interface FormNumberProps extends NumberProps {
|
|
9
|
+
name: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function FormNumber({
|
|
14
|
+
name,
|
|
15
|
+
label,
|
|
16
|
+
...props
|
|
17
|
+
}: FormNumberProps): React.ReactElement {
|
|
18
|
+
return (
|
|
19
|
+
<Controller
|
|
20
|
+
name={name}
|
|
21
|
+
render={({ field, fieldState }) => (
|
|
22
|
+
<FormLabel label={label}>
|
|
23
|
+
<Stack gap={0.8}>
|
|
24
|
+
<Number {...field} {...props} />
|
|
25
|
+
{fieldState.error && (
|
|
26
|
+
<FormError label={fieldState.error?.message ?? ''} />
|
|
27
|
+
)}
|
|
28
|
+
</Stack>
|
|
29
|
+
</FormLabel>
|
|
30
|
+
)}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { NumberField as BaseNumberField } from '@base-ui/react/number-field';
|
|
3
|
+
import IconButton from '@mui/material/IconButton';
|
|
4
|
+
import InputAdornment from '@mui/material/InputAdornment';
|
|
5
|
+
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
|
|
6
|
+
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
|
|
7
|
+
import { TextField } from '@mui/material';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This component is a placeholder for FormControl to correctly set the shrink label state on SSR.
|
|
11
|
+
*/
|
|
12
|
+
function SSRInitialFilled(_: BaseNumberField.Root.Props) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
SSRInitialFilled.muiName = 'Input';
|
|
16
|
+
|
|
17
|
+
export interface NumberProps extends Omit<
|
|
18
|
+
BaseNumberField.Root.Props,
|
|
19
|
+
'render' | 'label' | 'size'
|
|
20
|
+
> {
|
|
21
|
+
error?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Number({
|
|
25
|
+
id: idProp,
|
|
26
|
+
error,
|
|
27
|
+
...other
|
|
28
|
+
}: BaseNumberField.Root.Props & {
|
|
29
|
+
label?: React.ReactNode;
|
|
30
|
+
error?: boolean;
|
|
31
|
+
}) {
|
|
32
|
+
const size = 'medium';
|
|
33
|
+
|
|
34
|
+
let id = React.useId();
|
|
35
|
+
if (idProp) {
|
|
36
|
+
id = idProp;
|
|
37
|
+
}
|
|
38
|
+
return (
|
|
39
|
+
<BaseNumberField.Root {...other}>
|
|
40
|
+
<SSRInitialFilled {...other} />
|
|
41
|
+
<BaseNumberField.Input
|
|
42
|
+
id={id}
|
|
43
|
+
render={(props, state) => (
|
|
44
|
+
<TextField
|
|
45
|
+
aria-describedby={`${id}-helper-text`}
|
|
46
|
+
inputRef={props.ref}
|
|
47
|
+
value={state.inputValue}
|
|
48
|
+
onBlur={props.onBlur}
|
|
49
|
+
onChange={props.onChange}
|
|
50
|
+
onKeyUp={props.onKeyUp}
|
|
51
|
+
onKeyDown={props.onKeyDown}
|
|
52
|
+
onFocus={props.onFocus}
|
|
53
|
+
InputProps={{
|
|
54
|
+
inputProps: {
|
|
55
|
+
sx: {
|
|
56
|
+
height: 19,
|
|
57
|
+
fontWeight: 400,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
endAdornment: (
|
|
61
|
+
<InputAdornment
|
|
62
|
+
position="end"
|
|
63
|
+
sx={{
|
|
64
|
+
flexDirection: 'column',
|
|
65
|
+
maxHeight: 'unset',
|
|
66
|
+
alignSelf: 'stretch',
|
|
67
|
+
borderLeft: '1px solid',
|
|
68
|
+
borderColor: 'divider',
|
|
69
|
+
'& button': {
|
|
70
|
+
py: 0,
|
|
71
|
+
flex: 1,
|
|
72
|
+
borderRadius: 0.5,
|
|
73
|
+
},
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
<BaseNumberField.Increment
|
|
77
|
+
render={<IconButton aria-label="Increase" />}
|
|
78
|
+
>
|
|
79
|
+
<KeyboardArrowUpIcon
|
|
80
|
+
fontSize={size}
|
|
81
|
+
sx={{ transform: 'translateY(2px)' }}
|
|
82
|
+
/>
|
|
83
|
+
</BaseNumberField.Increment>
|
|
84
|
+
|
|
85
|
+
<BaseNumberField.Decrement
|
|
86
|
+
render={<IconButton aria-label="Decrease" />}
|
|
87
|
+
>
|
|
88
|
+
<KeyboardArrowDownIcon
|
|
89
|
+
fontSize={size}
|
|
90
|
+
sx={{ transform: 'translateY(-2px)' }}
|
|
91
|
+
/>
|
|
92
|
+
</BaseNumberField.Decrement>
|
|
93
|
+
</InputAdornment>
|
|
94
|
+
),
|
|
95
|
+
}}
|
|
96
|
+
sx={{ width: '100%' }}
|
|
97
|
+
/>
|
|
98
|
+
)}
|
|
99
|
+
/>
|
|
100
|
+
</BaseNumberField.Root>
|
|
101
|
+
);
|
|
102
|
+
}
|