@app-studio/web 0.3.57 → 0.3.59

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/web.esm.js CHANGED
@@ -1,7 +1,8 @@
1
- import React, { useState, useEffect, useRef, useMemo, useCallback, Fragment } from 'react';
2
- import { View as View$1, Element, useTheme, Typography, Input, Image } from 'app-studio';
1
+ import React, { useState, useEffect, useRef, useMemo, useCallback, createContext, useContext, Fragment } from 'react';
2
+ import { View as View$1, Element, useTheme, Typography, Input, Form, Image } from 'app-studio';
3
3
  import { Link as Link$1 } from 'react-router-dom';
4
4
  import format from 'date-fns/format';
5
+ import { useFormikContext } from 'formik';
5
6
  import { create } from 'zustand';
6
7
 
7
8
  var useButtonState = function useButtonState() {
@@ -4110,7 +4111,7 @@ var SliderPadding = {
4110
4111
  }
4111
4112
  };
4112
4113
 
4113
- var _excluded$s = ["id", "name", "inActiveChild", "activeChild", "shadow", "size", "colorScheme", "on", "isHovered", "isChecked", "isDisabled", "isReadOnly", "onChange", "onValueChange", "setOn", "setIsHovered", "styles"];
4114
+ var _excluded$s = ["id", "name", "inActiveChild", "activeChild", "shadow", "size", "colorScheme", "value", "isHovered", "isDisabled", "isReadOnly", "onChange", "setValue", "setIsHovered", "styles"];
4114
4115
  var SwitchContent = function SwitchContent(props) {
4115
4116
  return React.createElement(Input, Object.assign({
4116
4117
  type: "checkbox"
@@ -4127,8 +4128,8 @@ var SwitchView = function SwitchView(_ref) {
4127
4128
  size = _ref$size === void 0 ? 'sm' : _ref$size,
4128
4129
  _ref$colorScheme = _ref.colorScheme,
4129
4130
  colorScheme = _ref$colorScheme === void 0 ? 'theme.primary' : _ref$colorScheme,
4130
- _ref$on = _ref.on,
4131
- on = _ref$on === void 0 ? false : _ref$on,
4131
+ _ref$value = _ref.value,
4132
+ value = _ref$value === void 0 ? false : _ref$value,
4132
4133
  _ref$isHovered = _ref.isHovered,
4133
4134
  isHovered = _ref$isHovered === void 0 ? false : _ref$isHovered,
4134
4135
  _ref$isDisabled = _ref.isDisabled,
@@ -4136,9 +4137,8 @@ var SwitchView = function SwitchView(_ref) {
4136
4137
  _ref$isReadOnly = _ref.isReadOnly,
4137
4138
  isReadOnly = _ref$isReadOnly === void 0 ? false : _ref$isReadOnly,
4138
4139
  onChange = _ref.onChange,
4139
- onValueChange = _ref.onValueChange,
4140
- _ref$setOn = _ref.setOn,
4141
- setOn = _ref$setOn === void 0 ? function () {} : _ref$setOn,
4140
+ _ref$setValue = _ref.setValue,
4141
+ setValue = _ref$setValue === void 0 ? function () {} : _ref$setValue,
4142
4142
  _ref$setIsHovered = _ref.setIsHovered,
4143
4143
  setIsHovered = _ref$setIsHovered === void 0 ? function () {} : _ref$setIsHovered,
4144
4144
  _ref$styles = _ref.styles,
@@ -4149,7 +4149,7 @@ var SwitchView = function SwitchView(_ref) {
4149
4149
  props = _objectWithoutPropertiesLoose(_ref, _excluded$s);
4150
4150
  var handleToggle = function handleToggle(event) {
4151
4151
  if (!isReadOnly) {
4152
- setOn(!on);
4152
+ setValue(!value);
4153
4153
  if (onChange) onChange(event.target.checked);
4154
4154
  }
4155
4155
  };
@@ -4166,26 +4166,24 @@ var SwitchView = function SwitchView(_ref) {
4166
4166
  opacity: 0,
4167
4167
  width: 0,
4168
4168
  height: 0,
4169
- checked: on,
4169
+ checked: value,
4170
4170
  onChange: handleToggle,
4171
4171
  disabled: isDisabled,
4172
4172
  readOnly: isReadOnly
4173
- }, onValueChange && {
4174
- onValueChange: handleToggle
4175
4173
  }, props)), React.createElement(View, Object.assign({
4176
4174
  display: "flex",
4177
4175
  cursor: "pointer",
4178
4176
  alignItems: "center",
4179
4177
  borderRadius: 24,
4180
4178
  marginBottom: 5,
4181
- filter: isHovered && on ? 'brightness(0.9)' : 'brightness(1)',
4179
+ filter: isHovered && value ? 'brightness(0.9)' : 'brightness(1)',
4182
4180
  transition: "justify-content 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
4183
- backgroundColor: isDisabled ? 'disabled' : on ? colorScheme : 'lightgray',
4184
- justifyContent: activeChild ? 'space-between' : on ? 'flex-end' : 'flex-start'
4185
- }, shadow, SliderPadding[size], SliderSizes[size], styles['slider']), activeChild && on && React.createElement(View, null, activeChild), React.createElement(View, Object.assign({
4181
+ backgroundColor: isDisabled ? 'disabled' : value ? colorScheme : 'lightgray',
4182
+ justifyContent: activeChild ? 'space-between' : value ? 'flex-end' : 'flex-start'
4183
+ }, shadow, SliderPadding[size], SliderSizes[size], styles['slider']), activeChild && value && React.createElement(View, null, activeChild), React.createElement(View, Object.assign({
4186
4184
  borderRadius: "50%",
4187
4185
  backgroundColor: "white"
4188
- }, KnobSizes[size], styles['circle'])), inActiveChild && !on && React.createElement(View, null, inActiveChild)));
4186
+ }, KnobSizes[size], styles['circle'])), inActiveChild && !value && React.createElement(View, null, inActiveChild)));
4189
4187
  };
4190
4188
 
4191
4189
  var SwitchComponent = function SwitchComponent(props) {
@@ -4385,6 +4383,254 @@ var TextFieldComponent = function TextFieldComponent(props) {
4385
4383
  */
4386
4384
  var TextField = TextFieldComponent;
4387
4385
 
4386
+ var FocusContext = /*#__PURE__*/createContext({
4387
+ active: false,
4388
+ focusNextInput: function focusNextInput() {},
4389
+ setInputRef: function setInputRef() {},
4390
+ handleSubmitEditing: function handleSubmitEditing() {},
4391
+ getReturnKeyType: function getReturnKeyType() {
4392
+ return 'next';
4393
+ }
4394
+ });
4395
+ var useFormFocus = function useFormFocus() {
4396
+ return useContext(FocusContext);
4397
+ };
4398
+ var FormikForm = function FormikForm(_ref) {
4399
+ var children = _ref.children,
4400
+ _ref$autoFocus = _ref.autoFocus,
4401
+ autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
4402
+ initFocus = _ref.initFocus;
4403
+ var formik = useFormikContext();
4404
+ var inputRefs = useRef({});
4405
+ var inputNames = useRef([]);
4406
+ var setInputRef = function setInputRef(name, ref) {
4407
+ inputRefs.current[name] = ref;
4408
+ if (!inputNames.current.includes(name)) {
4409
+ inputNames.current.push(name);
4410
+ }
4411
+ };
4412
+ var focusNextInput = function focusNextInput(currentName) {
4413
+ if (autoFocus) {
4414
+ var currentIndex = inputNames.current.indexOf(currentName);
4415
+ var nextIndex = currentIndex + 1;
4416
+ if (nextIndex < inputNames.current.length) {
4417
+ var _inputRefs$current$in;
4418
+ (_inputRefs$current$in = inputRefs.current[inputNames.current[nextIndex]]) == null || _inputRefs$current$in.focus();
4419
+ } else if (formik.onSubmit) {
4420
+ formik.onSubmit(formik.values);
4421
+ }
4422
+ }
4423
+ };
4424
+ var contextValue = {
4425
+ active: autoFocus,
4426
+ focusNextInput: focusNextInput,
4427
+ setInputRef: setInputRef,
4428
+ handleSubmitEditing: focusNextInput,
4429
+ getReturnKeyType: function getReturnKeyType(name) {
4430
+ return inputNames.current.indexOf(name) === inputNames.current.length - 1 ? 'done' : 'next';
4431
+ }
4432
+ };
4433
+ useEffect(function () {
4434
+ if (autoFocus) {
4435
+ if (initFocus && inputRefs.current[initFocus]) {
4436
+ var _inputRefs$current$in2;
4437
+ (_inputRefs$current$in2 = inputRefs.current[initFocus]) == null || _inputRefs$current$in2.focus();
4438
+ } else if (inputNames.current[0]) {
4439
+ var _inputRefs$current$in3;
4440
+ (_inputRefs$current$in3 = inputRefs.current[inputNames.current[0]]) == null || _inputRefs$current$in3.focus();
4441
+ }
4442
+ }
4443
+ }, [autoFocus, initFocus]);
4444
+ return React.createElement(FocusContext.Provider, {
4445
+ value: contextValue
4446
+ }, React.createElement(Form, null, children));
4447
+ };
4448
+
4449
+ var _excluded$u = ["name", "type"];
4450
+ var getInputTypeProps = function getInputTypeProps(type) {
4451
+ switch (type) {
4452
+ case 'email':
4453
+ return {
4454
+ autoCorrect: 'off',
4455
+ keyboardType: 'email-address',
4456
+ autoCapitalize: 'none'
4457
+ };
4458
+ case 'password':
4459
+ return {
4460
+ autoCorrect: 'off',
4461
+ secureTextEntry: true,
4462
+ autoCapitalize: 'none'
4463
+ };
4464
+ case 'digits':
4465
+ return {
4466
+ keyboardType: 'phone-pad'
4467
+ };
4468
+ case 'name':
4469
+ return {
4470
+ autoCorrect: 'off'
4471
+ };
4472
+ default:
4473
+ return {};
4474
+ }
4475
+ };
4476
+ var useFormikInput = function useFormikInput(_ref) {
4477
+ var name = _ref.name,
4478
+ type = _ref.type,
4479
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$u);
4480
+ var focus = useFormFocus();
4481
+ var _useFormikContext = useFormikContext(),
4482
+ touched = _useFormikContext.touched,
4483
+ errors = _useFormikContext.errors,
4484
+ submitCount = _useFormikContext.submitCount,
4485
+ values = _useFormikContext.values,
4486
+ setFieldTouched = _useFormikContext.setFieldTouched,
4487
+ setFieldValue = _useFormikContext.setFieldValue;
4488
+ var error = touched[name] || submitCount > 0 ? errors[name] : undefined;
4489
+ var onChangeText = function onChangeText(text) {
4490
+ setFieldValue(name, text);
4491
+ props.onChangeText == null || props.onChangeText(text);
4492
+ };
4493
+ var onChange = function onChange(value) {
4494
+ setFieldValue(name, value);
4495
+ props.onChange == null || props.onChange(value);
4496
+ };
4497
+ var handleBlur = function handleBlur() {
4498
+ setFieldTouched(name, true);
4499
+ // if(props.onBlur)props.onBlur();
4500
+ };
4501
+
4502
+ var handleKeyPress = function handleKeyPress(e) {
4503
+ if (e.key === 'Enter') {
4504
+ e.preventDefault();
4505
+ focus.focusNextInput(name);
4506
+ }
4507
+ };
4508
+ var isText = ['text', 'password', 'email', 'digits'].includes(type);
4509
+ return _extends({}, getInputTypeProps(type), props, {
4510
+ value: values[name],
4511
+ error: error,
4512
+ onBlur: handleBlur,
4513
+ onKeyPress: handleKeyPress
4514
+ }, isText ? {
4515
+ onChangeText: onChangeText
4516
+ } : {
4517
+ onChange: onChange
4518
+ }, focus.active ? {
4519
+ handleKeyPress: handleKeyPress
4520
+ } : {});
4521
+ };
4522
+ // import FormPicker from 'src/Picker/Picker';
4523
+ // import FormRater from 'src/Rate/Rate';
4524
+ // import Upload from 'src/Upload/Upload';
4525
+
4526
+ var _excluded$v = ["value"];
4527
+ var CheckboxComponent$1 = function CheckboxComponent(props) {
4528
+ var _useFormikInput = useFormikInput(props),
4529
+ value = _useFormikInput.value,
4530
+ formProps = _objectWithoutPropertiesLoose(_useFormikInput, _excluded$v);
4531
+ formProps.isChecked = value;
4532
+ var checkboxStates = useCheckboxState(props);
4533
+ return React.createElement(CheckboxView, Object.assign({}, checkboxStates, formProps));
4534
+ };
4535
+ /**
4536
+ * Checkbox allows users to select one or more options from a list of choices.
4537
+ */
4538
+ var FormikCheckbox = CheckboxComponent$1;
4539
+
4540
+ var DatePickerComponent$1 = function DatePickerComponent(props) {
4541
+ var formProps = useFormikInput(props);
4542
+ var datePickerStates = useDatePickerState();
4543
+ return React.createElement(DatePickerView, Object.assign({}, datePickerStates, formProps));
4544
+ };
4545
+ /**
4546
+ * Date picker allows users to select a date from a calendar view.
4547
+ */
4548
+ var FormikDatePicker = DatePickerComponent$1;
4549
+
4550
+ var CountryPickerComponent$1 = function CountryPickerComponent(props) {
4551
+ var formProps = useFormikInput(props);
4552
+ var countryPickerStates = useCountryPickerState(props);
4553
+ return React.createElement(CountryPickerView, Object.assign({}, countryPickerStates, formProps));
4554
+ };
4555
+ /**
4556
+ * Country picker allows users to select a country from a dropdown list or search field.
4557
+ */
4558
+ var FormikCountryPicker = CountryPickerComponent$1;
4559
+
4560
+ var SelectComponent$1 = function SelectComponent(props) {
4561
+ var formProps = useFormikInput(props);
4562
+ formProps.selected = formProps.value;
4563
+ var selectStates = useSelectState(props);
4564
+ return React.createElement(SelectView, Object.assign({}, selectStates, formProps));
4565
+ };
4566
+ /**
4567
+ * Select provides a dropdown list of options for the user to choose from.
4568
+ */
4569
+ var FormikSelect = SelectComponent$1;
4570
+
4571
+ var SwitchComponent$1 = function SwitchComponent(props) {
4572
+ var formProps = useFormikInput(props);
4573
+ var switchStates = useSwitchState(props);
4574
+ return React.createElement(SwitchView, Object.assign({}, switchStates, formProps));
4575
+ };
4576
+ var FormikSwitch = SwitchComponent$1;
4577
+
4578
+ var TextAreaComponent$1 = function TextAreaComponent(props) {
4579
+ var formProps = useFormikInput(props);
4580
+ var textAreaState = useTextAreaState(props);
4581
+ return React.createElement(TextAreaView, Object.assign({}, textAreaState, formProps));
4582
+ };
4583
+ /**
4584
+ * Text Area is an component used to create a multi-line input field.
4585
+ */
4586
+ var FormikTextArea = TextAreaComponent$1;
4587
+
4588
+ var _excluded$w = ["value"];
4589
+ var TextFieldComponent$1 = function TextFieldComponent(props) {
4590
+ var formProps = useFormikInput(props);
4591
+ var _useTextFieldState = useTextFieldState(props),
4592
+ textFieldStates = _objectWithoutPropertiesLoose(_useTextFieldState, _excluded$w);
4593
+ return React.createElement(TextFieldView, Object.assign({}, textFieldStates, formProps));
4594
+ };
4595
+ /**
4596
+ * TextField is used to capture text data from users.
4597
+ */
4598
+ var FormikTextField = TextFieldComponent$1;
4599
+
4600
+ var _excluded$x = ["visibleIcon", "hiddenIcon"],
4601
+ _excluded2$3 = ["isVisible", "setIsVisible"];
4602
+ var PasswordComponent$1 = function PasswordComponent(_ref) {
4603
+ var _ref$visibleIcon = _ref.visibleIcon,
4604
+ visibleIcon = _ref$visibleIcon === void 0 ? React.createElement(OpenEyeSvg, {
4605
+ size: 14
4606
+ }) : _ref$visibleIcon,
4607
+ _ref$hiddenIcon = _ref.hiddenIcon,
4608
+ hiddenIcon = _ref$hiddenIcon === void 0 ? React.createElement(CloseEyeSvg, {
4609
+ size: 14
4610
+ }) : _ref$hiddenIcon,
4611
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$x);
4612
+ var formProps = useFormikInput(props);
4613
+ var _usePasswordState = usePasswordState(formProps),
4614
+ isVisible = _usePasswordState.isVisible,
4615
+ setIsVisible = _usePasswordState.setIsVisible,
4616
+ passwordProps = _objectWithoutPropertiesLoose(_usePasswordState, _excluded2$3);
4617
+ return React.createElement(TextFieldView, Object.assign({}, passwordProps, {
4618
+ type: isVisible ? 'text' : 'password',
4619
+ isClearable: false,
4620
+ rightChild: React.createElement(View$1, {
4621
+ onClick: function onClick() {
4622
+ if (!props.isDisabled) {
4623
+ setIsVisible(!isVisible);
4624
+ }
4625
+ }
4626
+ }, isVisible ? visibleIcon : hiddenIcon)
4627
+ }));
4628
+ };
4629
+ /**
4630
+ * To allow users to securely enter sensitive information
4631
+ */
4632
+ var FormikPassword = PasswordComponent$1;
4633
+
4388
4634
  var useModalStore = /*#__PURE__*/create(function (set) {
4389
4635
  return {
4390
4636
  modal: false,
@@ -4470,8 +4716,8 @@ var HeaderIconSizes = {
4470
4716
  xl: 28
4471
4717
  };
4472
4718
 
4473
- var _excluded$u = ["children", "blur", "isOpen", "isClosePrevented", "onClose", "position"],
4474
- _excluded2$3 = ["children", "shadow", "isFullScreen", "shape"],
4719
+ var _excluded$y = ["children", "blur", "isOpen", "isClosePrevented", "onClose", "position"],
4720
+ _excluded2$4 = ["children", "shadow", "isFullScreen", "shape"],
4475
4721
  _excluded3$2 = ["children", "buttonColor", "iconSize", "buttonPosition"],
4476
4722
  _excluded4$2 = ["children"],
4477
4723
  _excluded5 = ["children"];
@@ -4486,7 +4732,7 @@ var ModalOverlay = function ModalOverlay(_ref) {
4486
4732
  onClose = _ref$onClose === void 0 ? function () {} : _ref$onClose,
4487
4733
  _ref$position = _ref.position,
4488
4734
  position = _ref$position === void 0 ? 'center' : _ref$position,
4489
- props = _objectWithoutPropertiesLoose(_ref, _excluded$u);
4735
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$y);
4490
4736
  var handleClick = function handleClick() {
4491
4737
  if (!isClosePrevented) onClose();
4492
4738
  };
@@ -4519,7 +4765,7 @@ var ModalContainer = function ModalContainer(_ref2) {
4519
4765
  isFullScreen = _ref2$isFullScreen === void 0 ? false : _ref2$isFullScreen,
4520
4766
  _ref2$shape = _ref2.shape,
4521
4767
  shape = _ref2$shape === void 0 ? 'rounded' : _ref2$shape,
4522
- props = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
4768
+ props = _objectWithoutPropertiesLoose(_ref2, _excluded2$4);
4523
4769
  var defaultShadow = typeof document !== undefined ? {
4524
4770
  boxShadow: '0px 2px 8px rgba(0, 0, 0, 0.3)'
4525
4771
  } : {
@@ -4642,12 +4888,12 @@ Modal.Body = ModalBody;
4642
4888
  Modal.Footer = ModalFooter;
4643
4889
  Modal.Layout = ModalLayout;
4644
4890
 
4645
- var _excluded$v = ["src", "color"],
4646
- _excluded2$4 = ["path"];
4891
+ var _excluded$z = ["src", "color"],
4892
+ _excluded2$5 = ["path"];
4647
4893
  var FileSVG = function FileSVG(_ref) {
4648
4894
  var src = _ref.src,
4649
4895
  color = _ref.color,
4650
- props = _objectWithoutPropertiesLoose(_ref, _excluded$v);
4896
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$z);
4651
4897
  var _useTheme = useTheme(),
4652
4898
  getColor = _useTheme.getColor;
4653
4899
  var Colorprops = color ? {
@@ -4662,11 +4908,11 @@ var FileSVG = function FileSVG(_ref) {
4662
4908
  };
4663
4909
  var FileImage = function FileImage(_ref2) {
4664
4910
  var path = _ref2.path,
4665
- props = _objectWithoutPropertiesLoose(_ref2, _excluded2$4);
4911
+ props = _objectWithoutPropertiesLoose(_ref2, _excluded2$5);
4666
4912
  return React.createElement(Image, Object.assign({
4667
4913
  src: path
4668
4914
  }, props));
4669
4915
  };
4670
4916
 
4671
- export { Bottom, Button, Center, Checkbox, CountryPicker, DatePicker, FileImage, FileSVG, Horizontal, Inline, Left, Link, Loader, Modal, Password, Right, Select, Switch, Text, TextArea, TextField, Top, Vertical, View, hideModal, showModal, useModalStore };
4917
+ export { Bottom, Button, Center, Checkbox, CountryPicker, DatePicker, FileImage, FileSVG, FormikCheckbox, FormikCountryPicker, FormikDatePicker, FormikForm, FormikPassword, FormikSelect, FormikSwitch, FormikTextArea, FormikTextField, Horizontal, Inline, Left, Link, Loader, Modal, Password, Right, Select, Switch, Text, TextArea, TextField, Top, Vertical, View, hideModal, showModal, useModalStore };
4672
4918
  //# sourceMappingURL=web.esm.js.map