Skip to content

Commit

Permalink
cleanup none
Browse files Browse the repository at this point in the history
  • Loading branch information
evansjohnson committed Jun 28, 2024
1 parent 06d5dd1 commit 8514c6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@

import { type IconName, IconNames } from "@blueprintjs/icons";

export const NONE = "None";
export type IconNameOrNone = IconName | typeof NONE;

export function getIconNames(): IconNameOrNone[] {
const iconNames = new Set<IconNameOrNone>();
export function getIconNames(): IconName[] {
const iconNames = new Set<IconName>();
for (const [, name] of Object.entries(IconNames)) {
iconNames.add(name);
}
iconNames.add(NONE);
return Array.from(iconNames.values());
}
21 changes: 8 additions & 13 deletions packages/docs-app/src/examples/core-examples/common/iconSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Alignment, Button, Classes, MenuItem } from "@blueprintjs/core";
import type { IconName } from "@blueprintjs/icons";
import { type ItemRenderer, Select } from "@blueprintjs/select";

import { getIconNames, type IconNameOrNone, NONE } from "./iconNames";
import { getIconNames } from "./iconNames";

const ICON_NAMES = getIconNames();

Expand All @@ -37,7 +37,7 @@ export class IconSelect extends React.PureComponent<IconSelectProps> {
return (
<label className={classNames("icon-select", Classes.LABEL, { [Classes.DISABLED]: disabled })}>
Icon
<Select<IconNameOrNone>
<Select<IconName>
disabled={disabled}
items={ICON_NAMES}
itemPredicate={this.filterIconName}
Expand All @@ -53,15 +53,15 @@ export class IconSelect extends React.PureComponent<IconSelectProps> {
disabled={disabled}
fill={true}
icon={iconName}
text={iconName || NONE}
text={iconName || "None"}
rightIcon="caret-down"
/>
</Select>
</label>
);
}

private renderIconItem: ItemRenderer<IconName | typeof NONE> = (icon, { handleClick, handleFocus, modifiers }) => {
private renderIconItem: ItemRenderer<IconName | undefined> = (icon, { handleClick, handleFocus, modifiers }) => {
if (!modifiers.matchesPredicate) {
return null;
}
Expand All @@ -70,7 +70,7 @@ export class IconSelect extends React.PureComponent<IconSelectProps> {
roleStructure="listoption"
active={modifiers.active}
selected={this.props.iconName === icon}
icon={icon === NONE ? undefined : icon}
icon={icon}
key={icon}
onClick={handleClick}
onFocus={handleFocus}
Expand All @@ -79,19 +79,14 @@ export class IconSelect extends React.PureComponent<IconSelectProps> {
);
};

private filterIconName = (query: string, iconName: IconName | typeof NONE) => {
private filterIconName = (query: string, iconName: IconName | undefined) => {
if (query === "") {
return iconName === this.props.iconName;
}
return iconName.toLowerCase().indexOf(query.toLowerCase()) >= 0;
};

private handleIconChange = (icon: IconNameOrNone) => {
if (icon === this.props.iconName) {
this.props.onChange(undefined);
return;
}

this.props.onChange(icon === NONE ? undefined : icon);
private handleIconChange = (icon: IconName) => {
this.props.onChange(icon === this.props.iconName ? undefined : icon);
};
}

0 comments on commit 8514c6c

Please sign in to comment.