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

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 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
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
2 changes: 1 addition & 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,7 @@ const AnimatedChip = styled(BaseBox)<AnimatedChipProps>((props) => {
);
return {
...getAnimatedChipStyles(props),
width: 'fit-content',
width: '100%',
transform: `scale(${props.isPressed ? '0.92' : '1'})`,
transitionDuration: duration,
transitionTimingFunction: easing,
Expand Down
26 changes: 22 additions & 4 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 @@ -72,7 +84,6 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
const useChip = groupProps?.selectionType === 'single' ? useRadio : useCheckbox;
const _size = groupProps?.size || 'small';
const chipColor = color ?? groupProps?.color ?? 'primary';

const handleChange: OnChange = ({ isChecked, value }) => {
if (isChecked) {
groupProps?.state?.addValue(value!);
Expand Down Expand Up @@ -147,6 +158,9 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
{...makeAnalyticsAttribute(rest)}
display={(isReactNative() ? 'flex' : 'inline-flex') as never}
ref={getOuterMotionRef({ _motionMeta, ref })}
width={width}
maxWidth={maxWidth}
minWidth={minWidth}
>
<SelectorLabel
componentName={MetaConstants.ChipLabel}
Expand All @@ -158,9 +172,12 @@ 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: '100%',
}}
>
<BaseBox display="flex" flexDirection="column">
<BaseBox display="flex" flexDirection="column" width="100%">
<BaseBox display="flex" alignItems="center" flexDirection="row">
<SelectorInput
hoverTokens={getChipInputHoverTokens(chipColor)}
Expand Down Expand Up @@ -201,6 +218,7 @@ const _Chip: React.ForwardRefRenderFunction<BladeElementRef, ChipProps> = (
}
height={makeSize(chipHeightTokens[_size])}
gap="spacing.3"
width="100%"
>
{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?

>
{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