@7shifts/sous-chef 2.7.0 → 2.8.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/dist/forms/CurrencyField/CurrencyField.d.ts +11 -0
- package/dist/forms/CurrencyField/index.d.ts +1 -0
- package/dist/forms/PercentageField/PercentageField.d.ts +13 -0
- package/dist/forms/PercentageField/index.d.ts +1 -0
- package/dist/forms/index.d.ts +3 -1
- package/dist/index.js +136 -5
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +135 -6
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Props as TextFieldProps } from '../TextField/TextField';
|
|
3
|
+
/**
|
|
4
|
+
* `CurrencyField` is like `TextField` but it auto-format the value when the user leaves the field.
|
|
5
|
+
*
|
|
6
|
+
* At the end, it is just a string formatted nicely. **You are in charge of validating the value and parsing it back to a value that you can use on your application**.
|
|
7
|
+
*/
|
|
8
|
+
declare const CurrencyField: React.ForwardRefExoticComponent<TextFieldProps & {
|
|
9
|
+
currencySymbol: string;
|
|
10
|
+
} & Pick<TextFieldProps, "disabled" | "id" | "caption" | "label" | "error" | "onChange" | "name" | "value" | "onBlur" | "placeholder" | "autoFocus" | "onFocus" | "onKeyDown" | "defaultValue" | "autoComplete" | "maxLength"> & React.RefAttributes<HTMLInputElement>>;
|
|
11
|
+
export default CurrencyField;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './CurrencyField';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Props as TextFieldProps } from '../TextField/TextField';
|
|
3
|
+
/**
|
|
4
|
+
* `PercentageField` is an extended `TextField` input with validation and formatting in place to properly display percentage values.
|
|
5
|
+
* In its default state it only allows integers between 0 and 100, but it can be configured to allow decimals and negative values.
|
|
6
|
+
*/
|
|
7
|
+
declare const PercentageField: React.ForwardRefExoticComponent<{
|
|
8
|
+
max?: number | undefined;
|
|
9
|
+
min?: number | undefined;
|
|
10
|
+
precision?: number | undefined;
|
|
11
|
+
stepSize?: number | undefined;
|
|
12
|
+
} & Pick<TextFieldProps, "disabled" | "id" | "caption" | "label" | "error" | "onChange" | "name" | "value" | "onBlur" | "placeholder" | "prefix" | "autoFocus" | "onFocus" | "onKeyDown" | "defaultValue" | "autoComplete"> & React.RefAttributes<HTMLInputElement>>;
|
|
13
|
+
export default PercentageField;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './PercentageField';
|
package/dist/forms/index.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ import DateField from './DateField';
|
|
|
13
13
|
import DateRangeField from './DateRangeField';
|
|
14
14
|
import WeekField from './WeekField';
|
|
15
15
|
import TimeField from './TimeField';
|
|
16
|
-
|
|
16
|
+
import CurrencyField from './CurrencyField';
|
|
17
|
+
import PercentageField from './PercentageField';
|
|
18
|
+
export { Form, FormRow, TextAreaField, TextField, CheckboxField, PillSelectField, RadioGroupField, RadioGroupOption, PasswordField, MultiSelectField, SelectField, DateField, DateRangeField, WeekField, TimeField, CurrencyField, PercentageField, SIZE_25_PERCENT, SIZE_33_PERCENT, SIZE_50_PERCENT, SIZE_66_PERCENT, SIZE_75_PERCENT };
|
|
17
19
|
export type { PasswordCriteria } from './PasswordField/types';
|
|
18
20
|
export type { SelectOption, SelectOptions } from './SelectField/types';
|
|
19
21
|
export type { FormikType } from './Form/types';
|
package/dist/index.js
CHANGED
|
@@ -4581,7 +4581,7 @@ var useRadioGroupFieldControllers = function useRadioGroupFieldControllers(_ref)
|
|
|
4581
4581
|
error: error !== undefined ? controllers.error : formikState.error,
|
|
4582
4582
|
value: value !== undefined ? controllers.value : formikState.value,
|
|
4583
4583
|
onChange: function onChange(e) {
|
|
4584
|
-
formik.setFieldValue(name, e.target.
|
|
4584
|
+
formik.setFieldValue(name, e.target.value);
|
|
4585
4585
|
_onChange && _onChange(e.target.value);
|
|
4586
4586
|
}
|
|
4587
4587
|
});
|
|
@@ -5361,7 +5361,7 @@ var DateField = function DateField(_ref) {
|
|
|
5361
5361
|
inputProps: {
|
|
5362
5362
|
name: name,
|
|
5363
5363
|
id: controllers.id,
|
|
5364
|
-
className: classnames(inputStyles['date-field'], (_classnames = {}, _classnames[inputStyles['date--invalid']] = hasError, _classnames)),
|
|
5364
|
+
className: classnames(inputStyles['date-field'], (_classnames = {}, _classnames[inputStyles['date-field--invalid']] = hasError, _classnames)),
|
|
5365
5365
|
'data-testid': "date-field-" + name,
|
|
5366
5366
|
'aria-describedby': hasError ? controllers.id + "-error-message" : controllers.id + "-describer",
|
|
5367
5367
|
'aria-invalid': hasError,
|
|
@@ -5863,7 +5863,7 @@ var WeekField = function WeekField(_ref) {
|
|
|
5863
5863
|
inputProps: {
|
|
5864
5864
|
name: name,
|
|
5865
5865
|
id: controllers.id,
|
|
5866
|
-
className: classnames(inputStyles['date-field'], (_classnames = {}, _classnames[inputStyles['date--invalid']] = hasError, _classnames)),
|
|
5866
|
+
className: classnames(inputStyles['date-field'], (_classnames = {}, _classnames[inputStyles['date-field--invalid']] = hasError, _classnames)),
|
|
5867
5867
|
'data-testid': "week-field-" + name,
|
|
5868
5868
|
'aria-describedby': hasError ? controllers.id + "-error-message" : controllers.id + "-describer",
|
|
5869
5869
|
'aria-invalid': hasError,
|
|
@@ -5909,6 +5909,135 @@ var TimeFieldElement = function TimeFieldElement(_ref, ref) {
|
|
|
5909
5909
|
|
|
5910
5910
|
var TimeField = React.forwardRef(TimeFieldElement);
|
|
5911
5911
|
|
|
5912
|
+
var _excluded$7 = ["currencySymbol"];
|
|
5913
|
+
|
|
5914
|
+
var CurrencyFieldElement = function CurrencyFieldElement(_ref, ref) {
|
|
5915
|
+
var _ref$currencySymbol = _ref.currencySymbol,
|
|
5916
|
+
currencySymbol = _ref$currencySymbol === void 0 ? "$" : _ref$currencySymbol,
|
|
5917
|
+
allOtherProps = _objectWithoutPropertiesLoose(_ref, _excluded$7);
|
|
5918
|
+
|
|
5919
|
+
var _useTextField = useTextField(_extends({}, allOtherProps, {
|
|
5920
|
+
ref: ref
|
|
5921
|
+
})),
|
|
5922
|
+
inputProps = _useTextField.inputProps,
|
|
5923
|
+
fieldProps = _useTextField.fieldProps;
|
|
5924
|
+
|
|
5925
|
+
return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(AffixContainer, {
|
|
5926
|
+
prefix: currencySymbol
|
|
5927
|
+
}, React__default.createElement("input", Object.assign({}, inputProps, {
|
|
5928
|
+
type: 'number',
|
|
5929
|
+
inputMode: 'decimal',
|
|
5930
|
+
step: '0.01',
|
|
5931
|
+
min: 0,
|
|
5932
|
+
onKeyDown: function onKeyDown(e) {
|
|
5933
|
+
if (e.key === 'e' || e.key === '-') {
|
|
5934
|
+
e.preventDefault();
|
|
5935
|
+
return;
|
|
5936
|
+
}
|
|
5937
|
+
|
|
5938
|
+
inputProps.onKeyDown(e);
|
|
5939
|
+
},
|
|
5940
|
+
onBlur: function onBlur(e) {
|
|
5941
|
+
e.currentTarget.value = parseFloat(e.currentTarget.value).toFixed(2);
|
|
5942
|
+
inputProps.onChange(e);
|
|
5943
|
+
inputProps.onBlur(e);
|
|
5944
|
+
}
|
|
5945
|
+
}))));
|
|
5946
|
+
};
|
|
5947
|
+
|
|
5948
|
+
var CurrencyField = React.forwardRef(CurrencyFieldElement);
|
|
5949
|
+
|
|
5950
|
+
var _excluded$8 = ["max", "min", "precision", "stepSize"];
|
|
5951
|
+
|
|
5952
|
+
var PercentageElement = function PercentageElement(_ref, ref) {
|
|
5953
|
+
var _ref$max = _ref.max,
|
|
5954
|
+
max = _ref$max === void 0 ? 100 : _ref$max,
|
|
5955
|
+
_ref$min = _ref.min,
|
|
5956
|
+
min = _ref$min === void 0 ? 0 : _ref$min,
|
|
5957
|
+
_ref$precision = _ref.precision,
|
|
5958
|
+
precision = _ref$precision === void 0 ? 0 : _ref$precision,
|
|
5959
|
+
_ref$stepSize = _ref.stepSize,
|
|
5960
|
+
stepSize = _ref$stepSize === void 0 ? 1 : _ref$stepSize,
|
|
5961
|
+
allOtherProps = _objectWithoutPropertiesLoose(_ref, _excluded$8);
|
|
5962
|
+
|
|
5963
|
+
var _useTextField = useTextField(_extends({}, allOtherProps, {
|
|
5964
|
+
ref: ref
|
|
5965
|
+
})),
|
|
5966
|
+
inputProps = _useTextField.inputProps,
|
|
5967
|
+
fieldProps = _useTextField.fieldProps;
|
|
5968
|
+
|
|
5969
|
+
var inputMode = precision > 0 ? 'decimal' : 'numeric';
|
|
5970
|
+
|
|
5971
|
+
var decimalDigitsCount = function decimalDigitsCount(input) {
|
|
5972
|
+
var decimalIndex = input.indexOf('.');
|
|
5973
|
+
return decimalIndex === -1 ? 0 : input.length - decimalIndex - 1;
|
|
5974
|
+
};
|
|
5975
|
+
|
|
5976
|
+
var inputIsValid = function inputIsValid(valueAsString) {
|
|
5977
|
+
if (valueAsString.startsWith('00')) {
|
|
5978
|
+
return false;
|
|
5979
|
+
}
|
|
5980
|
+
|
|
5981
|
+
if (valueAsString === '-' || valueAsString === '.') {
|
|
5982
|
+
return true;
|
|
5983
|
+
}
|
|
5984
|
+
|
|
5985
|
+
if (valueAsString.indexOf('-') > 0) {
|
|
5986
|
+
return false;
|
|
5987
|
+
}
|
|
5988
|
+
|
|
5989
|
+
return decimalDigitsCount(valueAsString) <= precision;
|
|
5990
|
+
};
|
|
5991
|
+
|
|
5992
|
+
var keyPressIsValid = function keyPressIsValid(keyPress, value) {
|
|
5993
|
+
if (keyPress == 'e' || keyPress == '+' || keyPress == '-' && min >= 0) {
|
|
5994
|
+
return false;
|
|
5995
|
+
}
|
|
5996
|
+
|
|
5997
|
+
if (keyPress == '.' && (precision == 0 || Number(value) == max)) {
|
|
5998
|
+
return false;
|
|
5999
|
+
}
|
|
6000
|
+
|
|
6001
|
+
return true;
|
|
6002
|
+
};
|
|
6003
|
+
|
|
6004
|
+
return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(AffixContainer, {
|
|
6005
|
+
suffix: '%'
|
|
6006
|
+
}, React__default.createElement("input", Object.assign({}, inputProps, {
|
|
6007
|
+
type: 'number',
|
|
6008
|
+
inputMode: inputMode,
|
|
6009
|
+
step: stepSize,
|
|
6010
|
+
max: max,
|
|
6011
|
+
min: min,
|
|
6012
|
+
onKeyDown: function onKeyDown(e) {
|
|
6013
|
+
var value = e.currentTarget.value + e.key;
|
|
6014
|
+
|
|
6015
|
+
if (e.key.length === 1 && (!keyPressIsValid(e.key, value) || !inputIsValid(value))) {
|
|
6016
|
+
e.preventDefault();
|
|
6017
|
+
return;
|
|
6018
|
+
}
|
|
6019
|
+
|
|
6020
|
+
inputProps.onKeyDown(e);
|
|
6021
|
+
},
|
|
6022
|
+
onChange: function onChange(e) {
|
|
6023
|
+
var number = Number(e.target.value);
|
|
6024
|
+
|
|
6025
|
+
if (number > max) {
|
|
6026
|
+
e.target.value = String(max);
|
|
6027
|
+
}
|
|
6028
|
+
|
|
6029
|
+
if (number < min) {
|
|
6030
|
+
e.target.value = String(min);
|
|
6031
|
+
}
|
|
6032
|
+
|
|
6033
|
+
inputProps.onChange(e);
|
|
6034
|
+
inputProps.onBlur(e);
|
|
6035
|
+
}
|
|
6036
|
+
}))));
|
|
6037
|
+
};
|
|
6038
|
+
|
|
6039
|
+
var PercentageField = React.forwardRef(PercentageElement);
|
|
6040
|
+
|
|
5912
6041
|
var styles$u = {"caption":"_1QDLF","label":"_2wiMV","toggle":"_1ui8X","toggle__label":"_1YRJT","toggle__caption":"_1jEiW","toggle__switch":"_3tNyE"};
|
|
5913
6042
|
|
|
5914
6043
|
var Toggle = function Toggle(_ref) {
|
|
@@ -6082,7 +6211,7 @@ var FooterContainer = function FooterContainer(_ref2) {
|
|
|
6082
6211
|
|
|
6083
6212
|
var styles$z = {"badge":"_2f81N","badge--warning":"_2g1GI","badge--danger":"_2zLnM","badge--success":"_27QOo","badge--info":"_2gmsM"};
|
|
6084
6213
|
|
|
6085
|
-
var _excluded$
|
|
6214
|
+
var _excluded$9 = ["children", "theme", "title"];
|
|
6086
6215
|
|
|
6087
6216
|
var Badge = function Badge(_ref, forwardedRef) {
|
|
6088
6217
|
var _classnames;
|
|
@@ -6090,7 +6219,7 @@ var Badge = function Badge(_ref, forwardedRef) {
|
|
|
6090
6219
|
var children = _ref.children,
|
|
6091
6220
|
theme = _ref.theme,
|
|
6092
6221
|
title = _ref.title,
|
|
6093
|
-
otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
6222
|
+
otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$9);
|
|
6094
6223
|
|
|
6095
6224
|
var internalRef = React.useRef(null);
|
|
6096
6225
|
var ref = forwardedRef || internalRef;
|
|
@@ -6225,6 +6354,7 @@ exports.Avatar = Avatar;
|
|
|
6225
6354
|
exports.Badge = Badge$1;
|
|
6226
6355
|
exports.Button = Button$1;
|
|
6227
6356
|
exports.CheckboxField = CheckboxField;
|
|
6357
|
+
exports.CurrencyField = CurrencyField;
|
|
6228
6358
|
exports.DataTable = DataTable;
|
|
6229
6359
|
exports.DataTableCell = DataTableCell;
|
|
6230
6360
|
exports.DataTableEditableCell = DataTableEditableCell;
|
|
@@ -6364,6 +6494,7 @@ exports.ModalFooter = ModalFooter;
|
|
|
6364
6494
|
exports.MultiSelectField = MultiSelectField;
|
|
6365
6495
|
exports.PaginationControls = PaginationControls;
|
|
6366
6496
|
exports.PasswordField = PasswordField;
|
|
6497
|
+
exports.PercentageField = PercentageField;
|
|
6367
6498
|
exports.PillSelectField = PillSelectField;
|
|
6368
6499
|
exports.RadioGroupField = RadioGroupField;
|
|
6369
6500
|
exports.RadioGroupOption = RadioGroupOption;
|