Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

className prop consistency #1950

Merged
merged 14 commits into from
Jan 25, 2018
11 changes: 7 additions & 4 deletions packages/core/src/components/hotkeys/hotkey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* Licensed under the terms of the LICENSE file distributed with this project.
*/

import * as classNames from "classnames";
import * as React from "react";

import { AbstractPureComponent } from "../../common";
import { AbstractPureComponent, IProps } from "../../common";
import { KeyCombo } from "./keyCombo";

export interface IHotkeyProps {
export interface IHotkeyProps extends IProps {
/**
* Whether the hotkey should be triggerable when focused in a text input.
* @default false
Expand Down Expand Up @@ -86,9 +87,11 @@ export class Hotkey extends AbstractPureComponent<IHotkeyProps, {}> {
}

public render() {
const { label, ...spreadableProps } = this.props;
const { label, className, ...spreadableProps } = this.props;

const rootClasses = classNames("pt-hotkey", className);
return (
<div className="pt-hotkey">
<div className={rootClasses}>
<div className="pt-hotkey-label">{label}</div>
<KeyCombo {...spreadableProps} />
</div>
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/components/hotkeys/hotkeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import * as React from "react";

import * as classNames from "classnames";
import { AbstractPureComponent, IProps } from "../../common";
import { HOTKEYS_HOTKEY_CHILDREN } from "../../common/errors";
import { Hotkey, IHotkeyProps } from "./hotkey";
Expand Down Expand Up @@ -64,8 +65,8 @@ export class Hotkeys extends AbstractPureComponent<IHotkeysProps, {}> {
}
elems.push(<Hotkey key={elems.length} {...hotkey} />);
}

return <div className="pt-hotkey-column">{elems}</div>;
const rootClasses = classNames("pt-hotkey-column", this.props.className);
return <div className={rootClasses}>{elems}</div>;
}

protected validateProps(props: IHotkeysProps & { children: React.ReactNode }) {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/components/hotkeys/keyCombo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* Licensed under the terms of the LICENSE file distributed with this project.
*/

import * as classNames from "classnames";
import * as React from "react";
import { IProps } from "../../common";
import { normalizeKeyCombo } from "./hotkeyParser";

const KeyIcons: { [key: string]: string } = {
Expand All @@ -21,7 +23,7 @@ const KeyIcons: { [key: string]: string } = {
up: "pt-icon-arrow-up",
};

export interface IKeyComboProps {
export interface IKeyComboProps extends IProps {
allowInInput?: boolean;
combo: string;
disabled?: boolean;
Expand All @@ -33,6 +35,7 @@ export class KeyCombo extends React.Component<IKeyComboProps, {}> {
public render() {
const keys = normalizeKeyCombo(this.props.combo);
const components = [] as JSX.Element[];
const rootClasses = classNames("pt-key-combo", this.props.className);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
const icon = KeyIcons[key];
Expand All @@ -54,6 +57,6 @@ export class KeyCombo extends React.Component<IKeyComboProps, {}> {
);
}
}
return <span className="pt-key-combo">{components}</span>;
return <span className={rootClasses}>{components}</span>;
}
}
14 changes: 10 additions & 4 deletions packages/core/test/isotest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the terms of the LICENSE file distributed with this project.
*/

// @ts-check
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏

const { generateIsomorphicTests } = require("@blueprintjs/test-commons");
const React = require("react");
// TODO: get this to work with require("@std/esm")(module)("../lib/esm")
Expand All @@ -11,10 +12,13 @@ const Core = require("../lib/cjs");
const tooltipContent = { content: React.createElement("h1", {}, "content") };
const customProps = {
Hotkey: { combo: "mod+s", global: true, label: "save" },
Icon: { iconName: "pt-icon-build" },
KeyCombo: { combo: "?" },
Overlay: { lazy: false, inline: true },
SVGTooltip: tooltipContent,
TagInput: { values: ["foo", "bar", "baz"] },
Tooltip: tooltipContent,
Toaster: { inline: true },
};

const popoverTarget = React.createElement("button");
Expand All @@ -25,11 +29,13 @@ const customChildren = {
SVGTooltip: popoverTarget,
Tabs: React.createElement(Core.Tab, { key: 1, id: 1, title: "Tab one" }),
Tooltip: popoverTarget,
Toaster: React.createElement(Core.Toast, { message: "Toast" }),
};

const skipList = [
"Portal", // doesn't render any DOM inline
]

describe("Core isomorphic rendering", () => {
generateIsomorphicTests(Core, customProps, customChildren, [
"Portal", // doesn't render any DOM inline
"Tabs", // deprecated component, logs a warning
]);
generateIsomorphicTests(Core, customProps, customChildren, skipList);
});
1 change: 1 addition & 0 deletions packages/icons/test/isotest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the terms of the LICENSE file distributed with this project.
*/

// @ts-check
const { generateIsomorphicTests } = require("@blueprintjs/test-commons");
const React = require("react");
const Icons = require("../lib/cjs");
Expand Down
15 changes: 8 additions & 7 deletions packages/select/test/isotest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the terms of the LICENSE file distributed with this project.
*/

// @ts-check
const { generateIsomorphicTests } = require("@blueprintjs/test-commons");
const React = require("react");
const Select = require("../lib/cjs");
Expand All @@ -22,17 +23,17 @@ const customProps = {
renderer: () => null
},
Select: {
items: []
items: [],
},
Suggest: {
items: []
items: [],
}
};

const skipList = [
"QueryList", // doesn't render any DOM itself
]

describe("Select isomorphic rendering", () => {
generateIsomorphicTests(
Select,
customProps,
customChildren
);
generateIsomorphicTests(Select, customProps, customChildren, skipList);
});
14 changes: 9 additions & 5 deletions packages/table/src/interactions/resizeHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ export class ResizeHandle extends React.PureComponent<IResizeHandleProps, IResiz
return undefined;
}

const targetClasses = classNames(Classes.TABLE_RESIZE_HANDLE_TARGET, {
[Classes.TABLE_DRAGGING]: this.state.isDragging,
[Classes.TABLE_RESIZE_HORIZONTAL]: orientation === Orientation.HORIZONTAL,
[Classes.TABLE_RESIZE_VERTICAL]: orientation === Orientation.VERTICAL,
});
const targetClasses = classNames(
Classes.TABLE_RESIZE_HANDLE_TARGET,
{
[Classes.TABLE_DRAGGING]: this.state.isDragging,
[Classes.TABLE_RESIZE_HORIZONTAL]: orientation === Orientation.HORIZONTAL,
[Classes.TABLE_RESIZE_VERTICAL]: orientation === Orientation.VERTICAL,
},
this.props.className,
);

const handleClasses = classNames(Classes.TABLE_RESIZE_HANDLE, {
[Classes.TABLE_DRAGGING]: this.state.isDragging,
Expand Down
17 changes: 10 additions & 7 deletions packages/table/test/isotest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
* Licensed under the terms of the LICENSE file distributed with this project.
*/

// @ts-check
const { generateIsomorphicTests } = require("@blueprintjs/test-commons");
const React = require("react");
const Table = require("../lib/cjs");

const draggableElement = React.createElement("button");
const customChildren = {
DragSelectable: draggableElement,
Draggable: draggableElement,
};

const customProps = {
ResizeHandle: {
// needs at least one handler or it returns undefined
onDoubleClick: () => undefined,
},
};

const skipList = [
// Pass-through renders
"DragSelectable",
"Draggable",
]


describe("Table isomorphic rendering", () => {
generateIsomorphicTests(
Table,
customProps,
customChildren
{},
skipList
);
});
6 changes: 5 additions & 1 deletion packages/timezone/test/isotest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
* Licensed under the terms of the LICENSE file distributed with this project.
*/

// @ts-check
const { generateIsomorphicTests } = require("@blueprintjs/test-commons");
const React = require("react");
const Timezone = require("../lib/cjs");

const skipList = []

describe("Timezone isomorphic rendering", () => {
generateIsomorphicTests(
Timezone,
{},
{}
{},
skipList
);
});