@bytebrand/fe-ui-core 4.2.72 → 4.2.73

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/common.ts CHANGED
@@ -3,6 +3,7 @@ export { default as Accordion } from './source/components/_common/Accordion/Acco
3
3
  export { default as Button } from './source/components/_common/Button/Button';
4
4
  export { default as ButtonOld } from './source/components/_common/ButtonOld/Button';
5
5
  export { default as PSGroup } from './source/components/_common/PropertySelector/PSGroup';
6
+ export { default as FormPSGroup } from './source/components/_common/PropertySelector/FormPSGroup';
6
7
  export { default as PropertySelector } from './source/components/_common/PropertySelector/PropertySelector';
7
8
 
8
9
  export { default as FormRadioGroup } from './source/components/_common/Radio/FormRadioGroup';
@@ -29,7 +30,6 @@ export { default as VehicleSliderForSRL } from './source/components/_common/Vehi
29
30
  export { default as VehicleSmallCard } from './source/components/VehicleSmallCard/VehicleSmallCard';
30
31
  export { default as OfferPanel } from './source/components/OfferPanel/OfferPanel';
31
32
 
32
- export { default as FormTextField } from './source/components/_common/TextField/FormTextField';
33
33
  export { default as Tooltip } from './source/components/_common/Tooltip/Tooltip';
34
34
  export { default as TextField } from './source/components/_common/TextField/TextField';
35
35
  export { default as FormattedNumber } from './source/components/FormattedNumber/FormattedNumber';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/fe-ui-core",
3
- "version": "4.2.72",
3
+ "version": "4.2.73",
4
4
  "description": "UI components for the auto.de project",
5
5
  "main": "index.ts",
6
6
  "module": "dist/common.js",
@@ -1,5 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import classnames from 'classnames';
3
+ import { observer } from 'mobx-react';
4
+
3
5
  import Checkbox from './Checkbox';
4
6
  import styles from './FormCheckbox.styl';
5
7
 
@@ -7,6 +9,8 @@ interface IFormCheckboxProps {
7
9
  className?: string;
8
10
  errorClassName?: string;
9
11
  label?: JSX.Element | string | null;
12
+
13
+ // mobx form field instance
10
14
  field: any;
11
15
  checkboxClassName?: string;
12
16
  labelClassName?: string;
@@ -14,70 +18,34 @@ interface IFormCheckboxProps {
14
18
  helperText?: string;
15
19
  }
16
20
 
17
- interface IFormCheckboxState {
18
- field: {
19
- name?: string;
20
- value?: boolean;
21
- checked?: boolean;
22
- error?: boolean;
23
- disabled?: boolean
24
- }
25
- }
26
-
27
- class FormCheckbox extends React.Component<IFormCheckboxProps, IFormCheckboxState> {
28
- constructor(props: IFormCheckboxProps) {
29
- super(props);
30
-
31
- this.state = {
32
- field: {
33
- value: this.props.field.value,
34
- error: this.props.field.error,
35
- checked: this.props.field.checked,
36
- disabled: this.props.field.disabled,
37
- name: this.props.field.name
38
- }
39
- };
40
- }
21
+ @observer
22
+ class FormCheckbox extends React.Component<IFormCheckboxProps> {
41
23
  static defaultProps = {
42
24
  className: '',
43
25
  label: false
44
26
  };
45
27
 
46
- handleChange = (event: React.ChangeEvent<HTMLInputElement>, checked?: boolean, value?: any) => {
47
- const { name, disabled, onChange, rules } = this.props.field;
48
- const customError = (rules.includes('accepted') && !checked);
49
- this.setState(() => ({
50
- field: {
51
- value,
52
- name,
53
- disabled,
54
- checked,
55
- error: customError
56
- }
57
- }));
58
- onChange(event, checked, value);
59
- }
60
-
61
28
  render() {
62
- const { label, className, checkboxClassName, labelClassName } = this.props;
63
- const { name, value, checked, disabled, error } = this.state.field;
64
- const customError = error || (this.props.field.error && !checked);
29
+ const { field, label, className, checkboxClassName, labelClassName, customError } = this.props;
30
+
31
+ // const customHasError = customError;
32
+ // const hasError = field.hasError;
33
+ const error = customError ? customError : field.error;
65
34
 
66
35
  const _props = {
67
- value,
68
- checked,
69
- name,
70
- disabled,
71
- onChange: this.handleChange,
72
- error: customError,
73
- label,
36
+ ...field.bind(),
37
+ error, label,
74
38
  checkboxClassName,
75
39
  labelClassName
76
40
  };
77
41
 
42
+ // const errorClassNames = classnames(styles.errorText, errorClassName);
43
+
78
44
  return (
79
45
  <div className={classnames(styles.field, className)}>
80
46
  <Checkbox {..._props} />
47
+ {/* {hasError && error ? (<span className={errorClassNames}>{error}</span>) : false} */}
48
+ {/* {customHasError ? (<span className={errorClassNames}>{helperText}</span>) : false} */}
81
49
  </div>
82
50
  );
83
51
  }
@@ -4,6 +4,7 @@ import { action } from '@storybook/addon-actions';
4
4
 
5
5
  import { ROW_STYLES } from '../../../framework/constants';
6
6
  import CheckboxMaterial from './CheckboxMaterial';
7
+ import FormCheckboxMaterial from './FormCheckboxMaterial';
7
8
 
8
9
  import styles from './CheckboxMaterial.story.styl';
9
10
 
@@ -123,4 +124,13 @@ const CheckboxWrap = () => {
123
124
 
124
125
  storiesOf('_Common_UI', module)
125
126
  .add('CheckboxMaterial', () => <CheckboxWrap />)
126
-
127
+ .add('FormCheckboxMaterial', () => (
128
+ <div>
129
+ <div style={ROW_STYLES}>
130
+ <FormCheckboxMaterial {...basePropsForm} />
131
+ </div>
132
+ <div style={ROW_STYLES}>
133
+ <FormCheckboxMaterial {...withErrorForm} />
134
+ </div>
135
+ </div>
136
+ ));
@@ -1,8 +1,13 @@
1
+ @import '../../../theme/theme.styl'
2
+
1
3
  .field
2
4
  position: relative
5
+ flex: 1 0 100%
3
6
 
4
7
  .errorText
5
8
  position: absolute
9
+ left: 0
10
+ bottom: -15px
6
11
  display: block
7
12
  width: 100%
8
13
  z-index: 1
@@ -10,26 +15,8 @@
10
15
  font-weight: 400;
11
16
  font-style: normal
12
17
  font-size: 10px
13
- color: rgb(204, 51, 51)
18
+ line-height: 15px
19
+ color: $darkRed
14
20
  overflow: hidden
15
21
  text-overflow: ellipsis
16
22
  white-space: nowrap
17
- box-sizing border-box
18
- padding: 0 2px
19
-
20
- .errorBottomLeft,
21
- .errorTopLeft
22
- text-align: left
23
-
24
- .errorBottomRight,
25
- .errorTopRight
26
- text-align: right
27
-
28
- .errorBottomLeft,
29
- .errorBottomRight
30
- bottom: -15px
31
-
32
- .errorTopLeft,
33
- .errorTopRight
34
- top: -15px
35
-
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import classnames from 'classnames';
3
+ import { observer } from 'mobx-react';
4
+
5
+ import CheckboxMaterial from './CheckboxMaterial';
6
+ import styles from './FormCheckboxMaterial.styl';
7
+
8
+ interface IFormCheckboxProps {
9
+ className?: string;
10
+ errorClassName?: string;
11
+ label?: JSX.Element | string | null;
12
+
13
+ // mobx form field instance
14
+ field: any;
15
+ checkboxClassName?: string;
16
+ labelClassName?: string;
17
+ }
18
+
19
+ @observer
20
+ class FormCheckboxMaterial extends React.Component<IFormCheckboxProps> {
21
+ static defaultProps = {
22
+ className: '',
23
+ label: false
24
+ };
25
+
26
+ render() {
27
+ const { field, label, className, checkboxClassName, labelClassName, errorClassName } = this.props;
28
+
29
+ const hasError = field.hasError;
30
+ const error = field.error;
31
+
32
+ const _props = {
33
+ ...field.bind(),
34
+ error, label,
35
+ checkboxClassName,
36
+ labelClassName
37
+ };
38
+
39
+ const errorClassNames = classnames(styles.errorText, errorClassName);
40
+
41
+ return (
42
+ <div className={classnames(styles.field, className)}>
43
+ <CheckboxMaterial {..._props} />
44
+ {hasError && error ? (<span className={errorClassNames}>{error}</span>) : false}
45
+ </div>
46
+ );
47
+ }
48
+ }
49
+
50
+ export default FormCheckboxMaterial;
@@ -4,7 +4,8 @@ import classnames from 'classnames';
4
4
  import styles from './FormDropDown.styl';
5
5
 
6
6
  import DropDown from './DropDown';
7
- import { ErrorPositionType } from '../TextField/FormTextField';
7
+
8
+ type ErrorPositionType = 'TopRight' | 'TopLeft' | 'BottomRight' | 'BottomLeft';
8
9
 
9
10
  interface IFormDropDownProps {
10
11
  // mobx form field instance
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { storiesOf } from '@storybook/react';
3
+ import { action } from '@storybook/addon-actions';
4
+
5
+ import PropertySelector from './PropertySelector';
6
+ import FormPSGroup from './FormPSGroup';
7
+ import styles from './FormPSGroup.story.styl';
8
+
9
+ const mockField = {
10
+ name: 'availability',
11
+ value: ['always'],
12
+ error: 'Something went wrong',
13
+ hasError: true,
14
+ onChange: action('FormRadioGroup change'),
15
+ bind: () => {
16
+ const { bind, ...rest } = mockField;
17
+ return rest;
18
+ }
19
+ };
20
+
21
+ storiesOf('_Common_UI', module)
22
+ .add('FormPSGroup', () => (
23
+ <div>
24
+ <FormPSGroup field={mockField} childClassName={styles.child}>
25
+ <PropertySelector label='Available always' value='always'/>
26
+ <PropertySelector label='Available from' value='fromDate'/>
27
+ <PropertySelector label='Unknown' value='unknown' disabled={true} />
28
+ </FormPSGroup>
29
+
30
+ <FormPSGroup field={mockField} containerClassName={styles.vertical}>
31
+ <PropertySelector label='Available always' value='always'/>
32
+ <PropertySelector label='Available from' value='fromDate'/>
33
+ <PropertySelector label='Unknown' value='unknown' disabled={true} />
34
+ </FormPSGroup>
35
+ </div>
36
+ ));
@@ -0,0 +1,5 @@
1
+ .vertical
2
+ display: flex
3
+ flex-direction: row
4
+ align-items: center
5
+
@@ -0,0 +1,22 @@
1
+ @import '../../../theme/theme.styl'
2
+
3
+ .field
4
+ position: relative
5
+ display: inline-block
6
+
7
+ .errorText
8
+ position: absolute
9
+ left: 0
10
+ bottom: -15px
11
+ display: block
12
+ width: 100%
13
+ z-index: 1
14
+ font-family: $font-style-arial
15
+ font-weight: $font-weight-default
16
+ font-style: normal
17
+ font-size: 10px
18
+ line-height: 15px
19
+ color: $darkRed
20
+ overflow: hidden
21
+ text-overflow: ellipsis
22
+ white-space: nowrap
@@ -0,0 +1,54 @@
1
+ import * as React from 'react';
2
+ import classnames from 'classnames';
3
+ import { observer } from 'mobx-react';
4
+
5
+ import PSGroup from './PSGroup';
6
+ import styles from './FormPSGroup.styl';
7
+
8
+ interface IFormRadioGroupProps {
9
+ children: any;
10
+ className?: string;
11
+ behavior?: string;
12
+
13
+ // mobx form field instance
14
+ field: any;
15
+
16
+ containerClassName?: string;
17
+ childClassName?: string;
18
+ }
19
+
20
+ @observer
21
+ class FormPSGroup extends React.Component<IFormRadioGroupProps> {
22
+ static defaultProps = {
23
+ className: '',
24
+ label: false,
25
+ containerClassName: '',
26
+ childClassName: ''
27
+ };
28
+
29
+ render() {
30
+ const { field, className, behavior, containerClassName, childClassName } = this.props;
31
+
32
+ const hasError = field.hasError;
33
+ const error = field.error;
34
+
35
+ const _props = {
36
+ ...field.bind(),
37
+ behavior,
38
+ containerClassName,
39
+ childClassName,
40
+ error: hasError
41
+ };
42
+
43
+ return (
44
+ <div className={classnames(styles.field, className)}>
45
+ <PSGroup {..._props} >
46
+ {this.props.children}
47
+ </PSGroup>
48
+ {hasError && error ? (<span className={styles.errorText}>{error}</span>) : false}
49
+ </div>
50
+ );
51
+ }
52
+ }
53
+
54
+ export default FormPSGroup;
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import classnames from 'classnames';
3
- import { observer } from 'mobx-react';
4
3
 
5
4
  import RadioGroup from './RadioGroup';
6
5
  import styles from './FormRadioGroup.styl';
@@ -8,16 +7,19 @@ import styles from './FormRadioGroup.styl';
8
7
  interface IFormRadioGroupProps {
9
8
  children: any;
10
9
  className?: string;
11
-
12
- // mobx form field instance
13
10
  field: any;
14
-
15
11
  containerClassName?: string;
16
12
  childClassName?: string;
17
13
  }
18
14
 
19
- @observer
20
- class FormRadioGroup extends React.Component<IFormRadioGroupProps> {
15
+ interface IFormRadioGroupState {
16
+ field: {
17
+ name?: string;
18
+ value?: string;
19
+ };
20
+ }
21
+
22
+ class FormRadioGroup extends React.Component<IFormRadioGroupProps, IFormRadioGroupState> {
21
23
  static defaultProps = {
22
24
  className: '',
23
25
  label: false,
@@ -25,16 +27,39 @@ class FormRadioGroup extends React.Component<IFormRadioGroupProps> {
25
27
  childClassName: ''
26
28
  };
27
29
 
28
- render() {
29
- const { field, className, containerClassName, childClassName } = this.props;
30
+ constructor(props: IFormRadioGroupProps) {
31
+ super(props);
32
+ this.state = {
33
+ field: {
34
+ name: '',
35
+ value: ''
36
+ }
37
+ };
38
+ }
30
39
 
40
+ handleRadioChange = (event: React.ChangeEvent<HTMLInputElement>, value?: any) => {
41
+ const { name, onChange } = this.props.field;
42
+ this.setState(() => ({
43
+ field: {
44
+ name,
45
+ value
46
+ }
47
+ }));
48
+ onChange(event, value);
49
+ };
50
+
51
+ render() {
52
+ const { className, containerClassName, childClassName, field } = this.props;
53
+ const { name, value } = this.state.field;
31
54
  const hasError = field.hasError;
32
55
  const error = field.error;
33
56
 
34
57
  const _props = {
35
- ...field.bind(),
58
+ name,
59
+ value,
36
60
  containerClassName,
37
61
  childClassName,
62
+ onChange: this.handleRadioChange,
38
63
  error: hasError
39
64
  };
40
65
 
@@ -1,21 +0,0 @@
1
- import React from 'react';
2
-
3
- import { storiesOf } from '@storybook/react';
4
- import FormTextField from './FormTextField';
5
-
6
-
7
- const field = {
8
- error: 'Something went wrong',
9
- hasError: true,
10
- bind: () => {
11
- const { bind, ...rest } = field;
12
- return rest;
13
- }
14
- };
15
-
16
- storiesOf('_Common_UI', module)
17
- .add('FormTextField', () => (
18
- <div>
19
- <FormTextField errorPosition='BottomRight' field={field}/>
20
- </div>
21
- ));
@@ -1,54 +0,0 @@
1
- import * as React from 'react';
2
- import classnames from 'classnames';
3
- import { observer } from 'mobx-react';
4
-
5
- import styles from './FormTextField.styl';
6
- import TextField from './TextField';
7
-
8
- export type ErrorPositionType = 'TopRight' | 'TopLeft' | 'BottomRight' | 'BottomLeft';
9
-
10
- interface IFormTextFieldProps {
11
- errorPosition?: ErrorPositionType;
12
- className?: string;
13
- // TODO: change this when mobx-react-form supports typescript
14
- field: any;
15
- type?: string;
16
-
17
- min?: number;
18
- step?: number;
19
- max?: number;
20
-
21
- onKeyPress?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
22
- }
23
-
24
- @observer
25
- class FormTextField extends React.Component<IFormTextFieldProps, {}> {
26
- static defaultProps = {
27
- className: '',
28
- errorPosition: 'BottomLeft',
29
- t: () => ''
30
- };
31
-
32
- render() {
33
- const { className, errorPosition, field, type, min, step, max, onKeyPress } = this.props;
34
- const errorClassName = classnames(styles.errorText, styles[`error${errorPosition}`]);
35
-
36
- const hasError = field.hasError;
37
- const error = field.error;
38
-
39
- const props = {
40
- ...field.bind(),
41
- min, step, max,
42
- onKeyPress
43
- };
44
-
45
- return (
46
- <div className={classnames(styles.field, className)}>
47
- <TextField error={hasError && error} {...props} type={type || field.type} />
48
- {hasError && error ? (<span className={errorClassName}>{error}</span>) : false}
49
- </div>
50
- );
51
- }
52
- }
53
-
54
- export default FormTextField;