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

feat(textProps): adding ability to spread TextProps to help with accessibility #62

Merged
5 changes: 5 additions & 0 deletions .changeset/curvy-files-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marceloterreiro/flash-calendar": minor
---

Add the ability to pass TextProps to the <Text> fields especially when supporting accessibility
7 changes: 5 additions & 2 deletions packages/flash-calendar/src/components/CalendarItemDay.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -126,7 +126,8 @@ const buildBaseStyles = (theme: BaseTheme): CalendarItemDayTheme => {
};
};

export interface CalendarItemDayProps {
export interface CalendarItemDayProps
extends Omit<TextProps, "children" | "onPress"> {
theonetheycallneo marked this conversation as resolved.
Show resolved Hide resolved
children: ReactNode;
onPress: (id: string) => void;
metadata: CalendarDayMetadata;
Expand Down Expand Up @@ -158,6 +159,7 @@ export const CalendarItemDay = ({
theme,
height,
metadata,
...rest
}: CalendarItemDayProps) => {
const baseTheme = useTheme();
const baseStyles = useMemo(() => {
Expand Down Expand Up @@ -196,6 +198,7 @@ export const CalendarItemDay = ({
const { content } = baseStyles[metadata.state](params);
return (
<Text
{...rest}
style={{
...content,
...theme?.base?.({ ...metadata, isPressed }).content,
theonetheycallneo marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactNode } from "react";
import { useMemo } from "react";
import type { TextStyle, ViewStyle } from "react-native";
import type { TextProps, TextStyle, ViewStyle } from "react-native";
import { StyleSheet, Text, View } from "react-native";

import { lightTheme } from "@/helpers/tokens";
Expand All @@ -21,7 +21,7 @@ interface CalendarItemWeekNameTheme {
content?: TextStyle;
}

export interface CalendarItemWeekNameProps {
export interface CalendarItemWeekNameProps extends Omit<TextProps, "children"> {
children: ReactNode;
/**
* The height of the week name, needed to correctly measure the calendar's
Expand All @@ -35,6 +35,7 @@ export const CalendarItemWeekName = ({
children,
height,
theme,
...rest
}: CalendarItemWeekNameProps) => {
const { colors } = useTheme();
const { containerStyles, contentStyles } = useMemo(() => {
Expand All @@ -49,7 +50,9 @@ export const CalendarItemWeekName = ({

return (
<View style={containerStyles}>
<Text style={contentStyles}>{children}</Text>
<Text {...rest} style={contentStyles}>
{children}
</Text>
</View>
);
};
Loading