Skip to content

Commit

Permalink
add icons auto size (#16027)
Browse files Browse the repository at this point in the history
Update ui/components/component-library/icon/README.mdx

Co-authored-by: George Marshall <[email protected]>

Update ui/components/component-library/icon/icon.stories.js

Co-authored-by: George Marshall <[email protected]>

Update ui/helpers/constants/design-system.js

Co-authored-by: George Marshall <[email protected]>

story fix

font size comment

update auto demo and fix inline style
  • Loading branch information
garrettbear authored Sep 29, 2022
1 parent 47f1363 commit 455735c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
5 changes: 5 additions & 0 deletions ui/components/component-library/icon/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Possible sizes include:
- `SIZES.MD` 20px
- `SIZES.LG` 24px
- `SIZES.XL` 32px
- `SIZES.AUTO` inherits the font-size from parent element. This is useful for inline icons in text.

<Canvas>
<Story id="ui-components-component-library-icon-icon-stories-js--size" />
Expand All @@ -62,6 +63,10 @@ import { Icon, ICON_NAMES } from '../ui/component-library';
<Icon name={ICON_NAMES.ADD_SQUARE_FILLED} size={SIZES.MD} />
<Icon name={ICON_NAMES.ADD_SQUARE_FILLED} size={SIZES.LG} />
<Icon name={ICON_NAMES.ADD_SQUARE_FILLED} size={SIZES.XL} />
<Text as="p" variant={TEXT.BODY_SM}>
<Icon size={SIZES.AUTO} /> Auto also exists and inherits the
font-size of the parent element.
</Text>
```

### Color
Expand Down
7 changes: 7 additions & 0 deletions ui/components/component-library/icon/icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@
&--size-xl {
--size: 32px;
}

&--size-auto {
--size: 1em; // Inherits parent font-size

position: relative; // Fixes vertical alignment
top: 0.125em; // Fixes vertical alignment
}
}
28 changes: 19 additions & 9 deletions ui/components/component-library/icon/icon.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,26 @@ export const Name = (args) => {
};

export const Size = (args) => (
<Box display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.BASELINE} gap={1}>
<Icon {...args} size={SIZES.XXS} />
<Icon {...args} size={SIZES.XS} />
<Icon {...args} size={SIZES.SM} />
<Icon {...args} size={SIZES.MD} />
<Icon {...args} size={SIZES.LG} />
<Icon {...args} size={SIZES.XL} />
</Box>
<>
<Box
display={DISPLAY.FLEX}
alignItems={ALIGN_ITEMS.BASELINE}
gap={1}
marginBottom={4}
>
<Icon {...args} size={SIZES.XXS} />
<Icon {...args} size={SIZES.XS} />
<Icon {...args} size={SIZES.SM} />
<Icon {...args} size={SIZES.MD} />
<Icon {...args} size={SIZES.LG} />
<Icon {...args} size={SIZES.XL} />
</Box>
<Text as="p" variant={TEXT.BODY_SM}>
<Icon {...args} size={SIZES.AUTO} /> Auto also exists and inherits the
font-size of the parent element.
</Text>
</>
);

export const Color = (args) => (
<Box display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.BASELINE}>
<Box padding={1} display={DISPLAY.FLEX} alignItems={ALIGN_ITEMS.CENTER}>
Expand Down
6 changes: 6 additions & 0 deletions ui/components/component-library/icon/icon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ describe('Icon', () => {
size={SIZES.XL}
data-testid="icon-xl"
/>
<Icon
name={MOCK_ICON_NAMES.ADD_SQUARE_FILLED}
size={SIZES.AUTO}
data-testid="icon-auto"
/>
</>,
);
expect(getByTestId('icon-xxs')).toHaveClass('icon--size-xxs');
Expand All @@ -96,6 +101,7 @@ describe('Icon', () => {
expect(getByTestId('icon-md')).toHaveClass('icon--size-md');
expect(getByTestId('icon-lg')).toHaveClass('icon--size-lg');
expect(getByTestId('icon-xl')).toHaveClass('icon--size-xl');
expect(getByTestId('icon-auto')).toHaveClass('icon--size-auto');
});
it('should render with icon colors', () => {
const { getByTestId } = render(
Expand Down
1 change: 1 addition & 0 deletions ui/helpers/constants/design-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const SIZES = {
MD: 'md',
LG: 'lg',
XL: 'xl',
AUTO: 'auto', // Used for Text and Icon components to inherit the parent elements font-size
NONE,
};

Expand Down

0 comments on commit 455735c

Please sign in to comment.