native-pytech 1.0.185 → 1.0.190

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.
@@ -0,0 +1,3 @@
1
+ import type Props from './types';
2
+ declare const _default: import("react").MemoExoticComponent<({ label, selection, minDate, maxDate, onValueChange, }: Props) => import("react").JSX.Element>;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import type Props from './types';
2
+ declare const _default: import("react").MemoExoticComponent<({ label, selection, minDate, maxDate, onValueChange }: Props) => import("react").JSX.Element>;
3
+ export default _default;
@@ -0,0 +1,7 @@
1
+ import { DatePicker } from '@expo/ui/swift-ui';
2
+ import { memo } from 'react';
3
+ import { environment } from '@expo/ui/swift-ui/modifiers';
4
+ export default memo(({ label, selection, minDate, maxDate, onValueChange }) => (<DatePicker title={label} selection={selection} onDateChange={onValueChange} modifiers={[environment('locale', 'es_ES')]} range={{
5
+ start: minDate,
6
+ end: maxDate,
7
+ }}/>));
@@ -0,0 +1,33 @@
1
+ import { memo, useCallback, useRef } from 'react';
2
+ import { Pressable, StyleSheet } from 'react-native';
3
+ import Table from '../../../../../../libs/table';
4
+ import { useApp } from '../../../../../../libs/providers/App';
5
+ import Formats from '../../../../../../libs/constants/formats';
6
+ import Colors from '../../../../../../libs/constants/colors';
7
+ export default memo(({ label, selection, minDate, maxDate, onValueChange, }) => {
8
+ const { colorScheme } = useApp();
9
+ const inputRef = useRef(null);
10
+ const _onValueChange = useCallback((value_str) => {
11
+ const [year, month, day] = value_str.split('-').map(Number);
12
+ const value = new Date(year, month - 1, day);
13
+ onValueChange?.(value);
14
+ }, []);
15
+ return (<Table.Option id={label ?? ''} colorScheme={colorScheme} childrenLeft={<Table.Option.Components.Text text={label ?? 'Seleccione una fecha'}/>} childrenRight={(<>
16
+ <Pressable onPress={() => inputRef.current?.showPicker()} style={[styles.container, { backgroundColor: Colors.especiales.azul }]}>
17
+ <Table.Option.Components.Text text={Formats.dateToTextFormat(selection, 'dd/MM/yyyy')} style={{ color: 'white', userSelect: 'none' }}/>
18
+ <input ref={inputRef} type="date" value={Formats.dateToTextFormat(selection, 'yyyy-MM-dd')} onChange={(e) => _onValueChange(e.target.value)} style={{
19
+ all: 'unset',
20
+ visibility: 'hidden',
21
+ width: 0,
22
+ position: 'absolute'
23
+ }}/>
24
+ </Pressable>
25
+ </>)}/>);
26
+ });
27
+ const styles = StyleSheet.create({
28
+ container: {
29
+ padding: 7,
30
+ paddingHorizontal: 30,
31
+ borderRadius: 20
32
+ },
33
+ });
@@ -0,0 +1,23 @@
1
+ type Props = {
2
+ /**
3
+ Title of the date picker.
4
+ */
5
+ label?: string;
6
+ /**
7
+ Selection of the date picker.
8
+ */
9
+ selection: Date;
10
+ /**
11
+ Minimum date allowed.
12
+ */
13
+ minDate?: Date;
14
+ /**
15
+ Maximum date allowed.
16
+ */
17
+ maxDate?: Date;
18
+ /**
19
+ Callback function to be called when the value changes.
20
+ */
21
+ onValueChange?: (value: Date) => void;
22
+ };
23
+ export default Props;
@@ -1,30 +1,31 @@
1
- import { memo, useCallback, useEffect, useRef, useState } from 'react';
2
- import { Pressable, StyleSheet } from 'react-native';
3
- import Table from '../../../../../libs/table';
4
- import { useApp } from '../../../../../libs/providers/App';
5
- import Formats from '../../../../../libs/constants/formats';
1
+ import { memo, useCallback, useEffect, useRef, useState, useMemo } from 'react';
6
2
  import { usePage } from '../../context/page';
7
- import Colors from '../../../../../libs/constants/colors';
3
+ import Hooks from '../../../../../libs/constants/hooks';
4
+ import DatePicker from './DatePicker';
8
5
  export default memo(({ itemKey, label, selection, defaultValue, minDate, maxDate, onValueChange, }) => {
9
- const { colorScheme } = useApp();
10
6
  const { store, registerItem } = usePage();
11
- const [_selection, setSelection] = useState(selection ?? defaultValue ?? new Date());
12
- const inputRef = useRef(null);
7
+ const [_selection, setSelection] = useState(selection);
8
+ const currentDate = useMemo(() => _selection ?? defaultValue ?? new Date(), [_selection, defaultValue]);
9
+ const currentDateRanged = useMemo(() => {
10
+ if (maxDate && currentDate > maxDate)
11
+ return maxDate;
12
+ if (minDate && currentDate < minDate)
13
+ return minDate;
14
+ return currentDate;
15
+ }, [currentDate, minDate, maxDate]);
13
16
  // Key
14
17
  const keyRef = useRef(itemKey);
15
18
  useEffect(() => {
16
19
  keyRef.current = registerItem(itemKey);
17
- _onValueChange(Formats.dateToTextFormat(_selection, 'yyyy-MM-dd'));
20
+ _onValueChange(currentDate);
18
21
  }, []);
19
22
  // Hooks
20
- useEffect(() => {
21
- setSelection(selection ?? defaultValue ?? new Date());
22
- if (selection === undefined)
23
- _onValueChange(Formats.dateToTextFormat(_selection, 'yyyy-MM-dd'));
24
- }, [selection]);
25
- const _onValueChange = useCallback((value_str) => {
26
- const [year, month, day] = value_str.split('-').map(Number);
27
- const value = new Date(year, month - 1, day);
23
+ useEffect(() => setSelection(selection), [selection]);
24
+ Hooks.useEffectWithoutFirstRender(() => {
25
+ setSelection(currentDateRanged);
26
+ _onValueChange(currentDateRanged);
27
+ }, [currentDateRanged]);
28
+ const _onValueChange = useCallback((value) => {
28
29
  setSelection(value);
29
30
  store.values[keyRef.current ?? 0].set({
30
31
  value: value,
@@ -33,22 +34,5 @@ export default memo(({ itemKey, label, selection, defaultValue, minDate, maxDate
33
34
  });
34
35
  onValueChange?.(value);
35
36
  }, []);
36
- return (<Table.Option id={label ?? ''} colorScheme={colorScheme} childrenLeft={<Table.Option.Components.Text text={label ?? 'Seleccione una fecha'}/>} childrenRight={(<>
37
- <Pressable onPress={() => inputRef.current?.showPicker()} style={[styles.container, { backgroundColor: Colors.especiales.azul }]}>
38
- <Table.Option.Components.Text text={Formats.dateToTextFormat(_selection, 'dd/MM/yyyy')} style={{ color: 'white', userSelect: 'none' }}/>
39
- <input ref={inputRef} type="date" value={Formats.dateToTextFormat(_selection, 'yyyy-MM-dd')} onChange={(e) => _onValueChange(e.target.value)} style={{
40
- all: 'unset',
41
- visibility: 'hidden',
42
- width: 0,
43
- position: 'absolute'
44
- }}/>
45
- </Pressable>
46
- </>)}/>);
47
- });
48
- const styles = StyleSheet.create({
49
- container: {
50
- padding: 7,
51
- paddingHorizontal: 30,
52
- borderRadius: 20
53
- },
37
+ return (<DatePicker label={label} selection={currentDateRanged} onValueChange={_onValueChange} minDate={minDate} maxDate={maxDate}/>);
54
38
  });
@@ -1,32 +1,17 @@
1
- type Props = {
1
+ import DatePickerProps from './DatePicker/types';
2
+ type Props = Omit<DatePickerProps, 'selection'> & {
2
3
  /**
3
4
  identification key of the item.
4
5
  */
5
6
  itemKey?: string;
6
- /**
7
- Title of the date picker.
8
- */
9
- label?: string;
10
- /**
11
- Selection of the date picker.
12
- */
13
- selection?: Date;
14
7
  /**
15
8
  The value that applies when selection is undefined.
16
9
  @default Date()
17
10
  */
18
11
  defaultValue?: Date;
19
12
  /**
20
- Minimum date allowed.
21
- */
22
- minDate?: Date;
23
- /**
24
- Maximum date allowed.
25
- */
26
- maxDate?: Date;
27
- /**
28
- Callback function to be called when the value changes.
13
+ Selection of the date picker.
29
14
  */
30
- onValueChange?: (value: Date) => void;
15
+ selection?: Date;
31
16
  };
32
17
  export default Props;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-pytech",
3
- "version": "1.0.185",
3
+ "version": "1.0.190",
4
4
  "description": "Libreria de React Native Pytech",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,3 +0,0 @@
1
- import type Props from './types';
2
- declare const _default: import("react").MemoExoticComponent<({ itemKey, label, selection, defaultValue, minDate, maxDate, onValueChange, }: Props) => import("react").JSX.Element>;
3
- export default _default;
@@ -1,42 +0,0 @@
1
- import { DatePicker } from '@expo/ui/swift-ui';
2
- import { memo, useCallback, useEffect, useRef, useState, useMemo } from 'react';
3
- import { environment } from '@expo/ui/swift-ui/modifiers';
4
- import { usePage } from '../../context/page';
5
- import Hooks from '../../../../../libs/constants/hooks';
6
- export default memo(({ itemKey, label, selection, defaultValue, minDate, maxDate, onValueChange, }) => {
7
- const { store, registerItem } = usePage();
8
- const [_selection, setSelection] = useState(selection);
9
- const currentDate = useMemo(() => _selection ?? defaultValue ?? new Date(), [_selection, defaultValue]);
10
- const currentDateRanged = useMemo(() => {
11
- if (maxDate && currentDate > maxDate)
12
- return maxDate;
13
- if (minDate && currentDate < minDate)
14
- return minDate;
15
- return currentDate;
16
- }, [currentDate, minDate, maxDate]);
17
- // Key
18
- const keyRef = useRef(itemKey);
19
- useEffect(() => {
20
- keyRef.current = registerItem(itemKey);
21
- _onValueChange(currentDate);
22
- }, []);
23
- // Hooks
24
- useEffect(() => setSelection(selection), [selection]);
25
- Hooks.useEffectWithoutFirstRender(() => {
26
- setSelection(currentDateRanged);
27
- _onValueChange(currentDateRanged);
28
- }, [currentDateRanged]);
29
- const _onValueChange = useCallback((value) => {
30
- setSelection(value);
31
- store.values[keyRef.current ?? 0].set({
32
- value: value,
33
- hasChanged: value.getTime() !== selection?.getTime(),
34
- isValid: true,
35
- });
36
- onValueChange?.(value);
37
- }, []);
38
- return (<DatePicker title={label} selection={currentDate} onDateChange={_onValueChange} modifiers={[environment('locale', 'es_ES')]} range={{
39
- start: minDate,
40
- end: maxDate,
41
- }}/>);
42
- });