Skip to content

Commit 66657fd

Browse files
authored
[docs] Update CardExample (#7108)
1 parent b0e5ba0 commit 66657fd

File tree

1 file changed

+36
-48
lines changed

1 file changed

+36
-48
lines changed
Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 Palantir Technologies, Inc. All rights reserved.
2+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,64 +16,52 @@
1616

1717
import * as React from "react";
1818

19-
import { Button, Card, Classes, type Elevation, FormGroup, H5, Slider, Switch } from "@blueprintjs/core";
20-
import { Example, type ExampleProps } from "@blueprintjs/docs-theme";
19+
import { Button, Card, Classes, Elevation, FormGroup, H5, Slider, Switch } from "@blueprintjs/core";
20+
import { Example, type ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";
2121

22-
export interface CardExampleState {
23-
compact: boolean;
24-
elevation: Elevation;
25-
interactive: boolean;
26-
selected: boolean;
27-
}
22+
const MAX_ELEVATION = 4;
2823

29-
export class CardExample extends React.PureComponent<ExampleProps, CardExampleState> {
30-
public state: CardExampleState = {
31-
compact: false,
32-
elevation: 0,
33-
interactive: false,
34-
selected: false,
35-
};
24+
export const CardExample: React.FC<ExampleProps> = props => {
25+
const [compact, setCompact] = React.useState(false);
26+
const [elevation, setElevation] = React.useState<Elevation>(Elevation.ZERO);
27+
const [interactive, setInteractive] = React.useState(false);
28+
const [selected, setSelected] = React.useState(false);
3629

37-
public render() {
38-
return (
39-
<Example options={this.renderOptions()} {...this.props}>
40-
<Card {...this.state}>
41-
<H5>Analytical applications</H5>
42-
<p>
43-
User interfaces that enable people to interact smoothly with data, ask better questions, and
44-
make better decisions.
45-
</p>
46-
<Button text="Explore products" className={Classes.BUTTON} />
47-
</Card>
48-
</Example>
49-
);
50-
}
30+
const handleElevationChange = React.useCallback((value: number) => setElevation(value as Elevation), []);
5131

52-
private renderOptions = () => (
32+
const options = (
5333
<>
5434
<H5>Props</H5>
55-
<Switch checked={this.state.interactive} label="Interactive" onChange={this.handleInteractiveChange} />
56-
{this.state.interactive && (
57-
<Switch checked={this.state.selected} label="Selected" onChange={this.handleSelectedChange} />
58-
)}
59-
<Switch checked={this.state.compact} label="Compact" onChange={this.handleCompactChange} />
35+
<Switch checked={interactive} label="Interactive" onChange={handleBooleanChange(setInteractive)} />
36+
<Switch
37+
checked={interactive && selected}
38+
disabled={!interactive}
39+
label="Selected"
40+
onChange={handleBooleanChange(setSelected)}
41+
/>
42+
<Switch checked={compact} label="Compact" onChange={handleBooleanChange(setCompact)} />
6043
<FormGroup label="Elevation">
6144
<Slider
62-
max={4}
63-
showTrackFill={false}
64-
value={this.state.elevation}
65-
onChange={this.handleElevationChange}
6645
handleHtmlProps={{ "aria-label": "card elevation" }}
46+
max={MAX_ELEVATION}
47+
onChange={handleElevationChange}
48+
showTrackFill={false}
49+
value={elevation}
6750
/>
6851
</FormGroup>
6952
</>
7053
);
7154

72-
private handleElevationChange = (elevation: Elevation) => this.setState({ elevation });
73-
74-
private handleInteractiveChange = () => this.setState({ interactive: !this.state.interactive });
75-
76-
private handleCompactChange = () => this.setState({ compact: !this.state.compact });
77-
78-
private handleSelectedChange = () => this.setState({ selected: !this.state.selected });
79-
}
55+
return (
56+
<Example options={options} {...props}>
57+
<Card compact={compact} elevation={elevation} interactive={interactive} selected={selected}>
58+
<H5>Analytical applications</H5>
59+
<p>
60+
User interfaces that enable people to interact smoothly with data, ask better questions, and make
61+
better decisions.
62+
</p>
63+
<Button text="Explore products" className={Classes.BUTTON} />
64+
</Card>
65+
</Example>
66+
);
67+
};

0 commit comments

Comments
 (0)