@synerise/ds-form-field 1.0.0
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/LICENSE.md +21 -0
- package/README.md +39 -0
- package/dist/FormField.d.ts +4 -0
- package/dist/FormField.js +33 -0
- package/dist/FormField.styles.d.ts +13 -0
- package/dist/FormField.styles.js +44 -0
- package/dist/FormField.types.d.ts +24 -0
- package/dist/FormField.types.js +1 -0
- package/dist/components/ContentAboveElement.d.ts +3 -0
- package/dist/components/ContentAboveElement.js +16 -0
- package/dist/components/ContentBelowElement.d.ts +3 -0
- package/dist/components/ContentBelowElement.js +11 -0
- package/dist/components/FormFieldLabel.d.ts +3 -0
- package/dist/components/FormFieldLabel.js +33 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/modules.d.js +1 -0
- package/package.json +48 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Synerise
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: form-field
|
|
3
|
+
title: FormField
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
FormField UI Component
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm i @synerise/ds-form-field
|
|
12
|
+
or
|
|
13
|
+
yarn add @synerise/ds-form-field
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
import FormField from '@synerise/ds-form-field'
|
|
20
|
+
|
|
21
|
+
<FormField />
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Demo
|
|
26
|
+
|
|
27
|
+
<iframe src="/storybook-static/iframe.html?id=components-form-field--default"></iframe>
|
|
28
|
+
|
|
29
|
+
## API
|
|
30
|
+
|
|
31
|
+
| Property | Description | Type | Default |
|
|
32
|
+
| ------------- | ----------------------------------------------- | ------------ | ------- |
|
|
33
|
+
| id | Element id to match label for attribute | string | - |
|
|
34
|
+
| label | Element label | ReactNode | - |
|
|
35
|
+
| tooltip | Label tooltip text | ReactNode | - |
|
|
36
|
+
| tooltipConfig | Label tooltip extra config | TooltipProps | - |
|
|
37
|
+
| rightSide | Content rendered to the right side of the label | ReactNode | - |
|
|
38
|
+
| description | Element description | ReactNode | - |
|
|
39
|
+
| errorText | Error message | ReactNode | - |
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var _excluded = ["label", "tooltip", "id", "rightSide", "tooltipConfig", "description", "errorText", "children"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import React, { useId } from 'react';
|
|
5
|
+
import * as S from './FormField.styles';
|
|
6
|
+
import { ContentAboveElement } from './components/ContentAboveElement';
|
|
7
|
+
import { ContentBelowElement } from './components/ContentBelowElement';
|
|
8
|
+
var FormField = function FormField(_ref) {
|
|
9
|
+
var label = _ref.label,
|
|
10
|
+
tooltip = _ref.tooltip,
|
|
11
|
+
id = _ref.id,
|
|
12
|
+
rightSide = _ref.rightSide,
|
|
13
|
+
tooltipConfig = _ref.tooltipConfig,
|
|
14
|
+
description = _ref.description,
|
|
15
|
+
errorText = _ref.errorText,
|
|
16
|
+
children = _ref.children,
|
|
17
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
18
|
+
var uniqueId = useId();
|
|
19
|
+
var hasContent = Boolean(label || rightSide || description || errorText);
|
|
20
|
+
return /*#__PURE__*/React.createElement(S.FormFieldWrapper, _extends({
|
|
21
|
+
hasContent: hasContent
|
|
22
|
+
}, rest), /*#__PURE__*/React.createElement(ContentAboveElement, {
|
|
23
|
+
label: label,
|
|
24
|
+
rightSide: rightSide,
|
|
25
|
+
id: id || uniqueId,
|
|
26
|
+
tooltip: tooltip,
|
|
27
|
+
tooltipConfig: tooltipConfig
|
|
28
|
+
}), /*#__PURE__*/React.createElement(S.FormFieldComponent, null, children), /*#__PURE__*/React.createElement(ContentBelowElement, {
|
|
29
|
+
description: description,
|
|
30
|
+
errorText: errorText
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
export default FormField;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const FormFieldWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
2
|
+
hasContent?: boolean | undefined;
|
|
3
|
+
}, never>;
|
|
4
|
+
export declare const ErrorText: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
+
export declare const Description: import("styled-components").StyledComponent<"div", any, {
|
|
6
|
+
disabled?: boolean | undefined;
|
|
7
|
+
}, never>;
|
|
8
|
+
export declare const FormFieldLabelWrapper: import("styled-components").StyledComponent<"label", any, {}, never>;
|
|
9
|
+
export declare const IconWrapper: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
10
|
+
export declare const FormFieldComponent: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
11
|
+
export declare const ContentAbove: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
12
|
+
export declare const ContentBelow: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
13
|
+
export declare const RightSide: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { ErrorText as BaseErrorText, Description as BaseDescription, Label, macro } from '@synerise/ds-typography';
|
|
3
|
+
export var FormFieldWrapper = styled.div.withConfig({
|
|
4
|
+
displayName: "FormFieldstyles__FormFieldWrapper",
|
|
5
|
+
componentId: "sc-584zv-0"
|
|
6
|
+
})(["", ""], function (props) {
|
|
7
|
+
return props.hasContent && "display: flex;\n flex-direction: column;\n gap: 8px;\n align-items: stretch;\n justify-content: flex-start;\n ";
|
|
8
|
+
});
|
|
9
|
+
export var ErrorText = styled(BaseErrorText).withConfig({
|
|
10
|
+
displayName: "FormFieldstyles__ErrorText",
|
|
11
|
+
componentId: "sc-584zv-1"
|
|
12
|
+
})(["margin:0;"]);
|
|
13
|
+
export var Description = styled(BaseDescription).withConfig({
|
|
14
|
+
displayName: "FormFieldstyles__Description",
|
|
15
|
+
componentId: "sc-584zv-2"
|
|
16
|
+
})([""]);
|
|
17
|
+
export var FormFieldLabelWrapper = styled(Label).withConfig({
|
|
18
|
+
displayName: "FormFieldstyles__FormFieldLabelWrapper",
|
|
19
|
+
componentId: "sc-584zv-3"
|
|
20
|
+
})(["", ";height:17px;display:flex;align-items:center;cursor:pointer;white-space:nowrap;min-width:0;overflow:hidden;text-overflow:ellipsis;"], macro.heading);
|
|
21
|
+
export var IconWrapper = styled.span.withConfig({
|
|
22
|
+
displayName: "FormFieldstyles__IconWrapper",
|
|
23
|
+
componentId: "sc-584zv-4"
|
|
24
|
+
})(["display:inline-block;.ds-icon > svg{margin-top:-1px;fill:", ";}"], function (props) {
|
|
25
|
+
return props.theme.palette['grey-400'];
|
|
26
|
+
});
|
|
27
|
+
export var FormFieldComponent = styled.div.withConfig({
|
|
28
|
+
displayName: "FormFieldstyles__FormFieldComponent",
|
|
29
|
+
componentId: "sc-584zv-5"
|
|
30
|
+
})([""]);
|
|
31
|
+
export var ContentAbove = styled.div.withConfig({
|
|
32
|
+
displayName: "FormFieldstyles__ContentAbove",
|
|
33
|
+
componentId: "sc-584zv-6"
|
|
34
|
+
})(["display:flex;justify-content:space-between;min-height:18px;"]);
|
|
35
|
+
export var ContentBelow = styled.div.withConfig({
|
|
36
|
+
displayName: "FormFieldstyles__ContentBelow",
|
|
37
|
+
componentId: "sc-584zv-7"
|
|
38
|
+
})(["display:flex;flex-direction:column;gap:4px;"]);
|
|
39
|
+
export var RightSide = styled.div.withConfig({
|
|
40
|
+
displayName: "FormFieldstyles__RightSide",
|
|
41
|
+
componentId: "sc-584zv-8"
|
|
42
|
+
})(["font-weight:500;flex:1 0 auto;text-align:end;color:", ";"], function (props) {
|
|
43
|
+
return props.theme.palette['grey-500'];
|
|
44
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { WithHTMLAttributes } from '@synerise/ds-utils';
|
|
3
|
+
import type { TooltipProps } from '@synerise/ds-tooltip';
|
|
4
|
+
export type ContentAboveProps = BaseLabelProps & {
|
|
5
|
+
rightSide?: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
type BaseLabelProps = {
|
|
8
|
+
label?: ReactNode;
|
|
9
|
+
tooltip?: ReactNode;
|
|
10
|
+
tooltipConfig?: TooltipProps;
|
|
11
|
+
id?: string;
|
|
12
|
+
};
|
|
13
|
+
export type FormFieldCommonProps = Omit<ContentAboveProps, 'id' | 'rightSide'> & ContentBelowProps;
|
|
14
|
+
export type FormFieldProps = WithHTMLAttributes<HTMLDivElement, {
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
} & ContentAboveProps & ContentBelowProps>;
|
|
17
|
+
export type ContentBelowProps = {
|
|
18
|
+
errorText?: ReactNode;
|
|
19
|
+
description?: ReactNode;
|
|
20
|
+
};
|
|
21
|
+
export type FormFieldLabelProps = WithHTMLAttributes<HTMLLabelElement, BaseLabelProps & {
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
}>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as S from '../FormField.styles';
|
|
3
|
+
import { FormFieldLabel } from './FormFieldLabel';
|
|
4
|
+
export var ContentAboveElement = function ContentAboveElement(_ref) {
|
|
5
|
+
var label = _ref.label,
|
|
6
|
+
id = _ref.id,
|
|
7
|
+
tooltip = _ref.tooltip,
|
|
8
|
+
tooltipConfig = _ref.tooltipConfig,
|
|
9
|
+
rightSide = _ref.rightSide;
|
|
10
|
+
return label || rightSide ? /*#__PURE__*/React.createElement(S.ContentAbove, null, /*#__PURE__*/React.createElement(FormFieldLabel, {
|
|
11
|
+
label: label,
|
|
12
|
+
id: id,
|
|
13
|
+
tooltip: tooltip,
|
|
14
|
+
tooltipConfig: tooltipConfig
|
|
15
|
+
}), /*#__PURE__*/React.createElement(S.RightSide, null, rightSide)) : /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
16
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as S from '../FormField.styles';
|
|
3
|
+
export var ContentBelowElement = function ContentBelowElement(_ref) {
|
|
4
|
+
var description = _ref.description,
|
|
5
|
+
errorText = _ref.errorText;
|
|
6
|
+
if (!errorText && !description) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
var hasErrorMessage = Boolean(errorText);
|
|
10
|
+
return /*#__PURE__*/React.createElement(S.ContentBelow, null, hasErrorMessage && /*#__PURE__*/React.createElement(S.ErrorText, null, errorText), description && /*#__PURE__*/React.createElement(S.Description, null, description));
|
|
11
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var _excluded = ["id", "label", "tooltip", "tooltipConfig", "children"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import Tooltip from '@synerise/ds-tooltip';
|
|
6
|
+
import Icon, { InfoFillS } from '@synerise/ds-icon';
|
|
7
|
+
import { Text } from '@synerise/ds-typography';
|
|
8
|
+
import * as S from '../FormField.styles';
|
|
9
|
+
export var FormFieldLabel = function FormFieldLabel(_ref) {
|
|
10
|
+
var id = _ref.id,
|
|
11
|
+
label = _ref.label,
|
|
12
|
+
tooltip = _ref.tooltip,
|
|
13
|
+
tooltipConfig = _ref.tooltipConfig,
|
|
14
|
+
children = _ref.children,
|
|
15
|
+
htmlAttributes = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, (label || children) && /*#__PURE__*/React.createElement(S.FormFieldLabelWrapper, _extends({
|
|
17
|
+
htmlFor: id
|
|
18
|
+
}, htmlAttributes), /*#__PURE__*/React.createElement(Text, {
|
|
19
|
+
ellipsis: {
|
|
20
|
+
tooltip: label || children
|
|
21
|
+
}
|
|
22
|
+
}, label || children), (tooltip || tooltipConfig) && /*#__PURE__*/React.createElement(Tooltip, _extends({
|
|
23
|
+
title: tooltip,
|
|
24
|
+
placement: "top",
|
|
25
|
+
trigger: "hover",
|
|
26
|
+
transitionName: "zoom-big-fast"
|
|
27
|
+
}, tooltipConfig), /*#__PURE__*/React.createElement(S.IconWrapper, {
|
|
28
|
+
"data-testid": "label-tooltip-trigger"
|
|
29
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
30
|
+
size: 24,
|
|
31
|
+
component: /*#__PURE__*/React.createElement(InfoFillS, null)
|
|
32
|
+
})))));
|
|
33
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@synerise/ds-form-field",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "FormField UI Component for the Synerise Design System",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"repository": "Synerise/synerise-design",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"/dist",
|
|
10
|
+
"CHANGELOG.md",
|
|
11
|
+
"README.md",
|
|
12
|
+
"package.json",
|
|
13
|
+
"LICENSE.md"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run build:js && npm run build:css && npm run defs",
|
|
20
|
+
"build:css": "node ../../../scripts/style/less.js",
|
|
21
|
+
"build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
|
|
22
|
+
"build:watch": "npm run build:js -- --watch",
|
|
23
|
+
"defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
|
|
24
|
+
"pack:ci": "npm pack --pack-destination ../../storybook/storybook-static/static",
|
|
25
|
+
"prepublish": "npm run build",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"test:watch": "npm run test -- --watchAll",
|
|
28
|
+
"types": "tsc --noEmit",
|
|
29
|
+
"upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
|
|
30
|
+
},
|
|
31
|
+
"sideEffects": [
|
|
32
|
+
"dist/style/*",
|
|
33
|
+
"*.less"
|
|
34
|
+
],
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@synerise/ds-icon": "^1.3.0",
|
|
38
|
+
"@synerise/ds-tooltip": "^1.1.3",
|
|
39
|
+
"@synerise/ds-typography": "^1.0.4",
|
|
40
|
+
"@synerise/ds-utils": "^1.0.1"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@synerise/ds-core": "*",
|
|
44
|
+
"react": ">=16.9.0 <= 18.3.1",
|
|
45
|
+
"styled-components": "^5.3.3"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "1682edec2e4b03e3960c3de671cd7d3f3a2e01e4"
|
|
48
|
+
}
|