Skip to content
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

Improved playground #35

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
527 changes: 195 additions & 332 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"react-hook-form": "7.53.2",
"react-native": "0.76.2",
"react-native": "0.76.3",
"react-native-collapsible": "1.6.2",
"react-native-date-picker": "5.0.7",
"react-native-gesture-handler": "~2.20.2",
Expand All @@ -80,7 +80,7 @@
"react-native-permissions": "5.1.0",
"react-native-reanimated": "~3.16.1",
"react-native-safe-area-context": "4.12.0",
"react-native-screens": "^4.0.0",
"react-native-screens": "~4.1.0",
"react-native-svg": "15.8.0",
"react-native-toast-message": "2.2.1",
"react-native-web": "~0.19.13",
Expand All @@ -99,11 +99,12 @@
"@types/react": "~18.3.12",
"@typescript-eslint/eslint-plugin": "8.15.0",
"@typescript-eslint/parser": "8.15.0",
"ajv": "8.17.1",
"eslint": "8.57.1",
"eslint-config-expo": "~8.0.1",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-lingui": "0.8.0",
"eslint-plugin-lodash": "8.0.0",
"eslint-plugin-lodash": "7.4.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/app/playground/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function PlaygroundLayout() {
<Stack.Screen name="bottom-sheet" options={{ title: 'Bottom Sheet' }} />
<Stack.Screen name="accordion" options={{ title: 'Accordion' }} />
<Stack.Screen name="progress" options={{ title: 'Progress' }} />
<Stack.Screen name="image" options={{ title: 'Image' }} />
<Stack.Screen name="toast" options={{ title: 'Toast' }} />
</Stack>
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/playground/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export default function Accordions() {
<Stack axis="y" spacing="2xl">
<Stack axis="y" spacing="small">
<Text variant="headingS">Accordion</Text>
<Accordion initialOpen={true} title="Accordion Heading">
<Accordion initialOpen title="Accordion Heading">
<AccordionContent />
</Accordion>
</Stack>

<Stack axis="y" spacing="small">
<Text variant="headingS">Accordion with icon</Text>
<Accordion
initialOpen={true}
initialOpen
title="Accordion Heading"
icon="checkCircle"
iconColor="success"
Expand Down
43 changes: 43 additions & 0 deletions src/app/playground/image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Grid, Stack, Text, Image as UiImage } from '~components/uikit';
import { styled } from '~styles';

const photos = [
'https://tinyurl.com/57ssptjn',
'https://tinyurl.com/4mew8zn6',
'https://tinyurl.com/5dkxbcjc',
];

export default function Image() {
return (
<Wrapper>
<Stack axis="y" spacing="large">
<Stack axis="y" spacing="regular">
<Text variant="headingS">Images</Text>

<Grid spacing="regular" justify="center">
{photos.map((photo, index) => (
<Img
key={index}
source={{ uri: photo }}
autoSize={{ width: 300 }}
accessibilityLabel={`Flower ${index + 1}`}
/>
))}
</Grid>
</Stack>
</Stack>
</Wrapper>
);
}

const Wrapper = styled('ScrollView', {
flex: 1,
}).attrs((p) => ({
contentContainerStyle: {
padding: p.theme.space.regular,
},
}));

const Img = styled(UiImage, {
borderRadius: '$regular',
});
1 change: 1 addition & 0 deletions src/app/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function PlaygroundPage() {
{ screen: 'playground/layout', label: 'Layout' },
{ screen: 'playground/accordion', label: 'Accordion' },
{ screen: 'playground/progress', label: 'Progress' },
{ screen: 'playground/image', label: 'Image' },
{ screen: 'playground/toast', label: 'Toast' },
];

Expand Down
4 changes: 2 additions & 2 deletions src/app/playground/progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default function Progress() {
<Text variant="headingS">Progress bar</Text>

<Stack axis="y" spacing="regular">
{Array.from({ length: totalSteps }).map((_, i) => (
<ProgressBar key={i} step={i + 1} totalSteps={totalSteps} />
{Array.from({ length: totalSteps + 1 }).map((_, i) => (
<ProgressBar key={i} step={i} totalSteps={totalSteps} />
))}
</Stack>
</Stack>
Expand Down
31 changes: 26 additions & 5 deletions src/components/uikit/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { View } from 'react-native';
import Animated, {
useAnimatedStyle,
useDerivedValue,
useSharedValue,
withTiming,
} from 'react-native-reanimated';

import { styled } from '~styles';

type Props = {
step: number;
totalSteps: number;
height?: number;
animated?: boolean;
};

/**
Expand All @@ -14,18 +20,31 @@ type Props = {
* @param {Object} props - The component props.
* @param {number} props.step - The current step of the form.
* @param {number} props.totalSteps - The total number of steps in the form.
* @param {number} [props.height=12] - The height of the progress bar.
* @param {boolean} [props.animated=false] - Whether the progress bar should animate.
* @returns {JSX.Element} - The rendered component.
*/
export function ProgressBar({
step,
totalSteps,
height = 12,
animated = true,
}: Props): JSX.Element {
const progress = Math.min(Math.max((step / totalSteps) * 100, 0), 100);

if (step === 0) {
return <View />;
}
const progressAnim = useSharedValue(0);

useDerivedValue(() => {
progressAnim.value = withTiming(progress, {
duration: animated ? 200 : 0,
});
}, [step]);

const animatedStyle = useAnimatedStyle(() => {
return {
width: `${progressAnim.value}%`,
};
});

return (
<ProgressContainer
Expand All @@ -34,7 +53,7 @@ export function ProgressBar({
accessibilityRole="progressbar"
accessibilityValue={{ now: step, min: 0, max: totalSteps }}
>
<Progress style={{ height, width: `${progress}%` }} />
<AnimatedProgress style={[{ height }, animatedStyle]} />
</ProgressContainer>
);
}
Expand All @@ -48,3 +67,5 @@ const Progress = styled('View', {
borderRadius: '$full',
backgroundColor: '$primary',
});

const AnimatedProgress = Animated.createAnimatedComponent(Progress);
1 change: 0 additions & 1 deletion src/components/uikit/inputs/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const TextInput = forwardRef<RNTextInput, TextInputProps>(
color="error"
accessibilityLabel={_(msg`Required field indicator`)}
accessibilityHint={_(msg`This field is marked as required`)}

// eslint-disable-next-line lingui/no-unlocalized-strings
>
*
Expand Down
Loading
Loading