Skip to content

Commit

Permalink
[docs-app] feat(BreadcrumbsExample): render current as input (#3986)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Feb 27, 2020
1 parent 680df58 commit dd8b43c
Showing 1 changed file with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@

import * as React from "react";

import { Boundary, Breadcrumbs, Card, H5, IBreadcrumbProps, Label, RadioGroup, Slider } from "@blueprintjs/core";
import {
Boundary,
Breadcrumbs,
Card,
Checkbox,
H5,
IBreadcrumbProps,
InputGroup,
Label,
RadioGroup,
Slider,
} from "@blueprintjs/core";
import { Example, handleStringChange, IExampleProps } from "@blueprintjs/docs-theme";

export interface IBreadcrumbsExampleState {
collapseFrom: Boundary;
renderCurrentAsInput: boolean;
width: number;
}

Expand All @@ -41,6 +53,7 @@ const ITEMS: IBreadcrumbProps[] = [
export class BreadcrumbsExample extends React.PureComponent<IExampleProps, IBreadcrumbsExampleState> {
public state: IBreadcrumbsExampleState = {
collapseFrom: Boundary.START,
renderCurrentAsInput: false,
width: 50,
};

Expand All @@ -58,6 +71,12 @@ export class BreadcrumbsExample extends React.PureComponent<IExampleProps, IBrea
options={COLLAPSE_FROM_RADIOS}
selectedValue={this.state.collapseFrom.toString()}
/>
<Checkbox
name="renderCurrent"
label="Render current breadcrumb as input"
onChange={this.handleChangeRenderCurrentAsInput}
checked={this.state.renderCurrentAsInput}
/>
<H5>Example</H5>
<Label>Width</Label>
<Slider
Expand All @@ -71,11 +90,15 @@ export class BreadcrumbsExample extends React.PureComponent<IExampleProps, IBrea
</>
);

const { collapseFrom, width } = this.state;
const { collapseFrom, renderCurrentAsInput, width } = this.state;
return (
<Example options={options} {...this.props}>
<Card elevation={0} style={{ width: `${width}%` }}>
<Breadcrumbs collapseFrom={collapseFrom} items={ITEMS} />
<Breadcrumbs
collapseFrom={collapseFrom}
items={ITEMS}
currentBreadcrumbRenderer={renderCurrentAsInput ? this.renderBreadcrumbInput : undefined}
/>
</Card>
</Example>
);
Expand All @@ -86,4 +109,28 @@ export class BreadcrumbsExample extends React.PureComponent<IExampleProps, IBrea
}

private handleChangeWidth = (width: number) => this.setState({ width });
private handleChangeRenderCurrentAsInput = () =>
this.setState({ renderCurrentAsInput: !this.state.renderCurrentAsInput });

private renderBreadcrumbInput = ({ text }: IBreadcrumbProps) => {
return <BreadcrumbInput defaultValue={typeof text === "string" ? text : undefined} />;
};
}

/* tslint:disable max-classes-per-file */
class BreadcrumbInput extends React.PureComponent<IBreadcrumbProps & { defaultValue: string | undefined }> {
public state = {
text: this.props.defaultValue ?? "",
};

public render() {
const { text } = this.state;
return <InputGroup placeholder="rename me" value={text} onChange={this.handleChange} />;
}

private handleChange = (event: React.FormEvent<HTMLInputElement>) => {
this.setState({
text: (event.target as HTMLInputElement).value,
});
};
}

1 comment on commit dd8b43c

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[docs-app] feat(BreadcrumbsExample): render current as input (#3986)

Previews: documentation | landing | table

Please sign in to comment.