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
40 changes: 39 additions & 1 deletion src/components/Button/component.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const meta = {
size: {
control: 'select',
options: SIZE_VALUES,
description: `Button size. Allowed values: ${SIZE_VALUES.join(', ')}. Note: size affects padding and, for \`circle\` layout, the overall diameter.`,
description: `Button size. Allowed values: ${SIZE_VALUES.join(', ')}. Note: size affects padding and, for \`circle\`/\`squared\` layouts, the overall box size (both render at the same size).`,
table: { defaultValue: { summary: `${DEFAULT_SIZE}` } },
},
layout: {
Expand Down Expand Up @@ -323,6 +323,44 @@ export const AllSizes: Story = {
),
};

/** Renders the icon-only `circle` and `squared` layouts across every available `size`, showing that both render at the same box size for a given `size`. */
export const IconOnlySizes: Story = {
name: 'Icon-Only Layout Sizes',
args: {
variant: 'primary',
},
render: (args) => (
<div style={{ display: 'flex', flexDirection: 'column', gap: '1.5rem' }}>
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
{SIZE_VALUES.map((size) => (
<BBButton
{...args}
key={`circle-${size}`}
layout="circle"
size={size}
icon={<MdFavorite size="1.25rem" />}
ariaLabel={`Circle ${size}`}
tooltipLabel={`Circle ${size}`}
/>
))}
</div>
<div style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
{SIZE_VALUES.map((size) => (
<BBButton
{...args}
key={`squared-${size}`}
layout="squared"
size={size}
icon={<MdFavorite size="1.25rem" />}
ariaLabel={`Squared ${size}`}
tooltipLabel={`Squared ${size}`}
/>
))}
</div>
</div>
),
};

/** Shows the button in its disabled state. */
export const Disabled: Story = {
args: {
Expand Down
8 changes: 6 additions & 2 deletions src/components/Button/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
colorGray,
colorBrandAux,
} from '../../stylesheets/palette';
import { spacingMedium, spacingSmall, spacingSmallMedium } from '../../stylesheets/sizing';
import {
spacingSmall, spacingSmallMedium, spacingMedium, spacingXLarge, spacingXXLarge,
} from '../../stylesheets/sizing';
import { CSSColorPropertiesType, CSSSizePropertiesType, EssentialColorProperties } from './type';

const VARIANTS = {
Expand Down Expand Up @@ -193,9 +195,11 @@ const CSS_COLOR_PROPERTIES_DISABLED: EssentialColorProperties = {
const CSS_SIZE_PROPERTIES: CSSSizePropertiesType = {
sm: {
padding: `${spacingSmall} ${spacingSmallMedium}`,
iconBoxSize: spacingXLarge,
},
md: {
padding: spacingMedium
padding: spacingMedium,
iconBoxSize: spacingXXLarge,
},
};

Expand Down
29 changes: 16 additions & 13 deletions src/components/Button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,30 @@ const stackedLayoutStyles = css`
align-items: center;
`;

const circleLayoutStyles = css`
border-radius: 50%;
width: 3rem;
height: 3rem;
// Shared by `circle` and `squared`: both are icon-only, fixed-box layouts that
// must render at the same width/height for a given `size` — they differ only
// in border-radius (round vs. slightly rounded square).
const iconOnlyBoxStyles = css<StyledButtonProps>`
${({ $size }) => {
const safeSize = $size ?? DEFAULT_SIZE;
const { iconBoxSize } = CSS_SIZE_PROPERTIES[safeSize] ?? CSS_SIZE_PROPERTIES[DEFAULT_SIZE];
return `width: ${iconBoxSize}; height: ${iconBoxSize};`;
}}
aspect-ratio: 1;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
`;

// Icon-only, sized by its own (equal, non-text) padding rather than a fixed
// box — stays compact next to a single line of text instead of forcing a
// fixed height like circle/stacked do.
const squaredLayoutStyles = css`
const circleLayoutStyles = css<StyledButtonProps>`
${iconOnlyBoxStyles}
border-radius: 50%;
`;

const squaredLayoutStyles = css<StyledButtonProps>`
${iconOnlyBoxStyles}
border-radius: ${borderRadiusSmall};
aspect-ratio: 1;
padding: ${spacingSmall};
display: flex;
justify-content: center;
align-items: center;
`;

const defaultLayoutStyles = css`
Expand Down
3 changes: 2 additions & 1 deletion src/components/Button/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type CSSColorPropertiesType = {

export type SizeProperties = {
padding: string;
iconBoxSize: string;
}

export type CSSSizePropertiesType = {
Expand Down Expand Up @@ -97,7 +98,7 @@ type BaseButtonProps = {
/** Visual variant controlling emphasis and background/border styling. @default 'primary' */
variant?: VariantType;

/** Button size; affects padding and, for the `circle` layout, the overall diameter. @default 'md' */
/** Button size; affects padding and, for the `circle`/`squared` layouts, the overall box size (both render at the same size). @default 'md' */
size?: SizeType;

/** Disables interaction and applies disabled styling. @default false */
Expand Down
1 change: 1 addition & 0 deletions src/stylesheets/sizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const spacingMedium = '1rem'; // 16px
export const spacingMediumLarge = '1.25rem'; // 20px
export const spacingLarge = '1.5rem'; // 24px
export const spacingXLarge = '2rem'; // 32px
export const spacingXXLarge = '3rem'; // 48px

// Border sizes
export const borderRadiusDefault = '1rem'; //16px
Expand Down
Loading