Skip to content

Commit

Permalink
feat(IconButton): Adjust IconButton size. Deprecate size="large" an…
Browse files Browse the repository at this point in the history
…d `children`
  • Loading branch information
maxcheremisin committed Sep 11, 2023
1 parent a23f361 commit 21cd4f8
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-buckets-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@contentful/f36-button': patch
---

IconButton: adjust size, deprecate `size="large"` and `children` props.
33 changes: 33 additions & 0 deletions packages/components/button/src/IconButton/IconButton.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { css } from 'emotion';
import tokens from '@contentful/f36-tokens';
import { ButtonSize } from '../types';

function sizeToStyles(size: ButtonSize) {
switch (size) {
case 'small': {
return {
padding: tokens.spacing2Xs,
minHeight: '32px',
minWidth: '32px',
};
}
case 'medium': {
return {
padding: tokens.spacingXs,
minHeight: '40px',
minWidth: '40px',
};
}
default: {
return {};
}
}
}

export function getStyles({ size }: { size: ButtonSize }) {
return {
iconButton: css({
...sizeToStyles(size),
}),
};
}
22 changes: 21 additions & 1 deletion packages/components/button/src/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';
import { cx } from 'emotion';
import type {
PolymorphicProps,
PolymorphicComponent,
ExpandProps,
} from '@contentful/f36-core';
import { Button } from '../Button';
import type { ButtonInternalProps } from '../types';
import { getStyles } from './IconButton.styles';

interface IconButtonInternalProps
extends Omit<ButtonInternalProps, 'startIcon' | 'endIcon'> {
extends Omit<
ButtonInternalProps,
'startIcon' | 'endIcon' | 'children' | 'size'
> {
/**
* Expects any of the icon components
*/
Expand All @@ -17,6 +22,15 @@ interface IconButtonInternalProps
* Aria label is required when using icon only
*/
'aria-label': string;
/**
* @deprecated Use <Button /> component instead
*/
children?: ButtonInternalProps['children'];
/**
* Determines size variation of IconButton component
* Note: 'large' is @deprecated
* */
size?: ButtonInternalProps['size'];
}

const ICON_BUTTON_DEFAULT_TAG = 'button';
Expand All @@ -32,14 +46,20 @@ function _IconButton<
testId = 'cf-ui-icon-button',
variant = 'transparent',
icon,
className,
size = 'medium',
...otherProps
} = props;

const styles = getStyles({ size });

return (
<Button
testId={testId}
ref={ref}
variant={variant}
className={cx(styles.iconButton, className)}
size={size}
{...otherProps}
startIcon={icon}
/>
Expand Down
58 changes: 51 additions & 7 deletions packages/components/button/stories/IconButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react';
import type { Meta } from '@storybook/react/types-6-0';
import { SectionHeading, Paragraph } from '@contentful/f36-typography';
import { Flex, Stack, Box } from '@contentful/f36-core';
import { TextInput } from '@contentful/f36-forms';
import { Icon } from '@contentful/f36-icon';
import * as icons from '@contentful/f36-icons';

Expand Down Expand Up @@ -70,6 +71,56 @@ export const ColoredIconInTransparentIconButton = () => {
</Flex>
);
};

export const WithTextInput = () => {
return (
<Stack flexDirection="column">
<TextInput.Group>
<TextInput aria-label="Content type name" defaultValue="blog" />
<IconButton
variant="secondary"
icon={<icons.LockIcon />}
aria-label="Unlock"
/>
</TextInput.Group>
<TextInput.Group>
<TextInput
size="small"
aria-label="Content type name"
defaultValue="blog"
/>
<IconButton
size="small"
variant="secondary"
icon={<icons.LockIcon />}
aria-label="Unlock"
/>
</TextInput.Group>
<TextInput.Group spacing="spacingS">
<TextInput aria-label="Content type name" defaultValue="blog" />
<IconButton
variant="secondary"
icon={<icons.LockIcon />}
aria-label="Unlock"
/>
</TextInput.Group>
<TextInput.Group spacing="spacingS">
<TextInput
size="small"
aria-label="Content type name"
defaultValue="blog"
/>
<IconButton
size="small"
variant="secondary"
icon={<icons.LockIcon />}
aria-label="Unlock"
/>
</TextInput.Group>
</Stack>
);
};

export const Overview = () => (
<>
<Flex flexDirection="column" marginBottom="spacingL">
Expand Down Expand Up @@ -135,13 +186,6 @@ export const Overview = () => (
aria-label="Plus"
size="medium"
/>

<IconButton
variant="primary"
icon={<Icon as={icons.PlusIcon} />}
aria-label="Plus"
size="large"
/>
</Stack>
</Flex>
</>
Expand Down

0 comments on commit 21cd4f8

Please sign in to comment.