@atlaskit/textfield 5.1.2
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 +673 -0
- package/LICENSE +13 -0
- package/README.md +13 -0
- package/__perf__/default.tsx +5 -0
- package/__perf__/examples.tsx +58 -0
- package/codemods/5.0.0-lite-mode.tsx +16 -0
- package/codemods/__tests__/5.0.0-lite-mode.tsx +87 -0
- package/codemods/__tests__/remove-imports.tsx +64 -0
- package/codemods/__tests__/remove-prop.tsx +142 -0
- package/codemods/__tests__/rename-imports.tsx +85 -0
- package/codemods/migrations/remove-imports.tsx +8 -0
- package/codemods/migrations/remove-props.tsx +10 -0
- package/codemods/migrations/rename-imports.tsx +15 -0
- package/codemods/migrations/utils.tsx +375 -0
- package/dist/cjs/component-tokens.js +66 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/styles.js +231 -0
- package/dist/cjs/text-field.js +169 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/component-tokens.js +46 -0
- package/dist/es2019/index.js +2 -0
- package/dist/es2019/styles.js +192 -0
- package/dist/es2019/text-field.js +129 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/component-tokens.js +46 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/styles.js +206 -0
- package/dist/esm/text-field.js +145 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/component-tokens.d.ts +44 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/styles.d.ts +208 -0
- package/dist/types/text-field.d.ts +14 -0
- package/dist/types/types.d.ts +71 -0
- package/package.json +79 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "default", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _textField.default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "TextFieldColors", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _styles.textFieldColors;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
var _textField = _interopRequireDefault(require("./text-field"));
|
|
22
|
+
|
|
23
|
+
var _styles = require("./styles");
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.textFieldColors = exports.inputStyles = exports.containerStyles = void 0;
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _colors = require("@atlaskit/theme/colors");
|
|
15
|
+
|
|
16
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
17
|
+
|
|
18
|
+
var _tokens = require("@atlaskit/tokens");
|
|
19
|
+
|
|
20
|
+
var componentTokens = _interopRequireWildcard(require("./component-tokens"));
|
|
21
|
+
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
29
|
+
|
|
30
|
+
var fontSize = (0, _constants.fontSize)();
|
|
31
|
+
var gridSize = (0, _constants.gridSize)();
|
|
32
|
+
var disabledRules = {
|
|
33
|
+
light: {
|
|
34
|
+
backgroundColor: componentTokens.disabledBackgroundColor.light,
|
|
35
|
+
backgroundColorHover: componentTokens.disabledBackgroundColor.light,
|
|
36
|
+
borderColor: componentTokens.disabledBackgroundColor.light,
|
|
37
|
+
textColor: componentTokens.disabledTextColor.light
|
|
38
|
+
},
|
|
39
|
+
dark: {
|
|
40
|
+
backgroundColor: componentTokens.disabledBackgroundColor.dark,
|
|
41
|
+
backgroundColorHover: componentTokens.disabledBackgroundColor.dark,
|
|
42
|
+
borderColor: componentTokens.disabledBackgroundColor.dark,
|
|
43
|
+
textColor: componentTokens.disabledTextColor.dark
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var invalidRules = {
|
|
47
|
+
light: {
|
|
48
|
+
// ----
|
|
49
|
+
backgroundColor: componentTokens.defaultBackgroundColor.light,
|
|
50
|
+
backgroundColorHover: componentTokens.defaultBackgroundColorHover.light,
|
|
51
|
+
// ^--- the above values aren't used directly they remain because its exposed by the `textFieldColors` export
|
|
52
|
+
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.light,
|
|
53
|
+
borderColor: (0, _tokens.token)('color.iconBorder.danger', _colors.R400),
|
|
54
|
+
borderColorFocus: componentTokens.defaultBorderColorFocus.light
|
|
55
|
+
},
|
|
56
|
+
dark: {
|
|
57
|
+
// ----
|
|
58
|
+
backgroundColor: componentTokens.defaultBackgroundColor.dark,
|
|
59
|
+
backgroundColorHover: componentTokens.defaultBackgroundColorHover.dark,
|
|
60
|
+
// ^--- the above values aren't used directly they remain because its exposed by the `textFieldColors` export
|
|
61
|
+
backgroundColorFocus: componentTokens.defaultBackgroundColorFocus.dark,
|
|
62
|
+
borderColor: (0, _tokens.token)('color.iconBorder.danger', _colors.R400),
|
|
63
|
+
borderColorFocus: componentTokens.defaultBorderColorFocus.dark
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var backgroundColor = {
|
|
67
|
+
standard: componentTokens.defaultBackgroundColor,
|
|
68
|
+
subtle: componentTokens.transparent,
|
|
69
|
+
none: componentTokens.transparent
|
|
70
|
+
};
|
|
71
|
+
var backgroundColorFocus = {
|
|
72
|
+
standard: componentTokens.defaultBackgroundColorFocus,
|
|
73
|
+
subtle: componentTokens.defaultBackgroundColorFocus,
|
|
74
|
+
none: componentTokens.transparent
|
|
75
|
+
};
|
|
76
|
+
var backgroundColorHover = {
|
|
77
|
+
standard: componentTokens.defaultBackgroundColorHover,
|
|
78
|
+
subtle: componentTokens.subtleBackgroundColorHover,
|
|
79
|
+
none: componentTokens.transparent
|
|
80
|
+
};
|
|
81
|
+
var borderColor = {
|
|
82
|
+
standard: componentTokens.defaultBorderColor,
|
|
83
|
+
subtle: componentTokens.transparent,
|
|
84
|
+
none: componentTokens.transparent
|
|
85
|
+
};
|
|
86
|
+
var borderColorFocus = {
|
|
87
|
+
standard: componentTokens.defaultBorderColorFocus,
|
|
88
|
+
subtle: componentTokens.defaultBorderColorFocus,
|
|
89
|
+
none: componentTokens.transparent
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var getContainerTextBgAndBorderColor = function getContainerTextBgAndBorderColor(appearance, mode) {
|
|
93
|
+
return {
|
|
94
|
+
backgroundColor: backgroundColor[appearance][mode],
|
|
95
|
+
borderColor: borderColor[appearance][mode],
|
|
96
|
+
color: componentTokens.textColor[mode],
|
|
97
|
+
cursor: 'text',
|
|
98
|
+
'&:hover': {
|
|
99
|
+
backgroundColor: backgroundColorHover[appearance][mode]
|
|
100
|
+
},
|
|
101
|
+
'&:focus-within': {
|
|
102
|
+
backgroundColor: backgroundColorFocus[appearance][mode],
|
|
103
|
+
borderColor: borderColorFocus[appearance][mode]
|
|
104
|
+
},
|
|
105
|
+
'&[data-disabled]': {
|
|
106
|
+
backgroundColor: disabledRules[mode].backgroundColor,
|
|
107
|
+
borderColor: disabledRules[mode].borderColor,
|
|
108
|
+
color: disabledRules[mode].textColor,
|
|
109
|
+
cursor: 'not-allowed'
|
|
110
|
+
},
|
|
111
|
+
'&[data-invalid]': {
|
|
112
|
+
borderColor: invalidRules[mode].borderColor
|
|
113
|
+
},
|
|
114
|
+
'&[data-invalid]:focus-within': {
|
|
115
|
+
backgroundColor: invalidRules[mode].backgroundColorFocus,
|
|
116
|
+
borderColor: invalidRules[mode].borderColorFocus
|
|
117
|
+
},
|
|
118
|
+
'@media screen and (-ms-high-contrast: active)': {
|
|
119
|
+
'&[data-invalid]:focus-within': {
|
|
120
|
+
borderColor: 'Highlight'
|
|
121
|
+
},
|
|
122
|
+
'&:focus-within': {
|
|
123
|
+
borderColor: 'Highlight'
|
|
124
|
+
},
|
|
125
|
+
'&[data-disabled]': {
|
|
126
|
+
borderColor: 'GrayText'
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
var widthMap = {
|
|
133
|
+
xsmall: 80,
|
|
134
|
+
small: 160,
|
|
135
|
+
medium: 240,
|
|
136
|
+
large: 320,
|
|
137
|
+
xlarge: 480
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
var getMaxWidth = function getMaxWidth(width) {
|
|
141
|
+
return !width ? "100%" : width in widthMap ? widthMap[width] : +width;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
var containerStyles = function containerStyles(appearance, mode, width) {
|
|
145
|
+
return _objectSpread(_objectSpread({
|
|
146
|
+
alignItems: 'center'
|
|
147
|
+
}, getContainerTextBgAndBorderColor(appearance, mode)), {}, {
|
|
148
|
+
borderRadius: 3,
|
|
149
|
+
borderWidth: 2,
|
|
150
|
+
borderStyle: appearance === 'none' ? 'none' : 'solid',
|
|
151
|
+
boxSizing: 'border-box',
|
|
152
|
+
display: 'flex',
|
|
153
|
+
flex: '1 1 100%',
|
|
154
|
+
fontSize: fontSize,
|
|
155
|
+
justifyContent: 'space-between',
|
|
156
|
+
maxWidth: getMaxWidth(width),
|
|
157
|
+
overflow: 'hidden',
|
|
158
|
+
transition: "background-color 0.2s ease-in-out, border-color 0.2s ease-in-out",
|
|
159
|
+
wordWrap: 'break-word',
|
|
160
|
+
verticalAlign: 'top',
|
|
161
|
+
pointerEvents: 'auto'
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
exports.containerStyles = containerStyles;
|
|
166
|
+
|
|
167
|
+
var inputStyles = function inputStyles(mode) {
|
|
168
|
+
return {
|
|
169
|
+
backgroundColor: 'transparent',
|
|
170
|
+
border: 0,
|
|
171
|
+
boxSizing: 'border-box',
|
|
172
|
+
color: 'inherit',
|
|
173
|
+
cursor: 'inherit',
|
|
174
|
+
fontSize: fontSize,
|
|
175
|
+
minWidth: '0',
|
|
176
|
+
outline: 'none',
|
|
177
|
+
width: '100%',
|
|
178
|
+
lineHeight: gridSize * 2.5 / fontSize,
|
|
179
|
+
fontFamily: (0, _constants.fontFamily)(),
|
|
180
|
+
'&[data-monospaced]': {
|
|
181
|
+
fontFamily: (0, _constants.codeFontFamily)()
|
|
182
|
+
},
|
|
183
|
+
'&[data-compact]': {
|
|
184
|
+
padding: "".concat(gridSize / 2, "px ").concat(gridSize - 2, "px"),
|
|
185
|
+
height: "".concat((gridSize * 3.5 / fontSize).toFixed(2), "em")
|
|
186
|
+
},
|
|
187
|
+
'&:not([data-compact])': {
|
|
188
|
+
padding: "".concat(gridSize, "px ").concat(gridSize - 2, "px"),
|
|
189
|
+
height: "".concat((gridSize * 4.5 / fontSize).toFixed(2), "em")
|
|
190
|
+
},
|
|
191
|
+
'&[disabled]': {
|
|
192
|
+
// Safari (WebKit) adds a -webkit-text-fill-color style to disabled inputs
|
|
193
|
+
// which takes priority over color and makes the text unreadable. Need to
|
|
194
|
+
// override it with the color we want.
|
|
195
|
+
WebkitTextFillColor: disabledRules[mode].textColor
|
|
196
|
+
},
|
|
197
|
+
// Hide the clear indicator on Edge (Windows only)
|
|
198
|
+
'&::-ms-clear': {
|
|
199
|
+
display: 'none'
|
|
200
|
+
},
|
|
201
|
+
'&:invalid': {
|
|
202
|
+
boxShadow: 'none'
|
|
203
|
+
},
|
|
204
|
+
'&::placeholder': {
|
|
205
|
+
color: componentTokens.placeholderTextColor[mode],
|
|
206
|
+
'&:disabled': {
|
|
207
|
+
color: disabledRules[mode].textColor
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
'@media screen and (-ms-high-contrast: active)': {
|
|
211
|
+
'&[disabled]': {
|
|
212
|
+
color: 'GrayText'
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}; // TODO: Remove when removing legacy theming.
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
exports.inputStyles = inputStyles;
|
|
220
|
+
var textFieldColors = {
|
|
221
|
+
backgroundColor: backgroundColor,
|
|
222
|
+
backgroundColorFocus: backgroundColorFocus,
|
|
223
|
+
backgroundColorHover: backgroundColorHover,
|
|
224
|
+
borderColor: borderColor,
|
|
225
|
+
borderColorFocus: borderColorFocus,
|
|
226
|
+
placeholderTextColor: componentTokens.placeholderTextColor,
|
|
227
|
+
textColor: componentTokens.textColor,
|
|
228
|
+
invalidRules: invalidRules,
|
|
229
|
+
disabledRules: disabledRules
|
|
230
|
+
};
|
|
231
|
+
exports.textFieldColors = textFieldColors;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
15
|
+
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
19
|
+
|
|
20
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
21
|
+
|
|
22
|
+
var _core = require("@emotion/core");
|
|
23
|
+
|
|
24
|
+
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
25
|
+
|
|
26
|
+
var _components = require("@atlaskit/theme/components");
|
|
27
|
+
|
|
28
|
+
var _styles = require("./styles");
|
|
29
|
+
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
+
|
|
34
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
+
|
|
36
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
37
|
+
|
|
38
|
+
var analyticsParams = {
|
|
39
|
+
componentName: 'textField',
|
|
40
|
+
packageName: "@atlaskit/textfield",
|
|
41
|
+
packageVersion: "5.1.2"
|
|
42
|
+
};
|
|
43
|
+
var Textfield = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
44
|
+
var _props$appearance = props.appearance,
|
|
45
|
+
appearance = _props$appearance === void 0 ? 'standard' : _props$appearance,
|
|
46
|
+
_props$isCompact = props.isCompact,
|
|
47
|
+
isCompact = _props$isCompact === void 0 ? false : _props$isCompact,
|
|
48
|
+
_props$isDisabled = props.isDisabled,
|
|
49
|
+
isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,
|
|
50
|
+
_props$isInvalid = props.isInvalid,
|
|
51
|
+
isInvalid = _props$isInvalid === void 0 ? false : _props$isInvalid,
|
|
52
|
+
_props$isRequired = props.isRequired,
|
|
53
|
+
isRequired = _props$isRequired === void 0 ? false : _props$isRequired,
|
|
54
|
+
_props$isReadOnly = props.isReadOnly,
|
|
55
|
+
isReadOnly = _props$isReadOnly === void 0 ? false : _props$isReadOnly,
|
|
56
|
+
_props$isMonospaced = props.isMonospaced,
|
|
57
|
+
isMonospaced = _props$isMonospaced === void 0 ? false : _props$isMonospaced,
|
|
58
|
+
width = props.width,
|
|
59
|
+
elemAfterInput = props.elemAfterInput,
|
|
60
|
+
elemBeforeInput = props.elemBeforeInput,
|
|
61
|
+
testId = props.testId,
|
|
62
|
+
onFocus = props.onFocus,
|
|
63
|
+
onBlur = props.onBlur,
|
|
64
|
+
onMouseDown = props.onMouseDown,
|
|
65
|
+
className = props.className,
|
|
66
|
+
spreadProps = (0, _objectWithoutProperties2.default)(props, ["appearance", "isCompact", "isDisabled", "isInvalid", "isRequired", "isReadOnly", "isMonospaced", "width", "elemAfterInput", "elemBeforeInput", "testId", "onFocus", "onBlur", "onMouseDown", "className"]);
|
|
67
|
+
var inputRef = (0, _react.useRef)(null);
|
|
68
|
+
|
|
69
|
+
var _useGlobalTheme = (0, _components.useGlobalTheme)(),
|
|
70
|
+
mode = _useGlobalTheme.mode;
|
|
71
|
+
|
|
72
|
+
var handleOnFocus = (0, _analyticsNext.usePlatformLeafEventHandler)(_objectSpread({
|
|
73
|
+
fn: function fn(event) {
|
|
74
|
+
onFocus && onFocus(event);
|
|
75
|
+
},
|
|
76
|
+
action: 'focused'
|
|
77
|
+
}, analyticsParams));
|
|
78
|
+
var handleOnBlur = (0, _analyticsNext.usePlatformLeafEventHandler)(_objectSpread({
|
|
79
|
+
fn: function fn(event) {
|
|
80
|
+
onBlur && onBlur(event);
|
|
81
|
+
},
|
|
82
|
+
action: 'blurred'
|
|
83
|
+
}, analyticsParams));
|
|
84
|
+
var handleOnMouseDown = (0, _react.useCallback)(function (event) {
|
|
85
|
+
// Running e.preventDefault() on the INPUT prevents double click behaviour
|
|
86
|
+
// Sadly we needed this cast as the target type is being correctly set
|
|
87
|
+
var target = event.target;
|
|
88
|
+
|
|
89
|
+
if (target.tagName !== 'INPUT') {
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (inputRef && inputRef.current && !isDisabled && document.activeElement !== inputRef.current) {
|
|
94
|
+
inputRef.current.focus();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
onMouseDown && onMouseDown(event);
|
|
98
|
+
}, [onMouseDown, isDisabled]);
|
|
99
|
+
var setInputRef = (0, _react.useCallback)(function (inputElement) {
|
|
100
|
+
inputRef.current = inputElement;
|
|
101
|
+
|
|
102
|
+
if (!ref) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if ((0, _typeof2.default)(ref) === 'object') {
|
|
107
|
+
// This is a blunder on the part of @types/react
|
|
108
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/31065
|
|
109
|
+
// .current should be assignable
|
|
110
|
+
// @ts-expect-error
|
|
111
|
+
ref.current = inputElement;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (typeof ref === 'function') {
|
|
115
|
+
ref(inputElement);
|
|
116
|
+
}
|
|
117
|
+
}, [ref]);
|
|
118
|
+
var containerStyles = (0, _react.useMemo)(function () {
|
|
119
|
+
return (0, _styles.containerStyles)(appearance, mode, width);
|
|
120
|
+
}, [appearance, mode, width]);
|
|
121
|
+
var inputStyle = (0, _react.useMemo)(function () {
|
|
122
|
+
return (0, _styles.inputStyles)(mode);
|
|
123
|
+
}, [mode]);
|
|
124
|
+
return (// We use event bubbling here to listen to any child element mouse down event.
|
|
125
|
+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
126
|
+
(0, _core.jsx)("div", {
|
|
127
|
+
"data-disabled": isDisabled ? isDisabled : undefined,
|
|
128
|
+
"data-invalid": isInvalid ? isInvalid : undefined,
|
|
129
|
+
"data-ds--text-field--container": true,
|
|
130
|
+
"data-testid": testId && "".concat(testId, "-container"),
|
|
131
|
+
onMouseDown: handleOnMouseDown // TODO: When removing legacy theming fix this.
|
|
132
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
133
|
+
,
|
|
134
|
+
css: containerStyles,
|
|
135
|
+
className: className
|
|
136
|
+
}, elemBeforeInput, (0, _core.jsx)("input", (0, _extends2.default)({}, spreadProps, {
|
|
137
|
+
"data-compact": isCompact ? isCompact : undefined,
|
|
138
|
+
"data-monospaced": isMonospaced ? isMonospaced : undefined,
|
|
139
|
+
"data-ds--text-field--input": true,
|
|
140
|
+
"data-testid": testId,
|
|
141
|
+
"aria-invalid": isInvalid ? isInvalid : undefined,
|
|
142
|
+
disabled: isDisabled,
|
|
143
|
+
readOnly: isReadOnly,
|
|
144
|
+
required: isRequired,
|
|
145
|
+
onBlur: handleOnBlur,
|
|
146
|
+
onFocus: handleOnFocus,
|
|
147
|
+
ref: setInputRef // TODO: When removing legacy theming fix this.
|
|
148
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
149
|
+
,
|
|
150
|
+
css: inputStyle
|
|
151
|
+
})), elemAfterInput)
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
Textfield.displayName = 'Textfield';
|
|
155
|
+
/**
|
|
156
|
+
* __Textfield__
|
|
157
|
+
*
|
|
158
|
+
* A text field is an input that allows a user to write or edit text.
|
|
159
|
+
*
|
|
160
|
+
* - [Examples](https://atlassian.design/components/textfield/examples)
|
|
161
|
+
* - [Code](https://atlassian.design/components/textfield/code)
|
|
162
|
+
* - [Usage](https://atlassian.design/components/textfield/usage)
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
var _default = /*#__PURE__*/(0, _react.memo)(Textfield); // The above generic is used to let ERTC know what props to extract.
|
|
166
|
+
// See: https://github.com/atlassian/extract-react-types/issues/201
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
exports.default = _default;
|
|
@@ -0,0 +1,46 @@
|
|
|
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';
|
|
3
|
+
export const disabledBackgroundColor = {
|
|
4
|
+
light: token('color.background.disabled', N10),
|
|
5
|
+
dark: token('color.background.disabled', DN10)
|
|
6
|
+
};
|
|
7
|
+
export const defaultBackgroundColor = {
|
|
8
|
+
light: token('color.background.subtleBorderedNeutral.resting', N10),
|
|
9
|
+
dark: token('color.background.subtleBorderedNeutral.resting', DN10)
|
|
10
|
+
};
|
|
11
|
+
export const defaultBackgroundColorFocus = {
|
|
12
|
+
light: token('color.background.default', N0),
|
|
13
|
+
dark: token('color.background.default', DN10)
|
|
14
|
+
};
|
|
15
|
+
export const defaultBackgroundColorHover = {
|
|
16
|
+
light: token('color.background.default', N30),
|
|
17
|
+
dark: token('color.background.default', DN30)
|
|
18
|
+
};
|
|
19
|
+
export const subtleBackgroundColorHover = {
|
|
20
|
+
light: token('color.background.transparentNeutral.hover', N30),
|
|
21
|
+
dark: token('color.background.transparentNeutral.hover', DN30)
|
|
22
|
+
};
|
|
23
|
+
export const defaultBorderColor = {
|
|
24
|
+
light: token('color.border.neutral', N40),
|
|
25
|
+
dark: token('color.border.neutral', DN40)
|
|
26
|
+
};
|
|
27
|
+
export const defaultBorderColorFocus = {
|
|
28
|
+
light: token('color.border.focus', B100),
|
|
29
|
+
dark: token('color.border.focus', B75)
|
|
30
|
+
};
|
|
31
|
+
export const transparent = {
|
|
32
|
+
light: 'transparent',
|
|
33
|
+
dark: 'transparent'
|
|
34
|
+
};
|
|
35
|
+
export const textColor = {
|
|
36
|
+
light: token('color.text.highEmphasis', N900),
|
|
37
|
+
dark: token('color.text.highEmphasis', DN600)
|
|
38
|
+
};
|
|
39
|
+
export const disabledTextColor = {
|
|
40
|
+
light: token('color.text.disabled', N70),
|
|
41
|
+
dark: token('color.text.disabled', DN90)
|
|
42
|
+
};
|
|
43
|
+
export const placeholderTextColor = {
|
|
44
|
+
light: token('color.text.lowEmphasis', N100),
|
|
45
|
+
dark: token('color.text.lowEmphasis', DN90)
|
|
46
|
+
};
|