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

refactor: BaseProps type is genric now to exclude some style prop key… #103

Merged
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
2 changes: 1 addition & 1 deletion src/components/AlertBanner/stylesBuilder/stylesBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type AlertBannerStylesBuilder = {
container: BaseProps;
iconContainer: BaseProps;
actionContainer: BaseProps;
closeButton: BaseProps;
closeButton: BaseProps<'appearance'>;
actionProps: Partial<BareButtonProps>;
closeButtonProps: Partial<GhostIconButtonProps>;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Avatar/Avatar.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type AvatarConfig = {
innerElements?: {
image?: BaseProps;
};
} & BaseProps;
} & BaseProps<'appearance'>;

export const defaultConfig = {
overflow: 'hidden',
Expand Down
2 changes: 1 addition & 1 deletion src/components/Badge/Badge.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type BadgeConfig = {
label?: BaseProps;
iconContainer?: BaseProps;
};
} & BaseProps;
} & BaseProps<'appearance'>;

export const defaultConfig = {
display: 'flex',
Expand Down
6 changes: 3 additions & 3 deletions src/components/Button/Button.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export type DefaultButtonConfig = {
};
};
};
} & BaseProps;
} & BaseProps<'appearance'>;

export type GhostButtonConfig = {
appearance?: {
Expand Down Expand Up @@ -154,7 +154,7 @@ export type GhostButtonConfig = {
};
};
};
} & BaseProps;
} & BaseProps<'appearance'>;

export type BareButtonConfig = {
appearance?: {
Expand Down Expand Up @@ -229,7 +229,7 @@ export type BareButtonConfig = {
};
};
};
} & BaseProps;
} & BaseProps<'appearance'>;

const size = {
small: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Counter/Counter.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type CounterConfig = {
}
>
>;
} & BaseProps;
} & BaseProps<'appearance'>;

export const defaultConfig = {
display: 'inline-flex',
Expand Down
2 changes: 1 addition & 1 deletion src/components/InlineBanner/stylesBuilder/stylesBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type InlineBannerStylesBuilder = {
actionContainer: BaseProps;
description: BaseProps;
title: BaseProps;
closeButton: BaseProps;
closeButton: BaseProps<'appearance'>;
};

export const stylesBuilder = ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/Label/stylesBuilder/stylesBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type LabelStylesBuilder = {
label: BaseProps;
optional: BaseProps;
tooltip: BaseProps;
action: BaseProps;
action: BaseProps<'appearance'>;
};

export const stylesBuilder = (
Expand Down
4 changes: 2 additions & 2 deletions src/components/Loader/Loader.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { LoaderAppearance, LoaderShape, LoaderSize } from './types';
import { Theme } from '@/theme';
import { BaseProps } from '@/types/BaseProps';

export type SVGProps = Omit<
BaseProps,
export type SVGProps = BaseProps<
| 'appearance'
| 'opacity'
| 'display'
| 'order'
Expand Down
2 changes: 1 addition & 1 deletion src/components/SocialButton/SocialButton.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseProps } from '@/types/BaseProps';

export type SocialButtonAppearance = 'primary' | 'secondary';

export type SocialButtonConfig = BaseProps & {
export type SocialButtonConfig = BaseProps<'appearance'> & {
appearance?: Partial<Record<SocialButtonAppearance, BaseProps>>;
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/StatusDot/StatusDot.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { BaseProps } from '@/types/BaseProps';
export type StatusDotConfig = {
appearance?: Partial<Record<StatusDotAppearance, BaseProps>>;
hasStroke?: BaseProps;
} & BaseProps;
} & BaseProps<'appearance'>;

export const defaultConfig = {
w: '12px',
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tag/stylesBuilder/stylesBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { BaseProps } from '@/types/BaseProps';
type TagStylesBuilder = {
container: BaseProps;
label: BaseProps;
avatar: BaseProps;
closeButton: BaseProps;
avatar: BaseProps<'appearance'>;
closeButton: BaseProps<'appearance'>;
};
export const stylesBuilder = (
custom: TagProps['custom'],
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/stylesBuilder/stylesBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type TextInputStylesBuilder = {
input: BaseProps;
icon: BaseProps;
text: BaseProps;
clearButton: BaseProps;
clearButton: BaseProps<'appearance'>;
beforeComponent: BaseProps;
afterComponent: BaseProps;
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toast/stylesBuilder/stylesBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type StylesBuilderProps = Required<Pick<ToastProps, 'emphasis' | 'intent'>> & {
type ToastStylesBuilder = {
container: BaseProps;
actionContainer: BaseProps;
closeButton: BaseProps;
closeButton: BaseProps<'appearance'>;
iconContainer: BaseProps;
middleDot: BaseProps;
};
Expand Down
13 changes: 12 additions & 1 deletion src/types/BaseProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ import { SystemProps } from '@xstyled/styled-components';

import { Theme } from '@/theme';

export type BaseProps = Omit<SystemProps<Theme>, 'appearance'>;
type TetrislySystemProps = SystemProps<Theme>;

/**
* A utility type that allows you to pick all style properties from a TetrislySystemProps type except for a specified set of keys.
* @template K - The union of keys to exclude from the resulting type, for instance 'appearance' | 'size' | 'background.
* @template TetrislySystemProps - The type to pick properties from.
* @returns A new type that includes all properties from `TetrislySystemProps` except for those specified in `K`.
*/
export type BaseProps<K extends keyof TetrislySystemProps = never> = Pick<
TetrislySystemProps,
Exclude<keyof TetrislySystemProps, K>
>;