Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2516 from teamleadercrm/advanced-collapsible-onch…
Browse files Browse the repository at this point in the history
…ange

AdvancedCollapsible - add `onChange` prop
  • Loading branch information
BeirlaenAaron authored Jan 4, 2023
2 parents baf4db4 + 8f06ae9 commit a5563f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

### Dependency updates

## [18.5.1] - 2023-01-04

### Added

- `AdvancedCollapsible`: Added `onChange` prop ([@BeirlaenAaron](https://github.com/BeirlaenAaron) in [#2516](https://github.com/teamleadercrm/ui/pull/2516))

## [18.5.0] - 2023-01-04

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@teamleader/ui",
"description": "Teamleader UI library",
"version": "18.5.0",
"version": "18.5.1",
"author": "Teamleader <[email protected]>",
"bugs": {
"url": "https://github.com/teamleadercrm/ui/issues"
Expand Down
8 changes: 7 additions & 1 deletion src/components/advancedCollapsible/AdvancedCollapsible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface AdvancedCollapsibleProps extends Omit<BoxProps, 'size'> {
title: string;
size?: AllowedAdvancedCollapsibleSize;
defaultIsCollapsed?: boolean;
onChange?: (collapsed: boolean, event: React.MouseEvent) => void;
}

const AdvancedCollapsible: GenericComponent<AdvancedCollapsibleProps> = ({
Expand All @@ -29,14 +30,19 @@ const AdvancedCollapsible: GenericComponent<AdvancedCollapsibleProps> = ({
size = 'medium',
title,
defaultIsCollapsed = true,
onChange,
...others
}) => {
const [collapsed, setCollapsed] = useState(defaultIsCollapsed);

const boxProps = pickBoxProps(others);
const TitleElement = size === 'large' ? Heading3 : TextBody;

const handleTitleClick = () => {
const handleTitleClick = (event: React.MouseEvent) => {
if (onChange) {
onChange(!collapsed, event);
}

setCollapsed(!collapsed);
};

Expand Down

0 comments on commit a5563f3

Please sign in to comment.