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

Fix typo information for props #175

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 4 additions & 1 deletion src/createVariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export type VariantProps<
K extends keyof Theme,
Property extends keyof any = 'variant'
> = {
[key in Property]?: ResponsiveValue<keyof Omit<Theme[K], 'defaults'>, Theme>;
[key in Property]?: ResponsiveValue<
keyof Omit<Theme[K], 'defaults'>,
Theme['breakpoints']
>;
};

export default createVariant;
2 changes: 1 addition & 1 deletion src/hooks/useResponsiveProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useDimensions from './useDimensions';
import useTheme from './useTheme';

const useResponsiveProp = <Theme extends BaseTheme, TVal extends PropValue>(
propValue: ResponsiveValue<TVal, Theme>,
propValue: ResponsiveValue<TVal, Theme['breakpoints']>,
) => {
const theme = useTheme<Theme>();
const dimensions = useDimensions();
Expand Down
8 changes: 4 additions & 4 deletions src/responsiveHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getValueForScreenSize = <Theme extends BaseTheme, TVal>({
breakpoints,
dimensions,
}: {
responsiveValue: AtLeastOneResponsiveValue<TVal, Theme>;
responsiveValue: AtLeastOneResponsiveValue<TVal, Theme['breakpoints']>;
breakpoints: Theme['breakpoints'];
dimensions: Dimensions;
}): TVal | undefined => {
Expand Down Expand Up @@ -62,9 +62,9 @@ export const getValueForScreenSize = <Theme extends BaseTheme, TVal>({
};

export const isResponsiveObjectValue = <Theme extends BaseTheme, TVal>(
val: ResponsiveValue<TVal, Theme>,
val: ResponsiveValue<TVal, Theme['breakpoints']>,
theme: Theme,
): val is AtLeastOneResponsiveValue<TVal, Theme> => {
): val is AtLeastOneResponsiveValue<TVal, Theme['breakpoints']> => {
if (!val) return false;
if (typeof val !== 'object') return false;
return getKeys(val).reduce((acc: boolean, key) => {
Expand All @@ -77,7 +77,7 @@ export const getResponsiveValue = <
Theme extends BaseTheme,
K extends keyof Theme | undefined
>(
propValue: ResponsiveValue<TVal, Theme>,
propValue: ResponsiveValue<TVal, Theme['breakpoints']>,
{
theme,
transform,
Expand Down
42 changes: 24 additions & 18 deletions src/restyleFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,99 +266,105 @@ export const all = [
];

export interface ColorProps<Theme extends BaseTheme> {
color?: ResponsiveValue<keyof Theme['colors'], Theme>;
color?: ResponsiveValue<keyof Theme['colors'], Theme['breakpoints']>;
}
export interface OpacityProps<Theme extends BaseTheme> {
opacity?: ResponsiveValue<number, Theme>;
opacity?: ResponsiveValue<number, Theme['breakpoints']>;
}

export interface VisibleProps<Theme extends BaseTheme> {
visible?: ResponsiveValue<boolean, Theme>;
visible?: ResponsiveValue<boolean, Theme['breakpoints']>;
}

export interface BackgroundColorProps<Theme extends BaseTheme> {
backgroundColor?: ResponsiveValue<keyof Theme['colors'], Theme>;
backgroundColor?: ResponsiveValue<
keyof Theme['colors'],
Theme['breakpoints']
>;
}

export interface BackgroundColorShorthandProps<Theme extends BaseTheme> {
bg?: ResponsiveValue<keyof Theme['colors'], Theme>;
bg?: ResponsiveValue<keyof Theme['colors'], Theme['breakpoints']>;
}

export type SpacingProps<Theme extends BaseTheme> = {
[Key in keyof typeof spacingProperties]?: ResponsiveValue<
keyof Theme['spacing'],
Theme
Theme['breakpoints']
>;
};

export type SpacingShorthandProps<Theme extends BaseTheme> = {
[Key in keyof typeof spacingPropertiesShorthand]?: ResponsiveValue<
keyof Theme['spacing'],
Theme
Theme['breakpoints']
>;
};

export type TypographyProps<Theme extends BaseTheme> = {
[Key in keyof typeof typographyProperties]?: ResponsiveValue<
TextStyle[Key],
Theme
Theme['breakpoints']
>;
};

export type LayoutProps<Theme extends BaseTheme> = {
[Key in keyof typeof layoutProperties]?: ResponsiveValue<
FlexStyle[Key],
Theme
Theme['breakpoints']
>;
};

export type PositionProps<Theme extends BaseTheme> = {
[Key in keyof typeof positionProperties]?: ResponsiveValue<
FlexStyle[Key],
Theme
Theme['breakpoints']
>;
} & {
zIndex?: ResponsiveValue<
Theme['zIndices'] extends {} ? keyof Theme['zIndices'] : number,
Theme
Theme['breakpoints']
>;
};

export type BorderProps<Theme extends BaseTheme> = {
[Key in keyof typeof borderProperties]?: ResponsiveValue<
ViewStyle[Key],
Theme
Theme['breakpoints']
>;
} &
{
[Key in keyof typeof borderColorProperties]?: ResponsiveValue<
keyof Theme['colors'],
Theme
Theme['breakpoints']
>;
} &
{
[Key in keyof typeof borderRadiusProperties]?: ResponsiveValue<
Theme['borderRadii'] extends {} ? keyof Theme['borderRadii'] : number,
Theme
Theme['breakpoints']
>;
};

export type ShadowProps<Theme extends BaseTheme> = {
[Key in keyof typeof shadowProperties]?: ResponsiveValue<
ViewStyle[Key],
Theme
Theme['breakpoints']
>;
} & {
shadowColor?: ResponsiveValue<keyof Theme['colors'], Theme>;
shadowColor?: ResponsiveValue<keyof Theme['colors'], Theme['breakpoints']>;
};

export type TextShadowProps<Theme extends BaseTheme> = {
[Key in keyof typeof textShadowProperties]?: ResponsiveValue<
TextStyle[Key],
Theme
Theme['breakpoints']
>;
} & {
textShadowColor?: ResponsiveValue<keyof Theme['colors'], Theme>;
textShadowColor?: ResponsiveValue<
keyof Theme['colors'],
Theme['breakpoints']
>;
};

export type AllProps<Theme extends BaseTheme> = BackgroundColorProps<Theme> &
Expand Down
7 changes: 3 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {ImageStyle, TextStyle, ViewStyle, StyleProp} from 'react-native';

export type AtLeastOneResponsiveValue<
Value,
Theme extends BaseTheme,
B = Theme['breakpoints'],
B extends BaseTheme['breakpoints'],
R = {[Key in keyof B]: Record<Key, Value>}
> = Partial<
{
Expand All @@ -12,9 +11,9 @@ export type AtLeastOneResponsiveValue<
> &
R[keyof R];

export type ResponsiveValue<Value, Theme extends BaseTheme> =
export type ResponsiveValue<Value, B extends BaseTheme['breakpoints']> =
| Value
| AtLeastOneResponsiveValue<Value, Theme>;
| AtLeastOneResponsiveValue<Value, B>;

export type SafeVariants<T> = Omit<T, keyof KnownBaseTheme>;

Expand Down