Skip to content

Commit

Permalink
feat(react): Add IconsProvider (#4268)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanksdesign authored Aug 18, 2023
1 parent 29775e2 commit f8c5b77
Show file tree
Hide file tree
Showing 76 changed files with 1,509 additions and 333 deletions.
34 changes: 34 additions & 0 deletions .changeset/few-eggs-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"@aws-amplify/ui-react-storage": minor
"@aws-amplify/ui-react": minor
---

feat(react): Add IconsProvider to customize icons globally for all Amplify UI components

Components that use icons:
* Alert
* Checkbox
* Expander
* Field
* Menu
* Pagination
* PasswordField
* Rating
* SearchField
* Select
* StepperField
* StorageManager

Wrap your application with the `<IconsProvider>` (or whatever part of your app you want to customize the icons).

```jsx
<IconsProvider icons={{
alert: {
info: <MdInfo />
}
}}>
{/* ... */}
</IconProvider>
```

Works well with the react-icons package!
1 change: 1 addition & 0 deletions docs/__tests__/__snapshots__/sitemap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ exports[`Sitemap Snapshot 1`] = `
/react/theming/default-theme/colors,
/react/theming/default-theme/sizes,
/react/theming/default-theme/typography,
/react/theming/icons,
/react/theming/responsive,
/react/theming/style-props,
/react/theming/theme-provider,
Expand Down
5 changes: 5 additions & 0 deletions docs/src/data/links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ export const theming: ComponentNavItem[] = [
platforms: ['react', 'vue', 'angular'],
tertiary: true,
},
{
href: '/theming/icons',
label: 'Icons',
platforms: ['react'],
},
{
href: '/theming/theme-provider',
label: 'ThemeProvider',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Alert, Flex, IconsProvider } from '@aws-amplify/ui-react';
import {
FcMediumPriority,
FcHighPriority,
FcInfo,
FcOk,
FcMinus,
} from 'react-icons/fc';

export const AlertIconProviderExample = () => (
<IconsProvider
icons={{
alert: {
info: <FcInfo />,
success: <FcOk />,
error: <FcHighPriority />,
warning: <FcMediumPriority />,
close: <FcMinus />,
},
}}
>
<Flex direction="column">
<Alert variation="info" heading="Info">
Here is some info
</Alert>
<Alert variation="success" heading="Success" isDismissible>
Hooray!
</Alert>
<Alert variation="warning" heading="Warning" />
<Alert variation="error" heading="Error" />
</Flex>
</IconsProvider>
);
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { DismissButtonLabelExample } from './DismissButtonLabelExample';
export { DismissibleAlertExample } from './DismissibleAlertExample';
export { OnDismissAlertExample } from './OnDismissAlertExample';
export { RoleOverride } from './RoleOverride';
export { AlertIconProviderExample } from './AlertIconProviderExample';
19 changes: 17 additions & 2 deletions docs/src/pages/[platform]/components/alert/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
AlertStylePropsExample,
AlertThemeExample,
DismissButtonLabelExample,
RoleOverride
RoleOverride,
AlertIconProviderExample,
} from './examples';

<Badge variation="info">Usage note:</Badge> The Alert component has an ARIA `alert` role by default which has some <Link href="#accessibility">accessibility implications</Link>.
Expand Down Expand Up @@ -131,7 +132,7 @@ Use the `onDismiss` prop to pass a function that will run when the Alert is dism
</ExampleCode>
</Example>

## CSS Styling
## Styling

<ThemeExample component="Alert">
<Example>
Expand All @@ -147,6 +148,20 @@ Use the `onDismiss` prop to pass a function that will run when the Alert is dism
</Example>
</ThemeExample>

### Icons

<Example>
<AlertIconProviderExample />

<ExampleCode>

```tsx file=./examples/AlertIconProviderExample.tsx

```

</ExampleCode>
</Example>

### Target classes

<ComponentStyleDisplay componentName="Alert" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CheckboxField, Flex, IconsProvider } from '@aws-amplify/ui-react';
import { HiMinus, HiCheck } from 'react-icons/hi';

export const CheckboxFieldIconExample = () => (
<IconsProvider
icons={{
checkbox: {
checked: <HiCheck />,
indeterminate: <HiMinus />,
},
}}
>
<Flex direction="column">
<CheckboxField name="cat" label="Cat" value="cat" defaultChecked={true} />
<CheckboxField name="dog" label="Dog" value="dog" isIndeterminate />
</Flex>
</IconsProvider>
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { CheckboxFieldControlledExample } from './CheckboxFieldControlledExample';
export { CheckboxFieldDisabledExample } from './CheckboxFieldDisabledExample';
export { CheckboxFieldIconExample } from './CheckboxFieldIconExample';
export { CheckboxFieldIndeterminateExample } from './CheckboxFieldIndeterminateExample';
export { CheckboxFieldLabelHiddenExample } from './CheckboxFieldLabelHiddenExample';
export { CheckboxFieldSizesExample } from './CheckboxFieldSizesExample';
Expand Down
14 changes: 13 additions & 1 deletion docs/src/pages/[platform]/components/checkboxfield/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CheckboxField } from '@aws-amplify/ui-react';
import {
CheckboxFieldControlledExample,
CheckboxFieldDisabledExample,
CheckboxFieldIconExample,
CheckboxFieldIndeterminateExample,
CheckboxFieldLabelHiddenExample,
CheckboxFieldSizesExample,
Expand Down Expand Up @@ -172,7 +173,7 @@ Use the `hasError` and `errorMessage` props to mark a CheckboxField as having an
</Example>
</StandardHTMLAttributes>

## CSS Styling
## Styling

<ThemeExample component="CheckboxField" link="checkbox">
<Example>
Expand All @@ -188,6 +189,17 @@ Use the `hasError` and `errorMessage` props to mark a CheckboxField as having an
</Example>
</ThemeExample>

### Icons

<Example>
<CheckboxFieldIconExample />

<ExampleCode>
```tsx file=./examples/CheckboxFieldIconExample.tsx
```
</ExampleCode>
</Example>

### Target classes

<ComponentStyleDisplay componentName="CheckboxField" />
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/[platform]/components/icon/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import {ICON_NAME} from '@aws-amplify/ui-react';
import {ICON_NAME} from 'react-icons/md';`
```

To customize the default icons used in components like [Alert](alert) and [Rating](rating), you can use the [IconProvider](../theming/icons).

## Custom icon

### Using path data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Menu, MenuItem, IconsProvider } from '@aws-amplify/ui-react';
import { FiMoreHorizontal } from 'react-icons/fi';

export const MenuIconExample = () => (
<IconsProvider
icons={{
menu: {
menu: <FiMoreHorizontal />,
},
}}
>
<Menu>
<MenuItem>Download</MenuItem>
<MenuItem>Create a Copy</MenuItem>
<MenuItem>Mark as Draft</MenuItem>
</Menu>
</IconsProvider>
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { MenuItemsExample } from './menuItemsExample';
export { SizeExample } from './sizeExample';
export { StylePropsExample } from './stylePropsExample';
export { MenuThemeExample } from './MenuThemeExample';
export { MenuIconExample } from './MenuIconExample';
35 changes: 18 additions & 17 deletions docs/src/pages/[platform]/components/menu/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SizeExample,
StylePropsExample,
MenuThemeExample,
MenuIconExample,
} from './examples/';

import { Example, ExampleCode } from '@/components/Example';
Expand All @@ -29,8 +30,7 @@ Import the `Menu` and `MenuItem` components. Note that the Menu component is ren
<BasicExample />
<ExampleCode>
```tsx file=./examples/basicExample.tsx

````
```
</ExampleCode>
</Example>

Expand All @@ -42,9 +42,7 @@ Use the `MenuItem` component to configure Menu options. The example below demons
<MenuItemsExample />
<ExampleCode>
```tsx file=./examples/menuItemsExample.tsx

````

```
</ExampleCode>
</Example>

Expand All @@ -56,9 +54,7 @@ The default Menu button can be customized by importing the `MenuButton` componen
<MenuExample />
<ExampleCode>
```tsx file=./examples/menuExample.tsx

````

```
</ExampleCode>
</Example>

Expand All @@ -70,9 +66,7 @@ To control the alignment of the Menu with the Menu button, use the `menuAlign` p
<MenuAlignExample />
<ExampleCode>
```tsx file=./examples/menuAlignExample.tsx

````

```
</ExampleCode>
</Example>

Expand All @@ -84,9 +78,7 @@ Control the size of the Menu button and items using the `size` prop. Available o
<SizeExample />
<ExampleCode>
```tsx file=./examples/sizeExample.tsx

````

```
</ExampleCode>
</Example>

Expand All @@ -98,13 +90,12 @@ Create a controlled `Menu` using the `isOpen` and `onOpenChange` props.
<ControlledExample />
<ExampleCode>
```tsx file=./examples/controlledExample.tsx

````
```

</ExampleCode>
</Example>

## CSS Styling
## Styling

<ThemeExample component="Menu">
<Example>
Expand All @@ -120,6 +111,16 @@ Create a controlled `Menu` using the `isOpen` and `onOpenChange` props.
</Example>
</ThemeExample>

### Icons

<Example>
<MenuIconExample />
<ExampleCode>
```tsx file=./examples/MenuIconExample.tsx
```
</ExampleCode>
</Example>

### Target classes

<ComponentStyleDisplay componentName="Menu" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
Pagination,
usePagination,
IconsProvider,
} from '@aws-amplify/ui-react';
import { FiArrowLeft, FiArrowRight } from 'react-icons/fi';

export const PaginationIconExample = () => {
const paginationProps = usePagination({ totalPages: 6 });

return (
<IconsProvider
icons={{
pagination: {
next: <FiArrowRight />,
previous: <FiArrowLeft />,
},
}}
>
<Pagination {...paginationProps} />
</IconsProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { PaginationStylingExample } from './PaginationStylingExample';
export { PaginationHasMorePagesExample } from './PaginationHasMorePagesExample';
export { PaginationSiblingCountExample } from './PaginationSiblingCountExample';
export { PaginationThemeExample } from './PaginationThemeExample';
export { PaginationIconExample } from './PaginationIconExample';
13 changes: 12 additions & 1 deletion docs/src/pages/[platform]/components/pagination/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PaginationSiblingCountExample,
PaginationStylingExample,
PaginationThemeExample,
PaginationIconExample,
} from './examples';

## Demo
Expand Down Expand Up @@ -108,7 +109,7 @@ By default, the root node of the Pagination component is a `<nav>` element. Elem
</ExampleCode>
</Example>

## CSS styling
## Styling

<ThemeExample component="Pagination">
<Example>
Expand All @@ -124,6 +125,16 @@ By default, the root node of the Pagination component is a `<nav>` element. Elem
</Example>
</ThemeExample>

### Icons

<Example>
<PaginationIconExample />

<ExampleCode>
```tsx file=./examples/PaginationIconExample.tsx
```
</ExampleCode>
</Example>

### Target classes

Expand Down
Loading

0 comments on commit f8c5b77

Please sign in to comment.