@elliemae/ds-classnames 2.2.0 → 2.3.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/aggregatedClasses.js +68 -89
- package/cjs/aggregatedClasses.js.map +7 -0
- package/cjs/aggregatedClasses.md +323 -0
- package/cjs/classNameManager.js +68 -77
- package/cjs/classNameManager.js.map +7 -0
- package/cjs/converPropsToFormModifiers.js +48 -25
- package/cjs/converPropsToFormModifiers.js.map +7 -0
- package/cjs/convertPropToFeedBackModifiers.js +51 -25
- package/cjs/convertPropToFeedBackModifiers.js.map +7 -0
- package/cjs/convertPropsToColorModifiers.js +41 -21
- package/cjs/convertPropsToColorModifiers.js.map +7 -0
- package/cjs/convertPropsToLayoutModifiers.js +51 -27
- package/cjs/convertPropsToLayoutModifiers.js.map +7 -0
- package/cjs/convertPropsToSizeModifiers.js +62 -28
- package/cjs/convertPropsToSizeModifiers.js.map +7 -0
- package/cjs/convertPropsToTextModifiers.js +43 -23
- package/cjs/convertPropsToTextModifiers.js.map +7 -0
- package/cjs/index.js +38 -12
- package/cjs/index.js.map +7 -0
- package/cjs/validateNativeProps.js +48 -31
- package/cjs/validateNativeProps.js.map +7 -0
- package/esm/aggregatedClasses.js +41 -75
- package/esm/aggregatedClasses.js.map +7 -0
- package/esm/aggregatedClasses.md +323 -0
- package/esm/classNameManager.js +38 -67
- package/esm/classNameManager.js.map +7 -0
- package/esm/converPropsToFormModifiers.js +19 -23
- package/esm/converPropsToFormModifiers.js.map +7 -0
- package/esm/convertPropToFeedBackModifiers.js +22 -23
- package/esm/convertPropToFeedBackModifiers.js.map +7 -0
- package/esm/convertPropsToColorModifiers.js +12 -19
- package/esm/convertPropsToColorModifiers.js.map +7 -0
- package/esm/convertPropsToLayoutModifiers.js +22 -25
- package/esm/convertPropsToLayoutModifiers.js.map +7 -0
- package/esm/convertPropsToSizeModifiers.js +33 -26
- package/esm/convertPropsToSizeModifiers.js.map +7 -0
- package/esm/convertPropsToTextModifiers.js +14 -21
- package/esm/convertPropsToTextModifiers.js.map +7 -0
- package/esm/index.js +9 -2
- package/esm/index.js.map +7 -0
- package/esm/validateNativeProps.js +19 -19
- package/esm/validateNativeProps.js.map +7 -0
- package/package.json +3 -3
- package/types/classNameManager.d.ts +1 -0
- package/types/converPropsToFormModifiers.d.ts +1 -0
- package/types/convertPropToFeedBackModifiers.d.ts +1 -0
- package/types/convertPropsToColorModifiers.d.ts +1 -0
- package/types/convertPropsToLayoutModifiers.d.ts +1 -0
- package/types/convertPropsToSizeModifiers.d.ts +1 -0
- package/types/convertPropsToTextModifiers.d.ts +1 -0
package/cjs/aggregatedClasses.js
CHANGED
|
@@ -1,91 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var aggregatedClasses_exports = {};
|
|
29
|
+
__export(aggregatedClasses_exports, {
|
|
30
|
+
cssPrefix: () => cssPrefix,
|
|
31
|
+
default: () => aggregatedClasses_default
|
|
32
|
+
});
|
|
33
|
+
var React = __toESM(require("react"));
|
|
34
|
+
var import_react = __toESM(require("react"));
|
|
35
|
+
var import_obj_str = __toESM(require("obj-str"));
|
|
36
|
+
var import_classNameManager = require("./classNameManager");
|
|
37
|
+
var import_dimsum = require("@elliemae/ds-shared/dimsum.config");
|
|
38
|
+
var import_validateNativeProps = require("./validateNativeProps");
|
|
39
|
+
const cssPrefix = import_dimsum.dimsumConfig.classNamePrefix;
|
|
40
|
+
const generateClassNameWithModifier = (block, element, modifier) => `${cssPrefix}-${block}${element ? `__${element}` : ""}--${modifier}`;
|
|
41
|
+
const appendBlockAndPrefixToObj = (obj, block, element) => obj ? Object.keys(obj).reduce((acc, key) => ({
|
|
42
|
+
...acc,
|
|
43
|
+
[`${generateClassNameWithModifier(block, element, key)}`]: obj[key]
|
|
39
44
|
}), {}) : [];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
as
|
|
51
|
-
} = _ref,
|
|
52
|
-
rest = _objectWithoutProperties__default["default"](_ref, _excluded);
|
|
53
|
-
|
|
54
|
-
// get the additional classNames either from a function or an object
|
|
55
|
-
let otherModifiers = appendBlockAndPrefixToObj(additionalModifiers, block, element);
|
|
56
|
-
if (typeof additionalModifiers === 'function') otherModifiers = appendBlockAndPrefixToObj(additionalModifiers(_objectSpread(_objectSpread(_objectSpread({}, rest), classProps), {}, {
|
|
57
|
-
className
|
|
58
|
-
})), block, element);
|
|
59
|
-
const otherModifiersStr = cx__default["default"](otherModifiers);
|
|
60
|
-
const {
|
|
61
|
-
prefix,
|
|
62
|
-
propsToRemoveFromFinalElement = []
|
|
63
|
-
} = options;
|
|
64
|
-
const {
|
|
65
|
-
cssClassName: classNames
|
|
66
|
-
} = classNameManager["default"](block, null, _objectSpread({}, classProps), {
|
|
67
|
-
prefix,
|
|
68
|
-
element
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const cleanedPropsPassedDown = _objectSpread(_objectSpread({}, props), rest);
|
|
72
|
-
|
|
73
|
-
propsToRemoveFromFinalElement.forEach(propKey => {
|
|
74
|
-
delete cleanedPropsPassedDown[propKey];
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (validateNativeProps.isNativeHTMLElement(block)) {
|
|
78
|
-
Object.keys(cleanedPropsPassedDown).forEach(key => {
|
|
79
|
-
if (!validateNativeProps.isValidNativeAttribute(key)) delete cleanedPropsPassedDown[key];
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return /*#__PURE__*/React__default["default"].createElement(as || type, _objectSpread({
|
|
84
|
-
ref: innerRef || ref,
|
|
85
|
-
className: [classNames, otherModifiersStr, className].join(' ')
|
|
86
|
-
}, cleanedPropsPassedDown), children);
|
|
45
|
+
const aggregatedClasses = (type, props) => (block, element, additionalModifiers, options = {}) => import_react.default.forwardRef(({ innerRef, children, classProps, useComponent, className, as, ...rest }, ref) => {
|
|
46
|
+
let otherModifiers = appendBlockAndPrefixToObj(additionalModifiers, block, element);
|
|
47
|
+
if (typeof additionalModifiers === "function")
|
|
48
|
+
otherModifiers = appendBlockAndPrefixToObj(additionalModifiers({ ...rest, ...classProps, className }), block, element);
|
|
49
|
+
const otherModifiersStr = (0, import_obj_str.default)(otherModifiers);
|
|
50
|
+
const { prefix, propsToRemoveFromFinalElement = [] } = options;
|
|
51
|
+
const { cssClassName: classNames } = (0, import_classNameManager.convertPropToCssClassName)(block, null, { ...classProps }, { prefix, element });
|
|
52
|
+
const cleanedPropsPassedDown = { ...props, ...rest };
|
|
53
|
+
propsToRemoveFromFinalElement.forEach((propKey) => {
|
|
54
|
+
delete cleanedPropsPassedDown[propKey];
|
|
87
55
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
56
|
+
if ((0, import_validateNativeProps.isNativeHTMLElement)(block)) {
|
|
57
|
+
Object.keys(cleanedPropsPassedDown).forEach((key) => {
|
|
58
|
+
if (!(0, import_validateNativeProps.isValidNativeAttribute)(key))
|
|
59
|
+
delete cleanedPropsPassedDown[key];
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return import_react.default.createElement(as || type, {
|
|
63
|
+
ref: innerRef || ref,
|
|
64
|
+
className: [classNames, otherModifiersStr, className].join(" "),
|
|
65
|
+
...cleanedPropsPassedDown
|
|
66
|
+
}, children);
|
|
67
|
+
});
|
|
68
|
+
var aggregatedClasses_default = aggregatedClasses;
|
|
69
|
+
module.exports = __toCommonJS(aggregatedClasses_exports);
|
|
70
|
+
//# sourceMappingURL=aggregatedClasses.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/aggregatedClasses.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable prettier/prettier */\n/* eslint-disable max-params */\n/* eslint-disable react/prop-types */\nimport React from 'react';\nimport cx from 'obj-str';\nimport { convertPropToCssClassName } from './classNameManager';\nimport { dimsumConfig } from '@elliemae/ds-shared/dimsum.config';\nimport {\n isValidNativeAttribute,\n isNativeHTMLElement,\n} from './validateNativeProps';\n\nexport const cssPrefix = dimsumConfig.classNamePrefix;\n\ntype AggregatedClassesT<T = unknown> = (\n type: any,\n props?: any,\n) => (\n block: string,\n element?: string | null,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n additionalModifiers?: { [key: string]: unknown } | ((arg: any) => { [key: string]: unknown }),\n options?: { [key: string]: unknown },\n) => React.ForwardRefExoticComponent<React.RefAttributes<T>>;\n\nconst generateClassNameWithModifier = (block, element, modifier) =>\n `${cssPrefix}-${block}${element ? `__${element}` : ''}--${modifier}`;\n\nconst appendBlockAndPrefixToObj = (obj, block, element) =>\n obj\n ? Object.keys(obj).reduce(\n (acc, key) => ({\n ...acc,\n [`${generateClassNameWithModifier(block, element, key)}`]: obj[key],\n }),\n {},\n )\n : [];\n\nconst aggregatedClasses: AggregatedClassesT=\n (type, props) =>\n (block, element, additionalModifiers, options = {}) =>\n React.forwardRef(({ innerRef, children, classProps, useComponent, className, as, ...rest }, ref) => {\n // get the additional classNames either from a function or an object\n let otherModifiers = appendBlockAndPrefixToObj(additionalModifiers, block, element);\n if (typeof additionalModifiers === 'function')\n otherModifiers = appendBlockAndPrefixToObj(\n additionalModifiers({ ...rest, ...classProps, className }),\n block,\n element,\n );\n\n const otherModifiersStr = cx(otherModifiers);\n const { prefix, propsToRemoveFromFinalElement = [] } = options;\n const { cssClassName: classNames } = convertPropToCssClassName(\n block,\n null,\n { ...classProps },\n { prefix, element },\n );\n const cleanedPropsPassedDown = { ...props, ...rest };\n propsToRemoveFromFinalElement.forEach((propKey) => {\n delete cleanedPropsPassedDown[propKey];\n });\n\n if (isNativeHTMLElement(block)) {\n Object.keys(cleanedPropsPassedDown).forEach((key) => {\n if (!isValidNativeAttribute(key)) delete cleanedPropsPassedDown[key];\n });\n }\n\n return React.createElement(\n as || type,\n {\n ref: innerRef || ref,\n className: [classNames, otherModifiersStr, className].join(' '),\n ...cleanedPropsPassedDown,\n },\n children,\n );\n });\n\nexport default aggregatedClasses;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAkB;AAClB,qBAAe;AACf,8BAA0C;AAC1C,oBAA6B;AAC7B,iCAGO;AAEA,MAAM,YAAY,2BAAa;AAatC,MAAM,gCAAgC,CAAC,OAAO,SAAS,aACrD,GAAG,aAAa,QAAQ,UAAU,KAAK,YAAY,OAAO;AAE5D,MAAM,4BAA4B,CAAC,KAAK,OAAO,YAC7C,MACI,OAAO,KAAK,KAAK,OACjB,CAAC,KAAK,QAAS;AAAA,KACV;AAAA,GACF,GAAG,8BAA8B,OAAO,SAAS,SAAS,IAAI;AAAA,IAEjE,MAEA;AAEN,MAAM,oBACJ,CAAC,MAAM,UACL,CAAC,OAAO,SAAS,qBAAqB,UAAU,OAC9C,qBAAM,WAAW,CAAC,EAAE,UAAU,UAAU,YAAY,cAAc,WAAW,OAAO,QAAQ,QAAQ;AAElG,MAAI,iBAAiB,0BAA0B,qBAAqB,OAAO;AAC3E,MAAI,OAAO,wBAAwB;AACjC,qBAAiB,0BACf,oBAAoB,KAAK,SAAS,YAAY,cAC9C,OACA;AAGJ,QAAM,oBAAoB,4BAAG;AAC7B,QAAM,EAAE,QAAQ,gCAAgC,OAAO;AACvD,QAAM,EAAE,cAAc,eAAe,uDACnC,OACA,MACA,KAAK,cACL,EAAE,QAAQ;AAEZ,QAAM,yBAAyB,KAAK,UAAU;AAC9C,gCAA8B,QAAQ,CAAC,YAAY;AACjD,WAAO,uBAAuB;AAAA;AAGhC,MAAI,oDAAoB,QAAQ;AAC9B,WAAO,KAAK,wBAAwB,QAAQ,CAAC,QAAQ;AACnD,UAAI,CAAC,uDAAuB;AAAM,eAAO,uBAAuB;AAAA;AAAA;AAIpE,SAAO,qBAAM,cACX,MAAM,MACN;AAAA,IACE,KAAK,YAAY;AAAA,IACjB,WAAW,CAAC,YAAY,mBAAmB,WAAW,KAAK;AAAA,OACxD;AAAA,KAEL;AAAA;AAIV,IAAO,4BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
# aggregatedClasses
|
|
2
|
+
|
|
3
|
+
Utility to clean up the renders of too many classNames, internally uses the classNamePipeline and obj-str to ease the workflow.
|
|
4
|
+
Follows BEM methodology (block - element - modifier)
|
|
5
|
+
<br> This utility allows us to create components outside the render method with the block-element-modifiers injected in the className
|
|
6
|
+
## Constructor
|
|
7
|
+
|
|
8
|
+
```jsx
|
|
9
|
+
const blockName = 'form-item'
|
|
10
|
+
|
|
11
|
+
const Label = aggregatedClasses('div')(blockName, 'label')
|
|
12
|
+
const InputController = aggregatedClasses('div')(blockName, 'controller')
|
|
13
|
+
|
|
14
|
+
// generates
|
|
15
|
+
<div className='ds-em-form-item__label' />
|
|
16
|
+
<div className='ds-em-form-item__controller' />
|
|
17
|
+
|
|
18
|
+
// and based on the props passed through classProps is going to inject the proper modifiers
|
|
19
|
+
render() {
|
|
20
|
+
return (
|
|
21
|
+
<Label
|
|
22
|
+
classProps={{
|
|
23
|
+
hasError: true,
|
|
24
|
+
readOnly: true,
|
|
25
|
+
disabled: true
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// generates
|
|
32
|
+
<div className='ds-em-form-item__label ds-em-form-item__label--error ds-em-form-item__label--readonly ds-em-form-item__label--disabled' />
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
This creates a component with the specified element or other component and creates the className based on the blockName, the elementName, and the props that this component is going to receive.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Parameters
|
|
40
|
+
```js
|
|
41
|
+
export default type => (block, element, additionalClassNames, options)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
@type - element or component to create <br>
|
|
45
|
+
@block - block name <br>
|
|
46
|
+
@element - element name
|
|
47
|
+
@additionalModifiers - object that appends new modifiers to the className if the value is true. <br>
|
|
48
|
+
Also we can use a function that takes the props of the component created <br>
|
|
49
|
+
<br>
|
|
50
|
+
@options - Object to configure 'prefix'
|
|
51
|
+
|
|
52
|
+
####Example
|
|
53
|
+
```js
|
|
54
|
+
const Wrapper = aggregatedClasses('div')(blockName, 'elementName', props => ({
|
|
55
|
+
someModifier: true,
|
|
56
|
+
otherModifier: props.hasClass
|
|
57
|
+
}))
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
####Example
|
|
62
|
+
```js
|
|
63
|
+
const Wrapper = aggregatedClasses('div')(blockName, 'elementName', {someClassName: true}, {prefix: 'DIMSUM'})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```jsx
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// this translates
|
|
70
|
+
const Wrapper = ({ children, ...rest }) => {
|
|
71
|
+
const { cssClassName } = convertPropToCssClassName(
|
|
72
|
+
blockName,
|
|
73
|
+
null,
|
|
74
|
+
{ ...rest })
|
|
75
|
+
return (
|
|
76
|
+
<div className={cssClassName}>
|
|
77
|
+
{ children }
|
|
78
|
+
</div>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// to this
|
|
83
|
+
const WrapperClassed = aggregatedClasses('div')(blockName, null)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Complete example
|
|
87
|
+
before
|
|
88
|
+
```jsx
|
|
89
|
+
import React, { Component } from 'react'
|
|
90
|
+
import getSvgPath from 'components/basic/form/OutlinedInputField/getSvgPath'
|
|
91
|
+
import { convertPropToCssClassName } from '@elliemae/ds-classnames'
|
|
92
|
+
import { DSTextWrapper } from 'components/index'
|
|
93
|
+
|
|
94
|
+
const blockName = 'labeled-outline'
|
|
95
|
+
const pfxBlockName = `em-ds-${blockName}`
|
|
96
|
+
|
|
97
|
+
class DSFloatingLabelInput extends Component {
|
|
98
|
+
constructor(props) {
|
|
99
|
+
super(props)
|
|
100
|
+
this.wrapper = React.createRef()
|
|
101
|
+
this.pathEl = React.createRef()
|
|
102
|
+
this.outlineEl = React.createRef()
|
|
103
|
+
this.outlineIdleEl = React.createRef()
|
|
104
|
+
this.labelEl = React.createRef()
|
|
105
|
+
this.state = {
|
|
106
|
+
open: props.open,
|
|
107
|
+
value: props.value,
|
|
108
|
+
focused: false,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
componentWillUnmount() {
|
|
112
|
+
window.removeEventListener('resize', this.updatePath)
|
|
113
|
+
}
|
|
114
|
+
get sizes() {
|
|
115
|
+
return {
|
|
116
|
+
labelWidth: this.labelEl.current.offsetWidth * 0.9,
|
|
117
|
+
width: this.wrapper.current.offsetWidth,
|
|
118
|
+
height: this.wrapper.current.offsetHeight,
|
|
119
|
+
radiusStyle: window.getComputedStyle(this.outlineIdleEl.current).getPropertyValue('border-radius'),
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
updatePath() {
|
|
123
|
+
const path = getSvgPath(this.sizes)
|
|
124
|
+
this.pathEl.current.setAttribute('d', path)
|
|
125
|
+
}
|
|
126
|
+
openOutline() {
|
|
127
|
+
this.setState({ open: true })
|
|
128
|
+
}
|
|
129
|
+
closeOutline() {
|
|
130
|
+
this.setState({ open: false })
|
|
131
|
+
}
|
|
132
|
+
render() {
|
|
133
|
+
const {
|
|
134
|
+
className,
|
|
135
|
+
hasError,
|
|
136
|
+
readOnly,
|
|
137
|
+
disabled,
|
|
138
|
+
inputComponent,
|
|
139
|
+
label,
|
|
140
|
+
} = this.props
|
|
141
|
+
const InputComponent = inputComponent
|
|
142
|
+
const { open, focused, value } = this.state
|
|
143
|
+
const isOpen = open || focused || !!value
|
|
144
|
+
|
|
145
|
+
const { cssClassName: classNames } = convertPropToCssClassName(
|
|
146
|
+
blockName,
|
|
147
|
+
className, {
|
|
148
|
+
hasError,
|
|
149
|
+
readOnly,
|
|
150
|
+
disabled,
|
|
151
|
+
})
|
|
152
|
+
return (
|
|
153
|
+
<div
|
|
154
|
+
ref={this.wrapper}
|
|
155
|
+
className={`${classNames} ${isOpen ? `${pfxBlockName}--opened` : ''} ${focused ? `${pfxBlockName}--focused` : ''}`}
|
|
156
|
+
onMouseEnter={this.openOutline}
|
|
157
|
+
onMouseLeave={this.closeOutline}
|
|
158
|
+
>
|
|
159
|
+
<div
|
|
160
|
+
ref={this.outlineEl}
|
|
161
|
+
className={`${pfxBlockName}__outline`}
|
|
162
|
+
>
|
|
163
|
+
<svg>
|
|
164
|
+
<path
|
|
165
|
+
ref={this.pathEl}
|
|
166
|
+
className={`${pfxBlockName}__outline__path`}
|
|
167
|
+
/>
|
|
168
|
+
</svg>
|
|
169
|
+
</div>
|
|
170
|
+
<div
|
|
171
|
+
ref={this.outlineIdleEl}
|
|
172
|
+
className={`${pfxBlockName}__idle`}
|
|
173
|
+
/>
|
|
174
|
+
<div className={`${pfxBlockName}__content`}>
|
|
175
|
+
<InputComponent
|
|
176
|
+
disabled={disabled}
|
|
177
|
+
hasError={hasError}
|
|
178
|
+
onBlur={() => this.setState({ focused: false })}
|
|
179
|
+
onChange={e => this.setState({ value: e.target.value })}
|
|
180
|
+
onFocus={() => this.setState({ focused: true })}
|
|
181
|
+
readOnly={readOnly}
|
|
182
|
+
value={value}
|
|
183
|
+
/>
|
|
184
|
+
<label
|
|
185
|
+
ref={this.labelEl}
|
|
186
|
+
className={`${pfxBlockName}__label ${isOpen ? `${pfxBlockName}__label--floated` : ''}`}
|
|
187
|
+
>
|
|
188
|
+
<DSTextWrapper
|
|
189
|
+
innerRef={this.labelEl}
|
|
190
|
+
maxWidth='20px'
|
|
191
|
+
text={label}
|
|
192
|
+
textEllipsis
|
|
193
|
+
/>
|
|
194
|
+
</label>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default DSFloatingLabelInput
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
after
|
|
206
|
+
|
|
207
|
+
```jsx
|
|
208
|
+
import React, { Component } from 'react'
|
|
209
|
+
import getSvgPath from 'components/basic/form/OutlinedInputField/getSvgPath'
|
|
210
|
+
import { DSTextWrapper } from 'components/index'
|
|
211
|
+
import { aggregatedClasses } from '@elliemae/ds-classnames'
|
|
212
|
+
|
|
213
|
+
const blockName = 'labeled-outline'
|
|
214
|
+
|
|
215
|
+
const Wrapper = aggregatedClasses('div')(blockName, null, ({ isOpen, isFocused }) => ({
|
|
216
|
+
opened: isOpen,
|
|
217
|
+
focused: isFocused,
|
|
218
|
+
}))
|
|
219
|
+
|
|
220
|
+
const FloatingLabel = aggregatedClasses('label')(blockName, 'label', ({ isOpen }) => ({
|
|
221
|
+
floated: isOpen,
|
|
222
|
+
}))
|
|
223
|
+
|
|
224
|
+
const OutlineContent = aggregatedClasses('div')(blockName, 'content')
|
|
225
|
+
const OutlineIdle = aggregatedClasses('div')(blockName, 'idle')
|
|
226
|
+
const Outline = aggregatedClasses('div')(blockName, 'outline')
|
|
227
|
+
const OutlinePath = aggregatedClasses('path')(blockName, 'outline__path')
|
|
228
|
+
|
|
229
|
+
class DSFloatingLabelInput extends Component {
|
|
230
|
+
constructor(props) {
|
|
231
|
+
super(props)
|
|
232
|
+
this.wrapper = React.createRef()
|
|
233
|
+
this.pathEl = React.createRef()
|
|
234
|
+
this.outlineEl = React.createRef()
|
|
235
|
+
this.outlineIdleEl = React.createRef()
|
|
236
|
+
this.labelEl = React.createRef()
|
|
237
|
+
this.state = {
|
|
238
|
+
open: props.open,
|
|
239
|
+
value: props.value,
|
|
240
|
+
focused: false,
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
componentDidMount() {
|
|
244
|
+
// TODO: not getting referenced elements height / width without this
|
|
245
|
+
// this is a temporary workaround
|
|
246
|
+
setTimeout(() => this.updatePath(), 1)
|
|
247
|
+
window.addEventListener('resize', this.updatePath)
|
|
248
|
+
}
|
|
249
|
+
componentWillUnmount() {
|
|
250
|
+
window.removeEventListener('resize', this.updatePath)
|
|
251
|
+
}
|
|
252
|
+
get sizes() {
|
|
253
|
+
return {
|
|
254
|
+
labelWidth: this.labelEl.current.offsetWidth * 0.9,
|
|
255
|
+
width: this.wrapper.current.offsetWidth,
|
|
256
|
+
height: this.wrapper.current.offsetHeight,
|
|
257
|
+
radiusStyle: window.getComputedStyle(this.outlineIdleEl.current).getPropertyValue('border-radius'),
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
updatePath() {
|
|
261
|
+
const path = getSvgPath(this.sizes)
|
|
262
|
+
this.pathEl.current.setAttribute('d', path)
|
|
263
|
+
}
|
|
264
|
+
openOutline() {
|
|
265
|
+
this.setState({ open: true })
|
|
266
|
+
}
|
|
267
|
+
closeOutline() {
|
|
268
|
+
this.setState({ open: false })
|
|
269
|
+
}
|
|
270
|
+
render() {
|
|
271
|
+
const {
|
|
272
|
+
hasError,
|
|
273
|
+
readOnly,
|
|
274
|
+
disabled,
|
|
275
|
+
inputComponent,
|
|
276
|
+
label,
|
|
277
|
+
} = this.props
|
|
278
|
+
const InputComponent = inputComponent
|
|
279
|
+
const { open, focused, value } = this.state
|
|
280
|
+
const isOpen = open || focused || !!value
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<Wrapper
|
|
284
|
+
classProps={{ hasError, isOpen, isFocused: focused, readOnly, disabled }}
|
|
285
|
+
innerRef={this.wrapper}
|
|
286
|
+
onMouseEnter={this.openOutline}
|
|
287
|
+
onMouseLeave={this.closeOutline}
|
|
288
|
+
>
|
|
289
|
+
<Outline innerRef={this.outlineEl}>
|
|
290
|
+
<svg>
|
|
291
|
+
<OutlinePath innerRef={this.pathEl} />
|
|
292
|
+
</svg>
|
|
293
|
+
</Outline>
|
|
294
|
+
<OutlineIdle innerRef={this.outlineIdleEl} />
|
|
295
|
+
<OutlineContent>
|
|
296
|
+
<InputComponent
|
|
297
|
+
disabled={disabled}
|
|
298
|
+
hasError={hasError}
|
|
299
|
+
onBlur={() => this.setState({ focused: false })}
|
|
300
|
+
onChange={e => this.setState({ value: e.target.value })}
|
|
301
|
+
onFocus={() => this.setState({ focused: true })}
|
|
302
|
+
readOnly={readOnly}
|
|
303
|
+
value={value}
|
|
304
|
+
/>
|
|
305
|
+
<FloatingLabel
|
|
306
|
+
classProps={{ isOpen }}
|
|
307
|
+
innerRef={this.labelEl}
|
|
308
|
+
>
|
|
309
|
+
<DSTextWrapper
|
|
310
|
+
maxWidth='20px'
|
|
311
|
+
text={label}
|
|
312
|
+
textEllipsis
|
|
313
|
+
/>
|
|
314
|
+
</FloatingLabel>
|
|
315
|
+
</OutlineContent>
|
|
316
|
+
</Wrapper>
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export default DSFloatingLabelInput
|
|
322
|
+
|
|
323
|
+
```
|
package/cjs/classNameManager.js
CHANGED
|
@@ -1,92 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var classNameManager_exports = {};
|
|
29
|
+
__export(classNameManager_exports, {
|
|
30
|
+
convertPropToCssClassName: () => cssPipeline,
|
|
31
|
+
cssPrefix: () => cssPrefix,
|
|
32
|
+
default: () => classNameManager_default
|
|
33
|
+
});
|
|
34
|
+
var React = __toESM(require("react"));
|
|
35
|
+
var import_utils = require("@elliemae/ds-utilities/utils");
|
|
36
|
+
var import_dimsum = require("@elliemae/ds-shared/dimsum.config");
|
|
37
|
+
var import_converPropsToFormModifiers = require("./converPropsToFormModifiers");
|
|
38
|
+
var import_convertPropsToLayoutModifiers = require("./convertPropsToLayoutModifiers");
|
|
39
|
+
var import_convertPropToFeedBackModifiers = require("./convertPropToFeedBackModifiers");
|
|
40
|
+
var import_convertPropsToSizeModifiers = require("./convertPropsToSizeModifiers");
|
|
41
|
+
var import_convertPropsToTextModifiers = require("./convertPropsToTextModifiers");
|
|
42
|
+
var import_convertPropsToColorModifiers = require("./convertPropsToColorModifiers");
|
|
43
|
+
const cssPrefix = `${import_dimsum.dimsumConfig.classNamePrefix}-`;
|
|
44
|
+
const executePipelines = (props) => {
|
|
45
|
+
const form = (0, import_converPropsToFormModifiers.pipe)().execute(props);
|
|
46
|
+
const layout = (0, import_convertPropsToLayoutModifiers.pipe)().execute(props);
|
|
47
|
+
const feedback = (0, import_convertPropToFeedBackModifiers.pipe)().execute(props);
|
|
48
|
+
const size = (0, import_convertPropsToSizeModifiers.pipe)().execute(props);
|
|
49
|
+
const text = (0, import_convertPropsToTextModifiers.pipe)().execute(props);
|
|
50
|
+
const color = (0, import_convertPropsToColorModifiers.pipe)().execute(props);
|
|
28
51
|
return [...form, ...layout, ...feedback, ...size, ...text, ...color];
|
|
29
52
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @param blockName
|
|
37
|
-
* @param cssClassNameModifier
|
|
38
|
-
* @param props
|
|
39
|
-
* @param options
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const cssPipeline = function () {
|
|
44
|
-
let blockName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'block';
|
|
45
|
-
let cssClassNameModifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
46
|
-
let props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
47
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
48
|
-
const {
|
|
49
|
-
prefix,
|
|
50
|
-
element
|
|
51
|
-
} = options;
|
|
52
|
-
const prefixBlockName = "".concat(prefix || cssPrefix).concat(blockName).concat(element ? "__".concat(element) : ''); // PipeLine
|
|
53
|
-
|
|
54
|
-
const pipes = !utils.isEmpty(props) ? executePipelines(props) : [];
|
|
55
|
-
const basePipeline = [prefixBlockName, ...pipes]; // specific classname
|
|
56
|
-
|
|
57
|
-
const className = cssClassNameModifier ? [...basePipeline].join(" ".concat(prefixBlockName, "--")).concat(" ".concat(cssClassNameModifier)) : [...basePipeline].join(" ".concat(prefixBlockName, "--"));
|
|
53
|
+
const cssPipeline = (blockName = "block", cssClassNameModifier = "", props = {}, options = {}) => {
|
|
54
|
+
const { prefix, element } = options;
|
|
55
|
+
const prefixBlockName = `${prefix || cssPrefix}${blockName}${element ? `__${element}` : ""}`;
|
|
56
|
+
const pipes = !(0, import_utils.isEmpty)(props) ? executePipelines(props) : [];
|
|
57
|
+
const basePipeline = [prefixBlockName, ...pipes];
|
|
58
|
+
const className = cssClassNameModifier ? [...basePipeline].join(` ${prefixBlockName}--`).concat(` ${cssClassNameModifier}`) : [...basePipeline].join(` ${prefixBlockName}--`);
|
|
58
59
|
return {
|
|
59
60
|
blockName,
|
|
60
61
|
cssPrefix,
|
|
61
62
|
prefixBlockName,
|
|
62
63
|
cssClassName: className,
|
|
63
|
-
|
|
64
64
|
mainModifier(modifier) {
|
|
65
|
-
return
|
|
65
|
+
return `${className}--${modifier}`;
|
|
66
66
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
let usePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
70
|
-
return "".concat(!usePrefix ? blockName : prefixBlockName, "-").concat(elementName);
|
|
67
|
+
classNameBlock(elementName, usePrefix = true) {
|
|
68
|
+
return `${!usePrefix ? blockName : prefixBlockName}-${elementName}`;
|
|
71
69
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
let elementBlockName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
75
|
-
return "".concat(prefixBlockName, "-").concat(elementBlockName, "--").concat(modifierName);
|
|
70
|
+
classNameBlockModifier(modifierName, elementBlockName = "") {
|
|
71
|
+
return `${prefixBlockName}-${elementBlockName}--${modifierName}`;
|
|
76
72
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
let elementBlockName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
80
|
-
return "".concat(prefixBlockName).concat(elementBlockName ? "-".concat(elementBlockName) : '', "__").concat(elementName);
|
|
73
|
+
classNameElement(elementName, elementBlockName = "") {
|
|
74
|
+
return `${prefixBlockName}${elementBlockName ? `-${elementBlockName}` : ""}__${elementName}`;
|
|
81
75
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let elementName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
85
|
-
return "".concat(prefixBlockName).concat(elementName ? "__".concat(elementName) : '', "--").concat(modifierName);
|
|
76
|
+
classNameModifier(modifierName, elementName = "") {
|
|
77
|
+
return `${prefixBlockName}${elementName ? `__${elementName}` : ""}--${modifierName}`;
|
|
86
78
|
}
|
|
87
|
-
|
|
88
79
|
};
|
|
89
80
|
};
|
|
90
|
-
|
|
91
|
-
exports
|
|
92
|
-
|
|
81
|
+
var classNameManager_default = cssPipeline;
|
|
82
|
+
module.exports = __toCommonJS(classNameManager_exports);
|
|
83
|
+
//# sourceMappingURL=classNameManager.js.map
|