Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .changeset/mosaic-avatar-sizing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion packages/swingset/src/stories/avatar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ While an image is still resolving, the fallback carries `data-pending` and pulse

### Interactive

Use `render` to compose the avatar onto a button or another trigger without introducing a separate wrapper component. The `xl` avatar and button are both 48×48.
Use `render` to compose the avatar onto a button or another trigger without introducing a separate wrapper component. The `lg` avatar and button are both 48×48.

<Story
name='Interactive'
Expand Down
6 changes: 3 additions & 3 deletions packages/swingset/src/stories/avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const meta: StoryMeta = {
styles: {
_variants: {
shape: { circle: {}, square: {} },
size: { xs: {}, sm: {}, md: {}, lg: {}, xl: {} },
size: { xs: {}, sm: {}, md: {}, lg: {} },
},
_defaultVariants: {
shape: 'circle',
Expand Down Expand Up @@ -76,7 +76,7 @@ export function Interactive(props: Record<string, unknown>) {
return (
<Avatar.Root
{...knobsAsProps(props)}
size='xl'
size='lg'
render={
<button
type='button'
Expand All @@ -99,7 +99,7 @@ export function Interactive(props: Record<string, unknown>) {
export function Sizes(props: Record<string, unknown>) {
return (
<div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
{(['xs', 'sm', 'md', 'lg', 'xl'] as const).map(size => (
{(['xs', 'sm', 'md', 'lg'] as const).map(size => (
<Avatar.Root
key={size}
{...knobsAsProps(props)}
Expand Down
40 changes: 32 additions & 8 deletions packages/ui/src/mosaic/components/avatar/avatar.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,43 @@ export const styles = stylex.create({
},
});

// shape — square shares its radius with Button; circle rounds fully
// shape — square takes the radius its size sets below; circle rounds fully
export const shapes = stylex.create({
circle: { borderRadius: radiusVars['--cl-radius-full'] },
square: { borderRadius: radiusVars['--cl-radius-md'] },
square: { borderRadius: 'var(--_cl-avatar-radius)' },
});

// size — square box; font-size is ~0.4x the box, the ceiling at which two initials still clear
// the circle's clip.
export const sizes = stylex.create({
xs: { fontSize: '0.5rem', height: space['5'], width: space['5'] },
sm: { fontSize: '0.6875rem', height: space['7'], width: space['7'] },
md: { fontSize: '0.875rem', height: space['9'], width: space['9'] },
lg: { fontSize: '1rem', height: space['10'], width: space['10'] },
xl: { fontSize: '1rem', height: space['12'], width: space['12'] },
fit: { fontSize: '0.75rem', height: '100%', width: '100%' },
xs: {
'--_cl-avatar-radius': radiusVars['--cl-radius-sm'],
fontSize: '0.625rem',
height: space['6'],
width: space['6'],
},
sm: {
'--_cl-avatar-radius': radiusVars['--cl-radius-md'],
fontSize: '0.8125rem',
height: space['8'],
width: space['8'],
},
md: {
'--_cl-avatar-radius': radiusVars['--cl-radius-lg'],
fontSize: '0.9375rem',
height: space['9.5'],
width: space['9.5'],
},
lg: {
'--_cl-avatar-radius': radiusVars['--cl-radius-lg'],
fontSize: '1.125rem',
height: space['12'],
width: space['12'],
},
fit: {
'--_cl-avatar-radius': radiusVars['--cl-radius-md'],
fontSize: '0.75rem',
height: '100%',
width: '100%',
},
});
2 changes: 1 addition & 1 deletion packages/ui/src/mosaic/components/avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function useAvatarContext(part: string): AvatarContextValue {

export interface AvatarProps extends MosaicComponentProps<'span'> {
shape?: 'circle' | 'square';
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'fit';
size?: 'xs' | 'sm' | 'md' | 'lg' | 'fit';
}

const AvatarRoot = React.forwardRef<HTMLSpanElement, AvatarProps>(function MosaicAvatarRoot(
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/mosaic/tokens.stylex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export const colorVars = stylex.defineVars(colorDefaults);
// =============================================================================
// Radius Tokens
// =============================================================================
// `md` is 6px rather than a 4/8/12 step: it is the control radius (button, avatar
// square), and neither neighbour sits right on a control.
// `md` is 6px rather than a 4/8/12 step: it is the control radius (button), and
// neither neighbour sits right on a control.

const radiusDefaults = {
'--cl-radius-none': '0rem',
Expand Down
Loading