Skip to content

Commit

Permalink
Merge branch 'main' into add-module-navigation-component
Browse files Browse the repository at this point in the history
  • Loading branch information
mastro993 authored May 2, 2024
2 parents 500e2f0 + c1d42bc commit 7339f4d
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 54 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v1.36.4](https://github.com/pagopa/io-app-design-system/compare/v1.36.3...v1.36.4)

- chore: Expose `autoFocus` `prop` on `OTPInput` [`#252`](https://github.com/pagopa/io-app-design-system/pull/252)

#### [v1.36.3](https://github.com/pagopa/io-app-design-system/compare/v1.36.2...v1.36.3)

> 2 May 2024
- [chore] Add optional `testID` property to `ListItemSwitch` [`#253`](https://github.com/pagopa/io-app-design-system/pull/253)
- Revert "feat: add `ModuleNavigation` component" [`9476296`](https://github.com/pagopa/io-app-design-system/commit/9476296cb4453dd22abf01134d0fd97fb8095662)
- feat: add `ModuleNavigation` component [`99d065e`](https://github.com/pagopa/io-app-design-system/commit/99d065e8348292eecc932852eb0c21b354dff659)
- chore: release 1.36.3 [`1de1183`](https://github.com/pagopa/io-app-design-system/commit/1de11832418086fd3c332149bf2a7baf0bb58c89)

#### [v1.36.2](https://github.com/pagopa/io-app-design-system/compare/v1.36.1...v1.36.2)

> 24 April 2024
- fix: Typo into `ListItemRadioWithAmount` [`#250`](https://github.com/pagopa/io-app-design-system/pull/250)
- [chore] Optional viewRef for Banner [`#249`](https://github.com/pagopa/io-app-design-system/pull/249)
- chore: release 1.36.2 [`3cd3947`](https://github.com/pagopa/io-app-design-system/commit/3cd394739e22441f1b222549c02c51317d09b05e)

#### [v1.36.1](https://github.com/pagopa/io-app-design-system/compare/v1.36.0...v1.36.1)

Expand Down
168 changes: 121 additions & 47 deletions example/src/pages/OTPInput.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,152 @@
import * as React from "react";
import { View } from "react-native";
import { useHeaderHeight } from "@react-navigation/elements";
import { KeyboardAvoidingView, Platform, ScrollView, View } from "react-native";
import {
H1,
H5,
IOStyles,
VSpacer,
OTPInput,
LabelSmall,
ButtonSolid
ButtonSolid,
ContentWrapper,
ButtonOutline
} from "@pagopa/io-app-design-system";
import { useState } from "react";
import { Screen } from "../components/Screen";

const OTP_LENGTH = 8;
const OTP_COMPARE = "12345678";

type WrapperProps = {
secret?: boolean;
validation?: boolean;
autoFocus?: boolean;
};

const OTPWrapper = ({ secret = false, validation = false }: WrapperProps) => {
const OTPWrapper = ({
secret = false,
validation = false,
autoFocus = false
}: WrapperProps) => {
const [value, setValue] = useState("");
const onValueChange = (v: string) => {
const onValueChange = React.useCallback((v: string) => {
if (v.length <= OTP_LENGTH) {
setValue(v);
}
};
}, []);

const onValidate = (v: string) => !validation || v === OTP_COMPARE;
const onValidate = React.useCallback(
(v: string) => !validation || v === OTP_COMPARE,
[validation]
);

return (
<>
<OTPInput
value={value}
accessibilityLabel={"OTP Input"}
onValueChange={onValueChange}
length={OTP_LENGTH}
secret={secret}
onValidate={onValidate}
errorMessage={"Wrong OTP"}
/>
<VSpacer />
<ButtonSolid onPress={() => setValue("")} label={"Pulisci valore"} />
</>
return React.useMemo(
() => (
<>
<OTPInput
value={value}
accessibilityLabel={"OTP Input"}
onValueChange={onValueChange}
length={OTP_LENGTH}
secret={secret}
onValidate={onValidate}
errorMessage={"Wrong OTP"}
autoFocus={autoFocus}
/>
<VSpacer />
<ButtonSolid onPress={() => setValue("")} label={"Pulisci valore"} />
</>
),
[value, onValueChange, secret, onValidate, autoFocus]
);
};

const scrollVerticallyToView = (
scrollViewRef: React.RefObject<ScrollView>,
targetViewRef: React.RefObject<View>
) => {
if (targetViewRef.current && scrollViewRef.current) {
targetViewRef.current.measureLayout(
scrollViewRef.current.getInnerViewNode(),
(_: number, y: number) => {
scrollViewRef.current?.scrollTo({ y, animated: true });
}
);
}
};

/**
* This Screen is used to test components in isolation while developing.
* @returns a screen with a flexed view where you can test components
*/
export const OTPInputScreen = () => (
<View
style={{
flexGrow: 1
}}
>
<Screen>
<View style={IOStyles.alignCenter}>
<H1>OTP Input</H1>
</View>
<VSpacer />
<H5>Default</H5>
<VSpacer />
<OTPWrapper />
<VSpacer />
<H5>Secret</H5>
<VSpacer />
<OTPWrapper secret />
<VSpacer />
<H5>Validation+Secret</H5>
<LabelSmall>Correct OTP {`${OTP_COMPARE}`}</LabelSmall>
<VSpacer />
<OTPWrapper secret validation />
</Screen>
</View>
);
export const OTPInputScreen = () => {
const scrollViewRef = React.useRef<ScrollView>(null);
const autofocusableOTPViewRef = React.useRef<View>(null);
const [showAutofocusableOTP, setShowAutofocusableOTP] = useState(false);
const headerHeight = useHeaderHeight();

const ToggleButton = showAutofocusableOTP ? ButtonSolid : ButtonOutline;

return (
<View
style={{
flexGrow: 1
}}
>
<KeyboardAvoidingView
behavior={Platform.select({
ios: "padding",
android: undefined
})}
contentContainerStyle={[IOStyles.flex, { paddingBottom: 70 }]}
style={IOStyles.flex}
keyboardVerticalOffset={headerHeight}
>
<ScrollView ref={scrollViewRef}>
<ContentWrapper>
<View style={IOStyles.alignCenter}>
<H1>OTP Input</H1>
</View>
<VSpacer />
<H5>Default</H5>
<VSpacer />
<OTPWrapper />
<VSpacer />
<H5>Secret</H5>
<VSpacer />
<OTPWrapper secret />
<VSpacer />
<H5>Validation+Secret</H5>
<LabelSmall>Correct OTP {`${OTP_COMPARE}`}</LabelSmall>
<VSpacer />
<OTPWrapper secret validation />
<VSpacer />
<H5>Autofocus</H5>
<VSpacer />
<ToggleButton
onPress={() => {
setShowAutofocusableOTP(!showAutofocusableOTP);
setTimeout(() => {
scrollVerticallyToView(
scrollViewRef,
autofocusableOTPViewRef
);
}, 100);
}}
label={`${
showAutofocusableOTP ? "Hide" : "Show"
} Autofocusable OTP`}
/>
<VSpacer />
{showAutofocusableOTP && (
<View ref={autofocusableOTPViewRef}>
<OTPWrapper autoFocus />
<VSpacer />
</View>
)}
</ContentWrapper>
</ScrollView>
</KeyboardAvoidingView>
</View>
);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pagopa/io-app-design-system",
"version": "1.36.2",
"version": "1.36.4",
"description": "The library defining the core components of the design system of @pagopa/io-app",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
10 changes: 6 additions & 4 deletions src/components/listitems/ListItemSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo } from "react";
import { GestureResponderEvent, Platform, Switch, View } from "react-native";
import { WithTestID } from "src/utils/types";
import {
IOSelectionListItemStyles,
IOSelectionListItemVisualParams,
Expand All @@ -13,14 +14,14 @@ import { HSpacer, VSpacer } from "../spacer";
import { NativeSwitch } from "../switch/NativeSwitch";
import { H6, LabelLink, LabelSmall } from "../typography";

type PartialProps = {
type PartialProps = WithTestID<{
label: string;
onSwitchValueChange?: (newValue: boolean) => void;
description?: string;
action?: SwitchAction;
isLoading?: boolean;
badge?: Badge;
};
}>;

export type SwitchAction = {
label: string;
Expand Down Expand Up @@ -53,7 +54,8 @@ export const ListItemSwitch = React.memo(
action,
isLoading,
badge,
onSwitchValueChange
onSwitchValueChange,
testID
}: ListItemSwitchProps) => {
const theme = useIOTheme();

Expand All @@ -66,7 +68,7 @@ export const ListItemSwitch = React.memo(

return (
<View
testID="ListItemSwitch"
testID={testID ?? "ListItemSwitch"}
style={[
IOSelectionListItemStyles.listItem,
{
Expand Down
7 changes: 5 additions & 2 deletions src/components/otpInput/OTPInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Props = {
accessibilityLabel?: string;
accessibilityHint?: string;
inputAccessoryViewID?: string;
autoFocus?: boolean;
};

/**
Expand Down Expand Up @@ -46,11 +47,12 @@ export const OTPInput = React.forwardRef<View, Props>(
errorMessage = "",
secret = false,
autocomplete = false,
inputAccessoryViewID
inputAccessoryViewID,
autoFocus = false
},
ref
) => {
const [hasFocus, setHasFocus] = React.useState(false);
const [hasFocus, setHasFocus] = React.useState(autoFocus);
const [hasError, setHasError] = React.useState(false);

const { translate, animatedStyle, shakeAnimation } =
Expand Down Expand Up @@ -119,6 +121,7 @@ export const OTPInput = React.forwardRef<View, Props>(
autoComplete={autocomplete ? "sms-otp" : undefined}
inputAccessoryViewID={inputAccessoryViewID}
accessible={true}
autoFocus={autoFocus}
/>
{[...Array(length)].map((_, i) => (
<BoxedInput
Expand Down

0 comments on commit 7339f4d

Please sign in to comment.