@atlaskit/textfield 5.0.5 → 5.1.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/CHANGELOG.md +35 -0
- package/codemods/{5.0.0-lite-mode.ts → 5.0.0-lite-mode.tsx} +1 -1
- package/codemods/__tests__/{5.0.0-lite-mode.ts → 5.0.0-lite-mode.tsx} +0 -0
- package/codemods/__tests__/remove-imports.tsx +1 -1
- package/codemods/__tests__/remove-prop.tsx +1 -1
- package/codemods/__tests__/rename-imports.tsx +1 -1
- package/codemods/migrations/{remove-imports.ts → remove-imports.tsx} +1 -1
- package/codemods/migrations/{remove-props.ts → remove-props.tsx} +1 -1
- package/codemods/migrations/{rename-imports.ts → rename-imports.tsx} +1 -1
- package/codemods/{utils.ts → migrations/utils.tsx} +0 -0
- package/dist/cjs/component-tokens.js +27 -29
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/styles.js +22 -30
- package/dist/cjs/text-field.js +48 -45
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/component-tokens.js +25 -28
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/styles.js +18 -28
- package/dist/es2019/text-field.js +47 -44
- package/dist/es2019/version.json +1 -1
- package/dist/esm/component-tokens.js +25 -28
- package/dist/esm/index.js +1 -1
- package/dist/esm/styles.js +18 -28
- package/dist/esm/text-field.js +48 -46
- package/dist/esm/version.json +1 -1
- package/dist/types/component-tokens.d.ts +22 -22
- package/dist/types/index.d.ts +2 -2
- package/dist/types/styles.d.ts +135 -46
- package/dist/types/text-field.d.ts +11 -2
- package/dist/types/types.d.ts +1 -6
- package/package.json +17 -21
- package/extract-react-types/text-field-props.tsx +0 -5
package/dist/es2019/styles.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
1
2
|
import { codeFontFamily, fontFamily, fontSize as getFontSize, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
3
|
+
import { token } from '@atlaskit/tokens';
|
|
2
4
|
import * as componentTokens from './component-tokens';
|
|
3
5
|
const fontSize = getFontSize();
|
|
4
6
|
const gridSize = getGridSize();
|
|
5
7
|
const disabledRules = {
|
|
6
8
|
light: {
|
|
7
|
-
backgroundColor: componentTokens.
|
|
8
|
-
backgroundColorFocus: componentTokens.disabledBackgroundColor.light,
|
|
9
|
+
backgroundColor: componentTokens.disabledBackgroundColor.light,
|
|
9
10
|
backgroundColorHover: componentTokens.disabledBackgroundColor.light,
|
|
10
|
-
|
|
11
|
-
borderColor: componentTokens.defaultBackgroundColor.light,
|
|
12
|
-
borderColorFocus: componentTokens.defaultBorderColorFocus.light,
|
|
11
|
+
borderColor: componentTokens.disabledBackgroundColor.light,
|
|
13
12
|
textColor: componentTokens.disabledTextColor.light
|
|
14
13
|
},
|
|
15
14
|
dark: {
|
|
16
|
-
backgroundColor: componentTokens.
|
|
17
|
-
backgroundColorFocus: componentTokens.disabledBackgroundColor.dark,
|
|
15
|
+
backgroundColor: componentTokens.disabledBackgroundColor.dark,
|
|
18
16
|
backgroundColorHover: componentTokens.disabledBackgroundColor.dark,
|
|
19
|
-
|
|
20
|
-
borderColor: componentTokens.defaultBackgroundColor.dark,
|
|
21
|
-
borderColorFocus: componentTokens.defaultBorderColorFocus.dark,
|
|
17
|
+
borderColor: componentTokens.disabledBackgroundColor.dark,
|
|
22
18
|
textColor: componentTokens.disabledTextColor.dark
|
|
23
19
|
}
|
|
24
20
|
};
|
|
25
21
|
const invalidRules = {
|
|
26
22
|
light: {
|
|
23
|
+
// ----
|
|
27
24
|
backgroundColor: componentTokens.defaultBackgroundColor.light,
|
|
28
|
-
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.light,
|
|
29
25
|
backgroundColorHover: componentTokens.defaultBackgroundColorHover.light,
|
|
30
|
-
|
|
26
|
+
// ^--- the above values aren't used directly they remain because its exposed by the `textFieldColors` export
|
|
27
|
+
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.light,
|
|
28
|
+
borderColor: token('color.iconBorder.danger', R400),
|
|
31
29
|
borderColorFocus: componentTokens.defaultBorderColorFocus.light
|
|
32
30
|
},
|
|
33
31
|
dark: {
|
|
32
|
+
// ----
|
|
34
33
|
backgroundColor: componentTokens.defaultBackgroundColor.dark,
|
|
35
|
-
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.dark,
|
|
36
34
|
backgroundColorHover: componentTokens.defaultBackgroundColorHover.dark,
|
|
37
|
-
|
|
35
|
+
// ^--- the above values aren't used directly they remain because its exposed by the `textFieldColors` export
|
|
36
|
+
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.dark,
|
|
37
|
+
borderColor: token('color.iconBorder.danger', R400),
|
|
38
38
|
borderColorFocus: componentTokens.defaultBorderColorFocus.dark
|
|
39
39
|
}
|
|
40
40
|
};
|
|
@@ -50,7 +50,7 @@ const backgroundColorFocus = {
|
|
|
50
50
|
};
|
|
51
51
|
const backgroundColorHover = {
|
|
52
52
|
standard: componentTokens.defaultBackgroundColorHover,
|
|
53
|
-
subtle: componentTokens.
|
|
53
|
+
subtle: componentTokens.subtleBackgroundColorHover,
|
|
54
54
|
none: componentTokens.transparent
|
|
55
55
|
};
|
|
56
56
|
const borderColor = {
|
|
@@ -82,24 +82,13 @@ const getContainerTextBgAndBorderColor = (appearance, mode) => ({
|
|
|
82
82
|
color: disabledRules[mode].textColor,
|
|
83
83
|
cursor: 'not-allowed'
|
|
84
84
|
},
|
|
85
|
-
'&[data-disabled]:focus-within': {
|
|
86
|
-
backgroundColor: disabledRules[mode].backgroundColorFocus,
|
|
87
|
-
borderColor: disabledRules[mode].borderColorFocus
|
|
88
|
-
},
|
|
89
|
-
'&[data-disabled]:hover': {
|
|
90
|
-
backgroundColor: disabledRules[mode].backgroundColorHover
|
|
91
|
-
},
|
|
92
85
|
'&[data-invalid]': {
|
|
93
|
-
backgroundColor: invalidRules[mode].backgroundColor,
|
|
94
86
|
borderColor: invalidRules[mode].borderColor
|
|
95
87
|
},
|
|
96
88
|
'&[data-invalid]:focus-within': {
|
|
97
89
|
backgroundColor: invalidRules[mode].backgroundColorFocus,
|
|
98
90
|
borderColor: invalidRules[mode].borderColorFocus
|
|
99
91
|
},
|
|
100
|
-
'&[data-invalid]:hover': {
|
|
101
|
-
backgroundColor: invalidRules[mode].backgroundColorHover
|
|
102
|
-
},
|
|
103
92
|
'@media screen and (-ms-high-contrast: active)': {
|
|
104
93
|
'&[data-invalid]:focus-within': {
|
|
105
94
|
borderColor: 'Highlight'
|
|
@@ -188,8 +177,9 @@ export const inputStyles = mode => ({
|
|
|
188
177
|
color: 'GrayText'
|
|
189
178
|
}
|
|
190
179
|
}
|
|
191
|
-
});
|
|
192
|
-
|
|
180
|
+
}); // TODO: Remove when removing legacy theming.
|
|
181
|
+
|
|
182
|
+
export const textFieldColors = {
|
|
193
183
|
backgroundColor,
|
|
194
184
|
backgroundColorFocus,
|
|
195
185
|
backgroundColorHover,
|
|
@@ -4,15 +4,14 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
4
4
|
import React, { forwardRef, memo, useCallback, useMemo, useRef } from 'react';
|
|
5
5
|
import { jsx } from '@emotion/core';
|
|
6
6
|
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
7
|
-
import
|
|
7
|
+
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
8
8
|
import { containerStyles as getContainerStyles, inputStyles as getInputStyles } from './styles';
|
|
9
9
|
const analyticsParams = {
|
|
10
10
|
componentName: 'textField',
|
|
11
11
|
packageName: "@atlaskit/textfield",
|
|
12
|
-
packageVersion: "5.
|
|
12
|
+
packageVersion: "5.1.3"
|
|
13
13
|
};
|
|
14
|
-
const
|
|
15
|
-
const input = useRef(null);
|
|
14
|
+
const Textfield = /*#__PURE__*/forwardRef((props, ref) => {
|
|
16
15
|
const {
|
|
17
16
|
appearance = 'standard',
|
|
18
17
|
isCompact = false,
|
|
@@ -22,7 +21,6 @@ const TextfieldWithMode = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
22
21
|
isReadOnly = false,
|
|
23
22
|
isMonospaced = false,
|
|
24
23
|
width,
|
|
25
|
-
mode,
|
|
26
24
|
elemAfterInput,
|
|
27
25
|
elemBeforeInput,
|
|
28
26
|
testId,
|
|
@@ -30,8 +28,12 @@ const TextfieldWithMode = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
30
28
|
onBlur,
|
|
31
29
|
onMouseDown,
|
|
32
30
|
className,
|
|
33
|
-
...
|
|
31
|
+
...spreadProps
|
|
34
32
|
} = props;
|
|
33
|
+
const inputRef = useRef(null);
|
|
34
|
+
const {
|
|
35
|
+
mode
|
|
36
|
+
} = useGlobalTheme();
|
|
35
37
|
const handleOnFocus = usePlatformLeafEventHandler({
|
|
36
38
|
fn: event => {
|
|
37
39
|
onFocus && onFocus(event);
|
|
@@ -47,7 +49,7 @@ const TextfieldWithMode = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
47
49
|
...analyticsParams
|
|
48
50
|
});
|
|
49
51
|
const handleOnMouseDown = useCallback(event => {
|
|
50
|
-
|
|
52
|
+
// Running e.preventDefault() on the INPUT prevents double click behaviour
|
|
51
53
|
// Sadly we needed this cast as the target type is being correctly set
|
|
52
54
|
const target = event.target;
|
|
53
55
|
|
|
@@ -55,72 +57,73 @@ const TextfieldWithMode = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
55
57
|
event.preventDefault();
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
+
if (inputRef && inputRef.current && !isDisabled && document.activeElement !== inputRef.current) {
|
|
61
|
+
inputRef.current.focus();
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
onMouseDown && onMouseDown(event);
|
|
63
|
-
}, [onMouseDown,
|
|
64
|
-
|
|
65
|
+
}, [onMouseDown, isDisabled]);
|
|
65
66
|
const setInputRef = useCallback(inputElement => {
|
|
66
|
-
|
|
67
|
-
const forwardedRef = ref;
|
|
67
|
+
inputRef.current = inputElement;
|
|
68
68
|
|
|
69
|
-
if (!
|
|
69
|
+
if (!ref) {
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
if (typeof
|
|
73
|
+
if (typeof ref === 'object') {
|
|
74
74
|
// This is a blunder on the part of @types/react
|
|
75
75
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31065
|
|
76
76
|
// .current should be assignable
|
|
77
|
-
// @ts-
|
|
78
|
-
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
ref.current = inputElement;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
if (typeof
|
|
82
|
-
|
|
81
|
+
if (typeof ref === 'function') {
|
|
82
|
+
ref(inputElement);
|
|
83
83
|
}
|
|
84
84
|
}, [ref]);
|
|
85
|
-
const inputControlProps = {
|
|
86
|
-
'data-compact': isCompact ? isCompact : undefined,
|
|
87
|
-
'data-monospaced': isMonospaced ? isMonospaced : undefined,
|
|
88
|
-
'aria-invalid': isInvalid ? isInvalid : undefined
|
|
89
|
-
};
|
|
90
|
-
const containerControlProps = {
|
|
91
|
-
'data-disabled': isDisabled ? isDisabled : undefined,
|
|
92
|
-
'data-invalid': isInvalid ? isInvalid : undefined
|
|
93
|
-
};
|
|
94
85
|
const containerStyles = useMemo(() => getContainerStyles(appearance, mode, width), [appearance, mode, width]);
|
|
95
86
|
const inputStyle = useMemo(() => getInputStyles(mode), [mode]);
|
|
96
|
-
return (//
|
|
87
|
+
return (// We use event bubbling here to listen to any child element mouse down event.
|
|
97
88
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
98
|
-
jsx("div",
|
|
99
|
-
|
|
89
|
+
jsx("div", {
|
|
90
|
+
"data-disabled": isDisabled ? isDisabled : undefined,
|
|
91
|
+
"data-invalid": isInvalid ? isInvalid : undefined,
|
|
100
92
|
"data-ds--text-field--container": true,
|
|
101
93
|
"data-testid": testId && `${testId}-container`,
|
|
94
|
+
onMouseDown: handleOnMouseDown // TODO: When removing legacy theming fix this.
|
|
95
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
96
|
+
,
|
|
102
97
|
css: containerStyles,
|
|
103
98
|
className: className
|
|
104
|
-
}
|
|
99
|
+
}, elemBeforeInput, jsx("input", _extends({}, spreadProps, {
|
|
100
|
+
"data-compact": isCompact ? isCompact : undefined,
|
|
101
|
+
"data-monospaced": isMonospaced ? isMonospaced : undefined,
|
|
102
|
+
"data-ds--text-field--input": true,
|
|
103
|
+
"data-testid": testId,
|
|
104
|
+
"aria-invalid": isInvalid ? isInvalid : undefined,
|
|
105
105
|
disabled: isDisabled,
|
|
106
106
|
readOnly: isReadOnly,
|
|
107
107
|
required: isRequired,
|
|
108
108
|
onBlur: handleOnBlur,
|
|
109
109
|
onFocus: handleOnFocus,
|
|
110
|
-
ref: setInputRef
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
ref: setInputRef // TODO: When removing legacy theming fix this.
|
|
111
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
112
|
+
,
|
|
113
113
|
css: inputStyle
|
|
114
114
|
})), elemAfterInput)
|
|
115
115
|
);
|
|
116
116
|
});
|
|
117
|
-
const Textfield = /*#__PURE__*/forwardRef(function Textfield(props, ref) {
|
|
118
|
-
return jsx(GlobalTheme.Consumer, null, ({
|
|
119
|
-
mode
|
|
120
|
-
}) => jsx(TextfieldWithMode, _extends({}, props, {
|
|
121
|
-
mode: mode,
|
|
122
|
-
ref: ref
|
|
123
|
-
})));
|
|
124
|
-
});
|
|
125
117
|
Textfield.displayName = 'Textfield';
|
|
126
|
-
|
|
118
|
+
/**
|
|
119
|
+
* __Textfield__
|
|
120
|
+
*
|
|
121
|
+
* A text field is an input that allows a user to write or edit text.
|
|
122
|
+
*
|
|
123
|
+
* - [Examples](https://atlassian.design/components/textfield/examples)
|
|
124
|
+
* - [Code](https://atlassian.design/components/textfield/code)
|
|
125
|
+
* - [Usage](https://atlassian.design/components/textfield/usage)
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
export default /*#__PURE__*/memo(Textfield); // The above generic is used to let ERTC know what props to extract.
|
|
129
|
+
// See: https://github.com/atlassian/extract-react-types/issues/201
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,49 +1,46 @@
|
|
|
1
|
-
import { B100, B75, DN10,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { B100, B75, DN10, DN30, DN40, DN600, DN90, N0, N10, N100, N30, N40, N70, N900 } from '@atlaskit/theme/colors';
|
|
2
|
+
import { token } from '@atlaskit/tokens';
|
|
4
3
|
export var disabledBackgroundColor = {
|
|
5
|
-
light:
|
|
6
|
-
dark:
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export var invalidBorderColor = {
|
|
10
|
-
light: R400,
|
|
11
|
-
dark: R400
|
|
12
|
-
}; // The following do not yet have a darkmode 'map': N20A, N10
|
|
13
|
-
|
|
4
|
+
light: token('color.background.disabled', N10),
|
|
5
|
+
dark: token('color.background.disabled', DN10)
|
|
6
|
+
};
|
|
14
7
|
export var defaultBackgroundColor = {
|
|
15
|
-
light: N10,
|
|
16
|
-
dark: DN10
|
|
8
|
+
light: token('color.background.subtleBorderedNeutral.resting', N10),
|
|
9
|
+
dark: token('color.background.subtleBorderedNeutral.resting', DN10)
|
|
17
10
|
};
|
|
18
11
|
export var defaultBackgroundColorFocus = {
|
|
19
|
-
light: N0,
|
|
20
|
-
dark: DN10
|
|
12
|
+
light: token('color.background.default', N0),
|
|
13
|
+
dark: token('color.background.default', DN10)
|
|
21
14
|
};
|
|
22
15
|
export var defaultBackgroundColorHover = {
|
|
23
|
-
light: N30,
|
|
24
|
-
dark: DN30
|
|
16
|
+
light: token('color.background.default', N30),
|
|
17
|
+
dark: token('color.background.default', DN30)
|
|
18
|
+
};
|
|
19
|
+
export var subtleBackgroundColorHover = {
|
|
20
|
+
light: token('color.background.transparentNeutral.hover', N30),
|
|
21
|
+
dark: token('color.background.transparentNeutral.hover', DN30)
|
|
25
22
|
};
|
|
26
23
|
export var defaultBorderColor = {
|
|
27
|
-
light: N40,
|
|
28
|
-
dark: DN40
|
|
24
|
+
light: token('color.border.neutral', N40),
|
|
25
|
+
dark: token('color.border.neutral', DN40)
|
|
29
26
|
};
|
|
30
27
|
export var defaultBorderColorFocus = {
|
|
31
|
-
light: B100,
|
|
32
|
-
dark: B75
|
|
28
|
+
light: token('color.border.focus', B100),
|
|
29
|
+
dark: token('color.border.focus', B75)
|
|
33
30
|
};
|
|
34
31
|
export var transparent = {
|
|
35
32
|
light: 'transparent',
|
|
36
33
|
dark: 'transparent'
|
|
37
34
|
};
|
|
38
35
|
export var textColor = {
|
|
39
|
-
light: N900,
|
|
40
|
-
dark: DN600
|
|
36
|
+
light: token('color.text.highEmphasis', N900),
|
|
37
|
+
dark: token('color.text.highEmphasis', DN600)
|
|
41
38
|
};
|
|
42
39
|
export var disabledTextColor = {
|
|
43
|
-
light: N70,
|
|
44
|
-
dark: DN90
|
|
40
|
+
light: token('color.text.disabled', N70),
|
|
41
|
+
dark: token('color.text.disabled', DN90)
|
|
45
42
|
};
|
|
46
43
|
export var placeholderTextColor = {
|
|
47
|
-
light: N100,
|
|
48
|
-
dark: DN90
|
|
44
|
+
light: token('color.text.lowEmphasis', N100),
|
|
45
|
+
dark: token('color.text.lowEmphasis', DN90)
|
|
49
46
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from './text-field';
|
|
2
|
-
export { TextFieldColors } from './styles';
|
|
2
|
+
export { textFieldColors as TextFieldColors } from './styles';
|
package/dist/esm/styles.js
CHANGED
|
@@ -4,43 +4,43 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
4
4
|
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
6
|
|
|
7
|
+
import { R400 } from '@atlaskit/theme/colors';
|
|
7
8
|
import { codeFontFamily, fontFamily, fontSize as getFontSize, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
9
|
+
import { token } from '@atlaskit/tokens';
|
|
8
10
|
import * as componentTokens from './component-tokens';
|
|
9
11
|
var fontSize = getFontSize();
|
|
10
12
|
var gridSize = getGridSize();
|
|
11
13
|
var disabledRules = {
|
|
12
14
|
light: {
|
|
13
|
-
backgroundColor: componentTokens.
|
|
14
|
-
backgroundColorFocus: componentTokens.disabledBackgroundColor.light,
|
|
15
|
+
backgroundColor: componentTokens.disabledBackgroundColor.light,
|
|
15
16
|
backgroundColorHover: componentTokens.disabledBackgroundColor.light,
|
|
16
|
-
|
|
17
|
-
borderColor: componentTokens.defaultBackgroundColor.light,
|
|
18
|
-
borderColorFocus: componentTokens.defaultBorderColorFocus.light,
|
|
17
|
+
borderColor: componentTokens.disabledBackgroundColor.light,
|
|
19
18
|
textColor: componentTokens.disabledTextColor.light
|
|
20
19
|
},
|
|
21
20
|
dark: {
|
|
22
|
-
backgroundColor: componentTokens.
|
|
23
|
-
backgroundColorFocus: componentTokens.disabledBackgroundColor.dark,
|
|
21
|
+
backgroundColor: componentTokens.disabledBackgroundColor.dark,
|
|
24
22
|
backgroundColorHover: componentTokens.disabledBackgroundColor.dark,
|
|
25
|
-
|
|
26
|
-
borderColor: componentTokens.defaultBackgroundColor.dark,
|
|
27
|
-
borderColorFocus: componentTokens.defaultBorderColorFocus.dark,
|
|
23
|
+
borderColor: componentTokens.disabledBackgroundColor.dark,
|
|
28
24
|
textColor: componentTokens.disabledTextColor.dark
|
|
29
25
|
}
|
|
30
26
|
};
|
|
31
27
|
var invalidRules = {
|
|
32
28
|
light: {
|
|
29
|
+
// ----
|
|
33
30
|
backgroundColor: componentTokens.defaultBackgroundColor.light,
|
|
34
|
-
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.light,
|
|
35
31
|
backgroundColorHover: componentTokens.defaultBackgroundColorHover.light,
|
|
36
|
-
|
|
32
|
+
// ^--- the above values aren't used directly they remain because its exposed by the `textFieldColors` export
|
|
33
|
+
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.light,
|
|
34
|
+
borderColor: token('color.iconBorder.danger', R400),
|
|
37
35
|
borderColorFocus: componentTokens.defaultBorderColorFocus.light
|
|
38
36
|
},
|
|
39
37
|
dark: {
|
|
38
|
+
// ----
|
|
40
39
|
backgroundColor: componentTokens.defaultBackgroundColor.dark,
|
|
41
|
-
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.dark,
|
|
42
40
|
backgroundColorHover: componentTokens.defaultBackgroundColorHover.dark,
|
|
43
|
-
|
|
41
|
+
// ^--- the above values aren't used directly they remain because its exposed by the `textFieldColors` export
|
|
42
|
+
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.dark,
|
|
43
|
+
borderColor: token('color.iconBorder.danger', R400),
|
|
44
44
|
borderColorFocus: componentTokens.defaultBorderColorFocus.dark
|
|
45
45
|
}
|
|
46
46
|
};
|
|
@@ -56,7 +56,7 @@ var backgroundColorFocus = {
|
|
|
56
56
|
};
|
|
57
57
|
var backgroundColorHover = {
|
|
58
58
|
standard: componentTokens.defaultBackgroundColorHover,
|
|
59
|
-
subtle: componentTokens.
|
|
59
|
+
subtle: componentTokens.subtleBackgroundColorHover,
|
|
60
60
|
none: componentTokens.transparent
|
|
61
61
|
};
|
|
62
62
|
var borderColor = {
|
|
@@ -89,24 +89,13 @@ var getContainerTextBgAndBorderColor = function getContainerTextBgAndBorderColor
|
|
|
89
89
|
color: disabledRules[mode].textColor,
|
|
90
90
|
cursor: 'not-allowed'
|
|
91
91
|
},
|
|
92
|
-
'&[data-disabled]:focus-within': {
|
|
93
|
-
backgroundColor: disabledRules[mode].backgroundColorFocus,
|
|
94
|
-
borderColor: disabledRules[mode].borderColorFocus
|
|
95
|
-
},
|
|
96
|
-
'&[data-disabled]:hover': {
|
|
97
|
-
backgroundColor: disabledRules[mode].backgroundColorHover
|
|
98
|
-
},
|
|
99
92
|
'&[data-invalid]': {
|
|
100
|
-
backgroundColor: invalidRules[mode].backgroundColor,
|
|
101
93
|
borderColor: invalidRules[mode].borderColor
|
|
102
94
|
},
|
|
103
95
|
'&[data-invalid]:focus-within': {
|
|
104
96
|
backgroundColor: invalidRules[mode].backgroundColorFocus,
|
|
105
97
|
borderColor: invalidRules[mode].borderColorFocus
|
|
106
98
|
},
|
|
107
|
-
'&[data-invalid]:hover': {
|
|
108
|
-
backgroundColor: invalidRules[mode].backgroundColorHover
|
|
109
|
-
},
|
|
110
99
|
'@media screen and (-ms-high-contrast: active)': {
|
|
111
100
|
'&[data-invalid]:focus-within': {
|
|
112
101
|
borderColor: 'Highlight'
|
|
@@ -202,8 +191,9 @@ export var inputStyles = function inputStyles(mode) {
|
|
|
202
191
|
}
|
|
203
192
|
}
|
|
204
193
|
};
|
|
205
|
-
};
|
|
206
|
-
|
|
194
|
+
}; // TODO: Remove when removing legacy theming.
|
|
195
|
+
|
|
196
|
+
export var textFieldColors = {
|
|
207
197
|
backgroundColor: backgroundColor,
|
|
208
198
|
backgroundColorFocus: backgroundColorFocus,
|
|
209
199
|
backgroundColorHover: backgroundColorHover,
|
package/dist/esm/text-field.js
CHANGED
|
@@ -11,16 +11,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
11
11
|
import React, { forwardRef, memo, useCallback, useMemo, useRef } from 'react';
|
|
12
12
|
import { jsx } from '@emotion/core';
|
|
13
13
|
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
14
|
-
import
|
|
14
|
+
import { useGlobalTheme } from '@atlaskit/theme/components';
|
|
15
15
|
import { containerStyles as getContainerStyles, inputStyles as getInputStyles } from './styles';
|
|
16
16
|
var analyticsParams = {
|
|
17
17
|
componentName: 'textField',
|
|
18
18
|
packageName: "@atlaskit/textfield",
|
|
19
|
-
packageVersion: "5.
|
|
19
|
+
packageVersion: "5.1.3"
|
|
20
20
|
};
|
|
21
|
-
var
|
|
22
|
-
var input = useRef(null);
|
|
23
|
-
|
|
21
|
+
var Textfield = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
24
22
|
var _props$appearance = props.appearance,
|
|
25
23
|
appearance = _props$appearance === void 0 ? 'standard' : _props$appearance,
|
|
26
24
|
_props$isCompact = props.isCompact,
|
|
@@ -36,7 +34,6 @@ var TextfieldWithMode = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
36
34
|
_props$isMonospaced = props.isMonospaced,
|
|
37
35
|
isMonospaced = _props$isMonospaced === void 0 ? false : _props$isMonospaced,
|
|
38
36
|
width = props.width,
|
|
39
|
-
mode = props.mode,
|
|
40
37
|
elemAfterInput = props.elemAfterInput,
|
|
41
38
|
elemBeforeInput = props.elemBeforeInput,
|
|
42
39
|
testId = props.testId,
|
|
@@ -44,7 +41,12 @@ var TextfieldWithMode = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
44
41
|
onBlur = props.onBlur,
|
|
45
42
|
onMouseDown = props.onMouseDown,
|
|
46
43
|
className = props.className,
|
|
47
|
-
|
|
44
|
+
spreadProps = _objectWithoutProperties(props, ["appearance", "isCompact", "isDisabled", "isInvalid", "isRequired", "isReadOnly", "isMonospaced", "width", "elemAfterInput", "elemBeforeInput", "testId", "onFocus", "onBlur", "onMouseDown", "className"]);
|
|
45
|
+
|
|
46
|
+
var inputRef = useRef(null);
|
|
47
|
+
|
|
48
|
+
var _useGlobalTheme = useGlobalTheme(),
|
|
49
|
+
mode = _useGlobalTheme.mode;
|
|
48
50
|
|
|
49
51
|
var handleOnFocus = usePlatformLeafEventHandler(_objectSpread({
|
|
50
52
|
fn: function fn(event) {
|
|
@@ -59,7 +61,7 @@ var TextfieldWithMode = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
59
61
|
action: 'blurred'
|
|
60
62
|
}, analyticsParams));
|
|
61
63
|
var handleOnMouseDown = useCallback(function (event) {
|
|
62
|
-
|
|
64
|
+
// Running e.preventDefault() on the INPUT prevents double click behaviour
|
|
63
65
|
// Sadly we needed this cast as the target type is being correctly set
|
|
64
66
|
var target = event.target;
|
|
65
67
|
|
|
@@ -67,77 +69,77 @@ var TextfieldWithMode = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
67
69
|
event.preventDefault();
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
+
if (inputRef && inputRef.current && !isDisabled && document.activeElement !== inputRef.current) {
|
|
73
|
+
inputRef.current.focus();
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
onMouseDown && onMouseDown(event);
|
|
75
|
-
}, [onMouseDown,
|
|
76
|
-
|
|
77
|
+
}, [onMouseDown, isDisabled]);
|
|
77
78
|
var setInputRef = useCallback(function (inputElement) {
|
|
78
|
-
|
|
79
|
-
var forwardedRef = ref;
|
|
79
|
+
inputRef.current = inputElement;
|
|
80
80
|
|
|
81
|
-
if (!
|
|
81
|
+
if (!ref) {
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
if (_typeof(
|
|
85
|
+
if (_typeof(ref) === 'object') {
|
|
86
86
|
// This is a blunder on the part of @types/react
|
|
87
87
|
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31065
|
|
88
88
|
// .current should be assignable
|
|
89
|
-
// @ts-
|
|
90
|
-
|
|
89
|
+
// @ts-expect-error
|
|
90
|
+
ref.current = inputElement;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
if (typeof
|
|
94
|
-
|
|
93
|
+
if (typeof ref === 'function') {
|
|
94
|
+
ref(inputElement);
|
|
95
95
|
}
|
|
96
96
|
}, [ref]);
|
|
97
|
-
var inputControlProps = {
|
|
98
|
-
'data-compact': isCompact ? isCompact : undefined,
|
|
99
|
-
'data-monospaced': isMonospaced ? isMonospaced : undefined,
|
|
100
|
-
'aria-invalid': isInvalid ? isInvalid : undefined
|
|
101
|
-
};
|
|
102
|
-
var containerControlProps = {
|
|
103
|
-
'data-disabled': isDisabled ? isDisabled : undefined,
|
|
104
|
-
'data-invalid': isInvalid ? isInvalid : undefined
|
|
105
|
-
};
|
|
106
97
|
var containerStyles = useMemo(function () {
|
|
107
98
|
return getContainerStyles(appearance, mode, width);
|
|
108
99
|
}, [appearance, mode, width]);
|
|
109
100
|
var inputStyle = useMemo(function () {
|
|
110
101
|
return getInputStyles(mode);
|
|
111
102
|
}, [mode]);
|
|
112
|
-
return (//
|
|
103
|
+
return (// We use event bubbling here to listen to any child element mouse down event.
|
|
113
104
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
114
|
-
jsx("div",
|
|
115
|
-
|
|
105
|
+
jsx("div", {
|
|
106
|
+
"data-disabled": isDisabled ? isDisabled : undefined,
|
|
107
|
+
"data-invalid": isInvalid ? isInvalid : undefined,
|
|
116
108
|
"data-ds--text-field--container": true,
|
|
117
109
|
"data-testid": testId && "".concat(testId, "-container"),
|
|
110
|
+
onMouseDown: handleOnMouseDown // TODO: When removing legacy theming fix this.
|
|
111
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
112
|
+
,
|
|
118
113
|
css: containerStyles,
|
|
119
114
|
className: className
|
|
120
|
-
}
|
|
115
|
+
}, elemBeforeInput, jsx("input", _extends({}, spreadProps, {
|
|
116
|
+
"data-compact": isCompact ? isCompact : undefined,
|
|
117
|
+
"data-monospaced": isMonospaced ? isMonospaced : undefined,
|
|
118
|
+
"data-ds--text-field--input": true,
|
|
119
|
+
"data-testid": testId,
|
|
120
|
+
"aria-invalid": isInvalid ? isInvalid : undefined,
|
|
121
121
|
disabled: isDisabled,
|
|
122
122
|
readOnly: isReadOnly,
|
|
123
123
|
required: isRequired,
|
|
124
124
|
onBlur: handleOnBlur,
|
|
125
125
|
onFocus: handleOnFocus,
|
|
126
|
-
ref: setInputRef
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
ref: setInputRef // TODO: When removing legacy theming fix this.
|
|
127
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
128
|
+
,
|
|
129
129
|
css: inputStyle
|
|
130
130
|
})), elemAfterInput)
|
|
131
131
|
);
|
|
132
132
|
});
|
|
133
|
-
var Textfield = /*#__PURE__*/forwardRef(function Textfield(props, ref) {
|
|
134
|
-
return jsx(GlobalTheme.Consumer, null, function (_ref) {
|
|
135
|
-
var mode = _ref.mode;
|
|
136
|
-
return jsx(TextfieldWithMode, _extends({}, props, {
|
|
137
|
-
mode: mode,
|
|
138
|
-
ref: ref
|
|
139
|
-
}));
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
133
|
Textfield.displayName = 'Textfield';
|
|
143
|
-
|
|
134
|
+
/**
|
|
135
|
+
* __Textfield__
|
|
136
|
+
*
|
|
137
|
+
* A text field is an input that allows a user to write or edit text.
|
|
138
|
+
*
|
|
139
|
+
* - [Examples](https://atlassian.design/components/textfield/examples)
|
|
140
|
+
* - [Code](https://atlassian.design/components/textfield/code)
|
|
141
|
+
* - [Usage](https://atlassian.design/components/textfield/usage)
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
export default /*#__PURE__*/memo(Textfield); // The above generic is used to let ERTC know what props to extract.
|
|
145
|
+
// See: https://github.com/atlassian/extract-react-types/issues/201
|
package/dist/esm/version.json
CHANGED