-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
/
CardOverflow.tsx
171 lines (160 loc) · 5.62 KB
/
CardOverflow.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { unstable_composeClasses as composeClasses } from '@mui/base';
import { OverridableComponent } from '@mui/types';
import { unstable_capitalize as capitalize } from '@mui/utils';
import { useThemeProps } from '../styles';
import styled from '../styles/styled';
import { getCardOverflowUtilityClass } from './cardOverflowClasses';
import { CardOverflowProps, CardOverflowTypeMap } from './CardOverflowProps';
import { CardRowContext } from '../Card/CardContext';
const useUtilityClasses = (ownerState: CardOverflowProps) => {
const { variant, color } = ownerState;
const slots = {
root: [
'root',
variant && `variant${capitalize(variant)}`,
color && `color${capitalize(color)}`,
],
};
return composeClasses(slots, getCardOverflowUtilityClass, {});
};
const CardOverflowRoot = styled('div', {
name: 'JoyCardOverflow',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})<{
ownerState: CardOverflowProps & {
row: boolean;
'data-first-child'?: string;
'data-last-child'?: string;
};
}>(({ theme, ownerState }) => {
const childRadius = 'calc(var(--CardOverflow-radius) - var(--variant-borderWidth, 0px))';
return [
ownerState.row
? {
'--AspectRatio-margin': 'calc(-1 * var(--Card-padding)) 0px',
marginTop: 'var(--CardOverflow-offset)',
marginBottom: 'var(--CardOverflow-offset)',
padding: 'var(--Card-padding) 0px',
borderRadius: 'var(--CardOverflow-radius)',
position: 'relative',
// use data-attribute instead of :first-child, :last-child to support zero config SSR (emotion)
...(ownerState['data-first-child'] !== undefined && {
'--AspectRatio-radius': `${childRadius} 0 0 ${childRadius}`,
borderTopRightRadius: 0,
borderBottomRightRadius: 0,
marginLeft: 'var(--CardOverflow-offset)',
}),
...(ownerState['data-last-child'] !== undefined && {
'--AspectRatio-radius': `0 ${childRadius} ${childRadius} 0`,
borderTopLeftRadius: 0,
borderBottomLeftRadius: 0,
marginRight: 'var(--CardOverflow-offset)',
}),
}
: {
'--AspectRatio-margin': '0px calc(-1 * var(--Card-padding))',
marginLeft: 'var(--CardOverflow-offset)',
marginRight: 'var(--CardOverflow-offset)',
padding: '0px var(--Card-padding)',
borderRadius: 'var(--CardOverflow-radius)',
position: 'relative',
// use data-attribute instead of :first-child, :last-child to support zero config SSR (emotion)
...(ownerState['data-first-child'] !== undefined && {
'--AspectRatio-radius': `${childRadius} ${childRadius} 0 0`,
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0,
marginTop: 'var(--CardOverflow-offset)',
}),
...(ownerState['data-last-child'] !== undefined && {
'--AspectRatio-radius': `0 0 ${childRadius} ${childRadius}`,
borderTopLeftRadius: 0,
borderTopRightRadius: 0,
marginBottom: 'var(--CardOverflow-offset)',
}),
},
theme.variants[ownerState.variant!]?.[ownerState.color!],
];
});
const CardOverflow = React.forwardRef(function CardOverflow(inProps, ref) {
const props = useThemeProps<typeof inProps & CardOverflowProps>({
props: inProps,
name: 'JoyCardOverflow',
});
const row = React.useContext(CardRowContext);
const {
className,
component = 'div',
children,
color = 'neutral',
variant = 'plain',
...other
} = props;
const ownerState = {
...props,
component,
color,
variant,
row,
};
const classes = useUtilityClasses(ownerState);
return (
<CardOverflowRoot
as={component}
ownerState={ownerState}
className={clsx(classes.root, className)}
ref={ref}
{...other}
>
{children}
</CardOverflowRoot>
);
}) as OverridableComponent<CardOverflowTypeMap>;
CardOverflow.propTypes /* remove-proptypes */ = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
/**
* Used to render icon or text elements inside the CardOverflow if `src` is not set.
* This can be an element, or just a string.
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
* @default 'neutral'
*/
color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
PropTypes.oneOf(['danger', 'info', 'neutral', 'primary', 'success', 'warning']),
PropTypes.string,
]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])),
PropTypes.func,
PropTypes.object,
]),
/**
* The variant to use.
* @default 'plain'
*/
variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
PropTypes.oneOf(['outlined', 'plain', 'soft', 'solid']),
PropTypes.string,
]),
} as any;
export default CardOverflow;