Skip to content

Commit

Permalink
docs(MenuItem2): demo 'active' prop; add 'selected' prop docs (#5800)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Dec 12, 2022
1 parent 842ec3c commit b6c1518
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 40 deletions.
36 changes: 31 additions & 5 deletions packages/core/src/components/forms/_label.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2015 Palantir Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0.

@import "../../common/variables";
@import "../../common/variables-extended";

/*
Labels
Expand Down Expand Up @@ -49,12 +49,12 @@ label.#{$ns}-label {
.#{$ns}-slider,
.#{$ns}-popover-wrapper {
display: block;
margin-top: $pt-grid-size * 0.5;
margin-top: $half-grid-size;
text-transform: none;
}

.#{$ns}-button-group {
margin-top: $pt-grid-size * 0.5;
margin-top: $half-grid-size;
}

.#{$ns}-select select,
Expand All @@ -64,6 +64,19 @@ label.#{$ns}-label {
width: 100%;
}

.#{$ns}-control-group {
margin-top: $half-grid-size;

> .#{$ns}-button-group,
> .#{$ns}-html-select,
> .#{$ns}-input,
> .#{$ns}-select,
> .#{$ns}-slider,
> .#{$ns}-popover-wrapper {
margin-top: 0;
}
}

&.#{$ns}-disabled {
&,
.#{$ns}-text-muted {
Expand All @@ -80,12 +93,12 @@ label.#{$ns}-label {
.#{$ns}-select,
.#{$ns}-popover-wrapper {
display: inline-block;
margin: 0 0 0 ($pt-grid-size * 0.5);
margin: 0 0 0 $half-grid-size;
vertical-align: top;
}

.#{$ns}-button-group {
margin: 0 0 0 ($pt-grid-size * 0.5);
margin: 0 0 0 $half-grid-size;
}

.#{$ns}-input-group .#{$ns}-input {
Expand All @@ -95,6 +108,19 @@ label.#{$ns}-label {
&.#{$ns}-large {
line-height: $pt-input-height-large;
}

.#{$ns}-control-group {
margin: 0 0 0 $half-grid-size;

> .#{$ns}-button-group,
> .#{$ns}-html-select,
> .#{$ns}-input,
> .#{$ns}-select,
> .#{$ns}-slider,
> .#{$ns}-popover-wrapper {
margin: 0;
}
}
}

&:not(.#{$ns}-inline) .#{$ns}-popover-target {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { Alignment, AnchorButton, Button, ButtonGroup, Classes, H5, Icon, Intent, Switch } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";
import { Tooltip2 } from "@blueprintjs/popover2";

import { AlignmentSelect } from "./common/alignmentSelect";
Expand Down Expand Up @@ -48,7 +48,7 @@ export class ButtonGroupExample extends React.PureComponent<ExampleProps, IButto

private handleIconOnlyChange = handleBooleanChange(iconOnly => this.setState({ iconOnly }));

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

private handleLargeChange = handleBooleanChange(large => this.setState({ large }));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { AnchorButton, Button, Code, H5, Intent, Switch } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";
import { Size, SizeSelect } from "./common/sizeSelect";
Expand Down Expand Up @@ -61,7 +61,7 @@ export class ButtonsExample extends React.PureComponent<ExampleProps, IButtonsEx

private handleSizeChange = (size: Size) => this.setState({ size });

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

private wiggleTimeoutId: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { Callout, Code, H5, Intent, Switch } from "@blueprintjs/core";
import { Example, handleBooleanChange, handleValueChange, IDocsExampleProps } from "@blueprintjs/docs-theme";
import { Example, handleBooleanChange, IDocsExampleProps } from "@blueprintjs/docs-theme";
import { IconName } from "@blueprintjs/icons";

import { IconSelect } from "./common/iconSelect";
Expand All @@ -36,7 +36,7 @@ export class CalloutExample extends React.PureComponent<IDocsExampleProps, ICall

private handleIconNameChange = (icon: IconName) => this.setState({ icon });

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

public render() {
const { showHeader, ...calloutProps } = this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import * as React from "react";

import { HTMLSelect, Intent, Label } from "@blueprintjs/core";
import { Button, ControlGroup, HTMLSelect, Intent, Label } from "@blueprintjs/core";
import { handleValueChange } from "@blueprintjs/docs-theme";

const INTENTS = [
{ label: "None", value: Intent.NONE },
Expand All @@ -29,15 +30,26 @@ const INTENTS = [
export interface IIntentSelectProps {
intent: Intent;
label?: React.ReactNode;
onChange: React.FormEventHandler<HTMLSelectElement>;
onChange: (intent: Intent) => void;
/** @default false */
showClearButton?: boolean;
}

export const IntentSelect: React.FC<IIntentSelectProps> = props => (
<Label>
{props.label}
<HTMLSelect value={props.intent} onChange={props.onChange} options={INTENTS} />
</Label>
);
export const IntentSelect: React.FC<IIntentSelectProps> = props => {
const handleChange = handleValueChange(props.onChange);
const handleClear = React.useCallback(() => props.onChange("none"), []);
return (
<Label>
{props.label}
<ControlGroup>
<HTMLSelect value={props.intent} onChange={handleChange} options={INTENTS} fill={true} />
{props.showClearButton && (
<Button aria-label="Clear" disabled={props.intent === "none"} icon="cross" onClick={handleClear} />
)}
</ControlGroup>
</Label>
);
};
IntentSelect.defaultProps = {
label: "Intent",
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { Classes, EditableText, FormGroup, H1, H5, Intent, NumericInput, Switch } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";

Expand All @@ -44,7 +44,7 @@ export class EditableTextExample extends React.PureComponent<ExampleProps, IEdit

private toggleDisabled = handleBooleanChange((disabled: boolean) => this.setState({ disabled }));

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

private toggleSelectAll = handleBooleanChange(selectAllOnFocus => this.setState({ selectAllOnFocus }));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { FormGroup, H5, InputGroup, Intent, Switch } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";

Expand Down Expand Up @@ -54,7 +54,7 @@ export class FormGroupExample extends React.PureComponent<ExampleProps, IFormGro

private handleSubLabelChange = handleBooleanChange(subLabel => this.setState({ subLabel }));

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

public render() {
const { disabled, helperText, inline, intent, label, subLabel, requiredLabel } = this.state;
Expand Down
4 changes: 2 additions & 2 deletions packages/docs-app/src/examples/core-examples/iconExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { H5, Icon, IconSize, Intent, Label, Slider } from "@blueprintjs/core";
import { Example, ExampleProps, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps } from "@blueprintjs/docs-theme";
import { IconName } from "@blueprintjs/icons";

import { IconSelect } from "./common/iconSelect";
Expand All @@ -36,7 +36,7 @@ export class IconExample extends React.PureComponent<ExampleProps, IIconExampleS
intent: Intent.NONE,
};

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

private handleIconSizeChange = (iconSize: number) => this.setState({ iconSize });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { Classes, H5, Intent, Menu, MenuItem, Switch } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";

Expand All @@ -37,7 +37,7 @@ export function MenuItemExample(props: ExampleProps) {
<Switch label="Selected" checked={selected} onChange={handleBooleanChange(setSelected)} />
<Switch label="Enable icon" checked={iconEnabled} onChange={handleBooleanChange(setIconEnabled)} />
<Switch label="Enable submenu" checked={submenuEnabled} onChange={handleBooleanChange(setSubmenuEnabled)} />
<IntentSelect intent={intent} onChange={handleValueChange(setIntent)} />
<IntentSelect intent={intent} onChange={setIntent} />
</>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class NumericInputBasicExample extends React.PureComponent<ExampleProps,

private handleMinChange = handleNumberChange(min => this.setState({ min }));

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

private handleButtonPositionChange = handleValueChange((buttonPosition: NumericInputProps["buttonPosition"]) =>
this.setState({ buttonPosition }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { H5, Intent, ProgressBar, Slider, Switch } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";

Expand All @@ -35,15 +35,15 @@ export class ProgressExample extends React.PureComponent<ExampleProps, IProgress

private handleIndeterminateChange = handleBooleanChange(hasValue => this.setState({ hasValue }));

private handleModifierChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

public render() {
const { hasValue, intent, value } = this.state;

const options = (
<>
<H5>Props</H5>
<IntentSelect intent={intent} onChange={this.handleModifierChange} />
<IntentSelect intent={intent} onChange={this.handleIntentChange} />
<Switch checked={hasValue} label="Known value" onChange={this.handleIndeterminateChange} />
<Slider
disabled={!hasValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { H5, Intent, Label, Slider, Spinner, SpinnerSize, Switch } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";

Expand All @@ -37,7 +37,7 @@ export class SpinnerExample extends React.PureComponent<ExampleProps, ISpinnerEx

private handleIndeterminateChange = handleBooleanChange(hasValue => this.setState({ hasValue }));

private handleModifierChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

public render() {
const { size, hasValue, intent, value } = this.state;
Expand All @@ -60,7 +60,7 @@ export class SpinnerExample extends React.PureComponent<ExampleProps, ISpinnerEx
return (
<>
<H5>Props</H5>
<IntentSelect intent={intent} onChange={this.handleModifierChange} />
<IntentSelect intent={intent} onChange={this.handleIntentChange} />
<Label id={this.spinnerSizeLabelId}>Size</Label>
<Slider
labelStepSize={50}
Expand Down
4 changes: 2 additions & 2 deletions packages/docs-app/src/examples/core-examples/tagExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { Button, H5, Intent, Switch, Tag } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";

Expand Down Expand Up @@ -52,7 +52,7 @@ export class TagExample extends React.PureComponent<ExampleProps, ITagExampleSta

private handleIconChange = handleBooleanChange(icon => this.setState({ icon }));

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

private handleInteractiveChange = handleBooleanChange(interactive => this.setState({ interactive }));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as React from "react";

import { Button, H5, Intent, Switch, TagInput, TagProps } from "@blueprintjs/core";
import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme";
import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme";

import { IntentSelect } from "./common/intentSelect";

Expand Down Expand Up @@ -69,7 +69,7 @@ export class TagInputExample extends React.PureComponent<ExampleProps, ITagInput

private handleFillChange = handleBooleanChange(fill => this.setState({ fill }));

private handleIntentChange = handleValueChange((intent: Intent) => this.setState({ intent }));
private handleIntentChange = (intent: Intent) => this.setState({ intent });

private handleLargeChange = handleBooleanChange(large => this.setState({ large }));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { BooleanOrUndefinedSelect } from "./booleanOrUndefinedSelect";

export function MenuItem2Example(props: ExampleProps) {
const [large, setLarge] = React.useState(false);
const [active, setActive] = React.useState(false);
const [disabled, setDisabled] = React.useState(false);
const [selected, setSelected] = React.useState<boolean | undefined>(undefined);
const [intent, setIntent] = React.useState<Intent>("none");
Expand All @@ -37,8 +38,10 @@ export function MenuItem2Example(props: ExampleProps) {

const options = (
<>
<H5>Props</H5>
<H5>Menu props</H5>
<Switch label="Large" checked={large} onChange={handleBooleanChange(setLarge)} />
<H5>MenuItem2 props</H5>
<Switch label="Active" checked={active} onChange={handleBooleanChange(setActive)} />
<Switch label="Disabled" checked={disabled} onChange={handleBooleanChange(setDisabled)} />
<PropCodeTooltip
content={
Expand All @@ -59,7 +62,7 @@ export function MenuItem2Example(props: ExampleProps) {
</PropCodeTooltip>
<Switch label="Enable icon" checked={iconEnabled} onChange={handleBooleanChange(setIconEnabled)} />
<Switch label="Enable submenu" checked={submenuEnabled} onChange={handleBooleanChange(setSubmenuEnabled)} />
<IntentSelect intent={intent} onChange={handleValueChange(setIntent)} />
<IntentSelect intent={intent} onChange={setIntent} showClearButton={true} />
<Label>
Role structure
<HTMLSelect
Expand All @@ -75,6 +78,7 @@ export function MenuItem2Example(props: ExampleProps) {
<Example className="docs-menu-example" options={options} {...props}>
<Menu className={Classes.ELEVATION_1} large={large}>
<MenuItem2
active={active}
disabled={disabled}
icon={iconEnabled ? "cog" : undefined}
intent={intent}
Expand Down
Loading

1 comment on commit b6c1518

@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(MenuItem2): demo 'active' prop; add 'selected' prop docs (#5800)

Previews: documentation | landing | table | demo

Please sign in to comment.