-
Notifications
You must be signed in to change notification settings - Fork 0
feat(renderers): add currency/file renderers, filler generators, and list sub-schema modal #6
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
Open
iguit0
wants to merge
1
commit into
main
Choose a base branch
from
feat/field-types-fillers-sub-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { View, Text, TextInput, StyleSheet } from "react-native"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import type { FieldRendererProps } from "@ybyra/react"; | ||
| import { useTheme } from "../theme/context"; | ||
| import type { Theme } from "../theme/default"; | ||
| import { ds } from "../support/ds"; | ||
|
|
||
| export function CurrencyField({ domain, name, value, config, proxy, errors, onChange, onBlur, onFocus }: FieldRendererProps) { | ||
| const { t } = useTranslation(); | ||
| const theme = useTheme(); | ||
| const styles = createStyles(theme); | ||
| if (proxy.hidden) return null; | ||
|
|
||
| const fieldLabel = t(`${domain}.fields.${name}`, { defaultValue: name }); | ||
| const prefix = (config.attrs.prefix as string) ?? ""; | ||
|
|
||
| return ( | ||
| <View style={styles.container} {...ds(`CurrencyField:${name}`)}> | ||
| <Text style={styles.label}>{fieldLabel}</Text> | ||
| <View style={styles.inputWrapper}> | ||
| {prefix ? <Text style={styles.prefix}>{prefix}</Text> : null} | ||
| <TextInput | ||
| style={[styles.input, prefix ? styles.inputWithPrefix : null, proxy.disabled && styles.inputDisabled, errors.length > 0 && styles.inputError]} | ||
| value={value !== undefined && value !== null ? String(value) : ""} | ||
| onChangeText={(text) => { | ||
| const num = Number(text); | ||
| onChange(isNaN(num) ? text : num); | ||
| }} | ||
| onBlur={onBlur} | ||
| onFocus={onFocus} | ||
| editable={!proxy.disabled} | ||
| keyboardType="decimal-pad" | ||
| placeholderTextColor={theme.colors.mutedForeground} | ||
| /> | ||
| </View> | ||
| <View style={styles.errorSlot}> | ||
| {errors.map((error, i) => ( | ||
| <Text key={i} style={styles.error}>{error}</Text> | ||
| ))} | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| const createStyles = (theme: Theme) => StyleSheet.create({ | ||
| container: { | ||
| paddingHorizontal: theme.spacing.xs, | ||
| }, | ||
| label: { | ||
| fontSize: theme.fontSize.sm, | ||
| fontWeight: theme.fontWeight.semibold, | ||
| marginBottom: theme.spacing.xs, | ||
| color: theme.colors.foreground, | ||
| }, | ||
| inputWrapper: { | ||
| flexDirection: "row", | ||
| alignItems: "center", | ||
| }, | ||
| prefix: { | ||
| position: "absolute", | ||
| left: theme.spacing.md, | ||
| fontSize: theme.fontSize.md, | ||
| color: theme.colors.mutedForeground, | ||
| zIndex: 1, | ||
| }, | ||
| input: { | ||
| flex: 1, | ||
| borderWidth: 1, | ||
| borderColor: theme.colors.input, | ||
| borderRadius: theme.borderRadius.md, | ||
| paddingHorizontal: theme.spacing.md, | ||
| paddingVertical: 10, | ||
| fontSize: theme.fontSize.md, | ||
| backgroundColor: theme.colors.card, | ||
| color: theme.colors.cardForeground, | ||
| }, | ||
| inputWithPrefix: { | ||
| paddingLeft: 36, | ||
| }, | ||
| inputDisabled: { | ||
| backgroundColor: theme.colors.muted, | ||
| color: theme.colors.mutedForeground, | ||
| }, | ||
| inputError: { | ||
| borderColor: theme.colors.destructive, | ||
| }, | ||
| errorSlot: { | ||
| minHeight: 20, | ||
| marginTop: 2, | ||
| }, | ||
| error: { | ||
| fontSize: theme.fontSize.xs, | ||
| color: theme.colors.destructive, | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { View, Text, Pressable, StyleSheet } from "react-native"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import type { FieldRendererProps } from "@ybyra/react"; | ||
| import { useTheme } from "../theme/context"; | ||
| import type { Theme } from "../theme/default"; | ||
| import { ds } from "../support/ds"; | ||
|
|
||
| export function FileField({ domain, name, value, config, proxy, errors }: FieldRendererProps) { | ||
| const { t } = useTranslation(); | ||
| const theme = useTheme(); | ||
| const styles = createStyles(theme); | ||
| if (proxy.hidden) return null; | ||
|
|
||
| const fieldLabel = t(`${domain}.fields.${name}`, { defaultValue: name }); | ||
| const isImage = config.component === "image"; | ||
| const fileName = value && typeof value === "object" && "name" in value ? String(value.name) : (value ? String(value) : ""); | ||
|
|
||
| return ( | ||
| <View style={styles.container} {...ds(`FileField:${name}`)}> | ||
| <Text style={styles.label}>{fieldLabel}</Text> | ||
| <View style={styles.inputWrapper}> | ||
| {/* TODO: integrate expo-document-picker or react-native-document-picker for actual file selection */} | ||
| <Pressable | ||
| style={[styles.chooseBtn, proxy.disabled && styles.chooseBtnDisabled]} | ||
| disabled={proxy.disabled} | ||
| > | ||
| <Text style={[styles.chooseBtnText, proxy.disabled && styles.chooseBtnTextDisabled]}> | ||
| {t("common.file.choose", { defaultValue: isImage ? "Choose image…" : "Choose file…" })} | ||
| </Text> | ||
| </Pressable> | ||
| <Text style={styles.fileName} numberOfLines={1}> | ||
| {fileName || t("common.file.none", { defaultValue: "No file selected" })} | ||
| </Text> | ||
| </View> | ||
| <View style={styles.errorSlot}> | ||
| {errors.map((error, i) => ( | ||
| <Text key={i} style={styles.error}>{error}</Text> | ||
| ))} | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| const createStyles = (theme: Theme) => StyleSheet.create({ | ||
| container: { | ||
| paddingHorizontal: theme.spacing.xs, | ||
| }, | ||
| label: { | ||
| fontSize: theme.fontSize.sm, | ||
| fontWeight: theme.fontWeight.semibold, | ||
| marginBottom: theme.spacing.xs, | ||
| color: theme.colors.foreground, | ||
| }, | ||
| inputWrapper: { | ||
| flexDirection: "row", | ||
| alignItems: "center", | ||
| gap: theme.spacing.sm, | ||
| }, | ||
| chooseBtn: { | ||
| borderWidth: 1, | ||
| borderColor: theme.colors.input, | ||
| borderRadius: theme.borderRadius.md, | ||
| paddingHorizontal: theme.spacing.md, | ||
| paddingVertical: 8, | ||
| backgroundColor: theme.colors.secondary, | ||
| }, | ||
| chooseBtnDisabled: { | ||
| backgroundColor: theme.colors.muted, | ||
| }, | ||
| chooseBtnText: { | ||
| fontSize: theme.fontSize.sm, | ||
| color: theme.colors.secondaryForeground, | ||
| }, | ||
| chooseBtnTextDisabled: { | ||
| color: theme.colors.mutedForeground, | ||
| }, | ||
| fileName: { | ||
| flex: 1, | ||
| fontSize: theme.fontSize.sm, | ||
| color: theme.colors.mutedForeground, | ||
| }, | ||
| errorSlot: { | ||
| minHeight: 20, | ||
| marginTop: 2, | ||
| }, | ||
| error: { | ||
| fontSize: theme.fontSize.xs, | ||
| color: theme.colors.destructive, | ||
| }, | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearing the input silently produces
onChange(0)instead of an empty/null value.Number("") === 0andisNaN(0) === false, so when the user erases all digits,onChange(0)is called. A cleared currency field and an explicitly entered0are indistinguishable downstream. The same behavior exists inreact-web/CurrencyField.tsx, so if this is intentional parity, it should be explicitly documented; otherwise, guard for the empty string:🐛 Proposed fix
🤖 Prompt for AI Agents