Skip to content

Feat/date time picker ts #1694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions generatedTypes/src/components/baseInput/Validators.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const validators: {
required: (value: string) => boolean;
email: (value: string) => boolean;
url: (value: string) => boolean;
number: (value: string) => boolean;
price: (value: string) => boolean;
};
export default validators;
29 changes: 29 additions & 0 deletions generatedTypes/src/components/baseInput/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'react';
import { BaseComponent } from '../../commons';
export default class BaseInput extends BaseComponent {
static displayName: string;
static propTypes: any;
static defaultProps: {
validateOnBlur: boolean;
};
constructor(props: any);
componentDidMount(): void;
/** Events */
onFocus: (...args: any[]) => void;
onBlur: (...args: any[]) => void;
onChange: (event: any) => void;
onChangeText: (text: any) => void;
/** Actions */
getTypography(): any;
hasText(): any;
isFocused(): any;
focus(): void;
blur(): void;
clear(): void;
validate: any;
isRequiredField(): boolean;
getRequiredPlaceholder(placeholder: any): any;
getErrorMessage(): any;
getColor(value: string): string;
toggleExpandableModal(...args: any[]): any;
}
121 changes: 121 additions & 0 deletions generatedTypes/src/components/dateTimePicker/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React, { Component } from 'react';
import { StyleProp, ViewStyle } from 'react-native';
import { BaseComponentInjectedProps } from '../../commons/new';
import { DialogProps } from '../dialog';
/**
* @description: Date and Time Picker Component that wraps RNDateTimePicker for date and time modes.
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/DateTimePickerScreen.js
* @important: DateTimePicker uses a native library. You MUST add and link the native library to both iOS and Android projects.
* @extends: TextField, react-native-community/datetimepicker
* @extendsLink: https://github.com/react-native-community/react-native-datetimepicker#react-native-datetimepicker
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/DateTimePicker/DateTimePicker_iOS.gif?raw=true, https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/DateTimePicker/DateTimePicker_Android.gif?raw=true
*/
export interface DateTimePickerProps {
/**
* The type of picker to display ('date' or 'time')
*/
mode?: 'date' | 'time';
/**
* The initial value to set the picker to. Defaults to device's date / time
*/
value?: Date;
/**
* The onChange callback
*/
onChange?: (date: Date) => void;
/**
* The minimum date or time value to use
*/
minimumDate?: Date;
/**
* The maximum date or time value to use
*/
maximumDate?: Date;
/**
* The date format for the text display
*/
dateFormat?: string;
/**
* A callback function to format date
*/
dateFormatter?: (date: Date) => string;
/**
* The time format for the text display
*/
timeFormat?: string;
/**
* A callback function to format time
*/
timeFormatter?: (date: Date) => string;
/**
* Allows changing of the locale of the component (iOS only)
*/
locale?: string;
/**
* Allows changing of the time picker to a 24 hour format (Android only)
*/
is24Hour?: boolean;
/**
* The interval at which minutes can be selected. Possible values are: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 (iOS only)
*/
minuteInterval?: number;
/**
* Allows changing of the timeZone of the date picker. By default it uses the device's time zone (iOS only)
*/
timeZoneOffsetInMinutes?: number;
/**
* Props to pass the Dialog component
*/
dialogProps?: DialogProps;
/**
* style to apply to the iOS dialog header
*/
headerStyle?: StyleProp<ViewStyle>;
/**
* Render custom input
*/
renderInput?: () => React.ReactElement;
/**
* Override system theme variant (dark or light mode) used by the date picker.
*/
themeVariant?: 'light' | 'dark';
/**
* The component testID
*/
testID?: string;
}
interface DateTimePickerState {
showExpandableOverlay: boolean;
prevValue?: Date;
value?: Date;
}
declare type DateTimePickerPropsInternal = DateTimePickerProps & BaseComponentInjectedProps;
declare class DateTimePicker extends Component<DateTimePickerPropsInternal, DateTimePickerState> {
static displayName: string;
static defaultProps: {
mode: string;
enableErrors: boolean;
validateOnBlur: boolean;
};
chosenDate?: Date;
constructor(props: DateTimePickerPropsInternal);
static getDerivedStateFromProps(nextProps: DateTimePickerProps, prevState: DateTimePickerState): {
prevValue: Date | undefined;
value: Date | undefined;
} | null;
handleChange: (event: any, date: Date) => void;
toggleExpandableOverlay: (callback?: (() => void) | undefined) => void;
onToggleExpandableModal: (value: boolean) => void;
onDonePressed: () => void;
getStringValue: () => string | undefined;
renderExpandableOverlay: () => JSX.Element;
renderHeader(): JSX.Element;
renderDateTimePicker(): JSX.Element | null | undefined;
renderExpandable: () => JSX.Element | null | undefined;
render(): JSX.Element;
}
export { DateTimePicker };
declare const _default: React.ComponentClass<{
useCustomTheme?: boolean | undefined;
}, any>;
export default _default;
2 changes: 1 addition & 1 deletion generatedTypes/src/components/dialog/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface DialogProps extends AlignmentModifiers, RNPartialProps {
/**
* The dialog height (default: undefined)
*/
height?: string | number;
height?: string | number | null;
/**
* The direction of the allowed pan (default is DOWN).
* Types: UP, DOWN, LEFT and RIGHT (using PanningProvider.Directions.###).
Expand Down
71 changes: 71 additions & 0 deletions generatedTypes/src/components/textField/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/// <reference types="react" />
import BaseInput from '../baseInput';
/**
* @description: A wrapper for TextInput component with extra functionality like floating placeholder and validations (This is an uncontrolled component)
* @modifiers: Typography
* @extends: TextInput
* @extendsLink: https://reactnative.dev/docs/textinput
* @gif: https://media.giphy.com/media/xULW8su8Cs5Z9Fq4PS/giphy.gif, https://media.giphy.com/media/3ohc1dhDcLS9FvWLJu/giphy.gif, https://media.giphy.com/media/oNUSOxnHdMP5ZnKYsh/giphy.gif
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TextFieldScreen/BasicTextFieldScreen.js
*/
export default class TextField extends BaseInput {
static displayName: string;
static propTypes: any;
static defaultProps: {
enableErrors: boolean;
validateOnBlur: boolean;
};
constructor(props: any);
UNSAFE_componentWillReceiveProps(nextProps: any): void;
componentDidUpdate(_prevProps: any, prevState: any): void;
onPlaceholderLayout: (event: any) => void;
/** Actions */
generatePropsWarnings(props: any): void;
generateStyles(): void;
getAccessibilityInfo(): {
accessibilityLabel: any;
accessibilityState: {
disabled: boolean;
} | undefined;
};
toggleExpandableModal: (value: any) => void;
updateFloatingPlaceholderState: (withoutAnimation: any) => void;
getPlaceholderText: (this: any, placeholder: any, helperText: any) => any;
getStateColor(colorProp?: {}): any;
getCharCount(): any;
setCharCountColor(key: any): void;
getCharCountColor(): any;
getTopPaddings(): 25 | undefined;
getTopErrorsPosition(): {
top: number;
} | undefined;
isDisabled(): boolean;
isCounterLimit(): boolean;
hasText(value: any): boolean;
shouldShowHelperText(): any;
shouldFloatOnFocus(): any;
shouldFloatPlaceholder(text: any): any;
shouldFakePlaceholder(): boolean;
shouldShowError(): any;
getErrorMessage(): any;
shouldShowTopError(): any;
shouldDisplayRightButton(): any;
shouldRenderTitle(): any;
onPressRightButton: () => void;
/** Renders */
renderPlaceholder(): JSX.Element | undefined;
renderPrefix(): JSX.Element | undefined;
renderTitle(): JSX.Element | undefined;
renderCharCounter(): JSX.Element | undefined;
renderError(visible: any): JSX.Element | undefined;
renderExpandableModal(): any;
renderExpandableInput(): any;
renderTextInput(): JSX.Element;
renderRightButton(): JSX.Element | undefined;
renderRightIcon(): JSX.Element | undefined;
render(): JSX.Element;
/** Events */
onDoneEditingExpandableInput: () => void;
onKeyPress: (event: any) => void;
onChangeText: (text: any) => void;
}
18 changes: 0 additions & 18 deletions src/components/baseInput/Validators.js

This file was deleted.

18 changes: 18 additions & 0 deletions src/components/baseInput/Validators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import _ from 'lodash';
import {EmailValidator} from 'commons-validator-js';

const urlRegEx =
/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i; //eslint-disable-line
const decimalNumberRegEx = /^-?\d+[.,]?\d+$/;
const integerRegEx = /^-?\d*$/; // allows empty string
const priceRegEx = /^[0-9]{1,9}([.][0-9]{1,2})?$/;

const validators = {
required: (value: string) => !_.isEmpty(value),
email: (value: string) => new EmailValidator().isValid(value),
url: (value: string) => urlRegEx.test(value),
number: (value: string) => integerRegEx.test(value) || decimalNumberRegEx.test(value),
price: (value: string) => priceRegEx.test(value)
};

export default validators;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import _ from 'lodash';
import PropTypes from 'prop-types';
import 'react';
Expand Down Expand Up @@ -101,11 +102,11 @@ export default class BaseInput extends BaseComponent {
}
};

onChange = (event) => {
onChange = event => {
_.invoke(this.props, 'onChange', event);
};

onChangeText = (text) => {
onChangeText = text => {
_.invoke(this.props, 'onChangeText', text);
this.setState({value: text});

Expand Down Expand Up @@ -147,8 +148,7 @@ export default class BaseInput extends BaseComponent {
if (!validate) {
return;
}



let isValid = true;
const inputValidators = _.isArray(validate) ? validate : [validate];
let failingValidatorIndex;
Expand Down Expand Up @@ -205,7 +205,7 @@ export default class BaseInput extends BaseComponent {

getRequiredPlaceholder(placeholder) {
const {markRequired} = this.getThemeProps();
const shouldDisplayPlaceholderAsRequired = (this.isRequiredField() && markRequired && placeholder);
const shouldDisplayPlaceholderAsRequired = this.isRequiredField() && markRequired && placeholder;

if (shouldDisplayPlaceholderAsRequired) {
return `${placeholder} *`;
Expand All @@ -220,15 +220,16 @@ export default class BaseInput extends BaseComponent {
return propsError || stateError;
}

getColor(value) {
getColor(value: string) {
if (this.state.focused) {
return Colors.grey10;
} else {
return _.isEmpty(value) ? Colors.grey40 : Colors.grey10;
}
}

toggleExpandableModal(...args) {
toggleExpandableModal(...args: any[]) {
// @ts-expect-error
return this.input.toggleExpandableModal(...args);
}
}
Loading