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(blade): chipgroup grid alignment #2536

Merged
merged 31 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
39da608
chore: expose grid and flexbox props
tewarig Feb 9, 2025
67b9d5f
fix: add changeset
tewarig Feb 9, 2025
fb84e53
chore: update lint error
tewarig Feb 9, 2025
2481620
feat: add width prop in chip
tewarig Feb 10, 2025
1e89e97
feat: let user change the layout
tewarig Feb 10, 2025
72efaeb
chore: remove unsed commit types
tewarig Feb 10, 2025
18838c7
chore: review changes
tewarig Feb 10, 2025
464acc8
chore: update snap
tewarig Feb 10, 2025
f280c95
chore: removed unused utils
tewarig Feb 11, 2025
98296fb
chore: remove types
tewarig Feb 11, 2025
7c9803a
chore: update ts
tewarig Feb 11, 2025
f3633f3
chore: review change
tewarig Feb 11, 2025
a818274
chore: update snap
tewarig Feb 11, 2025
dc6fa5a
chore : review change
tewarig Feb 11, 2025
23ee578
chore: review changes
tewarig Feb 11, 2025
f4652cb
chore: addMaxWidth , minWidth
tewarig Feb 11, 2025
bb40a3f
chore: expose maxWidth , minWidth
tewarig Feb 11, 2025
62f74c1
chore: update chipgroup width
tewarig Feb 11, 2025
2a32ed1
chore: more refactor
tewarig Feb 11, 2025
a1f66f9
chore: update snap
tewarig Feb 11, 2025
c02f1e9
chore: chipgroup custom layout
tewarig Feb 12, 2025
1836fdc
chore: change to getBaseBoxStyles
tewarig Feb 12, 2025
8adc366
chore: refactor width
tewarig Feb 12, 2025
3443de8
chore: refactor
tewarig Feb 12, 2025
1774421
chore: more changes
tewarig Feb 12, 2025
833b335
chore: snap update
tewarig Feb 12, 2025
4be16b6
chore: change to width 100%
tewarig Feb 13, 2025
bf73016
chore: update snaps
tewarig Feb 13, 2025
eee166f
chore: review changes
tewarig Feb 14, 2025
29bfc15
chore: docs update
tewarig Feb 17, 2025
aad91c2
chore: change baseBoxProps to box props
tewarig Feb 17, 2025
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: 5 additions & 0 deletions .changeset/two-cows-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@razorpay/blade': patch
---

fix(blade): allow consumers to align chips in chipgroup
4 changes: 3 additions & 1 deletion packages/blade/src/components/Chip/AnimatedChip.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const AnimatedChip = styled(BaseBox)<AnimatedChipProps>((props) => {
);
return {
...getAnimatedChipStyles(props),
width: 'fit-content',
width: props?.width ? (props.width as string | number) : 'fit-content',
maxWidth: props?.maxWidth as string | number,
minWidth: props?.minWidth as string | number,
Copy link
Member

Choose a reason for hiding this comment

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

why is as string | number required here? isn't styled-components by default accepting string and number?

transform: `scale(${props.isPressed ? '0.92' : '1'})`,
transitionDuration: duration,
transitionTimingFunction: easing,
Expand Down
35 changes: 32 additions & 3 deletions packages/blade/src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ 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,
maxWidth,
minWidth,
...rest
},
ref,
) => {
const { theme } = useTheme();
Expand Down Expand Up @@ -158,9 +170,20 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
onKeyDown={handleKeyboardPressedIn}
onKeyUp={handleKeyboardPressedOut}
inputProps={isReactNative() ? inputProps : {}}
style={{ cursor: _isDisabled ? 'not-allowed' : 'pointer' }}
style={{
cursor: _isDisabled ? 'not-allowed' : 'pointer',
width: width as string | number,
maxWidth: maxWidth as string | number,
minWidth: minWidth as string | number,
Copy link
Member

Choose a reason for hiding this comment

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

why is as string | number required here?

Copy link
Member

Choose a reason for hiding this comment

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

This will break if I do width="spacing.3" no?

}}
>
<BaseBox display="flex" flexDirection="column">
<BaseBox
display="flex"
flexDirection="column"
width={width}
maxWidth={maxWidth}
minWidth={minWidth}
tewarig marked this conversation as resolved.
Show resolved Hide resolved
>
<BaseBox display="flex" alignItems="center" flexDirection="row">
<SelectorInput
hoverTokens={getChipInputHoverTokens(chipColor)}
Expand All @@ -175,6 +198,9 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
isDisabled={_isDisabled}
isPressed={isPressed}
isDesktop={matchedDeviceType === 'desktop'}
width={width}
maxWidth={maxWidth}
minWidth={minWidth}
>
<StyledChipWrapper
borderColor={chipBorderColor}
Expand All @@ -201,6 +227,9 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
}
height={makeSize(chipHeightTokens[_size])}
gap="spacing.3"
width={width}
maxWidth={maxWidth}
minWidth={minWidth}
>
{Icon ? (
<BaseBox display="flex">
Expand Down
79 changes: 79 additions & 0 deletions packages/blade/src/components/Chip/ChipGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,82 @@ chipRef.parameters = {
exclude: ['icon'],
},
};

export const CutomLayoutInChipGroup: StoryFn<typeof ChipGroupComponent> = () => {
const chipArray = [
{
value: '100',
label: '₹100',
},
{
value: '500',
label: '₹500',
},
{
value: '1000',
label: '₹1000',
},
{
value: '2000',
label: '₹2000',
},
{
value: '5000',
label: '₹5000',
},
{
value: '10000',
label: '₹10000',
},
{
value: '20000',
label: '₹20000',
},
{
value: '50000',
label: '₹50000',
},
{
value: '100000',
label: '₹100000',
},
{
value: '200000',
label: '₹200000',
},
];

return (
<Box gap="spacing.3" display="flex" flexDirection="column">
<ChipGroupComponent
selectionType="single"
label="Select a gift card with value (without custom chipGroupContainerLayout)"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
label="Select a gift card with value (without custom chipGroupContainerLayout)"
label="Select a gift card with value (without custom chipGroupContainerLayout)"

what is chipGroupContainerLayout?

Copy link
Member

Choose a reason for hiding this comment

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

  • with default layout
  • with custom layout

>
{chipArray.map((chip, index) => (
<ChipComponent key={index} value={chip.value}>
{chip.label}
</ChipComponent>
))}
</ChipGroupComponent>
<ChipGroupComponent
selectionType="single"
label="Select a gift card with value (custom chipGroupContainerLayout)"
>
<Box
display="grid"
gridTemplateColumns="repeat(3, 1fr)"
gridTemplateRows="repeat(3, minmax(0, 30px))"
gap="spacing.3"
>
{chipArray.map((chip, index) => (
<ChipComponent key={index} value={chip.value} width="100%">
{chip.label}
</ChipComponent>
))}
</Box>
</ChipGroupComponent>
</Box>
);
};

CutomLayoutInChipGroup.storyName = 'ChipGroup with Custom layout';
23 changes: 10 additions & 13 deletions packages/blade/src/components/Chip/ChipGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { chipGroupGapTokens, chipGroupLabelSizeTokens } from './chipTokens';
import { chipGroupLabelSizeTokens, chipGroupGapTokens } from './chipTokens';
import { ChipGroupProvider } from './ChipGroupContext';
import { useChipGroup } from './useChipGroup';
import type { ChipGroupProps } from './types';
Expand Down Expand Up @@ -96,18 +96,15 @@ const _ChipGroup = (
<VisuallyHidden>
<Text>{accessibilityLabel}</Text>
</VisuallyHidden>
<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>
);
})}
<BaseBox
display="flex"
flexDirection="row"
flexWrap="wrap"
rowGap={chipGroupGapTokens[size].bottom}
columnGap={chipGroupGapTokens[size].right}
marginBottom={chipGroupGapTokens[size].bottom}
>
{children}
Comment on lines -99 to +107
Copy link
Member

Choose a reason for hiding this comment

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

nice 🏅

</BaseBox>
<FormHint
size={chipGroupLabelSizeTokens[size]}
Expand Down
Loading
Loading