-
Notifications
You must be signed in to change notification settings - Fork 151
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(blade): chipgroup grid alignment #2536
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a1f66f9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ PR title follows Conventional Commits specification. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit a1f66f9:
|
We should ideally do this, and let consumer handle the layout. <ChipGroupComponent
selectionType="single"
label="Select a gift card with value (custom chipGroupContainerLayout)"
>
<Box display="grid" gridTemplateColumns="1fr 1fr 1fr">
{chipArray.map((chip, index) => (
<ChipComponent key={index} value={chip.value}>
{chip.label}
</ChipComponent>
))}
</Box>
</ChipGroupComponent> Only challenge is internally we are applying some default margins to each Chip component, we need to somehow make it work with the above example + keep the existing behaviour intact. Maybe we could do something like: <BaseBox
display="flex"
flexDirection="row"
flexWrap="wrap"
rowGap={chipGroupGapTokens[size].bottom}
columnGap={chipGroupGapTokens[size].right}
marginBottom={chipGroupGapTokens[size].bottom}
>
{React.Children.map(children, (child, index) => {
return <BaseBox key={index}>{child}</BaseBox>; // maybe we can remove the box if needed
})}
</BaseBox> |
thanks for suggesting this... i have implemented this... the api looks like <ChipGroupComponent
selectionType="single"
label="Select a gift card with value (custom chipGroupContainerLayout)"
>
<Box
display="grid"
gridTemplateColumns="repeat(3, minmax(0,120px))"
gridTemplateRows="repeat(3, minmax(0,30px))"
gap="spacing.3"
>
{chipArray.map((chip, index) => (
<ChipComponent key={index} value={chip.value} width="120px">
{chip.label}
</ChipComponent>
))}
</Box>
</ChipGroupComponent> also regarding that margin ... i think we don't need to do anything .. we can get children's from wrapper and render them. {React.Children.map(getChipWrapperChildren(), (child, index) => {
return (
<BaseBox
key={index}
marginBottom={chipGroupGapTokens[size].bottom}
marginRight={chipGroupGapTokens[size].right}
>
{child}
</BaseBox>
);
})} |
@@ -68,6 +70,24 @@ const _ChipGroup = ( | |||
}); | |||
} | |||
} | |||
const isWrapperLayoutControlled = | |||
typeof children === 'object' && getComponentId(children) === 'Box'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<BaseBox
display="flex"
flexDirection="row"
flexWrap="wrap"
rowGap={chipGroupGapTokens[size].bottom}
columnGap={chipGroupGapTokens[size].right}
marginBottom={chipGroupGapTokens[size].bottom}
>
{React.Children.map(children, (child, index) => {
return <BaseBox key={index}>{child}</BaseBox>; // maybe we can remove the box if needed
})}
</BaseBox>
This code i shared, should just work without doing any of these checks/conditionals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I think we should add a wrapper and check for styles since consumers can pass props like background color or margin and padding, which should not be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not do arbitrary checks if it's absolutely not necessary. If they add background etc anyways it will look odd.
Your above code will fail in many cases like so:
const SomeCustomWrapperBox = styled(Box)``
<ChipGroup>
<SomeCustomWrapperBox>
...
</SomeCustomWrapperBox>
</ChipGroup>
``
177d4f9
to
72efaeb
Compare
<BaseBox display="flex" flexDirection="row" flexWrap="wrap"> | ||
{React.Children.map(children, (child, index) => { | ||
return ( | ||
<BaseBox | ||
key={index} | ||
marginBottom={chipGroupGapTokens[size].bottom} | ||
marginRight={chipGroupGapTokens[size].right} | ||
> | ||
{child} | ||
</BaseBox> | ||
); | ||
})} | ||
{React.Children.map(children, (child) => child)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, we need to keep the row gap etc props to make sure we are not changing the existing spacing that was there PLUS we let consumers handle the layout if they want.
<BaseBox
display="flex"
flexDirection="row"
flexWrap="wrap"
// Keep existing spacing that was there
rowGap={chipGroupGapTokens[size].bottom}
columnGap={chipGroupGapTokens[size].right}
marginBottom={chipGroupGapTokens[size].bottom}
>
{React.Children.map(children, (child, index) => {
return <BaseBox key={index}>{child}</BaseBox>;
})}
</BaseBox>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/razorpay/blade/blob/98296fb7f8da7dfbb9a9db44e5b7e0fa957ddf51/packages/blade/src/components/Chip/Chip.tsx
Moved that to Chip, consumers can modify it from there.
Adding spacing on the wrapper won't work since this spacing needs to be applied to Chip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tewarig reusable components should not have margins, they are bit harmful. If in future we want to expose Chip as a standalone component (eg: Clickable only chip) then it will break component encapsulation.
Adding spacing on the wrapper won't work since this spacing needs to be applied to Chip.
Thus the BaseBox i've added on my example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense
columnGap={chipGroupGapTokens[size].right} | ||
marginBottom={chipGroupGapTokens[size].bottom} | ||
> | ||
{React.Children.map(children, (child) => child)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably can just be {children}
gridTemplateColumns="repeat(3, minmax(0,120px))" | ||
gridTemplateRows="repeat(3, minmax(0,30px))" | ||
gap="spacing.3" | ||
> | ||
{chipArray.map((chip, index) => ( | ||
<ChipComponent key={index} value={chip.value} width="120px"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 We shouldn't need to add explicit pixel values in ChipComponent.
ideally width=100% or flex={1} should work, instead of hard coding 120px like so:
<ChipComponent key={index} value={chip.value} width="100%" />
I would assume this would work and the chip should automatically stretch/flex to available space.
Not to mention explicit pixel values will break the layout if there is no space:
![image](https://private-user-images.githubusercontent.com/35374649/411872676-56cb7daa-3d3b-4341-bb51-30537d114ff7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODc4NjAsIm5iZiI6MTczOTI4NzU2MCwicGF0aCI6Ii8zNTM3NDY0OS80MTE4NzI2NzYtNTZjYjdkYWEtM2QzYi00MzQxLWJiNTEtMzA1MzdkMTE0ZmY3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDE1MjYwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTMxYTE5OThkNDdkZTk5ZTZkMDk5NjA3NzBhN2I0ZTRmYzIyNmY3ODQyMDhjZGQ2ODg5NTZmOGFhMTE3YjM3ZWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.05VYIjuyrYSCAAWm7wYqHUmcsu_c7VRHDova5IoiS6c)
@@ -144,5 +144,5 @@ const getStyledProps = (props: Record<string, any>): StyledPropsBlade => { | |||
return removeUndefinedStyledProps(makeStyledProps(props)); | |||
}; | |||
|
|||
export type { StyledPropsBlade }; | |||
export type { StyledPropsBlade, StyledPropsInputType }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -332,5 +332,5 @@ type BoxRefType = Platform.Select<{ | |||
native: View; | |||
}>; | |||
|
|||
export type { BaseBoxProps, BoxProps, BoxRefType, StyledPropsBlade, FlexboxProps }; | |||
export type { BaseBoxProps, BoxProps, BoxRefType, StyledPropsBlade, FlexboxProps, GridProps }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -39,7 +39,7 @@ type OnChange = ({ | |||
}) => void; | |||
|
|||
const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = ( | |||
{ isDisabled, value, children, icon: Icon, color, testID, _motionMeta, ...rest }, | |||
{ isDisabled, value, children, icon: Icon, color, testID, _motionMeta, width, ...rest }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should expose minWidth
, maxWidth
as well right if we're exposing width
?
Description
ref - https://razorpay.slack.com/archives/CMQ3RBHEU/p1738752395317139
Changes
Additional Information
Component Checklist