diff --git a/packages/core/src/common/classes.ts b/packages/core/src/common/classes.ts index 9a15526870..b66c3ba23d 100644 --- a/packages/core/src/common/classes.ts +++ b/packages/core/src/common/classes.ts @@ -4,26 +4,39 @@ * Licensed under the terms of the LICENSE file distributed with this project. */ +import { Elevation } from "../components/card/card"; import { Alignment } from "./alignment"; import { Intent } from "./intent"; // modifiers -export const DARK = "pt-dark"; export const ACTIVE = "pt-active"; -export const MINIMAL = "pt-minimal"; -export const DISABLED = "pt-disabled"; -export const SMALL = "pt-small"; -export const LARGE = "pt-large"; -export const LOADING = "pt-loading"; -export const INTERACTIVE = "pt-interactive"; export const ALIGN_LEFT = "pt-align-left"; export const ALIGN_RIGHT = "pt-align-right"; -export const INLINE = "pt-inline"; +export const DARK = "pt-dark"; +export const DISABLED = "pt-disabled"; export const FILL = "pt-fill"; export const FIXED = "pt-fixed"; export const FIXED_TOP = "pt-fixed-top"; -export const VERTICAL = "pt-vertical"; +export const INLINE = "pt-inline"; +export const INTERACTIVE = "pt-interactive"; +export const LARGE = "pt-large"; +export const LOADING = "pt-loading"; +export const MINIMAL = "pt-minimal"; +export const MULTILINE = "pt-multiline"; export const ROUND = "pt-round"; +export const SMALL = "pt-small"; +export const VERTICAL = "pt-vertical"; + +export const ELEVATION_0 = elevationClass(Elevation.ZERO); +export const ELEVATION_1 = elevationClass(Elevation.ONE); +export const ELEVATION_2 = elevationClass(Elevation.TWO); +export const ELEVATION_3 = elevationClass(Elevation.THREE); +export const ELEVATION_4 = elevationClass(Elevation.FOUR); + +export const INTENT_PRIMARY = intentClass(Intent.PRIMARY); +export const INTENT_SUCCESS = intentClass(Intent.SUCCESS); +export const INTENT_WARNING = intentClass(Intent.WARNING); +export const INTENT_DANGER = intentClass(Intent.DANGER); // text utilities export const TEXT_MUTED = "pt-text-muted"; @@ -61,6 +74,7 @@ export const CALLOUT_TITLE = "pt-callout-title"; export const CARD = "pt-card"; export const COLLAPSE = "pt-collapse"; +export const COLLAPSE_BODY = "pt-collapse-body"; export const COLLAPSIBLE_LIST = "pt-collapse-list"; @@ -81,12 +95,12 @@ export const DIALOG_HEADER = "pt-dialog-header"; export const DIALOG_HEADER_TITLE = "pt-dialog-header-title"; export const EDITABLE_TEXT = "pt-editable-text"; +export const EDITABLE_TEXT_CONTENT = "pt-editable-content"; +export const EDITABLE_TEXT_EDITING = "pt-editable-editing"; +export const EDITABLE_TEXT_INPUT = "pt-editable-input"; +export const EDITABLE_TEXT_PLACEHOLDER = "pt-editable-placeholder"; -export const ELEVATION_0 = "pt-elevation-0"; -export const ELEVATION_1 = "pt-elevation-1"; -export const ELEVATION_2 = "pt-elevation-2"; -export const ELEVATION_3 = "pt-elevation-3"; -export const ELEVATION_4 = "pt-elevation-4"; +export const FLEX_EXPANDER = "pt-flex-expander"; export const HTML_TABLE = "pt-html-table"; export const HTML_TABLE_STRIPED = "pt-html-table-striped"; @@ -94,6 +108,7 @@ export const HTML_TABLE_BORDERED = "pt-html-table-bordered"; export const INPUT = "pt-input"; export const INPUT_GROUP = "pt-input-group"; +export const INPUT_ACTION = "pt-input-action"; export const CHECKBOX = "pt-checkbox"; export const RADIO = "pt-radio"; @@ -103,10 +118,15 @@ export const FILE_UPLOAD_INPUT = "pt-file-upload-input"; export const INPUT_GHOST = "pt-input-ghost"; -export const INTENT_PRIMARY = "pt-intent-primary"; -export const INTENT_SUCCESS = "pt-intent-success"; -export const INTENT_WARNING = "pt-intent-warning"; -export const INTENT_DANGER = "pt-intent-danger"; +export const KEY = "pt-key"; +export const KEY_COMBO = "pt-key-combo"; +export const MODIFIER_KEY = "pt-modifier-key"; + +export const HOTKEY = "pt-hotkey"; +export const HOTKEY_LABEL = "pt-hotkey-label"; +export const HOTKEY_GROUP = "pt-hotkey-group"; +export const HOTKEY_COLUMN = "pt-hotkey-column"; +export const HOTKEY_DIALOG = "pt-hotkey-dialog"; export const LABEL = "pt-label"; export const FORM_GROUP = "pt-form-group"; @@ -145,6 +165,7 @@ export const POPOVER = "pt-popover"; export const POPOVER_ARROW = "pt-popover-arrow"; export const POPOVER_BACKDROP = "pt-popover-backdrop"; export const POPOVER_CONTENT = "pt-popover-content"; +export const POPOVER_CONTENT_SIZING = "pt-popover-content-sizing"; export const POPOVER_DISMISS = "pt-popover-dismiss"; export const POPOVER_DISMISS_OVERRIDE = "pt-popover-dismiss-override"; export const POPOVER_OPEN = "pt-popover-open"; @@ -164,14 +185,21 @@ export const SELECT = "pt-select"; export const SKELETON = "pt-skeleton"; export const SLIDER = "pt-slider"; -export const SLIDER_HANDLE = `${SLIDER}-handle`; -export const SLIDER_LABEL = `${SLIDER}-label`; +export const SLIDER_HANDLE = "pt-slider-handle"; +export const SLIDER_LABEL = "pt-slider-label"; +export const SLIDER_PROGRESS = "pt-slider-progress"; export const RANGE_SLIDER = "pt-range-slider"; export const SPINNER = "pt-spinner"; +export const SPINNER_HEAD = "pt-spinner-head"; +export const SPINNER_NO_SPIN = "pt-no-spin"; +export const SPINNER_TRACK = "pt-spinner-track"; +export const SPINNER_SVG_CONTAINER = "pt-spinner-svg-container"; export const SVG_SPINNER = "pt-svg-spinner"; export const TAB = "pt-tab"; +export const TAB_INDICATOR = "pt-tab-indicator"; +export const TAB_INDICATOR_WRAPPER = "pt-tab-indicator-wrapper"; export const TAB_LIST = "pt-tab-list"; export const TAB_PANEL = "pt-tab-panel"; export const TABS = "pt-tabs"; @@ -189,6 +217,7 @@ export const TOAST_CONTAINER = "pt-toast-container"; export const TOAST_MESSAGE = "pt-toast-message"; export const TOOLTIP = "pt-tooltip"; +export const TOOLTIP_INDICATOR = "pt-tooltip-indicator"; export const TREE = "pt-tree"; export const TREE_NODE = "pt-tree-node"; @@ -221,6 +250,13 @@ export function alignmentClass(alignment: Alignment) { } } +export function elevationClass(elevation: Elevation) { + if (elevation == null) { + return undefined; + } + return `pt-elevation-${elevation}`; +} + /** Return CSS class for icon, whether or not 'pt-icon-' prefix is included */ export function iconClass(iconName?: string) { if (iconName == null) { diff --git a/packages/core/src/components/card/card.tsx b/packages/core/src/components/card/card.tsx index 3ee88922d4..5b0750ff73 100644 --- a/packages/core/src/components/card/card.tsx +++ b/packages/core/src/components/card/card.tsx @@ -45,14 +45,6 @@ export enum Elevation { FOUR = 4, } -const ELEVATION_CLASSES = [ - Classes.ELEVATION_0, - Classes.ELEVATION_1, - Classes.ELEVATION_2, - Classes.ELEVATION_3, - Classes.ELEVATION_4, -]; - export class Card extends React.PureComponent { public static displayName = "Blueprint2.Card"; public static defaultProps: ICardProps = { @@ -65,7 +57,7 @@ export class Card extends React.PureComponent { const classes = classNames( Classes.CARD, { [Classes.INTERACTIVE]: interactive }, - ELEVATION_CLASSES[elevation], + Classes.elevationClass(elevation), className, ); return
; diff --git a/packages/core/src/components/collapse/collapse.tsx b/packages/core/src/components/collapse/collapse.tsx index 8e02e96e71..bdddfd9bf6 100644 --- a/packages/core/src/components/collapse/collapse.tsx +++ b/packages/core/src/components/collapse/collapse.tsx @@ -150,7 +150,7 @@ export class Collapse extends AbstractPureComponent {this.maybeRenderInput(value)} - + {hasValue ? value : this.props.placeholder}
@@ -283,7 +283,7 @@ export class EditableText extends AbstractPureComponent = { - className: "pt-editable-input", + className: Classes.EDITABLE_TEXT_INPUT, maxLength, onBlur: this.toggleEditing, onChange: this.handleTextChange, diff --git a/packages/core/src/components/forms/inputGroup.tsx b/packages/core/src/components/forms/inputGroup.tsx index a9f5c6214d..28d1231c5e 100644 --- a/packages/core/src/components/forms/inputGroup.tsx +++ b/packages/core/src/components/forms/inputGroup.tsx @@ -111,7 +111,7 @@ export class InputGroup extends React.PureComponent + {rightElement} ); diff --git a/packages/core/src/components/hotkeys/hotkey.tsx b/packages/core/src/components/hotkeys/hotkey.tsx index b9d6bea582..619514ea08 100644 --- a/packages/core/src/components/hotkeys/hotkey.tsx +++ b/packages/core/src/components/hotkeys/hotkey.tsx @@ -7,7 +7,7 @@ import classNames from "classnames"; import * as React from "react"; -import { AbstractPureComponent, IProps } from "../../common"; +import { AbstractPureComponent, Classes, IProps } from "../../common"; import { KeyCombo } from "./keyCombo"; export interface IHotkeyProps extends IProps { @@ -85,10 +85,10 @@ export class Hotkey extends AbstractPureComponent { public render() { const { label, className, ...spreadableProps } = this.props; - const rootClasses = classNames("pt-hotkey", className); + const rootClasses = classNames(Classes.HOTKEY, className); return (
-
{label}
+
{label}
); diff --git a/packages/core/src/components/hotkeys/hotkeys.tsx b/packages/core/src/components/hotkeys/hotkeys.tsx index 69bd444d49..08efd4134d 100644 --- a/packages/core/src/components/hotkeys/hotkeys.tsx +++ b/packages/core/src/components/hotkeys/hotkeys.tsx @@ -7,7 +7,7 @@ import * as React from "react"; import classNames from "classnames"; -import { AbstractPureComponent, IProps } from "../../common"; +import { AbstractPureComponent, Classes, IProps } from "../../common"; import { HOTKEYS_HOTKEY_CHILDREN } from "../../common/errors"; import { isElementOfType } from "../../common/utils"; import { Hotkey, IHotkeyProps } from "./hotkey"; @@ -58,7 +58,7 @@ export class Hotkeys extends AbstractPureComponent { const groupLabel = hotkey.group; if (groupLabel !== lastGroup) { elems.push( -

+

{groupLabel}

, ); @@ -66,7 +66,7 @@ export class Hotkeys extends AbstractPureComponent { } elems.push(); } - const rootClasses = classNames("pt-hotkey-column", this.props.className); + const rootClasses = classNames(Classes.HOTKEY_COLUMN, this.props.className); return
{elems}
; } diff --git a/packages/core/src/components/hotkeys/hotkeysDialog.tsx b/packages/core/src/components/hotkeys/hotkeysDialog.tsx index 7b0fe43c88..b287dbf0ea 100644 --- a/packages/core/src/components/hotkeys/hotkeysDialog.tsx +++ b/packages/core/src/components/hotkeys/hotkeysDialog.tsx @@ -101,7 +101,7 @@ class HotkeysDialog { return ( diff --git a/packages/core/src/components/hotkeys/keyCombo.tsx b/packages/core/src/components/hotkeys/keyCombo.tsx index 698987c957..67cf83eed5 100644 --- a/packages/core/src/components/hotkeys/keyCombo.tsx +++ b/packages/core/src/components/hotkeys/keyCombo.tsx @@ -6,7 +6,7 @@ import classNames from "classnames"; import * as React from "react"; -import { IProps } from "../../common"; +import { Classes, IProps } from "../../common"; import { Icon, IconName } from "../icon/icon"; import { normalizeKeyCombo } from "./hotkeyParser"; @@ -43,18 +43,18 @@ export class KeyCombo extends React.Component { const keys = normalizeKeyCombo(combo) .map(key => (key.length === 1 ? key.toUpperCase() : key)) .map(minimal ? this.renderMinimalKey : this.renderKey); - return {keys}; + return {keys}; } private renderKey = (key: string, index: number) => { const icon = KeyIcons[key]; const reactKey = `key-${index}`; return icon == null ? ( - + {key} ) : ( - + {key} ); diff --git a/packages/core/src/components/progress/progressBar.tsx b/packages/core/src/components/progress/progressBar.tsx index 98bef4f61b..ea8cf52aa1 100644 --- a/packages/core/src/components/progress/progressBar.tsx +++ b/packages/core/src/components/progress/progressBar.tsx @@ -48,7 +48,7 @@ export class ProgressBar extends React.PureComponent { return (
-
+
); } diff --git a/packages/core/src/components/spinner/spinner.tsx b/packages/core/src/components/spinner/spinner.tsx index a6810e1cd5..d357c18fc7 100644 --- a/packages/core/src/components/spinner/spinner.tsx +++ b/packages/core/src/components/spinner/spinner.tsx @@ -45,7 +45,7 @@ export class Spinner extends React.PureComponent { { [Classes.LARGE]: large, [Classes.SMALL]: small, - "pt-no-spin": value != null, + [Classes.SPINNER_NO_SPIN]: value != null, }, className, ); @@ -59,7 +59,7 @@ export class Spinner extends React.PureComponent { // HACKHACK to squash error regarding React.SVGProps missing prop pathLength const svgPathAttributes: React.DOMAttributes = { - className: "pt-spinner-head", + className: Classes.SPINNER_HEAD, d: SPINNER_TRACK, pathLength: PATH_LENGTH, style, @@ -68,7 +68,7 @@ export class Spinner extends React.PureComponent { return this.renderContainer( classes, = 0 ? "-15 -15 130 130" : "0 0 100 100"}> - + , ); @@ -78,7 +78,7 @@ export class Spinner extends React.PureComponent { protected renderContainer(classes: string, content: JSX.Element) { return (
-
{content}
+
{content}
); } diff --git a/packages/core/src/components/tabs/tabs.tsx b/packages/core/src/components/tabs/tabs.tsx index db5110e981..c4cc3c4e2c 100644 --- a/packages/core/src/components/tabs/tabs.tsx +++ b/packages/core/src/components/tabs/tabs.tsx @@ -16,7 +16,7 @@ import * as Utils from "../../common/utils"; import { ITabProps, Tab, TabId } from "./tab"; import { generateTabPanelId, generateTabTitleId, TabTitle } from "./tabTitle"; -export const Expander: React.SFC<{}> = () =>
; +export const Expander: React.SFC<{}> = () =>
; type TabElement = React.ReactElement; @@ -122,8 +122,8 @@ export class Tabs extends AbstractPureComponent { .map(this.renderTabPanel); const tabIndicator = this.props.animate ? ( -
-
+
+
) : ( undefined diff --git a/packages/core/src/components/tag/tag.tsx b/packages/core/src/components/tag/tag.tsx index b16262af87..66c59b60bc 100644 --- a/packages/core/src/components/tag/tag.tsx +++ b/packages/core/src/components/tag/tag.tsx @@ -13,7 +13,7 @@ import { Icon } from "../icon/icon"; export interface ITagProps extends IProps, IIntentProps, React.HTMLAttributes { /** * If set to `true`, the tag will display in an active state. - * This is equivalent to setting `className="pt-active"`. + * This is equivalent to setting `className={Classes.ACTIVE}`. * @default false */ active?: boolean; diff --git a/packages/core/src/components/tree/treeNode.tsx b/packages/core/src/components/tree/treeNode.tsx index a333a293d8..ff46a5015a 100644 --- a/packages/core/src/components/tree/treeNode.tsx +++ b/packages/core/src/components/tree/treeNode.tsx @@ -101,7 +101,10 @@ export class TreeNode extends React.Component, {}> { className, ); - const contentClasses = classNames(Classes.TREE_NODE_CONTENT, `pt-tree-node-content-${this.props.depth}`); + const contentClasses = classNames( + Classes.TREE_NODE_CONTENT, + `${Classes.TREE_NODE_CONTENT}-${this.props.depth}`, + ); return (
  • diff --git a/packages/core/test/alert/alertTests.tsx b/packages/core/test/alert/alertTests.tsx index 2b4c995610..5a3bc545bb 100644 --- a/packages/core/test/alert/alertTests.tsx +++ b/packages/core/test/alert/alertTests.tsx @@ -136,7 +136,7 @@ describe("", () => {

    There is no going back.

    , ); - const overlay = alert.find(".pt-overlay").hostNodes(); + const overlay = alert.find("." + Classes.OVERLAY).hostNodes(); overlay.simulate("keydown", { which: Keys.ESCAPE }); assert.isTrue(onCancel.notCalled); @@ -155,7 +155,7 @@ describe("", () => {

    There is no going back.

    , ); - const backdrop = alert.find(".pt-overlay-backdrop").hostNodes(); + const backdrop = alert.find("." + Classes.OVERLAY_BACKDROP).hostNodes(); backdrop.simulate("mousedown"); assert.isTrue(onCancel.notCalled); diff --git a/packages/core/test/controls/controlsTests.tsx b/packages/core/test/controls/controlsTests.tsx index d01a03d49a..74bcf17991 100644 --- a/packages/core/test/controls/controlsTests.tsx +++ b/packages/core/test/controls/controlsTests.tsx @@ -8,13 +8,13 @@ import { assert } from "chai"; import { mount } from "enzyme"; import * as React from "react"; -import { Icon } from "../../src"; +import { Classes, Icon } from "../../src"; import { Checkbox, IControlProps, Radio, Switch } from "../../src/components/forms/controls"; type ControlType = typeof Checkbox | typeof Radio | typeof Switch; describe("Controls:", () => { - controlsTests(Checkbox, "checkbox", "pt-checkbox", () => { + controlsTests(Checkbox, "checkbox", Classes.CHECKBOX, () => { describe("indeterminate", () => { let input: HTMLInputElement; const handleInputRef = (ref: HTMLInputElement) => (input = ref); @@ -53,15 +53,15 @@ describe("Controls:", () => { }); }); - controlsTests(Switch, "checkbox", "pt-switch"); + controlsTests(Switch, "checkbox", Classes.SWITCH); - controlsTests(Radio, "radio", "pt-radio"); + controlsTests(Radio, "radio", Classes.RADIO); function controlsTests(classType: ControlType, propType: string, className: string, moreTests?: () => void) { describe(`<${classType.displayName.split(".")[1]}>`, () => { - it(`renders .pt-control.${className}`, () => { + it(`renders .${Classes.CONTROL}.${className}`, () => { const control = mountControl(); - assert.isTrue(control.find(".pt-control").hasClass(className)); + assert.isTrue(control.find(`.${Classes.CONTROL}`).hasClass(className)); }); it(`renders input[type=${propType}]`, () => { diff --git a/packages/core/test/controls/inputGroupTests.tsx b/packages/core/test/controls/inputGroupTests.tsx index fbad934c1c..b2eef39da7 100644 --- a/packages/core/test/controls/inputGroupTests.tsx +++ b/packages/core/test/controls/inputGroupTests.tsx @@ -9,13 +9,13 @@ import { mount } from "enzyme"; import * as React from "react"; import { spy } from "sinon"; -import { Icon, InputGroup } from "../../src/index"; +import { Classes, Icon, InputGroup } from "../../src/index"; describe("", () => { it("renders left icon before input", () => { const input = mount().children(); assert.isTrue(input.childAt(0).is(Icon)); - assert.isTrue(input.childAt(1).hasClass("pt-input")); + assert.isTrue(input.childAt(1).hasClass(Classes.INPUT)); }); it("supports custom style", () => { @@ -27,11 +27,11 @@ describe("", () => { assert.equal(inputElement.style.background, "yellow"); }); - it("renders right element inside .pt-input-action after input", () => { + it(`renders right element inside .${Classes.INPUT_ACTION} after input`, () => { const action = mount(} />) .children() .childAt(2); - assert.isTrue(action.hasClass("pt-input-action")); + assert.isTrue(action.hasClass(Classes.INPUT_ACTION)); assert.lengthOf(action.find("address"), 1); }); diff --git a/packages/core/test/forms/labelTests.tsx b/packages/core/test/forms/labelTests.tsx index 6880601505..c780893e91 100644 --- a/packages/core/test/forms/labelTests.tsx +++ b/packages/core/test/forms/labelTests.tsx @@ -7,13 +7,13 @@ import { assert } from "chai"; import { shallow } from "enzyme"; import * as React from "react"; -import { Label } from "../../src/index"; +import { Classes, Label } from "../../src/index"; describe("