Skip to content

Commit

Permalink
Merge pull request #1051 from Abderahman88/issue-1033
Browse files Browse the repository at this point in the history
Added custom icons on Accordion control
  • Loading branch information
joelfmrodrigues authored Nov 18, 2021
2 parents 2859c73 + d6fc581 commit fa7232f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions docs/documentation/docs/controls/Accordion.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Here is an example of the control in action:

![Accordion control](../assets/accordion.png)

Here is an example of the control with custom icons:

![Accordion control with custom icons](../assets/accordionCustomIcons.png)

## How to use this control in your solutions

- Check that you installed the `@pnp/spfx-controls-react` dependency. Check out the [getting started](../../#getting-started) page for more information about installing the dependency.
Expand All @@ -30,6 +34,14 @@ import { Accordion } from "@pnp/spfx-controls-react/lib/Accordion";
}
```

- For the `Accordion` control with custom icons:

```TypeScript
{
<Accordion title={item.Question} defaultCollapsed={true} className={"itemCell"} key={index} collapsedIcon={"Rocket"} expandedIcon={"InkingTool"}>
}
```

## Implementation

The `Accordion` control can be configured with the following properties:
Expand All @@ -39,6 +51,8 @@ The `Accordion` control can be configured with the following properties:
| title | string | yes | The title in the accordion to display. | |
| defaultCollapsed | boolean | no | Is the accordion by default collapsed? | false |
| className | string | no | Additional class name to add to your accordion. | |
| collapsedIcon | string | no | Optional custom icon when accordion is collapsed [See Fluent UI icons](https://developer.microsoft.com/en-us/fluentui#/styles/web/icons)| ChevronRight |
| expandedIcon | string | no | Optional custom icon when accordion is expanded [See Fluent UI icons](https://developer.microsoft.com/en-us/fluentui#/styles/web/icons)| ChevronDown |


![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/Accordion)
3 changes: 3 additions & 0 deletions src/controls/accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class Accordion extends React.Component<IAccordionProps, IAccordionState>
this.state = {
expanded: !props.defaultCollapsed
};

!!props.collapsedIcon? collapsedIcon.iconName = props.collapsedIcon : collapsedIcon.iconName = 'ChevronRight';
!!props.expandedIcon? expandedIcon.iconName = props.expandedIcon : expandedIcon.iconName = 'ChevronDown';

telemetry.track('ReactAccordion', {});
}
Expand Down
2 changes: 2 additions & 0 deletions src/controls/accordion/IAccordion.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export interface IAccordionProps {
defaultCollapsed?: boolean;
title: string;
className?: string;
collapsedIcon?: string;
expandedIcon?: string;
}

export interface IAccordionState {
Expand Down

0 comments on commit fa7232f

Please sign in to comment.