Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,217 +11,37 @@ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle

### Basic

```js
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

class SimpleExpandableSection extends React.Component {
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
this.onToggle = isExpanded => {
this.setState({
isExpanded
});
};
}

render() {
const { isExpanded } = this.state;
return (
<ExpandableSection
toggleText={isExpanded ? 'Show less' : 'Show more'}
onToggle={this.onToggle}
isExpanded={isExpanded}
>
This content is visible only when the component is expanded.
</ExpandableSection>
);
}
}
```ts file="ExpandableSectionBasic.tsx"
```

### Uncontrolled

```js
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

<ExpandableSection toggleText="Show more">
This content is visible only when the component is expanded.
</ExpandableSection>;
```ts file="ExpandableSectionUncontrolled.tsx"
```

### Uncontrolled with dynamic toggle text

```js
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

<ExpandableSection toggleTextExpanded="Show less" toggleTextCollapsed="Show more">
This content is visible only when the component is expanded.
</ExpandableSection>;
```ts file="ExpandableSectionUncontrolledDynamicToggleText.tsx"
```

### Detached

```js
import React from 'react';
import { ExpandableSection, ExpandableSectionToggle, Stack, StackItem } from '@patternfly/react-core';

class DetachedExpandableSection extends React.Component {
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
this.onToggle = isExpanded => {
this.setState({
isExpanded
});
};
}

render() {
const { isExpanded } = this.state;
const contentId = 'detached-toggle-content';
return (
<Stack hasGutter>
<StackItem>
<ExpandableSection isExpanded={isExpanded} isDetached contentId={contentId}>
This content is visible only when the component is expanded.
</ExpandableSection>
</StackItem>
<StackItem>
<ExpandableSectionToggle
isExpanded={isExpanded}
onToggle={this.onToggle}
contentId={contentId}
direction="up"
>
{isExpanded ? 'Show less' : 'Show more'}
</ExpandableSectionToggle>
</StackItem>
</Stack>
);
}
}
```ts file="ExpandableSectionDetached.tsx"
```

### Disclosure variation

```js
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

class DisclosureExpandableSection extends React.Component {
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
this.onToggle = isExpanded => {
this.setState({
isExpanded
});
};
}

render() {
const { isExpanded } = this.state;
return (
<ExpandableSection
toggleText={isExpanded ? 'Show less' : 'Show more'}
onToggle={this.onToggle}
isExpanded={isExpanded}
displaySize="large"
isWidthLimited
>
This content is visible only when the component is expanded.
</ExpandableSection>
);
}
}
```ts file="ExpandableSectionDisclosure.tsx"
```

### Indented

```js
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

class SimpleExpandableSection extends React.Component {
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
this.onToggle = isExpanded => {
this.setState({
isExpanded
});
};
}

render() {
const { isExpanded } = this.state;
return (
<ExpandableSection
toggleText={isExpanded ? 'Show less' : 'Show more'}
onToggle={this.onToggle}
isExpanded={isExpanded}
isIndented={true}
>
This content is visible only when the component is expanded.
</ExpandableSection>
);
}
}
```ts file="ExpandableSectionIndented.tsx"
```

### With custom toggle content

By using the `toggleContent` prop, you can pass in content other than a simple string such as an icon or a badge. When passing in custom content in this way, you should not pass in any interactive element such as a button.

```js
import React from "react";
import { ExpandableSection, Badge } from "@patternfly/react-core";
import CheckCircleIcon from "@patternfly/react-icons/dist/esm/icons/check-circle-icon";

class CustomExpandableSection extends React.Component {
constructor(props) {
super(props);
this.state = {
isExpanded: false
};
this.onToggle = (isExpanded) => {
this.setState({
isExpanded
});
};
}

render() {
const { isExpanded } = this.state;
return (
<ExpandableSection
toggleContent={
<div>
<span>You can also use icons </span>
<CheckCircleIcon />
<span> or badges </span>
<Badge isRead={true}>4</Badge>
<span> !</span>
</div>
}
onToggle={this.onToggle}
isExpanded={isExpanded}
>
This content is visible only when the component is expanded.
</ExpandableSection>
);
}
}
```ts file="ExpandableSectionCustomToggle.tsx"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

export const ExpandableSectionBasic: React.FunctionComponent = () => {
const [isExpanded, setIsExpanded] = React.useState(false);

const onToggle = (isExpanded: boolean) => {
setIsExpanded(isExpanded);
};

return (
<ExpandableSection toggleText={isExpanded ? 'Show less' : 'Show more'} onToggle={onToggle} isExpanded={isExpanded}>
This content is visible only when the component is expanded.
</ExpandableSection>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { ExpandableSection, Badge } from '@patternfly/react-core';
import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';

export const ExpandableSectionCustomToggle: React.FunctionComponent = () => {
const [isExpanded, setIsExpanded] = React.useState(false);

const onToggle = (isExpanded: boolean) => {
setIsExpanded(isExpanded);
};

return (
<ExpandableSection
toggleContent={
<div>
<span>You can also use icons </span>
<CheckCircleIcon />
<span> or badges </span>
<Badge isRead={true}>4</Badge>
<span> !</span>
</div>
}
onToggle={onToggle}
isExpanded={isExpanded}
>
This content is visible only when the component is expanded.
</ExpandableSection>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { ExpandableSection, ExpandableSectionToggle, Stack, StackItem } from '@patternfly/react-core';

export const ExpandableSectionDetached: React.FunctionComponent = () => {
const [isExpanded, setIsExpanded] = React.useState(false);

const onToggle = (isExpanded: boolean) => {
setIsExpanded(isExpanded);
};

const contentId = 'detached-toggle-content';
return (
<Stack hasGutter>
<StackItem>
<ExpandableSection isExpanded={isExpanded} isDetached contentId={contentId}>
This content is visible only when the component is expanded.
</ExpandableSection>
</StackItem>
<StackItem>
<ExpandableSectionToggle isExpanded={isExpanded} onToggle={onToggle} contentId={contentId} direction="up">
{isExpanded ? 'Show less' : 'Show more'}
</ExpandableSectionToggle>
</StackItem>
</Stack>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

export const ExpandableSectionDisclosure: React.FunctionComponent = () => {
const [isExpanded, setIsExpanded] = React.useState(false);

const onToggle = (isExpanded: boolean) => {
setIsExpanded(isExpanded);
};

return (
<ExpandableSection
toggleText={isExpanded ? 'Show less' : 'Show more'}
onToggle={onToggle}
isExpanded={isExpanded}
displaySize="large"
isWidthLimited
>
This content is visible only when the component is expanded.
</ExpandableSection>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

export const ExpandableSectionIndented: React.FunctionComponent = () => {
const [isExpanded, setIsExpanded] = React.useState(false);

const onToggle = (isExpanded: boolean) => {
setIsExpanded(isExpanded);
};

return (
<ExpandableSection
toggleText={isExpanded ? 'Show less' : 'Show more'}
onToggle={onToggle}
isExpanded={isExpanded}
isIndented
>
This content is visible only when the component is expanded.
</ExpandableSection>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

export const ExpandableSectionUncontrolled: React.FunctionComponent = () => (
<ExpandableSection toggleText="Show more">
This content is visible only when the component is expanded.
</ExpandableSection>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import { ExpandableSection } from '@patternfly/react-core';

export const ExpandableSectionUncontrolledDynamicToggle: React.FunctionComponent = () => (
<ExpandableSection toggleTextExpanded="Show less" toggleTextCollapsed="Show more">
This content is visible only when the component is expanded.
</ExpandableSection>
);