From f3b9ec8b767e9b27efa61782e8d184c3a98b57f7 Mon Sep 17 00:00:00 2001 From: Anthony Wentzel Date: Sun, 27 Oct 2024 06:49:47 -0400 Subject: [PATCH] feat(textProps): adding ability to spread TextProps to help with accessibility (#62) * feat(textProps): adding ability to spread TextProps to help with accessibility * feat(textProps): adding ability to spread TextProps to help with accessibility * fix(ci): lint * fix(ci): lint * fix(textProps): adding textProps vs extending * fix(textProps): adding textProps vs extending * chore(docs): update docs with a simple example to override textProps * chore(textProps): cleanup spreading textProps.style * chore(docs): update docs --- .changeset/curvy-files-teach.md | 5 ++ apps/docs/docs/fundamentals/customization.mdx | 62 +++++++++++++++++++ .../src/components/CalendarItemDay.tsx | 7 ++- .../src/components/CalendarItemWeekName.tsx | 18 +++++- 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 .changeset/curvy-files-teach.md diff --git a/.changeset/curvy-files-teach.md b/.changeset/curvy-files-teach.md new file mode 100644 index 0000000..aabacb1 --- /dev/null +++ b/.changeset/curvy-files-teach.md @@ -0,0 +1,5 @@ +--- +"@marceloterreiro/flash-calendar": minor +--- + +Add the ability to pass TextProps to the fields especially when supporting accessibility diff --git a/apps/docs/docs/fundamentals/customization.mdx b/apps/docs/docs/fundamentals/customization.mdx index 13c488a..bf09a3d 100644 --- a/apps/docs/docs/fundamentals/customization.mdx +++ b/apps/docs/docs/fundamentals/customization.mdx @@ -157,3 +157,65 @@ The sky is the limit here. Here are two demos from the example app: + +### Changing the text props + +You can override the `textProps` to control the nested [Text components](https://reactnative.dev/docs/text). For example [disabling font scaling](https://reactnative.dev/docs/text#allowfontscaling) for accessibility on the Calendar's Day: + +```tsx +import { + Calendar, + useOptimizedDayMetadata, +} from "@marceloterreiro/flash-calendar"; +import { Text } from "react-native"; +import type { CalendarItemDayWithContainerProps } from "@/components/CalendarItemDay"; + +import { useRenderCount } from "./useRenderCount"; + +export const PerfTestCalendarItemDayWithContainer = ({ + children, + metadata: baseMetadata, + onPress, + theme, + dayHeight, + daySpacing, + containerTheme, +}: CalendarItemDayWithContainerProps) => { + const metadata = useOptimizedDayMetadata(baseMetadata); + const renderCounter = useRenderCount(); + + return ( + + + {children} + + {"\n"}render: {renderCounter}x + + + + ); +}; +``` diff --git a/packages/flash-calendar/src/components/CalendarItemDay.tsx b/packages/flash-calendar/src/components/CalendarItemDay.tsx index 073dc00..a18ffc6 100644 --- a/packages/flash-calendar/src/components/CalendarItemDay.tsx +++ b/packages/flash-calendar/src/components/CalendarItemDay.tsx @@ -1,6 +1,6 @@ import type { ReactNode } from "react"; import { useCallback, useMemo } from "react"; -import type { TextStyle, ViewStyle } from "react-native"; +import type { TextProps, TextStyle, ViewStyle } from "react-native"; import { Pressable, StyleSheet, Text, View } from "react-native"; import type { BaseTheme } from "@/helpers/tokens"; @@ -142,6 +142,8 @@ export interface CalendarItemDayProps { >; /** The cell's height */ height: number; + /** Optional TextProps to spread to the component. */ + textProps?: Omit; } /** @@ -158,6 +160,7 @@ export const CalendarItemDay = ({ theme, height, metadata, + textProps, }: CalendarItemDayProps) => { const baseTheme = useTheme(); const baseStyles = useMemo(() => { @@ -196,8 +199,10 @@ export const CalendarItemDay = ({ const { content } = baseStyles[metadata.state](params); return ( component. */ + textProps?: Omit; } export const CalendarItemWeekName = ({ children, height, theme, + textProps, }: CalendarItemWeekNameProps) => { const { colors } = useTheme(); const { containerStyles, contentStyles } = useMemo(() => { @@ -42,14 +45,23 @@ export const CalendarItemWeekName = ({ const contentStyles = [ styles.content, { color: colors.content.primary }, + textProps?.style, theme?.content, ]; return { containerStyles, contentStyles }; - }, [colors.content.primary, height, theme?.container, theme?.content]); + }, [ + colors.content.primary, + height, + theme?.container, + theme?.content, + textProps?.style, + ]); return ( - {children} + + {children} + ); };