Skip to content

Commit b04b7af

Browse files
committed
Merge branch 'main' of github.com:adobe/react-spectrum into style_macro_docs
2 parents 4ef4996 + 69b8ec6 commit b04b7af

File tree

126 files changed

+25172
-570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+25172
-570
lines changed

packages/@react-spectrum/s2/src/Calendar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {useSpectrumContextProps} from './useSpectrumContextProps';
5252

5353

5454
export interface CalendarProps<T extends DateValue>
55-
extends Omit<AriaCalendarProps<T>, 'visibleDuration' | 'style' | 'className' | 'styles' | keyof GlobalDOMAttributes>,
55+
extends Omit<AriaCalendarProps<T>, 'visibleDuration' | 'style' | 'className' | 'styles' | 'children' | keyof GlobalDOMAttributes>,
5656
StyleProps {
5757
/**
5858
* The error message to display when the calendar is invalid.

packages/@react-spectrum/s2/src/Card.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {AvatarContext} from './Avatar';
1515
import {ButtonContext, LinkButtonContext} from './Button';
1616
import {Checkbox} from './Checkbox';
1717
import {color, focusRing, lightDark, space, style} from '../style' with {type: 'macro'};
18-
import {composeRenderProps, ContextValue, DEFAULT_SLOT, type GridListItem, GridListItemProps, Provider} from 'react-aria-components';
18+
import {composeRenderProps, ContextValue, DEFAULT_SLOT, type GridListItem, GridListItemProps, Link, Provider} from 'react-aria-components';
1919
import {ContentContext, FooterContext, TextContext} from './Content';
2020
import {createContext, CSSProperties, forwardRef, ReactNode, useContext} from 'react';
2121
import {DividerContext} from './Divider';
@@ -95,18 +95,19 @@ let card = style({
9595
variant: {
9696
tertiary: {
9797
// Render border with box-shadow to avoid affecting layout.
98-
default: `[0 0 0 1px ${color('gray-100')}]`,
99-
isHovered: `[0 0 0 1px ${color('gray-200')}]`,
100-
isFocusVisible: `[0 0 0 1px ${color('gray-200')}]`,
98+
default: `[0 0 0 2px ${color('gray-100')}]`,
99+
isHovered: `[0 0 0 2px ${color('gray-200')}]`,
100+
isFocusVisible: `[0 0 0 2px ${color('gray-200')}]`,
101101
isSelected: 'none',
102-
forcedColors: '[0 0 0 1px ButtonBorder]'
102+
forcedColors: '[0 0 0 2px ButtonBorder]'
103103
},
104104
quiet: 'none'
105105
}
106106
},
107107
forcedColorAdjust: 'none',
108108
transition: 'default',
109109
fontFamily: 'sans',
110+
textDecoration: 'none',
110111
overflow: {
111112
default: 'clip',
112113
variant: {
@@ -424,6 +425,28 @@ export const Card = forwardRef(function Card(props: CardProps, ref: DOMRef<HTMLD
424425
</Provider>
425426
);
426427

428+
let press = pressScale(domRef, UNSAFE_style);
429+
if (ElementType === 'div' && !isSkeleton && props.href) {
430+
// Standalone Card that has an href should be rendered as a Link.
431+
// NOTE: In this case, the card must not contain interactive elements.
432+
return (
433+
<Link
434+
{...filterDOMProps(otherProps, {isLink: true})}
435+
ref={domRef as any}
436+
className={renderProps => UNSAFE_className + card({...renderProps, size, density, variant, isCardView: false, isLink: true}, styles)}
437+
style={renderProps =>
438+
// Only the preview in quiet cards scales down on press
439+
variant === 'quiet' ? UNSAFE_style : press(renderProps)
440+
}>
441+
{(renderProps) => (
442+
<InternalCardContext.Provider value={{size, isQuiet, isCheckboxSelection: false, isSelected: false, ...renderProps}}>
443+
{children}
444+
</InternalCardContext.Provider>
445+
)}
446+
</Link>
447+
);
448+
}
449+
427450
if (ElementType === 'div' || isSkeleton) {
428451
return (
429452
<div
@@ -441,7 +464,6 @@ export const Card = forwardRef(function Card(props: CardProps, ref: DOMRef<HTMLD
441464
);
442465
}
443466

444-
let press = pressScale(domRef, UNSAFE_style);
445467
return (
446468
<ElementType
447469
{...props}

packages/@react-spectrum/s2/src/Menu.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,12 @@ export function Divider(props: SeparatorProps): ReactNode {
409409
);
410410
}
411411

412-
export interface MenuSectionProps<T extends object> extends Omit<AriaMenuSectionProps<T>, keyof GlobalDOMAttributes> {}
412+
export interface MenuSectionProps<T extends object> extends Omit<AriaMenuSectionProps<T>, 'style' | 'className' | keyof GlobalDOMAttributes> {
413+
/**
414+
* The children of the menu section.
415+
*/
416+
children?: ReactNode
417+
}
413418
export function MenuSection<T extends object>(props: MenuSectionProps<T>): ReactNode {
414419
// remember, context doesn't work if it's around Section nor inside
415420
let {size} = useContext(InternalMenuContext);

packages/@react-spectrum/s2/src/Popover.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from 'react-aria-components';
2323
import {colorScheme, getAllowedOverrides, heightProperties, UnsafeStyles, widthProperties} from './style-utils' with {type: 'macro'};
2424
import {ColorSchemeContext} from './Provider';
25-
import {createContext, ForwardedRef, forwardRef, useCallback, useContext, useMemo} from 'react';
25+
import {createContext, ForwardedRef, forwardRef, ReactNode, useCallback, useContext, useMemo} from 'react';
2626
import {DOMRef, DOMRefValue, GlobalDOMAttributes} from '@react-types/shared';
2727
import {lightDark, style} from '../style' with {type: 'macro'};
2828
import {mergeRefs} from '@react-aria/utils';
@@ -31,7 +31,20 @@ import {StyleString} from '../style/types' with {type: 'macro'};
3131
import {useDOMRef} from '@react-spectrum/utils';
3232
import {useSpectrumContextProps} from './useSpectrumContextProps';
3333

34-
export interface PopoverProps extends UnsafeStyles, Omit<AriaPopoverProps, 'arrowSize' | 'isNonModal' | 'arrowBoundaryOffset' | 'isKeyboardDismissDisabled' | 'shouldCloseOnInteractOutside' | 'shouldUpdatePosition' | keyof GlobalDOMAttributes> {
34+
export interface PopoverProps extends UnsafeStyles, Omit<AriaPopoverProps,
35+
'arrowSize' |
36+
'isNonModal' |
37+
'arrowBoundaryOffset' |
38+
'isKeyboardDismissDisabled' |
39+
'shouldCloseOnInteractOutside' |
40+
'shouldUpdatePosition' |
41+
'style' |
42+
'className' |
43+
keyof GlobalDOMAttributes
44+
> {
45+
/**
46+
* The styles of the popover.
47+
*/
3548
styles?: StyleString,
3649
/**
3750
* Whether a popover's arrow should be hidden.
@@ -228,7 +241,22 @@ export const PopoverBase = forwardRef(function PopoverBase(props: PopoverProps,
228241
});
229242

230243
type PopoverStylesProp = StyleString<((typeof widthProperties)[number] | (typeof heightProperties)[number])>;
231-
export interface PopoverDialogProps extends Pick<PopoverProps, 'children' | 'size' | 'hideArrow'| 'placement' | 'shouldFlip' | 'containerPadding' | 'offset' | 'crossOffset' | 'triggerRef' | 'isOpen' | 'onOpenChange'>, Omit<DialogProps, 'children' | 'className' | 'style' | keyof GlobalDOMAttributes>, UnsafeStyles {
244+
export interface PopoverDialogProps extends Pick<PopoverProps,
245+
'size' |
246+
'hideArrow'|
247+
'placement' |
248+
'shouldFlip' |
249+
'containerPadding' |
250+
'offset' |
251+
'crossOffset' |
252+
'triggerRef' |
253+
'isOpen' |
254+
'onOpenChange'
255+
>, Omit<DialogProps, 'children' | 'className' | 'style' | keyof GlobalDOMAttributes>, UnsafeStyles {
256+
/**
257+
* The children of the popover.
258+
*/
259+
children?: ReactNode,
232260
/**
233261
* The amount of padding around the contents of the dialog.
234262
* @default 'default'

packages/@react-spectrum/s2/src/RangeCalendar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {useSpectrumContextProps} from './useSpectrumContextProps';
3434

3535

3636
export interface RangeCalendarProps<T extends DateValue>
37-
extends Omit<AriaRangeCalendarProps<T>, 'visibleDuration' | 'style' | 'className' | 'styles' | keyof GlobalDOMAttributes>,
37+
extends Omit<AriaRangeCalendarProps<T>, 'visibleDuration' | 'style' | 'className' | 'children' | 'styles' | keyof GlobalDOMAttributes>,
3838
StyleProps {
3939
/**
4040
* The error message to display when the calendar is invalid.

packages/@react-spectrum/s2/src/TableView.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ const columnStyles = style({
519519
forcedColorAdjust: 'none'
520520
});
521521

522-
export interface ColumnProps extends Omit<RACColumnProps, keyof GlobalDOMAttributes> {
522+
export interface ColumnProps extends Omit<RACColumnProps, 'style' | 'className' | keyof GlobalDOMAttributes> {
523523
/** Whether the column should render a divider between it and the next column. */
524524
showDivider?: boolean,
525525
/** Whether the column allows resizing. */
@@ -1017,7 +1017,7 @@ const cellContent = style({
10171017
}
10181018
});
10191019

1020-
export interface CellProps extends RACCellProps, Pick<ColumnProps, 'align' | 'showDivider'> {
1020+
export interface CellProps extends Omit<RACCellProps, 'style' | 'className' | keyof GlobalDOMAttributes>, Pick<ColumnProps, 'align' | 'showDivider'> {
10211021
/** @private */
10221022
isSticky?: boolean,
10231023
/** The content to render as the cell children. */
@@ -1410,6 +1410,9 @@ export const Row = /*#__PURE__*/ (forwardRef as forwardRefType)(function Row<T e
14101410
}) + (renderProps.isFocusVisible && ' ' + raw('&:before { content: ""; display: inline-block; position: sticky; inset-inline-start: 0; width: 3px; height: 100%; margin-inline-end: -3px; margin-block-end: 1px; z-index: 3; background-color: var(--rowFocusIndicatorColor)'))}
14111411
{...otherProps}>
14121412
{selectionMode !== 'none' && selectionBehavior === 'toggle' && (
1413+
// Not sure what we want to do with this className, in Cell it currently overrides the className that would have been applied.
1414+
// The `spread` otherProps must be after className in Cell.
1415+
// @ts-ignore
14131416
<Cell isSticky className={checkboxCellStyle}>
14141417
<Checkbox isEmphasized slot="selection" />
14151418
</Cell>

packages/@react-spectrum/s2/src/Toast.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {useMediaQuery} from '@react-spectrum/utils';
3434
import {useOverlayTriggerState} from 'react-stately';
3535

3636
export type ToastPlacement = 'top' | 'top end' | 'bottom' | 'bottom end';
37-
export interface ToastContainerProps extends Omit<ToastRegionProps<SpectrumToastValue>, 'queue' | 'children'> {
37+
export interface ToastContainerProps extends Omit<ToastRegionProps<SpectrumToastValue>, 'queue' | 'children' | 'style' | 'className'> {
3838
/**
3939
* Placement of the toast container on the page.
4040
* @default "bottom"
@@ -490,7 +490,7 @@ export function SpectrumToast(props: SpectrumToastProps): ReactNode {
490490
width: '100%',
491491
translate: `0 0 ${(-12 * index) / 16}rem`,
492492
// Only 3 toasts are visible in the stack at once, but all toasts are in the DOM.
493-
// This allows view transitions to smoothly animate them from where they would be
493+
// This allows view transitions to smoothly animate them from where they would be
494494
// in the collapsed stack to their final position in the expanded list.
495495
opacity: index >= 3 ? 0 : 1,
496496
zIndex: visibleToasts.length - index - 1,
@@ -528,7 +528,7 @@ export function SpectrumToast(props: SpectrumToastProps): ReactNode {
528528
}
529529
<Text slot="title">{toast.content.children}</Text>
530530
</ToastContent>
531-
{!isExpanded && visibleToasts.length > 1 &&
531+
{!isExpanded && visibleToasts.length > 1 &&
532532
<ActionButton
533533
isQuiet
534534
staticColor="white"

packages/@react-spectrum/s2/style/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@
1111
*/
1212

1313
import type * as CSS from 'csstype';
14-
import {Inset, fontRelative as internalFontRelative, size as internalSize, space as internalSpace, Spacing, style} from './spectrum-theme';
14+
import {Inset, fontRelative as internalFontRelative, space as internalSpace, Spacing, style} from './spectrum-theme';
1515
import type {MacroContext} from '@parcel/macros';
1616
import {StyleString} from './types';
1717

18-
export {baseColor, color, edgeToText, lightDark, linearGradient, colorMix, style} from './spectrum-theme';
18+
export {baseColor, color, edgeToText, lightDark, linearGradient, colorMix, size, style} from './spectrum-theme';
1919
export type {StyleString} from './types';
2020

2121
// Wrap these functions in arbitrary value syntax when called from the outside.
22-
export function size(px: number): `[${string}]` {
23-
return `[${internalSize(px)}]`;
24-
}
25-
2622
export function space(px: number): `[${string}]` {
2723
return `[${internalSpace(px)}]`;
2824
}

packages/@react-spectrum/s2/style/spectrum-theme.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ const padding = {
330330
...relativeSpacing
331331
};
332332

333-
export function size(this: MacroContext | void, px: number): string {
333+
export function size(this: MacroContext | void, px: number): `calc(${string})` {
334334
return `calc(${pxToRem(px)} * var(--s2-scale))`;
335335
}
336336

@@ -760,16 +760,17 @@ export const style = createTheme({
760760
code: 'source-code-pro, "Source Code Pro", Monaco, monospace'
761761
},
762762
fontSize: new ExpandedProperty<keyof typeof fontSize>(['fontSize', 'lineHeight'], (value) => {
763-
return {
764-
'--fs': `pow(1.125, ${value})`,
765-
fontSize: `round(${fontSizeCalc} / 16 * 1rem, 1px)`
766-
};
763+
if (typeof value === 'number') {
764+
return {
765+
'--fs': `pow(1.125, ${value})`,
766+
fontSize: `round(${fontSizeCalc} / 16 * 1rem, 1px)`
767+
} as CSSProperties;
768+
}
769+
770+
return {fontSize: value};
767771
}, fontSize),
768772
fontWeight: new ExpandedProperty<keyof typeof fontWeight>(['fontWeight', 'fontVariationSettings', 'fontSynthesisWeight'], (value) => {
769773
return {
770-
// Set font-variation-settings in addition to font-weight to work around typekit issue.
771-
// (This was fixed, but leaving for backward compatibility for now.)
772-
fontVariationSettings: value === 'inherit' ? 'inherit' : `"wght" ${value}`,
773774
fontWeight: value as any,
774775
fontSynthesisWeight: 'none'
775776
};

packages/@react-stately/layout/src/WaterfallLayout.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ export interface WaterfallLayoutOptions {
4848

4949
class WaterfallLayoutInfo extends LayoutInfo {
5050
column = 0;
51+
index = 0;
5152

5253
copy(): WaterfallLayoutInfo {
5354
let res = super.copy() as WaterfallLayoutInfo;
5455
res.column = this.column;
56+
res.index = this.index;
5557
return res;
5658
}
5759
}
@@ -123,18 +125,19 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
123125
// Setup an array of column heights
124126
let columnHeights = Array(numColumns).fill(minSpace.height);
125127
let newLayoutInfos = new Map();
128+
let index = 0;
126129
let addNode = (key: Key, node: Node<T>) => {
127130
let oldLayoutInfo = this.layoutInfos.get(key);
128131
let height = itemHeight;
129132
let estimatedSize = true;
130133
if (oldLayoutInfo) {
131-
height = oldLayoutInfo.rect.height;
134+
height = oldLayoutInfo.rect.height / oldLayoutInfo.rect.width * itemWidth;
132135
estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;
133136
}
134137

135138
// Figure out which column to place the item in, and compute its position.
136139
// Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
137-
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;
140+
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.index === index && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;
138141
let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);
139142
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;
140143
let y = columnHeights[column];
@@ -145,6 +148,7 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
145148
layoutInfo.allowOverflow = true;
146149
layoutInfo.content = node;
147150
layoutInfo.column = column;
151+
layoutInfo.index = index++;
148152
newLayoutInfos.set(key, layoutInfo);
149153

150154
columnHeights[column] += layoutInfo.rect.height + minSpace.height;

0 commit comments

Comments
 (0)