Skip to content

Commit 7e8a7f6

Browse files
authored
Removing smart padding from quiet grid cards (#2768)
* removing closeToSquare styling from quiet grid cards * fix lint
1 parent 1098d68 commit 7e8a7f6

File tree

2 files changed

+2
-65
lines changed

2 files changed

+2
-65
lines changed

packages/@adobe/spectrum-css-temp/components/card/index.css

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -794,20 +794,9 @@ user-provided
794794
border-radius: var(--spectrum-card-quiet-border-radius);
795795
}
796796
}
797-
&:not(.spectrum-Card--closeToSquare) .spectrum-Card-image,
798-
&:not(.spectrum-Card--closeToSquare) .spectrum-Card-illustration {
799-
box-sizing: border-box; /* so that 100% counts padding as well */
800-
block-size: 100%;
801-
inline-size: 100%;
802-
min-inline-size: 100%; /* I do not know why setting a min-width causes the image to shrink */
803-
804-
align-self: center;
805-
justify-self: center;
806-
}
807-
&.spectrum-Card--closeToSquare .spectrum-Card-image,
808-
&.spectrum-Card--closeToSquare .spectrum-Card-illustration {
797+
.spectrum-Card-image,
798+
.spectrum-Card-illustration {
809799
box-sizing: border-box; /* so that 100% counts padding as well */
810-
padding: var(--spectrum-global-dimension-size-300);
811800
block-size: 100%;
812801
inline-size: 100%;
813802
min-inline-size: 100%; /* I do not know why setting a min-width causes the image to shrink */

packages/@react-spectrum/card/src/CardBase.tsx

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,57 +95,6 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
9595
detail: {UNSAFE_className: classNames(styles, 'spectrum-Card-detail')}
9696
}), [titleProps, contentProps, height, isQuiet, orientation]);
9797

98-
// This is only for quiet grid cards
99-
let [isCloseToSquare, setIsCloseToSquare] = useState(false);
100-
useLayoutEffect(() => {
101-
if (!(layout === 'grid' && isQuiet)) {
102-
return;
103-
}
104-
// ToDo: how to handle illustrations? what if the illustration looks like an image? What about swatches/fonts https://spectrum-contributions.corp.adobe.com/page/asset-card-beta/#File-type
105-
let image = gridRef.current.querySelector(`.${styles['spectrum-Card-image']} img`) as HTMLImageElement;
106-
if (!image) {
107-
return;
108-
}
109-
let measure = () => {
110-
let height = image.naturalHeight;
111-
let width = image.naturalWidth;
112-
/*
113-
* ToDo: Choose between min-padding and plain ratio
114-
* Do we want to just do a ratio measurement when it's close to being a square?
115-
* or do we want to actually figure out min-padding?
116-
* Min Padding would require us to check that the padding is not less than the min in both Vertical and Horizontal
117-
* Unfortunately img contain doesn't actually create padding, which is what this math below can figure out
118-
* Vs the commented out straight ratio check
119-
* */
120-
let imgTagHeight = image.clientHeight;
121-
let imgTagWidth = image.clientWidth;
122-
let ratio = Math.min(imgTagWidth / width, imgTagHeight / height);
123-
let trueHeight = ratio * height;
124-
let trueWidth = ratio * width;
125-
let paddingVertical = imgTagHeight - trueHeight;
126-
let paddingHorizontal = imgTagWidth - trueWidth;
127-
if (paddingVertical < 16 && paddingHorizontal < 16) { // ToDo: does this need to be different per scale?
128-
setIsCloseToSquare(true);
129-
} else {
130-
setIsCloseToSquare(false);
131-
}
132-
133-
// let ratio = height / width;
134-
// if (ratio > 0.9 && ratio < 1.1) {
135-
// setIsCloseToSquare(true);
136-
// }
137-
};
138-
if (image.complete) {
139-
measure();
140-
} else {
141-
image.addEventListener('load', measure);
142-
return () => {
143-
image.removeEventListener('load', measure);
144-
};
145-
}
146-
// ToDo: how to re-run if image src changes?
147-
}, [children, setIsCloseToSquare, isQuiet, layout]);
148-
14998
useLayoutEffect(() => {
15099
if (gridRef?.current) {
151100
let walker = getFocusableTreeWalker(gridRef.current);
@@ -170,7 +119,6 @@ function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDiv
170119
'spectrum-Card--default': !isQuiet && orientation !== 'horizontal',
171120
'spectrum-Card--isQuiet': isQuiet && orientation !== 'horizontal',
172121
'spectrum-Card--horizontal': orientation === 'horizontal',
173-
'spectrum-Card--closeToSquare': isCloseToSquare,
174122
'spectrum-Card--noPreview': !hasPreview,
175123
'is-hovered': isHovered,
176124
'is-focused': isFocused,

0 commit comments

Comments
 (0)