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

Split definitions for group types #3370

Merged
merged 4 commits into from
Apr 26, 2024
Merged

Split definitions for group types #3370

merged 4 commits into from
Apr 26, 2024

Conversation

steviehailey-skyscanner
Copy link
Contributor

Splitting up definitions of the group types to reduce logic

@@ -70,131 +70,172 @@ export type ChipItem = {
hidden?: boolean;
} & SingleSelectChipItem;

export type InternalProps = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Props common to both components which are not exposed to external consumers

export type CommonProps = {
label?: string;
ariaLabel?: string;
type?: ChipGroupType;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now only used where we define the union of component types

};

export type ChipGroupProps = {
chips: ChipItem[];
export type RailChipGroupProps = {
stickyChip?: ChipItem;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define props that are specific to rail version

trailingNudgerLabel?: string;
} & CommonProps;

export type WrapChipGroupProps = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't anything specific in here but open question whether we like having a marker type to describe the scenario

} & CommonProps;

export type ChipGroupProps = (RailChipGroupProps & { type: typeof CHIP_GROUP_TYPES.rail } | WrapChipGroupProps & { type: typeof CHIP_GROUP_TYPES.wrap });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move the type field into the respective sub-types but it isn't used by any direct consumers so eslint isn't happy with that - defining it with the union here covers what we need without exposing it to places that don't use it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this I'm expecting typeof CHIP_GROUP_TYPES.rail to be string, instead of 'rail' which is what I think we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, thanks to the as const on the CHIP_GROUP_TYPES (line 39) the type is specifically rail instead of string

Here is a preview of the evaluated type:
image


const BpkChipGroup = ({
const Chip = ({ ariaMultiselectable, chipIndex, chipItem, chipStyle }: { chipIndex: number, chipItem: ChipItem, chipStyle: ChipStyleType, ariaMultiselectable: boolean }, index: number) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted from the inline func to build a chip

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the index param now we have chipIndex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, well spotted 👍

);
}

const ChipGroupContent = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted from the common core legend component of each variety of chipgroup

</fieldset>
);

const RailChipGroup = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less conditionals now we know this is a rail group

);
};

const WrapChipGroup = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler logic now we know doesn't support rail logic

chips={chips}
label={label} />;

const BpkChipGroup = ({ label, type, ...rest }: ChipGroupProps) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

External interface which now defers to the respective sub-types

Copy link
Contributor

@Iain530 Iain530 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 🚀 couple of Qs

} & CommonProps;

export type ChipGroupProps = (RailChipGroupProps & { type: typeof CHIP_GROUP_TYPES.rail } | WrapChipGroupProps & { type: typeof CHIP_GROUP_TYPES.wrap });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this I'm expecting typeof CHIP_GROUP_TYPES.rail to be string, instead of 'rail' which is what I think we want?


const BpkChipGroup = ({
const Chip = ({ ariaMultiselectable, chipIndex, chipItem, chipStyle }: { chipIndex: number, chipItem: ChipItem, chipStyle: ChipStyleType, ariaMultiselectable: boolean }, index: number) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the index param now we have chipIndex?


export type SingleSelectProps = {
chips: SingleSelectChipItem[];
selectedIndex?: number;
onItemClick?: (item: SingleSelectChipItem, selected: boolean, index: number) => void,
} & CommonProps;

} & ChipGroupProps;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to use the entire ChipGroupProps because consumer can choose type and then may need to provided specific args based on selection

Copy link
Contributor

@Iain530 Iain530 Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might have caused the chips prop to now include the ChipItem as well as SingleSelectChipItem
image

Comment on lines +87 to +88
leadingNudgerLabel?: string;
trailingNudgerLabel?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two labels should now be required since they were previously required for rail but not needed for wrap. Now this type is rail only they can be required and the default of "" removed

@Iain530 Iain530 marked this pull request as ready for review April 26, 2024 14:30
@Iain530 Iain530 merged commit 58f20e2 into DTO-4223 Apr 26, 2024
1 check passed
@Iain530 Iain530 deleted the DTO-4223-sh branch April 26, 2024 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants