UNPKG

2.62 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.removeNonHTMLProps = exports.DISPLAYNAME_PREFIX = void 0;
19var tslib_1 = require("tslib");
20exports.DISPLAYNAME_PREFIX = "Blueprint3";
21/** A collection of curated prop keys used across our Components which are not valid HTMLElement props. */
22var INVALID_PROPS = [
23 "active",
24 "alignText",
25 "asyncControl",
26 "containerRef",
27 "current",
28 "elementRef",
29 "fill",
30 "icon",
31 "inputRef",
32 "intent",
33 "inline",
34 "large",
35 "loading",
36 "leftElement",
37 "leftIcon",
38 "minimal",
39 "onRemove",
40 "outlined",
41 "panel",
42 "panelClassName",
43 "popoverProps",
44 "rightElement",
45 "rightIcon",
46 "round",
47 "small",
48 "text",
49];
50/**
51 * Typically applied to HTMLElements to filter out disallowed props. When applied to a Component,
52 * can filter props from being passed down to the children. Can also filter by a combined list of
53 * supplied prop keys and the denylist (only appropriate for HTMLElements).
54 *
55 * @param props The original props object to filter down.
56 * @param {string[]} invalidProps If supplied, overwrites the default denylist.
57 * @param {boolean} shouldMerge If true, will merge supplied invalidProps and denylist together.
58 */
59function removeNonHTMLProps(props, invalidProps, shouldMerge) {
60 if (invalidProps === void 0) { invalidProps = INVALID_PROPS; }
61 if (shouldMerge === void 0) { shouldMerge = false; }
62 if (shouldMerge) {
63 invalidProps = invalidProps.concat(INVALID_PROPS);
64 }
65 return invalidProps.reduce(function (prev, curr) {
66 // Props with hyphens (e.g. data-*) are always considered html props
67 if (curr.indexOf("-") !== -1) {
68 return prev;
69 }
70 if (prev.hasOwnProperty(curr)) {
71 delete prev[curr];
72 }
73 return prev;
74 }, tslib_1.__assign({}, props));
75}
76exports.removeNonHTMLProps = removeNonHTMLProps;
77//# sourceMappingURL=props.js.map
\No newline at end of file