|
1 | | -import React from "react"; |
| 1 | +import React, { SetStateAction, useState } from "react"; |
2 | 2 | import { |
3 | 3 | Box, |
4 | 4 | Button, |
5 | 5 | CircularProgress, |
| 6 | + CircularProgressSizes, |
| 7 | + CircularProgressTheme, |
| 8 | + Radio, |
| 9 | + RadioGroup, |
| 10 | + Switch, |
6 | 11 | useTheme, |
7 | 12 | } from "@adaptui/react-native-tailwind"; |
8 | 13 |
|
| 14 | +import { Group } from "../../components"; |
| 15 | + |
9 | 16 | const useCircularProgressState = (initialValue: number | null = 0) => { |
10 | 17 | const [value, setValue] = React.useState<number | null>(initialValue); |
11 | 18 |
|
@@ -33,45 +40,98 @@ const useCircularProgressState = (initialValue: number | null = 0) => { |
33 | 40 |
|
34 | 41 | export const CircularProgressScreen = () => { |
35 | 42 | const tailwind = useTheme(); |
36 | | - const [value, setValue] = useCircularProgressState(); |
| 43 | + const [progressValue, setProgressValue] = useCircularProgressState(); |
| 44 | + const [selectedTheme, setSelectedTheme] = |
| 45 | + useState<CircularProgressTheme>("base"); |
| 46 | + const [selectedSize, setSelectedSize] = useState<CircularProgressSizes>("md"); |
| 47 | + const [hasHints, setHasHints] = useState<boolean>(false); |
| 48 | + const [hasCustomTrack, setHasCustomTrack] = useState<boolean>(false); |
| 49 | + |
37 | 50 | return ( |
38 | | - <Box |
39 | | - style={tailwind.style( |
40 | | - "flex-1 justify-center items-center px-2 bg-white-900", |
41 | | - )} |
42 | | - > |
43 | | - <Box style={tailwind.style("my-5")}> |
44 | | - <CircularProgress size="sm" /> |
45 | | - </Box> |
46 | | - <Box style={tailwind.style("my-5")}> |
47 | | - <CircularProgress themeColor="primary" /> |
48 | | - </Box> |
49 | | - <Box style={tailwind.style("my-5")}> |
50 | | - <CircularProgress |
51 | | - style={tailwind.style("w-48 h-48")} |
52 | | - themeColor="primary" |
53 | | - progressTrackColor={tailwind.getColor("text-green-600")} |
54 | | - /> |
55 | | - </Box> |
56 | | - <Box style={tailwind.style("my-5")}> |
57 | | - <CircularProgress size="lg" /> |
58 | | - </Box> |
59 | | - <Box style={tailwind.style("my-5")}> |
60 | | - <CircularProgress value={value} themeColor="primary" size="xl" /> |
61 | | - </Box> |
62 | | - <Box style={tailwind.style("my-5")}> |
| 51 | + <Box style={tailwind.style("flex-1 justify-center bg-white-900")}> |
| 52 | + <Box |
| 53 | + style={tailwind.style( |
| 54 | + "flex-1 px-2 justify-center items-center bg-white-900", |
| 55 | + )} |
| 56 | + > |
63 | 57 | <CircularProgress |
64 | | - hint={`${value}%`} |
65 | | - value={value} |
66 | | - themeColor="primary" |
67 | | - size="xl" |
| 58 | + style={!hasCustomTrack ? null : tailwind.style("w-48 h-48")} |
| 59 | + hint={!hasHints ? null : `${progressValue}%`} |
| 60 | + value={progressValue} |
| 61 | + themeColor={selectedTheme} |
| 62 | + size={selectedSize} |
| 63 | + progressTrackColor={ |
| 64 | + !hasCustomTrack ? null : tailwind.getColor("text-green-600") |
| 65 | + } |
68 | 66 | /> |
69 | 67 | </Box> |
70 | | - <Box style={tailwind.style("flex-row justify-center w-full")}> |
71 | | - <Button onPress={() => setValue(0)}>Reset</Button> |
72 | | - <Button variant="ghost" onPress={() => setValue(null)}> |
73 | | - Make Indeterminate |
74 | | - </Button> |
| 68 | + <Box |
| 69 | + style={tailwind.style( |
| 70 | + "rounded-t-lg shadow-lg bg-gray-100 justify-end p-2", |
| 71 | + )} |
| 72 | + > |
| 73 | + <RadioGroup |
| 74 | + value={selectedSize} |
| 75 | + onChange={(value: CircularProgressSizes) => setSelectedSize(value)} |
| 76 | + orientation="horizontal" |
| 77 | + > |
| 78 | + <Group label="Sizes"> |
| 79 | + <Radio value="sm" label="sm" /> |
| 80 | + <Radio value="md" label="md" /> |
| 81 | + <Radio value="lg" label="lg" /> |
| 82 | + <Radio value="xl" label="xl" /> |
| 83 | + </Group> |
| 84 | + </RadioGroup> |
| 85 | + <RadioGroup |
| 86 | + value={selectedTheme} |
| 87 | + onChange={(value: CircularProgressTheme) => setSelectedTheme(value)} |
| 88 | + orientation="horizontal" |
| 89 | + > |
| 90 | + <Group label="Theme" style={tailwind.style("mt-2")}> |
| 91 | + <Radio value="base" label="base" /> |
| 92 | + <Radio value="primary" label="primary" /> |
| 93 | + </Group> |
| 94 | + </RadioGroup> |
| 95 | + <Box |
| 96 | + style={tailwind.style( |
| 97 | + "flex flex-row justify-start flex-wrap w-full mt-2", |
| 98 | + )} |
| 99 | + > |
| 100 | + <Switch |
| 101 | + state={hasHints} |
| 102 | + onStateChange={(value: SetStateAction<boolean>) => { |
| 103 | + setHasHints(value); |
| 104 | + setProgressValue(0); |
| 105 | + }} |
| 106 | + size="md" |
| 107 | + label="Has Hints" |
| 108 | + /> |
| 109 | + <Switch |
| 110 | + state={hasCustomTrack} |
| 111 | + onStateChange={(value: SetStateAction<boolean>) => |
| 112 | + setHasCustomTrack(value) |
| 113 | + } |
| 114 | + size="md" |
| 115 | + style={tailwind.style("ml-1")} |
| 116 | + label="Custom track" |
| 117 | + /> |
| 118 | + </Box> |
| 119 | + <Box |
| 120 | + style={tailwind.style( |
| 121 | + "flex flex-row justify-start flex-wrap w-full mt-2", |
| 122 | + )} |
| 123 | + > |
| 124 | + <Button variant="solid" onPress={() => setProgressValue(0)}> |
| 125 | + Reset |
| 126 | + </Button> |
| 127 | + <Button |
| 128 | + variant="ghost" |
| 129 | + onPress={() => setProgressValue(null)} |
| 130 | + style={tailwind.style("ml-1")} |
| 131 | + > |
| 132 | + Make Indeterminate |
| 133 | + </Button> |
| 134 | + </Box> |
75 | 135 | </Box> |
76 | 136 | </Box> |
77 | 137 | ); |
|
0 commit comments