@7shifts/sous-chef 2.1.2 → 2.2.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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  declare type AutoCompleteType = 'off' | 'on';
3
- declare type Props = {
3
+ export declare type Props = {
4
4
  autoComplete?: AutoCompleteType;
5
5
  autoFocus?: boolean;
6
6
  caption?: React.ReactNode;
@@ -0,0 +1,38 @@
1
+ /// <reference types="react" />
2
+ import { RefType } from '../../utils/types';
3
+ import type { Props } from './TextField';
4
+ declare type UseTextFieldProps = Props & {
5
+ ref: RefType<HTMLInputElement>;
6
+ };
7
+ export declare const useTextField: ({ autoComplete, autoFocus, defaultValue, disabled, error, id, maxLength, name, caption, label, onBlur, onChange, onFocus, onKeyDown, placeholder, value, ref }: UseTextFieldProps) => {
8
+ inputProps: {
9
+ 'aria-describedby': string;
10
+ 'aria-invalid': boolean;
11
+ autoComplete: "on" | "off" | undefined;
12
+ autoFocus: boolean | undefined;
13
+ className: string;
14
+ 'data-testid': string;
15
+ disabled: boolean | undefined;
16
+ defaultValue: string | undefined;
17
+ id: string;
18
+ maxLength: number | undefined;
19
+ name: string;
20
+ onBlur: (e: import("react").ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
21
+ onChange: (e: import("react").ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
22
+ onFocus: (e: import("react").FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
23
+ onKeyDown: (e: import("react").KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
24
+ placeholder: string | undefined;
25
+ ref: RefType<HTMLInputElement>;
26
+ size: number;
27
+ type: string;
28
+ value: string | undefined;
29
+ };
30
+ fieldProps: {
31
+ caption: import("react").ReactNode;
32
+ error: string | undefined;
33
+ label: import("react").ReactNode;
34
+ id: string;
35
+ name: string;
36
+ };
37
+ };
38
+ export {};
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import type { Props as TextFieldProps } from '../TextField/TextField';
3
+ /**
4
+ * `TimeField` are 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 TimeField: React.ForwardRefExoticComponent<Pick<TextFieldProps, "disabled" | "id" | "caption" | "label" | "error" | "onChange" | "name" | "value" | "onBlur" | "placeholder" | "autoFocus" | "onFocus" | "onKeyDown" | "defaultValue" | "autoComplete" | "maxLength"> & React.RefAttributes<HTMLInputElement>>;
9
+ export default TimeField;
@@ -0,0 +1 @@
1
+ export { default } from './TimeField';
@@ -12,7 +12,8 @@ import SelectField from './SelectField';
12
12
  import DateField from './DateField';
13
13
  import DateRangeField from './DateRangeField';
14
14
  import WeekField from './WeekField';
15
- export { Form, FormRow, TextAreaField, TextField, CheckboxField, PillSelectField, RadioGroupField, RadioGroupOption, PasswordField, MultiSelectField, SelectField, DateField, DateRangeField, WeekField, SIZE_25_PERCENT, SIZE_33_PERCENT, SIZE_50_PERCENT, SIZE_66_PERCENT, SIZE_75_PERCENT };
15
+ import TimeField from './TimeField';
16
+ export { Form, FormRow, TextAreaField, TextField, CheckboxField, PillSelectField, RadioGroupField, RadioGroupOption, PasswordField, MultiSelectField, SelectField, DateField, DateRangeField, WeekField, TimeField, SIZE_25_PERCENT, SIZE_33_PERCENT, SIZE_50_PERCENT, SIZE_66_PERCENT, SIZE_75_PERCENT };
16
17
  export type { PasswordCriteria } from './PasswordField/types';
17
18
  export type { SelectOption, SelectOptions } from './SelectField/types';
18
19
  export type { FormikType } from './Form/types';
package/dist/index.css CHANGED
@@ -1571,6 +1571,7 @@ Please ask a designer if you have questions about which colours to use.
1571
1571
  ._1Sc9D {
1572
1572
  padding-top: 8px;
1573
1573
  padding-bottom: 6px;
1574
+ width: 100%;
1574
1575
  }
1575
1576
  /*********************************
1576
1577
  For new colours, see _colors.scss.
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ var dateFnsFormat = _interopDefault(require('date-fns/format'));
12
12
  var dateFnsParse = _interopDefault(require('date-fns/parse'));
13
13
  var startOfDay = _interopDefault(require('date-fns/startOfDay'));
14
14
  var eachDayOfInterval = _interopDefault(require('date-fns/eachDayOfInterval'));
15
+ var parseTime = _interopDefault(require('time-autocomplete/src/core/AMPMParser'));
15
16
  var ReactModal = _interopDefault(require('react-modal'));
16
17
 
17
18
  function _extends() {
@@ -3907,30 +3908,29 @@ var TextAreaField = function TextAreaField(_ref) {
3907
3908
 
3908
3909
  var styles$j = {"text-field":"_20YOA","text-field--invalid":"_3kUSh","text-field--prefixed":"_3IU3Q","text-field--suffixed":"_QXJOD"};
3909
3910
 
3910
- var TextFieldElement = function TextFieldElement(_ref, ref) {
3911
+ var useTextField = function useTextField(_ref) {
3911
3912
  var _classnames;
3912
3913
 
3913
3914
  var autoComplete = _ref.autoComplete,
3914
3915
  autoFocus = _ref.autoFocus,
3915
- caption = _ref.caption,
3916
3916
  defaultValue = _ref.defaultValue,
3917
3917
  disabled = _ref.disabled,
3918
3918
  error = _ref.error,
3919
- inputId = _ref.id,
3920
- label = _ref.label,
3919
+ id = _ref.id,
3921
3920
  maxLength = _ref.maxLength,
3922
3921
  name = _ref.name,
3922
+ caption = _ref.caption,
3923
+ label = _ref.label,
3923
3924
  onBlur = _ref.onBlur,
3924
3925
  onChange = _ref.onChange,
3925
3926
  onFocus = _ref.onFocus,
3926
3927
  onKeyDown = _ref.onKeyDown,
3927
3928
  placeholder = _ref.placeholder,
3928
- prefix = _ref.prefix,
3929
- suffix = _ref.suffix,
3930
- value = _ref.value;
3929
+ value = _ref.value,
3930
+ ref = _ref.ref;
3931
3931
  var controllers = useFieldControllers({
3932
3932
  error: error,
3933
- id: inputId,
3933
+ id: id,
3934
3934
  name: name,
3935
3935
  onChange: onChange,
3936
3936
  onBlur: onBlur,
@@ -3939,23 +3939,13 @@ var TextFieldElement = function TextFieldElement(_ref, ref) {
3939
3939
  value: value
3940
3940
  });
3941
3941
  var hasError = !!controllers.error;
3942
- var fieldProps = {
3943
- caption: caption,
3944
- error: controllers.error,
3945
- label: label,
3946
- id: controllers.id,
3947
- name: name
3948
- };
3949
- return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(AffixContainer, {
3950
- prefix: prefix,
3951
- suffix: suffix
3952
- }, React__default.createElement("input", {
3953
- "aria-describedby": hasError ? controllers.id + "-error-message" : controllers.id + "-describer",
3954
- "aria-invalid": hasError,
3942
+ var inputProps = {
3943
+ 'aria-describedby': hasError ? controllers.id + "-error-message" : controllers.id + "-describer",
3944
+ 'aria-invalid': hasError,
3955
3945
  autoComplete: autoComplete,
3956
3946
  autoFocus: autoFocus,
3957
3947
  className: classnames(styles$j['text-field'], (_classnames = {}, _classnames[styles$j['text-field--invalid']] = hasError, _classnames)),
3958
- "data-testid": "text-field-" + name,
3948
+ 'data-testid': "text-field-" + name,
3959
3949
  disabled: disabled,
3960
3950
  defaultValue: defaultValue,
3961
3951
  id: controllers.id,
@@ -3968,9 +3958,39 @@ var TextFieldElement = function TextFieldElement(_ref, ref) {
3968
3958
  placeholder: placeholder,
3969
3959
  ref: ref,
3970
3960
  size: 1,
3971
- type: "text",
3961
+ type: 'text',
3972
3962
  value: controllers.value
3973
- })));
3963
+ };
3964
+ var fieldProps = {
3965
+ caption: caption,
3966
+ error: controllers.error,
3967
+ label: label,
3968
+ id: inputProps.id,
3969
+ name: name
3970
+ };
3971
+ return {
3972
+ inputProps: inputProps,
3973
+ fieldProps: fieldProps
3974
+ };
3975
+ };
3976
+
3977
+ var _excluded$2 = ["prefix", "suffix"];
3978
+
3979
+ var TextFieldElement = function TextFieldElement(_ref, ref) {
3980
+ var prefix = _ref.prefix,
3981
+ suffix = _ref.suffix,
3982
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3983
+
3984
+ var _useTextField = useTextField(_extends({}, props, {
3985
+ ref: ref
3986
+ })),
3987
+ inputProps = _useTextField.inputProps,
3988
+ fieldProps = _useTextField.fieldProps;
3989
+
3990
+ return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement(AffixContainer, {
3991
+ prefix: prefix,
3992
+ suffix: suffix
3993
+ }, React__default.createElement("input", Object.assign({}, inputProps))));
3974
3994
  };
3975
3995
 
3976
3996
  var TextField = React.forwardRef(TextFieldElement);
@@ -4580,12 +4600,12 @@ var getSelectStyles = function getSelectStyles(_ref) {
4580
4600
  };
4581
4601
  };
4582
4602
 
4583
- var _excluded$2 = ["children", "CustomComponent"];
4603
+ var _excluded$3 = ["children", "CustomComponent"];
4584
4604
 
4585
4605
  function CustomOption(_ref) {
4586
4606
  var children = _ref.children,
4587
4607
  CustomComponent = _ref.CustomComponent,
4588
- props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
4608
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
4589
4609
 
4590
4610
  return React__default.createElement(Select.components.Option, Object.assign({}, props), React__default.createElement(CustomComponent, Object.assign({}, props), children));
4591
4611
  }
@@ -4714,14 +4734,14 @@ var useSelectFieldControllers = function useSelectFieldControllers(_ref) {
4714
4734
 
4715
4735
  var styles$q = {"custom-control":"_1cDCR"};
4716
4736
 
4717
- var _excluded$3 = ["children", "CustomPrefixComponent"];
4737
+ var _excluded$4 = ["children", "CustomPrefixComponent"];
4718
4738
 
4719
4739
  function CustomControl(_ref) {
4720
4740
  var _props$getValue;
4721
4741
 
4722
4742
  var children = _ref.children,
4723
4743
  CustomPrefixComponent = _ref.CustomPrefixComponent,
4724
- props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
4744
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
4725
4745
 
4726
4746
  var selectedOption = (_props$getValue = props.getValue()) === null || _props$getValue === void 0 ? void 0 : _props$getValue[0];
4727
4747
  return React__default.createElement(Select.components.Control, Object.assign({}, props), CustomControl && selectedOption ? React__default.createElement("div", {
@@ -4738,12 +4758,12 @@ function CustomControl(_ref) {
4738
4758
  }, props)), children)) : children);
4739
4759
  }
4740
4760
 
4741
- var _excluded$4 = ["children", "CustomComponent"];
4761
+ var _excluded$5 = ["children", "CustomComponent"];
4742
4762
 
4743
4763
  function CustomOption$1(_ref) {
4744
4764
  var children = _ref.children,
4745
4765
  CustomComponent = _ref.CustomComponent,
4746
- props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
4766
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$5);
4747
4767
 
4748
4768
  return React__default.createElement(Select.components.Option, Object.assign({}, props), React__default.createElement(CustomComponent, Object.assign({}, props), children));
4749
4769
  }
@@ -5413,6 +5433,34 @@ var WeekField = function WeekField(_ref) {
5413
5433
  })));
5414
5434
  };
5415
5435
 
5436
+ var _excluded$6 = ["placeholder", "autoComplete"];
5437
+
5438
+ var TimeFieldElement = function TimeFieldElement(_ref, ref) {
5439
+ var _ref$placeholder = _ref.placeholder,
5440
+ placeholder = _ref$placeholder === void 0 ? '9am' : _ref$placeholder,
5441
+ _ref$autoComplete = _ref.autoComplete,
5442
+ autoComplete = _ref$autoComplete === void 0 ? 'off' : _ref$autoComplete,
5443
+ allOtherProps = _objectWithoutPropertiesLoose(_ref, _excluded$6);
5444
+
5445
+ var _useTextField = useTextField(_extends({}, allOtherProps, {
5446
+ placeholder: placeholder,
5447
+ autoComplete: autoComplete,
5448
+ ref: ref
5449
+ })),
5450
+ inputProps = _useTextField.inputProps,
5451
+ fieldProps = _useTextField.fieldProps;
5452
+
5453
+ return React__default.createElement(Field, Object.assign({}, fieldProps), React__default.createElement("input", Object.assign({}, inputProps, {
5454
+ onBlur: function onBlur(e) {
5455
+ e.target.value = parseTime(e.target.value, 'g:i A');
5456
+ inputProps.onChange(e);
5457
+ inputProps.onBlur(e);
5458
+ }
5459
+ })));
5460
+ };
5461
+
5462
+ var TimeField = React.forwardRef(TimeFieldElement);
5463
+
5416
5464
  var styles$u = {"caption":"_1QDLF","label":"_2wiMV","toggle":"_1ui8X","toggle__label":"_1YRJT","toggle__caption":"_1jEiW","toggle__switch":"_3tNyE"};
5417
5465
 
5418
5466
  var Toggle = function Toggle(_ref) {
@@ -5586,7 +5634,7 @@ var FooterContainer = function FooterContainer(_ref2) {
5586
5634
 
5587
5635
  var styles$z = {"badge":"_2f81N","badge--warning":"_2g1GI","badge--danger":"_2zLnM","badge--success":"_27QOo","badge--info":"_2gmsM"};
5588
5636
 
5589
- var _excluded$5 = ["children", "theme", "title"];
5637
+ var _excluded$7 = ["children", "theme", "title"];
5590
5638
 
5591
5639
  var Badge = function Badge(_ref, forwardedRef) {
5592
5640
  var _classnames;
@@ -5594,7 +5642,7 @@ var Badge = function Badge(_ref, forwardedRef) {
5594
5642
  var children = _ref.children,
5595
5643
  theme = _ref.theme,
5596
5644
  title = _ref.title,
5597
- otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$5);
5645
+ otherProps = _objectWithoutPropertiesLoose(_ref, _excluded$7);
5598
5646
 
5599
5647
  var internalRef = React.useRef(null);
5600
5648
  var ref = forwardedRef || internalRef;
@@ -5877,6 +5925,7 @@ exports.Spinner = Spinner;
5877
5925
  exports.Stack = Stack;
5878
5926
  exports.TextAreaField = TextAreaField;
5879
5927
  exports.TextField = TextField;
5928
+ exports.TimeField = TimeField;
5880
5929
  exports.Toggle = Toggle;
5881
5930
  exports.Tooltip = Tooltip$1;
5882
5931
  exports.WeekField = WeekField;