Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions packages/@react-spectrum/s2/src/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export const btnStyles = style<
},
'--iconWidth': {
type: 'width',
value: fontRelative(20)
value: '1lh'
},
'--badgePosition': {
type: 'width',
Expand All @@ -306,15 +306,6 @@ export const btnStyles = style<
getAllowedOverrides()
);

// Matching icon sizes. TBD.
const avatarSize: Record<NonNullable<ActionButtonStyleProps['size']>, number> = {
XS: 14,
S: 16,
M: 20,
L: 22,
XL: 26
} as const;

interface ActionButtonContextProps extends Partial<ActionButtonProps> {
holdAffordance?: boolean;
}
Expand Down Expand Up @@ -402,7 +393,7 @@ export const ActionButton = forwardRef(function ActionButton(
{
render: centerBaseline({slot: 'icon', styles: style({gridArea: 'icon'})}),
styles: style({
size: fontRelative(20),
size: '1lh',
marginStart: '--iconMargin',
visibility: {
isProgressVisible: 'hidden'
Expand All @@ -413,7 +404,7 @@ export const ActionButton = forwardRef(function ActionButton(
[
AvatarContext,
{
size: avatarSize[size],
size: '1lh',
styles: style({
marginStart: '--iconMargin',
gridArea: 'icon'
Expand Down Expand Up @@ -468,17 +459,7 @@ export const ActionButton = forwardRef(function ActionButton(
aria-label={stringFormatter.format('button.pending')}
size="S"
staticColor={staticColor}
styles={style({
size: {
size: {
XS: 12,
S: 14,
M: 18,
L: 20,
XL: 24
}
}
})({size})}
styles={style({size: '1lh'})}
/>
</div>
)}
Expand Down
36 changes: 31 additions & 5 deletions packages/@react-spectrum/s2/src/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,23 @@ export interface AvatarProps extends UnsafeStyles, DOMProps, SlotProps {
*
* @default 24
*/
size?: 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 56 | 64 | 80 | 96 | 112 | (number & {});
size?:
| 16
| 20
| 24
| 28
| 32
| 36
| 40
| 44
| 48
| 56
| 64
| 80
| 96
| 112
| (number & {})
| `${number}lh`;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want this API? are users likely to do anything other than 1lh? should we limit it?

/** Whether the avatar is over a color background. */
isOverBackground?: boolean;
}
Expand All @@ -59,7 +75,9 @@ const imageStyles = style(
outlineColor: '--s2-container-bg',
outlineWidth: {
default: 1,
isLarge: 2
isLarge: 2,
// if bigger than 64px, use 2px outline, otherwise use 1px outline
isLH: 'min(2px, max(1px, calc((((1lh / 64) - 1px) * 9999) + 1px)))'
}
},
getAllowedOverrides({width: false})
Expand Down Expand Up @@ -90,8 +108,16 @@ export const Avatar = forwardRef(function Avatar(
const domProps = filterDOMProps(otherProps);

// In the docs build, we need to be able to simulate font scaling.
let remSize = isDocsEnv() ? `calc(${size / 16} * var(--rem, 1rem))` : `${size / 16}rem`;
let isLarge = size >= 64;
let remSize;
let isLarge = false;
let isLH = false;
if (typeof size === 'string') {
remSize = size;
isLH = size.endsWith('lh');
} else {
remSize = isDocsEnv() ? `calc(${size / 16} * var(--rem, 1rem))` : `${size / 16}rem`;
isLarge = size >= 64;
}
return (
<Image
{...domProps}
Expand All @@ -104,7 +130,7 @@ export const Avatar = forwardRef(function Avatar(
height: remSize
}}
UNSAFE_className={UNSAFE_className + ' ' + centerBaselineBefore}
styles={imageStyles({isOverBackground, isLarge}, props.styles)}
styles={imageStyles({isOverBackground, isLarge, isLH}, props.styles)}
src={src}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/s2/src/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {centerBaseline} from './CenterBaseline';
import {ContextValue, Provider, SlotProps} from 'react-aria-components/slots';
import {control, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
import {filterDOMProps} from 'react-aria/filterDOMProps';
import {fontRelative, lightDark, style} from '../style' with {type: 'macro'};
import {IconContext} from './Icon';
import {lightDark, style} from '../style' with {type: 'macro'};
import {TextContext as RACTextContext} from 'react-aria-components/Text';
import React, {createContext, forwardRef, ReactNode} from 'react';
import {SkeletonWrapper} from './Skeleton';
Expand Down Expand Up @@ -234,7 +234,7 @@ export const Badge = forwardRef(function Badge(props: BadgeProps, ref: DOMRef<HT
IconContext,
{
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
styles: style({size: fontRelative(20), marginStart: '--iconMargin', flexShrink: 0})
styles: style({size: '1lh', marginStart: '--iconMargin', flexShrink: 0})
}
]
]}>
Expand Down
6 changes: 3 additions & 3 deletions packages/@react-spectrum/s2/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {baseColor, focusRing, fontRelative, lightDark, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, lightDark, style} from '../style' with {type: 'macro'};
import {
ButtonRenderProps,
Button as RACButton,
Expand Down Expand Up @@ -478,7 +478,7 @@ export const Button = forwardRef(function Button(
{
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
styles: style({
size: fontRelative(20),
size: '1lh',
marginStart: '--iconMargin',
flexShrink: 0,
visibility: {
Expand Down Expand Up @@ -593,7 +593,7 @@ export const LinkButton = forwardRef(function LinkButton(
{
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
styles: style({
size: fontRelative(20),
size: '1lh',
marginStart: '--iconMargin',
flexShrink: 0
})
Expand Down
22 changes: 4 additions & 18 deletions packages/@react-spectrum/s2/src/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,7 @@ const loadingWrapperStyles = style({
});

const progressCircleStyles = style({
size: {
size: {
S: 16,
M: 20,
L: 22,
XL: 26
}
},
size: '1lh',
marginStart: {
isInput: 'text-to-visual'
}
Expand Down Expand Up @@ -452,13 +445,6 @@ export interface ComboBoxItemProps
children: ReactNode;
}

const avatarSize = {
S: 16,
M: 20,
L: 22,
XL: 26
} as const;

const checkmarkIconSize = {
S: 'XS',
M: 'M',
Expand Down Expand Up @@ -504,7 +490,7 @@ export function ComboBoxItem(props: ComboBoxItemProps): ReactNode {
AvatarContext,
{
slots: {
avatar: {size: avatarSize[size], styles: avatar}
avatar: {size: '1lh', styles: avatar}
}
}
],
Expand Down Expand Up @@ -667,7 +653,7 @@ const ComboboxInner = forwardRef(function ComboboxInner(
<ProgressCircle
isIndeterminate
size="S"
styles={progressCircleStyles({size})}
styles={progressCircleStyles({})}
// Same loading string as table
aria-label={stringFormatter.format('table.loadingMore')}
/>
Expand Down Expand Up @@ -738,7 +724,7 @@ const ComboboxInner = forwardRef(function ComboboxInner(
id={spinnerId}
isIndeterminate
size="S"
styles={progressCircleStyles({size, isInput: true})}
styles={progressCircleStyles({isInput: true})}
aria-label={stringFormatter.format('table.loading')}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/s2/src/DragPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {baseColor, fontRelative, style} from '../style' with {type: 'macro'};
import {baseColor, style} from '../style' with {type: 'macro'};
import {centerBaseline} from './CenterBaseline';
import {controlFont} from './style-utils' with {type: 'macro'};
import {DEFAULT_SLOT, Provider} from 'react-aria-components/slots';
Expand Down Expand Up @@ -63,7 +63,7 @@ export let iconCenterWrapper = style({

export let icon = style({
display: 'block',
size: fontRelative(20),
size: '1lh',
marginEnd: 'text-to-visual',
'--iconPrimary': {
type: 'fill',
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/s2/src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export const FieldGroup = forwardRef(function FieldGroup(
IconContext,
{
styles: style({
size: fontRelative(20),
size: '1lh',
'--iconPrimary': {type: 'fill', value: 'currentColor'}
})
}
Expand Down Expand Up @@ -490,7 +490,7 @@ export function FieldErrorIcon(props: {isDisabled?: boolean}): ReactNode {
})
}),
styles: style({
size: fontRelative(20),
size: '1lh',
marginStart: 'text-to-visual',
marginEnd: fontRelative(-2),
flexShrink: 0
Expand Down
12 changes: 2 additions & 10 deletions packages/@react-spectrum/s2/src/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@

import {ActionButtonGroupContext} from './ActionButtonGroup';
import {ActionMenuContext} from './ActionMenu';
import {
baseColor,
color,
colorMix,
focusRing,
fontRelative,
space,
style
} from '../style' with {type: 'macro'};
import {baseColor, color, colorMix, focusRing, space, style} from '../style' with {type: 'macro'};
import {centerBaseline} from './CenterBaseline';
import {Checkbox} from './Checkbox';
import {CheckboxContext} from 'react-aria-components/Checkbox';
Expand Down Expand Up @@ -235,7 +227,7 @@ const listView = style<GridListRenderProps & {isQuiet?: boolean; isDropTarget?:
type: 'width',
value: {
default: 'auto',
[hasTrailingIconRows]: fontRelative(20)
[hasTrailingIconRows]: '1lh'
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/s2/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export let checkbox = style({

export let icon = style({
display: 'block',
size: fontRelative(20),
size: '1lh',
// too small default icon size is wrong, it's like the icons are 1 tshirt size bigger than the rest of the component? check again after typography changes
// reminder, size of WF is applied via font size
marginEnd: 'text-to-visual',
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/s2/src/NotificationBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const badge = style(
isIndicatorOnly: 8
},
M: {
default: fontRelative(18), // sort of arbitrary? tried to get as close to the figma designs as possible
default: '1lh', // sort of arbitrary? tried to get as close to the figma designs as possible
isIndicatorOnly: 8
},
L: {
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/s2/src/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const SearchField = /*#__PURE__*/ forwardRef(function SearchField(
})
}),
styles: style({
size: fontRelative(20),
size: '1lh',
marginStart: '--iconMargin'
})
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@react-spectrum/s2/src/SideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import {ActionButtonGroupContext} from './ActionButtonGroup';
import {ActionMenuContext} from './ActionMenu';
import {baseColor, focusRing, fontRelative, space, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, space, style} from '../style' with {type: 'macro'};
import {Button, ButtonContext} from 'react-aria-components/Button';
import {centerBaseline} from './CenterBaseline';
import {
Expand Down Expand Up @@ -543,7 +543,7 @@ const SideNavItemContentInner = props => {
IconContext,
{
render: centerBaseline({slot: 'icon', styles: treeIcon}),
styles: style({size: fontRelative(20), flexShrink: 0})
styles: style({size: '1lh', flexShrink: 0})
}
],
[ActionButtonGroupContext, {styles: treeActions, isDisabled, size: 'S'}],
Expand Down Expand Up @@ -697,7 +697,7 @@ export const SideNavItemLink = (props: SideNavItemLinkProps): ReactNode => {
IconContext,
{
render: centerBaseline({slot: 'icon', styles: treeIcon}),
styles: style({size: fontRelative(20), flexShrink: 0})
styles: style({size: '1lh', flexShrink: 0})
}
]
]}>
Expand Down
6 changes: 3 additions & 3 deletions packages/@react-spectrum/s2/src/TagGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
TagRenderProps
} from 'react-aria-components/TagGroup';
import {AvatarContext} from './Avatar';
import {baseColor, focusRing, fontRelative, lightDark, style} from '../style' with {type: 'macro'};
import {baseColor, focusRing, lightDark, style} from '../style' with {type: 'macro'};
import {CenterBaseline, centerBaseline} from './CenterBaseline';
import {ClearButton} from './ClearButton';
import {CollectionBuilder} from 'react-aria/CollectionBuilder';
Expand Down Expand Up @@ -630,7 +630,7 @@ function TagWrapper({children, isDisabled, allowsRemoving, isInRealDOM, isEmphas
{
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
styles: style({
size: fontRelative(20),
size: '1lh',
marginStart: '--iconMargin',
flexShrink: 0
})
Expand All @@ -647,7 +647,7 @@ function TagWrapper({children, isDisabled, allowsRemoving, isInRealDOM, isEmphas
ImageContext,
{
styles: style({
size: fontRelative(20),
size: '1lh',
flexShrink: 0,
order: 0,
aspectRatio: 'square',
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/s2/src/ToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {ContextValue, Provider, useSlottedContext} from 'react-aria-components/s
import CornerTriangle from '../ui-icons/CornerTriangle';
import {createContext, forwardRef, ReactNode} from 'react';
import {FocusableRef, FocusableRefValue, GlobalDOMAttributes} from '@react-types/shared';
import {fontRelative, space, style} from '../style' with {type: 'macro'};
import {IconContext} from './Icon';
import {pressScale} from './pressScale';
import {
ToggleButton as RACToggleButton,
ToggleButtonProps as RACToggleButtonProps
} from 'react-aria-components/ToggleButton';
import {SkeletonContext} from './Skeleton';
import {space, style} from '../style' with {type: 'macro'};
import {StyleProps} from './style-utils';
import {Text, TextContext} from './Content';
import {ToggleButtonGroupContext} from './ToggleButtonGroup';
Expand Down Expand Up @@ -126,7 +126,7 @@ export const ToggleButton = forwardRef(function ToggleButton(
IconContext,
{
render: centerBaseline({slot: 'icon', styles: style({order: 0})}),
styles: style({size: fontRelative(20), marginStart: '--iconMargin', flexShrink: 0})
styles: style({size: '1lh', marginStart: '--iconMargin', flexShrink: 0})
}
]
]}>
Expand Down
Loading