Skip to content

Commit 3d5dfc7

Browse files
committed
fixup! transform RUI to typescript (#394)
1 parent 0ca5d0d commit 3d5dfc7

File tree

132 files changed

+2344
-2334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2344
-2334
lines changed

.eslintrc

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
{
22
"extends": [
33
"@visionappscz/eslint-config-visionapps",
4-
"airbnb-typescript",
5-
"plugin:@typescript-eslint/recommended",
6-
"plugin:@typescript-eslint/recommended-requiring-type-checking",
7-
"plugin:deprecation/recommended",
8-
"plugin:typescript-sort-keys/recommended",
4+
"plugin:deprecation/recommended"
5+
],
6+
"overrides": [
7+
{
8+
"files": [
9+
"**/*.ts",
10+
"**/*.tsx"
11+
],
12+
"extends": [
13+
"@visionappscz/eslint-config-visionapps",
14+
"airbnb-typescript",
15+
"plugin:@typescript-eslint/recommended",
16+
"plugin:typescript-sort-keys/recommended"
17+
],
18+
"parser": "@typescript-eslint/parser",
19+
"parserOptions": {
20+
"project": "tsconfig.json"
21+
},
22+
"plugins": ["@typescript-eslint"],
23+
"rules": {
24+
"@typescript-eslint/no-unused-vars": ["error"],
25+
"@typescript-eslint/object-curly-spacing": ["error"],
26+
"import/prefer-default-export": ["off"],
27+
"no-console": ["error"],
28+
"react/default-props-match-prop-types": ["off"],
29+
"react/require-default-props": ["off"]
30+
}
31+
}
932
],
1033
"env": {
1134
"browser": true,

declaration.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
declare module '*.css';
2-
declare module '*.scss';
2+
declare module '*.scss';

src/components/Alert/Alert.tsx

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import PropTypes from 'prop-types';
21
import React, { useContext } from 'react';
32
import { withGlobalProps } from '../../providers/globalProps';
43
import { TranslationsContext } from '../../providers/translations';
54
import { classNames } from '../../utils/classNames';
65
import { transferProps } from '../../utils/transferProps';
76
import { getRootColorClassName } from '../_helpers/getRootColorClassName';
87
import styles from './Alert.module.scss';
8+
import { AlertProps } from './Alert.types';
99

10-
export const Alert = ({
10+
export const Alert: React.FunctionComponent<AlertProps> = ({
1111
children,
12-
color,
13-
icon,
12+
color = 'note',
13+
icon = null,
1414
id,
15-
onClose,
15+
onClose = null,
1616
...restProps
1717
}) => {
1818
const translations = useContext(TranslationsContext);
@@ -45,7 +45,7 @@ export const Alert = ({
4545
className={styles.close}
4646
onClick={() => onClose()}
4747
onKeyPress={() => onClose()}
48-
tabIndex="0"
48+
tabIndex={0}
4949
title={translations.Alert.close}
5050
>
5151
<span className={styles.closeSign}>×</span>
@@ -55,42 +55,6 @@ export const Alert = ({
5555
);
5656
};
5757

58-
Alert.defaultProps = {
59-
color: 'note',
60-
icon: null,
61-
id: undefined,
62-
onClose: null,
63-
};
64-
65-
Alert.propTypes = {
66-
/**
67-
* Alert body.
68-
*/
69-
children: PropTypes.node.isRequired,
70-
/**
71-
* Color variant to clarify importance and meaning of the alert. Implements
72-
* [Feedback and Neutral color collections](/docs/foundation/collections#colors).
73-
*/
74-
color: PropTypes.oneOf(['success', 'warning', 'danger', 'help', 'info', 'note', 'light', 'dark']),
75-
/**
76-
* Optional element to be displayed next to the alert body.
77-
*/
78-
icon: PropTypes.node,
79-
/**
80-
* ID of the root HTML element.
81-
*
82-
* Also serves as base for ids of nested elements:
83-
* * `<ID>__close`
84-
* * `<ID>__content`
85-
*/
86-
id: PropTypes.string,
87-
/**
88-
* Function to call when the close button is clicked. If not provided, close buttons will be
89-
* hidden.
90-
*/
91-
onClose: PropTypes.func,
92-
};
93-
9458
export const AlertWithGlobalProps = withGlobalProps(Alert, 'Alert');
9559

9660
export default AlertWithGlobalProps;

src/components/Alert/Alert.types.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ReactNode } from 'react';
2+
import {
3+
FeedbackColor,
4+
NeutralColor,
5+
} from '../../types';
6+
7+
export type AlertProps = React.ComponentProps<'div'> & {
8+
/**
9+
* Alert body.
10+
*/
11+
children: ReactNode;
12+
/**
13+
* Color variant to clarify importance and meaning of the alert. Implements
14+
* [Feedback and Neutral color collections](/docs/foundation/collections#colors).
15+
*/
16+
color?: FeedbackColor | NeutralColor;
17+
/**
18+
* Optional element to be displayed next to the alert body.
19+
*/
20+
icon?: ReactNode;
21+
/**
22+
* ID of the root HTML element.
23+
*
24+
* Also serves as base for ids of nested elements:
25+
* * `<ID>__close`
26+
* * `<ID>__content`
27+
*/
28+
id?: string;
29+
/**
30+
* Function to call when the close button is clicked. If not provided, close buttons will be
31+
* hidden.
32+
*/
33+
onClose?: () => void;
34+
};

src/components/Badge/Badge.tsx

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import PropTypes from 'prop-types';
21
import React from 'react';
32
import { withGlobalProps } from '../../providers/globalProps';
43
import { classNames } from '../../utils/classNames';
54
import { transferProps } from '../../utils/transferProps';
65
import { getRootColorClassName } from '../_helpers/getRootColorClassName';
76
import { getRootPriorityClassName } from '../_helpers/getRootPriorityClassName';
7+
import { BadgeProps } from './Badge.types';
88
import styles from './Badge.module.scss';
99

10-
export const Badge = ({
11-
color,
10+
export const Badge: React.FunctionComponent<BadgeProps> = ({
11+
color = 'note',
1212
label,
13-
priority,
13+
priority = 'filled',
1414
...restProps
1515
}) => (
1616
<div
@@ -25,27 +25,6 @@ export const Badge = ({
2525
</div>
2626
);
2727

28-
Badge.defaultProps = {
29-
color: 'note',
30-
priority: 'filled',
31-
};
32-
33-
Badge.propTypes = {
34-
/**
35-
* Color to clarify importance and meaning of the badge. Implements
36-
* [Feedback and Neutral color collections](/docs/foundation/collections#colors).
37-
*/
38-
color: PropTypes.oneOf(['success', 'warning', 'danger', 'help', 'info', 'note', 'light', 'dark']),
39-
/**
40-
* Text to be displayed.
41-
*/
42-
label: PropTypes.string.isRequired,
43-
/**
44-
* Visual priority to highlight or suppress the badge.
45-
*/
46-
priority: PropTypes.oneOf(['filled', 'outline']),
47-
};
48-
4928
export const BadgeWithGlobalProps = withGlobalProps(Badge, 'Badge');
5029

5130
export default BadgeWithGlobalProps;

src/components/Badge/Badge.types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {
2+
FeedbackColor,
3+
NeutralColor,
4+
Priority,
5+
} from '../../types';
6+
7+
export type BadgeProps = React.ComponentProps<'div'> & {
8+
/**
9+
* Color to clarify importance and meaning of the badge. Implements
10+
* [Feedback and Neutral color collections](/docs/foundation/collections#colors).
11+
*/
12+
color?: FeedbackColor | NeutralColor;
13+
/**
14+
* Text to be displayed.
15+
*/
16+
label: string;
17+
/**
18+
* Visual priority to highlight or suppress the badge.
19+
*/
20+
priority?: Exclude<Priority, 'flat'>;
21+
};

src/components/Button/Button.tsx

Lines changed: 13 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import PropTypes from 'prop-types';
21
import React, { useContext } from 'react';
32
import { withGlobalProps } from '../../providers/globalProps';
43
import { classNames } from '../../utils/classNames';
@@ -10,23 +9,24 @@ import { resolveContextOrProp } from '../_helpers/resolveContextOrProp';
109
import { ButtonGroupContext } from '../ButtonGroup';
1110
import { InputGroupContext } from '../InputGroup/InputGroupContext';
1211
import getRootLabelVisibilityClassName from './helpers/getRootLabelVisibilityClassName';
12+
import { ButtonProps } from './Button.types';
1313
import styles from './Button.module.scss';
1414

15-
export const Button = React.forwardRef((props, ref) => {
15+
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => {
1616
const {
17-
afterLabel,
18-
beforeLabel,
19-
block,
20-
disabled,
21-
endCorner,
22-
feedbackIcon,
17+
afterLabel = null,
18+
beforeLabel = null,
19+
block = false,
20+
disabled = false,
21+
endCorner = null,
22+
feedbackIcon = null,
2323
id,
2424
label,
25-
labelVisibility,
26-
priority,
27-
size,
28-
startCorner,
29-
color,
25+
labelVisibility = 'xs',
26+
priority = 'filled',
27+
size = 'medium',
28+
startCorner = null,
29+
color = 'primary',
3030
...restProps
3131
} = props;
3232
const buttonGroupContext = useContext(ButtonGroupContext);
@@ -100,100 +100,6 @@ export const Button = React.forwardRef((props, ref) => {
100100
);
101101
});
102102

103-
Button.defaultProps = {
104-
afterLabel: null,
105-
beforeLabel: null,
106-
block: false,
107-
color: 'primary',
108-
disabled: false,
109-
endCorner: null,
110-
feedbackIcon: null,
111-
id: undefined,
112-
labelVisibility: 'xs',
113-
priority: 'filled',
114-
size: 'medium',
115-
startCorner: null,
116-
type: 'button',
117-
};
118-
119-
Button.propTypes = {
120-
/**
121-
* Element to be displayed after label, eg. an icon.
122-
*/
123-
afterLabel: PropTypes.node,
124-
/**
125-
* Element to be displayed before label, eg. an icon.
126-
*/
127-
beforeLabel: PropTypes.node,
128-
/**
129-
* If `true`, the button will span the full width of its parent.
130-
*
131-
* Ignored if the component is rendered within `ButtonGroup` component
132-
* as the value is inherited in such case.
133-
*/
134-
block: PropTypes.bool,
135-
/**
136-
* Color variant to clarify importance and meaning of the alert. Implements
137-
* [Action, Feedback and Neutral color collections](/docs/foundation/collections#colors).
138-
*/
139-
color: PropTypes.oneOf(
140-
['primary', 'secondary', 'selected', 'success', 'warning', 'danger', 'help', 'info', 'note', 'light', 'dark'],
141-
),
142-
/**
143-
* If `true`, the button will be disabled.
144-
*
145-
* Ignored if the component is rendered within `ButtonGroup` component
146-
* as the value is inherited in such case.
147-
*/
148-
disabled: PropTypes.bool,
149-
/**
150-
* Element to be displayed in the top right corner.
151-
*/
152-
endCorner: PropTypes.node,
153-
/**
154-
* Element to be displayed as a feedback icon on top of button label. When defined, it implies the
155-
* button is in feedback state.
156-
*/
157-
feedbackIcon: PropTypes.node,
158-
/**
159-
* ID of the root HTML element.
160-
*
161-
* Also serves as base for ids of nested elements:
162-
* * `<ID>__labelText`
163-
*/
164-
id: PropTypes.string,
165-
/**
166-
* Button label.
167-
*/
168-
label: PropTypes.string.isRequired,
169-
/**
170-
* Defines minimum breakpoint from which the button label will be visible.
171-
*/
172-
labelVisibility: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', 'x2l', 'x3l', 'none']),
173-
/**
174-
* Visual priority to highlight or suppress the button.
175-
*
176-
* Ignored if the component is rendered within `ButtonGroup` component
177-
* as the value is inherited in such case.
178-
*/
179-
priority: PropTypes.oneOf(['filled', 'outline', 'flat']),
180-
/**
181-
* Size of the button.
182-
*
183-
* Ignored if the component is rendered within `ButtonGroup` or `InputGroup` component as the value is inherited in
184-
* such case.
185-
*/
186-
size: PropTypes.oneOf(['small', 'medium', 'large']),
187-
/**
188-
* Element to be displayed in the top left corner.
189-
*/
190-
startCorner: PropTypes.node,
191-
/**
192-
* Set the HTML `type` attribute of the `button` element.
193-
*/
194-
type: PropTypes.oneOf(['button', 'submit']),
195-
};
196-
197103
export const ButtonWithGlobalProps = withGlobalProps(Button, 'Button');
198104

199105
export default ButtonWithGlobalProps;

0 commit comments

Comments
 (0)