|
| 1 | +import { ArgTypes, Canvas, Meta } from '@storybook/blocks'; |
| 2 | +import * as IconsStories from './Icons.stories'; |
| 3 | +import { stackblitzPrefillConfig } from '../../../previewer/codePreviewer'; |
| 4 | + |
| 5 | +<Meta isTemplate /> |
| 6 | + |
| 7 | +# Icons |
| 8 | + |
| 9 | +[Source code](https://github.com/carbon-design-system/carbon/tree/main/packages/react/src/components/Icons) |
| 10 | + | |
| 11 | +[Usage guidelines](https://carbondesignsystem.com/elements/icons/usage/) |
| 12 | + |
| 13 | +## Table of Contents |
| 14 | + |
| 15 | +- [Icons](#Icons) |
| 16 | + - [Overview](#overview) |
| 17 | + - [Customizing icon size with rem units](#customizing-icon-size-with-rem-units) |
| 18 | +- [Feedback](#feedback) |
| 19 | + |
| 20 | +## Overview |
| 21 | + |
| 22 | +<Canvas |
| 23 | + of={IconsStories.Default} |
| 24 | + additionalActions={[ |
| 25 | + { |
| 26 | + title: 'Open in Stackblitz', |
| 27 | + onClick: () => stackblitzPrefillConfig(IconsStories.Default), |
| 28 | + }, |
| 29 | + ]} |
| 30 | +/> |
| 31 | + |
| 32 | +This guide demonstrates how to make icons scale using `rem` units, without |
| 33 | +requiring any changes to the component’s default configuration. In Carbon, icons |
| 34 | +accept a `size` prop that can be a number or a string. Numbers are unitless and |
| 35 | +interpreted as pixels. This approach is effective for most scenarios, but if |
| 36 | +your goal is to improve accessibility or ensure that icons respond to changes in |
| 37 | +the browser’s font-size, using a string with `rem` units offers greater |
| 38 | +adaptability. |
| 39 | + |
| 40 | +### Customizing icon size with `rem` units |
| 41 | + |
| 42 | +To create scalable, responsive icons, you can pass a `rem` value to the `size` |
| 43 | +prop: |
| 44 | + |
| 45 | +```jsx |
| 46 | +<Edit size="1rem" /> |
| 47 | +``` |
| 48 | + |
| 49 | +<Canvas |
| 50 | + of={IconsStories.WithRelativeSize} |
| 51 | + additionalActions={[ |
| 52 | + { |
| 53 | + title: 'Open in Stackblitz', |
| 54 | + onClick: () => stackblitzPrefillConfig(IconsStories.WithRelativeSize), |
| 55 | + }, |
| 56 | + ]} |
| 57 | +/> |
| 58 | + |
| 59 | +Some components use a `renderIcon` prop to display icons internally. |
| 60 | + |
| 61 | +In these cases, you can still pass a responsive size by using an inline function |
| 62 | +that returns the icon: |
| 63 | + |
| 64 | +```jsx |
| 65 | +<MenuItem renderIcon={(props) => <Edit size="1rem" {...props} />} /> |
| 66 | +``` |
| 67 | + |
| 68 | +## Feedback |
| 69 | + |
| 70 | +Help us improve this component by providing feedback, asking questions on Slack, |
| 71 | +or updating this file on |
| 72 | +[GitHub](https://github.com/carbon-design-system/carbon/tree/main/packages/react/src/components/Icons/Icons.mdx). |
0 commit comments